
    <e                         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 Z G d de	          Ze
 G d d	                      Z G d
 dee	          Z G d dee	          Zedk    r e j                     dS dS )    N)policymessage_from_string)EmailMessageMIMEPart)TestEmailBaseparameterizec                 @    t          t          d |           d           S )Nc                 
    | d uS N )xs    3/usr/lib/python3.11/test/test_email/test_message.py<lambda>zfirst.<locals>.<lambda>
   s
    $     )nextfilter)iterables    r   firstr   	   s     ..994@@@r   c                   (    e Zd Zej        Zd Zd ZdS )Testc                     |                      d          }d|d<   |                     t                    5  d|d<   d d d            d S # 1 swxY w Y   d S )N zabc@xyzTozxyz@abc)_str_msgassertRaises
ValueErrorselfms     r   +test_error_on_setitem_if_max_count_exceededz0Test.test_error_on_setitem_if_max_count_exceeded   s    MM"$z** 	  	 AdG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   AAAc                    t          t          j        d          t          j                  }|                     |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   subjectu    Ayons asperges pour le déjeunerfromu   Pepé Le Pew <pepe@example.com>)r   textwrapdedentr   defaultassertEqualassertIsInstancer   r   s     r   /test_rfc2043_auto_decoded_and_emailmessage_usedz4Test.test_rfc2043_auto_decoded_and_emailmessage_used   s     1 ! !  ) ) ) 	9'IJJJ6$EFFFa.....r   N)__name__
__module____qualname__r   r'   r    r*   r   r   r   r   r      s9        ^F     / / / / /r   r   c                      e Zd Zej        Zdddd ej        d          fddd ej        d          fddd ej        d	          fddd ej        d
          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fddd ej        d          fd Zd! Zd" Z	d# Z
 G d$ d%          Zd& Zd' Zd( Zd) Zd*Zd+ Zd, Zd- Zd. Zd/ Zd0 Z G d1 d2          Zd3 Z G d4 d5          Zd6 Zd7 Zd8 Zd9 Zd: Zd;S )<TestEmailMessageBase)NNr   r   r   r   r0   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      )r2   r1   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>

                --===--
                )NNr2   )r1   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>

                --===--
                )Nr1   N)r2   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   r2   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   r1   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>"-->

                --===--
                )      r1   )      )r2   r5   r6   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

                --===--
                )r2   r4   r3   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

                --===--
                )r2   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.

                --===--
                )empty_messagenon_mime_plainmime_non_textplain_html_alternativeplain_html_mixedplain_html_attachment_mixedhtml_text_attachment_mixed!html_text_attachment_inline_mixedrelatedrelated_with_startmixed_alternative_plain_related$mixed_related_alternative_plain_html0mixed_related_alternative_plain_html_wrong_ordermessage_rfc822mixed_text_message_rfc822c           	        
 |                      |          }t          |                                          

fd|D             }d}d}d}	|                     |                                t          |                     |                     |                    d          t          |                     |                     |                    d          t          |||dz                                 |                     |                    d          t          ||         ||	         g                     |                     |                    d	          t          |||	dz                                 |                     |                    d
g          ||                    |                     |                    dg          ||                    |                     |                    dg          ||	                    |                     |                    d          t          ||	|dz
  d                              |                     |                    d          t          ||	         ||         g                     |                     |                    d          t          ||d d                              |                     |                    d          t          |d d d                              |                     |                    d          t          ||         ||	         ||         g                     d S )Nc                 (    g | ]}|d n|         S r   r   .0nallpartss     r   
