+
    Dfji2                         R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt  ! R R]4      tR# )zi
Tests for L{twisted.mail.scripts.mailmail}, the implementation of the
command line program I{mailmail}.
N)StringIO)skipIf)version)Deferred)MemoryReactor)smtp)mailmail)parseOptions)Failure)platformType)TestCasec                      a  ] tR t^t o Rt]! 4       tR tR tR t	R t
R tR tR tR	 tR
 tR tR tR t]! ]R8H  R4      R 4       t]! ]R8H  R4      R 4       tR tR tR tRtV tR# )OptionsTestsz
Tests for L{parseOptions} which parses command line arguments and reads
message text from stdin to produce an L{Options} instance which can be
used to send a message.
c                   a  \        4       S n        ^ RIHpHp V! S P                  4      pS P                  \        RV! VR7      4       RS n        RS n        RS n	        V 3R lpS P                  \        RV4       R# )zb
Override some things in mailmail, so that we capture C{stdout},
and do not call L{reactor.stop}.
)LoggertextFileLogObserver_log)observerNc                    < V Sn         VSn        VSn        \        P                  ! V VP
                  VP                  VP                  SP                  R 7      # ))reactor)	hostoptionsidentr   sendmailsendertobodymemoryReactor)r   r   r   selfs   &&&A/usr/lib/python3/dist-packages/twisted/mail/test/test_mailmail.pyr   $OptionsTests.setUp.<locals>.sendmail3   sJ    DI"DLDJ==

**     r   )
r   outtwisted.loggerr   r   patchr   r   r   r   )r   r   r   logObserverr   s   f    r   setUpOptionsTests.setUp#   s`    
 :>)$((3

8VV[%AB	

	 	

8Z2r!   c                    V P                  \        R\        R4      4       V P                  \        \
        . 4      pV P                  VP                  R4       R# )z
If no recipients are given in the argument list and there is no
recipient header in the message text, L{parseOptions} raises
L{SystemExit} with a string describing the problem.
stdinzSubject: foo

Hello, goodbye.
N)zNo recipients specified.)r$   sysr   assertRaises
SystemExitr	   assertEqualargsr   excs   & r   test_unspecifiedRecipients'OptionsTests.test_unspecifiedRecipientsA   sC     	

3*S!TU
L"=#@Ar!   c                v    V P                  \        \        R.4      pV P                  VP                  R4       R# )z
The I{-bp} option for listing queue information is unsupported and
if it is passed to L{parseOptions}, L{SystemExit} is raised.
z-bpNzUnsupported option.r+   r,   r	   r-   r.   r/   s   & r   test_listQueueInformation&OptionsTests.test_listQueueInformationK   s/    
 
L5'B#;<r!   c                v    V P                  \        \        R.4      pV P                  VP                  R4       R# )z
The I{-bs} option for using stdin and stdout as the SMTP transport
is unsupported and if it is passed to L{parseOptions}, L{SystemExit}
is raised.
z-bsNr4   r5   r/   s   & r   test_stdioTransport OptionsTests.test_stdioTransportS   /     
L5'B#;<r!   c                    V P                  \        \        R.4      pV P                  VP                  R4       V P                  \        \        R.4      pV P                  VP                  R4       R# )z
The I{-i} and I{-oi} options for ignoring C{"."} by itself on a line
are unsupported and if either is passed to L{parseOptions},
L{SystemExit} is raised.
z-iz-oiNr4   r5   r/   s   & r   test_ignoreFullStop OptionsTests.test_ignoreFullStop\   sZ     
L4&A#;<
L5'B#;<r!   c                v    V P                  \        \        R.4      pV P                  VP                  R4       R# )z
The I{-om} option for copying the sender if they appear in an alias
expansion is unsupported and if it is passed to L{parseOptions},
L{SystemExit} is raised.
z-omNr4   r5   r/   s   & r   test_copyAliasedSender#OptionsTests.test_copyAliasedSenderg   r;   r!   c                
   \        4       pV P                  \        RV4       V P                  \        \
        R4      pV P                  VP                  R4       VP                  4       pV P                  VR\         R24       R# )zf
The I{--version} option displays the version and raises
L{SystemExit} with L{None} as the exit code.
stdoutz	--versionNzmailmail version: 
)
r   r$   r*   r+   r,   r	   r-   codegetvaluer   )r   r"   systemExitCodedatas   &   r   test_versionOptionsTests.test_versionp   sj    
 j

3#&**:|[Q,,d3||~!3G9B?@r!   c                    \        R4      pV P                  \        RV4       \        R4      pV P	                  VP
                  4       R# )z1
