ó
    Ö›‘hi2  ã                   ó²   • S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr   " S S\5      rg)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                   óÈ   • \ rS rSrSr\" 5       rS rS rS r	S r
S rS rS	 rS
 rS rS rS rS r\" \S:H  S5      S 5       r\" \S:H  S5      S 5       rS rS rS rSrg)ÚOptionsTestsé   z¨
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                 óò   ^ • [        5       T l        SSKJnJn  U" T R                  5      nT R                  [        SU" US95        ST l        ST l        ST l	        U 4S jnT R                  [        SU5        g)zb
Override some things in mailmail, so that we capture C{stdout},
and do not call L{reactor.stop}.
r   )ÚLoggerÚtextFileLogObserverÚ_log)ÚobserverNc                 ó®   >• U Tl         UTl        UTl        [        R                  " U UR
                  UR                  UR                  TR                  S9$ )N)Úreactor)	ÚhostÚoptionsÚidentr   ÚsendmailÚsenderÚtoÚbodyÚmemoryReactor)r   r   r   Úselfs      €ÚcC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-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   `    r!   ÚsetUpÚOptionsTests.setUp#   s`   ø€ ô
 “:ˆŒç>á)¨$¯(©(Ó3ˆØ�
‰
”8˜V¡V°[Ñ%AÔBØˆŒ	ØˆŒØˆŒ
õ
	ð 	�
‰
”8˜Z¨Õ2r#   c                 ó²   • U R                  [        S[        S5      5        U R                  [        [
        / 5      nU R                  UR                  S5        g)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.
)zNo recipients specified.N)r&   Úsysr   ÚassertRaisesÚ
SystemExitr
   ÚassertEqualÚargs©r    Úexcs     r!   Útest_unspecifiedRecipientsÚ'OptionsTests.test_unspecifiedRecipientsA   sC   € ð 	�
‰
”3˜¤Ð*SÓ!TÔUØ×Ñ¤
¬L¸"Ó=ˆØ×Ñ˜Ÿ™Ð#@ÕAr#   c                 ót   • U R                  [        [        S/5      nU R                  UR                  S5        g)z�
The I{-bp} option for listing queue information is unsupported and
if it is passed to L{parseOptions}, L{SystemExit} is raised.
z-bp©zUnsupported option.N©r-   r.   r
   r/   r0   r1   s     r!   Útest_listQueueInformationÚ&OptionsTests.test_listQueueInformationK   s/   € ð
 ×Ñ¤
¬L¸5¸'ÓBˆØ×Ñ˜Ÿ™Ð#;Õ<r#   c                 ót   • U R                  [        [        S/5      nU R                  UR                  S5        g)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-bsr6   Nr7   r1   s     r!   Útest_stdioTransportÚ OptionsTests.test_stdioTransportS   ó/   € ð ×Ñ¤
¬L¸5¸'ÓBˆØ×Ñ˜Ÿ™Ð#;Õ<r#   c                 óä   • U R                  [        [        S/5      nU R                  UR                  S5        U R                  [        [        S/5      nU R                  UR                  S5        g)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-ir6   z-oiNr7   r1   s     r!   Útest_ignoreFullStopÚ OptionsTests.test_ignoreFullStop\   sZ   € ð ×Ñ¤
¬L¸4¸&ÓAˆØ×Ñ˜Ÿ™Ð#;Ô<Ø×Ñ¤
¬L¸5¸'ÓBˆØ×Ñ˜Ÿ™Ð#;Õ<r#   c                 ót   • U R                  [        [        S/5      nU R                  UR                  S5        g)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-omr6   Nr7   r1   s     r!   Útest_copyAliasedSenderÚ#OptionsTests.test_copyAliasedSenderg   r=   r#   c                 ó  • [        5       nU R                  [        SU5        U R                  [        [
        S5      nU R                  UR                  S5        UR                  5       nU R                  US[         S35        g)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                 ó”   • [        S5      nU R                  [        SU5        [        S5      nU R	                  UR
                  5        g)z1
The I{-odb} flag specifies background delivery.
rF   r+   z-odbN)r   r&   r,   r
   Ú
assertTrueÚ
background©r    r+   Úos      r!   Útest_backgroundDeliveryÚ$OptionsTests.test_backgroundDelivery}   s7   € ô ˜“ˆØ�
‰
”3˜ Ô'Ü˜Ó ˆØ�‰˜Ÿ™Õ%r#   c                 ó”   • [        S5      nU R                  [        SU5        [        S5      nU R	                  UR
                  5        g)z2
The I{-odf} flags specifies foreground delivery.
rF   r+   z-odfN)r   r&   r,   r
   ÚassertFalserO   rP   s      r!   Útest_foregroundDeliveryÚ$OptionsTests.test_foregroundDelivery†   s9   € ô ˜“ˆØ�
‰
”3˜ Ô'Ü˜Ó ˆØ×Ñ˜Ÿ™Õ&r#   c                 ó¨   • [        S5      nU R                  [        SU5        [        S5      nU R	                  [        UR                  5      S5        g)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+   ú-té   N)r   r&   r,   r
   r/   Úlenr   rP   s      r!   Útest_recipientsFromHeadersÚ'OptionsTests.test_recipientsFromHeaders�   sG   € ô
 ð ó
