a
    åzePˆ  ã                   @   s¢   d dl Z d dlZd dlmZmZ d dlmZmZ d dlm	Z	m
Z
 dd„ ZG dd„ de	ƒZe
G d	d
„ d
ƒƒZG dd„ dee	ƒZG dd„ dee	ƒZedkrže  ¡  dS )é    N)ÚpolicyÚmessage_from_string)ÚEmailMessageÚMIMEPart)ÚTestEmailBaseÚparameterizec                 C   s   t tdd„ | ƒd ƒS )Nc                 S   s   | d uS ©N© )Úxr	   r	   ú2/usr/lib/python3.9/test/test_email/test_message.pyÚ<lambda>
   ó    zfirst.<locals>.<lambda>)ÚnextÚfilter)Úiterabler	   r	   r   Úfirst	   s    r   c                   @   s"   e Zd ZejZdd„ Zdd„ ZdS )ÚTestc                 C   sH   |   d¡}d|d< |  t¡ d|d< W d   ƒ n1 s:0    Y  d S )NÚ zabc@xyzÚTozxyz@abc)Ú_str_msgÚassertRaisesÚ
ValueError©ÚselfÚmr	   r	   r   Ú+test_error_on_setitem_if_max_count_exceeded   s    
z0Test.test_error_on_setitem_if_max_count_exceededc                 C   sD   t t d¡tjd}|  |d d¡ |  |d d¡ |  |t¡ d S )Na>              Subject: Ayons asperges pour le =?utf-8?q?d=C3=A9jeuner?=
            From: =?utf-8?q?Pep=C3=A9?= Le Pew <pepe@example.com>
            To: "Penelope Pussycat" <"penelope@example.com">
            MIME-Version: 1.0
            Content-Type: text/plain; charset="utf-8"

            sample text
            ©r   Zsubjectu    Ayons asperges pour le dÃ©jeunerÚfromu   PepÃ© Le Pew <pepe@example.com>)r   ÚtextwrapÚdedentr   ÚdefaultÚassertEqualZassertIsInstancer   r   r	   r	   r   Ú/test_rfc2043_auto_decoded_and_emailmessage_used   s    
ø	z4Test.test_rfc2043_auto_decoded_and_emailmessage_usedN)Ú__name__Ú
__module__Ú__qualname__r   r    r   r"   r	   r	   r	   r   r      s   r   c                   @   sÀ  e Zd ZejZdddde d¡fddde d¡fddde d	¡fddde d
¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fddde d¡fd œZd!d"„ Zd#d$„ Z	d%d&„ Z
G d'd(„ d(ƒZd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ ZG d>d?„ d?ƒZd@dA„ ZG dBdC„ dCƒZdDdE„ ZdFdG„ ZdHdI„ ZdJdK„ ZdLdM„ ZdNS )OÚTestEmailMessageBase)©NNr   r	   r	   r   r'   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

                <p>simple body</p>
                --===--
                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

                <p>simple body</p>

                --===--
                )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

                <p>simple body</p>

                --===--
                )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

                <p>simple body</p>

                --===--
                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

                <p>simple body</p>

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

                --===
                Content-Type: text/html

                <p>simple body</p>

                --===
                Content-Type: image/jpg
                Content-ID: <image1>

                bogus data

                --===--
                )r   r(   Na                  To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/related; boundary="==="; type=text/html;
                 start="<body>"

                --===
                Content-Type: text/html
                Content-ID: <include>

                useless text

                --===
                Content-Type: text/html
                Content-ID: <body>

                <p>simple body</p>
                <!--#include file="<include>"-->

                --===--
                )é   é   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

                <p>simple body</p>

                --___
                Content-Type: image/jpg
                Content-ID: <image1@cid>

                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

                <p>simple body</p>

                --___--

                --+++
                Content-Type: image/jpg
                Content-ID: <image1@cid>

                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: <image1@cid>

                bogus jpg body

                --+++
                Content-Type: multipart/alternative; boundary="___"

                --___
                Content-Type: text/plain

                simple body

                --___
                Content-Type: text/html

                <p>simple body</p>

                --___--

                --+++--

                --===
                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, sir.

                --===
                Content-Type: message/rfc822

                To: bar@example.com
                From: robot@examp.com

                this is a message body.

                --===--
                )Zempty_messageZnon_mime_plainZmime_non_textZplain_html_alternativeZplain_html_mixedZplain_html_attachment_mixedZhtml_text_attachment_mixedZ!html_text_attachment_inline_mixedÚrelatedZrelated_with_startZmixed_alternative_plain_relatedZ$mixed_related_alternative_plain_htmlZ0mixed_related_alternative_plain_html_wrong_orderZmessage_rfc822Zmixed_text_message_rfc822c           
         sÖ  |   |¡}t| ¡ ƒ‰ ‡ fdd„|D ƒ}d}d}d}	|  | ¡ t|ƒ¡ |  |jddt|ƒ¡ |  |jddt|||d … ƒ¡ |  |jd	dt|| ||	 gƒ¡ |  |jd
