
    daf                         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"                          yy)    N)policymessage_from_string)EmailMessageMIMEPart)TestEmailBaseparameterizec                 0    t        t        d |       d       S )Nc                 
    | d uS N )xs    7/root/Python-3.12.4/Lib/test/test_email/test_message.py<lambda>zfirst.<locals>.<lambda>
   s
    $     )nextfilter)iterables    r   firstr   	   s    .94@@r   c                   0    e Zd Zej                  Zd Zd Zy)Testc                     | j                  d      }d|d<   | j                  t              5  d|d<   d d d        y # 1 sw Y   y xY w)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   sE    MM"$z* 	 AdG	  	  	 s	   ;Ac                     t        t        j                  d      t        j                        }| j                  |d   d       | j                  |d   d       | j                  |t               y )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   sa     1 !  ) 	9'IJ6$EFa.r   N)__name__
__module____qualname__r   r'   r    r*   r   r   r   r   r      s    ^^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;d<d=d>d?Zd@ Z yA)B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           	      P   | j                  |      }t        |j                               }|D cg c]  }|d n||    }}d}	d}
d}| j                  |j	                         t        |             | j                  |j	                  d      t        |             | j                  |j	                  d      t        ||	|
dz                 | j                  |j	                  d      t        ||	   ||   g             | j                  |j	                  d      t        ||
|dz                 | j                  |j	                  d	g      ||	          | j                  |j	                  d
g      ||
          | j                  |j	                  dg      ||          | j                  |j	                  d      t        |||
dz
  d                | j                  |j	                  d      t        ||   ||	   g             | j                  |j	                  d      t        ||
d d                | j                  |j	                  d      t        |d d d                | j                  |j	                  d      t        ||
   ||   ||	   g             y c c}w )Nr   r2   r1   )r?   htmlplain)preferencelist)r?   rG   )r?   rH   )rG   rH   r?   rG   rH   )rH   rG   )rH   r?   )rG   r?   )rH   rG   r?   )rG   rH   r?   )r   listwalkr(   get_bodyr   )r   
body_partsattachmentspartsmsgr   allpartsnexpectedr?   rG   rH   s               r   message_as_get_bodyz(TestEmailMessageBase.message_as_get_body  s   MM#>@JK1AID8A;6KKATquuX7 4D Ex	* 	3FGxQ78	:3GH 18E?CD	F3DExU1W56	8I;?!'*	,F8<htnMG9=xO3DExd1fR89	;3GH'1BCD	F3FGxb12	43OPx"~.	03OP ( ( 1 3 4	51 Ls   J#c                     | j                  |      }t        |j                               }|D cg c]  }||   	 }}| j                  t        |j	                               |       y c c}w r   )r   rK   rL   r(   iter_attachments)r   rN   rO   rP   rQ   r   rR   rS   s           r   message_as_iter_attachmentz/TestEmailMessageBase.message_as_iter_attachment  sY    MM#>,78qx{88a0023[A 9s   A'c                     d }| j                  |      }t        |j                               }|D cg c]  }||   	 }} ||      rt        |j                               ng }	| j	                  |	|       y c c}w )Nc                 
    d| v S )NzContent-Type: multipartr   )rQ   s    r   _is_multipart_msgzETestEmailMessageBase.message_as_iter_parts.<locals>._is_multipart_msg  s    ,33r   )r   rK   rL   
