a 8êdgwƒã@s¢ddlZddlZddlmZmZddlmZmZddlm Z m Z dd„Z Gdd„de ƒZ e Gd d „d ƒƒZ Gd d „d e e ƒZGd d„de e ƒZedkrže ¡dS)éN)ÚpolicyÚmessage_from_string)Ú EmailMessageÚMIMEPart)Ú TestEmailBaseÚ parameterizecCsttdd„|ƒdƒS)NcSs|duS©N©)Úxr r ú8/usr/local/lib/python3.9/test/test_email/test_message.pyÚ ózfirst..)ÚnextÚfilter)Úiterabler r r Úfirst src@s"eZdZejZdd„Zdd„ZdS)ÚTestcCsH| d¡}d|d<| t¡d|d<Wdƒn1s:0YdS)NÚzabc@xyzÚTozxyz@abc)Ú_str_msgÚ assertRaisesÚ ValueError©ÚselfÚmr r r Ú+test_error_on_setitem_if_max_count_exceededs  z0Test.test_error_on_setitem_if_max_count_exceededcCsDtt d¡tjd}| |dd¡| |dd¡| |t¡dS)Na> Subject: Ayons asperges pour le =?utf-8?q?d=C3=A9jeuner?= From: =?utf-8?q?Pep=C3=A9?= Le Pew To: "Penelope Pussycat" <"penelope@example.com"> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" sample text ©rZsubjectu Ayons asperges pour le déjeunerÚfromuPepé Le Pew )rÚtextwrapÚdedentrÚdefaultÚ assertEqualZassertIsInstancerrr r r Ú/test_rfc2043_auto_decoded_and_emailmessage_useds  ø z4Test.test_rfc2043_auto_decoded_and_emailmessage_usedN)Ú__name__Ú __module__Ú __qualname__rr rr"r r r r r src@sÀeZdZejZdddde d¡fddde d¡fddde d ¡fddde d ¡fd d de d ¡fddde d¡fddde d¡fdd de d¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fd d de d¡fd œZd!d"„Zd#d$„Z d%d&„Z Gd'd(„d(ƒZ d)d*„Z d+d,„Z d-d.„Zd/d0„Zd1Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Zdd?„d?ƒZd@dA„ZGdBdC„dCƒZdDdE„ZdFdG„ZdHdI„ZdJdK„ZdLdM„ZdNS)OÚTestEmailMessageBase)©NNrr r rr'r zV To: foo@example.com simple text body )NNNz› To: foo@example.com MIME-Version: 1.0 Content-Type: image/jpg bogus body. )Néé)r)r(aŒ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="===" preamble --=== Content-Type: text/plain simple body --=== Content-Type: text/html

simple body

--===-- a‡ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" preamble --=== Content-Type: text/plain simple body --=== Content-Type: text/html

simple body

--===-- )NNr))r(a To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: text/plain simple body --=== Content-Type: text/html Content-Disposition: attachment

simple body

--===-- )Nr(N)r)a To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: text/plain Content-Disposition: AtTaChment simple body --=== Content-Type: text/html

simple body

--===-- aÅ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: text/plain Content-Disposition: InLine simple body --=== Content-Type: text/html Content-Disposition: inline

simple body

--===-- )rr)Na¢ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/related; boundary="==="; type=text/html --=== Content-Type: text/html

simple body

--=== Content-Type: image/jpg Content-ID: bogus data --===-- )rr(Na To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/related; boundary="==="; type=text/html; start="" --=== Content-Type: text/html Content-ID: useless text --=== Content-Type: text/html Content-ID:

simple body

--===-- )éér()éé)r)r,r-aÿ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: multipart/alternative; boundary="+++" --+++ Content-Type: text/plain simple body --+++ Content-Type: multipart/related; boundary="___" --___ Content-Type: text/html

simple body

