B
    v9aê€  ã               @   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 k	S )N© )Úxr   r   ú"/usr/lib/python3.7/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   s4   |   d¡}d|d< |  t¡ d|d< W d Q R X 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   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   )NNr   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, ser.

                --===
                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 krd nˆ | ‘qS )Nr   )Ú.0Ún)Úallpartsr   r
   ú
<listcomp>Æ  s    z<TestEmailMessageBase.message_as_get_body.<locals>.<listcomp>r   r%   r$   )r*   ÚhtmlÚplain)Zpreferencelist)r*   r/   )r*   r0   )r/   r0   r*   r/   r0   )r0   r/   éÿÿÿÿ)r0   r*   )r/   r*   )r0   r/   r*   )r/   r0   r*   )r   ÚlistÚwalkr   Zget_bodyr   )
r   Ú
body_partsÚattachmentsÚpartsÚmsgr   Zexpectedr*   r/   r0   r   )r-   r
   Úmessage_as_get_bodyÃ  s@    
  

z(TestEmailMessageBase.message_as_get_bodyc                s@   |   |¡}t| ¡ ƒ‰ ‡ fdd„|D ƒ}|  t| ¡ ƒ|¡ d S )Nc                s   g | ]}ˆ | ‘qS r   r   )r+   r,   )r-   r   r
   r.   æ  s    zCTestEmailMessageBase.message_as_iter_attachment.<locals>.<listcomp>)r   r2   r3   r   Úiter_attachments)r   r4   r5   r6   r7   r   r   )r-   r
   Úmessage_as_iter_attachmentã  s    
z/TestEmailMessageBase.message_as_iter_attachmentc                s@   |   |¡}t| ¡ ƒ‰ ‡ fdd„|D ƒ}|  t| ¡ ƒ|¡ d S )Nc                s   g | ]}ˆ | ‘qS r   r   )r+   r,   )r-   r   r
   r.   ì  s    z>TestEmailMessageBase.message_as_iter_parts.<locals>.<listcomp>)r   r2   r3   r   Ú
iter_parts)r   r4   r5   r6   r7   r   r   )r-   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 )Nr   )r   r7   ÚargsÚkwr   r   r
   Úget_contentð  s    z4TestEmailMessageBase._TestContentManager.get_contentc             O   s   || _ || _|| _d S )N)r7   r=   r>   )r   r7   r=   r>   r   r   r
   Úset_contentò  s    z4TestEmailMessageBase._TestContentManager.set_contentN)r    r!   r"   r?   r@   r   r   r   r
   Ú_TestContentManagerï  s   rA   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$   )rB   ÚbarÚk)rC   )rD   rE   )r   rA   r   r?   Údict)r   r   Úcmr7   r=   r>   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 )
N)rB   r   )r   r   rC   r%   r$   )rD   rE   )rC   )r   r   ÚclonerA   r   r   r?   rF   )r   Úpr   r7   r=   r>   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 )
Nr   )rB   r   rC   r%   r$   )rB   rD   rE   )rC   )rD   rE   )r   rA   r@   r   r7   r=   r>   rF   )r   r   rG   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 )
N)rB   r   )r   r   rC   r%   r$   )rD   rE   )rC   )rA   r   r   rI   r   r@   r   r7   r=   r>   rF   )r   rG   rJ   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*   ÚnonerO   )r*   r0   rO   )r*   r*   r   )r*   ÚalternativeÚraises)r*   ÚmixedrR   )rQ   rN   rO   )rQ   rP   rO   )rQ   r0   rO   )rQ   r*   rO   )rQ   rQ   r   )rQ   rS   rR   )rS   rN   rO   )rS   rP   rO   )rS   r0   rO   )rS   r*   rO   )rS   rQ   rO   )rS   rS   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
¡ | |¡ x|D ]\}}|||< q€W |||fS )N)r   zfoo@bar.com)ZFromzbar@foo.comrN   )zX-Random-HeaderZCorwinÚtextr   )zContent-Typez
text/plainzContent-Typez
multipart/)zX-TrumpZRandom)ÚmessageÚappendÚset_payload)r   Úsubtyper   ÚpayloadÚmsg_headersÚnameÚvaluer   r   r
   Ú_make_subtype_test_message=  s$    