<listcomp>z<TestEmailMessageBase.message_as_get_body.<locals>.<listcomp>  s%    KKK1AIDD8A;KKKr   r   r2   r1   )r?   htmlplain)preferencelist)r?   rM   )r?   rN   )rM   rN   r?   rM   rN   )rN   rM   )rN   r?   )rM   r?   )rN   rM   r?   )rM   rN   r?   )r   listwalkr(   get_bodyr   )r   
body_partsattachmentspartsmsgr   expectedr?   rM   rN   rK   s             @r   message_as_get_bodyz(TestEmailMessageBase.message_as_get_body  sZ   MM#>>KKKK
KKKATquuX777 4D E Ex	* 	* 	* 	3FGGxQ788	: 	: 	:3GHH 18E?CDD	F 	F 	F3DEExU1W566	8 	8 	8I;??!'*	, 	, 	,F8<<htnMMMG9==xOOO3DEExd1fR899	; 	; 	;3GHH'1BCDD	F 	F 	F3FGGxb122	4 	4 	43OPPx"~..	0 	0 	03OPP ( ( 1 3 4 4	5 	5 	5 	5 	5r   c                     |                      |          }t          |                                          fd|D             }|                     t          |                                          |           d S )Nc                      g | ]
}|         S r   r   rH   s     r   rL   zCTestEmailMessageBase.message_as_iter_attachment.<locals>.<listcomp>  s    888qx{888r   )r   rQ   rR   r(   iter_attachments)r   rT   rU   rV   rW   r   rK   s         @r   message_as_iter_attachmentz/TestEmailMessageBase.message_as_iter_attachment  sp    MM#>>8888K888a002233[AAAAAr   c                    d }|                      |          }t          |                                          fd|D             } ||          r!t          |                                          ng }|                     ||           d S )Nc                 
    d| v S )NzContent-Type: multipartr   )rW   s    r   _is_multipart_msgzETestEmailMessageBase.message_as_iter_parts.<locals>._is_multipart_msg  s    ,33r   c                      g | ]
}|         S r   r   rH   s     r   rL   z>TestEmailMessageBase.message_as_iter_parts.<locals>.<listcomp>  s    ,,,!,,,r   )r   rQ   rR   
iter_partsr(   )	r   rT   rU   rV   rW   r`   r   rb   rK   s	           @r   message_as_iter_partsz*TestEmailMessageBase.message_as_iter_parts  s    	4 	4 	4 MM#>>,,,,e,,,->->s-C-CKT!,,..)))
U+++++r   c                       e Zd Zd Zd ZdS )(TestEmailMessageBase._TestContentManagerc                     |||fS r   r   r   rW   argskws       r   get_contentz4TestEmailMessageBase._TestContentManager.get_content  s    b= r   c                 0    || _         || _        || _        d S r   )rW   rh   ri   rg   s       r   set_contentz4TestEmailMessageBase._TestContentManager.set_content  s    DHDIDGGGr   N)r+   r,   r-   rj   rl   r   r   r   _TestContentManagerre     s2        	! 	! 	!	 	 	 	 	r   rm   c                    |                      d          }|                                 }|                     |                    |          |di f           |                    d|dd          \  }}}|                     ||           |                     |d           |                     |t	          dd	                     d S 
Nr   content_managerr   foor2   r1   )rq   barkrr   rs   rt   )r   rm   r(   rj   dict)r   r   cmrW   rh   ri   s         r   test_get_content_with_cmz-TestEmailMessageBase.test_get_content_with_cm  s    MM"%%''r::QBKHHHeRQ!LLT2a   x(((Ta1---.....r   c                    t           j                            |                                           }|                     d|          }|                     |                                |di f           |                    ddd          \  }}}|                     ||           |                     |d	           |                     |t          dd                     d S 
Nrp   r   r"   r   rr   r2   r1   rv   ru   )r   r'   clonerm   r   r(   rj   rw   )r   pr   rW   rh   ri   s         r   -test_get_content_default_cm_comes_from_policyzBTestEmailMessageBase.test_get_content_default_cm_comes_from_policy  s    N  1I1I1K1K LLMM"QM''1b"+666ea88T2a   x(((Ta1---.....r   c                    |                      d          }|                                 }|                    |           |                     |j        |           |                     |j        d           |                     |j        i            |                    d|dd           |                     |j        |           |                     |j        d           |                     |j        t          dd	                     d S ro   )r   rm   rl   r(   rW   rh   ri   rw   r   r   rx   s      r   test_set_content_with_cmz-TestEmailMessageBase.test_set_content_with_cm  s    MM"%%''	b)))###"%%%###	eRQ!<<<###(+++a 0 0 011111r   c                 V   |                                  }t          j                            |          }|                     d|          }|                                 |                     |j        |           |                     |j        d           |                     |j	        i            |                    ddd           |                     |j        |           |                     |j        d	           |                     |j	        t          dd                     d S r{   )rm   r   r'   r|   r   rl   r(   rW   rh   ri   rw   )r   rx   r}   r   s       r   -test_set_content_default_cm_comes_from_policyzBTestEmailMessageBase.test_set_content_default_cm_comes_from_policy  s   %%''N   44MM"QM''	###"%%%###	ea(((###(+++a 0 0 011111r   ))r?   
no_contentsucceeds)r?   noner   )r?   rN   r   )r?   r?   r   )r?   alternativeraises)r?   mixedr   )r   r   r   )r   r   r   )r   rN   r   )r   r?   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   rN   r   )r   r?   r   )r   r   r   )r   r   r   c                    |                                  }d }ddg}|dk    r	 |                    d           |dk    r-d}|                    d           |                    d           n"|dk    rg }|                    dd	|z   f           |                    d
           |                    |           |D ]
\  }}|||<   |||fS )N)r   zfoo@bar.com)Fromzbar@foo.comr   )zX-Random-HeaderCorwintextr   )Content-Type
text/plainr   
multipart/)zX-TrumpRandom)messageappendset_payload)r   subtyper   payloadmsg_headersnamevalues          r   _make_subtype_test_messagez/TestEmailMessageBase._make_subtype_test_messageA  s    LLNN!# l"")8999fG=>>>MM"$$Gw0FGHHH0111	g& 	 	KD%AdGG+w&&r   c                    |                      t                    5 } t          ||                       d d d            n# 1 swxY w Y   t          |j                  }|                     ||           |                     ||           d S r   )r   r   getattrstr	exceptionassertIn)r   r   method_namer   methodarexc_texts          r    _check_disallowed_subtype_raisesz5TestEmailMessageBase._check_disallowed_subtype_raisesX  s    z** 	!bGAv   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!r|$$gx(((k8,,,,,s   A  AAc                 r   d}|D ]M\  }}|                                                     d          s!|                     ||         |           |dz  }N|                     t          |          |dz              t	          |                                          }d}|D ]M\  }}|                                                     d          r!|                     ||         |           |dz  }N|                     t          |          |           |                     |                                |           d S )Nr   content-r2   )lower
startswithr(   lenr   rb   get_payload)r   r   r   r   countr   r   parts           r   _check_make_multipartz*TestEmailMessageBase._check_make_multipart_  s/   & 	 	KD%::<<**:66   4%000
Qq)))ALLNN##& 	 	KD%zz||&&z22   dU333
TE***))++W55555r   c                    |                      |          \  }}}d|z   }|dv r|                     ||||           d S  t          ||                       |                     |                                d           |                     |                                |           |dk    rh|                     t          |                                          d           |                     |                                |dd|z   fgz              d S |                     t          |                                          d           | 	                    |||           d S )	Nmake_r   r   	multipartr   r   r   r   r2   )
r   r   r   r(   get_content_maintypeget_content_subtyper   r   itemsr   )r   r   r   outcomer   r   r   make_methods           r   subtype_as_makez$TestEmailMessageBase.subtype_as_makeo  ss   "&"A"A'"J"J;&n$$11!VWkRRRF;!!!//11;???..00&999l""S111555QWWYY(^-9&-@-B ,C CD D D D D S111555&&q+w?????r   c                    |                                  }|dv rWd|z   |d<   |                     t                    5 } t          |d|z                          d d d            n# 1 swxY w Y   d S |dk    rd|d<   n|dk    rd|z   |d<    t          |d|z             d	           |                     |                                           |                     |                                d           d S )
Nr   r   r   r   rN   r   r   abc)boundary)r   r   r   r   
assertTrueis_multipartr(   get_boundary)r   r   r   r   r   rx   s         r   subtype_as_make_with_boundaryz2TestEmailMessageBase.subtype_as_make_with_boundary  sG   LLNNn$$ ,w 6An"":.. /",7V+,,.../ / / / / / / / / / / / / / /Fg ,An$$ ,w 6An$7V#$$e4444(()))))511111s   A##A'*A'c                    dD ]}|                      | j                            d                    }d|d<    t          ||                       |                     |                    d          j        j        d           d S )N)make_relatedmake_alternative
make_mixedrr   rp   r"   r   r   r   )r   r   r|   r   r(   r   rq   )r   r   r   s      r   3test_policy_on_part_made_by_make_comes_from_messagezHTestEmailMessageBase.test_policy_on_part_made_by_make_comes_from_message  s    H 	M 	MFDK$5$5e$5$L$LMMA ,AnGAv   Q]]1--4DeLLLL		M 	Mr   c                       e Zd Zd ZdS )+TestEmailMessageBase._TestSetContentManagerc                 :    d|d<   |                     |           d S )Nr   r   )r   r   rW   contentrh   ri   s        r   rl   z7TestEmailMessageBase._TestSetContentManager.set_content  s$    ".COOG$$$$$r   Nr+   r,   r-   rl   r   r   r   _TestSetContentManagerr     s#        	% 	% 	% 	% 	%r   r   c                    |                      |          \  }}}|                                 }|dk    rdnd|z   }|dk    r|                     ||||           d S  t          ||          d|           |                     |                                d           |                     |                                |           ||k    s|dk    rt|                     t          |                                          d	           |D ]!\  }	}
|                     ||	         |
           "|                                d
         }nf|                     t          |                                          d           | 	                    |||           |                                d	         }|                     |
                                d           |                     |                                d           |dk    r|                     |d         d           d S |dk    r|                     |d         d           d S |                     |d                    d S )Nr   add_attachmentadd_r   testrp   r   r   r2   r   r1   r   Content-Disposition
attachmentr?   inline)r   r   r   r   r(   r   r   r   r   r   get_content_typeassertIsNone)r   r   r   r   r   r   r   rx   
add_methodr   r   r   s               r   subtype_as_addz#TestEmailMessageBase.subtype_as_add  s^   "&"A"A'"J"J;((**)/%%fvo
h11!VWjQQQF:vr:::://11;???..00&999W< 7 7S111555* 1 1e  4%0000==??1%DDS111555&&q+w???==??1%D..00,???))++V4447??T"78,GGGGGYT"78(CCCCC d#89:::::r   c                   0    e Zd Z G d de          Zd ZdS )2TestEmailMessageBase._TestSetRaisingContentManagerc                       e Zd ZdS )>TestEmailMessageBase._TestSetRaisingContentManager.CustomErrorN)r+   r,   r-   r   r   r   CustomErrorr     s        Dr   r   c                 ,    |                      d          )Nr   )r   r   s        r   rl   z>TestEmailMessageBase._TestSetRaisingContentManager.set_content  s    ""6***r   N)r+   r,   r-   	Exceptionr   rl   r   r   r   _TestSetRaisingContentManagerr     sM        	 	 	 	 	) 	 	 		+ 	+ 	+ 	+ 	+r   r   c                    |                                  }|                     | j                            |                    }dD ]z}|                     | j         j                  5 } t          ||          d           d d d            n# 1 swxY w Y   |                     t          |j	                  d           {d S )Nrp   r"   )add_relatedadd_alternativer   r   r   )
r   r   r   r|   r   r   r   r(   r   r   )r   rx   r   r   r   s        r   6test_default_content_manager_for_add_comes_from_policyzKTestEmailMessageBase.test_default_content_manager_for_add_comes_from_policy  s    //11LL 1 1" 1 E ELFFJ 	8 	8F""4#E#QRR 'VX"6""2&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S..7777	8 	8s   'BB	B	c                    |                      |          }|                                 |                     t          |          d           |                     t	          |                                          g            |                     |                                           |                     t	          |                                          g            d S )Nr   )	r   clearr(   r   rQ   r   r   r   rb   )r   rT   rU   rV   rW   r   s         r   message_as_clearz%TestEmailMessageBase.message_as_clear  s    MM#				Q###aggii"---!--//***allnn--r22222r   c                    |                      |          }d |                                D             }|                                 |                     t	          |                                          |           |                     |                                           |                     t	          |                                          g            d S )Nc                 `    g | ]+}|                                                     d           )|,S )r   )r   r   )rI   hs     r   rL   zATestEmailMessageBase.message_as_clear_content.<locals>.<listcomp>  sI     E E E!#$7799#7#7
#C#CEA E E Er   )r   keysclear_contentr(   rQ   r   r   rb   )r   rT   rU   rV   rW   r   expected_headerss          r   message_as_clear_contentz-TestEmailMessageBase.message_as_clear_content  s    MM#E Eqvvxx E E E	affhh)9:::!--//***allnn--r22222r   c                 D   |                                  }|                     |                                           d|d<   |                     |                                           |                    dd           |                     |                                           |                    dd           |                     |                                           |                    ddd           |                     |                                           d S )Nr   r   r   
AtTachMentfilenamezabc.png)_make_messageassertFalseis_attachmentreplace_headerr   	set_paramr   s     r   test_is_attachmentz'TestEmailMessageBase.test_is_attachment  s      **+++#+
 **+++	.===))***	.===))***	J	+@AAA))*****r   c                    |                                  }|                    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"r1   )	r   rl   r   r   copyr(   r   rQ   r\   )r   r   origs      r   test_iter_attachments_mutationz3TestEmailMessageBase.test_iter_attachments_mutation  s      	3444	3444	>???}}##%%T!"4"4"6"67788!<<<$/////r   N)r+   r,   r-   r   r'   r%   r&   message_paramsrY   r]   rc   rm   ry   r~   r   r   subtype_paramsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r/   r/   &   s        ^F HO   	 HO   	
 HO   	#0 HO   	2 HO   	(0 HO   	'0 HO   	.4 HO   	6 HO   	8 HO , , ,	0,j HO , , ,	01l HO , , ,	0=f HO 	 	 		  HO   	&gL LN\5 5 5@B B B, , ,       / / // / /