iter_partsr(   )
r   rN   rO   rP   rQ   r[   r   rR   rS   r\   s
             r   message_as_iter_partsz*TestEmailMessageBase.message_as_iter_parts  sk    	4 MM#>&+,!,,->s-CT!,,.)
U+ -s   A6c                       e Zd Zd Zd Zy)(TestEmailMessageBase._TestContentManagerc                     |||fS r   r   r   rQ   argskws       r   get_contentz4TestEmailMessageBase._TestContentManager.get_content  s    b= r   c                 .    || _         || _        || _        y r   )rQ   rb   rc   ra   s       r   set_contentz4TestEmailMessageBase._TestContentManager.set_content  s    DHDIDGr   N)r+   r,   r-   rd   rf   r   r   r   _TestContentManagerr_     s    	!	r   rg   c                 D   | j                  d      }| j                         }| j                  |j                  |      |di f       |j                  d|dd      \  }}}| j                  ||       | j                  |d       | j                  |t	        dd	             y 
Nr   content_managerr   foor2   r1   )rk   barkrl   rm   rn   )r   rg   r(   rd   dict)r   r   cmrQ   rb   rc   s         r   test_get_content_with_cmz-TestEmailMessageBase.test_get_content_with_cm  s    MM"%%'r:QBKHeRQ!LT2a x(Ta1-.r   c                 ~   t         j                  j                  | j                               }| j	                  d|      }| j                  |j                         |di f       |j                  ddd      \  }}}| j                  ||       | j                  |d	       | j                  |t        dd             y 
Nrj   r   r"   r   rl   r2   r1   rp   ro   )r   r'   clonerg   r   r(   rd   rq   )r   pr   rQ   rb   rc   s         r   -test_get_content_default_cm_comes_from_policyzBTestEmailMessageBase.test_get_content_default_cm_comes_from_policy  s    NN  1I1I1K LMM"QM'1b"+6ea8T2a x(Ta1-.r   c                    | j                  d      }| j                         }|j                  |       | j                  |j                  |       | j                  |j
                  d       | j                  |j                  i        |j                  d|dd       | j                  |j                  |       | j                  |j
                  d       | j                  |j                  t        dd	             y ri   )r   rg   rf   r(   rQ   rb   rc   rq   r   r   rr   s      r   test_set_content_with_cmz-TestEmailMessageBase.test_set_content_with_cm  s    MM"%%'	b)#"%#	eRQ!<#(+a 01r   c                 8   | j                         }t        j                  j                  |      }| j	                  d|      }|j                          | j                  |j                  |       | j                  |j                  d       | j                  |j                  i        |j                  ddd       | j                  |j                  |       | j                  |j                  d	       | j                  |j                  t        dd             y ru   )rg   r   r'   rv   r   rf   r(   rQ   rb   rc   rq   )r   rr   rw   r   s       r   -test_set_content_default_cm_comes_from_policyzBTestEmailMessageBase.test_set_content_default_cm_comes_from_policy  s    %%'NN   4MM"QM'	#"%#	ea(#(+a 01r   ))r?   
no_contentsucceeds)r?   noner   )r?   rH   r   )r?   r?   r   )r?   alternativeraises)r?   mixedr   )r   r~   r   )r   r   r   )r   rH   r   )r   r?   r   )r   r   r   )r   r   r   )r   r~   r   )r   r   r   )r   rH   r   )r   r?   r   )r   r   r   )r   r   r   c                 V   | j                         }d }ddg}|dk7  r	 |j                  d       |dk(  r%d}|j                  d       |j                  d       n|dk7  rg }|j                  dd	|z   f       |j                  d
       |j                  |       |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    LLN!# l")89fG=>MM"$Gw0FGH01	g& 	KD%AdG	+w&&r   c                     | j                  t              5 } t        ||              d d d        t        j                        }| j                  ||       | j                  ||       y # 1 sw Y   CxY w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**A3c                     d}|D ]?  \  }}|j                         j                  d      r&| j                  ||   |       |dz  }A | j                  t        |      |dz          t	        |j                               }d}|D ]?  \  }}|j                         j                  d      s&| j                  ||   |       |dz  }A | j                  t        |      |       | j                  |j                         |       y )Nr   content-r2   )lower