z/TestEmailMessageBase._make_subtype_test_messagec          	   C   sH   |   t¡}t||ƒƒ  W d Q R X t|jƒ}|  ||¡ |  ||¡ d S )N)r   r   ÚgetattrÚstrÚ	exceptionZassertIn)r   r   Zmethod_namerX   ÚmethodÚarZexc_textr   r   r
   Ú _check_disallowed_subtype_raisesT  s
    
z5TestEmailMessageBase._check_disallowed_subtype_raisesc             C   s¼   d}x6|D ].\}}|  ¡  d¡s
|  || |¡ |d7 }q
W |  t|ƒ|d ¡ t| ¡ ƒ}d}x6|D ].\}}|  ¡  d¡rf|  || |¡ |d7 }qfW |  t|ƒ|¡ |  | ¡ |¡ d S )Nr   zcontent-r%   )ÚlowerÚ
startswithr   Úlenr   r;   Úget_payload)r   r   rZ   rY   Úcountr[   r\   Úpartr   r   r
   Ú_check_make_multipart[  s    z*TestEmailMessageBase._check_make_multipartc             C   sÂ   |   |¡\}}}d| }|dkr4|  ||||¡ d S t||ƒƒ  |  | ¡ d¡ |  | ¡ |¡ |dkrœ|  t| ¡ ƒd¡ |  | ¡ |dd| fg ¡ n"|  t| ¡ ƒd¡ |  	|||¡ d S )	NÚmake_)r   rR   Ú	multipartrN   r   zContent-Typez
multipart/r%   )
r]   rc   r^   r   Úget_content_maintypeÚget_content_subtyperf   rg   Úitemsrj   )r   ra   rX   Úoutcomer   rZ   rY   Zmake_methodr   r   r
   Úsubtype_as_makek  s    
z$TestEmailMessageBase.subtype_as_makec          	   C   s¢   |   ¡ }|dkrFd| |d< |  t¡}t|d| ƒƒ  W d Q R X d S |dkrXd|d< n|dkrld| |d< t|d| ƒdd	 |  | ¡ ¡ |  | ¡ d¡ d S )
N)r   rR   z
multipart/zContent-Typerk   r0   z
text/plainrN   Úabc)Úboundary)rU   r   r   r^   Ú
assertTrueZis_multipartr   Zget_boundary)r   ra   rX   rp   r   rG   r   r   r
   Úsubtype_as_make_with_boundary}  s    
z2TestEmailMessageBase.subtype_as_make_with_boundaryc             C   sR   xLdD ]D}| j | jjddd}d|d< t||ƒƒ  |  | d¡jjd¡ qW d S )N)Zmake_relatedZmake_alternativeZ
make_mixedrC   )rB   )r   z
text/plainzContent-Typer   )rU   r   rI   r^   r   rg   rB   )r   ra   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 )Nz
text/plainzContent-Type)rW   )r   r7   Úcontentr=   r>   r   r   r
   r@   •  s    z7TestEmailMessageBase._TestSetContentManager.set_contentN)r    r!   r"   r@   r   r   r   r
   Ú_TestSetContentManager”  s   rx   c             C   sf  |   |¡\}}}|  ¡ }|dkr$dnd| }|dkrH|  ||||¡ d S t||ƒd|d |  | ¡ d¡ |  | ¡ |¡ ||ksŠ|dkrÎ|  t| ¡ ƒd	¡ x |D ]\}	}
|  ||	 |
¡ q¤W | ¡ d
 }n.|  t| ¡ ƒd¡ |  	|||¡ | ¡ d	 }|  | 
