Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_email/__pycache__/test_email.cpython-39.pyc

a

XC?h�_�@s�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZddlZddlmZddlmZmZmZdd	lmZmZdd
lmZmZmZddl m!Z!ddl"m#Z#dd
l$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddlm2Z2ddlm3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddlm7Z7ddl8m9Z9m:Z:ddl;m<Z<m=Z=ddlm>Z>m?Z?dZ@dZAdZBGd d!�d!e=�ZCGd"d#�d#ejD�ZEGd$d%�d%e=�ZFGd&d'�d'ejD�ZGGd(d)�d)ejD�ZHGd*d+�d+ejD�ZIGd,d-�d-ejD�ZJGd.d/�d/ejD�ZKGd0d1�d1e=�ZLGd2d3�d3e=�ZMGd4d5�d5e=�ZNGd6d7�d7e=�ZOGd8d9�d9e=�ZPGd:d;�d;e=�ZQGd<d=�d=e=�ZRGd>d?�d?e=�ZSGd@dA�dAe=�ZTGdBdC�dCe=�ZUGdDdE�dEe=�ZVGdFdG�dG�ZWGdHdI�dIeWeQ�ZXGdJdK�dKeWeQ�ZYGdLdM�dMejD�ZZGdNdO�dOejD�Z[GdPdQ�dQejD�Z\GdRdS�dSe=�Z]GdTdU�dUe=�Z^GdVdW�dWe=�Z_e`dXk�r�e�a�dS)Y�N)�StringIO�BytesIO)�chain��choice)�Thread)�patch)�Charset)�Header�
decode_header�make_header)�Parser�HeaderParser)�	Generator�DecodedGenerator�BytesGenerator)�Message)�MIMEApplication)�	MIMEAudio)�MIMEText)�	MIMEImage)�MIMEBase)�MIMEMessage)�
MIMEMultipart)�MIMENonMultipart)�utils��errors)�encoders)�	iterators)�
base64mime)�
quoprimime)�unlink�
start_threads)�openfile�
TestEmailBase)�
FeedParser�BytesFeedParser�
�� c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�S)��TestMessageAPIcCs:|j}|�d�}||�d�gd��||�dd�d�dS)Nz
msg_20.txtZcc)zccc@zzz.orgzddd@zzz.orgzeee@zzz.orgZxxzn/a)�assertEqual�_msgobj�get_all��self�eq�msg�r3�?/opt/alt/python39/lib64/python3.9/test/test_email/test_email.py�test_get_all7s
zTestMessageAPI.test_get_allcCs|j}t�}||��d�td�}|�|�||dd�||��d�||dd�||�d�d�||dd	�||��jd�|�d�||��d�||dd�t�}d
|d<d|d
<d|d<|�|�||dd
�||dd�||dd�dS)N�
iso-8859-1�mime-versionz1.0�
text/plain�content-typez text/plain; charset="iso-8859-1"�charset�content-transfer-encoding�quoted-printablez2.0zMIME-Versionztext/x-weird�Content-Typezquinted-puntable�Content-Transfer-Encodingz"text/x-weird; charset="iso-8859-1")r,r�get_charsetr	�set_charset�get_content_type�	get_param�
input_charset�r0r1r2r:r3r3r4�test_getset_charset=s,


z"TestMessageAPI.test_getset_charsetcCs8|j}t�}|�d�||��jd�||dd�dS)N�us-asciir9�text/plain; charset="us-ascii")r,rr@r?rCr/r3r3r4�test_set_charset_from_stringWs

z+TestMessageAPI.test_set_charset_from_stringcCs0t�}td�}|�d|�|�|��jd�dS)Nr6zThis is a string payload)rr	�set_payloadr,r?rC)r0r2r:r3r3r4�test_set_payload_with_charset^sz,TestMessageAPI.test_set_payload_with_charsetcCsVd}td�}t�}|�||�|�|dd�|�|jdd�|�|�|��d�dS)N�АБВ�utf-8r;�base64T��decodez	0JDQkdCS
)r	rrIr,�get_payload�r0�datar:r2r3r3r4�+test_set_payload_with_8bit_data_and_charsetdsz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsRd}td�}d|_t�}|�|�d�|�|�|dd�|�|jdd�|�dS�NrKrLr;�8bitTrN)r	�
body_encodingrrIrOr,rPrQr3r3r4�>test_set_payload_with_non_ascii_and_charset_body_encoding_nonemszMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCsLd}td�}d|_t�}|�||�|�|dd�|�|jdd�|�dSrT)r	rVrrIr,rPrQr3r3r4�>test_set_payload_with_8bit_data_and_charset_body_encoding_nonevszMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs$t�}|�g�|�|��g�dS�N�rrIr,rP�r0r2r3r3r4�test_set_payload_to_lists
z'TestMessageAPI.test_set_payload_to_listcCs8t�}d|d<|�d�tt��}|�td|j|�dS)N�multipart/mixedr=zstring payloadz[Aa]ttach.*non-multipart)rrIrZassertRaisesRegex�	TypeError�attach)r0r2Zsub_msgr3r3r4�"test_attach_when_payload_is_string�s

�z1TestMessageAPI.test_attach_when_payload_is_stringcCsl|j}|�d�}|��}||gd��|�d�}|�d�}||gd��|�d�}|��}||gd��dS)Nz
msg_08.txt)NrFr6�
iso-8859-2�koi8-rz
msg_09.txt�dingbat)rcrFr6rcrbz
msg_12.txt)NrFr6Nraz
iso-8859-3rFrb)r,r-�get_charsets)r0r1r2�charsetsr3r3r4�test_get_charsets�s



z TestMessageAPI.test_get_charsetscCsV|j}|�d�}dd�|��D�}||ddg�|�d�}|�d�}||��d�dS)N�
msg_04.txtcSsg|]}|���qSr3��get_filename��.0�pr3r3r4�
<listcomp>��z4TestMessageAPI.test_get_filename.<locals>.<listcomp>�msg.txt�
msg_07.txt��dingusfish.gif)r,r-rPri)r0r1r2�	filenames�subpartr3r3r4�test_get_filename�s


z TestMessageAPI.test_get_filenamecCs4|j}|�d�}dd�|��D�}||ddg�dS)Nz
msg_44.txtcSsg|]}|���qSr3rhrjr3r3r4rm�rnzHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>ro�r,r-rP)r0r1r2rsr3r3r4�%test_get_filename_with_name_parameter�s
z4TestMessageAPI.test_get_filename_with_name_parametercCs"|j}|�d�}||��d�dS)Nrp�BOUNDARY)r,r-�get_boundaryr/r3r3r4�test_get_boundary�s
z TestMessageAPI.test_get_boundarycCs�|j}|�d�}|�d�|��d\}}||��d�||d�|�d�}|�d�|��d\}}||��d�||d�|�d�}|�tj|jd�dS)	N�
msg_01.txtrx�r9z3text/plain; charset="us-ascii"; boundary="BOUNDARY"rgz$multipart/mixed; boundary="BOUNDARY"�
msg_03.txt)r,r-�set_boundary�items�lower�assertRaisesr�HeaderParseError)r0r1r2�header�valuer3r3r4�test_set_boundary�s






�z TestMessageAPI.test_set_boundarycCsLtd�}|�|��ddd�|��|�|��dddd�d�dS)Nz	form-datarrqzmultipart/form-data�!z!multipart/form-data; boundary="==)rr,r�	as_stringr[r3r3r4�test_make_boundary�s�z!TestMessageAPI.test_make_boundarycCsrtd��}|��}Wd�n1s&0Yt�}|�|�}t�}t|dd�}|�|d�|�|��|�dS)N�
msg_46.txtTrF)	r$�readr�parsestrrr�flattenr,�getvalue�r0�fpZmsgdata�parserr2�out�genr3r3r4�test_message_rfc822_only�s
&
z'TestMessageAPI.test_message_rfc822_onlycCsztd��}|���d�}Wd�n1s,0Ytj��}|�|�}t�}tj�	|�}|�
|�|�|��|�dS)Nr��ascii)
r$r��encode�emailr��BytesHeaderParserZ
parsebytesr�	generatorrr�r,r�r�r3r3r4�test_byte_message_rfc822_only�s
,


z,TestMessageAPI.test_byte_message_rfc822_onlycCs�|j}|�d�}||jdd�d�||�d�jdd�d�||�d�jdd�d�||�d�jdd�d	�||�d
�jdd�d�||�d�jdd�d
�dS)Nz
msg_10.txtTrNrs This is a 7bit encoded message.
rqs-�This is a Quoted Printable encoded message!
�s!This is a Base64 encoded message.�s"This is a Base64 encoded message.
r|s/This has no Content-Transfer-Encoding: header.
rvr/r3r3r4�test_get_decoded_payload�s$
�����z'TestMessageAPI.test_get_decoded_payloadcCsZ|j}t�}|�d�dD]}||d<||jdd�d�q|�d�||jdd�d�dS)	Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
�z
x-uuencode�uuencodeZuuezx-uuer;TrN�hello world�foosfoo)r,rrIrP)r0r1r2�cter3r3r4�test_get_decoded_uu_payloads

z*TestMessageAPI.test_get_decoded_uu_payloadcCst�}|�t|jd�dS)Nrq)rr�r^rPr[r3r3r4�*test_get_payload_n_raises_on_non_multipartsz9TestMessageAPI.test_get_payload_n_raises_on_non_multipartcCsj|j}|�d�}td��}|��}Wd�n1s60Yt�}t|�}|�|�||��|�dS)Nrpz
msg_17.txt)r,r-r$r�rrr�r�)r0r1r2r��text�s�gr3r3r4�test_decoded_generators

&
z%TestMessageAPI.test_decoded_generatorcCsbt�}d|d<d|d<|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�dS)	NZMe�FromZYou�to�fromZFROM�ToZTO)r�assertInr[r3r3r4�test__contains__szTestMessageAPI.test__contains__cCs�|�d�}td��}|��}Wd�n1s00Y|�|t|��|jdd�}|�d�}|�|d�d��|�|t	�
|dd���dS)Nr{T��unixfromr(rzFrom rq)r-r$r�r,�strr��split�
assertTrue�
startswith�NL�join)r0r2r�r��fullrepr�linesr3r3r4�test_as_string(s

&
zTestMessageAPI.test_as_stringcCsT|�d�}|jjdd�}|j|d�}t�}t||d�}|�|�|�||���dS�Nr{�
��linesep��policy)	r-r��cloner�rrr�r,r��r0r2Z	newpolicyr�r�r�r3r3r4�test_as_string_policy2s

z$TestMessageAPI.test_as_string_policycCs<t�d�}|�d�}t�d�}t�|�}|�|��|�dS)Nu�            MIME-Version: 1.0
            Content-type: text/plain; charset="iso-8859-1"

            Test if non-ascii messages with no Content-Transfer-Encoding set
            can be as_string'd:
            Föö bär
            r6a%            MIME-Version: 1.0
            Content-type: text/plain; charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            Test if non-ascii messages with no Content-Transfer-Encoding set
            can be as_string'd:
            F=F6=F6 b=E4r
            )�textwrap�dedentr�r��message_from_bytesr,r��r0�m�source�expectedr2r3r3r4�#test_nonascii_as_string_without_cte;s



	
z2TestMessageAPI.test_nonascii_as_string_without_ctecCs>t�d�}|�d�}|�dd�}t�|�}|�|��|�dS)Nu�            MIME-Version: 1.0

            Test if non-ascii messages with no Content-Type nor
            Content-Transfer-Encoding set can be as_string'd:
            Föö bär
            r6r��replace)r�r�r�rOr�r�r,r�r�r3r3r4�4test_nonascii_as_string_without_content_type_and_cteQs



zCTestMessageAPI.test_nonascii_as_string_without_content_type_and_ctecCs�|�d�}td��}|���d�}Wd�n1s60Y|�|t|��|jdd�}|�d�}|�|d�	d��|�|d�
|dd���dS)	Nr{r�Tr��
rsFrom rq)r-r$r�r�r,�bytes�as_bytesr�r�r�r�)r0r2r�rRr�r�r3r3r4�
test_as_bytes^s

,
zTestMessageAPI.test_as_bytescCsT|�d�}|jjdd�}|j|d�}t�}t||d�}|�|�|�||���dSr�)	r-r�r�r�rrr�r,r�r�r3r3r4�test_as_bytes_policyhs

z#TestMessageAPI.test_as_bytes_policycCs t�d�}|�|�d�d�dS)NzContent-Type: blarg; baz; boo
�bazr)�r��message_from_stringr,rBr[r3r3r4�test_bad_paramrs
zTestMessageAPI.test_bad_paramcCst�d�}|�|��d�dS�Nz
From: foo
�r�r�r,rir[r3r3r4�test_missing_filenamevs
z$TestMessageAPI.test_missing_filenamecCst�d�}|�|��d�dS)Nz%Content-Disposition: blarg; filename
r)r�r[r3r3r4�test_bogus_filenamezs�z"TestMessageAPI.test_bogus_filenamecCst�d�}|�|��d�dSr��r�r�r,ryr[r3r3r4�test_missing_boundarys
z$TestMessageAPI.test_missing_boundarycCsx|j}t�d�}||jdd�gd��t�d�}||jdd�gd��||��d�t�d�}||jdd�gd��dS)N�&X-Header: foo=one; bar=two; baz=three
�x-header�r�))r��one)�bar�two�r�Zthreez X-Header: foo; bar=one; baz=two
))r�r))r�r�)r�r��"X-Header: foo; bar="one"; baz=two
)r,r�r��
get_paramsr/r3r3r4�test_get_params�s(������zTestMessageAPI.test_get_paramscCs$t�}d|d<|�|�d�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"r=�boundaryZCPIMSSMTPC06p5f3tG)rr,rBr[r3r3r4�test_get_param_liberal�sz%TestMessageAPI.test_get_param_liberalcCs�|j}t�d�}||jddd�d�||jddd�d�||�d�d�t�d�}||jddd�d	�||jddd�d
�||jddd�d�dS)Nr�r�r�r�r�Zquuzr�r�r)r�r��r,r�r�rBr/r3r3r4�test_get_param�s��zTestMessageAPI.test_get_paramcCs&|�d�}|�|�d��d�d�dS)Nz
msg_22.txtrq�namez
wibble.JPG)r-r,rPrBr[r3r3r4�'test_get_param_funky_continuation_lines�s
z6TestMessageAPI.test_get_param_funky_continuation_linescCs6t�d�}|�|�d�d�|�|jddd�d�dS)Nz4Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"
r�zJim&amp;&amp;JillF��unquotez"Jim&amp;&amp;Jill"r�r[r3r3r4�#test_get_param_with_semis_in_quotes�s��z2TestMessageAPI.test_get_param_with_semis_in_quotescCs<t�d�}|�|�d�d�t�d�}|�|�d�d�dS)Nz5Content-Type: foo; bar*0="baz\"foobar"; bar*1="\"baz"r�zbaz"foobar"bazr�r[r3r3r4�test_get_param_with_quotes�s��z)TestMessageAPI.test_get_param_with_quotescCs>t�d�}|�d|�|�d|�|�d|�|�d|�dS)NzHeader: existsr�r
ZHEADERZheaderx)r�r�r�ZassertNotInr[r3r3r4�test_field_containment�s

z%TestMessageAPI.test_field_containmentcCs�|j}t�}|�dd�||�d�d�|�dd�||�d�d�||jddd�d�||��gd��||jdd�gd	��|jdd
dd�||jddd�d
�dS)
Nr:�iso-2022-jp�
importance�
high valueFr��"high value")�r8r))r:r�)r�r�)r�)r:z
"iso-2022-jp")r�r�ziso-9999-xxzX-Jimmyr�)r,r�	set_paramrBr�r/r3r3r4�test_set_param�szTestMessageAPI.test_set_paramcCsp|j}|�d�}||��gd��|�d�}|�d�||��ddg�|�d|�||��ddd|fg�dS)N�
msg_05.txt)��multipart/reportr))�report-type�delivery-status�r��%D1690A7AC1.996856090/mail.example.comr�r�r�)r,r-r�rB�	del_paramr�)r0r1r2Zold_valr3r3r4�test_del_param�s&
�

����zTestMessageAPI.test_del_paramcCs6t�}|jdddd�|�dd�|�|dd�dS)N�Content-Disposition�
attachment�bud.gif��filenamer�content-disposition�r�
add_headerr�r,r[r3r3r4�test_del_param_on_other_header�sz-TestMessageAPI.test_del_param_on_other_headercCst�}|�dd�dS)Nrr)rr�r[r3r3r4�$test_del_param_on_nonexistent_header�sz3TestMessageAPI.test_del_param_on_nonexistent_headercCs@t�}|jdddd�|d}|jddd�|�|d|�dS)Nr=r8rL�r:�foobarr�r)r0r2Zexisting_headerr3r3r4�test_del_nonexistent_param�s
z)TestMessageAPI.test_del_nonexistent_paramcCsj|j}t�}|�t|jd�|�d�||dd�|�dd�||dd�|�d�||dd�dS)	Nr�r8r9r:rFrGz	text/htmlztext/html; charset="us-ascii")r,rr��
ValueError�set_typer�r/r3r3r4�
test_set_type�s

