Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/test_email/__pycache__/test_email.cpython-38.pyc

U

i�fy[�@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�dE�ZVGdFdG�dGeVeP�ZWGdHdI�dIeVeP�ZXGdJdK�dKejD�ZYGdLdM�dMejD�ZZGdNdO�dOejD�Z[GdPdQ�dQe=�Z\GdRdS�dSe=�Z]GdTdU�dUe=�Z^e_dVk�r�e�`�dS)W�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�dddg�||�dd�d�dS)Nz
msg_20.txtZcczccc@zzz.orgzddd@zzz.orgzeee@zzz.orgZxxzn/a)�assertEqual�_msgobj�get_all��self�eq�msg�r3�?/opt/alt/python38/lib64/python3.8/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_stringc
Cs�|j}|�d�}|��}||dddddg�|�d�}|�d�}||dddddg�|�d�}|��}||dddddd	ddg�dS)
Nz
msg_08.txtrFr6�
iso-8859-2�koi8-rz
msg_09.txtZdingbatz
msg_12.txtz
iso-8859-3)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>�sz4TestMessageAPI.test_get_filename.<locals>.<listcomp>�msg.txt�
msg_07.txt��dingusfish.gif)r,r-rPrh)r0r1r2�	filenames�subpartr3r3r4�test_get_filename�s


z TestMessageAPI.test_get_filenamecCs4|j}|�d�}dd�|��D�}||ddg�dS)Nz
msg_44.txtcSsg|]}|���qSr3rgrir3r3r4rl�szHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>rm�r,r-rP)r0r1r2rqr3r3r4�%test_get_filename_with_name_parameter�s
z4TestMessageAPI.test_get_filename_with_name_parametercCs"|j}|�d�}||��d�dS)Nrn�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.txtrv�r9z3text/plain; charset="us-ascii"; boundary="BOUNDARY"rfz$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-datarrozmultipart/form-data�!z!multipart/form-data; boundary="==)rr,r}�	as_stringr[r3r3r4�test_make_boundary�s�z!TestMessageAPI.test_make_boundaryc	Cs^td��}|��}W5QRXt�}|�|�}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_onlyc	Csftd��}|���d�}W5QRXtj��}|�|�}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.
ros-�This is a Quoted Printable encoded message!
�s!This is a Base64 encoded message.�s"This is a Base64 encoded message.
rzs/This has no Content-Transfer-Encoding: header.
rtr/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)Nro)rrr^rPr[r3r3r4�*test_get_payload_n_raises_on_non_multipartsz9TestMessageAPI.test_get_payload_n_raises_on_non_multipartc	CsV|j}|�d�}td��}|��}W5QRXt�}t|�}|�|�||��|�dS)Nrnz
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__c	Cs~|�d�}td��}|��}W5QRX|�|t|��|jdd�}|�d�}|�|d�d��|�|t	�
|dd���dS)NryT��unixfromr(rzFrom ro)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�Nry�
��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_ctec	Cs�|�d�}td��}|���d�}W5QRX|�|t|��|jdd�}|�d�}|�|d�	d��|�|d�
|dd���dS)	Nryr�Tr��
rsFrom ro)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,rhr[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,rwr[r3r3r4�test_missing_boundarys
z$TestMessageAPI.test_missing_boundarycCs~|j}t�d�}||jdd�dddg�t�d�}||jdd�dd	d
g�||��d�t�d�}||jdd�dd	d
g�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.txtro�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�||��dd	d
g�||jdd�dddg�|jdd
dd�||jddd�d
�dS)Nr:�iso-2022-jp�
importance�
high valueFr��"high value")r8r))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_paramcCsr|j}|�d�}||��dddg�|�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�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)Nr�r)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)rr	r,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)Nryr8rr[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)Nrrrrr[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)Nryr�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)Nryr$r-r[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)Nr0r=r$r%r[r3r3r4�test_get_content_subtype_error^sz-TestMessageAPI.test_get_content_subtype_errorcCs�|j}t�}|�dd�|�dd�|�dd�||��dddg�||��dddg�|�dd�||��dddg�||��dddg�|�dd�|�dd	�||��ddddg�||��d	dddg�|�t|jd
d�dS)N�First�One�Second�TwoZThirdZThreeZTwentyZElevenzOne HundredZFourthZMissing)r,rr�keys�values�replace_headerr�KeyErrorr/r3r3r4�test_replace_headercsz"TestMessageAPI.test_replace_headercCspt�}|�|���|jdddd�|�|��d�|�dd�|�|��d�|�dd�|�|��d�dS)Nr�r�z
random.avir��inlineZInlinE)r�assertIsNoneZget_content_dispositionrr,r9r[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�rBr3r3r4�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,rPrBr3r3r4�test_questionable_bytes_payload�s
z.TestMessageAPI.test_questionable_bytes_payloadcCs*t�}|jdddd�|�d|d�dS)Nr�r�r�r�zattachment; filename="bud.gif"�rrr,r[r3r3r4�test_ascii_add_header�s��z$TestMessageAPI.test_ascii_add_headercCs*t�}|jdddd�|�d|d�dS)Nr�r��Fußballer.pptr�z/attachment; filename*=utf-8''Fu%C3%9Fballer.pptrHr[r3r3r4�test_noascii_add_header�s��z&TestMessageAPI.test_noascii_add_headercCs*t�}|jdddd�|�d|d�dS)Nr�r�)r6r)rJr�z1attachment; filename*=iso-8859-1''Fu%DFballer.pptrHr[r3r3r4�#test_nonascii_add_header_via_triple�s��z2TestMessageAPI.test_nonascii_add_header_via_triplecCs*t�}|jdddd�|�d|d�dS)Nr�r�zwindows [filename].pptr�z-attachment; filename="windows [filename].ppt"rHr[r3r3r4�#test_ascii_add_header_with_tspecial�s��z2TestMessageAPI.test_ascii_add_header_with_tspecialcCs*t�}|jdddd�|�d|d�dS)Nr�r�uFußballer [filename].pptr�z@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptrHr[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)NrOrQr9rMr;sZm9v5paHYmFyTrNrRrSrZrTr3r3r4�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)NrOr�rQr9r;s begin 666 -
)9F]OYI:'8F%R
 
end
TrNrR)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)Nr�r<)Zfoo_barzinline; foo-barrHr[r3r3r4�$test_add_header_with_name_only_param�sz3TestMessageAPI.test_add_header_with_name_only_paramcCs&t�}|�dd�|�d|d�dS)NzX-Statusr)rHr[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
rrr�r�r[r3r3r4�(test_embedded_header_via_Header_rejected�sz7TestMessageAPI.test_embedded_header_via_Header_rejectedcCs"t�}d|d<|�tj|j�dSr\)rrrr�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=
            r`rar3r3r4�+test_unicode_body_defaults_to_utf8_encodingsz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)X�__name__�
__module__�__qualname__r5rErHrJrSrWrXr\r`rersrurxr�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�rrrr
rr
rrrrrrrrr r"r#r'r)r+r,r.r/r1r2r;r>rDrErGrIrKrLrMrNrUrVrYrZr[r]r^rbrcr3r3r3r4r+6s�			

	



r+c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncodersc	Cs\tdd��}|��}W5QRXtjj�|�}|��}|�d�}|�t	dd�|D��d�dS)N�PyBanner048.gif�rbr(cSsg|]}t|��qSr3)�len�rjrCr3r3r4rl&sz;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;rsuhello ø worldrMr6�Z_charsetr<)r,rr/r3r3r4�test_default_cte.szTestEncoders.test_default_ctecCs8|j}tddd�}||dd�||��t�d��dS)Nu文
�euc-jprvr;rsz�            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
            r`r[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
            r`r[r3r3r4�test_qp_encode_non_latin1Ssz&TestEncoders.test_qp_encode_non_latin1N)	rdrerfrrrtrwryrzr{r3r3r3r4rgs	
rgc@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.」と言っています。r_��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?=

rl��
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�r2rr3r3r4�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�文rx�=?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 ����Ƥ��줿�᡼��ϻʲ�Ԥξ�ǧ���ԤäƤ��ޤ�rxz�=?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�rj�ir3r3r4�	<genexpr>sz@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_unsplitableszMTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplitablecCs |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�Ftest_multiple_splittable_leading_char_followed_by_overlong_unsplitable szVTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplitablecCs |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_trailing_splitable_on_overlong_unsplitable)sz?TestLongHeaders.test_trailing_splitable_on_overlong_unsplitablecCs |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�Ftest_trailing_splitable_on_overlong_unsplitable_with_leading_splitable0szVTestLongHeaders.test_trailing_splitable_on_overlong_unsplitable_with_leading_splitablecCs |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 gibtr6r_r�u-grünes Licht für Offshore-Windkraftprojekterlr�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.rlr�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�rlr�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>ZListr�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)+rdrerf�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 ro)r�rkr3r3r4rl�s
�zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r(r�)rrr�r�r�r�r�r,rjr�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_mutltipart_with_bad_bytes_in_cte�s
�z6TestFromMangling.test_mutltipart_with_bad_bytes_in_cteN)	rdrerfr�r�r�r�r�r�r3r3r3r4r��sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudioc	Cs0tdd��}|��|_W5QRXt|j�|_dS)N�audiotest.auri)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)Nr�r�r�r�rz#attachment; filename="audiotest.au"r��r�r))r�r�r�r)r��Zfailobjr�r)r,r�rr�rB�assertIs�r0r1Zmissingr3r3r4�test_add_header�s4
�
�������zTestMIMEAudio.test_add_headerN�rdrerfr�r�r�r�r�r3r3r3r4r��s
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEImagec	Cs0tdd��}|��|_W5QRXt|j�|_dS)Nrhri)r$r��_imgdatar�_imr�r3r3r4r�szTestMIMEImage.setUpcCs|�|j��d�dS)Nz	image/gif)r,r�rAr�r3r3r4r�sz#TestMIMEImage.test_guess_minor_typecCs(|j��}|�t�t|d��|j�dSr�)r�rPr,rMr�r�r�r�r3r3r4r�s
�zTestMIMEImage.test_encodingcCs t|jd�}|�|��d�dS)Nr�z
image/fish)rr�r,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)Nr�r�rpr�rz%attachment; filename="dingusfish.gif"r�r�)r�rpr�r)r�r�r)r,r�rr�rBr�r�r3r3r4r�&s4
�
�������zTestMIMEImage.test_add_headerNr�r3r3r3r4r�s
r�c@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,rPrjrrr�r�r�r��r0rr2r�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,rPrjrrr�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)rrr
r,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)
rdrerfrrr	rrr
rr3r3r3r4r�<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,rrArBr�r�r3r3r4�
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)NrrFrvr9rGrLrF)r,rr?rCr	rVrPrDr3r3r4�test_charset�szTestMIMEText.test_charsetcCs4|j}tddd�}||��jd�||dd�dS)NrrFrvr9rG)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�кирилицаrLrvr9rFTrN)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)r0rr3r3r4�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
rdrerfr�rrrrrr�unittest�skiprr3r3r3r4r�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)*�
TestMultipartc	Cs�tdd��}|��}W5QRXtdddd�}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)Nrhri�	multipart�mixedrv�r�rp)r�rr�r�z$Hi there,

This is the dingus fish.
zBarry <barry@digicool.com>r�z)Dingus Lovers <cravindogs@cravindogs.com>r�zHere is your dingus fishr_g�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�	containerrnZintro�nowZ	timetupleZtzsecsZsignZtzoffsetr3r3r4r��s>�


��zTestMultipart.setUpcCs�|j}|j}|j}|�|���||��d�|t|���d�|t|jd�|�d�}|�d�}|�	||j
�|�	||j�||��||g�|�|���|�|���dS)Nr]r�rro)
r,rrr�rrArjrP�
IndexErrorr�r.r�r)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 subjectr_�aperson@dom.ainr��bperson@dom.ainr�rvz�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#r5r_r6r�r7r�r)rvz�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�r8r3r3r4�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#r5r_r6r�r7r�rvru�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��r0r1r9r2r3r3r4�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#r5r_r6r�r7r�r)rurvaContent-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|r�r?r3r3r4�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#r5r_r6r�r7r�rurvr>rAr?r3r3r4�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�dSrC�r}rr<rr_r|r�r?r3r3r4�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#r5r_r6r�r7r�r)rurvr>rEr?r3r3r4�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#r5r_r6r�r7r�r(rurvaContent-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--

rEr?r3r3r4�.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�rozmultipart/alternativezmessage/external-bodyrr8)r,r-rjrPrA)r0r1r2�msg1rr�
subsubpartr3r3r4�test_message_external_body�s


z(TestMultipart.test_message_external_bodycCs"|�d�}|�t|���d�dS)Nz
msg_37.txtr�)r-r,rjrPr[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��r0r1r2rr3r3r4�)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
rNrOr3r3r4�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�rrwrjrPr/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,rPrar3r3r4�&test_boundary_without_trailing_newline>sz4TestMultipart.test_boundary_without_trailing_newlinecCs tdd�}|�|jtjj�dS)Nr"r#)rr�r�r��compat32rar3r3r4�test_mimebase_default_policyLs
z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|�|jtjj�dS)Nr"r#r�)rr�r��defaultr�rar3r3r4�test_mimebase_custom_policyPsz)TestMultipart.test_mimebase_custom_policyN)rdrerfr�r3r4r:r=r@rBrDrFrGrHrLrMrPrQrRrSrTrVrXr3r3r3r4r!�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.txtrr@ro)
r-rPr��hasattrr,rjr@r?r�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�rro)
r-r?rPr�r,rjr@r�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: base64ror)	�_str_msg�
multipart_msgrWr,rjr@r?rZ-InvalidMultipartContentTransferEncodingDefectr[r3r3r4�test_multipart_invalid_cte�s
��z,TestNonConformant.test_multipart_invalid_ctecCs(|�|j�d��}|�t|j�d�dS)Nr)r�rcrdrWr,rjr@r[r3r3r4�test_multipart_no_cte_no_defect�sz1TestNonConformant.test_multipart_no_cte_no_defectcCs8dD].}|�|j�d�|���}|�t|j�d�qdS)N)rsrUZBINaryz
Content-Transfer-Encoding: {}rrf)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.txtr@r�rro)
r-r�r\r,rjr@r?rr`rar[r3r3r4�test_lying_multipart�s
��z&TestNonConformant.test_lying_multipartcCsD|�d�}|�d��d�}|�t|j�d�|�|jdtj�dS)Nz
msg_42.txtror)r-rPr,rjr@r?rr])r0r9Zbadr3r3r4�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

bodyr_�bodyrorz Line 1
)r,r�r�r7rPrjr@�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
r_znot a header
To: abc

b
)rcr,r7rPrqr@rZ MissingHeaderBodySeparatorDefectr[r3r3r4�"test_missing_header_body_separator�s
�z4TestNonConformant.test_missing_header_body_separatorN)rdrerfrZr_rbr�r�rdrergrhrjrlrmrnrorsrtr3r3r3r4rYUs
	