dt|||	d … ƒ¡ |  |jdgd|| ¡ |  |jdgd|| ¡ |  |jdgd||	 ¡ |  |jddt||	|d d… ƒ¡ |  |jddt||	 || gƒ¡ |  |jddt||d d… ƒ¡ |  |jddt|d d d… ƒ¡ |  |jddt|| ||	 || gƒ¡ d S )Nc                    s    g | ]}|d u rd nˆ | ‘qS r   r	   ©Ú.0Ún©Zallpartsr	   r   Ú
<listcomp>Æ  r   z<TestEmailMessageBase.message_as_get_body.<locals>.<listcomp>r   r)   r(   )r.   ÚhtmlÚplain)Zpreferencelist)r.   r4   )r.   r5   )r4   r5   r.   r4   r5   )r5   r4   éÿÿÿÿ)r5   r.   )r4   r.   )r5   r4   r.   )r4   r5   r.   )r   ÚlistÚwalkr!   Úget_bodyr   )
r   Ú
body_partsÚattachmentsÚpartsÚmsgr   Zexpectedr.   r4   r5   r	   r2   r   Úmessage_as_get_bodyÃ  sP    
þÿÿÿÿÿÿÿÿþÿz(TestEmailMessageBase.message_as_get_bodyc                    s@   |   |¡}t| ¡ ƒ‰ ‡ fdd„|D ƒ}|  t| ¡ ƒ|¡ d S )Nc                    s   g | ]}ˆ | ‘qS r	   r	   r/   r2   r	   r   r3   æ  r   zCTestEmailMessageBase.message_as_iter_attachment.<locals>.<listcomp>)r   r7   r8   r!   Úiter_attachments©r   r:   r;   r<   r=   r   r	   r2   r   Úmessage_as_iter_attachmentã  s    
z/TestEmailMessageBase.message_as_iter_attachmentc                    sX   dd„ }|   |¡}t| ¡ ƒ‰ ‡ fdd„|D ƒ}||ƒrDt| ¡ ƒng }|  ||¡ d S )Nc                 S   s   d| v S )NzContent-Type: multipartr	   )r=   r	   r	   r   Ú_is_multipart_msgê  s    zETestEmailMessageBase.message_as_iter_parts.<locals>._is_multipart_msgc                    s   g | ]}ˆ | ‘qS r	   r	   r/   r2   r	   r   r3   ï  r   z>TestEmailMessageBase.message_as_iter_parts.<locals>.<listcomp>)r   r7   r8   Ú
iter_partsr!   )r   r:   r;   r<   r=   rB   r   rC   r	   r2   r   Úmessage_as_iter_partsé  s    
z*TestEmailMessageBase.message_as_iter_partsc                   @   s   e Zd Zdd„ Zdd„ ZdS )z(TestEmailMessageBase._TestContentManagerc                 O   s
   |||fS r   r	   ©r   r=   ÚargsÚkwr	   r	   r   Úget_contentô  s    z4TestEmailMessageBase._TestContentManager.get_contentc                 O   s   || _ || _|| _d S r   )r=   rF   rG   rE   r	   r	   r   Úset_contentö  s    z4TestEmailMessageBase._TestContentManager.set_contentN)r#   r$   r%   rH   rI   r	   r	   r	   r   Ú_TestContentManageró  s   rJ   c                 C   st   |   d¡}|  ¡ }|  |j|d|di f¡ |jd|ddd\}}}|  ||¡ |  |d¡ |  |tddd	¡ d S ©