The I{-odb} flag specifies background delivery.
rD   r)   z-odbN)r   r$   r*   r	   
assertTrue
backgroundr   r)   os   &  r   test_backgroundDelivery$OptionsTests.test_backgroundDelivery}   s7     

3' %r!   c                    \        R4      pV P                  \        RV4       \        R4      pV P	                  VP
                  4       R# )z2
The I{-odf} flags specifies foreground delivery.
rD   r)   z-odfN)r   r$   r*   r	   assertFalserM   rN   s   &  r   test_foregroundDelivery$OptionsTests.test_foregroundDelivery   s9     

3' &r!   c                    \        R4      pV P                  \        RV4       \        R4      pV P	                  \        VP                  4      ^4       R# )zL
The I{-t} flags specifies that recipients should be obtained
from headers.
zTo: Curly <invaliduser2@example.com>
Cc: Larry <invaliduser1@example.com>
Bcc: Moe <invaliduser3@example.com>

Oh, a wise guy?
r)   -tN)r   r$   r*   r	   r-   lenr   rN   s   &  r   test_recipientsFromHeaders'OptionsTests.test_recipientsFromHeaders   sG    
  
 	

3'QTTA&r!   c                    \        R4      pV P                  \        RV4       \        . RO4      pV P	                  VP
                  R4       R# )z_
When a message has no I{From:} header, a I{From:} value can be
specified with the I{-F} flag.
z3To: invaliduser2@example.com
Subject: A wise guy?

r)    Larry <invaliduser1@example.com>N)-Fr\   rW   r   r$   r*   r	   r-   r   rN   s   &  r   test_setFromOptionsTests.test_setFrom   s?    
 TU

3'IJ#EFr!   c                    \        R4      pV P                  \        RV4       \        . RO4      pV P	                  VP
                  R4       R# )zy
The I{-F} flag specifies the From: value.  However, I{-F} flag is
overriden by the value of From: in the e-mail header.
zLTo: Curly <invaliduser4@example.com>
From: Shemp <invaliduser4@example.com>
r)   zinvaliduser4@example.comN)r]   z"Groucho <invaliduser5@example.com>rW   r^   rN   s   &  r   !test_overrideFromFlagByFromHeader.OptionsTests.test_overrideFromFlagByFromHeader   sE    
 7
 	

3'KL#=>r!   win32zImailmail.run() does not work on win32 due to lack of support for getuid()c                   Rp\        R4      pV P                  \        RV4       V P                  \        RV4       \        P                  ! 4        V P                  V P                  P                  \        P                  ! 4       4       V P                  V P                  P                  R.4       V P                  V P                  P                  4       V P                  \        P                  4       R# )z
Call L{mailmail.run}, and specify I{-oep} to print errors
to stderr.  The sender, to, and printErrors options should be
set and there should be no failure.
invaliduser2@example.comrD   argvr)   Nztest_mailmail.pyrf   z-oep)r   r$   r*   r   runr-   r   r   getloginr   rL   printErrorsassertIsNonefailed)r   rg   r)   s   &  r   test_runErrorsToStderr#OptionsTests.test_runErrorsToStderr   s     H

3%

3',,h.?.?.AB+E*FG001(//*r!   c                   \        R4      pV P                  \        RV4       V P                  4       p\        P
                  ! 4       p\        P                  ! 4       p\        VR4      ;_uu_ 4       pVP                  RP                  W44      4       RRR4       V P                  \        RV4       RpV P                  \        RV4       \        P                  ! 4        V P                  V P                  P                  4       R4       V P                  V P                  P                  4       R	4       V P                  V P                  P                  4       R
4       R#   + '       g   i     L; i)zm
Error messages for illegal UID value, illegal GID value, and illegal
identity entry will be sent to stderr.
rD   r)   wa  [useraccess]
allow=invaliduser2,invaliduser1
deny=invaliduser3,invaliduser4,{}
order=allow,deny
[groupaccess]
allow=invalidgid1,invalidgid2
deny=invalidgid1,invalidgid2,{}
order=deny,allow
[identity]
localhost=funny
[addresses]
smarthost=localhost
default_domain=example.com
N	LOCAL_CFGrg   z3Illegal UID in \[useraccess\] section: invaliduser1z3Illegal GID in \[groupaccess\] section: invalidgid1z,Illegal entry in \[identity\] section: funnyrh   )r   r$   r*   mktemposgetuidgetgidopenwriteformatr   ri   assertRegexr"   rF   )r   r)   filenamemyUidmyGidfrg   s   &      r   test_readInvalidConfig#OptionsTests.test_readInvalidConfig   s    