zTestMessageAPI.test_set_typecCs.t�}d|d<|�dd�|�|dd�dS)Nr8zX-Content-Type�application/octet-streamzx-content-type)rrr,r[r3r3r4�test_set_type_on_other_headersz,TestMessageAPI.test_set_type_on_other_headercCst�}|�|��d�dS)Nr8)rr,rAr[r3r3r4�test_get_content_type_missingsz,TestMessageAPI.test_get_content_type_missingcCs$t�}|�d�|�|��d�dS)N�message/rfc822)r�set_default_typer,rAr[r3r3r4�/test_get_content_type_missing_with_default_types
z>TestMessageAPI.test_get_content_type_missing_with_default_typecCs$|�d�}|�|�d���d�dS)N�
msg_30.txtrr�r-r,rPrAr[r3r3r4�+test_get_content_type_from_message_implicits
�z:TestMessageAPI.test_get_content_type_from_message_implicitcCs$|�d�}|�|�d���d�dS)N�
msg_28.txtrrrr[r3r3r4�+test_get_content_type_from_message_explicits
�z:TestMessageAPI.test_get_content_type_from_message_explicitcCs|�d�}|�|��d�dS)Nr}r8�r-r,rAr[r3r3r4�6test_get_content_type_from_message_text_plain_implicits
zETestMessageAPI.test_get_content_type_from_message_text_plain_implicitcCs|�d�}|�|��d�dS)Nr{r8rr[r3r3r4�6test_get_content_type_from_message_text_plain_explicit#s
zETestMessageAPI.test_get_content_type_from_message_text_plain_explicitcCst�}|�|��d�dS)Nr��rr,�get_content_maintyper[r3r3r4�!test_get_content_maintype_missing'sz0TestMessageAPI.test_get_content_maintype_missingcCs$t�}|�d�|�|��d�dS)Nr�message)rrr,rr[r3r3r4�3test_get_content_maintype_missing_with_default_type+s
zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCs$|�d�}|�|�d���d�dS)Nrrr!�r-r,rPrr[r3r3r4�/test_get_content_maintype_from_message_implicit0s
z>TestMessageAPI.test_get_content_maintype_from_message_implicitcCs$|�d�}|�|�d���d�dS)Nrrr!r#r[r3r3r4�/test_get_content_maintype_from_message_explicit4s
z>TestMessageAPI.test_get_content_maintype_from_message_explicitcCs|�d�}|�|��d�dS)Nr}r��r-r,rr[r3r3r4�:test_get_content_maintype_from_message_text_plain_implicit8s
zITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitcCs|�d�}|�|��d�dS)Nr{r�r&r[r3r3r4�:test_get_content_maintype_from_message_text_plain_explicit<s
zITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitcCst�}|�|��d�dS)N�plain�rr,�get_content_subtyper[r3r3r4� test_get_content_subtype_missing@sz/TestMessageAPI.test_get_content_subtype_missingcCs$t�}|�d�|�|��d�dS)Nr�rfc822)rrr,r+r[r3r3r4�2test_get_content_subtype_missing_with_default_typeDs
zATestMessageAPI.test_get_content_subtype_missing_with_default_typecCs$|�d�}|�|�d���d�dS)Nrrr-�r-r,rPr+r[r3r3r4�.test_get_content_subtype_from_message_implicitIs
z=TestMessageAPI.test_get_content_subtype_from_message_implicitcCs$|�d�}|�|�d���d�dS)Nrrr-r/r[r3r3r4�.test_get_content_subtype_from_message_explicitMs
z=TestMessageAPI.test_get_content_subtype_from_message_explicitcCs|�d�}|�|��d�dS)Nr}r)�r-r,r+r[r3r3r4�9test_get_content_subtype_from_message_text_plain_implicitQs
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCs|�d�}|�|��d�dS)Nr{r)r2r[r3r3r4�9test_get_content_subtype_from_message_text_plain_explicitUs
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitcCs"t�}d|d<|�|��d�dS)N�no-slash-in-this-stringr=r�rr[r3r3r4�test_get_content_maintype_errorYsz.TestMessageAPI.test_get_content_maintype_errorcCs"t�}d|d<|�|��d�dS)Nr5r=r)r*r[r3r3r4�test_get_content_subtype_error^sz-TestMessageAPI.test_get_content_subtype_errorcCs�|j}t�}|�dd�|�dd�|�dd�||��gd��||��gd��|�dd	�||��gd��||��gd
��|�dd�|�dd�||��gd
��||��gd��|�t|jdd�dS)N�First�One�Second�Two�Third�Three)r8r:r<)r9r;r=�Twenty)r9r>r=�Eleven�One Hundred)r8r:r<r8)r@r>r=r?ZFourthZMissing)r,rr�keys�values�replace_headerr��KeyErrorr/r3r3r4�test_replace_headercsz"TestMessageAPI.test_replace_headercCspt�}|�|���|jdddd�|�|��d�|�dd�|�|��d�|�dd�|�|��d�dS)Nrrz
random.avir�inlineZInlinE)r�assertIsNoneZget_content_dispositionrr,rCr[r3r3r4�test_get_content_dispositionts�z+TestMessageAPI.test_get_content_dispositioncCsPd}t�}d|d<d|d<|�|�|�|jdd�d�|�|jd	tj�dS)
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midir9rMr;TrNs����.���p���r)rrIr,rP�assertIsInstance�defectsr�InvalidBase64CharactersDefect�r0�xr2r3r3r4�test_broken_base64_payload�s
��z)TestMessageAPI.test_broken_base64_payloadcCsBd}t�}d|d<d|d<|�|�|�|jdd�t|d��dS)	Nuthis is a bröken thing to dor8r9rUr;TrNzraw-unicode-escape)rrIr,rPr�rLr3r3r4�test_broken_unicode_payload�s
�z*TestMessageAPI.test_broken_unicode_payloadcCs>d�d�}t�}d|d<d|d<||_|�|jdd�|�dS)	Nu#this is a quéstionable thing to dorL�text/plain; charset="utf-8"r9rUr;TrN)r�rZ_payloadr,rPrLr3r3r4�test_questionable_bytes_payload�s
z.TestMessageAPI.test_questionable_bytes_payloadcCs*t�}|jdddd�|�d|d�dS)Nrrrrzattachment; filename="bud.gif"�rrr,r[r3r3r4�test_ascii_add_header�s��z$TestMessageAPI.test_ascii_add_headercCs*t�}|jdddd�|�d|d�dS)Nrr�Fußballer.pptrz/attachment; filename*=utf-8''Fu%C3%9Fballer.pptrRr[r3r3r4�test_noascii_add_header�s��z&TestMessageAPI.test_noascii_add_headercCs*t�}|jdddd�|�d|d�dS)Nrr)r6r)rTrz1attachment; filename*=iso-8859-1''Fu%DFballer.pptrRr[r3r3r4�#test_nonascii_add_header_via_triple�s��z2TestMessageAPI.test_nonascii_add_header_via_triplecCs*t�}|jdddd�|�d|d�dS)Nrrzwindows [filename].pptrz-attachment; filename="windows [filename].ppt"rRr[r3r3r4�#test_ascii_add_header_with_tspecial�s��z2TestMessageAPI.test_ascii_add_header_with_tspecialcCs*t�}|jdddd�|�d|d�dS)NrruFußballer [filename].pptrz@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptrRr[r3r3r4�&test_nonascii_add_header_with_tspecial�s��z5TestMessageAPI.test_nonascii_add_header_with_tspecialcCsLdD]B}t�}d||d<d|d<|�d�|�|jdd�d	d
|�qdS)N��latin-1r��text/plain; charset=%sr9r<r;sfoo=e6=96=87barTrN�	foo文bar�1get_payload returns wrong result with charset %s.rZ�r0r:r2r3r3r4�test_binary_quopri_payload�s

�z)TestMessageAPI.test_binary_quopri_payloadcCsLdD]B}t�}d||d<d|d<|�d�|�|jdd�d	d
|�qdS)NrYr[r9rMr;sZm9v5paHYmFyTrNr\r]rZr^r3r3r4�test_binary_base64_payload�s

�z)TestMessageAPI.test_binary_base64_payloadc
Cs^dD]T}dD]J}t�}d||d<||d<|�d�|�|jdd�d	td
��||��qqdS)NrYr�r[r9r;s begin 666 -
)9F]OYI:'8F%R
 
end
TrNr\)z!get_payload returns wrong result z"with charset {0} and encoding {1}.)rrIr,rPr��format)r0r:�encodingr2r3r3r4�test_binary_uuencode_payload�s

��z+TestMessageAPI.test_binary_uuencode_payloadcCs*t�}|jdddd�|�d|d�dS)NrrF)Zfoo_barzinline; foo-barrRr[r3r3r4�$test_add_header_with_name_only_param�sz3TestMessageAPI.test_add_header_with_name_only_paramcCs&t�}|�dd�|�d|d�dS)NzX-Statusr)rRr[r3r3r4�test_add_header_with_no_value�sz,TestMessageAPI.test_add_header_with_no_valuecCs&t�}td�|d<|�tj|j�dS�Nzdummy
X-Injected-Header: testZDummy)rr
r�rr�r�r[r3r3r4�(test_embedded_header_via_Header_rejected�sz7TestMessageAPI.test_embedded_header_via_Header_rejectedcCs"t�}d|d<|�tj|j�dSrf)rr�rr�r�r[r3r3r4�(test_embedded_header_via_string_rejected�sz7TestMessageAPI.test_embedded_header_via_string_rejectedcCs*td�}d|d<|�t|�t�d��dS)Nzabc
uÉ test�Subjectz�            Content-Type: text/plain; charset="us-ascii"
            MIME-Version: 1.0
            Content-Transfer-Encoding: 7bit
            Subject: =?utf-8?q?=C3=89_test?=

            abc
            �rr,r�r�r��r0r�r3r3r4�-test_unicode_header_defaults_to_utf8_encodingsz<TestMessageAPI.test_unicode_header_defaults_to_utf8_encodingcCs"td�}|�t|�t�d��dS)NuÉ testabc
z�            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: base64

            w4kgdGVzdGFiYwo=
            rjrkr3r3r4�+test_unicode_body_defaults_to_utf8_encodingsz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)X�__name__�
__module__�__qualname__r5rErHrJrSrWrXr\r`rfrurwrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr	rrrrrrrrrr r"r$r%r'r(r,r.r0r1r3r4r6r7rErHrNrOrQrSrUrVrWrXr_r`rcrdrergrhrlrmr3r3r3r4r+6s�			

	



r+c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncoderscCsptdd��}|��}Wd�n1s(0Ytjj�|�}|��}|�d�}|�t	dd�|D��d�dS)N�PyBanner048.gif�rbr(cSsg|]}t|��qSr3)�len�rkrMr3r3r4rm&rnz;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>�L)
r$r�r��mime�imagerrPr��assertLessEqual�max)r0r��bindataZmimedZbase64edr�r3r3r4�test_EncodersEncode_base64s&
z'TestEncoders.test_EncodersEncode_base64cCs(|j}t�}|�d�||dd�dS)NrFr;�7bit)r,rr@r/r3r3r4�test_encode_empty_payload(s
z&TestEncoders.test_encode_empty_payloadcCsP|j}td�}||dd�td�}||dd�tddd�}||dd�dS)	N�hello worldr;r}uhello ø worldrMr6�Z_charsetr<)r,rr/r3r3r4�test_default_cte.szTestEncoders.test_default_ctecCs8|j}tddd�}||dd�||��t�d��dS)Nu文
�euc-jpr�r;r}z�            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r,rr�r�r�r/r3r3r4�test_encode7or8bit:szTestEncoders.test_encode7or8bitcCs&tddd�}|�t|�t�d��dS)Nuáö
r�z
ISO-8859-1z�            MIME-Version: 1.0
            Content-Type: text/text; charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            =E1=F6
            rjr[r3r3r4�test_qp_encode_latin1Isz"TestEncoders.test_qp_encode_latin1cCs&tddd�}|�t|�t�d��dS)Nuż
r�z
ISO-8859-2z�            MIME-Version: 1.0
            Content-Type: text/text; charset="iso-8859-2"
            Content-Transfer-Encoding: quoted-printable

            =BF
            rjr[r3r3r4�test_qp_encode_non_latin1Ssz&TestEncoders.test_qp_encode_non_latin1N)	rnrorpr|r~r�r�r�r�r3r3r3r4rqs	
rqc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dS)P�TestLongHeadersNcCs:|j}t�d�}t�}t|�}|�|�||��d�dS)Nz�Subject: bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text

test
)�ndiffAssertEqualr�r�rrr�r��r0r1r2�sfpr�r3r3r4�test_split_long_continuationds

z,TestLongHeaders.test_split_long_continuationcCsF|j}d}t|dd�}||��d�t|�dd��}||��d�dS)Nz�bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text�	��continuation_wsr*z�bug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)r�r
r�r��r0r1Zhstr�hr3r3r4�,test_another_long_almost_unsplittable_headerxsz<TestLongHeaders.test_another_long_almost_unsplittable_headercCs�|j}td�}td�}td�}d}d}d}t||dd�}|�||�|�||�t�}	||	d<t�}
t|
�}|�|	�||
��d	�||j	d
d�d�dS)
Nr6rarL�Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s�dl�ndischen Wandgem�lden vorbei, gegen die rotierenden Klingen bef�rdert. �;Finan�ni metropole se hroutily pod tlakem jejich d�vtipu.. ��正確に言うと翻訳はされていません。一部はドイツ語ですが、あとはでたらめです。実際には「Wenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.」と言っています。ri��header_namea!Subject: =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderb?=
 =?iso-8859-1?q?and_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen?=
 =?iso-8859-1?q?_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef?=
 =?iso-8859-1?q?=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hrouti?=
 =?iso-8859-2?q?ly_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
 =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC5LiA?=
 =?utf-8?b?6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn44Gf44KJ?=
 =?utf-8?b?44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFzIE51bnN0dWNr?=
 =?utf-8?b?IGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWloZXJodW5kIGRhcyBPZGVyIGRp?=
 =?utf-8?b?ZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI3jgajoqIDjgaPjgabjgYTjgb7jgZk=?=
 =?utf-8?b?44CC?=

rv��
maxlinelena	=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerde?=
 =?iso-8859-1?q?rband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndis?=
 =?iso-8859-1?q?chen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klinge?=
 =?iso-8859-1?q?n_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se?=
 =?iso-8859-2?q?_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
 =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb?=
 =?utf-8?b?44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go?=
 =?utf-8?b?44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBp?=
 =?utf-8?b?c3QgZGFzIE51bnN0dWNrIGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWlo?=
 =?utf-8?b?ZXJodW5kIGRhcyBPZGVyIGRpZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI0=?=
 =?utf-8?b?44Go6KiA44Gj44Gm44GE44G+44GZ44CC?=)
r�r	r
�appendrrrr�r�r�)r0r1r��cz�utf8�g_head�cz_head�	utf8_headr�r2r�r3r3r4�test_long_nonstring�s"
z#TestLongHeaders.test_long_nonstringcCs$|j}tddd�}||��d�dS)N�iwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"�X-Foobar-Spoink-Defrobnitr��jwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"�r�r
r��r0r1r�r3r3r4�test_long_header_encode�s
�z'TestLongHeaders.test_long_header_encodecCs&|j}tdddd�}||��d�dS)Nr�r�r��r�r�r�r�r�r3r3r4�<test_long_header_encode_with_tab_continuation_is_just_a_hint�s�zLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hintcCs&|j}tdddd�}||��d�dS)Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r�r�r�zjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r�r�r3r3r4�-test_long_header_encode_with_tab_continuation�s�z=TestLongHeaders.test_long_header_encode_with_tab_continuationcCstdd�}|�|��d�dS)N�文r��=?iso-2022-jp?b?GyRCSjgbKEI=?=�r
r,r��r0r�r3r3r4�0test_header_encode_with_different_output_charset�s
z@TestLongHeaders.test_header_encode_with_different_output_charsetcCs(td�d�d�}d}|�|��|�dS)Ns6test-ja ����Ƥ��줿�᡼��ϻʲ�Ԥξ�ǧ���ԤäƤ��ޤ�r�z�=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r
rOr,r�)r0r��resr3r3r4�5test_long_header_encode_with_different_output_charset�s��zETestLongHeaders.test_long_header_encode_with_different_output_charsetcCs@|j}td�}d|d<t�}t|�}|�|�||��d�dS)Nr)r�r�z�Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"

)r�rrrr�r�r�r3r3r4�test_header_splitter�s�
z$TestLongHeaders.test_header_splittercCsd|j}t�}d|d<t�dd�td�D��|d<|�d�t�}t|�}|�|�||�	�d�dS)	N�test@dom.ainr�css|]}d|VqdS)z<%d@dom.ain>Nr3�rk�ir3r3r4�	<genexpr>rnz@TestLongHeaders.test_no_semis_header_splitter.<locals>.<genexpr>�
�
References�Testz�From: test@dom.ain
References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
 <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>

Test)
r�r�SPACEr��rangerIrrr�r�r�r3r3r4�test_no_semis_header_splitter�s

z-TestLongHeaders.test_no_semis_header_splittercCs |j}td�}||��d�dS)Nz�Subject: the first part of this is short, but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfz�Subject: the first part of this is short,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfr�r�r3r3r4�"test_last_split_chunk_does_not_fitsz2TestLongHeaders.test_last_split_chunk_does_not_fitcCs |j}td�}||��d�dS)Nz_, but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfz`,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfr�r�r3r3r4�>test_splittable_leading_char_followed_by_overlong_unsplittableszNTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplittablecCs |j}td�}||��d�dS)Nza, , but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfzb, ,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfr�r�r3r3r4�Gtest_multiple_splittable_leading_char_followed_by_overlong_unsplittable szWTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplittablecCs |j}td�}||��d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;r�r�r3r3r4�1test_trailing_splittable_on_overlong_unsplittable)szATestLongHeaders.test_trailing_splittable_on_overlong_unsplittablecCs |j}td�}||��d�dS)NzW; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; zX;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; r�r�r3r3r4�Itest_trailing_splittable_on_overlong_unsplittable_with_leading_splittable0szYTestLongHeaders.test_trailing_splittable_on_overlong_unsplittable_with_leading_splittablecCs |j}td�}||��d�dS)NzpThis is a long line that has two whitespaces  in a row.  This used to cause truncation of the header when foldedzqThis is a long line that has two whitespaces  in a row.  This used to cause
 truncation of the header when foldedr�r�r3r3r4�5test_long_header_with_multiple_sequential_split_chars9szETestLongHeaders.test_long_header_with_multiple_sequential_split_charscCs |j}td�}||��d�dS)N�Kthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr�r�r3r3r4�:test_splitter_split_on_punctuation_only_if_fws_with_headerAszJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headercCs |j}td�}||��d�dS)Nz�this is a  test where we need to have more than one line before; our final line that is just too big to fit;; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;z�this is a  test where we need to have more than one line before;
 our final line that is just too big to fit;;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;r�r�r3r3r4�Dtest_leading_splittable_in_the_middle_just_before_overlong_last_partHszTTestLongHeaders.test_leading_splittable_in_the_middle_just_before_overlong_last_partcCs |j}td�}||��d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself r�r�r3r3r4�/test_overlong_last_part_followed_by_split_pointSsz?TestLongHeaders.test_overlong_last_part_followed_by_split_pointcCs |j}td�}||��d�dS)Nz�this_is_a__test_where_we_need_to_have_more_than_one_line_before_our_final_line_; ; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; z�this_is_a__test_where_we_need_to_have_more_than_one_line_before_our_final_line_;
 ;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; r�r�r3r3r4�@test_multiline_with_overlong_parts_separated_by_two_split_pointsZszPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointscCs |j}td�}||��d�dS)Nz�this is a test where we need to have more than one line before our final line; ; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; z�this is a test where we need to have more than one line before our final line;
 ;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; r�r�r3r3r4�>test_multiline_with_overlong_last_part_followed_by_split_pointeszNTestLongHeaders.test_multiline_with_overlong_last_part_followed_by_split_pointcCs\|j}t�}d|d<t�dgd�|d<|�d�t�}t|�}|�|�||��d�dS)Nr�r�z<foo@dom.ain>  r�r�r�z�From: test@dom.ain
References: <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>
   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>
   <foo@dom.ain>   <foo@dom.ain>  

Test�	r�rr�r�rIrrr�r�r�r3r3r4�%test_long_header_with_whitespace_runsps