Nr   ©Úcontent_managerr	   Úfoor)   r(   )rM   ÚbarÚk©rN   ©rO   rP   )r   rJ   r!   rH   Údict)r   r   Úcmr=   rF   rG   r	   r	   r   Útest_get_content_with_cmû  s    
z-TestEmailMessageBase.test_get_content_with_cmc                 C   s|   t jj|  ¡ d}| jd|d}|  | ¡ |di f¡ |jdddd\}}}|  ||¡ |  |d	¡ |  |tddd¡ d S ©
NrL   r   r   r	   rN   r)   r(   rR   rQ   )r   r    ÚclonerJ   r   r!   rH   rS   )r   Úpr   r=   rF   rG   r	   r	   r   Ú-test_get_content_default_cm_comes_from_policy  s    zBTestEmailMessageBase.test_get_content_default_cm_comes_from_policyc                 C   s   |   d¡}|  ¡ }|j|d |  |j|¡ |  |jd¡ |  |ji ¡ |jd|ddd |  |j|¡ |  |jd¡ |  |jtddd	¡ d S rK   )r   rJ   rI   r!   r=   rF   rG   rS   ©r   r   rT   r	   r	   r   Útest_set_content_with_cm  s    
z-TestEmailMessageBase.test_set_content_with_cmc                 C   sœ   |   ¡ }tjj|d}| jd|d}| ¡  |  |j|¡ |  |jd¡ |  |j	i ¡ |jdddd |  |j|¡ |  |jd	¡ |  |j	t
ddd¡ d S rV   )rJ   r   r    rW   r   rI   r!   r=   rF   rG   rS   )r   rT   rX   r   r	   r	   r   Ú-test_set_content_default_cm_comes_from_policy  s    zBTestEmailMessageBase.test_set_content_default_cm_comes_from_policy))r.   Ú
no_contentÚsucceeds)r.   Únoner^   )r.   r5   r^   )r.   r.   r   )r.   ÚalternativeÚraises)r.   Úmixedra   )r`   r]   r^   )r`   r_   r^   )r`   r5   r^   )r`   r.   r^   )r`   r`   r   )r`   rb   ra   )rb   r]   r^   )rb   r_   r^   )rb   r5   r^   )rb   r.   r^   )rb   r`   r^   )rb   rb   r   c                 C   sš   |   ¡ }d }ddg}|dkr| d¡ |dkrHd}| d¡ | d¡ n|dkrfg }| dd	| f¡ | d
¡ | |¡ |D ]\}}|||< q~|||fS )N)r   zfoo@bar.com)ZFromzbar@foo.comr]   )zX-Random-HeaderZCorwinÚtextr   )úContent-Typeú
text/plainrd   ú
multipart/)zX-TrumpÚRandom)ÚmessageÚappendÚset_payload)r   Úsubtyper   ÚpayloadÚmsg_headersÚnameÚvaluer	   r	   r   Ú_make_subtype_test_messageA  s&    þ




z/TestEmailMessageBase._make_subtype_test_messagec                 C   s\   |   t¡}t||ƒƒ  W d   ƒ n1 s,0    Y  t|jƒ}|  ||¡ |  ||¡ d S r   )r   r   ÚgetattrÚstrÚ	exceptionZassertIn)r   r   Zmethod_namerk   ÚmethodÚarÚexc_textr	   r	   r   Ú _check_disallowed_subtype_raisesX  s
    *
z5TestEmailMessageBase._check_disallowed_subtype_raisesc                 C   s´   d}|D ].\}}|  ¡  d¡s|  || |¡ |d7 }q|  t|ƒ|d ¡ t| ¡ ƒ}d}|D ].\}}|  ¡  d¡r`|  || |¡ |d7 }q`|  t|ƒ|¡ |  | ¡ |¡ d S )Nr   úcontent-r)   )ÚlowerÚ
startswithr!   Úlenr   rC   Úget_payload)r   r   rm   rl   Úcountrn   ro   Úpartr	   r	   r   Ú_check_make_multipart_  s    

