§
    Ètºfi2  ã                   óº   — d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ  G d„ de¦  «        ZdS )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                   óä   — e Zd ZdZ e¦   «         Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Z eedk    d¦  «        d„ ¦   «         Z eedk    d¦  «        d„ ¦   «         Zd„ Zd„ Zd„ ZdS )Ú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                 ó  ‡ — t          ¦   «         ‰ _        ddlm}m}  |‰ j        ¦  «        }‰                      t          d ||¬¦  «        ¦  «         d‰ _        d‰ _        d‰ _	        ˆ fd„}‰                      t          d|¦  «         dS )zz
        Override some things in mailmail, so that we capture C{stdout},
        and do not call L{reactor.stop}.
        r   )ÚLoggerÚtextFileLogObserverÚ_log)ÚobserverNc                 óˆ   •— | ‰_         |‰_        |‰_        t          j        | |j        |j        |j        ‰j        ¬¦  «        S )N)Úreactor)	ÚhostÚoptionsÚidentr   ÚsendmailÚsenderÚtoÚbodyÚmemoryReactor)r   r   r   Úselfs      €ú^/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/mail/test/test_mailmail.pyr   z$OptionsTests.setUp.<locals>.sendmail3   sI   ø€ ØˆDŒIØ"ˆDŒLØˆDŒJÝ”=ØØ”Ø”