3';;=				(C  AGG/ 06ve/C !2 	

8[(3G

3%HHF	
 	HHF	
 	HH!Q	
M ! s   1!EE/	c                    ^ RI Hp V P                  4       p\        VR4      ;_uu_ 4       pVP	                  V4       RRR4       V! V4      #   + '       g   i     L; i)ab  
Read a mailmail configuration file.

The mailmail script checks the twisted.mail.scripts.mailmail.GLOBAL_CFG
variable and then the twisted.mail.scripts.mailmail.LOCAL_CFG
variable for the path to its  config file.

@param config: path to config file
@type config: L{str}

@return: A parsed config.
@rtype: L{twisted.mail.scripts.mailmail.Configuration}
)
loadConfigrq   N)twisted.mail.scripts.mailmailr   rs   rw   rx   )r   configr   r{   r~   s   &&   r   getConfigFromFileOptionsTests.getConfigFromFile  sG     	=;;=(C  AGGFO ! (## ! s   AA	c                   V P                  R4      pV P                  VP                  R4       V P                  R4      pV P                  VP                  R4       V P                  R4      pV P                  VP                  R4       V P                  VP                  R4       V P                  R4      pV P	                  RVP
                  4       V P                  VP
                  R,          R	R
.4       V P                  R4      pV P                  VP                  ^#.4       V P                  R4      pV P                  VP                  ^#^$.4       V P                  R4      pV P                  VP                  ^#^$.4       V P                  VP                  ^%^&.4       V P                  R4      pV P                  VP                  ^).4       V P                  R4      pV P                  VP                  ^).4       V P                  R4      pV P                  VP                  ^)^*.4       V P                  VP                  ^+^,.4       R# )zR
L{twisted.mail.scripts.mailmail.loadConfig}
parses the config file for mailmail.
z 
[addresses]
smarthost=localhost	localhostz'
[addresses]
default_domain=example.comzexample.comz;
[addresses]
smarthost=localhost
default_domain=example.comz1
[identity]
host1=invalid
host2=username:passwordhost1host2usernamepasswordz+
[useraccess]
allow=invalid1,35
order=allowz#
[useraccess]
deny=35,36
order=denyz/
[useraccess]
allow=35,36
deny=37,38
order=denyz(
[groupaccess]
allow=gid1,41
order=allowz!
[groupaccess]
deny=41
order=denyz6
[groupaccess]
allow=41,42
deny=43,44
order=allow,denyN)
r   r-   	smarthostdomainassertNotIn
identities	allowUIDsdenyUIDs	allowGIDsdenyGIDs)r   r   s   & r   test_loadConfigOptionsTests.test_loadConfig  s6   
 ''

 	));7''

 	6''
 	));76''
 	&"3"34**73j*5MN''
 	))B40''
 	2r(3''
 	))B842r(3''
 	))B40''
 	2$/''
 	))B842r(3r!   c                   a  V 3R lpS P                  \        RV4       \        P                  ! 4       pRVn        \        \        4       4      p\        P                  ! W24       R# )z
L{twisted.mail.scripts.mailmail.senderror} sends mail back to the
sender if an error occurs while sending mail to the recipient.
c                    < SP                  VR 4       SP                  VR.4       SP                  VP                  4       R4       \        4       # )zpostmaster@
testsender
ValueError)rz   r-   rF   r   )r   r   	recipientr   r   s   &&&&r   r   -OptionsTests.test_senderror.<locals>.sendmail}  sC    V]3Y7T]]_l;:r!   r   r   N)r$   r   r   Optionsr   r
   r   	senderror)r   r   optsfails   f   r   test_senderrorOptionsTests.test_senderrorw  sI    	 	

4X.!"z|$4&r!   )r   r   r   r"   N)__name__
__module____qualname____firstlineno____doc__r   r   r&   r1   r6   r9   r=   r@   rI   rP   rT   rY   r_   rb   r   r   rn   r   r   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      s      "OM3<B==	==A&'' G? V+	+$ V4
	4
l$0W4r' 'r!   r   )r   rt   r*   ior   unittestr   twisted.copyrightr   twisted.internet.deferr   twisted.internet.testingr   twisted.mailr   twisted.mail.scriptsr   r   r	   twisted.python.failurer
   twisted.python.runtimer   twisted.trial.unittestr   r    r!   r   <module>r      sA   

 
 
   % + 2  ) 6 * / +m'8 m'r!   