z*TestEmailMessageBase._check_make_multipartc                 C   sÂ   |   |¡\}}}d| }|dv r4|  ||||¡ d S t||ƒƒ  |  | ¡ d¡ |  | ¡ |¡ |dkrœ|  t| ¡ ƒd¡ |  | ¡ |dd| fg ¡ n"|  t| ¡ ƒd¡ |  	|||¡ d S )	NÚmake_©r   ra   Ú	multipartr]   r   rd   rf   r)   )
rp   rw   rq   r!   Úget_content_maintypeÚget_content_subtyper{   r|   Úitemsr   )r   rt   rk   Úoutcomer   rm   rl   Zmake_methodr	   r	   r   Úsubtype_as_makeo  s"    
ÿÿz$TestEmailMessageBase.subtype_as_makec                 C   s¶   |   ¡ }|dv rZd| |d< |  t¡ }t|d| ƒƒ  W d   ƒ n1 sL0    Y  d S |dkrld|d< n|dkr€d| |d< t|d| ƒdd	 |  | ¡ ¡ |  | ¡ d¡ d S )
Nr   rf   rd   r€   r5   re   r]   Úabc)Úboundary)rh   r   r   rq   Ú
assertTrueZis_multipartr!   Zget_boundary)r   rt   rk   r†   r   rT   r	   r	   r   Úsubtype_as_make_with_boundary  s    .
z2TestEmailMessageBase.subtype_as_make_with_boundaryc                 C   sN   dD ]D}| j | jjddd}d|d< t||ƒƒ  |  | d¡jjd¡ qd S )N)Zmake_relatedZmake_alternativeZ
make_mixedrN   rL   r   re   rd   r   )rh   r   rW   rq   r!   r|   rM   )r   rt   r   r	   r	   r   Ú3test_policy_on_part_made_by_make_comes_from_message‘  s
    zHTestEmailMessageBase.test_policy_on_part_made_by_make_comes_from_messagec                   @   s   e Zd Zdd„ ZdS )z+TestEmailMessageBase._TestSetContentManagerc                 O   s   d|d< |  |¡ d S )Nre   rd   )rj   ©r   r=   ZcontentrF   rG   r	   r	   r   rI   ™  s    z7TestEmailMessageBase._TestSetContentManager.set_contentN©r#   r$   r%   rI   r	   r	   r	   r   Ú_TestSetContentManager˜  s   r   c                 C   sb  |   |¡\}}}|  ¡ }|dkr$dnd| }|dkrH|  ||||¡ d S t||ƒd|d |  | ¡ d¡ |  | ¡ |¡ ||ksŠ|dkrÊ|  t| ¡ ƒd	¡ |D ]\}	}
|  ||	 |
¡ q¢| ¡ d
 }n.|  t| ¡ ƒd¡ |  	|||¡ | ¡ d	 }|  | 
¡ d¡ |  | ¡ d¡ |dkr4|  |d d¡ n*|dkrP|  |d d¡ n|  |d ¡ d S )Nrb   Úadd_attachmentZadd_ra   ÚtestrL   r‚   r]   r)   r   r(   re   úContent-DispositionÚ
attachmentr.   Úinline)rp   r   rw   rq   r!   rƒ   r„   r{   r|   r   Zget_content_typeÚassertIsNone)r   rt   rk   r†   r   rm   rl   rT   Z
add_methodrn   ro   r~   r	   r	   r   Úsubtype_as_add  s0    