¡ d¡ |  | ¡ d¡ |dkr8|  |d d¡ n*|dkrT|  |d d¡ n|  |d ¡ d S )NrS   Úadd_attachmentZadd_rR   Útest)rB   rl   rN   r%   r   r$   z
text/plainzContent-DispositionÚ
attachmentr*   Úinline)r]   rx   rc   r^   r   rm   rn   rf   rg   rj   Zget_content_typeÚassertIsNone)r   ra   rX   rp   r   rZ   rY   rG   Z
add_methodr[   r\   ri   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 )Nrz   )Ú	Exception)r   r7   rw   r=   r>   r   r   r
   r@   ·  s    z>TestEmailMessageBase._TestSetRaisingContentManager.set_contentN)r    r!   r"   r@   r   r   r   r
   Ú_TestSetRaisingContentManager¶  s   r€   c          
   C   sf   |   ¡ }| j| jj|dd}xBdD ]:}|  t¡}t||ƒdƒ W d Q R X |  t|j	ƒd¡ q$W d S )N)rB   )r   )Úadd_relatedZadd_alternativery   r   rz   )
r€   rU   r   rI   r   r   r^   r   r_   r`   )r   rG   r   ra   rb   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   rf   r2   ro   r}   rg   r;   )r   r4   r5   r6   r7   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 )zcontent-)rd   re   )r+   Úhr   r   r
   r.   Ì  s    zATestEmailMessageBase.message_as_clear_content.<locals>.<listcomp>)r   ÚkeysZclear_contentr   r2   r}   rg   r;   )r   r4   r5   r6   r7   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|   zContent-Dispositionr{   Z
AtTachMentÚfilenamezabc.png)Ú_make_messageZassertFalseZis_attachmentZreplace_headerrt   Z	set_param)r   r   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‰   r@   r   rg   Úcopyr   rf   r2   r9   )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_paramsr8   r:   r<   rA   rH   rK   rL   rM   Zsubtype_paramsr]   rc   rj   rq   ru   rv   rx   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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S ) ÚTestEmailMessagec             C   s>   |   d¡}|  ¡ }|  d|¡ |j|d |  |d d¡ d S )Nr   zMIME-Version)rB   z1.0)r   rA   ÚassertNotInr@   r   )r   r   rG   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 )Nz1.0zMIME-Versionr   )r   r7   r=   r>   r   r   r
   r@   õ  s    z4TestEmailMessage._MIME_Version_adding_CM.set_contentN)r    r!   r"   r@   r   r   r   r
   Ú_MIME_Version_adding_CMô  s   r   c             C   s>   |   d¡}|  ¡ }|  d|¡ |j|d |  |d d¡ d S )Nr   zMIME-Version)rB   z1.0)r   r   rŽ   r@   r   )r   r   rG   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 )Nzª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   rf   Ú	as_stringÚstripÚ
splitlines)r   r   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 )Nzª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   )Zmaxheaderlenr%   é"   r(   )r   r   rf   r’   r“   r”   )r   r   r   r   r
   Ú"test_as_string_allows_maxheaderlen  s
    
z3TestEmailMessage.test_as_string_allows_maxheaderlenc             C   s*   |   d¡}|  tt|ƒ ¡  ¡ ƒd¡ d S )Nzª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   rf   r_   r“   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   r_   )r   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   Úbytes)r   r   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   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   r   r   r
   Ú!test_folding_with_utf8_encoding_34  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   r   r   r
   Ú!test_folding_with_utf8_encoding_4D  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   r   r   r
   Ú!test_folding_with_utf8_encoding_5T  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   r   r   r
   Ú!test_folding_with_utf8_encoding_6b  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   r   r   r
   Ú!test_folding_with_utf8_encoding_7r  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   r   r   r
   Ú!test_folding_with_utf8_encoding_8ƒ  s    
z2TestEmailMessage.test_folding_with_utf8_encoding_8N)r    r!   r"   r   rU   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S )ÚTestMIMEPartc             C   s:   |   d¡}|  ¡ }|  d|¡ |j|d |  d|¡ d S )Nr   zMIME-Version)rB   )r   rA   rŽ   r@   )r   r   rG   r   r   r
   Ú*test_set_content_does_not_add_MIME_Version  s
    
z7TestMIMEPart.test_set_content_does_not_add_MIME_VersionN)r    r!   r"   r   rU   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"        I .