+
    üÐ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   ø€ ØˆDŒIØ"ˆDŒLØˆDŒJÜ—=’=ØØ—‘Ø—
‘
Ø—‘Ø×*Ñ*ôð ó    r   )
r   ÚoutÚtwisted.loggerr   r   Úpatchr   r   r   r   )r   r   r   ÚlogObserverr   s   f    r   ÚsetUpÚOptionsTests.setUp#   s`   ø€ ô
 “:ˆŒç>á)¨$¯(©(Ó3ˆØ�
‰
”8˜V¡V°[Ô%AÔBØˆŒ	ØˆŒØˆŒ
õ
	ð 	�
‰
”8˜Z¨Ö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/   € ð
 ×Ñ¤
¬L¸5¸'Ó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   ó/   € ð ×Ñ¤
¬L¸5¸'Ó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   € ð ×Ñ¤
¬L¸4¸&ÓAˆØ×Ñ˜Ÿ™Ð#;Ô<Ø×Ñ¤
¬L¸5¸'Ó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Ø�|‰|‹~ˆØ×Ñ˜Ð!3´G°9¸BÐ?Ö@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˜ Ô'Ü˜ÓˆØ×Ñœ˜QŸT™T› 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à�G‰Gð/÷ 06©v°eÓ/Cô÷ !ð2 	�
‰
”8˜[¨(Ô3àGˆØ�
‰
”3˜ Ô%Ü�ŠŒØ×ÑØ�H‰H×ÑÓØFô	
ð 	×ÑØ�H‰H×ÑÓØFô	
ð 	×ÑØ�H‰H×ÑÓÐ!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Ø�G‰G�FŒO÷ !ñ ˜(Ó#Ð#÷ !× ú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Õ3°jÀ*Ð5MÔNà×'Ñ'ðó
ˆð 	×Ñ˜×)Ñ)¨B¨4Ô0à×'Ñ'ðó
ˆð 	×Ñ˜Ÿ™¨2¨r¨(Ô3à×'Ñ'ðó
ˆð 	×Ñ˜×)Ñ)¨B°¨8Ô4Ø×Ñ˜Ÿ™¨2¨r¨(Ô3à×'Ñ'ðó
ˆð 	×Ñ˜×)Ñ)¨B¨4Ô0à×'Ñ'ðó
ˆð 	×Ñ˜Ÿ™¨2¨$Ô/à×'Ñ'ðó
ˆð 	×Ñ˜×)Ñ)¨B°¨8Ô4Ø×Ñ˜Ÿ™¨2¨r¨(Ö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±   ø‡ € ññ "“O€Mò3ò<Bò=ò=ò	=ò=òAò&ò'ò'ò Gò?ñ Ø˜ÑØVóñ+ó	ð+ñ$ Ø˜ÑØVóñ4
ó	ð4
òl$ò0W4÷r'ð '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!   