Ø”ØÔ*ðñ ô ð ó    r   )
r   ÚoutÚtwisted.loggerr   r   Úpatchr	   r   r   r   )r   r   r   ÚlogObserverr   s   `    r    ÚsetUpzOptionsTests.setUp#   s©   ø€ õ
 ‘:”:ˆŒà>Ð>Ð>Ð>Ð>Ð>Ð>Ð>à)Ð)¨$¬(Ñ3Ô3ˆØ�
Š
•8˜V V V°[Ð%AÑ%AÔ%AÑBÔBÐBØˆŒ	ØˆŒØˆŒ
ð
	ð 
	ð 
	ð 
	ð 
	ð 	�
Š
•8˜Z¨Ñ2Ô2Ð2Ð2Ð2r!   c                 óÐ   — |                       t          dt          d¦  «        ¦  «         |                      t          t
          g ¦  «        }|                      |j        d¦  «         dS )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_unspecifiedRecipientsz'OptionsTests.test_unspecifiedRecipientsA   sY   € ð 	�
Š
•3˜¥Ð*SÑ!TÔ!TÑUÔUÐUØ×Ò¥
­L¸"Ñ=Ô=ˆØ×Ò˜œÐ#@ÑAÔAÐAÐAÐAr!   c                 ó€   — |                       t          t          dg¦  «        }|                      |j        d¦  «         dS )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,   r-   r.   s     r    Útest_listQueueInformationz&OptionsTests.test_listQueueInformationK   s<   € ð
 ×Ò¥
­L¸5¸'ÑBÔBˆØ×Ò˜œÐ#;Ñ<Ô<Ð<Ð<Ð<r!   c                 ó€   — |                       t          t          dg¦  «        }|                      |j        d¦  «         dS )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-bsr2   Nr3   r.   s     r    Útest_stdioTransportz OptionsTests.test_stdioTransportS   ó<   € ð ×Ò¥
­L¸5¸'ÑBÔBˆØ×Ò˜œÐ#;Ñ<Ô<Ð<Ð<Ð<r!   c                 óú   — |                       t          t          dg¦  «        }|                      |j        d¦  «         |                       t          t          dg¦  «        }|                      |j        d¦  «         dS )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-ir2   z-oiNr3   r.   s     r    Útest_ignoreFullStopz OptionsTests.test_ignoreFullStop\   sn   € ð ×Ò¥
­L¸4¸&ÑAÔAˆØ×Ò˜œÐ#;Ñ<Ô<Ð<Ø×Ò¥
­L¸5¸'ÑBÔBˆØ×Ò˜œÐ#;Ñ<Ô<Ð<Ð<Ð<r!   c                 ó€   — |                       t          t          dg¦  «        }|                      |j        d¦  «         dS )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-omr2   Nr3   r.   s     r    Útest_copyAliasedSenderz#OptionsTests.test_copyAliasedSenderg   r7   r!   c                 ó8  — t          ¦   «         }|                      t          d|¦  «         |                      t          t
          d¦  «        }|                      |j        d¦  «         |                     ¦   «         }|                      |dt          › d�¦  «         dS )z~
        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_versionzOptionsTests.test_versionp   sˆ   € õ
 ‰jŒjˆØ�
Š
•3˜ #Ñ&Ô&Ð&Ø×*Ò*­:µ|À[ÑQÔQˆà×Ò˜Ô,¨dÑ3Ô3Ð3Ø�|Š|‰~Œ~ˆØ×Ò˜Ð?µGÐ?Ð?Ð?Ñ@Ô@Ð@Ð@Ð@r!   c                 ó®   — t          d¦  «        }|                      t          d|¦  «         t          d¦  «        }|                      |j        ¦  «         dS )zA
        The I{-odb} flag specifies background delivery.
        r>   r(   z-odbN)r   r$   r)   r
   Ú
assertTrueÚ
background©r   r(   Úos      r    Útest_backgroundDeliveryz$OptionsTests.test_backgroundDelivery}   sL   € õ ˜‘”ˆØ�
Š
•3˜ Ñ'Ô'Ð'Ý˜Ñ Ô ˆØ�Š˜œÑ%Ô%Ð%Ð%Ð%r!   c                 ó®   — t          d¦  «        }|                      t          d|¦  «         t          d¦  «        }|                      |j        ¦  «         dS )zB
        The I{-odf} flags specifies foreground delivery.
        r>   r(   z-odfN)r   r$   r)   r
   ÚassertFalserF   rG   s      r    Útest_foregroundDeliveryz$OptionsTests.test_foregroundDelivery†   sN   € õ ˜‘”ˆØ�
Š
•3˜ Ñ'Ô'Ð'Ý˜Ñ Ô ˆØ×Ò˜œÑ&Ô&Ð&Ð&Ð&r!   c                 óÊ   — t          d¦  «        }|                      t          d|¦  «         t          d¦  «        }|                      t          |j        ¦  «        d¦  «         dS )zd
        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   rG   s      r    Útest_recipientsFromHeadersz'OptionsTests.test_recipientsFromHeaders�   sa   € õ
 ð ñ
ô 
ˆð 	�
Š
•3˜ Ñ'Ô'Ð'Ý˜ÑÔˆØ×Ò�˜QœT™œ AÑ&Ô&Ð&Ð&Ð&r!   c                 ó´   — t          d¦  «        }|                      t          d|¦  «         t          g d¢¦  «        }|                      |j        d¦  «         dS )zw
        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>rN   rT   N©r   r$   r)   r
   r,   r   rG   s      r    Útest_setFromzOptionsTests.test_setFromŸ   s[   € õ
 ÐTÑUÔUˆØ�
Š
•3˜ Ñ'Ô'Ð'ÝÐIÐIÐIÑJÔJˆØ×Ò˜œÐ#EÑFÔFÐFÐFÐFr!   c                 ó´   — t          d¦  «        }|                      t          d|¦  «         t          g d¢¦  «        }|                      |j        d¦  «         dS )z‘
        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(   )rS   z"Groucho <invaliduser5@example.com>rN   zinvaliduser4@example.comNrU   rG   s      r    Ú!test_overrideFromFlagByFromHeaderz.OptionsTests.test_overrideFromFlagByFromHeader©   sc   € õ
 ð7ñ
ô 
ˆð 	�
Š
•3˜ Ñ'Ô'Ð'ÝÐKÐKÐKÑLÔLˆØ×Ò˜œÐ#=Ñ>Ô>Ð>Ð>Ð>r!   Úwin32zImailmail.run() does not work on win32 due to lack of support for getuid()c                 óÞ  — d}t          d¦  «        }|                      t          d|¦  «         |                      t          d|¦  «         t          j        ¦   «          |                      | j        j        t          j        ¦   «         ¦  «         |                      | j        j	        dg¦  «         |  
                    | j        j        ¦  «         |                      t          j        ¦  «         dS )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-oepr>   Úargvr(   r\   N)r   r$   r)   r	   Úrunr,   r   r   Úgetloginr   rE   ÚprintErrorsÚassertIsNoneÚfailed)r   r]   r(   s      r    Útest_runErrorsToStderrz#OptionsTests.test_runErrorsToStderr¶   sÁ   € ð HˆÝ˜‘”ˆØ�
Š
•3˜ Ñ%Ô%Ð%Ø�
Š
•3˜ Ñ'Ô'Ð'ÝŒ‰ŒˆØ×Ò˜œÔ,­hÔ.?Ñ.AÔ.AÑBÔBÐBØ×Ò˜œœÐ+EÐ*FÑGÔGÐGà�Š˜œÔ0Ñ1Ô1Ð1à×Ò�(œ/Ñ*Ô*Ð*Ð*Ð*r!   c                 ó  — t          d¦  «        }|                      t          d|¦  «         |                      ¦   «         }t	          j        ¦   «         }t	          j        ¦   «         }t          |d¦  «        5 }|                     d 	                    ||¦  «        ¦  «         ddd¦  «         n# 1 swxY w Y   |                      t          d|¦  «         d}|                      t          d|¦  «         t          j        ¦   «          |                      | j                             ¦   «         d	¦  «         |                      | j                             ¦   «         d
¦  «         |                      | j                             ¦   «         d¦  «         dS )z…
        Error messages for illegal UID value, illegal GID value, and illegal
        identity entry will be sent to stderr.
        r>   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_CFGr[   r]   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	   r^   ÚassertRegexr"   r@   )r   r(   ÚfilenameÚmyUidÚmyGidÚfr]   s          r    Útest_readInvalidConfigz#OptionsTests.test_readInvalidConfigÌ   s¦  € õ ˜‘”ˆØ�
Š
•3˜ Ñ'Ô'Ð'à—;’;‘=”=ˆÝ”	‘”ˆÝ”	‘”ˆå�(˜CÑ Ô ð 	 Aà�GŠGð/÷ 06ªv°e¸UÑ/CÔ/Cñô ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð2 	�
Š
•8˜[¨(Ñ3Ô3Ð3àGˆØ�
Š
•3˜ Ñ%Ô%Ð%ÝŒ‰ŒˆØ×ÒØŒH×ÒÑÔØFñ	
ô 	
ð 	
ð 	×ÒØŒH×ÒÑÔØFñ	
ô 	
ð 	
ð 	×ÒØŒH×ÒÑÔÐ!Qñ	
ô 	
ð 	
ð 	
ð 	
s   Á6*B,Â,B0Â3B0c                 óÆ   — ddl m} |                      ¦   «         }t          |d¦  «        5 }|                     |¦  «         ddd¦  «         n# 1 swxY w Y    ||¦  «        S )aª  
        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   )Ú
loadConfigre   N)Útwisted.mail.scripts.mailmailru   rg   rk   rl   )r   Úconfigru   ro   rr   s        r    ÚgetConfigFromFilezOptionsTests.getConfigFromFile  s¦   € ð 	=Ð<Ð<Ð<Ð<Ð<à—;’;‘=”=ˆå�(˜CÑ Ô ð 	 AØ�GŠG�F‰OŒOˆOð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð ˆz˜(Ñ#Ô#Ð#s   «AÁAÁAc                 óÈ  — |                       d¦  «        }|                      |j        d¦  «         |                       d¦  «        }|                      |j        d¦  «         |                       d¦  «        }|                      |j        d¦  «         |                      |j        d¦  «         |                       d¦  «        }|                      d|j        ¦  «         |                      |j        d         d	d
g¦  «         |                       d¦  «        }|                      |j        dg¦  «         |                       d¦  «        }|                      |j        ddg¦  «         |                       d¦  «        }|                      |j        ddg¦  «         |                      |j        ddg¦  «         |                       d¦  «        }|                      |j        dg¦  «         |                       d¦  «        }|                      |j	        dg¦  «         |                       d¦  «        }|                      |j        ddg¦  «         |                      |j	        ddg¦  «         dS )zj
        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)
rx   r,   Ú	smarthostÚdomainÚassertNotInÚ
identitiesÚ	allowUIDsÚdenyUIDsÚ	allowGIDsÚdenyGIDs)r   rw   s     r    Útest_loadConfigzOptionsTests.test_loadConfig  sž  € ð
 ×'Ò'ðñ
ô 
ˆð
 	×Ò˜Ô)¨;Ñ7Ô7Ð7à×'Ò'ðñ
ô 
ˆð
 	×Ò˜œ¨Ñ6Ô6Ð6à×'Ò'ðñ
ô 
ˆð 	×Ò˜Ô)¨;Ñ7Ô7Ð7Ø×Ò˜œ¨Ñ6Ô6Ð6à×'Ò'ðñ
ô 
ˆð 	×Ò˜ &Ô"3Ñ4Ô4Ð4Ø×Ò˜Ô*¨7Ô3°jÀ*Ð5MÑNÔNÐNà×'Ò'ðñ
ô 
ˆð 	×Ò˜Ô)¨B¨4Ñ0Ô0Ð0à×'Ò'ðñ
ô 
ˆð 	×Ò˜œ¨2¨r¨(Ñ3Ô3Ð3à×'Ò'ðñ
ô 
ˆð 	×Ò˜Ô)¨B°¨8Ñ4Ô4Ð4Ø×Ò˜œ¨2¨r¨(Ñ3Ô3Ð3à×'Ò'ðñ
ô 
ˆð 	×Ò˜Ô)¨B¨4Ñ0Ô0Ð0à×'Ò'ðñ
ô 
ˆð 	×Ò˜œ¨2¨$Ñ/Ô/Ð/à×'Ò'ðñ
ô 
ˆð 	×Ò˜Ô)¨B°¨8Ñ4Ô4Ð4Ø×Ò˜œ¨2¨r¨(Ñ3Ô3Ð3Ð3Ð3r!   c                 óÞ   ‡ — ˆ fd„}‰                       t          d|¦  «         t          j        ¦   «         }d|_        t          t          ¦   «         ¦  «        }t          j        ||¦  «         dS )zš
        L{twisted.mail.scripts.mailmail.senderror} sends mail back to the
        sender if an error occurs while sending mail to the recipient.
        c                 óÊ   •— ‰                      |d¦  «         ‰                     |dg¦  «         ‰                      |                     ¦   «         d¦  «         t          ¦   «         S )Nzpostmaster@Ú
testsenderÚ
ValueError)rn   r,   r@   r   )r   r   Ú	recipientr   r   s       €r    r   z-OptionsTests.test_senderror.<locals>.sendmail}  sY   ø€ Ø×Ò˜V ]Ñ3Ô3Ð3Ø×Ò˜Y¨¨Ñ7Ô7Ð7Ø×Ò˜TŸ]š]™_œ_¨lÑ;Ô;Ð;Ý‘:”:Ðr!   r   r’   N)r$   r   r	   ÚOptionsr   r   r“   Ú	senderror)r   r   ÚoptsÚfails   `   r    Útest_senderrorzOptionsTests.test_senderrorw  ss   ø€ ð	ð 	ð 	ð 	ð 	ð 	�
Š
•4˜ XÑ.Ô.Ð.ÝÔÑ!Ô!ˆØ"ˆŒÝ•z‘|”|Ñ$Ô$ˆÝÔ˜4 Ñ&Ô&Ð&Ð&Ð&r!   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r&   r0   r4   r6   r9   r;   rC   rI   rL   rQ   rV   rX   r   r   rc   rs   rx   r�   r™   © r!   r    r   r      s„  € € € € € ðð ð "�M‘O”O€Mð3ð 3ð 3ð<Bð Bð Bð=ð =ð =ð=ð =ð =ð	=ð 	=ð 	=ð=ð =ð =ðAð Að Að&ð &ð &ð'ð 'ð 'ð'ð 'ð 'ð Gð Gð Gð?ð ?ð ?ð €VØ˜ÒØVñô ð+ð +ñ	ô ð+ð$ €VØ˜ÒØVñô ð4
ð 4
ñ	ô ð4
ðl$ð $ð $ð0W4ð W4ð W4ðr'ð 'ð 'ð 'ð 'r!   r   )r�   rh   r)   Úior   Úunittestr   Útwisted.copyrightr   Útwisted.internet.deferr   Útwisted.internet.testingr   Útwisted.mailr   Útwisted.mail.scriptsr	   rv   r
   Útwisted.python.failurer   Útwisted.python.runtimer   Útwisted.trial.unittestr   r   rž   r!   r    ú<module>r©      s'  ðð
ð ð
 
€	€	€	Ø 
€
€
€
Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à %Ð %Ð %Ð %Ð %Ð %Ø +Ð +Ð +Ð +Ð +Ð +Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø *Ð *Ð *Ð *Ð *Ð *Ø /Ð /Ð /Ð /Ð /Ð /Ø +Ð +Ð +Ð +Ð +Ð +ðm'ð m'ð m'ð m'ð m'�8ñ m'ô m'ð m'ð m'ð m'r!   