z5TestLongHeaders.test_long_header_with_whitespace_runscCs`|j}t�}d|d<t�dgd�d|d<|�d�t�}t|�}|�|�||��d�dS)	Nr�r�z
<foo@dom.ain>r�z; abcr�r�z�From: test@dom.ain
References: <foo@dom.ain> <foo@dom.ain> <foo@dom.ain> <foo@dom.ain>
 <foo@dom.ain> <foo@dom.ain> <foo@dom.ain> <foo@dom.ain> <foo@dom.ain>
 <foo@dom.ain>; abc

Testr�r�r3r3r4�'test_long_run_with_semi_header_splitter�s

z7TestLongHeaders.test_long_run_with_semi_header_splittercCsP|j}t�}d|d<d|d<|�d�t�}t|�}|�|�||��d�dS)Nr�r�r�r�r�zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r�rrIrrr�r�r�r3r3r4�.test_splitter_split_on_punctuation_only_if_fws�s

z>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fwscCs:|j}d}t|�}||��d�td�}||��d�dS)Nz\References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr�r�r3r3r4�test_no_split_long_header�sz)TestLongHeaders.test_no_split_long_headercCs(|j}d}t|dd�}||��d�dS)NaWfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
r�r�a_from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)r�r�r3r3r4�"test_splitting_multiple_long_lines�sz2TestLongHeaders.test_splitting_multiple_long_linescCs,|j}d}t|dddd�}||��d�dS)Nz�from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93] helo=cthulhu.gerg.ca)
	by kronos.mems-exchange.org with esmtp (Exim 4.05)
	id 17k4h5-00034i-00
	for test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400�NZReceivedr�)r�r�r�z�from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93]
 helo=cthulhu.gerg.ca)
	by kronos.mems-exchange.org with esmtp (Exim 4.05)
	id 17k4h5-00034i-00
	for test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400r�r�r3r3r4�&test_splitting_first_line_only_is_long�s�z6TestLongHeaders.test_splitting_first_line_only_is_longcCsf|j}t�}tdddd�}|�d�||jdd�d�||d<||jdd	�d
�||jdd	�d�dS)
NzBritische Regierung gibtr6rir�u-grünes Licht für Offshore-Windkraftprojektervr�zl=?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offs?=
 =?iso-8859-1?q?hore-Windkraftprojekte?=�ZmaxheaderlenzwSubject: =?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offs?=
 =?iso-8859-1?q?hore-Windkraftprojekte?=

rzdSubject: =?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offshore-Windkraftprojekte?=

)r�rr
r�r�r�)r0r1r2r�r3r3r4�test_long_8bit_header�s�
z%TestLongHeaders.test_long_8bit_headercCsV|j}t�}d}||d<||jdd�d�t�}t|dd�|d<||jdd�d�dS)NuhBritische Regierung gibt grünes Licht für Offshore-Windkraftprojekte <a-very-long-address@example.com>zReply-Tor�r�z�Reply-To: =?utf-8?q?Britische_Regierung_gibt_gr=C3=BCnes_Licht_f=C3=BCr_Offs?=
 =?utf-8?q?hore-Windkraftprojekte_=3Ca-very-long-address=40example=2Ecom=3E?=

r�)r�rr�r
)r0r1r2Z
header_stringr3r3r4� test_long_8bit_header_no_charset�s�
z0TestLongHeaders.test_long_8bit_header_no_charsetcCs.|j}d}t�}||d<||jdd�d�dS)Nz�"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>, "Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.edu>, "Someone Test #D" <someone@eecs.umich.edu>r�r�r�z�To: "Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,
 "Someone Test #B" <someone@umich.edu>,
 "Someone Test #C" <someone@eecs.umich.edu>,
 "Someone Test #D" <someone@eecs.umich.edu>

)r�rr�)r0r1r�r2r3r3r4�test_long_to_header�s
z#TestLongHeaders.test_long_to_headercCs2|j}d}t|�}|�d�||jdd�d�dS)NzIThis is an example of string which has almost the limit of header length.zAdd another line.rvr�z\This is an example of string which has almost the limit of header length.
 Add another line.�r�r
r�r��r0r1r�r�r3r3r4�test_long_line_after_appends

z+TestLongHeaders.test_long_line_after_appendcCs.|j}d}t|�}|�d�||��d�dS)NzThis is a shorter line.z!Add another sentence. (Surprise?)z9This is a shorter line. Add another sentence. (Surprise?)r�r�r3r3r4�test_shorter_line_with_appends
�z-TestLongHeaders.test_shorter_line_with_appendcCs2|j}d}d}t|d|d�}||jdd�d�dS)Nz!X-Very-Very-Very-Long-Header-Nameu�Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an südlündischen Wandgemälden vorbei, gegen die rotierenden Klingen befördert. r6r�rvr�a=?iso-8859-1?q?Die_Mieter_treten_hier_e?=
 =?iso-8859-1?q?in_werden_mit_einem_Foerderband_komfortabel_den_Korridor_e?=
 =?iso-8859-1?q?ntlang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei=2C_ge?=
 =?iso-8859-1?q?gen_die_rotierenden_Klingen_bef=F6rdert=2E_?=r�)r0r1�fnZgsr�r3r3r4�test_long_field_name!s
z$TestLongHeaders.test_long_field_namecCs:d}t�}t|dd�|d<||d<|�|jdd�d�dS)	Nz�from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP; Wed, 05 Mar 2003 18:10:18 -0700r�r��
Received-1�
Received-2r�r�a1Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
 Wed, 05 Mar 2003 18:10:18 -0700
Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
 Wed, 05 Mar 2003 18:10:18 -0700

�rr
r�r��r0r�r2r3r3r4�test_long_received_header0s
z)TestLongHeaders.test_long_received_headercCs<d}t�}t|ddd�|d<||d<|�|jdd�d�dS)	Nz�<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")r�r�r�r�r�r�a#Received-1: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
Received-2: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")

r�r�r3r3r4�test_string_headerinst_eqBs�
z)TestLongHeaders.test_string_headerinst_eqcCsJ|j}t�}d}||d<t|dd�|d<d||d<||jdd�d	�dS)
Nz�iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1zFace-2r�r*zFace-3r�r�a�Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

�r�rr
r�)r0r1r2�tr3r3r4�-test_long_unbreakable_lines_with_continuationUsz=TestLongHeaders.test_long_unbreakable_lines_with_continuationcCs*|j}d}t�|�}||jdd�d�dS)Nz�Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700r�r�z�Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700

)r�r�r�r��r0r1r�r2r3r3r4�"test_another_long_multiline_headerms
z2TestLongHeaders.test_another_long_multiline_headercCs>|j}d}t�}||d<t|dd�|d<||jdd�d�dS)Nz�List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>�Listr�r�r�a_List: List-Unsubscribe:
 <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
List: List-Unsubscribe:
 <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>

r�)r0r1r�r2r3r3r4�%test_long_lines_with_different_headerzsz5TestLongHeaders.test_long_lines_with_different_headercCs6tt�d�ddd�}|�|��dt�d�d�dS)Nz�            We're going to pretend this header is in a non-ascii character set
            	to see if line wrapping with encoded words and embedded
               folding white space worksrLr�)r:r�r(z�            =?utf-8?q?We=27re_going_to_pretend_this_header_is_in_a_non-ascii_chara?=
             =?utf-8?q?cter_set?=
             =?utf-8?q?_to_see_if_line_wrapping_with_encoded_words_and_embedded?=
             =?utf-8?q?_folding_white_space_works?=)r
r�r�r,r�r�r3r3r4�*test_long_rfc2047_header_with_embedded_fws�s
��z:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+rnrorp�maxDiffr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r�`sP6	


					
r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestFromManglingcCs"t�|_d|jd<|j�d�dS)Nzaaa@bbb.orgr�z(From the desk of A.A.A.:
Blah blah blah
)rr2rI�r0r3r3r4�setUp�s
zTestFromMangling.setUpcCs2t�}t|dd�}|�|j�|�|��d�dS)NT�Zmangle_from_z<From: aaa@bbb.org

>From the desk of A.A.A.:
Blah blah blah
�rrr�r2r,r��r0r�r�r3r3r4�test_mangled_from�sz"TestFromMangling.test_mangled_fromcCs2t�}t|dd�}|�|j�|�|��d�dS)NFr�z;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
r�r�r3r3r4�test_dont_mangle_from�sz&TestFromMangling.test_dont_mangle_fromcCsTt�}t|dd�}t�t�d��}|�|�|�tdd�|�	��
d�D��d�dS)NTr�a)            From: foo@bar.com
            Mime-Version: 1.0
            Content-Type: multipart/mixed; boundary=XXX

            From somewhere unknown

            --XXX
            Content-Type: text/plain

            foo

            --XXX--

            From somewhere unknowable
            cSsg|]}|�d�rd�qS)z>From rq)r�rur3r3r4rm�s
�zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r(r�)rrr�r�r�r�r�r,rtr�r�)r0r�r�r2r3r3r4�'test_mangle_from_in_preamble_and_epilog�s
�z8TestFromMangling.test_mangle_from_in_preamble_and_epilogcCsRt�d��d�}t�|d�}t�}t|dd�}|�|�|�|�	�|d�dS)Nz�            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: 8bit
            From: aaa@bbb.org

        rLsFrom Rölli
Tr�s
>From Rölli
)
r�r�r�r�r�rrr�r,r�)r0r�r2�br�r3r3r4� test_mangled_from_with_bad_bytes�s
�
z1TestFromMangling.test_mangled_from_with_bad_bytescCst�d��d�}t�|�}dS)Nu�            From: aperson@example.com
            Content-Type: multipart/mixed; boundary="1"
            Content-Transfer-Encoding: È
        rL)r�r�r�r�r�)r0r�r2r3r3r4�$test_multipart_with_bad_bytes_in_cte�s
�z5TestFromMangling.test_multipart_with_bad_bytes_in_cteN)	rnrorpr�r�r�r�r�r�r3r3r3r4r��sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudiocCsDtdd��}|��|_Wd�n1s*0Yt|j�|_dS)N�audiotest.aurs)r$r��
_audiodatar�_au�r0r�r3r3r4r��s(zTestMIMEAudio.setUpcCs|�|j��d�dS)Nzaudio/basic)r,r�rAr�r3r3r4�test_guess_minor_type�sz#TestMIMEAudio.test_guess_minor_typecCs(|j��}|�t�t|d��|j�dS�Nr�)r�rPr,rM�decodebytesr�r��r0�payloadr3r3r4�
test_encoding�s
�zTestMIMEAudio.test_encodingcCs t|jd�}|�|��d�dS)N�fishz
audio/fish)rr�r,rA)r0Zaur3r3r4�test_checkSetMinor�sz TestMIMEAudio.test_checkSetMinorcCs�|j}|jjdddd�||jdd�||jjdd�dd	g�||jjd
dd�d�g}||jjddd�d�|�|jjd|dd
�|�|�|j�d|�|�|�|jjd|dd�|�dS)Nrrr�rrz#attachment; filename="audiotest.au"r��rr))rr�rr)r��Zfailobjr�r)r,r�rr�rB�assertIs�r0r1Zmissingr3r3r4�test_add_header�s4
�
�������zTestMIMEAudio.test_add_headerN�rnrorpr�r�r�r�rr3r3r3r4r��s
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEImagecCsDtdd��}|��|_Wd�n1s*0Yt|j�|_dS)Nrrrs)r$r��_imgdatar�_imr�r3r3r4r�s(zTestMIMEImage.setUpcCs|�|j��d�dS)Nz	image/gif)r,rrAr�r3r3r4r�sz#TestMIMEImage.test_guess_minor_typecCs(|j��}|�t�t|d��|j�dSr�)rrPr,rMr�r�rr�r3r3r4r�s
�zTestMIMEImage.test_encodingcCs t|jd�}|�|��d�dS)Nr�z
image/fish)rrr,rA)r0Zimr3r3r4r�"sz TestMIMEImage.test_checkSetMinorcCs�|j}|jjdddd�||jdd�||jjdd�dd	g�||jjd
dd�d�g}||jjddd�d�|�|jjd|dd
�|�|�|j�d|�|�|�|jjd|dd�|�dS)Nrrrrrrz%attachment; filename="dingusfish.gif"r�r)rrrrr)r�rr)r,rrr�rBrrr3r3r4r&s4
�
�������zTestMIMEImage.test_add_headerNrr3r3r3r4rs
rc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestMIMEApplicationcCs.|j}td�}||��d�||dd�dS)N�������rr;rM)r,rrAr/r3r3r4�test_headers=sz TestMIMEApplication.test_headerscCs:|j}d}t|�}||����d�||jdd�|�dS)Nr
z+vv8/f7/TrN)r,rrP�strip)r0r1�	bytesdatar2r3r3r4�	test_bodyCs
zTestMIMEApplication.test_bodycCs�d}t|tjd�}|�|��dt|��|�|jdd�|�|�|dd�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�|�|dd�dS)Nr
�Z_encoder��TrNr>rU)rr�encode_7or8bitr,rPrtrrr�r�r�r��r0r
r2r�r�Zwireform�msg2r3r3r4�$test_binary_body_with_encode_7or8bitKs

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|tjd�}|�|��dt|��|�|jdd�|�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�dS)Nr
rrTrN)rr�encode_noopr,rPrtrrr�r�r�r�rr3r3r4�!test_binary_body_with_encode_noop\s

z5TestMIMEApplication.test_binary_body_with_encode_noopcCshd}t|tjd�}|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|jdd�|�dS)Ns������rTrN)rrrr,rPrrr�r�r�r�rr3r3r4�0test_binary_body_with_unicode_linend_encode_noopms

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|tjd�}|�|��d�|�|jdd�|�|�|dd�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�|�|dd�dS)Ns������ rz=FA=FB=FC=FD=FE=FF=20TrNr>r<)rrZ
encode_quoprir,rPrrr�r�r�r�rr3r3r4�#test_binary_body_with_encode_quopriys