rYc@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)"�TestRFC2047cCsR|j}d}t|�}||ddddg�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 Nu+Re: räksmörgås baz foo bar räksmörgåsrlr�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rvr3r3r4�test_whitespace_keeper_unicode	s�z*TestRFC2047.test_whitespace_keeper_unicodecCs>|j}d}t|�}||ddddg�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 dogry)r0r1r�rwZhur3r3r4� test_whitespace_keeper_unicode_2	s�z,TestRFC2047.test_whitespace_keeper_unicode_2cCs&d}t|�}|�|dddddg�dS)Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord)sSmN���r6)srgN���r6)ssbordN�rr,�r0r�rwr3r3r4�test_rfc2047_missing_whitespace(	s
�z+TestRFC2047.test_rfc2047_missing_whitespacecCs&d}t|�}|�|dddddg�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/	s
�z(TestRFC2047.test_rfc2047_with_whitespacecCsBd}dddddg}|D]&\}}t||�}|�||dfg�qdS)Nz=?iso-8859-1?B?%s?=)zdm==�v)zdm=r�)Zdmr�)zdmk=�vi)Zdmkr�r6r�)r0r�rR�q�arwr3r3r4�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|�dddg�dS)Nz(=?ISO-8859-1?Q?a?=)��(N��ar6��)Nr�r�r3r3r4�test_rfc2047_rfc2047_1F	s
�z"TestRFC2047.test_rfc2047_rfc2047_1cCsd}|�t|�dddg�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|�dddg�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|�dddg�dS)Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r�r�r�r�r�r3r3r4�test_rfc2047_rfc2047_4X	s
�z"TestRFC2047.test_rfc2047_rfc2047_4cCsd}|�t|�dddg�dS)Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r�r�r3r3r4�test_rfc2047_rfc2047_5a^	s
�z#TestRFC2047.test_rfc2047_rfc2047_5acCsd}|�t|�dddg�dS)Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r�r�r3r3r4�test_rfc2047_rfc2047_5bd	s
�z#TestRFC2047.test_rfc2047_rfc2047_5bcCsd}|�t|�dddg�dS)Nz(=?ISO-8859-1?Q?a_b?=)r�)sa br6r�r�r�r3r3r4�test_rfc2047_rfc2047_6j	s
�z"TestRFC2047.test_rfc2047_rfc2047_6cCsTd}|�t|�ddddg�|�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)rdrerfrxrzr{r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4ru	s 		
	ruc@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)"�TestMIMEMessagec	Cs"td��}|��|_W5QRXdS)N�
msg_11.txt)r$r�Z_textr�r3r3r4r��	s
zTestMIMEMessage.setUpcCs|�ttd�dS)Nza plain string)rr^rr�r3r3r4�test_type_error�	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||��d�|��}|�|t�|t|�d�|d}|�||�||d|�dS)Nz
A sub-messager_rror�subject)	r,rrrArPr?�listrjr�)r0r1r�r��rr�rrr3r3r4�test_valid_argument�	sz#TestMIMEMessage.test_valid_argumentcCs:t�}d|d<t�}d|d<t|�}|�tj|j|�dS)Nz	subpart 1r_z	subpart 2)rrrrZMultipartConversionErrorr_)r0rJrr�r3r3r4�test_bad_multipart�	sz"TestMIMEMessage.test_bad_multipartcCsTt�}d|d<|�d�t|�}d|d<t�}t|�}|�|�|�|��d�dS)N�An enclosed messager_�!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�rrorr�r�r�)r,r-rArPr?r�rjr)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

rozmessage/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�rrjrPr?rrBr�r�)r0r1r2rrZdsn1Zdsn2r�rKr3r3r4�test_dsn�	sD




�
�zTestMIMEMessage.test_dsnc		Cs�|j}td��}|��}W5QRXt�}d|d<d|d<d|d<d|_d	|_td
�}td�}|jdd
dd�|�|�|�|�t	�}t
|�}|�|�||��|�dS)N�
msg_21.txtr6r�r7r�r�r_�MIME messagezEnd of MIME message
r4r6r=r]rvr$)
r}r$r�rr;r<rrr_rrr�r�)	r0r1r�r�r2rJrrr�r3r3r4�
test_epilogue�	s$



zTestMIMEMessage.test_epiloguecCsv|j}t�}d|d<d|d<d|d<d|_d|_td	�}td
�}|jddd
d�|�|�|�|�||��d�dS)Nr6r�r7r�r�r_r�r)r4r6r=r]rvr$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}rr;r<rrr_r�)r0r1r2rJrr3r3r4�test_no_nl_preamble
s

z#TestMIMEMessage.test_no_nl_preamblec	Cs�|j}td��}t�|�}W5QRX|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nrrrror8�r,r$r��message_from_filerP�get_default_typerA�r0r1r�r2Z
container1Z
container2Zcontainer1aZcontainer2ar3r3r4�test_default_type3
s




z!TestMIMEMessage.test_default_typec	Cs�|j}td��}t�|�}W5QRX|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nrrrror8r�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)NZdigestrvr)�
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}rr<rrr_rAr�r�)r0r1rir/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�rro)r,rrrjrP)r0r1Ztext1Ztext2r2r3r3r4�$test_mime_attachments_in_constructor�
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|�|���dSrY)rr�rr[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_policyc	CsJttjjd�}d|d<|�t��}d|d<W5QRX|�t|j�d�dS)Nr�r�r�r�z.There may be at most 1 To headers in a message)	rr�r�rWrrr,r�Z	exception)r0r2�cmr3r3r4�test_multipart_custom_policy�
s�z,TestMIMEMessage.test_multipart_custom_policyN)rdrerfr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r��	s 9#J	r�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(c	Cs.t|��}|��}W5QRXt�|�}||fSrY�r$r�r�r��r0r�r�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)	Nryr8r�r$ro)r:rFr:rF)
r,r-rArr&r�rBr;r<r��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)Nrf�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_image�
sz$TestIdempotent.test_mixed_with_imagecCs|�d�\}}|�||�dS)Nr�r�r�r3r3r4�test_multipart_report�
sz$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)Nrkr�r�r3r3r4rlsz%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_parameterssz+TestIdempotent.test_more_rfc2231_parameterscCs|�d�\}}|�||�dS)Nz
msg_34.txtr�r�r3r3r4�%test_text_plain_in_a_multipart_digestsz4TestIdempotent.test_text_plain_in_a_multipart_digestcCs|�d�\}}|�||�dS)Nzmsg_12a.txtr�r�r3r3r4�test_nested_multipart_mixedssz+TestIdempotent.test_nested_multipart_mixedscCs|�d�\}}|�||�dS)NrIr�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_status$sz+TestIdempotent.test_message_delivery_statuscCs|�d�\}}|�||�dS�N�
msg_45.txtr�r�r3r3r4�test_message_signed_idempotent(sz-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 yaddaror�r)r,r-rAr�r;r�r<rjrPr?rr�)r0r1r2r�ZparamsZpkZpvrJrZmsg3r�Zmsg4r3r3r4�test_content_type,s4



z TestIdempotent.test_content_typecCs�|j}|�d�\}}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�|�|��t�||��|j	�dS)Nr�rrorr8)
r,r-rArPr?r�rjrr�r�)r0r1r2r�r�rJr3r3r4�test_parserKszTestIdempotent.test_parserN)F)rdrerfr�r-r�r�r�r�r�r�r�r�r�r�r�r�r�rlr�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:dqS)r�TestMiscellaneousc	CsVtd��}|��}W5QRXt�|�}t�}t|dd�}|�|�|�||���dS�Nryrr��	r$r�r�r�rrr�r,r��r0r�r�r2r�r�r3r3r4�test_message_from_string_s