startswithr(   lenr   r\   get_payload)r   r   r   r   countr   r   parts           r   _check_make_multipartz*TestEmailMessageBase._check_make_multipart_  s    & 	KD%::<**:6  4%0
	 	Qq)ALLN#& 	KD%zz|&&z2  dU3
	 	TE*))+W5r   c                 4   | j                  |      \  }}}d|z   }|dv r| j                  ||||       y  t        ||              | j                  |j	                         d       | j                  |j                         |       |dk(  rS| j                  t        |j                               d       | j                  |j                         |dd|z   fgz          y | j                  t        |j                               d       | j                  |||       y )	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  s   "&"A"A'"J;&n$11!VWkR;!//1;?..0&9l"S115QWWY(^-9&-@-B ,C CD S115&&q+w?r   c                    | j                         }|dv r;d|z   |d<   | j                  t              5 } t        |d|z                 d d d        y |dk(  rd|d<   n|dk7  rd|z   |d<    t        |d|z         d	       | j	                  |j                                | j                  |j                         d       y # 1 sw Y   y xY w)
Nr   r   r   r   rH   r   r~   abc)boundary)r   r   r   r   
assertTrueis_multipartr(   get_boundary)r   r   r   r   r   rr   s         r   subtype_as_make_with_boundaryz2TestEmailMessageBase.subtype_as_make_with_boundary  s    LLNn$ ,w 6An"":. /",7V+,./g ,An$ ,w 6An$7V#$e4())51/s   B>>Cc                     dD ]y  }| j                  | j                  j                  d            }d|d<    t        ||              | j	                  |j                  d      j                  j                  d       { y )N)make_relatedmake_alternative
make_mixedrl   rj   r"   r   r   r   )r   r   rv   r   r(   r   rk   )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  ss    H 	MFDKK$5$5e$5$LMA ,AnGAv Q]]1-44DDeL		Mr   c                       e Zd Zd Zy)+TestEmailMessageBase._TestSetContentManagerc                 0    d|d<   |j                  |       y )Nr   r   )r   r   rQ   contentrb   rc   s        r   rf   z7TestEmailMessageBase._TestSetContentManager.set_content  s    ".COOG$r   Nr+   r,   r-   rf   r   r   r   _TestSetContentManagerr     s    	%r   r   c                    | j                  |      \  }}}| j                         }|dk(  rdnd|z   }|dk(  r| j                  ||||       y  t        ||      d|       | j	                  |j                         d       | j	                  |j                         |       ||k(  s|dk(  r\| j	                  t        |j                               d	       |D ]  \  }	}
| j	                  ||	   |
        |j                         d
   }nO| j	                  t        |j                               d       | j                  |||       |j                         d	   }| j	                  |j                         d       | j	                  |j                         d       |dk(  r| j	                  |d   d       y |dk(  r| j	                  |d   d       y | j                  |d          y )Nr   add_attachmentadd_r   testrj   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   rr   
add_methodr   r   r   s               r   subtype_as_addz#TestEmailMessageBase.subtype_as_add  s   "&"A"A'"J;((*)/%fvo
h11!VWjQ:vr://1;?..0&9W< 7S115* 1e  4%01==?1%DS115&&q+w?==?1%D..0,?))+V47?T"78,GYT"78(C d#89:r   c                   (    e Zd Z G d de      Zd Zy)2TestEmailMessageBase._TestSetRaisingContentManagerc                       e Zd Zy)>TestEmailMessageBase._TestSetRaisingContentManager.CustomErrorN)r+   r,   r-   r   r   r   CustomErrorr     s    r   r   c                 $    | j                  d      )Nr   )r   r   s        r   rf   z>TestEmailMessageBase._TestSetRaisingContentManager.set_content  s    ""6**r   N)r+   r,   r-   	Exceptionr   rf   r   r   r   _TestSetRaisingContentManagerr     s    	) 		+r   r   c                 l   | j                         }| j                  | j                  j                  |            }dD ]g  }| j	                  | j                   j
                        5 } t        ||      d       d d d        | j                  t        j                        d       i y # 1 sw Y   1xY w)Nrj   r"   )add_relatedadd_alternativer   r   r   )