--___ Content-Type: image/jpg Content-ID: bogus jpg body --___-- --+++-- --=== Content-Type: image/jpg Content-Disposition: attachment bogus jpg body --=== Content-Type: image/jpg Content-Disposition: AttacHmenT another bogus jpg body --===-- )r)r+r*aÿ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: multipart/related; boundary="+++" --+++ Content-Type: multipart/alternative; boundary="___" --___ Content-Type: text/plain simple body --___ Content-Type: text/html

simple body

--___-- --+++ Content-Type: image/jpg Content-ID: bogus jpg body --+++-- --=== Content-Type: image/jpg Content-Disposition: attachment bogus jpg body --=== Content-Type: image/jpg Content-Disposition: attachment another bogus jpg body --===-- )r)NNaÿ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: multipart/related; boundary="+++" --+++ Content-Type: image/jpg Content-ID: bogus jpg body --+++ Content-Type: multipart/alternative; boundary="___" --___ Content-Type: text/plain simple body --___ Content-Type: text/html

simple body

--___-- --+++-- --=== Content-Type: image/jpg Content-Disposition: attachment bogus jpg body --=== Content-Type: image/jpg Content-Disposition: attachment another bogus jpg body --===-- z÷ To: foo@example.com MIME-Version: 1.0 Content-Type: message/rfc822 To: bar@example.com From: robot@examp.com this is a message body. aÕ To: foo@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===" --=== Content-Type: text/plain Your message has bounced, ser. --=== Content-Type: message/rfc822 To: bar@example.com From: robot@examp.com this is a message body. --===-- )Z empty_messageZnon_mime_plainZ mime_non_textZplain_html_alternativeZplain_html_mixedZplain_html_attachment_mixedZhtml_text_attachment_mixedZ!html_text_attachment_inline_mixedÚrelatedZrelated_with_startZmixed_alternative_plain_relatedZ$mixed_related_alternative_plain_htmlZ0mixed_related_alternative_plain_html_wrong_orderZmessage_rfc822Zmixed_text_message_rfc822c sÖ| |¡}t| ¡ƒ‰‡fdd„|Dƒ}d}d}d} | | ¡t|ƒ¡| |jddt|ƒ¡| |jddt|||d…ƒ¡| |jd dt|||| gƒ¡| |jd dt||| d…ƒ¡| |jd gd||¡| |jd gd||¡| |jd gd|| ¡| |jddt|| |dd…ƒ¡| |jddt|| ||gƒ¡| |jddt||dd…ƒ¡| |jddt|ddd…ƒ¡| |jddt|||| ||gƒ¡dS)Ncs g|]}|durdnˆ|‘qSrr ©Ú.0Ún©Zallpartsr r Ú Ær z.rr)r()r.ÚhtmlÚplain)Zpreferencelist)r.r4)r.r5)r4r5r.r4r5)r5r4éÿÿÿÿ)r5r.)r4r.)r5r4r.)r4r5r.)rÚlistÚwalkr!Zget_bodyr) rÚ body_partsÚ attachmentsÚpartsÚmsgrZexpectedr.r4r5r r2r Úmessage_as_get_bodyÃsP   þÿÿÿÿÿÿÿÿþÿz(TestEmailMessageBase.message_as_get_bodycs@| |¡}t| ¡ƒ‰‡fdd„|Dƒ}| t| ¡ƒ|¡dS)Ncsg|] }ˆ|‘qSr r r/r2r r r3ær zCTestEmailMessageBase.message_as_iter_attachment..)rr7r8r!Úiter_attachments©rr9r:r;r<rr r2r Úmessage_as_iter_attachmentãs  z/TestEmailMessageBase.message_as_iter_attachmentcs@| |¡}t| ¡ƒ‰‡fdd„|Dƒ}| t| ¡ƒ|¡dS)Ncsg|] }ˆ|‘qSr r r/r2r r r3ìr z>TestEmailMessageBase.message_as_iter_parts..)rr7r8r!Ú iter_partsr?r r2r Úmessage_as_iter_partsés  z*TestEmailMessageBase.message_as_iter_partsc@seZdZdd„Zdd„ZdS)z(TestEmailMessageBase._TestContentManagercOs |||fSrr ©rr<ÚargsÚkwr r r Ú get_contentðsz4TestEmailMessageBase._TestContentManager.get_contentcOs||_||_||_dSr)r<rDrErCr r r Ú set_contentòsz4TestEmailMessageBase._TestContentManager.set_contentN)r#r$r%rFrGr r r r Ú_TestContentManagerïsrHcCst| d¡}| ¡}| |j|d|dif¡|jd|ddd\}}}| ||¡| |d¡| |tddd ¡dS© Nr©Úcontent_managerr Úfoor)r()rKÚbarÚk©rL©rMrN)rrHr!rFÚdict)rrÚcmr<rDrEr r r Útest_get_content_with_cm÷s   z-TestEmailMessageBase.test_get_content_with_cmcCs|tjj| ¡d}|jd|d}| | ¡|dif¡|jdddd\}}}| ||¡| |d ¡| |tddd¡dS© NrJrrr rLr)r(rPrO)rr ÚclonerHrr!rFrQ)rÚprr<rDrEr r r Ú-test_get_content_default_cm_comes_from_policys  zBTestEmailMessageBase.test_get_content_default_cm_comes_from_policycCs| d¡}| ¡}|j|d| |j|¡| |jd¡| |ji¡|jd|ddd| |j|¡| |jd¡| |jtddd ¡dSrI)rrHrGr!r<rDrErQ©rrrRr r r Útest_set_content_with_cm s  z-TestEmailMessageBase.test_set_content_with_cmcCsœ| ¡}tjj|d}|jd|d}| ¡| |j|¡| |jd¡| |j i¡|jdddd| |j|¡| |jd ¡| |j t ddd¡dSrT) rHrr rUrrGr!r<rDrErQ)rrRrVrr r r Ú-test_set_content_default_cm_comes_from_policyszBTestEmailMessageBase.test_set_content_default_cm_comes_from_policy))r.Ú no_contentÚsucceeds)r.Únoner\)r.r5r\)r.r.r)r.Ú alternativeÚraises)r.Úmixedr_)r^r[r\)r^r]r\)r^r5r\)r^r.r\)r^r^r)r^r`r_)r`r[r\)r`r]r\)r`r5r\)r`r.r\)r`r^r\)r`r`rcCsš| ¡}d}ddg}|dkr| d¡|dkrHd}| d¡| d¡n|dkrfg}| dd |f¡| d ¡| |¡|D]\}}|||<q~|||fS) N)rz foo@bar.com)ZFromz bar@foo.comr[)zX-Random-HeaderZCorwinÚtextr)ú Content-Typeú text/plainrbú multipart/)zX-TrumpÚRandom)ÚmessageÚappendÚ set_payload)rÚsubtyperÚpayloadÚ msg_headersÚnameÚvaluer r r Ú_make_subtype_test_message=s&þ       z/TestEmailMessageBase._make_subtype_test_messagecCs\| t¡}t||ƒƒWdƒn1s,0Yt|jƒ}| ||¡| ||¡dSr)rrÚgetattrÚstrÚ exceptionZassertIn)rrZ method_nameriÚmethodÚarÚexc_textr r r Ú _check_disallowed_subtype_raisesTs  *  z5TestEmailMessageBase._check_disallowed_subtype_raisescCs´d}|D].\}}| ¡ d¡s| |||¡|d7}q| t|ƒ|d¡t| ¡ƒ}d}|D].\}}| ¡ d¡r`| |||¡|d7}q`| t|ƒ|¡| | ¡|¡dS)Nrúcontent-r))ÚlowerÚ startswithr!ÚlenrrAÚ get_payload)rrrkrjÚcountrlrmÚpartr r r Ú_check_make_multipart[s     z*TestEmailMessageBase._check_make_multipartcCsÂ| |¡\}}}d|}|dvr4| ||||¡dSt||ƒƒ| | ¡d¡| | ¡|¡|dkrœ| t| ¡ƒd¡| | ¡|dd|fg¡n"| t| ¡ƒd¡|  |||¡dS) NÚmake_©rr_Ú multipartr[rrbrdr)) rnruror!Úget_content_maintypeÚget_content_subtyperyrzÚitemsr})rrrriÚoutcomerrkrjZ make_methodr r r Úsubtype_as_makeks"  ÿÿz$TestEmailMessageBase.subtype_as_makecCs¶| ¡}|dvrZd||d<| t¡ }t|d|ƒƒWdƒn1sL0YdS|dkrld|d<n|dkr€d||d<t|d|ƒdd | | ¡¡| | ¡d¡dS) Nrrdrbr~r5rcr[Úabc)Úboundary)rfrrroÚ assertTrueZ is_multipartr!Z get_boundary)rrrrir„rrRr r r Úsubtype_as_make_with_boundary}s  .  z2TestEmailMessageBase.subtype_as_make_with_boundarycCsNdD]D}|j|jjddd}d|d<t||ƒƒ| | d¡jjd¡qdS)N)Z make_relatedZmake_alternativeZ make_mixedrLrJrrcrbr)rfrrUror!rzrK)rrrrr r r Ú3test_policy_on_part_made_by_make_comes_from_messages  zHTestEmailMessageBase.test_policy_on_part_made_by_make_comes_from_messagec@seZdZdd„ZdS)z+TestEmailMessageBase._TestSetContentManagercOsd|d<| |¡dS)Nrcrb)rh©rr<ZcontentrDrEr r r rG•sz7TestEmailMessageBase._TestSetContentManager.set_contentN©r#r$r%rGr r r r Ú_TestSetContentManager”src Csb| |¡\}}}| ¡}|dkr$dnd|}|dkrH| ||||¡dSt||ƒd|d| | ¡d¡| | ¡|¡||ksŠ|dkrÊ| t| ¡ƒd ¡|D]\} } | || | ¡q¢| ¡d } n.| t| ¡ƒd ¡|  |||¡| ¡d } | |   ¡d ¡| |  ¡d¡|dkr4| | d d¡n*|dkrP| | d d¡n|  | d ¡dS)Nr`Úadd_attachmentZadd_r_ÚtestrJr€r[r)rr(rcúContent-DispositionÚ attachmentr.Úinline) rnrruror!rr‚ryrzr}Zget_content_typeÚ assertIsNone) rrrrir„rrkrjrRZ add_methodrlrmr|r r r Úsubtype_as_add™s0    z#TestEmailMessageBase.subtype_as_addc@seZdZdd„ZdS)z2TestEmailMessageBase._TestSetRaisingContentManagercOs tdƒ‚dS)Nr)Ú Exceptionr‹r r r rG·sz>TestEmailMessageBase._TestSetRaisingContentManager.set_contentNrŒr r r r Ú_TestSetRaisingContentManager¶sr–c Csv| ¡}|j|jj|dd}dD]N}| t¡}t||ƒdƒWdƒn1sT0Y| t|j ƒd¡q"dS)NrJr)Ú add_relatedZadd_alternativerŽrr) r–rfrrUrr•ror!rprq)rrRrrrrsr r r Ú6test_default_content_manager_for_add_comes_from_policyºs  ,zKTestEmailMessageBase.test_default_content_manager_for_add_comes_from_policycCs\| |¡}| ¡| t|ƒd¡| t| ¡ƒg¡| | ¡¡| t| ¡ƒg¡dS)Nr) rÚclearr!ryr7rƒr“rzrAr?r r r Úmessage_as_clearÂs  z%TestEmailMessageBase.message_as_clearcCs^| |¡}dd„| ¡Dƒ}| ¡| t| ¡ƒ|¡| | ¡¡| t| ¡ƒg¡dS)NcSsg|]}| ¡ d¡s|‘qS)rv)rwrx)r0Úhr r r r3ÌsÿzATestEmailMessageBase.message_as_clear_content..)rÚkeysZ clear_contentr!r7r“rzrA)rr9r:r;r<rZexpected_headersr r r Úmessage_as_clear_contentÊs  z-TestEmailMessageBase.message_as_clear_contentcCs€| ¡}| | ¡¡d|d<| | ¡¡| dd¡| | ¡¡| dd¡| | ¡¡| ddd¡| | ¡¡dS)Nr’rr‘Z AtTachMentÚfilenamezabc.png)Ú _make_messageZ assertFalseZ is_attachmentZreplace_headerrˆZ set_paramrr r r Útest_is_attachmentÓs  z'TestEmailMessageBase.test_is_attachmentcCs^| ¡}| d¡| d¡| d¡| ¡ ¡}| tt| ¡ƒƒd¡| | ¡|¡dS)Nzarbitrary text as main partzmore text as a related partz&yet more text as a second "attachment"r() rŸrGr—rzÚcopyr!ryr7r>)rrZorigr r r Útest_iter_attachments_mutationßs    z3TestEmailMessageBase.test_iter_attachments_mutationN)r#r$r%rr rrZmessage_paramsr=r@rBrHrSrWrYrZZsubtype_paramsrnrur}r…r‰rŠrr”r–r˜ršrr r¢r r r r r&&sÊü ü üüüüüüüü5ü6ü3üü€€      r&c@s–eZdZeZdd„ZGdd„dƒZdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!S)"ÚTestEmailMessagecCs>| d¡}| ¡}| d|¡|j|d| |dd¡dS©Nrú MIME-VersionrJú1.0)rrHÚ assertNotInrGr!rXr r r Ú"test_set_content_adds_MIME_Versionís    z3TestEmailMessage.test_set_content_adds_MIME_Versionc@seZdZdd„ZdS)z(TestEmailMessage._MIME_Version_adding_CMcOs d|d<dS)Nr¦r¥r rCr r r rGõsz4TestEmailMessage._MIME_Version_adding_CM.set_contentNrŒr r r r Ú_MIME_Version_adding_CMôsr©cCs>| d¡}| ¡}| d|¡|j|d| |dd¡dSr¤)rr©r§rGr!rXr r r Ú0test_set_content_does_not_duplicate_MIME_Versionøs    zATestEmailMessage.test_set_content_does_not_duplicate_MIME_VersioncCs*| d¡}| t| ¡ ¡ ¡ƒd¡dS©NúªSubject: long line ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab r*©rr!ryÚ as_stringÚstripÚ splitlinesrr r r Ú0test_as_string_uses_max_header_length_by_defaultÿs zATestEmailMessage.test_as_string_uses_max_header_length_by_defaultcCsN| d¡}| t|jdd ¡ ¡ƒd¡| t|jdd ¡ ¡ƒd¡dS)Nr¬r)Z maxheaderlenr)é"r,r­rr r r Ú"test_as_string_allows_maxheaderlens ÿÿz3TestEmailMessage.test_as_string_allows_maxheaderlencCs@| d¡}| d¡| |jddd¡| |jddd¡dS)Nrz%From foo@bar Thu Jan 1 00:00:00 1970T)Zunixfromz+From foo@bar Thu Jan 1 00:00:00 1970 testFz test)rZ set_unixfromr!r®rr r r Útest_as_string_unixform s   ÿz(TestEmailMessage.test_as_string_unixformcCs*| d¡}| tt|ƒ ¡ ¡ƒd¡dSr«)rr!ryrpr¯r°rr r r Ú+test_str_defaults_to_policy_max_line_lengths zr!r7)rr<r:r r r Ú/test_string_payload_with_multipart_content_type«s  üzs$H5