z*TestMiscellaneous.test_message_from_stringc	Cs`td��N}|��}|�d�t�|�}t�}t|dd�}|�|�|�||�	��W5QRXdSr�)
r$r��seekr�r�rrr�r,r�r�r3r3r4�test_message_from_filejs



z(TestMiscellaneous.test_message_from_filec	Cs�td��}|��}W5QRXGdd�dt�}t�||�}|�||�td��}|��}W5QRXt�||�}|��D]}|�||�qtdS)Nryc@seZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN�rdrerfr3r3r3r4�	MyMessage{sr�r�)r$r�rr�r�r?�walk)r0r�r�r�r2rrr3r3r4�#test_message_from_string_with_classvs

z5TestMiscellaneous.test_message_from_string_with_classc	CszGdd�dt�}td��}t�||�}W5QRX|�||�td��}t�||�}W5QRX|��D]}|�||�qddS)Nc@seZdZdS)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageNr�r3r3r3r4r��sr�ryr�)rr$r�r�r?r�)r0r�r�r2rrr3r3r4�!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__)rdrerfr��
__classcell__r3r3r�r4r��sr�zSubject: test

test)rrcr?)r0r�r2r3r3r4�.test_custom_message_does_not_require_arguments�sz@TestMiscellaneous.test_custom_message_does_not_require_argumentscCs@td�}|�t|j�dddddddd	d
ddd
dddddg�dS)Nr�r r:rr�
feedparserr�r�rrZmessage_from_binary_filer�r�r�rmr�r!r)�
__import__r,�sorted�__all__)r0�moduler3r3r4�test__all__�s(�zTestMiscellaneous.test__all__cCs:t��}|�t�t�|��dd�t�|�dd��dS)N�)r)r,r�	parsedate�
formatdate�gmtime�r0r0r3r3r4�test_formatdate�s�z!TestMiscellaneous.test_formatdatecCs>t��}|�t�tj|dd��dd�t�|�dd��dS)NT�r*r�)r)r,rr�r�r*r�r3r3r4�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)r*Zusegmtz%a, %d %b %Y %H:%M:%S GMT)r)r,rr�r-r�r�r3r3r4�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��dS)Nr)r*�0zA Complete Waste of Time)r=rr��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���
�/�rror%透���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��r
rrrror%r
rrr3r3r4�#test_parsedate_compact_no_dayofweek�s
�z5TestMiscellaneous.test_parsedate_compact_no_dayofweekcCs|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26+0800)
��rzr���:rrror%i�prr�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)
rrzr�rrrrror%r
rr�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 -0800rz5 Feb 2003 13.47 -0800)
rr�rr
rrrror%r
rrr3r3r4�%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)Nrr�z%Yr�	)	r,rr��intr)�mktimer*r-r)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)
�rororrrr%r%r%rr)
rrororrrr%r%r%i�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 -0800Nrr�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@cr"za@b.c@cza@172.17.0.1@c�r,rr$r�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,rr%r�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,rr%r$�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>r/r)r,r-r3r3r4�test_escape_backslashes(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_names0s�z+TestMiscellaneous.test_quotes_unicode_namescsld}d}d}d�G�fdd�d�}|�}d�|f}|�t�||f|�|�|�t�||ftd��|�dS)	Nr1r)r2ZFOOBARcseZdZ�fdd�ZdS)zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockcs�SrYr3)r0�string�rr3r4�
header_encodeAszYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)rdrerfr8r3r7r3r4�CharsetMock@sr9z%s <%s>rL)r,rr%r	)r0r�r3r4r9ZmockZ
mock_expectedr3r7r4�$test_accepts_any_charset_like_object:s�z6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|�ttj||f|�dS)Nr1r))�objectr�AttributeErrorrr%)r0r�r3Zbad_charsetr3r3r4�-test_invalid_charset_like_object_raises_errorIs�z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|�ttjd|f�|�ttjd|f�dS)Nupersön@dom.in�Name)r�UnicodeErrorrr%�r0r3r3r3r4�!test_unicode_address_raises_errorR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.comr#)r0rC�yr�r�r3r3r4�test_name_with_dotXsz$TestMiscellaneous.test_name_with_dotcCs:|j}|t�d�d�|t�d�d�|t�d�d�dS)N�""example" example"@example.com)r)rD�!"\"example\" example"@example.com)r)rE�#"\\"example\\" example"@example.com)r)rFr'rr3r3r4�2test_parseaddr_preserves_quoted_pairs_in_addressesa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.comrH)r)�merwok  wok@xample.comrIz merwok  wok  @xample.com)r)�merwok"wok"  wok@xample.comrJ)r)zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.comr'r�r3r3r4�-test_parseaddr_preserves_spaces_in_local_parts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>r#)r0r3Zaddrstrr3r3r4�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 BarrLr')r0rCr3r3r4�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 Personr6)z
Bud Personr7�r,r�getaddressesrr3r3r4�test_getaddresses�s���z#TestMiscellaneous.test_getaddressescCs"|�t�dddg�dddg�dS)zGH-106669 regression test.z"Bud, Person" <bperson@dom.ain>rSz#"Mariusz Felisiak" <to@example.com>)zBud, Personr7rT)zMariusz Felisiak�to@example.comNrUr�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��d|�t�|g�|g�|�tj|gdd�|�|�t�|g�|�|�tj|gdd�d|f�W5QRXq�|�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�dddg�|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�ddg�|�tj|gdd�ddg�|�t�|g�|�|�tj|gdd�d|f�|�tjjd �d!S)"z>Test for parsing errors from CVE-2023-27043 and CVE-2019-16056�alice@example.org�bob@example.comr"�(�<�>�)r)�[z[<z>]�]�@�;�:�.�")�addressF��strictz,<z,"Alice, alice@example.org" <bob@example.com>)zAlice, alice@example.orgr[zalice@example.org (Alice))�AlicerZzalice@example.org )Alice()r)rZ)r)rj�<"Jane Doe" <jane@example.net>, "John Doe" <john@example.net>)zJane Doezjane@example.net)zJohn Doezjohn@example.netTN)�subTestr,rrVr$r�Zsupports_strict_parsing)r0ZaliceZbob�emptyZinvalid_separatorZexpected_non_strictrgZexpected_strictr3r3r4�test_parsing_errors�s��
�����������������z%TestMiscellaneous.test_parsing_errorscCs�dgdgfdgdgfddgddgfdgdgfd	gdgfd
gdddgfd
gdgfdgdgfdgdgfdgddgff
D]H\}}|j|d��.|�t�|�|�|�tj|dd�|�W5QRXqrdg}|�t�|�dg�|�tj|dd�dddg�dS)Nu&"Sürname, Firstname" <to@example.com>)uSürname, FirstnamerXzfoo: ;r"z#"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.net)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)�	addressesFrhz	[]*-- =~$)r)z*--)rlr,rrV)r0ror�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>rro�foo@bar.comNrU)r0r1Zaddrsr3r3r4�"test_getaddresses_embedded_commentI
sz4TestMiscellaneous.test_getaddresses_embedded_commentc	sjGdd�dt���fdd�td�D�}t|��W5QRXtdd�|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_msgidr)�	monotonic)r0r�rwZclockZtfinr3r3r4�runR
s

zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)rdrerfryr3r3r3r4�MsgidsThreadQ
srzcsg|]
}���qSr3r3r��rzr3r4rl\
sz@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>rcSsg|]
}|j�qSr3)rv)rjr�r3r3r4rl_
s)rr�r#�sumr,rj�set)r0ZthreadsZall_idsr3r{r4�test_make_msgid_collisionsO
s

z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||��d�dS)Nrr�zfoo\wacky"namer�)r,rrrhr/r3r3r4�test_utils_quote_unquoteb
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_charseti
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=r9rorrLrMr�r�aGVsbG8gd29ybGQ=
TrNr;ztext/plain; charset="US-ASCII"rFrurs)
r,rrcrjr	r�rIrPrr)r0r1r2rdr:r3r3r4�-test_get_body_encoding_with_uppercase_charsetm
s.z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs(td�}td�}|�|��|���dS)NrFrPr�)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
rNrOr3r3r4�1test_partial_falls_inside_message_delivery_status�
s

zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs"|�tjjdd�dd�d�dS)Nrsrti��z@testdomain-string>�r,r�rrwr�r3r3r4�test_make_msgid_domain�
s�z(TestMiscellaneous.test_make_msgid_domaincCs$|�tjjddd�dd�d�dS)Nz
test-idstringrs)Zidstringrui���z!.test-idstring@testdomain-string>r�r�r3r3r4�test_make_msgid_idstring�
s���z*TestMiscellaneous.test_make_msgid_idstringc	Cs@td��.}d|_}|�tj���d|d��W5QRXdS)Nzsocket.getfqdnzpythontest.example.comrbr^)rZreturn_valuer�r�rrw�endswith)r0Zmock_getfqdnrur3r3r4�test_make_msgid_default_domain�
s



��z0TestMiscellaneous.test_make_msgid_default_domainc	Csftddd��}|��}W5QRX|�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_linendc	Csptddd��}|��}W5QRX|�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_linendc	Csttdd��}|��}W5QRX|�dd�}|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
�|�dS)	Nr�riswith 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
Cs�tdd��}|��}W5QRXtdd��}|��}W5QRXtdft|fft|fftt�fftdftdfg}|D]~\}}|j	|j
dd�� ||�}|�|jt
jj�W5QRX|j	|j
dd��*||d	t
jji�}|�|jt
jj�W5QRXqpdS)
Nr�rirh)r))r"r#rU)�clsr�rWr�)r$r�rrrrrrrrlrdr�r�r�rUrW)r0r�Z	audiodatarq�classesr��constructorr�r3r3r4�!test_mime_classes_policy_argument�
s$
�z3TestMiscellaneous.test_mime_classes_policy_argumentcCsD|�tt�d��dddddddd	g�|�tt�d
��ddg�dS)Nza\\b\"c\\"d)rr�)r��\\)r�r�)rz\")r��c)�r�)rrf)r��dza\)ro�\)r,r�rZ_iter_escaped_charsr�r3r3r4�test_iter_escaped_chars�
s��	�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)r3r�r�r3r4�check
sz<TestMiscellaneous.test_strip_quoted_realnames.<locals>.checkrkz( <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�r3r3r�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_parenthesisrr@r3r3r4�test_check_parenthesis%sz(TestMiscellaneous.test_check_parenthesisN);rdrerfr�r�r�r�r�r�r�rrrrrrrrrrr r!r&r(r+r.r0r5r:r=rArCrGrKrMrNrOrRrWrYrnrprrr~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r�^sp




			X,*
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestIteratorsc	Cs�|j}|j}|�d�}t�|�}t|�}|t|�d�|t�|�|�	��|�d�}t�|�}t|�}|t|�d�t
d��}|t�|�|���W5QRXdS)Nryr�r��+z
msg_19.txt)r,r}r-rZbody_line_iteratorr�rj�EMPTYSTRINGr�rPr$r�)r0r1rir2�itr�r�r3r3r4�test_body_line_iterator2s




z%TestIterators.test_body_line_iteratorcCsb|j}|�d�}t�|d�}g}d}|D]}|d7}|�|���q(||d�|t�|�d�dS)Nrfr�rror�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�Zsubpartsrrr3r3r4�test_typed_subpart_iteratorCs

z)TestIterators.test_typed_subpart_iteratorcCsd|j}|�d�}t�|dd�}g}d}|D]}|d7}|�|���q*||d�|t�|�d�dS)Nr{r�r$rroz%
Hi,

Do you like this message?

-Me
r�r�r3r3r4�(test_typed_subpart_iterator_default_typeTs

z6TestIterators.test_typed_subpart_iterator_default_typecCs�ddddddddg}d	d
lm}m}|�}g}d	}|D]N\}}|�|�||7}d	}	t|j|�D]}
|�|
�|	d7}	q`|�||	�q6|�t|�|�|�d�	d
d�|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
ro)r)r)zd
ro)ze
r)z
fro)r�ror��BufferedSubFile�NeedMoreDataror)cSsg|]\}}|�qSr3r3)rj�il�nr3r3r4rl�sz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
�email.feedparserr�r��push�iter�readliner�r,rjr�)r0Zimtr�r��bsfZom�ntr�r�Zn1Zolr3r3r4�test_pushCR_LFgs.�



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'rzabcd 	
r)c3s|]}t��VqdSrYrr���charsr3r4r��sz1TestIterators.test_push_random.<locals>.<genexpr>r(T)r�r�r�r�r�r�rjr��extendr�r�r,)r0r�r�r�Z	chunksizer��targetr�r�r��chunkr3r�r4�test_push_random�s 