z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|tjd�}|�|��d�|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�dS)Nr
rz	+vv8/f7/
TrN)rrZ
encode_base64r,rPrrr�r�r�r�rr3r3r4�#test_binary_body_with_encode_base64�s

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
rnrorprrrrrrrr3r3r3r4r	<sr	c@sVeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�d�dd��ZdS)�TestMIMETextcCstd�|_dS�N�hello there)r�_msgr�r3r3r4r��szTestMIMEText.setUpcCs`|j}||j��d�||j�d�d�g}|�|j�d|�|�|�|jjd|dd�|�dS)Nr8r:rFrr�)r,rrArBrrr3r3r4�
test_types�s�zTestMIMEText.test_typescCs&|�|j��d�|�|j���dSr)r,rrP�assertFalse�is_multipartr�r3r3r4�test_payload�szTestMIMEText.test_payloadcCsz|j}tddd�}||��jd�||dd�td�}d|_td|d�}||��jd�||dd�||��d�dS)NrrFr�r9rGrLrP)r,rr?rCr	rVrPrDr3r3r4�test_charset�szTestMIMEText.test_charsetcCs4|j}tddd�}||��jd�||dd�dS)NrrFr�r9rG)r,rr?rCr/r3r3r4�test_7bit_input�szTestMIMEText.test_7bit_inputcCs>|j}td�}||��d�||dd�|�d|���dS)NrrFr9rG)r,rr?r�r�r/r3r3r4�test_7bit_input_no_charset�s
z'TestMIMEText.test_7bit_input_no_charsetcCsPd}|j}t|dd�}||��jd�||dd�||jdd�|�d��dS)N�кирилицаrLr�r9rPTrN)r,rr?Zoutput_charsetrPr�)r0�teststrr1r2r3r3r4�test_utf8_input�szTestMIMEText.test_utf8_inputzBcan't fix because of backward compat in email5, will fix in email6cCsd}|�tt|�dS)Nr%)r��UnicodeEncodeErrorr)r0r&r3r3r4�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
rnrorpr�rr!r"r#r$r'�unittest�skipr)r3r3r3r4r�s	
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�
TestMultipartcCs
tdd��}|��}Wd�n1s(0Ytdddd�}t|dd�}|jd	d
dd�td�}|�|�|�|�d
|d<d|d<d|d<d}t�|�}|ddkr�tj	}ntj
}|dkr�d}	nd}	d|	|df}
t�dt�|��|
|d<||_||_
||_dS)Nrrrs�	multipart�mixedrx�r�rr)r�rrrz$Hi there,

This is the dingus fish.
zBarry <barry@digicool.com>r�z)Dingus Lovers <cravindogs@cravindogs.com>r�zHere is your dingus fishrig�4F�cp�A���r�-�+z %s%04d�$z%a, %d %b %Y %H:%M:%SZDate)r$r�rrrrr_�time�	localtime�timezone�altzone�strftimerr�_txt)r0r�rR�	containerrxZintro�nowZ	timetupleZtzsecsZsignZtzoffsetr3r3r4r��s>&�


��zTestMultipart.setUpcCs�|j}|j}|j}|�|���||��d�|t|���d�|t|jd�|�d�}|�d�}|�	||j
�|�	||j�||��||g�|�|���|�|���dS)Nr]r�rrq)
r,r�rr�r rArtrP�
IndexErrorrr9rr)r0r1�raisesr�Zm0Zm1r3r3r4�test_hierarchy�s

zTestMultipart.test_hierarchycCs$d}t��|�}|�||���dS)Nz�Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY


--BOUNDARY--
)r
r�r�r�)r0r�r2r3r3r4�test_empty_multipart_idempotents
z-TestMultipart.test_empty_multipart_idempotentcCs@tdd�}d|d<d|d<d|d<|�d	�|�|��d
�dS)Nr-r.�	A subjectri�aperson@dom.ainr��bperson@dom.ainr�rxz�Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY

--BOUNDARY--
)rr~r�r��r0�outerr3r3r4�/test_no_parts_in_a_multipart_with_none_epilogues

z=TestMultipart.test_no_parts_in_a_multipart_with_none_epiloguecCsLtdd�}d|d<d|d<d|d<d	|_d	|_|�d
�|�|��d�dS)Nr-r.r@rirAr�rBr�r)rxz�Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY

--BOUNDARY--
)r�preamble�epiloguer~r�r�rCr3r3r4�0test_no_parts_in_a_multipart_with_empty_epilogue.s

z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguecCsV|j}tdd�}d|d<d|d<d|d<|�d	�td
�}|�|�||��d�dS)Nr-r.r@rirAr�rBr�rxr�Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

hello world
--BOUNDARY--
)r�rr~rr_r��r0r1rDr2r3r3r4�test_one_part_in_a_multipartCs


z*TestMultipart.test_one_part_in_a_multipartcCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nr-r.r@rirAr�rBr�r)rrxaContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

hello world
--BOUNDARY--
�r�rrFrr_r~r�rJr3r3r4�1test_seq_parts_in_a_multipart_with_empty_preamble\s


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamblecCs\|j}tdd�}d|d<d|d<d|d<d|_td	�}|�|�|�d
�||��d�dS�Nr-r.r@rirAr�rBr�rrxrIrLrJr3r3r4�0test_seq_parts_in_a_multipart_with_none_preamblexs


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblecCs\|j}tdd�}d|d<d|d<d|d<d|_td	�}|�|�|�d
�||��d�dSrN�r�rrGrr_r~r�rJr3r3r4�0test_seq_parts_in_a_multipart_with_none_epilogue�s


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguecCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nr-r.r@rirAr�rBr�r)rrxrIrPrJr3r3r4�1test_seq_parts_in_a_multipart_with_empty_epilogue�s


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epiloguecCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nr-r.r@rirAr�rBr�r(rrxaContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

hello world
--BOUNDARY--

rPrJr3r3r4�.test_seq_parts_in_a_multipart_with_nl_epilogue�s


z<TestMultipart.test_seq_parts_in_a_multipart_with_nl_epiloguecCs�|j}|�d�}|t|���d�|�d�}||��d�|t|���d�|��D]<}||��d�|t|���d�|�d�}||��d�qTdS)N�
msg_36.txtr�rqzmultipart/alternativezmessage/external-bodyrr8)r,r-rtrPrA)r0r1r2�msg1rt�
subsubpartr3r3r4�test_message_external_body�s


z(TestMultipart.test_message_external_bodycCs"|�d�}|�t|���d�dS)Nz
msg_37.txtr�)r-r,rtrPr[r3r3r4�test_double_boundary�s
z"TestMultipart.test_double_boundarycCs4|j}|�d�}t�}t�||�||��d�dS)Nz
msg_38.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
            text/plain
        text/plain
    text/plain
    text/plain
�r�r-rrZ
_structurer��r0r1r2r�r3r3r4�)test_nested_inner_contains_outer_boundary�s

z7TestMultipart.test_nested_inner_contains_outer_boundarycCs4|j}|�d�}t�}t�||�||��d�dS)Nz
msg_39.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
rYrZr3r3r4�test_nested_with_same_boundarys

z,TestMultipart.test_nested_with_same_boundarycCs|�d�}|�|��d�dS)Nz
msg_40.txtz�MIME-Version: 1.0
Content-Type: text/html; boundary="--961284236552522269"

----961284236552522269
Content-Type: text/html;
Content-Transfer-Encoding: 7Bit

<html></html>

----961284236552522269--
)r-r,r�r[r3r3r4�test_boundary_in_non_multiparts
z,TestMultipart.test_boundary_in_non_multipartcCsB|j}t�d�}|�|���||��d�|t|���d�dS)Nz�MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="    XXXX"

--    XXXX
Content-Type: text/plain


--    XXXX
Content-Type: text/plain

--    XXXX--
z    XXXXr�)r,r�r�r�r ryrtrPr/r3r3r4� test_boundary_with_leading_space+s


z.TestMultipart.test_boundary_with_leading_spacecCs&t��d�}|�|�d���d�dS)Nz�Content-Type: multipart/mixed; boundary="===============0012394164=="
MIME-Version: 1.0

--===============0012394164==
Content-Type: image/file1.jpg
MIME-Version: 1.0
Content-Transfer-Encoding: base64

YXNkZg==
--===============0012394164==--rzYXNkZg==)r
r�r,rPrkr3r3r4�&test_boundary_without_trailing_newline>sz4TestMultipart.test_boundary_without_trailing_newlinecCs tdd�}|�|jtjj�dS)Nr-r.)rrr�r��compat32rkr3r3r4�test_mimebase_default_policyLs
z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|�|jtjj�dS)Nr-r.r�)rr�r��defaultrrkr3r3r4�test_mimebase_custom_policyPsz)TestMultipart.test_mimebase_custom_policyN)rnrorpr�r>r?rErHrKrMrOrQrRrSrWrXr[r\r]r^r_rarcr3r3r3r4r,�s($
r,c@s~eZdZdd�Zdd�Zdd�Ze�d�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�TestNonConformantcCs>|j}|�d�}||��d�||��d�||��d�dS)Nz
msg_14.txtr8r�r))r,r-rArr+r/r3r3r4�test_parse_missing_minor_typeWs

z/TestNonConformant.test_parse_missing_minor_typecCsN|�d�}|�d�}|�t|d��|�t|j�d�|�|jdtj	�dS)N�
msg_15.txtrrJrq)
r-rPr��hasattrr,rtrJrIr�StartBoundaryNotFoundDefect)r0r2�innerr3r3r4�test_same_boundary_inner_outer_s

�z0TestNonConformant.test_same_boundary_inner_outercCsX|�d�}|�|��t�|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_25.txtr�rrq)
r-rIrPr�r,rtrJr�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefectr[r3r3r4�test_multipart_no_boundaryis
��z,TestNonConformant.test_multipart_no_boundarya^        Date: Wed, 14 Nov 2007 12:56:23 GMT
        From: foo@bar.invalid
        To: foo@bar.invalid
        Subject: Content-Transfer-Encoding: base64 and multipart
        MIME-Version: 1.0
        Content-Type: multipart/mixed;
            boundary="===============3344438784458119861=="{}

        --===============3344438784458119861==
        Content-Type: text/plain

        Test message

        --===============3344438784458119861==
        Content-Type: application/octet-stream
        Content-Transfer-Encoding: base64

        YWJj

        --===============3344438784458119861==--
        cCs<|�|j�d��}|�t|j�d�|�|jdtj�dS)Nz"
Content-Transfer-Encoding: base64rqr)	�_str_msg�
multipart_msgrar,rtrJrIrZ-InvalidMultipartContentTransferEncodingDefectr[r3r3r4�test_multipart_invalid_cte�s
��z,TestNonConformant.test_multipart_invalid_ctecCs(|�|j�d��}|�t|j�d�dS)Nr)r�rnrorar,rtrJr[r3r3r4�test_multipart_no_cte_no_defect�sz1TestNonConformant.test_multipart_no_cte_no_defectcCs8dD].}|�|j�d�|���}|�t|j�d�qdS)N)r}rUZBINaryz
Content-Transfer-Encoding: {}rrq)r0r�r2r3r3r4�"test_multipart_valid_cte_no_defect�s��z4TestNonConformant.test_multipart_valid_cte_no_defectcCs�|j}|j}t�}d|d<||��d�||��d�||��d�|d=d|d<||��d�||��d�||��d�t�}t|�}|�|�||�	�d�dS)Nr�r=r)r8r9r�zContent-Type: foo

)
r,r�rrr+rArrr�r�)r0r1�neqr2r�r�r3r3r4�test_invalid_content_type�s 
z+TestNonConformant.test_invalid_content_typecCs"|j}|�d�}||��d�dS)N�
msg_31.txtzm--BOUNDARY
Content-Type: text/plain

message 1

--BOUNDARY
Content-Type: text/plain

message 2

--BOUNDARY--
)r�r-rPr/r3r3r4�test_no_start_boundary�s
z(TestNonConformant.test_no_start_boundarycCs"|j}|�d�}||��d�dS)Nz
msg_35.txtz�From: aperson@dom.ain
To: bperson@dom.ain
Subject: here's something interesting

counter to RFC 2822, there's no separating newline here
)r�r-r�r/r3r3r4�test_no_separating_blank_line�s
z/TestNonConformant.test_no_separating_blank_linecCsX|�d�}|�t|d��|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_41.txtrJr�rrq)
r-r�rgr,rtrJrIrrkrlr[r3r3r4�test_lying_multipart�s
��z&TestNonConformant.test_lying_multipartcCsD|�d�}|�d��d�}|�t|j�d�|�|jdtj�dS)Nz
msg_42.txtrqr)r-rPr,rtrJrIrrh)r0rDZbadr3r3r4�test_missing_start_boundary�s
	�z-TestNonConformant.test_missing_start_boundarycCsj|j}d}t�|�}||��dg�||��d�|t|j�d�|�|jtj	g�||jdj
d�dS)Nz Line 1
Subject: test

bodyri�bodyrqrz Line 1
)r,r�r�rArPrtrJ�assertDefectsEqualrZ#FirstHeaderLineIsContinuationDefect�liner�r3r3r4�&test_first_line_is_continuation_header�s
�z8TestNonConformant.test_first_line_is_continuation_headercCsB|�d�}|�|��dg�|�|��d�|�|jtjg�dS)Nz&Subject: test
not a header
To: abc

b
riznot a header
To: abc

b
)rnr,rArPr|rJrZ MissingHeaderBodySeparatorDefectr[r3r3r4�"test_missing_header_body_separator�s
�z4TestNonConformant.test_missing_header_body_separatorN)rnrorprerjrmr�r�rorprrrsrurwrxryrzr~rr3r3r3r4rdUs
	

rdc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestRFC2047cCsN|j}d}t|�}||gd��t|�}|t|�d�|�|jdd�d�dS)NzVRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=))sRe: N�s
r�ksm�rg�szmac-iceland)s
 baz foo bar Nr�u+Re: räksmörgås baz foo bar räksmörgåsrvr�ziRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?=
 =?mac-iceland?q?=9Arg=8Cs?=)r,rrr�r�r��r0r1r��dhr�r3r3r4�test_rfc2047_multiline	s�z"TestRFC2047.test_rfc2047_multilinecCs:|j}d}t|�}||ddg�tt|��}||d�dS)Nz0=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>)sAndr�r6)s Pirard <pirard@dom.ain>NuAndré Pirard <pirard@dom.ain>�r,rr�rr�r3r3r4�test_whitespace_keeper_unicode	s�z*TestRFC2047.test_whitespace_keeper_unicodecCs:|j}d}t|�}||gd��tt|��}||d�dS)NzWThe =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?=))sThe N)squick brown foxr6)s jumped over the N)slazy dogr6z,The quick brown fox jumped over the lazy dogr�)r0r1r�r�Zhur3r3r4� test_whitespace_keeper_unicode_2	sz,TestRFC2047.test_whitespace_keeper_unicode_2cCs d}t|�}|�|gd��dS)Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord))sSmN���r6)srgN���r6)ssbordN�rr,�r0r�r�r3r3r4�test_rfc2047_missing_whitespace(	sz+TestRFC2047.test_rfc2047_missing_whitespacecCs d}t|�}|�|gd��dS)Nz7Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord))sSm Nr�)s rg Nr�)s sbordNr�r�r3r3r4�test_rfc2047_with_whitespace/	sz(TestRFC2047.test_rfc2047_with_whitespacecCs<d}gd�}|D]&\}}t||�}|�||dfg�qdS)Nz=?iso-8859-1?B?%s?=))zdm==�v)zdm=r�)Zdmr�)zdmk=�vi)Zdmkr�r6r�)r0r�rR�q�ar�r3r3r4�test_rfc2047_B_bad_padding6	s
z&TestRFC2047.test_rfc2047_B_bad_paddingcCsd}|�t|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=)sandr�=zzr6�r,r�r0r�r3r3r4�test_rfc2047_Q_invalid_digits@	s
�z)TestRFC2047.test_rfc2047_Q_invalid_digitscCsd}|�t|�gd��dS)Nz(=?ISO-8859-1?Q?a?=))��(N��ar6��)Nr�r�r3r3r4�test_rfc2047_rfc2047_1F	s
�z"TestRFC2047.test_rfc2047_rfc2047_1cCsd}|�t|�gd��dS)Nz(=?ISO-8859-1?Q?a?= b))r�r�)s b)Nr�r�r3r3r4�test_rfc2047_rfc2047_2L	s
�z"TestRFC2047.test_rfc2047_rfc2047_2cCsd}|�t|�gd��dS)Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)�r�)sabr6r�r�r�r3r3r4�test_rfc2047_rfc2047_3R	s
�z"TestRFC2047.test_rfc2047_rfc2047_3cCsd}|�t|�gd��dS)Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r�r�r�r3r3r4�test_rfc2047_rfc2047_4X	s
�z"TestRFC2047.test_rfc2047_rfc2047_4cCsd}|�t|�gd��dS)Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r3r3r4�test_rfc2047_rfc2047_5a^	s
�z#TestRFC2047.test_rfc2047_rfc2047_5acCsd}|�t|�gd��dS)Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r3r3r4�test_rfc2047_rfc2047_5bd	s
�z#TestRFC2047.test_rfc2047_rfc2047_5bcCsd}|�t|�gd��dS)Nz(=?ISO-8859-1?Q?a_b?=))r�)sa br6r�r�r�r3r3r4�test_rfc2047_rfc2047_6j	s
�z"TestRFC2047.test_rfc2047_rfc2047_6cCsPd}|�t|�gd��|�tt|����|���|�ttt|���d�dS)Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))r�r�)s brar�z(a b))r,rrr�r�r�r�r3r3r4�test_rfc2047_rfc2047_7p	s
�z"TestRFC2047.test_rfc2047_rfc2047_7cCsVd}|�t|�ddg�|�tt|����d�|����|�ttt|���d�dS)Nz9=?windows-1252?q?=22M=FCller_T=22?=
 <T.Mueller@xxx.com>)s
"M�ller T"zwindows-1252)s<T.Mueller@xxx.com>Nr)u"Müller T" <T.Mueller@xxx.com>)r,rrr�r��
splitlinesr�r�r3r3r4�test_multiline_headery	s
����z!TestRFC2047.test_multiline_headerN)rnrorpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r�	s 		
	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestMIMEMessagecCs6td��}|��|_Wd�n1s(0YdS)N�
msg_11.txt)r$r�Z_textr�r3r3r4r��	s
zTestMIMEMessage.setUpcCs|�ttd�dS)Nza plain string)r�r^rr�r3r3r4�test_type_error�	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||��d�|��}|�|t�|t|�d�|d}|�||�||d|�dS)Nz
A sub-messagerirrqr�subject)	r,rrrArPrI�listrtr)r0r1r�r��rr�rtr3r3r4�test_valid_argument�	sz#TestMIMEMessage.test_valid_argumentcCs:t�}d|d<t�}d|d<t|�}|�tj|j|�dS)N�	subpart 1riz	subpart 2)rrr�r�MultipartConversionErrorr_)r0rUrr�r3r3r4�test_bad_multipart�	sz"TestMIMEMessage.test_bad_multipartcCsTt�}d|d<|�d�t|�}d|d<t�}t|�}|�|�|�|��d�dS)N�An enclosed messageri�!Here is the body of the message.
zThe enclosing messagez�Content-Type: message/rfc822
MIME-Version: 1.0
Subject: The enclosing message

Subject: An enclosed message

Here is the body of the message.
)rrIrrrr�r,r�)r0r�r�r�r�r3r3r4�
test_generate�	s

zTestMIMEMessage.test_generatecCst|j}|�d�}||��d�|��}|�|t�|t|�d�|d}|�|t�||dd�||��d�dS)Nr�rrqrr�r�r�)r,r-rArPrIr�rtr)r0r1r2r�Zsubmsgr3r3r4�test_parse_message_rfc822�	s
z)TestMIMEMessage.test_parse_message_rfc822cCs�|j}|�d�}||��d�|�|���|t|���d�|�d�}||��d�||��d�|�d�}||��d�|t|���d	�|�d�}|�|t�||d
d�||j	dd
d�d�||j	dd
d�d�|�d�}|�|t�||dd�||j
dd�ddg�||j	ddd�d�|�d	�}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�||dd�dS)N�
msg_16.txtr�r�rr8a�This report relates to a message you sent with the following header fields:

  Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
  Date: Sun, 23 Sep 2001 20:10:55 -0700
  From: "Ian T. Henry" <henryi@oxy.edu>
  To: SoCal Raves <scr@socal-raves.org>
  Subject: [scr] yeah for Ians!!

Your message cannot be delivered to the following recipients:

  Recipient address: jangel1@cougar.noc.ucla.edu
  Reason: recipient reached disk quota

rqzmessage/delivery-statusr�zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnsz
reporting-mtar�r)Znsd�actionZfailedzoriginal-recipient)r-r))zjangel1@cougar.noc.ucla.edur)r-zfinal-recipientr�
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r,r-rAr�r rtrPrIrrBr�r�)r0r1r2rtZdsn1Zdsn2r�rVr3r3r4�test_dsn�	sD




�
�zTestMIMEMessage.test_dsnc	Cs�|j}td��}|��}Wd�n1s,0Yt�}d|d<d|d<d|d<d|_d	|_td
�}td�}|jdd
dd�|�|�|�|�t	�}t
|�}|�|�||��|�dS)N�
msg_21.txtrAr�rBr�r�ri�MIME messagezEnd of MIME message
r9r;r=r]rxr/)
r�r$r�rrFrGrrr_rrr�r�)	r0r1r�r�r2rUrr�r�r3r3r4�
test_epilogue�	s$
&


zTestMIMEMessage.test_epiloguecCsv|j}t�}d|d<d|d<d|d<d|_d|_td	�}td
�}|jddd
d�|�|�|�|�||��d�dS)NrAr�rBr�r�rir�r)r9r;r=r]rxr/adFrom: aperson@dom.ain
To: bperson@dom.ain
Subject: Test
Content-Type: multipart/mixed; boundary="BOUNDARY"

MIME message
--BOUNDARY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

One
--BOUNDARY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

Two
--BOUNDARY--
)r�rrFrGrrr_r�)r0r1r2rUrr3r3r4�test_no_nl_preamble
s

z#TestMIMEMessage.test_no_nl_preamblecCs�|j}td��}t�|�}Wd�n1s.0Y|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nrrrrqr8�r,r$r��message_from_filerP�get_default_typerA�r0r1r�r2Z
container1Z
container2Zcontainer1aZcontainer2ar3r3r4�test_default_type3
s
(



z!TestMIMEMessage.test_default_typecCs�|j}td��}t�|�}Wd�n1s.0Y|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nrrrrqr8r�r�r3r3r4�.test_default_type_with_explicit_container_typeD
s
(



z>TestMIMEMessage.test_default_type_with_explicit_container_typecCs�|j}|j}tdd�}d|_td�}td�}t|�}t|�}|�|�|�|�||��d�||��d�||��d�||��d�||�	d�d�|d	=|d
=|d	=|d
=||��d�||��d�||��d�||��d�||�	d�d�dS)NZdigestrxr)�
message 1
�
message 2
rra�Content-Type: multipart/digest; boundary="BOUNDARY"
MIME-Version: 1.0

--BOUNDARY
Content-Type: message/rfc822
MIME-Version: 1.0

Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

message 1

--BOUNDARY
Content-Type: message/rfc822
MIME-Version: 1.0

Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

message 2

--BOUNDARY--
r9r7aBContent-Type: multipart/digest; boundary="BOUNDARY"
MIME-Version: 1.0

--BOUNDARY

Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

message 1

--BOUNDARY

Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

message 2

--BOUNDARY--
)
r,r�rrGrrr_rAr�r�)r0r1rtr:Z	subpart1aZ	subpart2aZsubpart1Zsubpart2r3r3r4�test_default_type_non_parsedU
s0


z,TestMIMEMessage.test_default_type_non_parsedcCsZ|j}td�}td�}t||fd�}|t|���d�||�d�|�||�d�|�dS)Nr))Z	_subpartsr�rrq)r,rrrtrP)r0r1Ztext1Ztext2r2r3r3r4�$test_mime_attachments_in_constructor�
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|�|���dSrY)rr�r r[r3r3r4�"test_default_multipart_constructor�
sz2TestMIMEMessage.test_default_multipart_constructorcCs0t�}d|d<d|d<|�|�d�ddg�dS)N�a@b.comr��c@d.comr�)rr,r.r[r3r3r4�test_multipart_default_policy�
sz-TestMIMEMessage.test_multipart_default_policycCs^ttjjd�}d|d<|�t��}d|d<Wd�n1s>0Y|�t|j�d�dS)Nr�r�r�r�z.There may be at most 1 To headers in a message)	rr�r�rbr�r
r,r�Z	exception)r0r2�cmr3r3r4�test_multipart_custom_policy�
s&�z,TestMIMEMessage.test_multipart_custom_policyN)rnrorpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r��	s 9#J	r�c@seZdZdd�Zdd�ZdS)�TestNonMultipartcCstdd�}|�|���dS)Nr�r))rrr r[r3r3r4�"test_nonmultipart_is_not_multipart�
s
z3TestNonMultipart.test_nonmultipart_is_not_multipartcCs.t�}d|d<tdd�}|�tj|j|�dS)Nr�rir�r))rrr�rr�r_)r0r2r�r3r3r4�test_attach_raises_exception�
s
z-TestNonMultipart.test_attach_raises_exceptionN)rnrorpr�r�r3r3r3r4r��
sr�c@s�eZdZdZdd�Zd4dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)5�TestIdempotentr(cCsBt|��}|��}Wd�n1s&0Yt�|�}||fSrY�r$r�r�r��r0rr�rRr2r3r3r4r-�
s
&
zTestIdempotent._msgobjFcCs8|j}t�}t|dd�}|j||d�|||���dS)Nrr�r�)r�rrr�r�)r0r2r�r�r1r�r�r3r3r4�_idempotent�
s
zTestIdempotent._idempotentcCs�|j}|�d�\}}||��d�||��d�||��d�||��dd�||�d�d�||jd�||jd�|�	||�dS)	Nr{r8r�r)rq)r:rFr:rF)
r,r-rArr+r�rBrFrGr��r0r1r2r�r3r3r4�test_parse_text_message�
sz&TestIdempotent.test_parse_text_messagecCsP|j}|�d�\}}||��d�||��d�||�d�d�|�||�dS)Nr}r8r:)r,r-rAr�rBr�r�r3r3r4�test_parse_untyped_message�
sz)TestIdempotent.test_parse_untyped_messagecCs|�d�\}}|�||�dS)Nrg�r-r��r0r2r�r3r3r4�test_simple_multipart�
sz$TestIdempotent.test_simple_multipartcCs|�d�\}}|�||�dS)N�
msg_02.txtr�r�r3r3r4�test_MIME_digest�
szTestIdempotent.test_MIME_digestcCs|�d�\}}|�||�dS)Nz
msg_27.txtr�r�r3r3r4�test_long_header�
szTestIdempotent.test_long_headercCs|�d�\}}|�||�dS)Nrr�r�r3r3r4�"test_MIME_digest_with_part_headers�
sz1TestIdempotent.test_MIME_digest_with_part_headerscCs|�d�\}}|�||�dS)N�
msg_06.txtr�r�r3r3r4�test_mixed_with_imagesz$TestIdempotent.test_mixed_with_imagecCs|�d�\}}|�||�dS)Nr�r�r�r3r3r4�test_multipart_reportsz$TestIdempotent.test_multipart_reportcCs|�d�\}}|�||�dS)Nr�r�r�r3r3r4r�
szTestIdempotent.test_dsncCs|�d�\}}|�||�dS)Nr�r�r�r3r3r4�test_preamble_epiloguesz%TestIdempotent.test_preamble_epiloguecCs|�d�\}}|�||�dS)Nz
msg_23.txtr�r�r3r3r4�test_multipart_one_partsz&TestIdempotent.test_multipart_one_partcCs|�d�\}}|�||�dS)Nz
msg_24.txtr�r�r3r3r4�test_multipart_no_partssz&TestIdempotent.test_multipart_no_partscCs|�d�\}}|�||�dS)Nrvr�r�r3r3r4rwsz%TestIdempotent.test_no_start_boundarycCs|�d�\}}|�||�dS)N�
msg_32.txtr�r�r3r3r4�test_rfc2231_charsetsz#TestIdempotent.test_rfc2231_charsetcCs|�d�\}}|�||�dS)Nz
msg_33.txtr�r�r3r3r4�test_more_rfc2231_parameters"sz+TestIdempotent.test_more_rfc2231_parameterscCs|�d�\}}|�||�dS)Nz
msg_34.txtr�r�r3r3r4�%test_text_plain_in_a_multipart_digest&sz4TestIdempotent.test_text_plain_in_a_multipart_digestcCs|�d�\}}|�||�dS)Nzmsg_12a.txtr�r�r3r3r4�test_nested_multipart_mixeds*sz+TestIdempotent.test_nested_multipart_mixedscCs|�d�\}}|�||�dS)NrTr�r�r3r3r4�%test_message_external_body_idempotent.sz4TestIdempotent.test_message_external_body_idempotentcCs"|�d�\}}|j||dd�dS)N�
msg_43.txtTr�r�r�r3r3r4�test_message_delivery_status2sz+TestIdempotent.test_message_delivery_statuscCs|�d�\}}|�||�dS�N�
msg_45.txtr�r�r3r3r4�test_message_signed_idempotent6sz-TestIdempotent.test_message_signed_idempotentcCsX|j}|�d�\}}||��d�i}|��D]\}}|||<q.||dd�||dd�||jd|j�||j|j�|t|���d�|�d	�}||��d
�||��d|j�|�d�}||��d
�||��d|j�|�d
�}	||	��d�|�	|	t
�|	��}
|�	|
t�|t|
�d�|
d	}|�	|t
�||��d|j�dS)Nr�r�r�r�r�r�z$This is a MIME-encapsulated message.r�rr8zYadda yadda yaddarqr�r)r,r-rAr�rFr�rGrtrPrIrr�)r0r1r2r��paramsZpkZpvrUrZmsg3r�Zmsg4r3r3r4�test_content_type:s4



z TestIdempotent.test_content_typecCs�|j}|�d�\}}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�|�|��t�||��|j	�dS)Nr�rrqrr8)
r,r-rArPrIr�rtrr�r�)r0r1r2r�r�rUr3r3r4�test_parserYszTestIdempotent.test_parserN)F)rnrorpr�r-r�r�r�r�r�r�r�r�r�r�r�r�r�rwr�r�r�r�r�r�r�r�r�r3r3r3r4r��
s2
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsS)t�TestMiscellaneouscCsjtd��}|��}Wd�n1s&0Yt�|�}t�}t|dd�}|�|�|�||���dS�Nr{rr��	r$r�r�r�rrr�r,r��r0r�r�r2r�r�r3r3r4�test_message_from_stringms
&

z*TestMiscellaneous.test_message_from_stringcCsttd��X}|��}|�d�t�|�}t�}t|dd�}|�|�|�||�	��Wd�n1sf0YdSr�)
r$r��seekr�r�rrr�r,r�r�r3r3r4�test_message_from_filexs



z(TestMiscellaneous.test_message_from_filecCs�td��}|��}Wd�n1s&0YGdd�dt�}t�||�}|�||�td��}|��}Wd�n1s~0Yt�||�}|��D]}|�||�q�dS)Nr{c@seZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN�rnrorpr3r3r3r4�	MyMessage�sr�r�)r$r�rr�r�rI�walk)r0r�r�r�r2rtr3r3r4�#test_message_from_string_with_class�s
&
&z5TestMiscellaneous.test_message_from_string_with_classcCs�Gdd�dt�}td��}t�||�}Wd�n1s:0Y|�||�td��}t�||�}Wd�n1sz0Y|��D]}|�||�q�dS)Nc@seZdZdS)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageNr�r3r3r3r4r��sr�r{r�)rr$r�r�rIr�)r0r�r�r2rtr3r3r4�!test_message_from_file_with_class�s
*
*z3TestMiscellaneous.test_message_from_file_with_classcCs,Gdd�dt�}|�d|�}|�||�dS)NcseZdZ�fdd�Z�ZS)zSTestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessagecst���dSrY)�super�__init__r���	__class__r3r4r�sz\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)rnrorpr�
__classcell__r3r3rr4r��sr�zSubject: test

test)rrnrI)r0r�r2r3r3r4�.test_custom_message_does_not_require_arguments�sz@TestMiscellaneous.test_custom_message_does_not_require_argumentscCs"td�}|�t|j�gd��dS)Nr�)r r:rr�
feedparserr�r�rr!Zmessage_from_binary_filer�r�r�rwr�r!r)�
__import__r,�sorted�__all__)r0�moduler3r3r4�test__all__�szTestMiscellaneous.test__all__cCs:t��}|�t�t�|��dd�t�|�dd��dS)N�)r4r,r�	parsedate�
formatdate�gmtime�r0r;r3r3r4�test_formatdate�s�z!TestMiscellaneous.test_formatdatecCs>t��}|�t�tj|dd��dd�t�|�dd��dS)NT�r5r)r4r,rr
rr5rr3r3r4�test_formatdate_localtime�s
�z+TestMiscellaneous.test_formatdate_localtimec	CsVt��}|�tj|dd�t�dt�|���|�tj|ddd�t�dt�|���dS)NFrz%a, %d %b %Y %H:%M:%S -0000T)r5Zusegmtz%a, %d %b %Y %H:%M:%S GMT)r4r,rrr8rrr3r3r4�test_formatdate_usegmt�s��z(TestMiscellaneous.test_formatdate_usegmtcCs�|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��dS)Nr)r*�0zA Complete Waste of Timez Wed, 3 Apr 2002 12.34.56.78+0800)rGrr
�parsedate_tzr�r3r3r4�/test_parsedate_returns_None_for_invalid_strings�szATestMiscellaneous.test_parsedate_returns_None_for_invalid_stringscCs|�t�d�t�d��dS)NzWed,3 Apr 2002 14:58:26 +0800zWed, 3 Apr 2002 14:58:26 +0800)r,rr
r�r3r3r4�test_parsedate_compact�s�z(TestMiscellaneous.test_parsedate_compactcCs|j}|t�d�d�dS)N�25 Feb 2003 13:47:26 -0800)
��r���
�/�rrqr0透���r,rr�r0r1r3r3r4�test_parsedate_no_dayofweek�s
�z-TestMiscellaneous.test_parsedate_no_dayofweekcCs|j}|t�d�d�dS)N�5 Feb 2003 13:47:26 -0800�
rr��rrrrrqr0rr r!r3r3r4�#test_parsedate_compact_no_dayofweek�s
�z5TestMiscellaneous.test_parsedate_compact_no_dayofweekcCs|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26+0800)
��r|r���:rrrqr0i�pr r�r3r3r4�.test_parsedate_no_space_before_positive_offset�s�z@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCs|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26-0800)
r'r|r�r(r)rrrqr0rr r�r3r3r4�.test_parsedate_no_space_before_negative_offset�s�z@TestMiscellaneous.test_parsedate_no_space_before_negative_offsetcCs*|j}|t�d�d�|t�d�d�dS)Nz5 Feb 2003 13.47.26 -0800r$z5 Feb 2003 13.47 -0800)
rr�r%rrrrrqr0rr r!r3r3r4�%test_parsedate_accepts_time_with_dots�s
�
�z7TestMiscellaneous.test_parsedate_accepts_time_with_dotscCs�|j}t�d�}tt�|��}|t�|�dd�|dd��|tt�d|��d�t�d�}tt�|dd���}|t�|�dd�|dd��|tt�d|dd���d�dS)Nr#rz%Yr�	)	r,rr
�intr4�mktimer5r8r)r0r1Ztimetupr�r3r3r4�+test_parsedate_acceptable_to_time_functions�s
 
 z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCs(|�t�d�d�|�t�d�d�dS)N)
�rqrqrrrr0r0r0rr)
r1rqrqrrrr0r0r0i�i.���)r,rZ	mktime_tzr�r3r3r4�test_mktime_tzs��z TestMiscellaneous.test_mktime_tzcCs4|�t�d�t�d��|�t�d�t�d��dS)aTest for parsing a date with a two-digit year.

        Parsing a date with a two-digit year should return the correct
        four-digit year. RFC822 allows two-digit years, but RFC2822 (which
        obsoletes RFC822) requires four-digit years.

        z25 Feb 03 13:47:26 -0800rz25 Feb 71 13:47:26 -0800z25 Feb 1971 13:47:26 -0800Nr r�r3r3r4�test_parsedate_y2ks��z$TestMiscellaneous.test_parsedate_y2kcCs.|�t�d�d�|�t�t�d��d�dS)Nz<>�r)r)r)�r,r�	parseaddr�
formataddrr�r3r3r4�test_parseaddr_emptysz&TestMiscellaneous.test_parseaddr_emptycCs:|�t�d�d�|�t�d�d�|�t�d�d�dS)Nza@b@cr4za@b.c@cza@172.17.0.1@c�r,rr6r�r3r3r4�test_parseaddr_multiple_domainss���z1TestMiscellaneous.test_parseaddr_multiple_domainscCs|�t�d�d�dS)N)zA Silly Person�person@dom.ainzA Silly Person <person@dom.ain>�r,rr7r�r3r3r4�test_noquote_dump's�z#TestMiscellaneous.test_noquote_dumpcCsP|�t�d�d�|�t�d�d�d}d}|�t�t�||f��||f�dS)N)zA (Very) Silly Personr;z("A (Very) Silly Person" <person@dom.ain>z*"A \(Very\) Silly Person" <person@dom.ain>zA \(Special\) Personr;�r,rr7r6�r0r�r�r3r3r4�test_escape_dump,s��z"TestMiscellaneous.test_escape_dumpcCs>|�t�d�d�d}d}|�t�t�||f��||f�dS)N)�Arthur \Backslash\ Foobarr;z."Arthur \\Backslash\\ Foobar" <person@dom.ain>rAr;r>r?r3r3r4�test_escape_backslashes7s�z)TestMiscellaneous.test_escape_backslashescCsBd}d}d}d}|�t�||f�|�|�t�||fd�|�dS)N�Häns Würstr;�-=?utf-8?b?SMOkbnMgV8O8cnN0?= <person@dom.ain>z0=?iso-8859-1?q?H=E4ns_W=FCrst?= <person@dom.ain>r6r<)r0r��addr�utf8_base64Z
latin1_quoprir3r3r4�test_quotes_unicode_names?s�z+TestMiscellaneous.test_quotes_unicode_namescsld}d}d}d�G�fdd�d�}|�}d�|f}|�t�||f|�|�|�t�||ftd��|�dS)	NrCr;rDZFOOBARcseZdZ�fdd�ZdS)zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockcs�SrYr3)r0�string�rr3r4�
header_encodePszYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)rnrorprJr3rIr3r4�CharsetMockOsrKz%s <%s>rL)r,rr7r	)r0r�rErFrKZmockZ
mock_expectedr3rIr4�$test_accepts_any_charset_like_objectIs�z6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|�ttj||f|�dS)NrCr;)�objectr��AttributeErrorrr7)r0r�rEZbad_charsetr3r3r4�-test_invalid_charset_like_object_raises_errorXs�z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|�ttjd|f�|�ttjd|f�dS)Nupersön@dom.in�Name)r��UnicodeErrorrr7�r0rEr3r3r4�!test_unicode_address_raises_errorasz3TestMiscellaneous.test_unicode_address_raises_errorcCsVd}d}d\}}|�t�|�||f�|�t�|�||f�|�t�||f�|�dS)NzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>)zJohn X. Doezjxd@example.comr5)r0rM�yr�r�r3r3r4�test_name_with_dotgsz$TestMiscellaneous.test_name_with_dotcCs:|j}|t�d�d�|t�d�d�|t�d�d�dS)N�""example" example"@example.com)r)rV�!"\"example\" example"@example.com)r)rW�#"\\"example\\" example"@example.com)r)rXr9r!r3r3r4�2test_parseaddr_preserves_quoted_pairs_in_addressesps

�
�
�zDTestMiscellaneous.test_parseaddr_preserves_quoted_pairs_in_addressescCs^|�dt�d��|�dt�d��|�dt�d��|�dt�d��|�dt�d	��dS)
N)r)�merwok wok@xample.comrZ)r)�merwok  wok@xample.comr[z merwok  wok  @xample.com)r)�merwok"wok"  wok@xample.comr\)r)zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.comr9r�r3r3r4�-test_parseaddr_preserves_spaces_in_local_part�s�����z?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_partcCs0d}d}|�t�|�|�|�t�|�|�dS)N)z#'foo@example.com' (foo@example.com)�foo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>r5)r0rEZaddrstrr3r3r4�6test_formataddr_does_not_quote_parens_in_quoted_string�szHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_stringcCsd}|�t�|�d�dS)NzFoo
	Bar <foo@example.com>)zFoo Barr^r9)r0rMr3r3r4�test_multiline_from_comment�sz-TestMiscellaneous.test_multiline_from_commentcCs|�t�d�d�dS)N)zA Silly; Personr;z""A Silly; Person" <person@dom.ain>r<r�r3r3r4�test_quote_dump�s�z!TestMiscellaneous.test_quote_dumpcCs�|j}|j}t�}t�}||d�||d�||d�|d|�|d|�|d|�||d�||d�||d�|d|�|d|�|d|�|||�|||�dS)NrF�US-ASCIIzUs-AsCiIZusasciiZUSASCIIZUsAsCiI)r,ZassertNotEqualr	)r0r1�neZcset1Zcset2r3r3r4�test_charset_richcomparisons�s$












z.TestMiscellaneous.test_charset_richcomparisonscCs"|j}|t�ddg�ddg�dS)N�aperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>�z	Al PersonrA)z
Bud PersonrB�r,r�getaddressesr!r3r3r4�test_getaddresses�s���z#TestMiscellaneous.test_getaddressescCs|�t�gd��gd��dS)zGH-106669 regression test.)z"Bud, Person" <bperson@dom.ain>rez#"Mariusz Felisiak" <to@example.com>))zBud, PersonrBrf)zMariusz Felisiak�to@example.comNrgr�r3r3r4�test_getaddresses_comma_in_name�s��z1TestMiscellaneous.test_getaddresses_comma_in_namecCs�d}d}d}dd|�d�|fgfdd|f|d|fgfdd|f|d|f|gfdd|f|d|fgfd	d|�d
|�d�fgfdd|f|d|fgfd
||d|fgfdd|f|d|fgfdd|fd|fgfdd|dfd|fgfdd|fdd|�d�fgffD]�\}}|�|�d|�d�}|j|d��n|�t�|g�|g�|�tj|gdd�|�|�t�|g�|�|�tj|gdd�d|f�Wd�q�1�s�0Yq�|�d|�d�}|�t�|g�d|fd|fg�|�tj|gdd�d|fd|fg�|�t�|g�|�|�tj|gdd�d|f�d}d}|�t�|g�|g�|�tj|gdd�|g�|�t�|g�|�|�tj|gdd�d|f�d}d}|�t�|g�|g�|�tj|gdd�|g�|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�|g�|�tj|gdd�gd��|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�ddg�|�tj|gdd�ddg�|�t�|g�|�|�tj|gdd�d|f�|�tjjd �dS)!z>Test for parsing errors from CVE-2023-27043 and CVE-2019-16056�alice@example.org�bob@example.comr4�(�<�>�)r)�[z[<z>]�]�@�;�:�.�")�addressF��strictNz,<z,"Alice, alice@example.org" <bob@example.com>)zAlice, alice@example.orgrmzalice@example.org (Alice))�Alicerlzalice@example.org )Alice())r)rlr4)r)r|�<"Jane Doe" <jane@example.net>, "John Doe" <john@example.net>)zJane Doezjane@example.net)zJohn Doezjohn@example.netT)�subTestr,rrhr6r�Zsupports_strict_parsing)r0ZaliceZbob�emptyZinvalid_separatorZexpected_non_strictryZexpected_strictr3r3r4�test_parsing_errors�s��
����&�������������z%TestMiscellaneous.test_parsing_errorscCsdgdgfdgdgfddgddgfdgdgfd	gdgfd
ggd�fdgd
gfdgdgfdgdgfdgddgff
D]\\}}|j|d��8|�t�|�|�|�tj|dd�|�Wd�qp1s�0Yqpdg}|�t�|�dg�|�tj|dd�gd��dS)Nu&"Sürname, Firstname" <to@example.com>)uSürname, Firstnamerjzfoo: ;r4z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerz
jason@dom.ainz=Pete(A nice \) chap) <pete(his account)@silly.test(his host)>)z)Pete (A nice ) chap his account his host)zpete@silly.testz<(Empty list)(start)Undisclosed recipients  :(nobody(I know))z=Mary <@machine.tld:mary@example.net>, , jdoe@test   . example))ZMaryzmary@example.netr4)r)zjdoe@test.examplez*John Doe <jdoe@machine(comment).  example>)zJohn Doe (comment)zjdoe@machine.examplez3"Mary Smith: Personal Account" <smith@home.example>)zMary Smith: Personal Accountzsmith@home.examplezUndisclosed recipients:;z7<boss@nil.test>, "Giant; \"Big\" Box" <bob@example.net>)r)z
boss@nil.test)zGiant; "Big" Boxzbob@example.net)�	addressesFrzz	[]*-- =~$)r4r4)r)z*--)r~r,rrh)r0r�r�r3r3r4�test_getaddresses_nasty,
sZ�������������$��z)TestMiscellaneous.test_getaddresses_nastycCs(|j}t�dg�}||ddd�dS)z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>rrq�foo@bar.comNrg)r0r1�addrsr3r3r4�"test_getaddresses_embedded_commentX
sz4TestMiscellaneous.test_getaddresses_embedded_commentcCs(t�td�g�}|�|ddd�dS)z%Test the handling of a Header object.zAl Person <aperson@dom.ain>rrqrAN)rrhr
r,)r0r�r3r3r4�test_getaddresses_header_obj^
sz.TestMiscellaneous.test_getaddresses_header_objcs~Gdd�dt���fdd�td�D�}t|��Wd�n1sD0Ytdd�|D�g�}|�tt|��t|��dS)Nc@seZdZdd�ZdS)zBTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadcSsBg|_|jj}tj}tj}|�d}|�|kr>||dd��q$dS)Ng@�testdomain-string��domain)�msgidsr�r�
make_msgidr4�	monotonic)r0r�r�ZclockZtfinr3r3r4�runf
s

zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)rnrorpr�r3r3r3r4�MsgidsThreade
sr�csg|]
}���qSr3r3r��r�r3r4rmp
rnz@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>r%cSsg|]
}|j�qSr3)r�)rkr�r3r3r4rms
rn)rr�r#�sumr,rt�set)r0ZthreadsZall_idsr3r�r4�test_make_msgid_collisionsc
s
z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||��d�dS)Nrrzfoo\wacky"namer)r,rrrir/r3r3r4�test_utils_quote_unquotev
s�z*TestMiscellaneous.test_utils_quote_unquotecCstd�}|�|��d�dS)Nz
not a charsetrM�r	r,�get_body_encoding�r0r:r3r3r4�)test_get_body_encoding_with_bogus_charset}
sz;TestMiscellaneous.test_get_body_encoding_with_bogus_charsetcCs|j}t�}d|d<||dd�|��}|t|�d�||dd�t|d�}||��d�|jd|d	�||��d
�||jdd�d�||d
d�t�}d|d<|��}|t|�d�||dd�t|d�}||��tj	�|jd|d	�||��d�||d
d�dS)Nztext/plain; charset=UTF-8r=r9rqrrLrMr�r
�aGVsbG8gd29ybGQ=
TrNr;ztext/plain; charset="US-ASCII"rFrr})
r,rrdrtr	r�rIrPrr)r0r1r2rer:r3r3r4�-test_get_body_encoding_with_uppercase_charset�
s.z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs(td�}td�}|�|��|���dS)NrFrbr�)r0ZlcZucr3r3r4�test_charsets_case_insensitive�
sz0TestMiscellaneous.test_charsets_case_insensitivecCs4|j}|�d�}t�}t�||�||��d�dS)Nr�aBmultipart/report
    text/plain
    message/delivery-status
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
    text/rfc822-headers
rYrZr3r3r4�1test_partial_falls_inside_message_delivery_status�
s

zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs"|�tjjdd�dd�d�dS)Nr�r�i��z@testdomain-string>�r,r�rr�r�r3r3r4�test_make_msgid_domain�
s�z(TestMiscellaneous.test_make_msgid_domaincCs$|�tjjddd�dd�d�dS)Nz
test-idstringr�)Zidstringr�i���z!.test-idstring@testdomain-string>r�r�r3r3r4�test_make_msgid_idstring�
s���z*TestMiscellaneous.test_make_msgid_idstringcCsTtd��8}d|_}|�tj���d|d��Wd�n1sF0YdS)Nzsocket.getfqdnzpythontest.example.comrtrp)rZreturn_valuer�r�rr��endswith)r0Zmock_getfqdnr�r3r3r4�test_make_msgid_default_domain�
s



��z0TestMiscellaneous.test_make_msgid_default_domaincCsztddd��}|��}Wd�n1s*0Y|�dd�}t�|�}t�}tj�|�}|�|�|�	|�
�|�dS)N�
msg_26.txtr(��newliner�)r$r�r�r�r�rr�rr�r,r��r0�fZmsgtxtZ	msgtxt_nlr2r�r�r3r3r4�test_Generator_linend�
s&

z'TestMiscellaneous.test_Generator_linendcCs�tddd��}|��}Wd�n1s*0Y|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
��d�|�dS)Nr�r(r�r�r�r�)r$r�r�r�r�rr�rr�r,r�rOr�r3r3r4�test_BytesGenerator_linend�
s&
z,TestMiscellaneous.test_BytesGenerator_linendcCs�tdd��}|��}Wd�n1s(0Y|�dd�}|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
�|�dS)	Nr�rsswith attachmentsfo��
r�r�r�)r$r�r�r�r�rr�rr�r,r�r�r3r3r4�)test_BytesGenerator_linend_with_non_ascii�
s&
z;TestMiscellaneous.test_BytesGenerator_linend_with_non_asciic	CsFtdd��}|��}Wd�n1s(0Ytdd��}|��}Wd�n1sZ0Ytdft|fft|fftt�fftdftdfg}|D]�\}}|j	|j
dd��*||�}|�|jt
jj�Wd�n1s�0Y|j	|j
dd��4||d	t
jji�}|�|jt
jj�Wd�q�1�s60Yq�dS)
Nr�rsrr)r))r-r.r`)�clsr�rbr�)r$r�rrrrrrrr~rnrr�r�r`rb)r0r�Z	audiodatar{�classesr��constructorr�r3r3r4�!test_mime_classes_policy_argument�
s$&&
�0z3TestMiscellaneous.test_mime_classes_policy_argumentcCs8|�tt�d��gd��|�tt�d��ddg�dS)Nza\\b\"c\\"d)�rr�)r��\\)r�r�)r%z\")r�c)�r�)r-rx)r��dza\r�)rq�\)r,r�rZ_iter_escaped_charsr�r3r3r4�test_iter_escaped_charss�	�z)TestMiscellaneous.test_iter_escaped_charscs|�fdd�}|dd�|dd�|dd�|d	d
�|dd�|d
d�|dd�|dd�dD]}��t�|�|�q`dS)Ncs��t�|�|�dSrY�r,rZ_strip_quoted_realnames)rEr�r�r3r4�check!sz<TestMiscellaneous.test_strip_quoted_realnames.<locals>.checkr}z( <jane@example.net>,  <john@example.net>z""Jane \"Doe\"." <jane@example.net>z <jane@example.net>zbefore"name"afterZbeforeafterzbefore"name"Zbeforezb"name"r�z"name"afterZafterz"name"ar�z"name"r))z8Jane Doe <jane@example.net>, John Doe <john@example.net>zlone " quoter�)r0r�rEr3r�r4�test_strip_quoted_realnames s��





z-TestMiscellaneous.test_strip_quoted_realnamescCsvd}|�t�|�d���|�t�|�d���|�t�|�d���|�t�|�d���|�t�d|����dS)Nzalice@example.netz (Alice)z )Alice(z	 (Alice))z	 ((Alice)z")Alice((" )r�rZ_check_parenthesisrrRr3r3r4�test_check_parenthesis9sz(TestMiscellaneous.test_check_parenthesisN)<rnrorpr�r�r�r�rrrrrrrr"r&r*r+r,r0r2r3r8r:r=r@rBrGrLrOrSrUrYr]r_r`rardrirkr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r�lsr



			X,*
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestIteratorscCs�|j}|j}|�d�}t�|�}t|�}|t|�d�|t�|�|�	��|�d�}t�|�}t|�}|t|�d�t
d��$}|t�|�|���Wd�n1s�0YdS)Nr{rr��+z
msg_19.txt)r,r�r-rZbody_line_iteratorr�rt�EMPTYSTRINGr�rPr$r�)r0r1rtr2�itr�r�r3r3r4�test_body_line_iteratorFs




z%TestIterators.test_body_line_iteratorcCsb|j}|�d�}t�|d�}g}d}|D]}|d7}|�|���q(||d�|t�|�d�dS)Nrgr�rrqr�z`a simple kind of mirror
to reflect upon our own
a simple kind of mirror
to reflect upon our own
�r,r-rZtyped_subpart_iteratorr�rPr�r��r0r1r2r�r�Zsubpartsrtr3r3r4�test_typed_subpart_iteratorWs

z)TestIterators.test_typed_subpart_iteratorcCsd|j}|�d�}t�|dd�}g}d}|D]}|d7}|�|���q*||d�|t�|�d�dS)Nr}r�r)rrqz%
Hi,

Do you like this message?

-Me
r�r�r3r3r4�(test_typed_subpart_iterator_default_typehs

z6TestIterators.test_typed_subpart_iterator_default_typecCs�gd�}ddlm}m}|�}g}d}|D]N\}}|�|�||7}d}	t|j|�D]}
|�|
�|	d7}	qT|�||	�q*|�t|�|�|�d�	dd�|D��d�	|��dS)	z�FeedParser BufferedSubFile.push() assumed it received complete
           line endings.  A CR ending one push() followed by a LF starting
           the next push() added an empty line.
        ))za
 
r�)r�r)zc
rq)r)r)zd
rq)ze
r)z
frq)r�rqr��BufferedSubFile�NeedMoreDatarqr)cSsg|]\}}|�qSr3r3)rk�il�nr3r3r4rm�rnz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
�email.feedparserr�r��push�iter�readliner�r,rtr�)r0Zimtr�r��bsfZom�ntr�r�Zn1Zolr3r3r4�test_pushCR_LF{s



zTestIterators.test_pushCR_LFcs�ddlm}m}d}d}d�d��fdd�t|�D��d	}|�d
�}|�}g}tdt|�|�D]0}	||	|	|�}
|�|
�|�t	|j
|��q`|�||�dS)Nrr�i'r%zabcd 	
r)c3s|]}t��VqdSrYrr���charsr3r4r��rnz1TestIterators.test_push_random.<locals>.<genexpr>r(T)r�r�r�r�r�r�rtr��extendr�r�r,)r0r�r�r�Z	chunksizer��targetr�r�r��chunkr3r�r4�test_push_random�s 