z#TestEmailMessageBase.subtype_as_addc                   @   s   e Zd Zdd„ ZdS )z2TestEmailMessageBase._TestSetRaisingContentManagerc                 O   s   t dƒ‚d S )Nr‘   )Ú	Exceptionr   r	   r	   r   rI   »  s    z>TestEmailMessageBase._TestSetRaisingContentManager.set_contentNrŽ   r	   r	   r	   r   Ú_TestSetRaisingContentManagerº  s   r˜   c              	   C   sv   |   ¡ }| j| jj|dd}dD ]N}|  t¡}t||ƒdƒ W d   ƒ n1 sT0    Y  |  t|j	ƒd¡ q"d S )NrL   r   )Úadd_relatedZadd_alternativer   r   r‘   )
r˜   rh   r   rW   r   r—   rq   r!   rr   rs   )r   rT   r   rt   ru   r	   r	   r   Ú6test_default_content_manager_for_add_comes_from_policy¾  s    ,zKTestEmailMessageBase.test_default_content_manager_for_add_comes_from_policyc                 C   s\   |   |¡}| ¡  |  t|ƒd¡ |  t| ¡ ƒg ¡ |  | ¡ ¡ |  t| ¡ ƒg ¡ d S )Nr   )	r   Úclearr!   r{   r7   r…   r•   r|   rC   r@   r	   r	   r   Úmessage_as_clearÆ  s    
z%TestEmailMessageBase.message_as_clearc                 C   s^   |   |¡}dd„ | ¡ D ƒ}| ¡  |  t| ¡ ƒ|¡ |  | ¡ ¡ |  t| ¡ ƒg ¡ d S )Nc                 S   s   g | ]}|  ¡  d ¡s|‘qS )rx   )ry   rz   )r0   Úhr	   r	   r   r3   Ð  s   ÿzATestEmailMessageBase.message_as_clear_content.<locals>.<listcomp>)r   ÚkeysZclear_contentr!   r7   r•   r|   rC   )r   r:   r;   r<   r=   r   Zexpected_headersr	   r	   r   Úmessage_as_clear_contentÎ  s    
z-TestEmailMessageBase.message_as_clear_contentc                 C   s€   |   ¡ }|  | ¡ ¡ d|d< |  | ¡ ¡ | dd¡ |  | ¡ ¡ | dd¡ |  | ¡ ¡ | ddd¡ |  | ¡ ¡ d S )Nr”   r’   r“   Z
AtTachMentÚfilenamezabc.png)Ú_make_messageZassertFalseZis_attachmentZreplace_headerrŠ   Z	set_paramr   r	   r	   r   Útest_is_attachment×  s    z'TestEmailMessageBase.test_is_attachmentc                 C   s^   |   ¡ }| d¡ | d¡ | d¡ | ¡  ¡ }|  tt| ¡ ƒƒd¡ |  | ¡ |¡ d S )Nzarbitrary text as main partzmore text as a related partz&yet more text as a second "attachment"r(   )	r¡   rI   r™   r|   Úcopyr!   r{   r7   r?   )r   r   Zorigr	   r	   r   Útest_iter_attachments_mutationã  s    


z3TestEmailMessageBase.test_iter_attachments_mutationN)r#   r$   r%   r   r    r   r   Zmessage_paramsr>   rA   rD   rJ   rU   rY   r[   r\   Zsubtype_paramsrp   rw   r   r‡   r‹   rŒ   r   r–   r˜   rš   rœ   rŸ   r¢   r¤   r	   r	   r	   r   r&   &   sÊ   üüüüüüüüüü5ü6ü3üü€ €     
			r&   c                   @   sž   e Zd ZeZdd„ ZG dd„ dƒZdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#S )$ÚTestEmailMessagec                 C   s>   |   d¡}|  ¡ }|  d|¡ |j|d |  |d d¡ d S ©Nr   úMIME-VersionrL   ú1.0)r   rJ   ÚassertNotInrI   r!   rZ   r	   r	   r   Ú"test_set_content_adds_MIME_Versionñ  s
    
z3TestEmailMessage.test_set_content_adds_MIME_Versionc                   @   s   e Zd Zdd„ ZdS )z(TestEmailMessage._MIME_Version_adding_CMc                 O   s   d|d< d S )Nr¨   r§   r	   rE   r	   r	   r   rI   ù  s    z4TestEmailMessage._MIME_Version_adding_CM.set_contentNrŽ   r	   r	   r	   r   Ú_MIME_Version_adding_CMø  s   r«   c                 C   s>   |   d¡}|  ¡ }|  d|¡ |j|d |  |d d¡ d S r¦   )r   r«   r©   rI   r!   rZ   r	   r	   r   Ú0test_set_content_does_not_duplicate_MIME_Versionü  s
    