zTestIterators.test_push_randomN)rdrerfr�r�r�r�r�r3r3r3r4r�1s
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs"t�}|D]}|�|�q
|��SrY)r&�feed�close)r0�chunksr�r�r3r3r4�parse�szTestFeedParsers.parsecCs.|�d�}|�|dd�|�|dd�dS)NzFirst: val
: bad
Second: valr3�valr5)r�r,r[r3r3r4�test_empty_header_name_handled�s
z.TestFeedParsers.test_empty_header_name_handledcCs�|�dg�}|�|��ddddg�|�dg�}|�|��ddddg�|�ddg�}|�|��dd	g�|�d
dg�}|�|��ddg�|�d
dg�}|�|��ddg�|�d
g�}|�|��dg�|�d
ddg�}|�|��ddg�dS)Nz
a:
b:
c:
d:
r�r�r�r�za:
b:
c:
d:za:
bzc:
Zbc�a:
zb:
z
b:
ua:…b:
c:
)r�u	…b:
c:ub:…�r�r))r�u…c:)r�r,r7r}rar3r3r4�
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

rC)r�r�za:b

�…r�zb: r�r�)r�r,r}rP)r0�M�Nr�r3r3r4�test_long_lines�szTestFeedParsers.test_long_linesN)rdrerfr�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)$�TestParsersc	Csr|j}td��}t��|�}W5QRX||dd�||dd�||��d�|�|���|�|��t	�dS)Nr�r��ppp-request@zzz.orgr��ppp@zzz.orgr])
r,r$rr�rArrr?rPr��r0r1r�r2r3r3r4�test_header_parser�s
zTestParsers.test_header_parserc	Cs�|j}tdd��}tj���|�}W5QRX||dd�||dd�||��d�|�|���|�	|�
�t�|�	|j
dd	�t�dS)
Nr�rir�r�r�r�r]TrN)
r,r$r�r�r�r�rArrr?rPr�r�r�r3r3r4�test_bytes_header_parser�sz$TestParsers.test_bytes_header_parserc	Cs6tdd��"}tj���|�|�|j�W5QRXdS)Nr�ri)r$r�r��BytesParserr�r�closedr�r3r3r4�%test_bytes_parser_does_not_close_file�sz1TestParsers.test_bytes_parser_does_not_close_filec	CsLtdd��8}tjj}|�tjj|tjjd�j	|�|�
|j�W5QRXdS)Nr[rir�)r$r�r�r�rrr]r�rir�rr�)r0r�ZbytesParserr3r3r4�2test_bytes_parser_on_exception_does_not_close_file�s
�z>TestParsers.test_bytes_parser_on_exception_does_not_close_filec	Cs6tdd��"}tj���|�|�|j�W5QRXdS)Nr�r�)r$r�r�r
r�rr�r�r3r3r4�test_parser_does_not_close_file�sz+TestParsers.test_parser_does_not_close_filec	CsLtdd��8}tjj}|�tjj|tjjd�j	|�|�
|j�W5QRXdS)Nr[r�r�)r$r�r�r
rrr]r�rir�rr�)r0r�r�r3r3r4�,test_parser_on_exception_does_not_close_file�s
�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_continuation�s


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_headerc	Cs~|j}tddd��}t��|�}W5QRX|t|���d�|�d�}||��d�||��d�|�d�}||��d	�dS)
Nr�r(r�r�rr8z!Simple email with attachment.

rozapplication/riscos)r,r$r
r�rjrPrA)r0r1r�r2�part1�part2r3r3r4�test_crlf_separations

z TestParsers.test_crlf_separationc	CsZtddd��}|��}W5QRXt�|�}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�|�}W5QRX||��d�|t|���d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d�dS)	Nrror�rrr8r�r�)	r,r}r$r�r�rrjrPrA)	r0r1rir�r2r�Zpart1ar�Zpart2ar3r3r4�-test_multipart_digest_with_extra_mime_headers5s,




z9TestParsers.test_multipart_digest_with_extra_mime_headerscCs.dddg}t�t�|��}|�|dd�dS)Nz$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_linesTs�zTestParsers.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_headers\s�
z?TestParsers.test_strip_line_feed_and_carriage_return_in_headerscCsR|j}d}t�|�}|t|�d�|tdd�|D��dddg�||��d�dS)	Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyr�css|]
}|VqdSrYr3)rjZfieldr3r3r4r�lsz9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>z!"#QUX;~z>Fromr�rp)r,r�r�rjr�rPr�r3r3r4�test_rfc2822_header_syntaxgs
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�rjr7r�r3r3r4�(test_rfc2822_space_not_allowed_in_headeros
z4TestParsers.test_rfc2822_space_not_allowed_in_headercCsF|j}d}t�|�}|��}|��||dddg�||��d�dS)Nz7A: first header
B: second header
CC: third header