zTestIterators.test_push_randomN)rnrorpr�r�r�r�r�r3r3r3r4r�Es
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs"t�}|D]}|�|�q
|��SrY)r&�feed�close)r0�chunksrr�r3r3r4�parse�szTestFeedParsers.parsecCs.|�d�}|�|dd�|�|dd�dS)NzFirst: val
: bad
Second: valr8�valr:)r�r,r[r3r3r4�test_empty_header_name_handled�s
z.TestFeedParsers.test_empty_header_name_handledcCs�|�dg�}|�|��gd��|�dg�}|�|��gd��|�ddg�}|�|��ddg�|�dd	g�}|�|��dd
g�|�ddg�}|�|��dd
g�|�dg�}|�|��d
g�|�gd��}|�|��ddg�dS)Nz
a:
b:
c:
d:
)r�r�r�r�za:
b:
c:
d:za:
b�c:
r�Zbc�a:
zb:
r�z
b:
ua:…b:
c:
)r�u	…b:
c:)r�ub:…r��r�r))r�u…c:)r�r,rArrkr3r3r4�
test_newlines�szTestFeedParsers.test_newlinescCsd\}}|�dgd|g|�}|�|��dg�|�|��d||�|�dgd|g|�}|�|��dg�|�|��d||�|�dgd|dg|�}|�|��dg�|�|��d|d|�|�ddgd|g|�}|�|��d	d
d||fg�dS)N)i�i Nza:b

rM)r�r�za:b

�…r�zb: r�r�)r�r,rrP)r0�M�Nr�r3r3r4�test_long_lines�szTestFeedParsers.test_long_linesN)rnrorpr�r�r�r�r3r3r3r4r��sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdZ
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�TestParserscCs�|j}td��}t��|�}Wd�n1s00Y||dd�||dd�||��d�|�|���|�|��t	�dS)Nr�r��ppp-request@zzz.orgr��ppp@zzz.orgr])
r,r$rr�rArr rIrPr��r0r1r�r2r3r3r4�test_header_parser�s
*zTestParsers.test_header_parsercCs�|j}tdd�� }tj���|�}Wd�n1s60Y||dd�||dd�||��d�|�|���|�	|�
�t�|�	|j
dd	�t�dS)
Nr�rsr�r�r�r�r]TrN)
r,r$r�r�r�r�rArr rIrPr�r�r�r3r3r4�test_bytes_header_parser�s.z$TestParsers.test_bytes_header_parsercCsJtdd��,}tj���|�|�|j�Wd�n1s<0YdS)Nr�rs)r$r�r��BytesParserr�r�closedr�r3r3r4�%test_bytes_parser_does_not_close_file�sz1TestParsers.test_bytes_parser_does_not_close_filecCs`tdd��B}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�n1sR0YdS)Nrfrsr�)r$r�r�r�r�rrhr�r{r�rr�)r0r�ZbytesParserr3r3r4�2test_bytes_parser_on_exception_does_not_close_file�s
�z>TestParsers.test_bytes_parser_on_exception_does_not_close_filecCsJtdd��,}tj���|�|�|j�Wd�n1s<0YdS)Nr�r�)r$r�r�r
r�rr�r�r3r3r4�test_parser_does_not_close_filesz+TestParsers.test_parser_does_not_close_filecCs`tdd��B}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�n1sR0YdS)Nrfr�r�)r$r�r�r
r�rrhr�r{r�rr�)r0r�r�r3r3r4�,test_parser_on_exception_does_not_close_files
�z8TestParsers.test_parser_on_exception_does_not_close_filecCs>|j}t�d�}||dd�||dd�||��d�dS)Nz�From: aperson@dom.ain
To: bperson@dom.ain
Subject: the next line has a space on it
 
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam

Here's the message body
r��!the next line has a space on it
 r��spam�Here's the message body
�r,r�r�rPr/r3r3r4�test_whitespace_continuations


z(TestParsers.test_whitespace_continuationcCs>|j}t�d�}||dd�||dd�||��d�dS)Nz�From: aperson@dom.ain
To: bperson@dom.ain
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam
Subject: the next line has a space on it
 

Here's the message body
r�r�r�r�r�r�r/r3r3r4�(test_whitespace_continuation_last_header s


z4TestParsers.test_whitespace_continuation_last_headercCs�|j}tddd��}t��|�}Wd�n1s40Y|t|���d�|�d�}||��d�||��d�|�d�}||��d	�dS)
Nr�r(r�r�rr8z!Simple email with attachment.

rqzapplication/riscos)r,r$r
r�rtrPrA)r0r1r�r2�part1�part2r3r3r4�test_crlf_separation2s*

z TestParsers.test_crlf_separationcCsntddd��}|��}Wd�n1s*0Yt�|�}t�}t|�}|j|dd�|�|��|�dS)Nr�r(r�r�r�r�r�r3r3r4�test_crlf_flatten=s&
zTestParsers.test_crlf_flattenNc	Cs:|j}|j}td��}t�|�}Wd�n1s40Y||��d�|t|���d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d�dS)	Nrrqr�rrr8r�r�)	r,r�r$r�r�r rtrPrA)	r0r1rtr�r2r�Zpart1ar�Zpart2ar3r3r4�-test_multipart_digest_with_extra_mime_headersIs,
(



z9TestParsers.test_multipart_digest_with_extra_mime_headerscCs,gd�}t�t�|��}|�|dd�dS)N)z$From: Andrew Person <aperson@dom.ainz
Subject: Testz%Date: Tue, 20 Aug 2002 16:43:45 +1000�datezTue, 20 Aug 2002 16:43:45 +1000)r�r�r�r�r,)r0r�r2r3r3r4�test_three_lineshszTestParsers.test_three_linescCsH|j}d}d}d||f}t�|�}||�d�|�||�d�|�dS)Nr�z	more textz'Header: %s
Next-Header: %s

Body

r
zNext-Header)r,r�r��get)r0r1Zvalue1Zvalue2r�r2r3r3r4�3test_strip_line_feed_and_carriage_return_in_headersps�
z?TestParsers.test_strip_line_feed_and_carriage_return_in_headerscCsP|j}d}t�|�}|t|�d�|tdd�|D��gd��||��d�dS)Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyr�css|]
}|VqdSrYr3)rkZfieldr3r3r4r��rnz9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>)z!"#QUX;~z>Fromr�r{)r,r�r�rtrrPr�r3r3r4�test_rfc2822_header_syntax{s
z&TestParsers.test_rfc2822_header_syntaxcCs*|j}d}t�|�}|t|���d�dS)Nz<>From foo@example.com 11:25:53
From: bar
!"#QUX;~: zoo

bodyr)r,r�r�rtrAr�r3r3r4�(test_rfc2822_space_not_allowed_in_header�s
z4TestParsers.test_rfc2822_space_not_allowed_in_headercCsD|j}d}t�|�}|��}|��||gd��||��d�dS)Nz7A: first header
B: second header
CC: third header

body)�A�BZCCr{)r,r�r�rA�sortrP)r0r1r�r2Zheadersr3r3r4�!test_rfc2822_one_character_header�s
z-TestParsers.test_rfc2822_one_character_headercCs,d}t�|�}|�|�d����d��dS)Nz�From: foo@bar.com
To: baz
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=BOUNDARY

--BOUNDARY
Content-Type: text/plain

body ending with CRLF newline

--BOUNDARY--
rr�)r�r�r�rPr��r0r�r2r3r3r4�test_CRLFLF_at_end_of_part�s�
z&TestParsers.test_CRLFLF_at_end_of_part)rnrorpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr3r3r3r4r��s$
	r�c@s�eZdZe�d�Zdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdZd�
dd�eD��d�d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Ze�d*��d�Zd+d,�Zd-d.�Ze�d/�Zd0d1�Zd2d3�Z d4d5�Z!e�"d�Z#d6ge#d7d8�<d�
e#�Z#d9d:�Z$e�d;��d<�Z%e�d=�Z&d>d?�Z'd@dA�Z(dBdC�Z)dDdE�Z*dFdG�Z+dHdI�Z,dJdK�Z-dLZ.dLS)M�Test8BitBytesHandlingz�        From: foo@bar.com
        To: baz
        Mime-Version: 1.0
        Content-Type: text/plain; charset={charset}
        Content-Transfer-Encoding: {cte}

        {bodyline}
        cCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)NrLrU�pöstal�r:r�Zbodyline�pöstal
TrN��bodytest_msgrar�r�r�r,rPrr3r3r4�test_known_8bit_CTE�s��
�z)Test8BitBytesHandling.test_known_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
NZnotavalidcharsetrUrrrLup��stal
TrNr	r
rr3r3r4�test_unknown_8bit_CTE�s��
�z+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)	NrLr<�p=C3=B6stálru
p=C3=B6stál
TrN�	pöstál
r
rr3r3r4�test_8bit_in_quopri_body�s
��
�z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
Nr�r<rrrLup=C3=B6st��l
TrNrr
rr3r3r4�.test_invalid_8bit_in_non_8bit_cte_uses_replace�s��
�zDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replacecCsT|jjdddd��d�}t�|�}|�|jdd�d�d��|�|jdt	j
�dS)	NrLrMu
cMO2c3RhbAá=rTrNrr)rrar�r�r�r,rPrIrJrrKrr3r3r4�test_8bit_in_base64_body�s��
��z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd��d�}t�|�}|�|jdd�d�d��dS)NrLr�u
<,.V<W1A; á rTrNu<,.V<W1A; á 
r
rr3r3r4�test_8bit_in_uuencode_body�s��
�z0Test8BitBytesHandling.test_8bit_in_uuencode_body))zFrom: foo@bar.com�r�r�)uTo: báz)r�z=?unknown-8bit?q?b=C3=A1z?=)uVSubject: Maintenant je vous présente mon collègue, le pouf célèbre
	Jean de Baddie)riz�=?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=
 =?unknown-8bit?q?_Jean_de_Baddie?=)uFrom: göst)r�z=?unknown-8bit?b?Z8O2c3Q=?=r(cCsg|]\}}|�qSr3r3)rk�src�_r3r3r4rmrnz Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
rLcCs:t�|j�}|�t|�d��d�|�t|d�d�dS)Nr��b��z)r�r��headertest_msgr,r�r�r[r3r3r4�test_get_8bit_headersz*Test8BitBytesHandling.test_get_8bit_headercCs8t�|j�}|�t|�t�d�jdd�|jD���dS)Nz�                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            cSsg|]\}}|d�qS)rqr3)rkrr�r3r3r4rm!rnzATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	r�r�rr,r�r�r�ra�headertest_headersr[r3r3r4�test_print_8bit_headerss

���z-Test8BitBytesHandling.test_print_8bit_headerscCs.t�|j�}|�dd�|��D�gd��dS)NcSsg|]}t|��qSr3�r�rur3r3r4rm&rnzGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>)r�r�]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie�	g��st)r�r�r�assertListEqualrBr[r3r3r4�test_values_with_8bit_headers$s�z3Test8BitBytesHandling.test_values_with_8bit_headerscCs.t�|j�}|�dd�|��D�gd��dS)NcSs g|]\}}t|�t|�f�qSr3r)rkrMrTr3r3r4rm1rnzFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>)r)r�r)rir)r�r)r�r�rrrr[r3r3r4�test_items_with_8bit_headers/s�z2Test8BitBytesHandling.test_items_with_8bit_headerscCs0t�|j�}|�dd�|�d�D�ddg�dS)NcSsg|]}t|��qSr3rrur3r3r4rm=rnzHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�r�r)r�r�rrr.r[r3r3r4�test_get_all_with_8bit_headers;s��z4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsJt�t�d��d��}|�|��d�|�|��d�|�|��d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            rZutext/pl�inr�upl�in)	r�r�r�r�r�r,rArr+r[r3r3r4�test_get_content_type_with_8bitAs�z5Test8BitBytesHandling.test_get_content_type_with_8bitcCsXt�d�d��}|�|jdd�gd��|�|jddd�d�|�|jddd�d�dS)	Nu(X-Header: foo=§ne; b§r=two; baz=three
rZr�r�))r���ne)ub�rr�r�ZFoor$ub§r)r�r�r�r,r�rBr[r3r3r4�test_get_params_with_8bitJs��z/Test8BitBytesHandling.test_get_params_with_8bitcCs,t�t�d��d��}|�|�d�d�dS)N�n            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nrZ�title)rF�enuThis is not f�n)r�r�r�r�r�r,rBr[r3r3r4�!test_get_rfc2231_params_with_8bitTs��z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8t�t�d��d��}|�dd�|�|�d�d�dS)Nr&rZr'�test)r�r�r�r�r�r�r,rBr[r3r3r4�!test_set_rfc2231_params_with_8bit\s
�z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFt�t�d��d��}|�d�|�|�d�d�|�|��d�dS)Nr&rZr'r�)	r�r�r�r�r�r�r,rBrr[r3r3r4�!test_del_rfc2231_params_with_8bitds�
z7Test8BitBytesHandling.test_del_rfc2231_params_with_8bitcCs>t�t�d��d��}|�|��d�|�|jdd�d�dS)Nu�            Content-Transfer-Encoding: b§se64
            Content-Type: text/plain; charset=latin-1

            payload
            rZzpayload
TrNspayload
)r�r�r�r�r�r,rPr[r3r3r4�%test_get_payload_with_8bit_cte_headerms
�z;Test8BitBytesHandling.test_get_payload_with_8bit_cte_headeru0        From: foo@bar.com
        To: báz
        Subject: Maintenant je vous présente mon collègue, le pouf célèbre
        	Jean de Baddie
        Mime-Version: 1.0
        Content-Type: text/plain; charset="utf-8"
        Content-Transfer-Encoding: 8bit

        Да, они летят.
        cCs:t�|j�}t�}tj�|��|�|�|��|j�dSrY)	r�r��non_latin_bin_msgrr�rr�r,r��r0r2r�r3r3r4�test_bytes_generator�sz*Test8BitBytesHandling.test_bytes_generatorcCs6tj��}t�}tj�|��|�|�|��d�dS)Nr�)	r�r!rrr�rr�r,r�r/r3r3r4�&test_bytes_generator_handles_None_body�s
z<Test8BitBytesHandling.test_bytes_generator_handles_None_bodya�        From: foo@bar.com
        To: =?unknown-8bit?q?b=C3=A1z?=
        Subject: =?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue?=
         =?unknown-8bit?q?=2C_le_pouf_c=C3=A9l=C3=A8bre?=
         =?unknown-8bit?q?_Jean_de_Baddie?=
        Mime-Version: 1.0
        Content-Type: text/plain; charset="utf-8"
        Content-Transfer-Encoding: base64

        0JTQsCwg0L7QvdC4INC70LXRgtGP0YIuCg==
        cCs:t�|j�}t�}tj�|��|�|�|��|j	�dSrY)