zATestEmailMessage.test_set_content_does_not_duplicate_MIME_Versionc                 C   s*   |   d¡}|  t| ¡  ¡  ¡ ƒd¡ d S ©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*   ©r   r!   r{   Ú	as_stringÚstripÚ
splitlinesr   r	   r	   r   Ú0test_as_string_uses_max_header_length_by_default  s    
zATestEmailMessage.test_as_string_uses_max_header_length_by_defaultc                 C   sN   |   d¡}|  t|jdd ¡  ¡ ƒd¡ |  t|jdd ¡  ¡ ƒd¡ d S )Nr®   r   )Zmaxheaderlenr)   é"   r,   r¯   r   r	   r	   r   Ú"test_as_string_allows_maxheaderlen  s    
ÿÿz3TestEmailMessage.test_as_string_allows_maxheaderlenc                 C   s@   |   d¡}| d¡ |  |jddd¡ |  |jddd¡ d S )Nr‘   z%From foo@bar Thu Jan  1 00:00:00 1970T)Zunixfromz+From foo@bar Thu Jan  1 00:00:00 1970

testFz
test)r   Zset_unixfromr!   r°   r   r	   r	   r   Útest_as_string_unixform  s    

ÿz(TestEmailMessage.test_as_string_unixformc                 C   s*   |   d¡}|  tt|ƒ ¡  ¡ ƒd¡ d S r­   )r   r!   r{   rr   r±   r²   r   r	   r	   r   Ú+test_str_defaults_to_policy_max_line_length  s    
z<TestEmailMessage.test_str_defaults_to_policy_max_line_lengthc                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )Nu   unicÃ¶deÚSubjectu   Subject: unicÃ¶de

)r   r!   rr   r   r	   r	   r   Útest_str_defaults_to_utf8  s    z*TestEmailMessage.test_str_defaults_to_utf8c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )NuD   Hello WÃ¶rld! Hello WÃ¶rld! Hello WÃ¶rld! Hello WÃ¶rld!Hello WÃ¶rld!r¸   s|   Subject: Hello =?utf-8?q?W=C3=B6rld!_Hello_W=C3=B6rld!_Hello_W=C3=B6rld!?=
 Hello =?utf-8?q?W=C3=B6rld!Hello_W=C3=B6rld!?=

©r   r!   Úbytesr   r	   r	   r   Ú!test_folding_with_utf8_encoding_1  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_1c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )NuH   Hello WÃ¶rld! Hello WÃ¶rld! Hello WÃ¶rlds123! Hello WÃ¶rld!Hello WÃ¶rld!r¸   s€   Subject: Hello =?utf-8?q?W=C3=B6rld!_Hello_W=C3=B6rld!_Hello_W=C3=B6rlds123!?=
 Hello =?utf-8?q?W=C3=B6rld!Hello_W=C3=B6rld!?=

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_2/  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_2c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )NuH   Hello-WÃ¶rld!-Hello-WÃ¶rld!-Hello-WÃ¶rlds123! Hello WÃ¶rld!Hello WÃ¶rld!r¸   s€   Subject: =?utf-8?q?Hello-W=C3=B6rld!-Hello-W=C3=B6rld!-Hello-W=C3=B6rlds123!?=
 Hello =?utf-8?q?W=C3=B6rld!Hello_W=C3=B6rld!?=

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_3?  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_3c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )NuH   Hello-WÃ¶rld!-Hello-WÃ¶rld!-Hello-WÃ¶rlds123!-Hello WÃ¶rld!Hello WÃ¶rld!r¸   s   Subject: =?utf-8?q?Hello-W=C3=B6rld!-Hello-W=C3=B6rld!-Hello-W=C3=B6rlds123!?=
 =?utf-8?q?-Hello_W=C3=B6rld!Hello_W=C3=B6rld!?=

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_4O  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_4c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )NuS   123456789 123456789 123456789 123456789 123456789 123456789 123456789 Hello WÃ¶rld!r¸   so   Subject: 123456789 123456789 123456789 123456789 123456789 123456789 123456789
 Hello =?utf-8?q?W=C3=B6rld!?=

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_5_  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_5c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )Nuq   123456789 123456789 123456789 123456789 Hello WÃ¶rld! 123456789 123456789 123456789 123456789 123456789 123456789r¸   s   Subject: 123456789 123456789 123456789 123456789 Hello =?utf-8?q?W=C3=B6rld!?=
 123456789 123456789 123456789 123456789 123456789 123456789

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_6m  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_6c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )Nuo   123456789 123456789 Hello WÃ¶rld! Hello WÃ¶rld! 123456789-123456789 123456789 Hello WÃ¶rld! 123456789 123456789r¸   s    Subject: 123456789 123456789 Hello =?utf-8?q?W=C3=B6rld!_Hello_W=C3=B6rld!?=
 123456789-123456789 123456789 Hello =?utf-8?q?W=C3=B6rld!?= 123456789
 123456789

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_7}  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_7c                 C   s"   t ƒ }d|d< |  t|ƒd¡ d S )Nu¡   123456789 123456789 Hello WÃ¶rld! Hello WÃ¶rld! 123456789 123456789 123456789 123456789 123456789 123456789-123456789 123456789 Hello WÃ¶rld! 123456789 123456789r¸   sÒ   Subject: 123456789 123456789 Hello =?utf-8?q?W=C3=B6rld!_Hello_W=C3=B6rld!?=
 123456789 123456789 123456789 123456789 123456789 123456789-123456789
 123456789 Hello =?utf-8?q?W=C3=B6rld!?= 123456789 123456789