ˆð 	�
‰
”3˜ Ô'Ü˜ÓˆØ×Ñœ˜QŸT™T› AÕ&r#   c                 óš   • [        S5      nU R                  [        SU5        [        / SQ5      nU R	                  UR
                  S5        g)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+   )ú-Fú Larry <invaliduser1@example.com>rY   r`   N©r   r&   r,   r
   r/   r   rP   s      r!   Útest_setFromÚOptionsTests.test_setFromŸ   s?   € ô
 ÐTÓUˆØ�
‰
”3˜ Ô'ÜÒIÓJˆØ×Ñ˜Ÿ™Ð#EÕFr#   c                 óš   • [        S5      nU R                  [        SU5        [        / SQ5      nU R	                  UR
                  S5        g)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+   )r_   z"Groucho <invaliduser5@example.com>rY   zinvaliduser4@example.comNra   rP   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                 óì  • Sn[        S5      nU R                  [        SU5        U R                  [        SU5        [        R                  " 5         U R                  U R                  R                  [        R                  " 5       5        U R                  U R                  R                  S/5        U R                  U R                  R                  5        U R                  [        R                  5        g)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.
©ztest_mailmail.pyúinvaliduser2@example.comz-oeprF   Úargvr+   rj   N)r   r&   r,   r	   Úrunr/   r   r   Úgetloginr   rN   ÚprintErrorsÚassertIsNoneÚfailed)r    rk   r+   s      r!   Útest_runErrorsToStderrÚ#OptionsTests.test_runErrorsToStderr¶   s£   € ð HˆÜ˜“ˆØ�
‰
”3˜ Ô%Ø�
‰
”3˜ Ô'Ü�ŠŒØ×Ñ˜Ÿ™×,Ñ,¬h×.?Ò.?Ó.AÔBØ×Ñ˜Ÿ™Ÿ™Ð+EÐ*FÔGà�‰˜Ÿ™×0Ñ0Ô1à×Ñœ(Ÿ/™/Õ*r#   c                 óÎ  • [        S5      nU R                  [        SU5        U R                  5       n[        R
                  " 5       n[        R                  " 5       n[        US5       nUR                  SR                  X45      5        SSS5        U R                  [        SU5        SnU R                  [        SU5        [        R                  " 5         U R                  U R                  R                  5       S	5        U R                  U R                  R                  5       S
5        U R                  U R                  R                  5       S5        g! , (       d  f       NÒ= f)zm
Error messages for illegal UID value, illegal GID value, and illegal
identity entry will be sent to stderr.
rF   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_CFGri   rk   z3Illegal UID in \[useraccess\] section: invaliduser1z3Illegal GID in \[groupaccess\] section: invalidgid1z,Illegal entry in \[identity\] section: funny)r   r&   r,   ÚmktempÚosÚgetuidÚgetgidÚopenÚwriteÚformatr	   rl   ÚassertRegexr$   rH   )r    r+   ÚfilenameÚmyUidÚmyGidÚfrk   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   Á)!EÅ
E$c                 ó¬   • SSK Jn  U R                  5       n[        US5       nUR	                  U5        SSS5        U" U5      $ ! , (       d  f       N= f)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}
r   )Ú
loadConfigrt   N)Útwisted.mail.scripts.mailmailr…   rv   rz   r{   )r    Úconfigr…   r~   r�   s        r!   ÚgetConfigFromFileÚOptionsTests.getConfigFromFile  sD   € õ 	=à—;‘;“=ˆä�(˜CÔ  AØ�G‰G�FŒO÷ !ñ ˜(Ó#Ð#÷ !Õ ús   £AÁ
Ac                 óŒ  • U R                  S5      nU R                  UR                  S5        U R                  S5      nU R                  UR                  S5        U R                  S5      nU R                  UR                  S5        U R                  UR                  S5        U R                  S5      nU R	                  SUR
                  5        U R                  UR
                  S   S	S
/5        U R                  S5      nU R                  UR                  S/5        U R                  S5      nU R                  UR                  SS/5        U R                  S5      nU R                  UR                  SS/5        U R                  UR                  SS/5        U R                  S5      nU R                  UR                  S/5        U R                  S5      nU R                  UR                  S/5        U R                  S5      nU R                  UR                  SS/5        U R                  UR                  SS/5        g)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=allowé#   z#
[useraccess]
deny=35,36
order=denyé$   z/
[useraccess]
allow=35,36
deny=37,38
order=denyé%   é&   z(
[groupaccess]
allow=gid1,41
order=allowé)   z!
[groupaccess]
deny=41
order=denyz6
[groupaccess]
allow=41,42
deny=43,44
order=allow,denyé*   é+   é,   N)
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                 óÊ   ^ • U 4S jnT R                  [        SU5        [        R                  " 5       nSUl        [        [        5       5      n[        R                  " X25        g)z‚
L{twisted.mail.scripts.mailmail.senderror} sends mail back to the
sender if an error occurs while sending mail to the recipient.
c                 ó¢   >• TR                  US5        TR                  US/5        TR                  UR                  5       S5        [        5       $ )Nzpostmaster@Ú
testsenderÚ
ValueError)r}   r/   rH   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   `   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(   r3   r8   r;   r?   rB   rK   rR   rV   r\   rb   re   r   r   rq   r‚   rˆ   r    r¬   Ú__static_attributes__© r#   r!   r   r      s©   † ññ "“O€Mò3ò<Bò=ò=ò	=ò=òAò&ò'ò'ò Gò?ñ Ø˜ÑØVóñ+ó	ð+ñ$ Ø˜ÑØVóñ4
ó	ð4
òl$ò0W4õr'r#   r   )r²   rw   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#   r!   Ú<module>r¿      sA   ðñ
ó
 
Û 
Ý Ý å %Ý +Ý 2Ý Ý )Ý 6Ý *Ý /Ý +ôm'�8õ m'r#   