a  ze/@sddlZddlZddlZddlmZmZddlmZddlm Z m Z ddl m Z ddlm Z ddlmZmZeGdd d ZGd d d eeZGd d d eeZedkredS)N)message_from_stringmessage_from_bytes) EmailMessage) GeneratorBytesGenerator)Addresspolicy) TestEmailBase parameterizec@seZdZejZd$ddZedededdZeded <e Z d e d<d e d <d d eDZ ddZ ddZ ddZddZddZddZddZddZddZd d!Zd"d#ZdS)%TestGeneratorBaseNcCs |dur|jn|}|j||dS)Nr)r msgfunc)selfmsgr rR/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_email/test_generator.pymsgmakerszTestGeneratorBase.msgmakeraf To: whom_it_may_concern@example.com From: nobody_you_want_to_know@example.com Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing. None a To: whom_it_may_concern@example.com From: nobody_you_want_to_know@example.com Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing. None a To: whom_it_may_concern@example.com From: nobody_you_want_to_know@example.com Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing. None )r(rdaTo: whom_it_may_concern@example.com From: nobody_you_want_to_know@example.com Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing. None aTo: whom_it_may_concern@example.com From: nobody_you_want_to_know@example.com Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing. None cCsg|]}|qSrr).0nrrr UzTestGeneratorBase.cCsZ|||jd}|}|j|||jd}||||||j|dS)NrZ maxheaderlenr ) rtyprefold_long_expectedioclassgenclassr flatten assertEqualgetvaluerrrsgrrr length_as_maxheaderlen_parameterWs  z2TestGeneratorBase.length_as_maxheaderlen_parametercCs`|||jd}|}|j||jj|dd}|||| ||j|dSNrmax_line_lengthr rrrrrr clonerr r!r"rrr length_as_max_line_length_policy^s  z2TestGeneratorBase.length_as_max_line_length_policycCsb|||jd}|}|j|||jjddd}|||| ||j|dS)Nr r'rr)r"rrr,length_as_maxheaderlen_parm_overrides_policyes  z>TestGeneratorBase.length_as_maxheaderlen_parm_overrides_policycCsb|||jd}|}|j||jjd|dd}|||| ||jddS)NrZnoneZ refold_sourcer(rr)r"rrr8length_as_max_line_length_with_refold_none_does_not_foldms  zJTestGeneratorBase.length_as_max_line_length_with_refold_none_does_not_foldcCsb|||jd}|}|j||jjd|dd}|||| ||j |dS)Nrallr.r) rrrrrr r*rr r!refold_all_expectedr"rrr/length_as_max_line_length_with_refold_all_foldsus  zATestGeneratorBase.length_as_max_line_length_with_refold_all_foldscCsTd}|}|||}|}|j|tjd}||||||dS)NzSubject: test test body r rrrrr SMTPrr r!rsourceexpectedrr#r$rrrtest_crlf_control_via_policy}s z.TestGeneratorBase.test_crlf_control_via_policycCsXd}|}|||}|}|j|tjd}|j|dd||||dS)NzSubject: test test body r )linesepr3r5rrr%test_flatten_linesep_overrides_policysz7TestGeneratorBase.test_flatten_linesep_overrides_policyc Cstd}dtjdftjdftjjdddff}|D]\}}|rL|ddn|}|j||dV|| |}| }|j ||d }| || || |Wdq41s0Yq4dS) Nz Subject: test that from is mangled in the body! From time to time I write a rhyme. )NTTF) mangle_from_zFrom z>From )r r<r)textwrapdedentr compat32defaultr*replaceZsubTestrrrrrr r!) rr6ZvariantspZmangler7rr#r$rrrtest_set_mangle_from_via_policys   z1TestGeneratorBase.test_set_mangle_from_via_policycCs`|||jd}|}|j|tjjddd}||| | ||jddSr&) rrrrrr r?r*rr r!)rrr#r$rrr5test_compat32_max_line_length_does_not_fold_when_nones  zGTestGeneratorBase.test_compat32_max_line_length_does_not_fold_when_nonecCsd||td}td}|}|j||jjddd}||| | ||dS)N To: nobody Content-Disposition: attachment; filename="afilenamelongenoghtowraphere" None z To: nobody Content-Disposition: attachment; filename*0*=us-ascii''afilename; filename*1*=longenoghtowraphere None !r'r rrr=r>rrr r*rr r!rrr7r#r$rrrtest_rfc2231_wrappings   z'TestGeneratorBase.test_rfc2231_wrappingcCsd||td}td}|}|j||jjddd}||| | ||dS)NrEz To: nobody Content-Disposition: attachment; filename*0*=us-ascii''afilenamelongenoghtowraphere None rr'rrGrHrrr;test_rfc2231_wrapping_switches_to_default_len_if_too_narrows   zMTestGeneratorBase.test_rfc2231_wrapping_switches_to_default_len_if_too_narrow)N)__name__ __module__ __qualname__r r@rr=r>rcopyr1Z length_paramsr%r+r-r/r2r8r;rCrDrIrJrrrrr s0   *     r c@s"eZdZeeZeZej Z e Z dS) TestGeneratorN) rKrLrM staticmethodrr rrioStringIOrstrrrrrrrOsrOc@sFeZdZeeZeZej Z ddZ ddZ ddZ ddZd d Zd S) TestBytesGeneratorcCs |dS)Nascii)encode)rxrrrrzTestBytesGenerator.cCsXdd}dd}t|}t}t||jjddd}|||| |dS)Nu5Subject: Maintenant je vous présente mon collègue utf-8zPSubject: Maintenant je vous =?unknown-8bit?q?pr=C3=A9sente_mon_coll=C3=A8gue?= rU7bit)cte_typer) rVrrQBytesIOrr r*rr r!r5rrr'test_cte_type_7bit_handles_unknown_8bits z:TestBytesGenerator.test_cte_type_7bit_handles_unknown_8bitcCsftdd}t|}tdd}t}t||jjdddd}| || | |dS) Nu/ From: foo@bar.com To: Dinsdale Subject: Nudge nudge, wink, wink Mime-Version: 1.0 Content-Type: text/plain; charset="latin-1" Content-Transfer-Encoding: 8bit oh là là, know what I mean, know what I mean? latin1a@ From: foo@bar.com To: Dinsdale Subject: Nudge nudge, wink, wink Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable oh l=E0 l=E0, know what I mean, know what I mean? rUrZr9)r[r:r) r=r>rVrrQr\rr r*rr r!)rr6rr7r#r$rrr&test_cte_type_7bit_transforms_8bit_ctes       z9TestBytesGenerator.test_cte_type_7bit_transforms_8bit_ctecCstt}d|d<d|d<d|d<|dtdd d d }t}t|t j d }| || | |dS) NuPáolo FromDinsdaleTouNudge nudge, wink, wink ὠ9Subjectu/oh là là, know what I mean, know what I mean?u< From: Páolo To: Dinsdale Subject: Nudge nudge, wink, wink ὠ9 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit MIME-Version: 1.0 oh là là, know what I mean, know what I mean? rY  r)r set_contentr=r>rVrArQr\rr ZSMTPUTF8rr r!rHrrrtest_smtputf8_policys     z'TestBytesGenerator.test_smtputf8_policycCst}tddd|d<tddd|d<d|d <|d td d d }t}t |t j d}| || ||dS)Nz foo@bar.comuPáolo)Z addr_specZ display_namer`z bar@foo.comrarbzNudge nudge, wink, winkrcz+oh boy, know what I mean, know what I mean?aP From: =?utf-8?q?P=C3=A1olo?= To: Dinsdale Subject: Nudge nudge, wink, wink Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 oh boy, know what I mean, know what I mean? rdrer)rrrfr=r>rVrArQr\rr r4rr r!rHrrrtest_smtp_policy's    z#TestBytesGenerator.test_smtp_policyN)rKrLrMrPrr rrrQr\rrr]r_rgrhrrrrrTs rT__main__)rQr=ZunittestZemailrrZ email.messagerZemail.generatorrrZemail.headerregistryrr Ztest.test_emailr r r rOrTrKmainrrrrs   PY