a 8êdg/ã@s¶ddlZddlZddlZddlmZmZddlmZddlm Z m Z ddl m Z ddlm Z ddlmZmZeGdd „d ƒƒZGd d „d eeƒZGd d „d eeƒZedkr²e ¡dS)éN)Úmessage_from_stringÚmessage_from_bytes)Ú EmailMessage)Ú GeneratorÚBytesGenerator)ÚAddress©Úpolicy)Ú TestEmailBaseÚ parameterizec@sÄeZdZejZd$dd„Ze d¡e d¡e d¡dœZeded <e  ¡Z d e d<d e d <d d „eDƒZ dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„ZdS)%ÚTestGeneratorBaseNcCs |dur|jn|}|j||dS)Nr)r Úmsgfunc)ÚselfÚmsgr ©rú:/usr/local/lib/python3.9/test/test_email/test_generator.pyÚmsgmakerszTestGeneratorBase.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é(érédaTo: 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)Ú.0ÚnrrrÚ UózTestGeneratorBase.cCsZ| | |jd¡¡}| ¡}|j|||jd}| |¡| | ¡| |j|¡¡dS)Nr©Z maxheaderlenr ) rÚtypÚrefold_long_expectedÚioclassÚgenclassr ÚflattenÚ assertEqualÚgetvalue©rrrÚsÚgrrrÚ length_as_maxheaderlen_parameterWs  z2TestGeneratorBase.length_as_maxheaderlen_parametercCs`| | |jd¡¡}| ¡}|j||jj|dd}| |¡| |  ¡| |j|¡¡dS©Nr©Úmax_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}| |¡| |  ¡| |jd¡¡dS)NrZnone©Z refold_sourcer(rr)r"rrrÚ8length_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)NrÚallr.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!©rÚsourceÚexpectedrr#r$rrrÚtest_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_policy†sz7TestGeneratorBase.test_flatten_linesep_overrides_policyc CsÊt d¡}dtjdftjdftjjdddff}|D]\}}|rL| dd¡n|}|j||dV| |  |¡¡}|  ¡}|j ||d }|  |¡|  | ¡|  |¡¡Wdƒq41sº0Yq4dS) 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)ÚtextwrapÚdedentr Úcompat32Údefaultr*ÚreplaceZsubTestrrrrrr r!) rr6ZvariantsÚpZmangler7rr#r$rrrÚtest_set_mangle_from_via_policys ü  z1TestGeneratorBase.test_set_mangle_from_via_policycCs`| | |jd¡¡}| ¡}|j|tjjddd}| |¡|  |  ¡| |jd¡¡dSr&) rrrrrr r?r*rr r!)rrr#r$rrrÚ5test_compat32_max_line_length_does_not_fold_when_none¥s  zGTestGeneratorBase.test_compat32_max_line_length_does_not_fold_when_nonecCsd| | t d¡¡¡}t d¡}| ¡}|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$rrrÚtest_rfc2231_wrapping¬s   z'TestGeneratorBase.test_rfc2231_wrappingcCsd| | t d¡¡¡}t d¡}| ¡}|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_narrowÃs   zMTestGeneratorBase.test_rfc2231_wrapping_switches_to_default_len_if_too_narrow)N)Ú__name__Ú __module__Ú __qualname__r r@rr=r>rÚcopyr1Z length_paramsr%r+r-r/r2r8r;rCrDrIrJrrrrr s0   ê* ÿ ÿ   r c@s"eZdZeeƒZeZej Z e Z dS)Ú TestGeneratorN) rKrLrMÚ staticmethodrr rrÚioÚStringIOrÚstrrrrrrrOÜsrOc@sFeZdZeeƒZeZej Z dd„Z dd„Z dd„Z dd„Zd d „Zd S) ÚTestBytesGeneratorcCs | d¡S)NÚascii)Úencode)rÚxrrrÚérzTestBytesGenerator.cCsXd d¡}d d¡}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?= rUÚ7bit)Úcte_typer) rVrrQÚBytesIOrr r*rr r!r5rrrÚ'test_cte_type_7bit_handles_unknown_8bitësÿÿ z:TestBytesGenerator.test_cte_type_7bit_handles_unknown_8bitcCsft d¡ d¡}t|ƒ}t d¡ d¡}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_cteös ÷  ÷  ÿ  z9TestBytesGenerator.test_cte_type_7bit_transforms_8bit_ctecCsttƒ}d|d<d|d<d|d<| d¡t d¡ d ¡ d d ¡}t ¡}t|t j d }|  |¡|  |  ¡|¡dS) NuPáolo ÚFromÚDinsdaleÚTouNudge nudge, wink, wink á½ 9ÚSubjectu/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!rHrrrÚtest_smtputf8_policys  ÷ ÷  z'TestBytesGenerator.test_smtputf8_policycCs‚tƒ}tddd|d<tddd|d<d|d <| d ¡t d ¡ ¡ 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!rHrrrÚtest_smtp_policy's  ÷  z#TestBytesGenerator.test_smtp_policyN)rKrLrMrPrr rrrQr\rrr]r_rgrhrrrrrTäs rTÚ__main__)rQr=ZunittestZemailrrZ email.messagerZemail.generatorrrZemail.headerregistryrr Ztest.test_emailr r r rOrTrKÚmainrrrrÚs   PY