2 
2 
22 2 2&
N*' ' '.- - -6 6 6 @ @ @$2 2 2 M M M% % % % % % % %
; ; ;:+ + + + + + + +8 8 83 3 33 3 3
+ 
+ 
+0 0 0 0 0r   r/   c                       e Zd ZeZd Z G d d          Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestEmailMessagec                     |                      d          }|                                 }|                     d|           |                    |           |                     |d         d           d S Nr   MIME-Versionrp   1.0)r   rm   assertNotInrl   r(   r   s      r   "test_set_content_adds_MIME_Versionz3TestEmailMessage.test_set_content_adds_MIME_Version  so    MM"%%''+++	b)))>*E22222r   c                       e Zd Zd ZdS )(TestEmailMessage._MIME_Version_adding_CMc                     d|d<   d S )Nr   r   r   rg   s       r   rl   z4TestEmailMessage._MIME_Version_adding_CM.set_content  s    "'Cr   Nr   r   r   r   _MIME_Version_adding_CMr    s#        	( 	( 	( 	( 	(r   r  c                     |                      d          }|                                 }|                     d|           |                    |           |                     |d         d           d S r   )r   r  r  rl   r(   r   s      r   0test_set_content_does_not_duplicate_MIME_VersionzATestEmailMessage.test_set_content_does_not_duplicate_MIME_Version  so    MM"))+++++	b)))>*E22222r   c                     |                      d          }|                     t          |                                                                                                          d           d S NSubject: 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