r�r�r.rr�rr�r,r�� non_latin_bin_msg_as7bit_wrappedr/r3r3r4�test_generator_handles_8bit�sz1Test8BitBytesHandling.test_generator_handles_8bitcCs`t�|j�}t�}t|��|�|��}tt���|�t�}t|��|�|�	|��|�dSrY)
r�r�r.rrr�r�rrr,)r0r2r�Z
orig_valuer3r3r4�;test_str_generator_should_not_mutate_msg_when_handling_8bit�szQTest8BitBytesHandling.test_str_generator_should_not_mutate_msg_when_handling_8bitcCsnt�|j�}t�}tj�|�j|dd�|���d�}|�	|d��dd�|�	d�
|dd��|j�dS)NTr�r�rsFromrq)r�r�r.rr�rr�r�r�r,r�)r0r2r�r�r3r3r4�#test_bytes_generator_with_unix_from�sz9Test8BitBytesHandling.test_bytes_generator_with_unix_fromzkSubject: =?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=r�r|cCs�d}|�t|�t|d��}|�|j�Wd�n1s<0Yt|d�� }tj���|�}Wd�n1sv0Y|�	t
|�|j�dS)Nztest.msg�wbrs)Z
addCleanupr"�open�writer.r�r�r�r�r,r��non_latin_bin_msg_as7bit)r0r�Ztestfiler�r3r3r4�test_message_from_binary_file�s*.z3Test8BitBytesHandling.test_message_from_binary_fileu        From: foo@bar.com
        To: Dinsdale
        Subject: Nudge nudge, wink, wink
        Mime-Version: 1.0
        Content-Type: text/plain; charset="latin-1"
        Content-Transfer-Encoding: 8bit

        oh là là, know what I mean, know what I mean?
        rZa         From: foo@bar.com
        To: Dinsdale
        Subject: Nudge nudge, wink, wink
        Mime-Version: 1.0
        Content-Type: text/plain; charset="iso-8859-1"
        Content-Transfer-Encoding: quoted-printable

        oh l=E0 l=E0, know what I mean, know what I mean?
        cCs"t�|j�}|�t|�|j�dSrY)r�r��
latin_bin_msgr,r��latin_bin_msg_as7bitrkr3r3r4�:test_string_generator_reencodes_to_quopri_when_appropriate�szPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriatecCsDt�|j�}t�}tj�|��|�|�|��|j�	d�d�dS)NrZr()
r�r�r;rr�rr�r,r�rO)r0r�r�r3r3r4�)test_decoded_generator_emits_unicode_body�s
�z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCsXtj��}tdt|j�d�D]}|�|j||d��q|��}|�t	|�|j
�dS)Nrr�)r�rr'r�rtr;r�r�r,r�r<)r0Zbfpr�r�r3r3r4�test_bytes_feedparser�s

z+Test8BitBytesHandling.test_bytes_feedparsercCsptdd��}|��}Wd�n1s(0Yt�|�}t�}tj�|�}|j|dd�|�|�	�|�dS)Nr�rsr�r�)
r$r�r�r�rr�rr�r,r�r�r3r3r4r��s&
z'Test8BitBytesHandling.test_crlf_flattencCsJt�d��d�}t�|�}t�}tj�|�}|�|�|�	|�
�|�dS)Nuo            Date: Fri, 18 Mar 2011 17:15:43 +0100
            To: foo@example.com
            From: foodwatch-Newsletter <bar@example.com>
            Subject: Aktuelles zu Japan, Klonfleisch und Smiley-System
            Message-ID: <76a486bee62b0d200f33dc2ca08220ad@localhost.localdomain>
            MIME-Version: 1.0
            Content-Type: multipart/alternative;
                    boundary="b1_76a486bee62b0d200f33dc2ca08220ad"

            --b1_76a486bee62b0d200f33dc2ca08220ad
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit

            Guten Tag, ,

            mit großer Betroffenheit verfolgen auch wir im foodwatch-Team die
            Nachrichten aus Japan.


            --b1_76a486bee62b0d200f33dc2ca08220ad
            Content-Type: text/html; charset="utf-8"
            Content-Transfer-Encoding: 8bit

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/html4/loose.dtd">
            <html lang="de">
            <head>
                    <title>foodwatch - Newsletter</title>
            </head>
            <body>
              <p>mit gro&szlig;er Betroffenheit verfolgen auch wir im foodwatch-Team
                 die Nachrichten aus Japan.</p>
            </body>
            </html>
            --b1_76a486bee62b0d200f33dc2ca08220ad--

            rL)r�r�r�r�r�rr�rr�r,r�)r0r�r2r�r�r3r3r4�test_8bit_multipart�s
%�&

z)Test8BitBytesHandling.test_8bit_multipartcCsFt�}td�|d<t�}tj�|�}|j|dd�|�|��d�dS)N�žluťoučký kůňrir�r�s5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr
rr�r�rr�r,r��r0r�r�r�r3r3r4�'test_bytes_generator_b_encoding_linesep)s�z=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesepcCsFt�}td�|d<t�}tj�|�}|j|dd�|�|��d�dS)NrArir�r�z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr
rr�r�rr�r,r�rBr3r3r4�!test_generator_b_encoding_linesep5s�z7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/rnrorpr�r�rrr
rrrrrr�r�rrrr r!r"r#r%r)r+r,r-r.r0r1r2r3r4r5r�r9r:r;r<r=r>r?r�r@rCrDr�r3r3r3r4r�sd	

		

��
	
	


�



�
	
	�

	.rc@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNcCsTt|d��}|��}Wd�n1s(0Y|j�|j|�}t�|�}||fS)Nrs)r$r��normalize_linesep_regex�sub�blinesepr�r�r�r3r3r4r-Hs
&
z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|�||���dS)Nrr�)r�r�)rr�r�rr�r�r,r�)r0r2rRr�r�r�r3r3r4r�Osz,BaseTestBytesGeneratorIdempotent._idempotent)F)rnrorpr�r-r�r3r3r3r4rEDsrEc@seZdZdZdZe�d�ZdS)�TestBytesGeneratorIdempotentNLr(r�s\r\nN�rnrorpr�rH�re�compilerFr3r3r3r4rIVsrIc@seZdZdZdZe�d�ZdS)� TestBytesGeneratorIdempotentCRLFr�r�s	(?<!\r)\nNrJr3r3r3r4rM]srMc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TestBase64cCs�|j}|t�d�ttjddd���td�D]b}|dkr>d}n<|dkrLd}n.|d	krZd
}n |dkrhd}n|dkrvd
}nd}|t�d|�|�q,dS)N�hello�hellor)��eol�rr�r|rr�r-���rM)r,r �
header_lengthrt�body_encoder�)r0r1�sizeZbsizer3r3r4�test_lenes
�zTestBase64.test_lencCs*|j}|t�d�d�|t�d�d�dS)Nr)rnzaGVsbG8=rP)r,r rOr!r3r3r4�test_decoderszTestBase64.test_decodecCsd|j}|t�d�d�|t�d�d�|t�d�d�|tjddd�d	�|tjddd
d�d�dS)
NrnrPz	aGVsbG8=
shello
z	aGVsbG8K
sdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx �(r�z�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
r��r�rRz�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r,r rXr!r3r3r4�test_encodews�zTestBase64.test_encodecCsZ|j}tj}||d�d�||d�d�||d�d�||ddd�d	�||d�d�dS)
NrOz=?iso-8859-1?b?aGVsbG8=?=�hello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=�hello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=rar
z=?iso-8859-2?b?aGVsbG8=?=)r,r rJ)r0r1Zher3r3r4�test_header_encode�szTestBase64.test_header_encodeN)rnrorprZr[r^rar3r3r3r4rNds
rNc@s*eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd�dd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd�d&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,d�dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4dfdg�Z5dhdi�Z6djdk�Z7dldm�Z8dndo�Z9dpdq�Z:drds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd
S)��
TestQuoprics�ttttd�td�d�ttd�td�d�ttd�td�d�dd	�d
D����_�fdd�td
�D��_t�j�t�j�d
ks�J�tttd�td�d���_�j�td���j�	td���fdd�td
�D��_
t�j�t�j
�d
ks�J�dS)Nr��zrqr�Zr�9css|]
}|VqdSrYr3�rkr�r3r3r4r��rnz#TestQuopri.setUp.<locals>.<genexpr>s!*+-/csg|]}|�jvr|�qSr3)�hlitrfr�r3r4rm�rnz$TestQuopri.setUp.<locals>.<listcomp>�r*�~r��=csg|]}|�jvr|�qSr3)�blitrfr�r3r4rm�rn)r�rr��ordrg�hnonrtrkr��remove�bnonr�r3r�r4r��s�zTestQuopri.setUpcCsP|jD]}|�t�|�dt|��q|jD]}|�t�|�dt|��q,dS)Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)rgrr!Zheader_check�chrrmr��r0r�r3r3r4�test_quopri_header_check�s

�

�z#TestQuopri.test_quopri_header_checkcCsP|jD]}|�t�|�dt|��q|jD]}|�t�|�dt|��q,dS)Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)rkrr!Z
body_checkrpror�rqr3r3r4�test_quopri_body_check�s

�

�z!TestQuopri.test_quopri_body_checkcCs�|j}|t�d�d�|ttjddd��t�d�d�|t�d�d�|ttjddd��t�d�d�|jD]$}|t�t|g��dd	t|��qp|jD]2}|t	d
�kr�q�|t�t|g��ddt|��q�|t�d
�d�dS)NrPr%Zxxxr
r�s
h@e@l@l@o@rVrqzexpected length 1 for %rr*r�zexpected length 3 for %r� )
r,r!rWrtrJrgr�rprmrl�r0r1r�r3r3r4�test_header_quopri_len�s0����

�

�z!TestQuopri.test_header_quopri_lencCsN|j}|jD]}|t�t|g��d�q|jD]}|t�t|g��d�q.dS)Nrqr�)r,rkr!Zbody_lengthr�rorur3r3r4�test_body_quopri_len�s


zTestQuopri.test_body_quopri_lencCs2td�D]$}t|�}|�t�t�|��|�qdS)Nrh)r�rpr,r!r�Zquote)r0rMr�r3r3r4�test_quote_unquote_idempotent�sz(TestQuopri.test_quote_unquote_idempotentNcCs0|durt�|�}nt�||�}|�||�dSrY)r!rJr,)r0r�Zexpected_encoded_headerr:�encoded_headerr3r3r4�_test_header_encode�szTestQuopri._test_header_encodecCs|�dd�dS)Nrnr)�rzr�r3r3r4�test_header_encode_null�sz"TestQuopri.test_header_encode_nullcCs|�dd�dS)NrPz=?iso-8859-1?q?hello?=r{r�r3r3r4�test_header_encode_one_word�sz&TestQuopri.test_header_encode_one_wordcCs|�dd�dS)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=r{r�r3r3r4�test_header_encode_two_lines�s�z'TestQuopri.test_header_encode_two_linescCs|�dd�dS)Nshello�therez=?iso-8859-1?q?hello=C7there?=r{r�r3r3r4�test_header_encode_non_ascii�s�z'TestQuopri.test_header_encode_non_asciicCs|jdddd�dS)NrPz=?iso-8859-2?q?hello?=rar
r{r�r3r3r4�test_header_encode_alt_charset�s�z)TestQuopri.test_header_encode_alt_charsetcCst�|�}|�||�dSrY)r!�
header_decoder,)r0ryZexpected_decoded_headerZdecoded_headerr3r3r4�_test_header_decode�s
zTestQuopri._test_header_decodecCs|�dd�dS�Nr)�r�r�r3r3r4�test_header_decode_nullsz"TestQuopri.test_header_decode_nullcCs|�dd�dS�NrOr�r�r3r3r4�test_header_decode_one_wordsz&TestQuopri.test_header_decode_one_wordcCs|�dd�dS)Nz
hello=0Aworldr`r�r�r3r3r4�test_header_decode_two_linessz'TestQuopri.test_header_decode_two_linescCs|�dd�dS)Nz
hello=C7thereuhelloÇtherer�r�r3r3r4�test_header_decode_non_asciisz'TestQuopri.test_header_decode_non_asciicCs|�t�d�d�dS)Na=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)r,r!r�r�r3r3r4�test_header_decode_re_bug_18380sz*TestQuopri.test_header_decode_re_bug_18380cCs2|durt�|�}ntj||d�}|�||�dS)NrQ)r!rOr,)r0ZencodedZexpected_decodedrR�decodedr3r3r4�_test_decodeszTestQuopri._test_decodecCs|�dd�dSr��r�r�r3r3r4�test_decode_null_wordsz TestQuopri.test_decode_null_wordcCs|�dd�dS)Nr�r(r�r�r3r3r4�test_decode_null_line_null_wordsz*TestQuopri.test_decode_null_line_null_wordcCs|�dd�dSr�r�r�r3r3r4�test_decode_one_wordszTestQuopri.test_decode_one_wordcCs|jdddd�dS)NrO�XrQr�r�r3r3r4�test_decode_one_word_eol"sz#TestQuopri.test_decode_one_word_eolcCs|�dd�dS�N�hello
�hello
r�r�r3r3r4�test_decode_one_line%szTestQuopri.test_decode_one_linecCs|�dd�dS�Nr�r�r�r3r3r4�test_decode_one_line_lf(sz"TestQuopri.test_decode_one_line_lfcCs|�dd�dS)Nzhello
r�r�r�r3r3r4�test_decode_one_line_cr+sz"TestQuopri.test_decode_one_line_crcCs|jdddd�dS)Nr��helloXr�rQr�r�r3r3r4�test_decode_one_line_nl.sz"TestQuopri.test_decode_one_line_nlcCs|jdddd�dS)Nr�r�r�rQr�r�r3r3r4�test_decode_one_line_crnl1sz$TestQuopri.test_decode_one_line_crnlcCs|�dd�dS)Nr_r`r�r�r3r3r4�test_decode_one_line_one_word4sz(TestQuopri.test_decode_one_line_one_wordcCs|jdddd�dS)Nr_ZhelloXworldr�rQr�r�r3r3r4�!test_decode_one_line_one_word_eol7sz,TestQuopri.test_decode_one_line_one_word_eolcCs|�dd�dS)N�hello
world
�hello
world
r�r�r3r3r4�test_decode_two_lines:sz TestQuopri.test_decode_two_linescCs|jdddd�dS)Nr�ZhelloXworldXr�rQr�r�r3r3r4�test_decode_two_lines_eol=sz$TestQuopri.test_decode_two_lines_eolcCs|�dd�dS)NA�SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamr�r�r3r3r4�test_decode_one_long_line@sz$TestQuopri.test_decode_one_long_linecCs|�dd�dS)Nr*r)r�r�r3r3r4�test_decode_one_spaceCsz TestQuopri.test_decode_one_spacecCs|�dd�dS)Nz     r)r�r�r3r3r4�test_decode_multiple_spacesFsz&TestQuopri.test_decode_multiple_spacescCs|�dd�dS)Nzhello    
r�r�r�r3r3r4�$test_decode_one_line_trailing_spacesIsz/TestQuopri.test_decode_one_line_trailing_spacescCs|�dd�dS)Nzhello    
world   
r�r�r�r3r3r4�%test_decode_two_lines_trailing_spacesLsz0TestQuopri.test_decode_two_lines_trailing_spacescCs|�dd�dS)Nz=22quoted=20words=22z"quoted words"r�r�r3r3r4�test_decode_quoted_wordOsz"TestQuopri.test_decode_quoted_wordcCs|�dd�dS)Nzab=CD=EF�abÍïr�r�r3r3r4�test_decode_uppercase_quotingRsz(TestQuopri.test_decode_uppercase_quotingcCs|�dd�dS)Nzab=cd=efr�r�r�r3r3r4�test_decode_lowercase_quotingUsz(TestQuopri.test_decode_lowercase_quotingcCs|�dd�dS)Nzsoft line=
breakzsoft linebreakr�r�r3r3r4�test_decode_soft_line_breakXsz&TestQuopri.test_decode_soft_line_breakcCs|�dd�dS)NzA=1,B=A ==> A+B==2r�r�r3r3r4�test_decode_false_quoting[sz$TestQuopri.test_decode_false_quotingcCs�i}|durd}n||d<|dur(d}n||d<tj|fi|��}|�||�|dks^|dkr||��D]}|�t|�|�qfdS)Nrvr�r(rRr�)r!rXr,r�ryrt)r0r{Zexpected_encoded_bodyr�rR�kwargsZencoded_bodyr}r3r3r4�_test_encode^szTestQuopri._test_encodecCs|�dd�dSr��r�r�r3r3r4�test_encode_nullrszTestQuopri.test_encode_nullcCs|�dd�dS)Nz

r�r�r3r3r4�test_encode_null_linesusz!TestQuopri.test_encode_null_linescCs|�dd�dSr�r�r�r3r3r4�test_encode_one_linexszTestQuopri.test_encode_one_linecCs|�dd�dSr�r�r�r3r3r4�test_encode_one_line_crlf{sz$TestQuopri.test_encode_one_line_crlfcCs|jdddd�dS)Nr�r�r�rQr�r�r3r3r4�test_encode_one_line_eol~sz#TestQuopri.test_encode_one_line_eolcCs |jd�d��d�ddd�dS)Nuhelloυ
rL�latin1z
hello=CF=85
r�rQ)r�r�rOr�r3r3r4�(test_encode_one_line_eol_after_non_ascii�s�z3TestQuopri.test_encode_one_line_eol_after_non_asciicCs|�dd�dS)Nr*z=20r�r�r3r3r4�test_encode_one_space�sz TestQuopri.test_encode_one_spacecCs|�dd�dS)Nz 
z=20
r�r�r3r3r4�test_encode_one_line_one_space�sz)TestQuopri.test_encode_one_line_one_spacecCs|�dd�dS)Nz 
 
z=20
=20
r�r�r3r3r4�test_encode_two_lines_one_space�sz*TestQuopri.test_encode_two_lines_one_spacecCs|�dd�dS)Nzhello   z
hello  =20r�r�r3r3r4�$test_encode_one_word_trailing_spaces�sz/TestQuopri.test_encode_one_word_trailing_spacescCs|�dd�dS)Nz	hello   
zhello  =20
r�r�r3r3r4�$test_encode_one_line_trailing_spaces�sz/TestQuopri.test_encode_one_line_trailing_spacescCs|�dd�dS)Nzhello  	z
hello  =09r�r�r3r3r4�!test_encode_one_word_trailing_tab�sz,TestQuopri.test_encode_one_word_trailing_tabcCs|�dd�dS)Nz	hello  	
zhello  =09
r�r�r3r3r4�!test_encode_one_line_trailing_tab�sz,TestQuopri.test_encode_one_line_trailing_tabcCs|jdddd�dS)N�
abcd 
1234zabcd =

1234rr�r�r�r3r3r4�,test_encode_trailing_space_before_maxlinelen�sz7TestQuopri.test_encode_trailing_space_before_maxlinelencCs|jdddd�dS)Nr�zabcd=
=20
1234r%r�r�r�r3r3r4�(test_encode_trailing_space_at_maxlinelen�sz3TestQuopri.test_encode_trailing_space_at_maxlinelencCs|jdddd�dS)Nr�zabc=
d=20
1234r|r�r�r�r3r3r4�,test_encode_trailing_space_beyond_maxlinelen�sz7TestQuopri.test_encode_trailing_space_beyond_maxlinelencCs|�dd�dS)Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
r�r�r3r3r4�test_encode_whitespace_lines�sz'TestQuopri.test_encode_whitespace_linescCs|�dd�dS)Nza = bza =3D br�r�r3r3r4�test_encode_quoted_equals�sz$TestQuopri.test_encode_quoted_equalscCs|�dd�dS)NZdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxr�r�r3r3r4�test_encode_one_long_string�sz&TestQuopri.test_encode_one_long_stringcCs|�dd�dS)Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
r�r�r3r3r4�test_encode_one_long_line�sz$TestQuopri.test_encode_one_long_linecCs|�dd�dS)Nz�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
z�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r�r�r3r3r4�test_encode_one_very_long_line�s�z)TestQuopri.test_encode_one_very_long_linecCs|jdddd�dS)Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr|r�r�r�r3r3r4�test_encode_shortest_maxlinelen�sz*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr)r�r�)r�r
r�r�r3r3r4� test_encode_maxlinelen_too_small�sz+TestQuopri.test_encode_maxlinelen_too_smallcCst|j}|t�d�d�|t�d�d�|t�d�d�|tjddd�d�|tjddd	d
�d�|t�d�d�dS)
Nr)rOr_r`�dxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx r\r�zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20r�r]zlxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20zone line

two line)r,r!rXr!r3r3r4r^�s�
�zTestQuopri.test_encode)N)N)NN)Frnrorpr�rrrsrvrwrxrzr|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r^r3r3r3r4rb�s�


rbc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestCharsetcCs0ddlm}z|jd=Wnty*Yn0dS)Nrr
�fake)r�r:ZCHARSETSrD)r0�
CharsetModuler3r3r4�tearDown�s
zTestCharset.tearDowncCsN|j}td�}||�d�d�d}|�t|j|�td�}||�|�d�dS)NrF�Hello World!u¤¢¤¤¤¦¤¨¤ªrLz(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r,r	rJr�rQ)r0r1r�r�r3r3r4�test_codec_encodeable�sz!TestCharset.test_codec_encodeablecCs�|j}td�}|d|�d��td�}|d|�d��td�}|d|�d��td	�}d
dlm}|�d|jdd�td�}|d|�d��dS)
Nr6z
hello w=F6rlduhello wörldrLr�r�rFrr�rr
r�)r,r	rXr�r:Zadd_charsetZQP)r0r1r�r�r3r3r4�test_body_encode�szTestCharset.test_body_encodecCs,td�}|�t|�d�|�tjtd�dS)NrFuascÿii)r	r,r�r�rZCharsetErrorr�r3r3r4�test_unicode_charset_name
sz%TestCharset.test_unicode_charset_nameN)rnrorpr�r�r�r�r3r3r3r4r��sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)4�
TestHeadercCs8|j}td�}||��d�|�d�||��d�dS)Nr�z Goodbye World!zHello World!  Goodbye World!�r�r
r�r�r�r3r3r4�test_simples

zTestHeader.test_simplecCs8|j}td�}||��d�|�d�||��d�dS)Nr�zGoodbye World!zHello World! Goodbye World!r�r�r3r3r4�test_simple_surprises