r   r   r   rv   r   r   r   r(   r   r   )r   rr   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LL 1 1" 1 ELFJ 	8F""4#E#E#Q#QR 'VX"6"2&'S.7	8' 's   'B**B3	c                 ^   | j                  |      }|j                          | j                  t        |      d       | j                  t	        |j                               g        | j                  |j                                | j                  t	        |j                               g        y )Nr   )	r   clearr(   r   rK   r   r   r   r\   )r   rN   rO   rP   rQ   r   s         r   message_as_clearz%TestEmailMessageBase.message_as_clear  sv    MM#		Q#aggi"-!--/*alln-r2r   c                    | j                  |      }|j                         D cg c]#  }|j                         j                  d      s|% }}|j	                          | j                  t        |j                               |       | j                  |j                                | j                  t        |j                               g        y c c}w )Nr   )
r   keysr   r   clear_contentr(   rK   r   r   r\   )r   rN   rO   rP   rQ   r   hexpected_headerss           r   message_as_clear_contentz-TestEmailMessageBase.message_as_clear_content  s    MM#'(vvx E!#$779#7#7
#C  E E	affh)9:!--/*alln-r2Es   (Cc                    | j                         }| j                  |j                                d|d<   | j                  |j                                |j                  dd       | j	                  |j                                |j                  dd       | j	                  |j                                |j                  ddd       | j	                  |j                                y )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)*r   c                 j   | j                         }|j                  d       |j                  d       |j                  d       |j                         j	                         }| j                  t        t        |j                                     d       | j                  |j                         |       y )Nzarbitrary text as main partzmore text as a related partz&yet more text as a second "attachment"r1   )	r   rf   r   r   copyr(   r   rK   rW   )r   r   origs      r   test_iter_attachments_mutationz3TestEmailMessageBase.test_iter_attachments_mutation  s     	34	34	>?}}##%T!"4"4"678!<$/r   )u4   String that can be encodd with surrogateescapes0   String that can be encodëd with surrogateescape)u   String with utf-8 charactërs   String with utf-8 charactr)u8   String that cannot be ëncodd with surrogateescapes=   String that cannot be ncod\udcc3\udcabd with surrogateescape)u6   String with  cannot be encoded with surrogateescapes9   String with \udfff cannot be encoded with surrogateescape)good_surrogateescapestring_with_utf8surrogate_and_utf8out_of_range_surrogatec                 n    | j                  |      }|j                  d      }| j                  ||       y)ztest for GH issue 94606T)decodeN)r   r   r(   )r   rQ   rT   r   r   s        r   !get_payload_surrogate_as_gh_94606z6TestEmailMessageBase.get_payload_surrogate_as_gh_94606  s0    MM#--t-,7+r   N)!r+   r,   r-   r   r'   r%   r&   message_paramsrU   rX   r]   rg   rs   rx   r{   r}   subtype_paramsr   r   r   r   r   r   r   r   r   r   r   r   r   r   get_payload_surrogate_paramsr   r   r   r   r/   r/   &   s    ^^F HOO  	 HOO  	
 HOO  	#0 HOO  	2 HOO  	(0 HOO  	'0 HOO  	.4 HOO  	6 HOO  	8 HOO , ,	0,j HOO , ,	01l HOO , ,	0=f HOO 	 		  HOO  	&gLN\5@B, //
22&
N*'.-6 @$2 M% %
;:+ +833
+0!


##$ .,r   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y)TestEmailMessagec                     | j                  d      }| j                         }| j                  d|       |j                  |       | j	                  |d   d       y Nr   MIME-Versionrj   1.0)r   rg   assertNotInrf   r(   rz   s      r   "test_set_content_adds_MIME_Versionz3TestEmailMessage.test_set_content_adds_MIME_Version  sQ    MM"%%'+	b)>*E2r   c                       e Zd Zd Zy)(TestEmailMessage._MIME_Version_adding_CMc                     d|d<   y )Nr  r   r   ra   s       r   rf   z4TestEmailMessage._MIME_Version_adding_CM.set_content  s    "'Cr   Nr   r   r   r   _MIME_Version_adding_CMr    s    	(r   r  c                     | j                  d      }| j                         }| j                  d|       |j                  |       | j	                  |d   d       y r   )r   r  r  rf   r(   rz   s      r   0test_set_content_does_not_duplicate_MIME_VersionzATestEmailMessage.test_set_content_does_not_duplicate_MIME_Version  sQ    MM"))++	b)>*E2r   c                     | j                  d      }| j                  t        |j                         j	                         j                               d       y 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"  s>    MMBCQ[[]002==?@!Dr   c                 B   | j                  d      }| j                  t        |j                  d      j	                         j                               d       | j                  t        |j                  d      j	                         j                               d       y )Nr  r   )maxheaderlenr2   "   r5   r  r   s     r   "test_as_string_allows_maxheaderlenz3TestEmailMessage.test_as_string_allows_maxheaderlen&  s{    MMBCQ[[a[8>>@KKMN	Q[[b[9??ALLNO	r   c                     | j                  d      }|j                  d       | j                  |j                  d      d       | j                  |j                  d      d       y )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-  sW    MM&!	>?d3G	Ie4h?r   c                     | j                  d      }| j                  t        t        |      j	                         j                               d       y 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_length4  s9    MMBCSV\\^66891=r   c                 X    t               }d|d<   | j                  t        |      d       y )Nu   unicödeSubjectu   Subject: unicöde

)r   r(   r   r   s     r   test_str_defaults_to_utf8z*TestEmailMessage.test_str_defaults_to_utf88  s'    N!)Q!89r   c                 X    t               }d|d<   | j                  t        |      d       y )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=  s2     NB)qP	Qr   c                 X    t               }d|d<   | j                  t        |      d       y )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_2N  s2     NF)qP	Qr   c                 X    t               }d|d<   | j                  t        |      d       y )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_3^  s1     N4)qP	Qr   c                 X    t               }d|d<   | j                  t        |      d       y )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_4n  s1     N/)qQ	Rr   c                 X    t               }d|d<   | j                  t        |      d       y )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_5~  s0     N<)q?	@r   c                 X    t               }d|d<   | j                  t        |      d       y )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_6  s1     N$) 	q*	+r   c                 X    t               }d|d<   | j                  t        |      d       y )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  s3     N$) 	qN	Or   c                 X    t               }d|d<   | j                  t        |      d       y )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  s3     N$) 	qL	Mr   c                 p    t        j                  d      }| j                  |      }|j                          y)ztest for bpo-42892a'              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
            N)r%   r&   r   rM   )r   rQ   r   s      r   test_get_body_malformedz(TestEmailMessage.test_get_body_malformed  s0    oo  ( MM# 	


r   N)r+   r,   r-   r   r   r  r  r	  r  r  r  r  r  r"  r$  r&  r(  r*  r,  r.  r0  r2  r   r   r   r   r     sj    G3( (3E@>:
Q"Q Q R @+ O"M(r   r   c                       e Zd ZeZd Zd Zy)TestMIMEPartc                     | j                  d      }| j                         }| j                  d|       |j                  |       | j                  d|       y )Nr   r   rj   )r   rg   r  rf   rz   s      r   *test_set_content_does_not_add_MIME_Versionz7TestMIMEPart.test_set_content_does_not_add_MIME_Version  sL    MM"%%'+	b)+r   c                     t        t        j                  d      t        j                        }|j                         }| j                  t        |      g        y )NzT        Content-Type: multipart/mixed; charset="utf-8"

        sample text
        r"   )r   r%   r&   r   r'   rW   r(   rK   )r   rQ   rO   s      r   /test_string_payload_with_multipart_content_typez<TestMIMEPart.test_string_payload_with_multipart_content_type  sJ    !(// 3 # ^^	%
 **,k*B/r   N)r+   r,   r-   r   r   r6  r8  r   r   r   r4  r4    s     G,0r   r4  __main__)unittestr%   emailr   r   email.messager   r   test.test_emailr   r   r   r   r/   r   r4  r+   mainr   r   r   <module>r?     s~      - 0 7A/= /2 c, c, c,LM+] M`0' 0. zHMMO r   