rº   r   r	   r	   r   Ú!test_folding_with_utf8_encoding_8Ž  s
    
ÿz2TestEmailMessage.test_folding_with_utf8_encoding_8c                 C   s    t  d¡}|  |¡}| ¡  d S )Na'              Message-ID: <674392CA.4347091@email.au>
            Date: Wed, 08 Nov 2017 08:50:22 +0700
            From: Foo Bar <email@email.au>
            MIME-Version: 1.0
            To: email@email.com <email@email.com>
            Subject: Python Email
            Content-Type: multipart/mixed;
            boundary="------------879045806563892972123996"
            X-Global-filter:Messagescannedforspamandviruses:passedalltests

            This is a multi-part message in MIME format.
            --------------879045806563892972123996
            Content-Type: text/plain; charset=ISO-8859-1; format=flowed
            Content-Transfer-Encoding: 7bit

            Your message is ready to be sent with the following file or link
            attachments:
            XU89 - 08.11.2017
            )r   r   r   r9   )r   r=   r   r	   r	   r   Útest_get_body_malformed¢  s    

z(TestEmailMessage.test_get_body_malformedN)r#   r$   r%   r   rh   rª   r«   r¬   r³   rµ   r¶   r·   r¹   r¼   r½   r¾   r¿   rÀ   rÁ   rÂ   rÃ   rÄ   r	   r	   r	   r   r¥   î  s$   r¥   c                   @   s    e Zd ZeZdd„ Zdd„ ZdS )ÚTestMIMEPartc                 C   s:   |   d¡}|  ¡ }|  d|¡ |j|d |  d|¡ d S )Nr   r§   rL   )r   rJ   r©   rI   rZ   r	   r	   r   Ú*test_set_content_does_not_add_MIME_VersionÄ  s
    
z7TestMIMEPart.test_set_content_does_not_add_MIME_Versionc                 C   s0   t t d¡tjd}| ¡ }|  t|ƒg ¡ d S )NzT        Content-Type: multipart/mixed; charset="utf-8"

        sample text
        r   )r   r   r   r   r    r?   r!   r7   )r   r=   r;   r	   r	   r   Ú/test_string_payload_with_multipart_content_typeË  s
    
üz<TestMIMEPart.test_string_payload_with_multipart_content_typeN)r#   r$   r%   r   rh   rÆ   rÇ   r	   r	   r	   r   rÅ   ¾  s   rÅ   Ú__main__)Zunittestr   Zemailr   r   Zemail.messager   r   Ztest.test_emailr   r   r   r   r&   r¥   rÅ   r#   Úmainr	   r	   r	   r   Ú<module>   s$        L Q