zTestHeader.test_simple_surprisecCsd}|�t|�|dfg�dS)Nzno decoding neededr�r�r3r3r4�test_header_needs_no_decoding$sz(TestHeader.test_header_needs_no_decodingcCs8tddd�}|jdd��d�D]}|�t|�d�qdS)Na�I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.rvr�r*)Z
splitcharsz
 )r
r�r�ryrt)r0r��lr3r3r4�	test_long(s
�zTestHeader.test_longc
Cs�|j}td�}td�}td�}d}d}d}t||�}|�||�|�||�|jdd�}	||	d	�t|	�}
|t|
�d
�||
d|df�||
d|df�||
d
|�d�df�t|�}||d�d��t	t|	��}|||�dS)Nr6rarLr�r�r�rvr�a=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderband_kom?=
 =?iso-8859-1?q?fortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen_Wand?=
 =?iso-8859-1?q?gem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef=F6r?=
 =?iso-8859-1?q?dert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutily?=
 =?iso-8859-2?q?_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
 =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC?=
 =?utf-8?b?5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn?=
 =?utf-8?b?44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFz?=
 =?utf-8?b?IE51bnN0dWNrIGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWloZXJodW5k?=
 =?utf-8?b?IGRhcyBPZGVyIGRpZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI3jgajoqIA=?=
 =?utf-8?b?44Gj44Gm44GE44G+44GZ44CC?=r�rrqr�s�Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an südlündischen Wandgemälden vorbei, gegen die rotierenden Klingen befördert. Finančni metropole se hroutily pod tlakem jejich důvtipu.. 正確に言うと翻訳はされていません。一部はドイツ語ですが、あとはでたらめです。実際には「Wenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.」と言っています。)
r�r	r
r�r�rrtr�rOr)
r0r1r�r�r�r�r�r�r��encr�ZustrZnewhr3r3r4�test_multilingual.s2

��zTestHeader.test_multilingualcCst�}|�|��d�dSr�r�r�r3r3r4�test_empty_header_encodemsz#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|�dtd��||d�dS)Nr)r�r6)r�r
r�r	r�r3r3r4�test_header_ctor_default_argsqs

z(TestHeader.test_header_ctor_default_argscCs�|j}d}t|�}||��d�|t|�|�t|dd�}||��d�|t|�|�t|ddd�}||��|�|t|�|�dS)Nz|A very long line that must get split to something other than at the 76th character boundary to test the non-default behaviorz}A very long line that must get split to something other than at the 76th
 character boundary to test the non-default behaviorrir�z}A very long line that must get split to something other than at the
 76th character boundary to test the non-default behaviori)r�r�)r�r
r�r�r�r3r3r4�test_explicit_maxlinelenxsz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�d�|��}||d�||ttt|����dS)Nr6rV�r:r�r�a=?iso-8859-1?q?xxx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_?=r\z�=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xxx?=
 =?iso-8859-1?q?x_xxxx_xxxx_xxxx_xxxx_?=
 =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
 =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
 =?iso-8859-1?q?_xxxx_xxxx_?=�r�r
r�r�r�rr�r0r1r�rMr�r3r3r4�test_quopri_splittable�s

3

z!TestHeader.test_quopri_splittablecCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�|�|��}||d�||ttt|����dS)NrbrVr�r�a�=?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IA==?=r\z�=?koi8-r?b?eHh4eCB4eHh4IHh4eHggeHh4?=
 =?koi8-r?b?eCB4eHh4IHh4eHggeHh4eCB4?=
 =?koi8-r?b?eHh4IHh4eHggeHh4eCB4eHh4?=
 =?koi8-r?b?IHh4eHggeHh4eCB4eHh4IHh4?=
 =?koi8-r?b?eHggeHh4eCB4eHh4IHh4eHgg?=
 =?koi8-r?b?eHh4eCB4eHh4IA==?=r�r�r3r3r4�test_base64_splittable�s

#

z!TestHeader.test_base64_splittablecCs8|j}d}t|�}||dg�t|�}|||���dS)NrO)rON�r,rrr�)r0r1r�rMr�r3r3r4�test_us_ascii_headerszTestHeader.test_us_ascii_headercCs&|j}t�}|�dd�||d�dS)NrOr6)r,r
r�r�r3r3r4�test_string_charsetszTestHeader.test_string_charsetcCs:|j}tdd�}||��d�tdd�}||��d�dS)NrrLz=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=�r,r
r�r�r3r3r4�test_utf8_shortests


zTestHeader.test_utf8_shortestcCsr|j}|j}d}|tt|�t�}|t|j|�|�dd�}|tt|dd��|�|j|dd�|t|�|�dS)N�0Ynwp4dUEbay Auction Semiar- No Charge � Earn BigrLr�r)r�r,rQr
r�rOr�)r0r=r1rMr��er3r3r4�test_bad_8bit_header$szTestHeader.test_bad_8bit_headercCsNd}|�dd�}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS)Nr�r��surrogateescaper
�2Ynwp4dUEbay Auction Semiar- No Charge � Earn Big�unknown-8bit)	rOr
r�r:�UNKNOWN8BITr,r�r�r)r0rMr�r�r3r3r4�test_escaped_8bit_header0s
�z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS�Nr�r
r�r�)r
r�r:r�r,r�r�r)r0rMr�r3r3r4�&test_header_handles_binary_unknown8bit8s
�z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tj�tj�|��}|�t|�d�|�tj�|�|dfg�dSr�)	r
r�r:r�r�rrr,r�)r0rMr�Zh2r3r3r4�+test_make_header_handles_binary_unknown8bit?s
�z6TestHeader.test_make_header_handles_binary_unknown8bitcCs2td�}tj�|�}|�d�|�t|�d�dS)Nr*)r�Ztest2)r
r�r�rr�r,r�)r0r�r�r3r3r4�0test_modify_returned_list_does_not_change_headerGs
z;TestHeader.test_modify_returned_list_does_not_change_headercCsR|j}t�}|�dd�|�d�|��}||d�tt|��}||��|�dS)NrOr6Zworldz=?iso-8859-1?q?hello?= world)r,r
r�r�rr)r0r1r�r�r3r3r4� test_encoded_adjacent_nonencodedMs

z+TestHeader.test_encoded_adjacent_nonencodedcCs:|j}d}t|�}||gd��t|�}||��d�dS)NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.))s	Subject: N)s������� � ��������rb)s zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.r�)r0r1r��partsZhdrr3r3r4�test_whitespace_keeperWs�z!TestHeader.test_whitespace_keepercCs|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r�rr�r)r0r=r�r3r3r4�test_broken_base64_header`sz$TestHeader.test_broken_base64_headercCs tddd�}|�|��d�dS)Nr��	shift_jisr
r�r�r�r3r3r4�test_shift_jis_charsetesz!TestHeader.test_shift_jis_charsetcCst�d�}|�t|�d�dS)NzEmptyHeader:zEmptyHeader: 

)r�r�r,r�r[r3r3r4�!test_flatten_header_with_no_valueis
z,TestHeader.test_flatten_header_with_no_valuecCs"t�}d|d<|�t|�d�dS)Nz   value with leading wsZ
SomeHeaderz&SomeHeader:    value with leading ws

)rr,r�r[r3r3r4�)test_encode_preserves_leading_ws_on_valuepsz4TestHeader.test_encode_preserves_leading_ws_on_valuecCs|�td���d�dS)Nr*r�r�r3r3r4�test_whitespace_headerusz!TestHeader.test_whitespace_headerN)rnrorpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r�s2?E6
	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=S)>�TestRFC2231cCs8|j}|�d�}||�d�d�||jddd�d�dS)Nz
msg_29.txtr'�rFr(�%This is even more ***fun*** isn't it!Fr�)rFr(z'"This is even more ***fun*** isn't it!")r,r-rBr/r3r3r4r�s

��zTestRFC2231.test_get_paramcCs�|j}t�}|jdddd�||�d�d�|jddddd�||�d�d�|�d	�}|jddddd�||jd
d�d�dS)
Nr'rrFr
)rFr)rr(�r:�languager�r{r�r�a"Return-Path: <bbb@zzz.org>
Delivered-To: bbb@zzz.org
Received: by mail.zzz.org (Postfix, from userid 889)
	id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
From: bbb@ddd.com (John X. Doe)
To: bbb@zzz.org
Subject: This is a test message
Date: Fri, 4 May 2001 14:05:44 -0400
Content-Type: text/plain; charset=us-ascii;
 title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21


Hi,

Do you like this message?

-Me
)r�rr�rBr-r�r/r3r3r4r��s&�
��
�
�zTestRFC2231.test_set_paramcCsft�}|�dd�|�|dd�|jdddd�|�|dd�|jdd	dd�|�|dd
�dS)Nr'r�r9ztext/plain; title="foo"r�F)Zrequoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")rr�r,r[r3r3r4�test_set_param_requote�sz"TestRFC2231.test_set_param_requotecCsX|j}|�d�}|jddddd�|jddddd�|jdd	d
�||jdd�d
�dS)Nr{r�r�rFr(rr'rr=r�r�r�a$Return-Path: <bbb@zzz.org>
Delivered-To: bbb@zzz.org
Received: by mail.zzz.org (Postfix, from userid 889)
	id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
From: bbb@ddd.com (John X. Doe)
To: bbb@zzz.org
Subject: This is a test message
Date: Fri, 4 May 2001 14:05:44 -0400
Content-Type: text/plain; charset="us-ascii";
 title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21


Hi,

Do you like this message?

-Me
)r�r-r�r�r�r/r3r3r4r��s
�zTestRFC2231.test_del_paramcCs"|j}|�d�}||��d�dS)Nr�rF)r,r-�get_content_charsetr/r3r3r4� test_rfc2231_get_content_charset�s
z,TestRFC2231.test_rfc2231_get_content_charsetcCs8t�d�}t�|�}|�|��d�|�||���dS)Nz�            Content-Disposition: inline;
            	filename*0*=''This%20is%20even%20more%20;
            	filename*1*=%2A%2A%2Afun%2A%2A%2A%20;
            	filename*2="is it not.pdf"

            �)This is even more ***fun*** is it not.pdf�r�r�r�r�r,rir�rr3r3r4�test_rfc2231_parse_rfc_quoting�s


�z*TestRFC2231.test_rfc2231_parse_rfc_quotingcCs8t�d�}t�|�}|�|��d�|�||���dS)Nz�            Content-Disposition: inline;
            	filename*0*="''This%20is%20even%20more%20";
            	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
            	filename*2="is it not.pdf"

            rrrr3r3r4� test_rfc2231_parse_extra_quoting�s


�z,TestRFC2231.test_rfc2231_parse_extra_quotingcCs4d}t�|�}|�d�}|�|t�|�|d�dS)NaContent-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm"
Content-Type: text/html; NAME*0=file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEM; NAME*1=P_nsmail.htm

�NAMEzMfile____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm�r�r�rBZassertNotIsInstance�tupler,�r0r�r2Zparamr3r3r4�#test_rfc2231_no_language_or_charset�s

�z/TestRFC2231.test_rfc2231_no_language_or_charsetcCs"d}t�|�}|�|��d�dS�Nz�Content-Disposition: inline;
	filename*0*="''This%20is%20even%20more%20";
	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2="is it not.pdf"

rr�rr3r3r4�/test_rfc2231_no_language_or_charset_in_filename
s


�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamecCs"d}t�|�}|�|��d�dSrr�rr3r3r4�7test_rfc2231_no_language_or_charset_in_filename_encodeds


�zCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedcCs"d}t�|�}|�|��d�dS)Nz�Content-Disposition: inline;
	filename*0="''This%20is%20even%20more%20";
	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2="is it not.pdf"

z1This%20is%20even%20more%20***fun*** is it not.pdfr�rr3r3r4�test_rfc2231_partly_encoded%s
�z'TestRFC2231.test_rfc2231_partly_encodedcCs"d}t�|�}|�|��d�dS)Nz�Content-Disposition: inline;
	filename*0="This%20is%20even%20more%20";
	filename*1="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2="is it not.pdf"

z?This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdfr�rr3r3r4�test_rfc2231_partly_nonencoded2s
�z*TestRFC2231.test_rfc2231_partly_nonencodedcCs"d}t�|�}|�|��d�dS)Nz�Content-Type: multipart/alternative;
	boundary*0*="''This%20is%20even%20more%20";
	boundary*1*="%2A%2A%2Afun%2A%2A%2A%20";
	boundary*2="is it not.pdf"

rr�rr3r3r4�/test_rfc2231_no_language_or_charset_in_boundary?s


�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundarycCs"d}t�|�}|�|��d�dS)Nz�Content-Type: text/plain;
	charset*0*="This%20is%20even%20more%20";
	charset*1*="%2A%2A%2Afun%2A%2A%2A%20";
	charset*2="is it not.pdf"

z)this is even more ***fun*** is it not.pdf�r�r�r,rrr3r3r4�.test_rfc2231_no_language_or_charset_in_charsetKs


�z:TestRFC2231.test_rfc2231_no_language_or_charset_in_charsetcCs"d}t�|�}|�|��d�dS)Nz�Content-Disposition: inline;
	filename*0*="bogus'xx'This%20is%20even%20more%20";
	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2="is it not.pdf"

rr�rr3r3r4�%test_rfc2231_bad_encoding_in_filenameYs


�z1TestRFC2231.test_rfc2231_bad_encoding_in_filenamecCs"d}t�|�}|�|��d�dS)Nz:Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D

rrr3r3r4�$test_rfc2231_bad_encoding_in_charsetes
z0TestRFC2231.test_rfc2231_bad_encoding_in_charsetcCs"d}t�|�}|�|��d�dS)Nz:Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D

rrr3r3r4�%test_rfc2231_bad_character_in_charsetos
z1TestRFC2231.test_rfc2231_bad_character_in_charsetcCs"d}t�|�}|�|��d�dS)Nz�Content-Disposition: inline;
	filename*0*="ascii'xx'This%20is%20even%20more%20";
	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2*="is it not.pdf%E2"

u,This is even more ***fun*** is it not.pdf�r�rr3r3r4�&test_rfc2231_bad_character_in_filenameys


�z2TestRFC2231.test_rfc2231_bad_character_in_filenamecCs"d}t�|�}|�|��d�dS)Nz^Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt

�
myfile.txtr�rr3r3r4�test_rfc2231_unknown_encoding�s
z)TestRFC2231.test_rfc2231_unknown_encodingcCs"d}t�|�}|�|��d�dS)NucContent-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=utf-8���''myfile.txt

rr�rr3r3r4�&test_rfc2231_bad_character_in_encoding�s
z2TestRFC2231.test_rfc2231_bad_character_in_encodingcCsF|j}d}t�|�}|�d�\}}}||d�||d�||d�dS)NzJContent-Type: application/x-foo;
	name*0*="Frank's"; name*1*=" Document"

r��Frank's Documentr��r0r1r�r2r:rr�r3r3r4�-test_rfc2231_single_tick_in_filename_extended�s


z9TestRFC2231.test_rfc2231_single_tick_in_filename_extendedcCs4d}t�|�}|�d�}|�|t�|�|d�dS)NzGContent-Type: application/x-foo; name*0="Frank's"; name*1=" Document"

r�rrr
r3r3r4�$test_rfc2231_single_tick_in_filename�s


z0TestRFC2231.test_rfc2231_single_tick_in_filenamecCs"d}t�|�}|�|��d�dS)NzAContent-Disposition: inline;
	filename*0*="'This%20is%20broken";
z'This is brokenr�rr3r3r4�test_rfc2231_missing_tick�s
�z%TestRFC2231.test_rfc2231_missing_tickcCs"d}t�|�}|�|��d�dS)NzAContent-Disposition: inline;
	filename*0*="'This%20is%E2broken";
u'This is�brokenr�rr3r3r4�0test_rfc2231_missing_tick_with_encoded_non_ascii�s
�z<TestRFC2231.test_rfc2231_missing_tick_with_encoded_non_asciicCsF|j}d}t�|�}|�d�\}}}||d�||d�||d�dS)NzYContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'Frank's"; name*1*=" Document"

r�rF�en-usrr�rr3r3r4�!test_rfc2231_tick_attack_extended�s


z-TestRFC2231.test_rfc2231_tick_attack_extendedcCs4d}t�|�}|�d�}|�|t�|�|d�dS)NzWContent-Type: application/x-foo;
	name*0="us-ascii'en-us'Frank's"; name*1=" Document"

r�zus-ascii'en-us'Frank's Documentrr
r3r3r4�test_rfc2231_tick_attack�s


z$TestRFC2231.test_rfc2231_tick_attackcCs(|j}d}t�|�}||�d�d�dS)Nz:Content-Type: application/x-foo; name="Frank's Document"

r�rr�r�r3r3r4�test_rfc2231_no_extended_values�s
z+TestRFC2231.test_rfc2231_no_extended_valuescCsF|j}d}t�|�}|�d�\}}}||d�||d�||d�dS)NziContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'My";
	name*1=" Document";
	name*2*=" For You"

r�rFr$�My Document For Your�rr3r3r4�,test_rfc2231_encoded_then_unencoded_segments�s


z8TestRFC2231.test_rfc2231_encoded_then_unencoded_segmentscCsF|j}d}t�|�}|�d�\}}}||d�||d�||d�dS)NziContent-Type: application/x-foo;
	name*0="us-ascii'en-us'My";
	name*1*=" Document";
	name*2*=" For You"

r�rFr$r(r�rr3r3r4�,test_rfc2231_unencoded_then_encoded_segments�s


z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsc	CsLddg}|D]:}|j|d��t�|�}Wd�q1s<0YqdS)Nz�From: user@host.com
To: user@host.com
Bad-Header:
 =?us-ascii?Q?LCSwrV11+IB0rSbSker+M9vWR7wEDSuGqmHD89Gt=ea0nJFSaiz4vX3XMJPT4vrE?=
 =?us-ascii?Q?xGUZeOnp0o22pLBB7CYLH74Js=wOlK6Tfru2U47qR?=
 =?us-ascii?Q?72OfyEY2p2=2FrA9xNFyvH+fBTCmazxwzF8nGkK6D?=

Hello!
u�From: ����� �������� <xxx@xxx>
To: "xxx" <xxx@xxx>
Subject:   ��� ���������� ����� ����� � ��������� �� ����
MIME-Version: 1.0
Content-Type: text/plain; charset="windows-1251";
Content-Transfer-Encoding: 8bit

�� ����� � ���� ������ ��� ��������
)r�)r~r�r�)r0Zmessagesr�r2r3r3r4�+test_should_not_hang_on_invalid_ew_messagess�z7TestRFC2231.test_should_not_hang_on_invalid_ew_messagesN)!rnrorpr�r�rr�rrr	rrrrrrrrrrrrrr r!r"r#r%r&r'r)r*r+r3r3r3r4r�{s<%
!




		


r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestSignedcCsBt|��"}|��}t�|�}Wd�n1s00Y||fSrYr�)r0rr��originalr2r3r3r4�_msg_and_obj$s
(zTestSigned._msg_and_objcCsLddl}|�d|j|jB�}|�|��d�}|�|��d�}|�||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$r�)rKrL�Sr��search�groupr,)r0r-�resultrKZrepartZinpartZoutpartr3r3r4�_signed_parts_eq*s
zTestSigned._signed_parts_eqcCs&|�d�\}}|��}|�||�dSr��r.r�r3�r0r-r2r2r3r3r4�test_long_headers_as_string2sz&TestSigned.test_long_headers_as_stringcCs*|�d�\}}|jdd�}|�||�dS)Nr��<r�r4r5r3r3r4�(test_long_headers_as_string_maxheaderlen7sz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|�d�\}}t�}t|��|�|��}|�||�dSr�)r.rrr�r�r3)r0r-r2r�r2r3r3r4�test_long_headers_flatten<s
z$TestSigned.test_long_headers_flattenN)rnrorpr.r3r6r8r9r3r3r3r4r,"s
r,�__main__)brKr4rMr*r��iorr�	itertoolsrZrandomrZ	threadingrZ
unittest.mockrr�Zemail.policyZemail.utilsZ
email.charsetr	Zemail.headerr
rrZemail.parserr
rZemail.generatorrrrZ
email.messagerZemail.mime.applicationrZemail.mime.audiorZemail.mime.textrZemail.mime.imagerZemail.mime.baserZemail.mime.messagerZemail.mime.multipartrZemail.mime.nonmultipartrrrrrr r!Ztest.supportr"r#Ztest.test_emailr$r%r&r'r�r�r�r+ZTestCaserqr�r�r�rr	rr,rdr�r�r�r�r�r�r�r�rrErIrMrNrbr�r�r�r,rn�mainr3r3r3r4�<module>s�lCAO((\<09 ^g0K!��5D:h*#