body�A�BZCCrp)r,r�r�r7�sortrP)r0r1r�r2Zheadersr3r3r4�!test_rfc2822_one_character_headerus
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)rdrerfr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r3r3r4r��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_msgrWr�r�r�r,rPr�r3r3r4�test_known_8bit_CTE�s��
�z)Test8BitBytesHandling.test_known_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
NZnotavalidcharsetrUr�r�rLup��stal
TrNr�r�r�r3r3r4�test_unknown_8bit_CTE�s��
�z+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)	NrLr<�p=C3=B6stálr�u
p=C3=B6stál
TrN�	pöstál
r�r�r3r3r4�test_8bit_in_quopri_body�s
��
�z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
Nr�r<r�r�rLup=C3=B6st��l
TrNr�r�r�r3r3r4�.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á=r�TrNr�r)r�rWr�r�r�r,rPr?r@rrAr�r3r3r4�test_8bit_in_base64_body�s��
��z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd��d�}t�|�}|�|jdd�d�d��dS)NrLr�u
<,.V<W1A; á r�TrNu<,.V<W1A; á 
r�r�r3r3r4�test_8bit_in_uuencode_body�s��
�z0Test8BitBytesHandling.test_8bit_in_uuencode_body))zFrom: foo@bar.com�r�rq)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)r_z�=?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)rj�src�_r3r3r4rl�sz 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_header�s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)ror3)rjrr�r3r3r4rl
szATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	r�r�rr,r�r�r�rW�headertest_headersr[r3r3r4�test_print_8bit_headerss

���z-Test8BitBytesHandling.test_print_8bit_headerscCs2t�|j�}|�dd�|��D�ddddg�dS)NcSsg|]}t|��qSr3�r�rkr3r3r4rlszGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>rqr�]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie�	g��st)r�r�r�assertListEqualr8r[r3r3r4�test_values_with_8bit_headerss��z3Test8BitBytesHandling.test_values_with_8bit_headerscCs2t�|j�}|�dd�|��D�ddddg�dS)NcSs g|]\}}t|�t|�f�qSr3r)rjrCrBr3r3r4rlszFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>r�)r�r)r_r)r�r)r�r�rr	r}r[r3r3r4�test_items_with_8bit_headerss��z2Test8BitBytesHandling.test_items_with_8bit_headerscCs0t�|j�}|�dd�|�d�D�ddg�dS)NcSsg|]}t|��qSr3rrkr3r3r4rl)szHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�rqr)r�r�rr	r.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
            rPutext/pl�inr�upl�in)	r�r�r�r�r�r,rArr&r[r3r3r4�test_get_content_type_with_8bit-s�z5Test8BitBytesHandling.test_get_content_type_with_8bitcCsZt�d�d��}|�|jdd�dddg�|�|jddd�d	�|�|jd