r3   r   r(   r   	as_stringstrip
splitlinesr   s     r   0test_as_string_uses_max_header_length_by_defaultzATestEmailMessage.test_as_string_uses_max_header_length_by_default  sX    MMBCCQ[[]]0022==??@@!DDDDDr   c                    |                      d          }|                     t          |                    d                                                                                    d           |                     t          |                    d                                                                                    d           d S )Nr  r   )maxheaderlenr2   "   r5   r  r   s     r   "test_as_string_allows_maxheaderlenz3TestEmailMessage.test_as_string_allows_maxheaderlen	  s    MMBCCQ[[a[88>>@@KKMMNN	 	 	Q[[b[99??AALLNNOO	 	 	 	 	r   c                    |                      d          }|                    d           |                     |                    d          d           |                     |                    d          d           d S )Nr   z%From foo@bar Thu Jan  1 00:00:00 1970T)unixfromz+From foo@bar Thu Jan  1 00:00:00 1970

testFz
test)r   set_unixfromr(   r  r   s     r   test_as_string_unixformz(TestEmailMessage.test_as_string_unixform  s~    MM&!!	>???d33G	I 	I 	Ie44h?????r   c                     |                      d          }|                     t          t          |                                                                                    d           d S r
  )r   r(   r   r   r  r  r   s     r   +test_str_defaults_to_policy_max_line_lengthz<TestEmailMessage.test_str_defaults_to_policy_max_line_length  sR    MMBCCSVV\\^^6688991=====r   c                 r    t                      }d|d<   |                     t          |          d           d S )Nu   unicödeSubjectu   Subject: unicöde

)r   r(   r   r   s     r   test_str_defaults_to_utf8z*TestEmailMessage.test_str_defaults_to_utf8  s7    NN!)Q!899999r   c                 r    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   s     r   !test_folding_with_utf8_encoding_1z2TestEmailMessage.test_folding_with_utf8_encoding_1   sN     NNB)qP	Q 	Q 	Q 	Q 	Qr   c                 r    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   s     r   !test_folding_with_utf8_encoding_2z2TestEmailMessage.test_folding_with_utf8_encoding_21  sN     NNF)qP	Q 	Q 	Q 	Q 	Qr   c                 r    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   s     r   !test_folding_with_utf8_encoding_3z2TestEmailMessage.test_folding_with_utf8_encoding_3A  sM     NN4)qP	Q 	Q 	Q 	Q 	Qr   c                 r    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   s     r   !test_folding_with_utf8_encoding_4z2TestEmailMessage.test_folding_with_utf8_encoding_4Q  sM     NN/)qQ	R 	R 	R 	R 	Rr   c                 r    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   s     r   !test_folding_with_utf8_encoding_5z2TestEmailMessage.test_folding_with_utf8_encoding_5a  sL     NN<)q?	@ 	@ 	@ 	@ 	@r   c                 r    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   s     r   !test_folding_with_utf8_encoding_6z2TestEmailMessage.test_folding_with_utf8_encoding_6o  sI     NN$) 	q*	+ 	+ 	+ 	+ 	+r   c                 r    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   s     r   !test_folding_with_utf8_encoding_7z2TestEmailMessage.test_folding_with_utf8_encoding_7  sO     NN$) 	qN	O 	O 	O 	O 	Or   c                 r    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   s     r   !test_folding_with_utf8_encoding_8z2TestEmailMessage.test_folding_with_utf8_encoding_8  sO     NN$) 	qL	M 	M 	M 	M 	Mr   c                     	 t          j        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   rS   )r   rW   r   s      r   test_get_body_malformedz(TestEmailMessage.test_get_body_malformed  sA     o   ( MM# 	


r   N)r+   r,   r-   r   r   r  r  r  r  r  r  r  r  r!  r#  r%  r'  r)  r+  r-  r/  r1  r   r   r   r   r     sL       G3 3 3( ( ( ( ( ( ( (3 3 3E E E  @ @ @> > >: : :
Q Q Q"Q Q Q Q Q Q R R R @ @ @+ + + O O O"M M M(    r   r   c                       e Zd ZeZd Zd ZdS )TestMIMEPartc                     |                      d          }|                                 }|                     d|           |                    |           |                     d|           d S )Nr   r   rp   )r   rm   r  rl   r   s      r   *test_set_content_does_not_add_MIME_Versionz7TestMIMEPart.test_set_content_does_not_add_MIME_Version  sj    MM"%%''+++	b)))+++++r   c                     t          t          j        d          t          j                  }|                                }|                     t          |          g            d S )NzT        Content-Type: multipart/mixed; charset="utf-8"

        sample text
        r"   )r   r%   r&   r   r'   r\   r(   rQ   )r   rW   rU   s      r   /test_string_payload_with_multipart_content_typez<TestMIMEPart.test_string_payload_with_multipart_content_type  sg    !(/ 3 # # ^	% % %
 **,,k**B/////r   N)r+   r,   r-   r   r   r5  r7  r   r   r   r3  r3    s9         G, , ,0 0 0 0 0r   r3  __main__)unittestr%   emailr   r   email.messager   r   test.test_emailr   r   r   r   r/   r   r3  r+   mainr   r   r   <module>r>     sa     - - - - - - - - 0 0 0 0 0 0 0 0 7 7 7 7 7 7 7 7A A A/ / / / /= / / /2 F0 F0 F0 F0 F0 F0 F0 F0RM M M M M+] M M M`0 0 0 0 0' 0 0 0. zHMOOOOO r   