dd�d�dS)Nu(X-Header: foo=§ne; b§r=two; baz=three
rPr�r�)r���ne)ub�rr�r�ZFoorub§r)r�r�r�r,r�rBr[r3r3r4�test_get_params_with_8bit6s��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§nrP�title)rF�enuThis is not f�n)r�r�r�r�r�r,rBr[r3r3r4�!test_get_rfc2231_params_with_8bit@s��z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8t�t�d��d��}|�dd�|�|�d�d�dS)NrrPr�test)r�r�r�r�r�r�r,rBr[r3r3r4�!test_set_rfc2231_params_with_8bitHs
�z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFt�t�d��d��}|�d�|�|�d�d�|�|��d�dS)NrrPrr�)	r�r�r�r�r�r�r,rBrr[r3r3r4�!test_del_rfc2231_params_with_8bitPs�
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
            rPzpayload
TrNspayload
)r�r�r�r�r�r,rPr[r3r3r4�%test_get_payload_with_8bit_cte_headerYs
�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_generatorosz*Test8BitBytesHandling.test_bytes_generatorcCs6tj��}t�}tj�|��|�|�|��d�dS)Nr�)	r�rrrr�rr�r,r�rr3r3r4�&test_bytes_generator_handles_None_bodyus
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�rrr�rr�r,r�� non_latin_bin_msg_as7bit_wrappedrr3r3r4�test_generator_handles_8bit�sz1Test8BitBytesHandling.test_generator_handles_8bitcCs`t�|j�}t�}t|��|�|��}tt���|�t�}t|��|�|�	|��|�dSrY)
r�r�rrrr�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�rsFromro)r�r�rrr�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�rzc	Csnd}|�t|�t|d��}|�|j�W5QRXt|d��}tj���|�}W5QRX|�	t
|�|j�dS)Nztest.msg�wbri)Z
addCleanupr"�open�writerr�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?
        rPa         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_as7bitrar3r3r4�: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)NrPr()
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�r�r'r�rjr%r�r�r,r�r&)r0Zbfpr�r�r3r3r4�test_bytes_feedparser�s

z+Test8BitBytesHandling.test_bytes_feedparserc	Cs\tdd��}|��}W5QRXt�|�}t�}tj�|�}|j|dd�|�|�	�|�dS)Nr�rir�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ůňr_r�r�s5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

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

)	rr
rr�r�rr�r,r�r,r3r3r4�!test_generator_b_encoding_linesep!s�z7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/rdrerfr�r�r�r�r�r�r�r�r�rr�r�rrrr
rrr
rrrrrrrrrrrrr�r#r$r%r&r'r(r)r�r*r-r.r�r3r3r3r4r��sd	

		

��
	
	


�



�
	
	�

	.r�c@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNc	Cs@t|d��}|��}W5QRX|j�|j|�}t�|�}||fS)Nri)r$r��normalize_linesep_regex�sub�blinesepr�r�r�r3r3r4r-4s

z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|�||���dS)Nrr�)r�r�)rr�r�rr�r�r,r�)r0r2rRr�r�r�r3r3r4r�;sz,BaseTestBytesGeneratorIdempotent._idempotent)F)rdrerfr�r-r�r3r3r3r4r/0sr/c@seZdZdZdZe�d�ZdS)�TestBytesGeneratorIdempotentNLr(r�s\r\nN�rdrerfr�r2�re�compiler0r3r3r3r4r3Bsr3c@seZdZdZdZe�d�ZdS)� TestBytesGeneratorIdempotentCRLFr�r�s	(?<!\r)\nNr4r3r3r3r4r7Isr7c@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�rzr�r�r���rC)r,r �
header_lengthrj�body_encoder�)r0r1�sizeZbsizer3r3r4�test_lenQs"
�zTestBase64.test_lencCs*|j}|t�d�d�|t�d�d�dS)Nr)�zaGVsbG8=r:)r,r rOrr3r3r4�test_decode^szTestBase64.test_decodecCsd|j}|t�d�d�|t�d�d�|t�d�d�|tjddd�d	�|tjddd
d�d�dS)
NrEr:z	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�r<z�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r,r rBrr3r3r4�test_encodecs�zTestBase64.test_encodecCsZ|j}tj}||d�d�||d�d�||d�d�||ddd�d	�||d�d�dS)
Nr9z=?iso-8859-1?b?aGVsbG8=?=�hello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=�hello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=rarz=?iso-8859-2?b?aGVsbG8=?=)r,r r8)r0r1Zher3r3r4�test_header_encodeyszTestBase64.test_header_encodeN)rdrerfrDrFrIrLr3r3r3r4r8Ps
r8c@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�t�tttd�td�d���_�j�	td���j�
td���fdd�td
�D��_t�j�t�j�d
ks�t�dS)Nr��zror��Zr�9css|]
}|VqdSrYr3�rjr�r3r3r4r��sz#TestQuopri.setUp.<locals>.<genexpr>s!*+-/csg|]}|�jkr|�qSr3)�hlitrQr�r3r4rl�s
z$TestQuopri.setUp.<locals>.<listcomp>�r*�~r��=csg|]}|�jkr|�qSr3)�blitrQr�r3r4rl�s
)r�rr��ordrR�hnonrj�AssertionErrorrVr��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)rRrr!Zheader_check�chrrXr��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)rVrr!Z
body_checkr\r[r�r]r3r3r4�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)Nr:rZxxxrr�s
h@e@l@l@o@r@rozexpected length 1 for %rr*r�zexpected length 3 for %r� )
r,r!rArjr8rRr�r\rXrW�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)Nror�)r,rVr!Zbody_lengthr�r[rar3r3r4�test_body_quopri_len�s


zTestQuopri.test_body_quopri_lencCs2td�D]$}t|�}|�t�t�|��|�qdS)NrS)r�r\r,r!r�Zquote)r0rCr�r3r3r4�test_quote_unquote_idempotent�sz(TestQuopri.test_quote_unquote_idempotentNcCs0|dkrt�|�}nt�||�}|�||�dSrY)r!r8r,)r0r�Zexpected_encoded_headerr:�encoded_headerr3r3r4�_test_header_encode�szTestQuopri._test_header_encodecCs|�dd�dS)NrEr)�rfr�r3r3r4�test_header_encode_null�sz"TestQuopri.test_header_encode_nullcCs|�dd�dS)Nr:z=?iso-8859-1?q?hello?=rgr�r3r3r4�test_header_encode_one_word�sz&TestQuopri.test_header_encode_one_wordcCs|�dd�dS)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=rgr�r3r3r4�test_header_encode_two_lines�s�z'TestQuopri.test_header_encode_two_linescCs|�dd�dS)Nshello�therez=?iso-8859-1?q?hello=C7there?=rgr�r3r3r4�test_header_encode_non_ascii�s�z'TestQuopri.test_header_encode_non_asciicCs|jdddd�dS)Nr:z=?iso-8859-2?q?hello?=rarrgr�r3r3r4�test_header_encode_alt_charset�s�z)TestQuopri.test_header_encode_alt_charsetcCst�|�}|�||�dSrY)r!�
header_decoder,)r0reZexpected_decoded_headerZdecoded_headerr3r3r4�_test_header_decode�s
zTestQuopri._test_header_decodecCs|�dd�dS�Nr)�rnr�r3r3r4�test_header_decode_null�sz"TestQuopri.test_header_decode_nullcCs|�dd�dS�Nr9rpr�r3r3r4�test_header_decode_one_word�sz&TestQuopri.test_header_decode_one_wordcCs|�dd�dS)Nz
hello=0AworldrKrpr�r3r3r4�test_header_decode_two_lines�sz'TestQuopri.test_header_decode_two_linescCs|�dd�dS)Nz
hello=C7thereuhelloÇthererpr�r3r3r4�test_header_decode_non_ascii�sz'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!rmr�r3r3r4�test_header_decode_re_bug_18380�sz*TestQuopri.test_header_decode_re_bug_18380cCs2|dkrt�|�}ntj||d�}|�||�dS)Nr;)r!rOr,)r0ZencodedZexpected_decodedr<�decodedr3r3r4�_test_decode�szTestQuopri._test_decodecCs|�dd�dSro�rxr�r3r3r4�test_decode_null_wordsz TestQuopri.test_decode_null_wordcCs|�dd�dS)Nr�r(ryr�r3r3r4�test_decode_null_line_null_wordsz*TestQuopri.test_decode_null_line_null_wordcCs|�dd�dSrrryr�r3r3r4�test_decode_one_wordszTestQuopri.test_decode_one_wordcCs|jdddd�dS)Nr9�Xr;ryr�r3r3r4�test_decode_one_word_eolsz#TestQuopri.test_decode_one_word_eolcCs|�dd�dS�N�hello
�hello
ryr�r3r3r4�test_decode_one_lineszTestQuopri.test_decode_one_linecCs|�dd�dS�Nr�ryr�r3r3r4�test_decode_one_line_lfsz"TestQuopri.test_decode_one_line_lfcCs|�dd�dS)Nzhello
r�ryr�r3r3r4�test_decode_one_line_crsz"TestQuopri.test_decode_one_line_crcCs|jdddd�dS)Nr��helloXr}r;ryr�r3r3r4�test_decode_one_line_nlsz"TestQuopri.test_decode_one_line_nlcCs|jdddd�dS)Nr�r�r}r;ryr�r3r3r4�test_decode_one_line_crnlsz$TestQuopri.test_decode_one_line_crnlcCs|�dd�dS)NrJrKryr�r3r3r4�test_decode_one_line_one_word sz(TestQuopri.test_decode_one_line_one_wordcCs|jdddd�dS)NrJZhelloXworldr}r;ryr�r3r3r4�!test_decode_one_line_one_word_eol#sz,TestQuopri.test_decode_one_line_one_word_eolcCs|�dd�dS)N�hello
world
�hello
world
ryr�r3r3r4�test_decode_two_lines&sz TestQuopri.test_decode_two_linescCs|jdddd�dS)Nr�ZhelloXworldXr}r;ryr�r3r3r4�test_decode_two_lines_eol)sz$TestQuopri.test_decode_two_lines_eolcCs|�dd�dS)NA�SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamryr�r3r3r4�test_decode_one_long_line,sz$TestQuopri.test_decode_one_long_linecCs|�dd�dS)Nr*r)ryr�r3r3r4�test_decode_one_space/sz TestQuopri.test_decode_one_spacecCs|�dd�dS)Nz     r)ryr�r3r3r4�test_decode_multiple_spaces2sz&TestQuopri.test_decode_multiple_spacescCs|�dd�dS)Nzhello    
r�ryr�r3r3r4�$test_decode_one_line_trailing_spaces5sz/TestQuopri.test_decode_one_line_trailing_spacescCs|�dd�dS)Nzhello    
world   
r�ryr�r3r3r4�%test_decode_two_lines_trailing_spaces8sz0TestQuopri.test_decode_two_lines_trailing_spacescCs|�dd�dS)Nz=22quoted=20words=22z"quoted words"ryr�r3r3r4�test_decode_quoted_word;sz"TestQuopri.test_decode_quoted_wordcCs|�dd�dS)Nzab=CD=EF�abÍïryr�r3r3r4�test_decode_uppercase_quoting>sz(TestQuopri.test_decode_uppercase_quotingcCs|�dd�dS)Nzab=cd=efr�ryr�r3r3r4�test_decode_lowercase_quotingAsz(TestQuopri.test_decode_lowercase_quotingcCs|�dd�dS)Nzsoft line=
breakzsoft linebreakryr�r3r3r4�test_decode_soft_line_breakDsz&TestQuopri.test_decode_soft_line_breakcCs|�dd�dS)NzA=1,B=A ==> A+B==2ryr�r3r3r4�test_decode_false_quotingGsz$TestQuopri.test_decode_false_quotingcCs|i}|dkrd}n||d<|dkr(d}n||d<tj|f|�}|�||�|dksZ|dkrx|��D]}|�t|�|�qbdS)Nrlr�r(r<r�)r!rBr,r�rorj)r0rpZexpected_encoded_bodyr�r<�kwargsZencoded_bodyrrr3r3r4�_test_encodeJszTestQuopri._test_encodecCs|�dd�dSro�r�r�r3r3r4�test_encode_null^szTestQuopri.test_encode_nullcCs|�dd�dS)Nz

r�r�r3r3r4�test_encode_null_linesasz!TestQuopri.test_encode_null_linescCs|�dd�dSr�r�r�r3r3r4�test_encode_one_linedszTestQuopri.test_encode_one_linecCs|�dd�dSrr�r�r3r3r4�test_encode_one_line_crlfgsz$TestQuopri.test_encode_one_line_crlfcCs|jdddd�dS)Nr�r�r�r;r�r�r3r3r4�test_encode_one_line_eoljsz#TestQuopri.test_encode_one_line_eolcCs |jd�d��d�ddd�dS)Nuhelloυ
rL�latin1z
hello=CF=85
r�r;)r�r�rOr�r3r3r4�(test_encode_one_line_eol_after_non_asciims�z3TestQuopri.test_encode_one_line_eol_after_non_asciicCs|�dd�dS)Nr*z=20r�r�r3r3r4�test_encode_one_spacersz TestQuopri.test_encode_one_spacecCs|�dd�dS)Nz 
z=20
r�r�r3r3r4�test_encode_one_line_one_spaceusz)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
1234rr�r�r�r3r3r4�(test_encode_trailing_space_at_maxlinelen�sz3TestQuopri.test_encode_trailing_space_at_maxlinelencCs|jdddd�dS)Nr�zabc=
d=20
1234rzr�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=
=3Drzr�r�r�r3r3r4�test_encode_shortest_maxlinelen�sz*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr)r�r�)rrr�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)r9rJrK�dxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx rGr�zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20r�rHzlxxxx 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!rBrr3r3r4rI�s�
�zTestQuopri.test_encode)N)N)NN)Frdrerfr�r^r_rbrcrdrfrhrirjrkrlrnrqrsrtrurvrxrzr{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�rIr3r3r3r4rM�s�


rMc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestCharsetcCs2ddlm}z|jd=Wntk
r,YnXdS)Nrr�fake)r�r:ZCHARSETSr:)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	r8rr?)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�rFrurxrrr�)r,r	rBr�r:Zadd_charsetZQP)r0r1r�r�r3r3r4�test_body_encode�szTestCharset.test_body_encodecCs,td�}|�t|�d�|�tjtd�dS)NrFuascÿii)r	r,r�rrZCharsetErrorr�r3r3r4�test_unicode_charset_name�sz%TestCharset.test_unicode_charset_nameN)rdrerfr�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_surprise	s

zTestHeader.test_simple_surprisecCsd}|�t|�|dfg�dS)Nzno decoding neededr�r�r3r3r4�test_header_needs_no_decodingsz(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.rlr�r*)Z
splitcharsz
 )r
r�r�rorj)r0r��lr3r3r4�	test_longs
�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�rlr�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�rror�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�rrjr�rOr)
r0r1r�r�r�r�r�r�r��encrwZustrZnewhr3r3r4�test_multilinguals2

��zTestHeader.test_multilingualcCst�}|�|��d�dSror�r�r3r3r4�test_empty_header_encodeYsz#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|�dtd��||d�dS)Nr)r�r6)r}r
r�r	r�r3r3r4�test_header_ctor_default_args]s

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 behaviorr_r�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_maxlinelendsz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�d�|��}||d�||ttt|����dS)Nr6r@�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?_?=rGz�=?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�rCr�r3r3r4�test_quopri_splittablews

3

z!TestHeader.test_quopri_splittablecCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�|�|��}||d�||ttt|����dS)Nrbr@r�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==?=rGz�=?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)Nr9)r9N�r,rrr�)r0r1r�rCr�r3r3r4�test_us_ascii_header�szTestHeader.test_us_ascii_headercCs&|j}t�}|�dd�||d�dS)Nr9r6)r,r
r�r�r3r3r4�test_string_charset�szTestHeader.test_string_charsetcCs:|j}tdd�}||��d�tdd�}||��d�dS)Nr�rLz=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=�r,r
r�r�r3r3r4�test_utf8_shortest	s


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)rr,r?r
r�rOr�)r0r2r1rCr��er3r3r4�test_bad_8bit_headers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)r0rCr�r�r3r3r4�test_escaped_8bit_headers
�z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS�Nr�rr�r�)r
r�r:r�r,r�r�r)r0rCr�r3r3r4�&test_header_handles_binary_unknown8bit$s
�z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tj�tj�|��}|�t|�d�|�tj�|�|dfg�dSr�)	r
r�r:r�r�rrr,r�)r0rCr�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_header3s
z;TestHeader.test_modify_returned_list_does_not_change_headercCsR|j}t�}|�dd�|�d�|��}||d�tt|��}||��|�dS)Nr9r6Zworldz=?iso-8859-1?q?hello?= world)r,r
r�r�rr)r0r1r�r�r3r3r4� test_encoded_adjacent_nonencoded9s

z+TestHeader.test_encoded_adjacent_nonencodedcCs<|j}d}t|�}||dddg�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_keeperCs�z!TestHeader.test_whitespace_keepercCs|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)rrr�r)r0r2r�r3r3r4�test_broken_base64_headerLsz$TestHeader.test_broken_base64_headercCs tddd�}|�|��d�dS)Nr��	shift_jisrr�r�r�r3r3r4�test_shift_jis_charsetQsz!TestHeader.test_shift_jis_charsetcCst�d�}|�t|�d�dS)NzEmptyHeader:zEmptyHeader: 

)r�r�r,r�r[r3r3r4�!test_flatten_header_with_no_valueUs
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_value\sz4TestHeader.test_encode_preserves_leading_ws_on_valuecCs|�td���d�dS)Nr*r�r�r3r3r4�test_whitespace_headerasz!TestHeader.test_whitespace_headerN)rdrerfr�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;S)<�TestRFC2231cCs8|j}|�d�}||�d�d�||jddd�d�dS)Nz
msg_29.txtr�rFr�%This is even more ***fun*** isn't it!Fr�)rFrz'"This is even more ***fun*** isn't it!")r,r-rBr/r3r3r4r�ks

��zTestRFC2231.test_get_paramcCs�|j}t�}|jdddd�||�d�d�|jddddd�||�d�d�|�d	�}|jddddd�||jd
d�d�dS)
Nrr�rFr)rFr)r�r�r:�languager�ryr�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�ss*�
��
�
�zTestRFC2231.test_set_paramcCsft�}|�dd�|�|dd�|jdddd�|�|dd�|jdd	dd�|�|dd
�dS)Nrr�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)Nryr�r�rFrr�rr�r=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,rhr�r�r3r3r4�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"

            r�r�r�r3r3r4� 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"

r�r�r�r3r3r4�/test_rfc2231_no_language_or_charset_in_filename�s


�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamecCs"d}t�|�}|�|��d�dSr�r�r�r3r3r4�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�r�r3r3r4�test_rfc2231_partly_encodeds
�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�r�r3r3r4�test_rfc2231_partly_nonencodeds
�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"

r�r�r�r3r3r4�/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,r�r�r3r3r4�.test_rfc2231_no_language_or_charset_in_charset7s


�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"

r�r�r�r3r3r4�%test_rfc2231_bad_encoding_in_filenameEs


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

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

rr�r3r3r4�%test_rfc2231_bad_character_in_charset[s
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�r�r3r3r4�&test_rfc2231_bad_character_in_filenamees


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

z
myfile.txtr�r�r3r3r4�test_rfc2231_unknown_encodingqs
z)TestRFC2231.test_rfc2231_unknown_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:r�r�r3r3r4�-test_rfc2231_single_tick_in_filename_extendedzs


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�rr�r�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�r�r3r3r4�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�r�r3r3r4�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�r	r3r3r4�!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 Documentr�r�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�r	r3r3r4�,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�rFrrr�r	r3r3r4�,test_rfc2231_unencoded_then_encoded_segments�s


z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsc
Cs8ddg}|D]&}|j|d��t�|�}W5QRXq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�)rlr�r�)r0Zmessagesr�r2r3r3r4�+test_should_not_hang_on_invalid_ew_messages�s�z7TestRFC2231.test_should_not_hang_on_invalid_ew_messagesN) rdrerfr�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrr
rrr
rrrrrrr3r3r3r4r�gs:%
!




	


r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestSignedc	Cs.t|��}|��}t�|�}W5QRX||fSrYr�)r0r�r��originalr2r3r3r4�_msg_and_objs
zTestSigned._msg_and_objcCsLddl}|�d|j|jB�}|�|��d�}|�|��d�}|�||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$r�)r5r6�Sr��search�groupr,)r0r�resultr5ZrepartZinpartZoutpartr3r3r4�_signed_parts_eq
s
zTestSigned._signed_parts_eqcCs&|�d�\}}|��}|�||�dSr��rr�r�r0rr2rr3r3r4�test_long_headers_as_stringsz&TestSigned.test_long_headers_as_stringcCs*|�d�\}}|jdd�}|�||�dS)Nr��<r�rrr3r3r4�(test_long_headers_as_string_maxheaderlensz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|�d�\}}t�}t|��|�|��}|�||�dSr�)rrrr�r�r)r0rr2r�rr3r3r4�test_long_headers_flattens
z$TestSigned.test_long_headers_flattenN)rdrerfrrr r"r#r3r3r3r4rs
r�__main__)ar5r)rMrr��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+ZTestCasergr|r�r�r�r�rr!rYrur�r�r�r�r�r�r�r/r3r7r8rMr�r�r�rrd�mainr3r3r3r4�<module>s�lCAO((\<0< Xg0K!��5D:h!#