Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/test_email/__pycache__/test_email.cpython-310.opt-1.pyc

o

0�ij�@s�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZddlZddlmZddlmZmZmZdd	lmZmZmZdd
lmZddlm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2m3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddlm7Z7ddlm8Z8ddlm9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?m@Z@ddl1mAZAmBZBdZCd ZDd!ZEGd"d#�d#e@�ZFGd$d%�d%ejG�ZHGd&d'�d'e@�ZIGd(d)�d)ejG�ZJGd*d+�d+ejG�ZKGd,d-�d-ejG�ZLGd.d/�d/ejG�ZMGd0d1�d1ejG�ZNGd2d3�d3e@�ZOGd4d5�d5e@�ZPGd6d7�d7e@�ZQGd8d9�d9e@�ZRGd:d;�d;e@�ZSGd<d=�d=e@�ZTGd>d?�d?e@�ZUGd@dA�dAe@�ZVGdBdC�dCe@�ZWGdDdE�dEe@�ZXGdFdG�dGe@�ZYGdHdI�dI�ZZGdJdK�dKeZeT�Z[GdLdM�dMeZeT�Z\GdNdO�dOejG�Z]GdPdQ�dQejG�Z^GdRdS�dSejG�Z_GdTdU�dUe@�Z`GdVdW�dWe@�ZaGdXdY�dYe@�ZbGdZd[�d[e@�Zcedd\k�r�e�e�dSdS)]�N)�StringIO�BytesIO)�chain��choice)�Thread)�patch)�Charset)�	Generator�DecodedGenerator�BytesGenerator)�Header�
decode_header�make_header)�HeaderRegistry)�Message)�MIMEApplication)�	MIMEAudio)�MIMEBase)�	MIMEImage)�MIMEMessage)�
MIMEMultipart)�MIMENonMultipart)�MIMEText)�Parser�HeaderParser)�
base64mime)�encoders��errors)�	iterators)�
quoprimime)�utils)�threading_helper)�unlink)�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�d��ZXd�S)��TestMessageAPIcCs:|j}|�d�}||�d�gd��||�dd�d�dS)Nz
msg_20.txtZcc)zccc@zzz.orgzddd@zzz.orgzeee@zzz.orgZxxzn/a)�assertEqual�_msgobj�get_all��self�eq�msg�r4�A/opt/alt/python310/lib64/python3.10/test/test_email/test_email.py�test_get_all9s
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�r1r2r3r;r4r4r5�test_getset_charset?s,


z"TestMessageAPI.test_getset_charsetcCs8|j}t�}|�d�||��jd�||dd�dS)N�us-asciir:�text/plain; charset="us-ascii")r-rrAr@rDr0r4r4r5�test_set_charset_from_stringYs

z+TestMessageAPI.test_set_charset_from_stringcCs0t�}td�}|�d|�|�|��jd�dS)Nr7zThis is a string payload)rr	�set_payloadr-r@rD)r1r3r;r4r4r5�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	rrJr-�get_payload�r1�datar;r3r4r4r5�+test_set_payload_with_8bit_data_and_charsetfsz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsRd}td�}d|_t�}|�|�d�|�|�|dd�|�|jdd�|�dS�NrLrMr<�8bitTrO)r	�
body_encodingrrJrPr-rQrRr4r4r5�>test_set_payload_with_non_ascii_and_charset_body_encoding_noneoszMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCsLd}td�}d|_t�}|�||�|�|dd�|�|jdd�|�dSrU)r	rWrrJr-rQrRr4r4r5�>test_set_payload_with_8bit_data_and_charset_body_encoding_nonexszMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs$t�}|�g�|�|��g�dS�N�rrJr-rQ�r1r3r4r4r5�test_set_payload_to_list��
z'TestMessageAPI.test_set_payload_to_listcCs8t�}d|d<|�d�tt��}|�td|j|�dS)N�multipart/mixedr>zstring payloadz[Aa]ttach.*non-multipart)rrJrZassertRaisesRegex�	TypeError�attach)r1r3Zsub_msgr4r4r5�"test_attach_when_payload_is_string�s

�z1TestMessageAPI.test_attach_when_payload_is_stringcCsl|j}|�d�}|��}||gd��|�d�}|�d�}||gd��|�d�}|��}||gd��dS)Nz
msg_08.txt)NrGr7�
iso-8859-2�koi8-rz
msg_09.txt�dingbat)rerGr7rerdz
msg_12.txt)NrGr7Nrcz
iso-8859-3rGrd)r-r.�get_charsets)r1r2r3�charsetsr4r4r5�test_get_charsets�s



z TestMessageAPI.test_get_charsetscCsV|j}|�d�}dd�|��D�}||ddg�|�d�}|�d�}||��d�dS)N�
msg_04.txtcS�g|]}|���qSr4��get_filename��.0�pr4r4r5�
<listcomp>��z4TestMessageAPI.test_get_filename.<locals>.<listcomp>�msg.txt�
msg_07.txt��dingusfish.gif)r-r.rQrl)r1r2r3�	filenames�subpartr4r4r5�test_get_filename�s


z TestMessageAPI.test_get_filenamecCs4|j}|�d�}dd�|��D�}||ddg�dS)Nz
msg_44.txtcSrjr4rkrmr4r4r5rp�rqzHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>rr�r-r.rQ)r1r2r3rvr4r4r5�%test_get_filename_with_name_parameter�s
z4TestMessageAPI.test_get_filename_with_name_parametercC�"|j}|�d�}||��d�dS)Nrs�BOUNDARY)r-r.�get_boundaryr0r4r4r5�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.txtr|�r:z3text/plain; charset="us-ascii"; boundary="BOUNDARY"riz$multipart/mixed; boundary="BOUNDARY"�
msg_03.txt)r-r.�set_boundary�items�lower�assertRaisesr�HeaderParseError)r1r2r3�header�valuer4r4r5�test_set_boundary�s






�z TestMessageAPI.test_set_boundarycCsLtd�}|�|��ddd�|��|�|��dddd�d�dS)Nz	form-datarrtzmultipart/form-data�!z!multipart/form-data; boundary="==)rr-r��	as_stringr\r4r4r5�test_make_boundary�s�z!TestMessageAPI.test_make_boundarycCsvtddd��}|��}Wd�n1swYt�}|�|�}t�}t|dd�}|�|d�|�|��|�dS)N�
msg_46.txtrM��encodingTrF)	r%�readr�parsestrrr
�flattenr-�getvalue�r1�fpZmsgdata�parserr3�out�genr4r4r5�test_message_rfc822_only�s
�
z'TestMessageAPI.test_message_rfc822_onlycCs~tddd��}|���d�}Wd�n1swYtj��}|�|�}t�}tj�	|�}|�
|�|�|��|�dS)Nr�rMr��ascii)
r%r��encode�emailr��BytesHeaderParserZ
parsebytesr�	generatorrr�r-r�r�r4r4r5�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.txtTrOrs This is a 7bit encoded message.
rts-�This is a Quoted Printable encoded message!
�s!This is a Base64 encoded message.�s"This is a Base64 encoded message.
r�s/This has no Content-Transfer-Encoding: header.
ryr0r4r4r5�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<TrO�hello world�foosfoo)r-rrJrQ)r1r2r3�cter4r4r5�test_get_decoded_uu_payloads

z*TestMessageAPI.test_get_decoded_uu_payloadcCst�}|�t|jd�dS)Nrt)rr�r`rQr\r4r4r5�*test_get_payload_n_raises_on_non_multipart�z9TestMessageAPI.test_get_payload_n_raises_on_non_multipartcCsn|j}|�d�}tddd��}|��}Wd�n1swYt�}t|�}|�|�||��|�dS)Nrsz
msg_17.txtrMr�)r-r.r%r�rrr�r�)r1r2r3r��text�s�gr4r4r5�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\r4r4r5�test__contains__szTestMessageAPI.test__contains__cCs�|�d�}tddd��}|��}Wd�n1swY|�|t|��|jdd�}|�d�}|�|d�d��|�|t	�
|d	d���dS)
NrrMr�T��unixfromr)rzFrom rt)r.r%r�r-�strr��split�
assertTrue�
startswith�NL�join)r1r3r�r��fullrepr�linesr4r4r5�test_as_string*s

�
zTestMessageAPI.test_as_stringcC�T|�d�}|jjdd�}|j|d�}t�}t||d�}|�|�|�||���dS�Nr�
��linesep��policy)	r.r��cloner�rr
r�r-r��r1r3Z	newpolicyr�r�r�r4r4r5�test_as_string_policy4�

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
            r7a%            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��r1�m�source�expectedr3r4r4r5�#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
            r7r��replace)r�r�r�rPr�r�r-r�r�r4r4r5�4test_nonascii_as_string_without_content_type_and_cteSs



zCTestMessageAPI.test_nonascii_as_string_without_content_type_and_ctecCs�|�d�}tddd��}|���d�}Wd�n1swY|�|t|��|jdd�}|�d�}|�|d�	d	��|�|d�
|d
d���dS)NrrMr�r�Tr��
rsFrom rt)r.r%r�r�r-�bytes�as_bytesr�r�r�r�)r1r3r�rSr�r�r4r4r5�
test_as_bytes`s
�
zTestMessageAPI.test_as_bytescCr�r�)	r.r�r�r�rrr�r-r�r�r4r4r5�test_as_bytes_policyjr�z#TestMessageAPI.test_as_bytes_policycCs t�d�}|�|�d�d�dS)NzContent-Type: blarg; baz; boo
�bazr*�r��message_from_stringr-rCr\r4r4r5�test_bad_paramt�
zTestMessageAPI.test_bad_paramcC�t�d�}|�|��d�dS�Nz
From: foo
�r�r�r-rlr\r4r4r5�test_missing_filenamex�
z$TestMessageAPI.test_missing_filenamecCst�d�}|�|��d�dS)Nz%Content-Disposition: blarg; filename
r*r�r\r4r4r5�test_bogus_filename|s�z"TestMessageAPI.test_bogus_filenamecCr�r��r�r�r-r}r\r4r4r5�test_missing_boundary�r�z$TestMessageAPI.test_missing_boundarycCsx|j}t�d�}||jdd�gd��t�d�}||jdd�gd��||��d�t�d�}||jdd�gd��dS)N�&X-Header: foo=one; bar=two; baz=three
�x-header�r�))r��one)�bar�two�r�Zthreez X-Header: foo; bar=one; baz=two
))r�r*)r�r�)r�r��"X-Header: foo; bar="one"; baz=two
)r-r�r��
get_paramsr0r4r4r5�test_get_params�s(������zTestMessageAPI.test_get_paramscCs$t�}d|d<|�|�d�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"r>�boundaryZCPIMSSMTPC06p5f3tG)rr-rCr\r4r4r5�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�rCr0r4r4r5�test_get_param�s��zTestMessageAPI.test_get_paramcCs&|�d�}|�|�d��d�d�dS)Nz
msg_22.txtrt�namez
wibble.JPG)r.r-rQrCr\r4r4r5�'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\r4r4r5�#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\r4r4r5�test_get_param_with_quotes�s��z)TestMessageAPI.test_get_param_with_quotesc	Cs�d}dD]G\}}|j|||d��3|�d�|d|}tj�|�}|�t|�|�|�tt|��d�|�|d|�Wd�n1sFwYqdd|d}tj�|�}|�||g�dS)Ni��)�r*r*)�foo=barr�)z FOO = bar    r�)r��r�N�;rtrzs=")�subTestr��messageZ_parseparamr-�len�set)r1r�r�r��src�resZ	malformedr4r4r5� test_get_param_linear_complexity�s��z/TestMessageAPI.test_get_param_linear_complexitycCs>t�d�}|�d|�|�d|�|�d|�|�d|�dS)NzHeader: existsr�r
ZHEADERZheaderx)r�r�r�ZassertNotInr\r4r4r5�test_field_containment�s

z%TestMessageAPI.test_field_containmentcCs�|j}t�}|�dd�||�d�d�|�dd�||�d�d�||jddd�d�||��gd��||jdd�gd	��|jdd
dd�||jddd�d
�dS)
Nr;�iso-2022-jp�
importance�
high valueFr��"high value")�r9r*)r;r)r	r
)r)r;z
"iso-2022-jp")r	rziso-9999-xxzX-Jimmyr�)r-r�	set_paramrCr�r0r4r4r5�test_set_param�szTestMessageAPI.test_set_paramcCsp|j}|�d�}||��gd��|�d�}|�d�||��ddg�|�d|�||��ddd|fg�dS)N�
msg_05.txt)��multipart/reportr*)�report-type�delivery-status�r��%D1690A7AC1.996856090/mail.example.comrrr)r-r.r�rC�	del_paramr
)r1r2r3Zold_valr4r4r5�test_del_param�s&
�

����zTestMessageAPI.test_del_paramcCs6t�}|jdddd�|�dd�|�|dd�dS)N�Content-Disposition�
attachment�bud.gif��filenamer�content-disposition�r�
add_headerrr-r\r4r4r5�test_del_param_on_other_headersz-TestMessageAPI.test_del_param_on_other_headercCst�}|�dd�dS)Nrr)rrr\r4r4r5�$test_del_param_on_nonexistent_headersz3TestMessageAPI.test_del_param_on_nonexistent_headercCs@t�}|jdddd�|d}|jddd�|�|d|�dS)Nr>r9rM�r;�foobarr�r)r1r3Zexisting_headerr4r4r5�test_del_nonexistent_params
z)TestMessageAPI.test_del_nonexistent_paramcCsj|j}t�}|�t|jd�|�d�||dd�|�dd�||dd�|�d�||dd�dS)	Nr�r9r:r;rGrHz	text/htmlztext/html; charset="us-ascii")r-rr��
ValueError�set_typer
r0r4r4r5�
test_set_types

zTestMessageAPI.test_set_typecCs.t�}d|d<|�dd�|�|dd�dS)Nr9zX-Content-Type�application/octet-streamzx-content-type)rr&r-r\r4r4r5�test_set_type_on_other_headersz,TestMessageAPI.test_set_type_on_other_headercC�t�}|�|��d�dS)Nr9)rr-rBr\r4r4r5�test_get_content_type_missing#r�z,TestMessageAPI.test_get_content_type_missingcCs$t�}|�d�|�|��d�dS)N�message/rfc822)r�set_default_typer-rBr\r4r4r5�/test_get_content_type_missing_with_default_type'r^z>TestMessageAPI.test_get_content_type_missing_with_default_typecC�$|�d�}|�|�d���d�dS)N�
msg_30.txtrr,�r.r-rQrBr\r4r4r5�+test_get_content_type_from_message_implicit,�
�z:TestMessageAPI.test_get_content_type_from_message_implicitcCr/)N�
msg_28.txtrr,r1r\r4r4r5�+test_get_content_type_from_message_explicit1r3z:TestMessageAPI.test_get_content_type_from_message_explicitcC�|�d�}|�|��d�dS)Nr�r9�r.r-rBr\r4r4r5�6test_get_content_type_from_message_text_plain_implicit6r�zETestMessageAPI.test_get_content_type_from_message_text_plain_implicitcCr6)Nrr9r7r\r4r4r5�6test_get_content_type_from_message_text_plain_explicit:r�zETestMessageAPI.test_get_content_type_from_message_text_plain_explicitcCr*)Nr��rr-�get_content_maintyper\r4r4r5�!test_get_content_maintype_missing>r�z0TestMessageAPI.test_get_content_maintype_missingcC�$t�}|�d�|�|��d�dS)Nr,r)rr-r-r;r\r4r4r5�3test_get_content_maintype_missing_with_default_typeBr^zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCr/)Nr0rr�r.r-rQr;r\r4r4r5�/test_get_content_maintype_from_message_implicitG�
z>TestMessageAPI.test_get_content_maintype_from_message_implicitcCr/)Nr4rrr?r\r4r4r5�/test_get_content_maintype_from_message_explicitKrAz>TestMessageAPI.test_get_content_maintype_from_message_explicitcCr6)Nr�r��r.r-r;r\r4r4r5�:test_get_content_maintype_from_message_text_plain_implicitOr�zITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitcCr6)Nrr�rCr\r4r4r5�:test_get_content_maintype_from_message_text_plain_explicitSr�zITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitcCr*)N�plain�rr-�get_content_subtyper\r4r4r5� test_get_content_subtype_missingWr�z/TestMessageAPI.test_get_content_subtype_missingcCr=)Nr,�rfc822)rr-r-rHr\r4r4r5�2test_get_content_subtype_missing_with_default_type[r^zATestMessageAPI.test_get_content_subtype_missing_with_default_typecCr/)Nr0rrJ�r.r-rQrHr\r4r4r5�.test_get_content_subtype_from_message_implicit`rAz=TestMessageAPI.test_get_content_subtype_from_message_implicitcCr/)Nr4rrJrLr\r4r4r5�.test_get_content_subtype_from_message_explicitdrAz=TestMessageAPI.test_get_content_subtype_from_message_explicitcCr6)Nr�rF�r.r-rHr\r4r4r5�9test_get_content_subtype_from_message_text_plain_implicithr�zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCr6)NrrFrOr\r4r4r5�9test_get_content_subtype_from_message_text_plain_explicitlr�zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitcC�"t�}d|d<|�|��d�dS)N�no-slash-in-this-stringr>r�r:r\r4r4r5�test_get_content_maintype_errorp�z.TestMessageAPI.test_get_content_maintype_errorcCrR)NrSr>rFrGr\r4r4r5�test_get_content_subtype_errorurUz-TestMessageAPI.test_get_content_subtype_errorcCs�|j}t�}|�dd�|�dd�|�dd�||��gd��||��gd��|�dd	�||��gd��||��gd
��|�dd�|�dd�||��gd
��||��gd��|�t|jdd�dS)N�First�One�Second�Two�Third�Three)rWrYr[)rXrZr\�Twenty)rXr]r\�Eleven�One Hundred)rWrYr[rW)r_r]r\r^ZFourthZMissing)r-rr�keys�values�replace_headerr��KeyErrorr0r4r4r5�test_replace_headerzsz"TestMessageAPI.test_replace_headercCspt�}|�|���|jdddd�|�|��d�|�dd�|�|��d�|�dd�|�|��d�dS)Nrrz
random.avir�inlineZInlinE)r�assertIsNoneZget_content_dispositionrr-rbr\r4r4r5�test_get_content_disposition�s�z+TestMessageAPI.test_get_content_dispositioncCsPd}t�}d|d<d|d<|�|�|�|jdd�d�|�|jd	tj�dS)
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midir:rNr<TrOs����.���p���r)rrJr-rQ�assertIsInstance�defectsr�InvalidBase64CharactersDefect�r1�xr3r4r4r5�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 dor9r:rVr<TrOzraw-unicode-escape)rrJr-rQr�rkr4r4r5�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 dorM�text/plain; charset="utf-8"r:rVr<TrO)r�rZ_payloadr-rQrkr4r4r5�test_questionable_bytes_payload�s
z.TestMessageAPI.test_questionable_bytes_payloadcC�*t�}|jdddd�|�d|d�dS)Nrrrrzattachment; filename="bud.gif"�rrr-r\r4r4r5�test_ascii_add_header�s��z$TestMessageAPI.test_ascii_add_headercCrq)Nrr�Fußballer.pptrz/attachment; filename*=utf-8''Fu%C3%9Fballer.pptrrr\r4r4r5�test_noascii_add_header����z&TestMessageAPI.test_noascii_add_headercCrq)Nrr)r7r*rtrz1attachment; filename*=iso-8859-1''Fu%DFballer.pptrrr\r4r4r5�#test_nonascii_add_header_via_triple�rvz2TestMessageAPI.test_nonascii_add_header_via_triplecCrq)Nrrzwindows [filename].pptrz-attachment; filename="windows [filename].ppt"rrr\r4r4r5�#test_ascii_add_header_with_tspecial�rvz2TestMessageAPI.test_ascii_add_header_with_tspecialcCrq)NrruFußballer [filename].pptrz@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptrrr\r4r4r5�&test_nonascii_add_header_with_tspecial�rvz5TestMessageAPI.test_nonascii_add_header_with_tspecialcC�LdD]!}t�}d||d<d|d<|�d�|�|jdd�d	d
|�qdS)N��latin-1r��text/plain; charset=%sr:r=r<sfoo=e6=96=87barTrO�	foo文bar�1get_payload returns wrong result with charset %s.r[�r1r;r3r4r4r5�test_binary_quopri_payload��

��z)TestMessageAPI.test_binary_quopri_payloadcCrz)Nr{r}r:rNr<sZm9v5paHYmFyTrOr~rr[r�r4r4r5�test_binary_base64_payload�r�z)TestMessageAPI.test_binary_base64_payloadc
Cs^dD]*}dD]%}t�}d||d<||d<|�d�|�|jdd�d	td
��||��qqdS)Nr{r�r}r:r<s begin 666 -
)9F]OYI:'8F%R
 
end
TrOr~)z!get_payload returns wrong result z"with charset {0} and encoding {1}.)rrJr-rQr��format)r1r;r�r3r4r4r5�test_binary_uuencode_payload�s

���z+TestMessageAPI.test_binary_uuencode_payloadcCs*t�}|jdddd�|�d|d�dS)Nrre)Zfoo_barzinline; foo-barrrr\r4r4r5�$test_add_header_with_name_only_param�z3TestMessageAPI.test_add_header_with_name_only_paramcCs&t�}|�dd�|�d|d�dS)NzX-Statusr*rrr\r4r4r5�test_add_header_with_no_value	�z,TestMessageAPI.test_add_header_with_no_valuecCs&t�}td�|d<|�tj|j�dS�Nzdummy
X-Injected-Header: testZDummy)rr
r�rr�r�r\r4r4r5�(test_embedded_header_via_Header_rejectedr�z7TestMessageAPI.test_embedded_header_via_Header_rejectedcCs"t�}d|d<|�tj|j�dSr�)rr�rr�r�r\r4r4r5�(test_embedded_header_via_string_rejectedrUz7TestMessageAPI.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��r1r�r4r4r5�-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�r�r4r4r5�+test_unicode_body_defaults_to_utf8_encoding'sz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)Y�__name__�
__module__�__qualname__r6rFrIrKrTrXrYr]rbrhrxrzr~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�rrrrr r!r$r'r)r+r.r2r5r8r9r<r>r@rBrDrErIrKrMrNrPrQrTrVrdrgrmrnrprsrurwrxryr�r�r�r�r�r�r�r�r�r4r4r4r5r,8s�			

	



r,c@�<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncoderscCsptdd��}|��}Wd�n1swYtjj�|�}|��}|�d�}|�t	dd�|D��d�dS)N�PyBanner048.gif�rbr)cS�g|]}t|��qSr4)r�rnrlr4r4r5rp=rqz;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>�L)
r%r�r��mime�imagerrQr��assertLessEqual�max)r1r��bindataZmimedZbase64edr�r4r4r5�test_EncodersEncode_base646s
�
z'TestEncoders.test_EncodersEncode_base64cCs(|j}t�}|�d�||dd�dS)NrGr<�7bit)r-rrAr0r4r4r5�test_encode_empty_payload?s
z&TestEncoders.test_encode_empty_payloadcCsP|j}td�}||dd�td�}||dd�tddd�}||dd�dS)	N�hello worldr<r�uhello ø worldrNr7�Z_charsetr=)r-rr0r4r4r5�test_default_cteEszTestEncoders.test_default_ctecCs8|j}tddd�}||dd�||��t�d��dS)Nu文
�euc-jpr�r<r�z�            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r-rr�r�r�r0r4r4r5�test_encode7or8bitQszTestEncoders.test_encode7or8bitcC�&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\r4r4r5�test_qp_encode_latin1`sz"TestEncoders.test_qp_encode_latin1cCr�)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\r4r4r5�test_qp_encode_non_latin1jsz&TestEncoders.test_qp_encode_non_latin1N)	r�r�r�r�r�r�r�r�r�r4r4r4r5r�4s	
r�c@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�rr
r�r��r1r2r3�sfpr�r4r4r5�test_split_long_continuation{s

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��r1r2Zhstr�hr4r4r5�,test_another_long_almost_unsplittable_header�s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)
Nr7rcrM�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?=

r���
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
�appendrrr
r�r�r�)r1r2r��cz�utf8�g_head�cz_head�	utf8_headr�r3r�r4r4r5�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��r1r2r�r4r4r5�test_long_header_encode�s
�z'TestLongHeaders.test_long_header_encodecC�&|j}tdddd�}||��d�dS)Nr�r�r��r�r�r�r�r�r4r4r5�<test_long_header_encode_with_tab_continuation_is_just_a_hint���zLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hintcCr�)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�r4r4r5�-test_long_header_encode_with_tab_continuation�r�z=TestLongHeaders.test_long_header_encode_with_tab_continuationcCstdd�}|�|��d�dS)N�文r��=?iso-2022-jp?b?GyRCSjgbKEI=?=�r
r-r��r1r�r4r4r5�0test_header_encode_with_different_output_charset�r�z@TestLongHeaders.test_header_encode_with_different_output_charsetcCs(td�d�d�}d}|�|��|�dS)Ns6test-ja ����Ƥ��줿�᡼��ϻʲ�Ԥξ�ǧ���ԤäƤ��ޤ�r�z�=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r
rPr-r�)r1r�rr4r4r5�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�rrr
r�r�r�r4r4r5�test_header_splitters�
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>Nr4�rn�ir4r4r5�	<genexpr>��z@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��rangerJrr
r�r�r�r4r4r5�test_no_semis_header_splitters

z-TestLongHeaders.test_no_semis_header_splittercC� |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�r4r4r5�"test_last_split_chunk_does_not_fit%�z2TestLongHeaders.test_last_split_chunk_does_not_fitcCr�)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�r4r4r5�>test_splittable_leading_char_followed_by_overlong_unsplittable.r�zNTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplittablecCr�)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�r4r4r5�Gtest_multiple_splittable_leading_char_followed_by_overlong_unsplittable7r�zWTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplittablecC� |j}td�}||��d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;r�r�r4r4r5�1test_trailing_splittable_on_overlong_unsplittable@�zATestLongHeaders.test_trailing_splittable_on_overlong_unsplittablecCr�)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�r4r4r5�Itest_trailing_splittable_on_overlong_unsplittable_with_leading_splittableGr�zYTestLongHeaders.test_trailing_splittable_on_overlong_unsplittable_with_leading_splittablecCr�)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�r4r4r5�5test_long_header_with_multiple_sequential_split_charsPr�zETestLongHeaders.test_long_header_with_multiple_sequential_split_charscCr�)N�Kthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr�r�r4r4r5�:test_splitter_split_on_punctuation_only_if_fws_with_headerXr�zJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headercCr�)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�r4r4r5�Dtest_leading_splittable_in_the_middle_just_before_overlong_last_part_�zTTestLongHeaders.test_leading_splittable_in_the_middle_just_before_overlong_last_partcCr�)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself r�r�r4r4r5�/test_overlong_last_part_followed_by_split_pointjr�z?TestLongHeaders.test_overlong_last_part_followed_by_split_pointcCr�)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�r4r4r5�@test_multiline_with_overlong_parts_separated_by_two_split_pointsqr�zPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointscCr�)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�r4r4r5�>test_multiline_with_overlong_last_part_followed_by_split_point|r�zNTestLongHeaders.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�rJrr
r�r�r�r4r4r5�%test_long_header_with_whitespace_runs�s

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�r4r4r5�'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�rrJrr
r�r�r�r4r4r5�.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�r4r4r5�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�r4r4r5�"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�r4r4r5�&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 gibtr7r�r�u-grünes Licht für Offshore-Windkraftprojekter�r�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�)r1r2r3r�r4r4r5�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
)r1r2r3Z
header_stringr4r4r5� test_long_8bit_header_no_charsets
�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�)r1r2r�r3r4r4r5�test_long_to_headers
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.r�r�z\This is an example of string which has almost the limit of header length.
 Add another line.�r�r
r�r��r1r2r�r�r4r4r5�test_long_line_after_append's

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�rr4r4r5�test_shorter_line_with_append0s
�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. r7r�r�r�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�)r1r2�fnZgsr�r4r4r5�test_long_field_name8s
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��r1r�r3r4r4r5�test_long_received_headerGs
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")rr�r�rr�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")

rrr4r4r5�test_string_headerinst_eqYs
�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�)r1r2r3�tr4r4r5�-test_long_unbreakable_lines_with_continuationls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��r1r2r�r3r4r4r5�"test_another_long_multiline_header�s
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)r1r2r�r3r4r4r5�%test_long_lines_with_different_header�s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 worksrMr�)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�r4r4r5�*test_long_rfc2047_header_with_embedded_fws�s
�
�z:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+r�r�r��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�rrrr	r
r
rrrr4r4r4r5r�wsR6	


					
r�c@r�)�TestFromManglingcCs"t�|_d|jd<|j�d�dS)Nzaaa@bbb.orgr�z(From the desk of A.A.A.:
Blah blah blah
)rr3rJ�r1r4r4r5�setUp�s
zTestFromMangling.setUpcC�2t�}t|dd�}|�|j�|�|��d�dS)NT�Zmangle_from_z<From: aaa@bbb.org

>From the desk of A.A.A.:
Blah blah blah
�rr
r�r3r-r��r1r�r�r4r4r5�test_mangled_from��z"TestFromMangling.test_mangled_fromcCr)NFrz;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
rrr4r4r5�test_dont_mangle_from�rz&TestFromMangling.test_dont_mangle_fromcCsTt�}t|dd�}t�t�d��}|�|�|�tdd�|�	��
d�D��d�dS)NTra)            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 rt)r�r�r4r4r5rp�s
�zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r)r�)rr
r�r�r�r�r�r-rr�r�)r1r�r�r3r4r4r5�'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

        rMsFrom Rölli
Trs
>From Rölli
)
r�r�r�r�r�rrr�r-r�)r1r�r3�br�r4r4r5� 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: È
        rM)r�r�r�r�r�)r1r�r3r4r4r5�$test_multipart_with_bad_bytes_in_cte�s�z5TestFromMangling.test_multipart_with_bad_bytes_in_cteN)	r�r�r�rrrrrr r4r4r4r5r�src@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudiocC�Dtdd��
}|��|_Wd�n1swYt|j�|_dS)N�audiotest.aur�)r%r��
_audiodatar�_au�r1r�r4r4r5r��zTestMIMEAudio.setUpcC�|�|j��d�dS)Nzaudio/basic)r-r&rBrr4r4r5�test_guess_minor_type	�z#TestMIMEAudio.test_guess_minor_typecC�(|j��}|�t�t|d��|j�dS�Nr�)r&rQr-rN�decodebytesr�r%�r1�payloadr4r4r5�
test_encoding�
�zTestMIMEAudio.test_encodingcC� t|jd�}|�|��d�dS)N�fishz
audio/fish)rr%r-rB)r1Zaur4r4r5�test_checkSetMinor�z TestMIMEAudio.test_checkSetMinorcC�|j}|jjdddd�||jdd�||jjdd�dd	g�||jjd
dd�d�g}||jjddd�d�|�|jjd|dd
�|�|�|j�d|�|�|�|jjd|dd�|�dS)Nrrr$rrz#attachment; filename="audiotest.au"r��rr*)rr$rr*r��Zfailobjr�r#)r-r&rr�rC�assertIs�r1r2Zmissingr4r4r5�test_add_header�4
�
�������zTestMIMEAudio.test_add_headerN�r�r�r�rr*r1r5r<r4r4r4r5r"�r"c@r!)�
TestMIMEImagecCr#)Nr�r�)r%r��_imgdatar�_imr'r4r4r5r,r(zTestMIMEImage.setUpcCr))Nz	image/gif)r-rBrBrr4r4r5r*1r+z#TestMIMEImage.test_guess_minor_typecCr,r-)rBrQr-rNr.r�rAr/r4r4r5r14r2zTestMIMEImage.test_encodingcCr3)Nr4z
image/fish)rrAr-rB)r1Zimr4r4r5r59r6z TestMIMEImage.test_checkSetMinorcCr7)Nrrrurrz%attachment; filename="dingusfish.gif"r�r8)rrurr*r�r9r#)r-rBrr�rCr:r;r4r4r5r<=r=zTestMIMEImage.test_add_headerNr>r4r4r4r5r@+r?r@c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestMIMEApplicationcCs.|j}td�}||��d�||dd�dS)N�������r(r<rN)r-rrBr0r4r4r5�test_headersTsz TestMIMEApplication.test_headerscCs:|j}d}t|�}||����d�||jdd�|�dS)NrDz+vv8/f7/TrO)r-rrQ�strip)r1r2�	bytesdatar3r4r4r5�	test_bodyZs
zTestMIMEApplication.test_bodycCs�d}t|tjd�}|�|��dt|��|�|jdd�|�|�|dd�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�|�|dd�dS)NrD�Z_encoder��TrOr?rV)rr�encode_7or8bitr-rQrrrr�r�r�r��r1rGr3r�r�Zwireform�msg2r4r4r5�$test_binary_body_with_encode_7or8bitbs

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|tjd�}|�|��dt|��|�|jdd�|�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�dS)NrDrIrJTrO)rr�encode_noopr-rQrrrr�r�r�r�rLr4r4r5�!test_binary_body_with_encode_noopss

z5TestMIMEApplication.test_binary_body_with_encode_noopcCshd}t|tjd�}|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|jdd�|�dS)Ns������rITrO)rrrOr-rQrrr�r�r�r�rLr4r4r5�0test_binary_body_with_unicode_linend_encode_noop�s

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|tjd�}|�|��d�|�|jdd�|�|�|dd�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�|�|dd�dS)Ns������ rIz=FA=FB=FC=FD=FE=FF=20TrOr?r=)rrZ
encode_quoprir-rQrrr�r�r�r�rLr4r4r5�#test_binary_body_with_encode_quopri�s

z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|tjd�}|�|��d�|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�dS)NrDrIz	+vv8/f7/
TrO)rrZ
encode_base64r-rQrrr�r�r�r�rLr4r4r5�#test_binary_body_with_encode_base64�s

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
r�r�r�rErHrNrPrQrRrSr4r4r4r5rCSsrCc@sVeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�d�dd��ZdS)�TestMIMETextcCstd�|_dS�N�hello there)r�_msgrr4r4r5r��zTestMIMEText.setUpcCs`|j}||j��d�||j�d�d�g}|�|j�d|�|�|�|jjd|dd�|�dS)Nr9r;rGr#r�)r-rWrBrCr:r;r4r4r5�
test_types�s�zTestMIMEText.test_typescCs&|�|j��d�|�|j���dSrU)r-rWrQ�assertFalse�is_multipartrr4r4r5�test_payload�szTestMIMEText.test_payloadcCsz|j}tddd�}||��jd�||dd�td�}d|_td|d�}||��jd�||dd�||��d�dS)NrVrGr�r:rHrMro)r-rr@rDr	rWrQrEr4r4r5�test_charset�szTestMIMEText.test_charsetcCs4|j}tddd�}||��jd�||dd�dS)NrVrGr�r:rH)r-rr@rDr0r4r4r5�test_7bit_input�szTestMIMEText.test_7bit_inputcCs>|j}td�}||��d�||dd�|�d|���dS)NrVrGr:rH)r-rr@r�r�r0r4r4r5�test_7bit_input_no_charset�s
z'TestMIMEText.test_7bit_input_no_charsetcCsPd}|j}t|dd�}||��jd�||dd�||jdd�|�d��dS)N�кирилицаrMr�r:roTrO)r-rr@Zoutput_charsetrQr�)r1�teststrr2r3r4r4r5�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)r1rar4r4r5�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
r�r�r�rrYr\r]r^r_rb�unittest�skiprdr4r4r4r5rT�s	
rTc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�
TestMultipartcCs
tdd��}|��}Wd�n1swYtdddd�}t|dd�}|jd	d
dd�td�}|�|�|�|�d
|d<d|d<d|d<d}t�|�}|ddkrYtj	}ntj
}|dkrcd}	nd}	d|	|df}
t�dt�|��|
|d<||_||_
||_dS)Nr�r��	multipart�mixedr|�r�ru)r�rrrz$Hi there,

This is the dingus fish.
zBarry <barry@digicool.com>r�z)Dingus Lovers <cravindogs@cravindogs.com>r�zHere is your dingus fishr�g�4F�cp�A���r�-�+z %s%04d�$z%a, %d %b %Y %H:%M:%SZDate)r%r�rrrrra�time�	localtime�timezone�altzone�strftimerWrB�_txt)r1r�rS�	containerr�Zintro�nowZ	timetupleZtzsecsZsignZtzoffsetr4r4r5r�s@
��


��
zTestMultipart.setUpcCs�|j}|j}|j}|�|���||��d�|t|���d�|t|jd�|�d�}|�d�}|�	||j
�|�	||j�||��||g�|�|���|�|���dS)Nr_r�rrt)
r-r�rWr�r[rBrrQ�
IndexErrorr:rtrBrZ)r1r2�raisesr�Zm0Zm1r4r4r5�test_hierarchys

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--
)rr�r�r�)r1r�r3r4r4r5�test_empty_multipart_idempotent"s
z-TestMultipart.test_empty_multipart_idempotentcCs@tdd�}d|d<d|d<d|d<|�d	�|�|��d
�dS)Nrhri�	A subjectr��aperson@dom.ainr��bperson@dom.ainr�r|z�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��r1�outerr4r4r5�/test_no_parts_in_a_multipart_with_none_epilogue3s

z=TestMultipart.test_no_parts_in_a_multipart_with_none_epiloguecCsLtdd�}d|d<d|d<d|d<d	|_d	|_|�d
�|�|��d�dS)Nrhrir{r�r|r�r}r�r*r|z�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�r~r4r4r5�0test_no_parts_in_a_multipart_with_empty_epilogueEs

z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguecCsV|j}tdd�}d|d<d|d<d|d<|�d	�td
�}|�|�||��d�dS)Nrhrir{r�r|r�r}r�r|r��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�rrar��r1r2rr3r4r4r5�test_one_part_in_a_multipartZs


z*TestMultipart.test_one_part_in_a_multipartcC�\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nrhrir{r�r|r�r}r�r*r�r|aContent-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�rrar�r�r�r4r4r5�1test_seq_parts_in_a_multipart_with_empty_preambles�


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamblecC�\|j}tdd�}d|d<d|d<d|d<d|_td	�}|�|�|�d
�||��d�dS�Nrhrir{r�r|r�r}r�r�r|r�r�r�r4r4r5�0test_seq_parts_in_a_multipart_with_none_preamble�r�z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblecCr�r��r�rr�rrar�r�r�r4r4r5�0test_seq_parts_in_a_multipart_with_none_epilogue�r�z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguecCr�)
Nrhrir{r�r|r�r}r�r*r�r|r�r�r�r4r4r5�1test_seq_parts_in_a_multipart_with_empty_epilogue�r�z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epiloguecCr�)
Nrhrir{r�r|r�r}r�r)r�r|aContent-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�r�r4r4r5�.test_seq_parts_in_a_multipart_with_nl_epilogue�r�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�q*dS)N�
msg_36.txtr�rtzmultipart/alternativezmessage/external-bodyrr9)r-r.rrQrB)r1r2r3�msg1rw�
subsubpartr4r4r5�test_message_external_body�s


�z(TestMultipart.test_message_external_bodycCs"|�d�}|�t|���d�dS)Nz
msg_37.txtr�)r.r-rrQr\r4r4r5�test_double_boundarys
z"TestMultipart.test_double_boundarycC�4|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.rr Z
_structurer��r1r2r3r�r4r4r5�)test_nested_inner_contains_outer_boundary�

z7TestMultipart.test_nested_inner_contains_outer_boundarycCr�)Nz
msg_39.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
r�r�r4r4r5�test_nested_with_same_boundary"s

z,TestMultipart.test_nested_with_same_boundarycCr6)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\r4r4r5�test_boundary_in_non_multipart3r�z,TestMultipart.test_boundary_in_non_multipartcCsB|j}t�d�}|�|���||��d�|t|���d�dS)Nz�MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="    XXXX"

--    XXXX
Content-Type: text/plain


--    XXXX
Content-Type: text/plain

--    XXXX--
z    XXXXr�)r-r�r�r�r[r}rrQr0r4r4r5� test_boundary_with_leading_spaceBs


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==)rr�r-rQr�r4r4r5�&test_boundary_without_trailing_newlineUsz4TestMultipart.test_boundary_without_trailing_newlinecCs tdd�}|�|jtjj�dS)Nrhri)rr:r�r��compat32r�r4r4r5�test_mimebase_default_policycr�z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|�|jtjj�dS)Nrhrir�)rr�r��defaultr:r�r4r4r5�test_mimebase_custom_policyg�z)TestMultipart.test_mimebase_custom_policyN)r�r�r�rryrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r4r4r4r5rg�s*$
rgc@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.txtr9r�rF)r-r.rBr;rHr0r4r4r5�test_parse_missing_minor_typens

z/TestNonConformant.test_parse_missing_minor_typecCsN|�d�}|�d�}|�t|d��|�t|j�d�|�|jdtj	�dS)N�
msg_15.txtrrirt)
r.rQr��hasattrr-rrirhr�StartBoundaryNotFoundDefect)r1r3�innerr4r4r5�test_same_boundary_inner_outervs

�z0TestNonConformant.test_same_boundary_inner_outercCsX|�d�}|�|��t�|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_25.txtr�rrt)
r.rhrQr�r-rrir�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefectr\r4r4r5�test_multipart_no_boundary��
��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: base64rtr)	�_str_msg�
multipart_msgr�r-rrirhrZ-InvalidMultipartContentTransferEncodingDefectr\r4r4r5�test_multipart_invalid_cte�s
��z,TestNonConformant.test_multipart_invalid_ctecCs(|�|j�d��}|�t|j�d�dS)Nr*r�r�r�r�r-rrir\r4r4r5�test_multipart_no_cte_no_defect�r�z1TestNonConformant.test_multipart_no_cte_no_defectcCs8dD]}|�|j�d�|���}|�t|j�d�qdS)N)r�rVZBINaryz
Content-Transfer-Encoding: {}rr�)r1r�r3r4r4r5�"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>rFr9r:r�zContent-Type: foo

)
r-r�rr;rHrBrr
r�r�)r1r2�neqr3r�r�r4r4r5�test_invalid_content_type�s 
z+TestNonConformant.test_invalid_content_typecCr{)N�
msg_31.txtzm--BOUNDARY
Content-Type: text/plain

message 1

--BOUNDARY
Content-Type: text/plain

message 2

--BOUNDARY--
)r�r.rQr0r4r4r5�test_no_start_boundary��
z(TestNonConformant.test_no_start_boundarycCr{)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�r0r4r4r5�test_no_separating_blank_line�r�z/TestNonConformant.test_no_separating_blank_linecCsX|�d�}|�t|d��|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_41.txtrir�rrt)
r.r�r�r-rrirhrr�r�r\r4r4r5�test_lying_multipart�r�z&TestNonConformant.test_lying_multipartcCsD|�d�}|�d��d�}|�t|j�d�|�|jdtj�dS)Nz
msg_42.txtrtr)r.rQr-rrirhrr�)r1rZbadr4r4r5�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��bodyrtrz Line 1
)r-r�r�r`rQrri�assertDefectsEqualrZ#FirstHeaderLineIsContinuationDefect�linerr4r4r5�&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
)r�r-r`rQr�rirZ MissingHeaderBodySeparatorDefectr\r4r4r5�"test_missing_header_body_separator	s
�z4TestNonConformant.test_missing_header_body_separatorN)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r4r4r4r5r�ls

	
r�c@�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestRFC2047cCsN|j}d}t|�}||gd��t|�}|t|�d�|�|jdd�d�dS)NzVRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=))sRe: N�s
r�ksm�rg�szmac-iceland)s
 baz foo bar Nr�u+Re: räksmörgås baz foo bar räksmörgåsr�r�ziRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?=
 =?mac-iceland?q?=9Arg=8Cs?=)r-rrr�r�r��r1r2r��dhr�r4r4r5�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�r7)s Pirard <pirard@dom.ain>NuAndré Pirard <pirard@dom.ain>�r-rr�rr�r4r4r5�test_whitespace_keeper_unicode-	s�z*TestRFC2047.test_whitespace_keeper_unicodecCs:|j}d}t|�}||gd��tt|��}||d�dS)NzWThe =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?=))sThe N)squick brown foxr7)s jumped over the N)slazy dogr7z,The quick brown fox jumped over the lazy dogr�)r1r2r�r�Zhur4r4r5� test_whitespace_keeper_unicode_26	sz,TestRFC2047.test_whitespace_keeper_unicode_2cC� d}t|�}|�|gd��dS)Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord))sSmN���r7)srgN���r7)ssbordN�rr-�r1r�r�r4r4r5�test_rfc2047_missing_whitespace?	�z+TestRFC2047.test_rfc2047_missing_whitespacecCr�)Nz7Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord))sSm Nr�)s rg Nr�)s sbordNr�r�r4r4r5�test_rfc2047_with_whitespaceF	r�z(TestRFC2047.test_rfc2047_with_whitespacecCs<d}gd�}|D]\}}t||�}|�||dfg�qdS)Nz=?iso-8859-1?B?%s?=))zdm==�v)zdm=r�)Zdmr�)zdmk=�vi)Zdmkr�r7r�)r1r�rS�q�ar�r4r4r5�test_rfc2047_B_bad_paddingM	s�z&TestRFC2047.test_rfc2047_B_bad_paddingcCsd}|�t|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=)sandr�=zzr7�r-r�r1r�r4r4r5�test_rfc2047_Q_invalid_digitsW	s
�z)TestRFC2047.test_rfc2047_Q_invalid_digitscC�d}|�t|�gd��dS)Nz(=?ISO-8859-1?Q?a?=))��(N��ar7��)Nr�r�r4r4r5�test_rfc2047_rfc2047_1]	�
�z"TestRFC2047.test_rfc2047_rfc2047_1cCr�)Nz(=?ISO-8859-1?Q?a?= b))r�r�)s b)Nr�r�r4r4r5�test_rfc2047_rfc2047_2c	r�z"TestRFC2047.test_rfc2047_rfc2047_2cCr�)Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)�r�)sabr7r�r�r�r4r4r5�test_rfc2047_rfc2047_3i	r�z"TestRFC2047.test_rfc2047_rfc2047_3cCr�)Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r�r�r�r4r4r5�test_rfc2047_rfc2047_4o	r�z"TestRFC2047.test_rfc2047_rfc2047_4cCr�)Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r4r4r5�test_rfc2047_rfc2047_5au	r�z#TestRFC2047.test_rfc2047_rfc2047_5acCr�)Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r4r4r5�test_rfc2047_rfc2047_5b{	r�z#TestRFC2047.test_rfc2047_rfc2047_5bcCr�)Nz(=?ISO-8859-1?Q?a_b?=))r�)sa br7r�r�r�r4r4r5�test_rfc2047_rfc2047_6�	r�z"TestRFC2047.test_rfc2047_rfc2047_6cCsPd}|�t|�gd��|�tt|����|���|�ttt|���d�dS)Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))r�r�)s brcr�z(a b))r-rrr�r�r�r�r4r4r5�test_rfc2047_rfc2047_7�	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-rrr�r��
splitlinesr�r�r4r4r5�test_multiline_header�	s
����z!TestRFC2047.test_multiline_headerN)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r4r4r4r5r�	s"		
	r�c@r�)"�TestMIMEMessagecCs<tddd��}|��|_Wd�dS1swYdS)N�
msg_11.txtrMr�)r%r�Z_textr'r4r4r5r�	s"�zTestMIMEMessage.setUpcCs|�ttd�dS)Nza plain string)r�r`rrr4r4r5�test_type_error�	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||��d�|��}|�|t�|t|�d�|d}|�||�||d|�dS)Nz
A sub-messager�r,rtr�subject)	r-rrrBrQrh�listrr:)r1r2r�r�r�r0rwr4r4r5�test_valid_argument�	sz#TestMIMEMessage.test_valid_argumentcCs:t�}d|d<t�}d|d<t|�}|�tj|j|�dS)N�	subpart 1r�z	subpart 2)rrr�r�MultipartConversionErrorra)r1r�rMr�r4r4r5�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.
)rrJrrr
r�r-r�)r1r�r�r�r�r4r4r5�
test_generate�	s

zTestMIMEMessage.test_generatecCst|j}|�d�}||��d�|��}|�|t�|t|�d�|d}|�|t�||dd�||��d�dS)Nr�r,rtrr�r�r�)r-r.rBrQrhr�rr)r1r2r3r0Zsubmsgr4r4r5�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.txtrr�rr9a�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

rtzmessage/delivery-statusr�zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnsz
reporting-mtar�r*Znsd�actionZfailedzoriginal-recipient)rJr*)zjangel1@cougar.noc.ucla.edur*rJzfinal-recipientr,�
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r-r.rBr�r[rrQrhrrCr�r�)r1r2r3rwZdsn1Zdsn2r0r�r4r4r5�test_dsn�	sD




�
�zTestMIMEMessage.test_dsnc	Cs�|j}tddd��}|��}Wd�n1swYt�}d|d<d|d<d|d	<d
|_d|_td�}td
�}|jdddd�|�|�|�|�t	�}t
|�}|�|�||��|�dS)N�
msg_21.txtrMr�r|r�r}r�r�r��MIME messagezEnd of MIME message
rXrZr>r_r|rj)
r�r%r�rr�r�rrrarr
r�r�)	r1r2r�r�r3r�rMr�r�r4r4r5�
test_epilogue
s&
�


zTestMIMEMessage.test_epiloguecCsv|j}t�}d|d<d|d<d|d<d|_d|_td	�}td
�}|jddd
d�|�|�|�|�||��d�dS)Nr|r�r}r�r�r�rr*rXrZr>r_r|rjadFrom: 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�rrrar�)r1r2r3r�rMr4r4r5�test_no_nl_preamble'
s

z#TestMIMEMessage.test_no_nl_preamblecC��|j}tddd��
}t�|�}Wd�n1swY|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nr0rMr�rr,rtr9�r-r%r��message_from_filerQ�get_default_typerB�r1r2r�r3Z
container1Z
container2Zcontainer1aZcontainer2ar4r4r5�test_default_typeJ
� �



z!TestMIMEMessage.test_default_typecCr)Nr4rMr�rr,rtr9rr
r4r4r5�.test_default_type_with_explicit_container_type[
r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)NZdigestr|r*�
message 1
�
message 2
r,ra�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--
r:r8aBContent-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�rrrarBr	r�)r1r2r�ruZ	subpart1aZ	subpart2aZsubpart1Zsubpart2r4r4r5�test_default_type_non_parsedl
s0


z,TestMIMEMessage.test_default_type_non_parsedcCsZ|j}td�}td�}t||fd�}|t|���d�||�d�|�||�d�|�dS)Nr*)Z	_subpartsr�rrt)r-rrrrQ)r1r2Ztext1Ztext2r3r4r4r5�$test_mime_attachments_in_constructor�
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|�|���dSrZ)rr�r[r\r4r4r5�"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\r4r4r5�test_multipart_default_policy�
sz-TestMIMEMessage.test_multipart_default_policycCs^ttjjd�}d|d<|�t��}d|d<Wd�n1swY|�t|j�d�dS)Nr�rr�rz.There may be at most 1 To headers in a message)	rr�r�r�r�r%r-r�Z	exception)r1r3�cmr4r4r5�test_multipart_custom_policy�
s
��z,TestMIMEMessage.test_multipart_custom_policyN)r�r�r�rr�r�r�r�r�rrrrr
rrrrrr4r4r4r5r��	s"9#J	r�c@seZdZdd�Zdd�ZdS)�TestNonMultipartcCstdd�}|�|���dS)Nr�rF)rrZr[r\r4r4r5�"test_nonmultipart_is_not_multipart�
s
z3TestNonMultipart.test_nonmultipart_is_not_multipartcCs.t�}d|d<tdd�}|�tj|j|�dS)Nr�r�r�rF)rrr�rr�ra)r1r3r�r4r4r5�test_attach_raises_exception�
s
z-TestNonMultipart.test_attach_raises_exceptionN)r�r�r�rrr4r4r4r5r�
src@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)cCsFt|dd��}|��}Wd�n1swYt�|�}||fS�NrMr��r%r�r�r��r1rr�rSr3r4r4r5r.�
s

�
zTestIdempotent._msgobjFcCs8|j}t�}t|dd�}|j||d�|||���dS)Nrr�r�)r�rr
r�r�)r1r3r�r�r2r�r�r4r4r5�_idempotent�
s
zTestIdempotent._idempotentcCs�|j}|�d�\}}||��d�||��d�||��d�||��dd�||�d�d�||jd�||jd�|�	||�dS)	Nrr9r�rFrt)r;rGr;rG)
r-r.rBr;rHr�rCr�r�r�r1r2r3r�r4r4r5�test_parse_text_message�
sz&TestIdempotent.test_parse_text_messagecCsP|j}|�d�\}}||��d�||��d�||�d�d�|�||�dS)Nr�r9r;)r-r.rBr�rCrr r4r4r5�test_parse_untyped_messagesz)TestIdempotent.test_parse_untyped_messagecC�|�d�\}}|�||�dS)Nri�r.r�r1r3r�r4r4r5�test_simple_multipart	�z$TestIdempotent.test_simple_multipartcCr#)N�
msg_02.txtr$r%r4r4r5�test_MIME_digest
r'zTestIdempotent.test_MIME_digestcCr#)Nz
msg_27.txtr$r%r4r4r5�test_long_headerr'zTestIdempotent.test_long_headercCr#)Nr4r$r%r4r4r5�"test_MIME_digest_with_part_headersr'z1TestIdempotent.test_MIME_digest_with_part_headerscCr#)N�
msg_06.txtr$r%r4r4r5�test_mixed_with_imager'z$TestIdempotent.test_mixed_with_imagecCr#)Nrr$r%r4r4r5�test_multipart_reportr'z$TestIdempotent.test_multipart_reportcCr#)Nr�r$r%r4r4r5r!r'zTestIdempotent.test_dsncCr#)Nrr$r%r4r4r5�test_preamble_epilogue%r'z%TestIdempotent.test_preamble_epiloguecCr#)Nz
msg_23.txtr$r%r4r4r5�test_multipart_one_part)r'z&TestIdempotent.test_multipart_one_partcCr#)Nz
msg_24.txtr$r%r4r4r5�test_multipart_no_parts-r'z&TestIdempotent.test_multipart_no_partscCr#)Nr�r$r%r4r4r5r�1r'z%TestIdempotent.test_no_start_boundarycCr#)N�
msg_32.txtr$r%r4r4r5�test_rfc2231_charset5r'z#TestIdempotent.test_rfc2231_charsetcCr#)Nz
msg_33.txtr$r%r4r4r5�test_more_rfc2231_parameters9r'z+TestIdempotent.test_more_rfc2231_parameterscCr#)Nz
msg_34.txtr$r%r4r4r5�%test_text_plain_in_a_multipart_digest=r'z4TestIdempotent.test_text_plain_in_a_multipart_digestcCr#)Nzmsg_12a.txtr$r%r4r4r5�test_nested_multipart_mixedsAr'z+TestIdempotent.test_nested_multipart_mixedscCr#)Nr�r$r%r4r4r5�%test_message_external_body_idempotentEr'z4TestIdempotent.test_message_external_body_idempotentcCs"|�d�\}}|j||dd�dS)N�
msg_43.txtTr�r$r%r4r4r5�test_message_delivery_statusIsz+TestIdempotent.test_message_delivery_statuscCr#�N�
msg_45.txtr$r%r4r4r5�test_message_signed_idempotentMr'z-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)Nrrrrr�rz$This is a MIME-encapsulated message.r�rr9zYadda yadda yaddartr�r,)r-r.rBr�r�r�r�rrQrhrr�)r1r2r3r��paramsZpkZpvr�rMZmsg3r0Zmsg4r4r4r5�test_content_typeQs4



z TestIdempotent.test_content_typecCs�|j}|�d�\}}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�|�|��t�||��|j	�dS)Nr,r,rtrr9)
r-r.rBrQrhr�rrr�r�)r1r2r3r�r0r�r4r4r5�test_parserpszTestIdempotent.test_parserN�F)r�r�r�r�r.rr!r"r&r)r*r+r-r.rr/r0r1r�r3r4r5r6r7r9r<r>r?r4r4r4r5r�
s4
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)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=dwS)x�TestMiscellaneouscCsntddd��}|��}Wd�n1swYt�|�}t�}t|dd�}|�|�|�||���dS�NrrMr�rr��	r%r�r�r�rr
r�r-r��r1r�r�r3r�r�r4r4r5�test_message_from_string�s
�

z*TestMiscellaneous.test_message_from_stringcCsztddd��-}|��}|�d�t�|�}t�}t|dd�}|�|�|�||�	��Wd�dS1s6wYdSrB)
r%r��seekr�rrr
r�r-r�rDr4r4r5�test_message_from_file�s


"�z(TestMiscellaneous.test_message_from_filecCs�tddd��}|��}Wd�n1swYGdd�dt�}t�||�}|�||�tddd��}|��}Wd�n1sCwYt�||�}|��D]}|�||�qRdS)NrrMr�c@�eZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN�r�r�r�r4r4r4r5�	MyMessage��rJr()r%r�rr�r�rh�walk)r1r�r�rJr3rwr4r4r5�#test_message_from_string_with_class�s
�
��z5TestMiscellaneous.test_message_from_string_with_classcCs�Gdd�dt�}tddd��}t�||�}Wd�n1swY|�||�tddd��}t�||�}Wd�n1sAwY|��D]}|�||�qJdS)Nc@rH)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageNrIr4r4r4r5rJ�rKrJrrMr�r()rr%r�rrhrL)r1rJr�r3rwr4r4r5�!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���dSrZ)�super�__init__r��	__class__r4r5rP�rXz\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)r�r�r�rP�
__classcell__r4r4rQr5rJ�srJzSubject: test

test)rr�rh)r1rJr3r4r4r5�.test_custom_message_does_not_require_arguments�sz@TestMiscellaneous.test_custom_message_does_not_require_argumentscCs"td�}|�t|j�gd��dS)Nr�)rr;rr�
feedparserr�r�r rZmessage_from_binary_filer�rr�r�r�r!r")�
__import__r-�sorted�__all__)r1�moduler4r4r5�test__all__�szTestMiscellaneous.test__all__cCs:t��}|�t�t�|��dd�t�|�dd��dS)N�)ror-r"�	parsedate�
formatdate�gmtime�r1rvr4r4r5�test_formatdate�s�z!TestMiscellaneous.test_formatdatecCs>t��}|�t�tj|dd��dd�t�|�dd��dS)NT�rpr[)ror-r"r\r]rpr_r4r4r5�test_formatdate_localtime�s
�z+TestMiscellaneous.test_formatdate_localtimec	CsVt��}|�tj|dd�t�dt�|���|�tj|ddd�t�dt�|���dS)NFraz%a, %d %b %Y %H:%M:%S -0000T)rpZusegmtz%a, %d %b %Y %H:%M:%S GMT)ror-r"r]rsr^r_r4r4r5�test_formatdate_usegmt�s��z(TestMiscellaneous.test_formatdate_usegmtc	Cs�gd�}|D](}|j|d��|�t�|��|�t�|��Wd�n1s)wYq|�t�d��|�t�d��dS)N)	r*r+�0zA Complete Waste of Timez Wed, 3 Apr 2002 12.34.56.78+0800z17 June , 2022zFriday, -Nov-82 16:14:55 ESTzFriday, Nov--82 16:14:55 ESTzFriday, 19-Nov- 16:14:55 EST)�dtstr)rrfr"r\�parsedate_tz)r1Z
invalid_datesrer4r4r5�/test_parsedate_returns_None_for_invalid_strings�s��zATestMiscellaneous.test_parsedate_returns_None_for_invalid_stringscC�:|�t�d�d�|�t�d�d�|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26 +0800�
��r�r���:�rrtrk�pzWed,3 Apr 2002 14:58:26 +0800zWed 3 Apr 2002 14:58:26 +0800�r-r"rfrr4r4r5�test_parsedate_compact�s���z(TestMiscellaneous.test_parsedate_compactcCs*|j}|t�d�d�|t�d�d�dS)N�5 Feb 2003 13:47:26 -0800�
��r���
�/rmrrtrk透��zFebruary 5, 2003 13:47:26 -0800ro�r1r2r4r4r5�test_parsedate_no_dayofweek�
�
�z-TestMiscellaneous.test_parsedate_no_dayofweekcC�|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26+0800rirorr4r4r5�.test_parsedate_no_space_before_positive_offset��z@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCr{)NzWed, 3 Apr 2002 14:58:26-0800)
rjr�r�rkrlrmrrtrkrwrorr4r4r5�.test_parsedate_no_space_before_negative_offsets�z@TestMiscellaneous.test_parsedate_no_space_before_negative_offsetcC�*|j}|t�d�d�|t�d�d�dS)Nz5 Feb 2003 13.47.26 -0800rrz5 Feb 2003 13.47 -0800)
rsr�rtrurvrrrtrkrwrorxr4r4r5�%test_parsedate_accepts_time_with_dotsrzz7TestMiscellaneous.test_parsedate_accepts_time_with_dotscCr{)NzFriday, 19-Nov-82 16:14:55 EST)
i����rk�7rrtrki����rorr4r4r5�test_parsedate_rfc_850r}z(TestMiscellaneous.test_parsedate_rfc_850cCr{)NzWed, 3 Apr 2002 14:58 +0800�
rjr�r�rkrlrrrtrkrnrorr4r4r5�test_parsedate_no_secondsr}z+TestMiscellaneous.test_parsedate_no_secondscC�(|�t�d�d�|�t�d�d�dS)NzWed, 3 Apr 2002 14.58.26 +0800rizWed, 3 Apr 2002 14.58 +0800r�rorr4r4r5�!test_parsedate_dot_time_delimiter���z3TestMiscellaneous.test_parsedate_dot_time_delimitercCs�|j}t�d�}tt�|��}|t�|�dd�|dd��|tt�d|��d�t�d�}tt�|dd���}|t�|�dd�|dd��|tt�d|dd���d�dS)Nrqr[z%Yrs�	)	r-r"r\�intro�mktimerprsrf)r1r2Ztimetuprr4r4r5�+test_parsedate_acceptable_to_time_functions%s
 
 "z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCr�)N)
�rtrtrrrrkrkrkrr)
r�rtrtrrrrkrkrki�i.���)r-r"Z	mktime_tzrr4r4r5�test_mktime_tz0r�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 -0800z25 Feb 2003 13:47:26 -0800z25 Feb 71 13:47:26 -0800z25 Feb 1971 13:47:26 -0800Nrorr4r4r5�test_parsedate_y2k6s��z$TestMiscellaneous.test_parsedate_y2kcCs.|�t�d�d�|�t�t�d��d�dS)Nz<>r�r*�r-r"�	parseaddr�
formataddrrr4r4r5�test_parseaddr_emptyCsz&TestMiscellaneous.test_parseaddr_emptycCrh)Nza@b@cr�za@b.c@cza@172.17.0.1@c�r-r"r�rr4r4r5�test_parseaddr_multiple_domainsGs���z1TestMiscellaneous.test_parseaddr_multiple_domainscCr{)N)zA Silly Person�person@dom.ainzA Silly Person <person@dom.ain>�r-r"r�rr4r4r5�test_noquote_dumpU��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-r"r�r��r1r�rr4r4r5�test_escape_dumpZ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�r4r4r5�test_escape_backslashese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>r7r�)r1r��addr�utf8_base64Z
latin1_quoprir4r4r5�test_quotes_unicode_namesms�z+TestMiscellaneous.test_quotes_unicode_namescsld}d}d}d�G�fdd�d�}|�}d�|f}|�t�||f|�|�|�t�||ftd��|�dS)	Nr�r�r�ZFOOBARcseZdZ�fdd�ZdS)zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockcs�SrZr4)r1�string�r#r4r5�
header_encode~szYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)r�r�r�r�r4r�r4r5�CharsetMock}sr�z%s <%s>rM)r-r"r�r	)r1r�r�r�r�ZmockZ
mock_expectedr4r�r5�$test_accepts_any_charset_like_objectws�z6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|�ttj||f|�dS)Nr�r�)�objectr��AttributeErrorr"r�)r1r�r�Zbad_charsetr4r4r5�-test_invalid_charset_like_object_raises_error�s�z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|�ttjd|f�|�ttjd|f�dS)Nupersön@dom.in�Name)r��UnicodeErrorr"r��r1r�r4r4r5�!test_unicode_address_raises_error�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�)r1rl�yr�rr4r4r5�test_name_with_dot�sz$TestMiscellaneous.test_name_with_dotcCs:|j}|t�d�d�|t�d�d�|t�d�d�dS)N�""example" example"@example.com)r*r��!"\"example\" example"@example.com)r*r��#"\\"example\\" example"@example.com)r*r�r�rxr4r4r5�2test_parseaddr_preserves_quoted_pairs_in_addresses�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.comr�)r*�merwok  wok@xample.comr�z merwok  wok  @xample.com)r*�merwok"wok"  wok@xample.comr�)r*zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.comr�rr4r4r5�-test_parseaddr_preserves_spaces_in_local_part�s�����z?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_partcCs0d}d}|�t�|�|�|�t�|�|�dS)N)z#'foo@example.com' (foo@example.com)�foo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>r�)r1r�Zaddrstrr4r4r5�6test_formataddr_does_not_quote_parens_in_quoted_string�szHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_stringcCsd}|�t�|�d�dS)NzFoo
	Bar <foo@example.com>)zFoo Barr�r�)r1rlr4r4r5�test_multiline_from_comment�sz-TestMiscellaneous.test_multiline_from_commentcCr{)N)zA Silly; Personr�z""A Silly; Person" <person@dom.ain>r�rr4r4r5�test_quote_dump�r�z!TestMiscellaneous.test_quote_dumpcCs�|j}|j}t�}t�}||d�||d�||d�|d|�|d|�|d|�||d�||d�||d�|d|�|d|�|d|�|||�|||�dS)NrG�US-ASCIIzUs-AsCiIZusasciiZUSASCIIZUsAsCiI)r-ZassertNotEqualr	)r1r2�neZcset1Zcset2r4r4r5�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 Personr|)z
Bud Personr}�r-r"�getaddressesrxr4r4r5�test_getaddresses�s���z#TestMiscellaneous.test_getaddressescCs|�t�gd��gd��dS)zGH-106669 regression test.)z"Bud, Person" <bperson@dom.ain>r�z#"Mariusz Felisiak" <to@example.com>))zBud, Personr}r�)zMariusz Felisiak�to@example.comNr�rr4r4r5�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]S\}}|�|�d|�d�}|j|d��7|�t�|g�|g�|�tj|gdd�|�|�t�|g�|�|�tj|gdd�d|f�Wd�n1s�wYqz|�d|�d�}|�t�|g�d|fd|fg�|�tj|gdd�d|fd|fg�|�t�|g�|�|�tj|gdd�d|f�d}d}|�t�|g�|g�|�tj|gdd�|g�|�t�|g�|�|�tj|gdd�d|f�d}d}|�t�|g�|g�|�tj|gdd�|g�|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�|g�|�tj|gdd�gd��|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�ddg�|�tj|gdd�ddg�|�t�|g�|�|�tj|gdd�d|f�|�tjjd �dS)!z>Test for parsing errors from CVE-2023-27043 and CVE-2019-16056�alice@example.org�bob@example.comr��(�<�>�)r*�[z[<z>]�]�@r��:�.�")�addressF��strictNz,<z,"Alice, alice@example.org" <bob@example.com>)zAlice, alice@example.orgr�zalice@example.org (Alice))�Alicer�zalice@example.org )Alice())r*r�r�)r*r��<"Jane Doe" <jane@example.net>, "John Doe" <john@example.net>)zJane Doezjane@example.net)zJohn Doezjohn@example.netT)rr-r"r�r�r�Zsupports_strict_parsing)r1ZaliceZbob�emptyZinvalid_separatorZexpected_non_strictr�Zexpected_strictr4r4r5�test_parsing_errors
s��
������
�������������z%TestMiscellaneous.test_parsing_errorscCsdgdgfdgdgfddgddgfdgdgfd	gdgfd
ggd�fdgd
gfdgdgfdgdgfdgddgff
D].\}}|j|d��|�t�|�|�|�tj|dd�|�Wd�n1sawYq8dg}|�t�|�dg�|�tj|dd�gd��dS)Nu&"Sürname, Firstname" <to@example.com>)uSürname, Firstnamer�zfoo: ;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.netr�)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)�	addressesFr�z	[]*-- =~$)r�r�)r*z*--)rr-r"r�)r1r�r�r4r4r5�test_getaddresses_nastyZ
s^�����������������z)TestMiscellaneous.test_getaddresses_nastycCs(|j}t�dg�}||ddd�dS)z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>rrt�foo@bar.comNr�)r1r2�addrsr4r4r5�"test_getaddresses_embedded_comment�
sz4TestMiscellaneous.test_getaddresses_embedded_commentcCs(t�td�g�}|�|ddd�dS)z%Test the handling of a Header object.zAl Person <aperson@dom.ain>rrtr|N)r"r�r
r-)r1r�r4r4r5�test_getaddresses_header_obj�
sz.TestMiscellaneous.test_getaddresses_header_objcs�Gdd�dt���fdd�td�D�}t�|��Wd�n1s#wYtdd�|D�g�}|�tt|��t|��dS)Nc@�eZdZdd�ZdS)zBTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadcSsNg|_|jj}tj}tj}|�d}|�|kr%||dd��|�|ksdSdS)Ng@�testdomain-string��domain)�msgidsr�r"�
make_msgidro�	monotonic)r1r�r�ZclockZtfinr4r4r5�run�
s

�zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)r�r�r�r�r4r4r4r5�MsgidsThread�
sr�csg|]}���qSr4r4r��r�r4r5rp�
�z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>rtcSsg|]}|j�qSr4)r�)rnrr4r4r5rp�
r�)rr�r#Z
start_threads�sumr-rr)r1ZthreadsZall_idsr4r�r5�test_make_msgid_collisions�
s�z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||��d�dS)Nrrzfoo\wacky"namer)r-rrrlr0r4r4r5�test_utils_quote_unquote�
s�z*TestMiscellaneous.test_utils_quote_unquotecCstd�}|�|��d�dS)Nz
not a charsetrN�r	r-�get_body_encoding�r1r;r4r4r5�)test_get_body_encoding_with_bogus_charset�
sz;TestMiscellaneous.test_get_body_encoding_with_bogus_charsetcCs|j}t�}d|d<||dd�|��}|t|�d�||dd�t|d�}||��d�|jd|d	�||��d
�||jdd�d�||d
d�t�}d|d<|��}|t|�d�||dd�t|d�}||��tj	�|jd|d	�||��d�||d
d�dS)Nztext/plain; charset=UTF-8r>r:rtrrMrNr�r"�aGVsbG8gd29ybGQ=
TrOr<ztext/plain; charset="US-ASCII"rGr�r�)
r-rrfrr	r�rJrQrrK)r1r2r3rgr;r4r4r5�-test_get_body_encoding_with_uppercase_charset�
s.z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs(td�}td�}|�|��|���dS)NrGr�r�)r1ZlcZucr4r4r5�test_charsets_case_insensitive�
sz0TestMiscellaneous.test_charsets_case_insensitivecCr�)Nr8aBmultipart/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
r�r�r4r4r5�1test_partial_falls_inside_message_delivery_status�
r�zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs"|�tjjdd�dd�d�dS)Nr�r�i��z@testdomain-string>�r-r�r"r�rr4r4r5�test_make_msgid_domain�
s�z(TestMiscellaneous.test_make_msgid_domaincCs$|�tjjddd�dd�d�dS)Nz
test-idstringr�)Zidstringr�i���z!.test-idstring@testdomain-string>r�rr4r4r5�test_make_msgid_idstring�
s���z*TestMiscellaneous.test_make_msgid_idstringcCsVtd��}d|_}|�tj���d|d��Wd�dS1s$wYdS)Nzsocket.getfqdnzpythontest.example.comr�r�)rZreturn_valuer�r�r"r��endswith)r1Zmock_getfqdnr�r4r4r5�test_make_msgid_default_domains



��"�z0TestMiscellaneous.test_make_msgid_default_domaincCs|tdddd��}|��}Wd�n1swY|�dd�}t�|�}t�}tj�|�}|�|�|�	|�
�|�dS)N�
msg_26.txtrMr)�r��newliner�)r%r�r�r�r�rr�r
r�r-r��r1�fZmsgtxtZ	msgtxt_nlr3r�r�r4r4r5�test_Generator_linend
s
�

z'TestMiscellaneous.test_Generator_linendcCs�tdddd��}|��}Wd�n1swY|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
��d�|�dS)Nr�rMr)r�r�r�r�)r%r�r�r�r�rr�rr�r-r�rPrr4r4r5�test_BytesGenerator_linends
�
z,TestMiscellaneous.test_BytesGenerator_linendcCs�tdd��}|��}Wd�n1swY|�dd�}|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
�|�dS)	Nr�r�swith attachmentsfo��
r�r�r�)r%r�r�r�r�rr�rr�r-r�rr4r4r5�)test_BytesGenerator_linend_with_non_ascii s
�
z;TestMiscellaneous.test_BytesGenerator_linend_with_non_asciic	CsDtdd��}|��}Wd�n1swYtdd��}|��}Wd�n1s-wYtdft|fft|fftt�fftdftdfg}|D]S\}}|j	|j
dd��||�}|�|jt
jj�Wd�n1spwY|j	|j
dd��||d	t
jji�}|�|jt
jj�Wd�n1s�wYqLdS)
Nr$r�r�)r*)rhrir�)�clsr�r�r�)r%r�rrrrrrrrr�r:r�r�r�r�)r1r�Z	audiodatar�Zclassesr�constructorr�r4r4r5�!test_mime_classes_policy_argument,s0
�
�
�����z3TestMiscellaneous.test_mime_classes_policy_argumentcCs8|�tt�d��gd��|�tt�d��ddg�dS)Nza\\b\"c\\"d)�rr�)r��\\)r�r)rtz\")r[�c)�r)r�r�)r��dza\r
)rt�\)r-r�r"Z_iter_escaped_charsrr4r4r5�test_iter_escaped_charsAs�	�z)TestMiscellaneous.test_iter_escaped_charscs|�fdd�}|dd�|dd�|dd�|d	d
�|dd�|d
d�|dd�|dd�dD]}��t�|�|�q0dS)Ncs��t�|�|�dSrZ�r-r"Z_strip_quoted_realnames)r�r�rr4r5�checkOr+z<TestMiscellaneous.test_strip_quoted_realnames.<locals>.checkr�z( <jane@example.net>,  <john@example.net>z""Jane \"Doe\"." <jane@example.net>z <jane@example.net>zbefore"name"afterZbeforeafterzbefore"name"Zbeforezb"name"rz"name"afterZafterz"name"ar�z"name"r*)z8Jane Doe <jane@example.net>, John Doe <john@example.net>zlone " quoter)r1rr�r4rr5�test_strip_quoted_realnamesNs ��





�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�r"Z_check_parenthesisrZr�r4r4r5�test_check_parenthesisgsz(TestMiscellaneous.test_check_parenthesisN)>r�r�r�rErGrMrNrTrZr`rbrcrgrpryr|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�rrrr	rrrr4r4r4r5rA�sx




			X,*
rAc@r!)�
TestIteratorscCs�|j}|j}|�d�}t�|�}t|�}|t|�d�|t�|�|�	��|�d�}t�|�}t|�}|t|�d�t
ddd��}|t�|�|���Wd�dS1sVwYdS)Nrr[r(�+z
msg_19.txtrMr�)r-r�r.r Zbody_line_iteratorr�r�EMPTYSTRINGr�rQr%r�)r1r2r�r3�itr�r�r4r4r5�test_body_line_iteratorts



"�z%TestIterators.test_body_line_iteratorcCsb|j}|�d�}t�|d�}g}d}|D]
}|d7}|�|���q||d�|t�|�d�dS)Nrir�rrtr�z`a simple kind of mirror
to reflect upon our own
a simple kind of mirror
to reflect upon our own
�r-r.r Ztyped_subpart_iteratorr�rQrr��r1r2r3rr�Zsubpartsrwr4r4r5�test_typed_subpart_iterator�s

z)TestIterators.test_typed_subpart_iteratorcCsd|j}|�d�}t�|dd�}g}d}|D]
}|d7}|�|���q||d�|t�|�d�dS)Nr�r�rFrrtz%
Hi,

Do you like this message?

-Me
rrr4r4r5�(test_typed_subpart_iterator_default_type�s

z6TestIterators.test_typed_subpart_iterator_default_typecCs�gd�}ddlm}m}|�}g}d}|D]'\}}|�|�||7}d}	t|j|�D]}
|�|
�|	d7}	q*|�||	�q|�t|�|�|�d�	dd�|D��d�	|��dS)	z�FeedParser BufferedSubFile.push() assumed it received complete
           line endings.  A CR ending one push() followed by a LF starting
           the next push() added an empty line.
        ))za
 
r�)rr)zc
rt)r*r)zd
rt)ze
r)z
frt)r�rtr��BufferedSubFile�NeedMoreDatartr*cS�g|]\}}|�qSr4r4)rn�il�nr4r4r5rp�rqz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
�email.feedparserrr �push�iter�readliner�r-rr�)r1Zimtrr �bsfZom�ntr"r#Zn1Zolr4r4r5�test_pushCR_LF�s



&zTestIterators.test_pushCR_LFcs�ddlm}m}d}d}d�d��fdd�t|�D��d	}|�d
�}|�}g}tdt|�|�D]}	||	|	|�}
|�|
�|�t	|j
|��q0|�||�dS)Nrri'rtzabcd 	
r*c3s�|]}t��VqdSrZrr���charsr4r5r��r�z1TestIterators.test_push_random.<locals>.<genexpr>r)T)r$rr r�r�r�rr%�extendr&r'r-)r1rr r#Z	chunksizer��targetr(r�r��chunkr4r+r5�test_push_random�s 

zTestIterators.test_push_randomN)r�r�r�rrrr*r0r4r4r4r5rssrc@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs"t�}|D]}|�|�q|��SrZ)r'�feed�close)r1�chunksrUr/r4r4r5�parse�szTestFeedParsers.parsecCs.|�d�}|�|dd�|�|dd�dS)NzFirst: val
: bad
Second: valrW�valrY)r6r-r\r4r4r5�test_empty_header_name_handled�s
z.TestFeedParsers.test_empty_header_name_handledcCs�|�dg�}|�|��gd��|�dg�}|�|��gd��|�ddg�}|�|��ddg�|�dd	g�}|�|��dd
g�|�ddg�}|�|��dd
g�|�dg�}|�|��d
g�|�gd��}|�|��ddg�dS)Nz
a:
b:
c:
d:
)r�rrrza:
b:
c:
d:za:
b�c:
r�Zbc�a:
zb:
rz
b:
ua:…b:
c:
)r�u	…b:
c:)r:ub:…r9�r�r*)ru…c:)r6r-r`r�r�r4r4r5�
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

rl)r�rza:b

�…r:zb: r;r)r6r-r�rQ)r1�Mr�r�r4r4r5�test_long_lines�s$zTestFeedParsers.test_long_linesN)r�r�r�r6r8r<r?r4r4r4r5r2�s
r2c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdZ
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�TestParserscCs�|j}tddd��}t��|�}Wd�n1swY||dd�||dd�||��d�|�|���|�|��t	�dS)	Nr(rMr�r��ppp-request@zzz.orgr��ppp@zzz.orgr_)
r-r%rr6rBrZr[rhrQr��r1r2r�r3r4r4r5�test_header_parsers�zTestParsers.test_header_parsercCs�|j}tdd��}tj���|�}Wd�n1swY||dd�||dd�||��d�|�|���|�	|�
�t�|�	|j
dd	�t�dS)
Nr(r�r�rAr�rBr_TrO)
r-r%r�r�r�r6rBrZr[rhrQr�r�rCr4r4r5�test_bytes_header_parsers�z$TestParsers.test_bytes_header_parsercCsLtdd��}tj���|�|�|j�Wd�dS1swYdS)Nr(r�)r%r�r��BytesParserr6rZ�closedr'r4r4r5�%test_bytes_parser_does_not_close_file#s"�z1TestParsers.test_bytes_parser_does_not_close_filecCsbtdd��"}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�dS1s*wYdS)Nr�r�r�)r%r�r�rFr�rr�r�r�r6rZrG)r1r�ZbytesParserr4r4r5�2test_bytes_parser_on_exception_does_not_close_file(s
�"�z>TestParsers.test_bytes_parser_on_exception_does_not_close_filecCsNtddd��}tj���|�|�|j�Wd�dS1s wYdS)Nr(rMr�)r%r�r�rr6rZrGr'r4r4r5�test_parser_does_not_close_file0s"�z+TestParsers.test_parser_does_not_close_filecCsdtddd��"}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�dS1s+wYdS)Nr�rMr�r�)r%r�r�rr�rr�r�r�r6rZrG)r1r�r�r4r4r5�,test_parser_on_exception_does_not_close_file5s
�"�z8TestParsers.test_parser_on_exception_does_not_close_filecC�>|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�rQr0r4r4r5�test_whitespace_continuation<�


z(TestParsers.test_whitespace_continuationcCrL)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�rMrrNrOrPr0r4r4r5�(test_whitespace_continuation_last_headerNrRz4TestParsers.test_whitespace_continuation_last_headercCs�|j}tdddd��}t��|�}Wd�n1swY|t|���d�|�d�}||��d�||��d�|�d	�}||��d
�dS)Nr�rMr)r�r�rr9z!Simple email with attachment.

rtzapplication/riscos)r-r%rr6rrQrB)r1r2r�r3�part1�part2r4r4r5�test_crlf_separation`s�

z TestParsers.test_crlf_separationcCsptdddd��}|��}Wd�n1swYt�|�}t�}t|�}|j|dd�|�|��|�dS)Nr�rMr)r�r�r�rCrDr4r4r5�test_crlf_flattenks
�
zTestParsers.test_crlf_flattenNc	Cs>|j}|j}tddd��
}t�|�}Wd�n1swY||��d�|t|���d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d	�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d
�dS)Nr4rMr�rtr�rr,r9rr)	r-r�r%r�rr[rrQrB)	r1r2r�r�r3rTZpart1arUZpart2ar4r4r5�-test_multipart_digest_with_extra_mime_headersws.�



z9TestParsers.test_multipart_digest_with_extra_mime_headerscCs,gd�}t�t�|��}|�|dd�dS)N)z$From: Andrew Person <aperson@dom.ainz
Subject: Testz%Date: Tue, 20 Aug 2002 16:43:45 +1000�datezTue, 20 Aug 2002 16:43:45 +1000)r�r�r�r�r-)r1r�r3r4r4r5�test_three_lines�szTestParsers.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)r1r2Zvalue1Zvalue2r�r3r4r4r5�3test_strip_line_feed_and_carriage_return_in_headers�s�
z?TestParsers.test_strip_line_feed_and_carriage_return_in_headerscCsP|j}d}t�|�}|t|�d�|tdd�|D��gd��||��d�dS)Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyr�cs��|]}|VqdSrZr4)rnZfieldr4r4r5r����z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>)z!"#QUX;~z>Fromr�r�)r-r�r�rrWrQrr4r4r5�test_rfc2822_header_syntax�s
z&TestParsers.test_rfc2822_header_syntaxcCs*|j}d}t�|�}|t|���d�dS)Nz<>From foo@example.com 11:25:53
From: bar
!"#QUX;~: zoo

bodyr)r-r�r�rr`rr4r4r5�(test_rfc2822_space_not_allowed_in_header�s
z4TestParsers.test_rfc2822_space_not_allowed_in_headercCsD|j}d}t�|�}|��}|��||gd��||��d�dS)Nz7A: first header
B: second header
CC: third header

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

--BOUNDARY
Content-Type: text/plain

body ending with CRLF newline

--BOUNDARY--
rr�)r�r�r�rQr��r1r�r3r4r4r5�test_CRLFLF_at_end_of_part�s�

z&TestParsers.test_CRLFLF_at_end_of_part)r�r�r�rDrErHrIrJrKrQrSrVrWrrXrZr\r_r`rdrfr4r4r4r5r@
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)NrMrV�pöstal�r;r�Zbodyline�pöstal
TrO��bodytest_msgr�r�r�r�r-rQrer4r4r5�test_known_8bit_CTE����
�z)Test8BitBytesHandling.test_known_8bit_CTEcC�P|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
NZnotavalidcharsetrVrhrirMup��stal
TrOrjrkrer4r4r5�test_unknown_8bit_CTE�rnz+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)	NrMr=�p=C3=B6stálriu
p=C3=B6stál
TrO�	pöstál
rkrer4r4r5�test_8bit_in_quopri_body�s
��
�z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCro)
Nr�r=rqrirMup=C3=B6st��l
TrOrrrkrer4r4r5�.test_invalid_8bit_in_non_8bit_cte_uses_replaces��
�zDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replacecCsT|jjdddd��d�}t�|�}|�|jdd�d�d��|�|jdt	j
�dS)	NrMrNu
cMO2c3RhbAá=riTrOrhr)rlr�r�r�r�r-rQrhrirrjrer4r4r5�test_8bit_in_base64_bodys��
��z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd��d�}t�|�}|�|jdd�d�d��dS)NrMr�u
<,.V<W1A; á riTrOu<,.V<W1A; á 
rkrer4r4r5�test_8bit_in_uuencode_body(s��
�z0Test8BitBytesHandling.test_8bit_in_uuencode_body))zFrom: foo@bar.com�r�r�)uTo: báz)r�z=?unknown-8bit?q?b=C3=A1z?=)uVSubject: Maintenant je vous présente mon collègue, le pouf célèbre
	Jean de Baddie)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)cCr!r4r4)rnr�_r4r4r5rp=rqz Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
rMcCs:t�|j�}|�t|�d��d�|�t|d�d�dS)Nr��b��z)r�r��headertest_msgr-r�r[r\r4r4r5�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)rtr4)rnrxr�r4r4r5rpOszATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	r�r�rzr-r�r�r�r��headertest_headersr\r4r4r5�test_print_8bit_headersEs
���z-Test8BitBytesHandling.test_print_8bit_headerscC�.t�|j�}|�dd�|��D�gd��dS)NcSr�r4�r�r�r4r4r5rpTrqzGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>)r�ry�]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie�	g��st)r�r�rz�assertListEqualrar\r4r4r5�test_values_with_8bit_headersR��z3Test8BitBytesHandling.test_values_with_8bit_headerscCr~)NcSs g|]\}}t|�t|�f�qSr4r)rnrlr�r4r4r5rp_s zFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>)rw)r�ry)r�r�)r�r�)r�r�rzr�r�r\r4r4r5�test_items_with_8bit_headers]r�z2Test8BitBytesHandling.test_items_with_8bit_headerscCs0t�|j�}|�dd�|�d�D�ddg�dS)NcSr�r4rr�r4r4r5rpkrqzHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�r�r�)r�r�rzr�r/r\r4r4r5�test_get_all_with_8bit_headersis��z4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsJt�t�d��d��}|�|��d�|�|��d�|�|��d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            r|utext/pl�inr�upl�in)	r�r�r�r�r�r-rBr;rHr\r4r4r5�test_get_content_type_with_8bitos�z5Test8BitBytesHandling.test_get_content_type_with_8bitcCsXt�d�d��}|�|jdd�gd��|�|jddd�d�|�|jddd�d�dS)	Nu(X-Header: foo=§ne; b§r=two; baz=three
r|r�r�))r���ne)ub�rr�r�ZFoor�ub§r)r�r�r�r-r�rCr\r4r4r5�test_get_params_with_8bitxs��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§nr|�title)rG�enuThis is not f�n)r�r�r�r�r�r-rCr\r4r4r5�!test_get_rfc2231_params_with_8bit�s��z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8t�t�d��d��}|�dd�|�|�d�d�dS)Nr�r|r��test)r�r�r�r�r�r
r-rCr\r4r4r5�!test_set_rfc2231_params_with_8bit�s
�z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFt�t�d��d��}|�d�|�|�d�d�|�|��d�dS)Nr�r|r�r�)	r�r�r�r�r�rr-rCr;r\r4r4r5�!test_del_rfc2231_params_with_8bit�s�
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
            r|zpayload
TrOspayload
)r�r�r�r�r�r-rQr\r4r4r5�%test_get_payload_with_8bit_cte_header�s
�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�dSrZ)	r�r��non_latin_bin_msgrr�rr�r-r��r1r3r�r4r4r5�test_bytes_generator��z*Test8BitBytesHandling.test_bytes_generatorcCs6tj��}t�}tj�|��|�|�|��d�dS)Nr�)	r�rrrr�rr�r-r�r�r4r4r5�&test_bytes_generator_handles_None_body�s
z<Test8BitBytesHandling.test_bytes_generator_handles_None_bodya�        From: foo@bar.com
        To: =?unknown-8bit?q?b=C3=A1z?=
        Subject: =?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue?=
         =?unknown-8bit?q?=2C_le_pouf_c=C3=A9l=C3=A8bre?=
         =?unknown-8bit?q?_Jean_de_Baddie?=
        Mime-Version: 1.0
        Content-Type: text/plain; charset="utf-8"
        Content-Transfer-Encoding: base64

        0JTQsCwg0L7QvdC4INC70LXRgtGP0YIuCg==
        cCs:t�|j�}t�}tj�|��|�|�|��|j	�dSrZ)
r�r�r�rr�r
r�r-r�� non_latin_bin_msg_as7bit_wrappedr�r4r4r5�test_generator_handles_8bit�r�z1Test8BitBytesHandling.test_generator_handles_8bitcCs`t�|j�}t�}t|��|�|��}tt���|�t�}t|��|�|�	|��|�dSrZ)
r�r�r�rrr�r�r
rr-)r1r3r�Z
orig_valuer4r4r5�;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�rsFromrt)r�r�r�rr�rr�r�r�r-r�)r1r3r�r�r4r4r5�#test_bytes_generator_with_unix_from�s z9Test8BitBytesHandling.test_bytes_generator_with_unix_fromzkSubject: =?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=r�r�cCs�d}|�t|�t|d��}|�|j�Wd�n1swYt|d��}tj���|�}Wd�n1s;wY|�	t
|�|j�dS)Nztest.msg�wbr�)Z
addCleanupr$�open�writer�r�r�rFr6r-r��non_latin_bin_msg_as7bit)r1rZtestfiler�r4r4r5�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?
        r|a         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�dSrZ)r�r��
latin_bin_msgr-r��latin_bin_msg_as7bitr�r4r4r5�:test_string_generator_reencodes_to_quopri_when_appropriateszPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriatecCsDt�|j�}t�}tj�|��|�|�|��|j�	d�d�dS)Nr|r))
r�r�r�rr�rr�r-r�rP)r1r�r�r4r4r5�)test_decoded_generator_emits_unicode_bodys
�z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCsXtj��}tdt|j�d�D]}|�|j||d��q|��}|�t	|�|j
�dS)Nrr�)r�rUr(r�rr�r3r4r-r�r�)r1Zbfpr�r�r4r4r5�test_bytes_feedparsers

z+Test8BitBytesHandling.test_bytes_feedparsercCsptdd��}|��}Wd�n1swYt�|�}t�}tj�|�}|j|dd�|�|�	�|�dS)Nr�r�r�r�)
r%r�r�r�rr�rr�r-r�rDr4r4r5rW 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--

            rM)r�r�r�r�r�rr�rr�r-r�)r1r�r3r�r�r4r4r5�test_8bit_multipart)s%�
&
z)Test8BitBytesHandling.test_8bit_multipartcC�Ft�}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�rr�r-r��r1r�r�r�r4r4r5�'test_bytes_generator_b_encoding_linesepW��z=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesepcCr�)Nr�r�r�r�z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr
rr�r�r
r�r-r�r�r4r4r5�!test_generator_b_encoding_linesepcr�z7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/r�r�r�r�r�rlrmrprsrtrurvr|r�r�rzr{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�rWr�r�r�rr4r4r4r5rg�sf
	
		

��
	
	

�



�
		�

	.rgc@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNcCsTt|d��}|��}Wd�n1swY|j�|j|�}t�|�}||fS)Nr�)r%r��normalize_linesep_regex�sub�blinesepr�r�rr4r4r5r.vs
�
z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|�||���dS)Nrr�)r�r�)rr�r�rr�r�r-r�)r1r3rSr�rr�r4r4r5r}sz,BaseTestBytesGeneratorIdempotent._idempotentr@)r�r�r�rr.rr4r4r4r5r�rsr�c@�eZdZdZdZe�d�ZdS)�TestBytesGeneratorIdempotentNLr)r�s\r\nN�r�r�r�r�r��re�compiler�r4r4r4r5r���r�c@r�)� TestBytesGeneratorIdempotentCRLFr�rs	(?<!\r)\nNr�r4r4r4r5r��r�r�c@r1)
�
TestBase64cCs�|j}|t�d�ttjddd���td�D]1}|dkrd}n|dkr&d}n|d	kr-d
}n|dkr4d}n	|dkr;d
}nd}|t�d|�|�qdS)N�hello�hellor*��eol�rr�r�r[r
r��r��rl)r-r�
header_lengthr�body_encoder�)r1r2�sizeZbsizer4r4r5�test_len�s
��zTestBase64.test_lencCr)Nr*�zaGVsbG8=r�)r-rrPrxr4r4r5�test_decode�r�zTestBase64.test_decodecCsd|j}|t�d�d�|t�d�d�|t�d�d�|tjddd	�d
�|tjdddd�d
�dS)Nr�r*r�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-rr�rxr4r4r5�test_encode�s�zTestBase64.test_encodecCsZ|j}tj}||d�d�||d�d�||d�d�||ddd�d	�||d�d�dS)
Nr�z=?iso-8859-1?b?aGVsbG8=?=�hello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=�hello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=rcr"z=?iso-8859-2?b?aGVsbG8=?=)r-rr�)r1r2Zher4r4r5�test_header_encode�szTestBase64.test_header_encodeN)r�r�r�r�r�r�r�r4r4r4r5r��s

r�c@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��_tttd�td�d���_�j�td���j�td���fdd�td
�D��_	dS)Nr��zrtra�Zrd�9csr]rZr4�rnrr4r4r5r��r^z#TestQuopri.setUp.<locals>.<genexpr>s!*+-/c�g|]	}|�jvr|�qSr4)�hlitr�rr4r5rp��z$TestQuopri.setUp.<locals>.<listcomp>�r+�~r��=cr�r4)�blitr�rr4r5rp�r�)
r�rr��ordr��hnonr�r��remove�bnonrr4rr5r�s�zTestQuopri.setUpcC�P|jD]}|�t�|�dt|��q|jD]}|�t�|�dt|��qdS)Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)r�rZr!Zheader_check�chrr�r��r1rr4r4r5�test_quopri_header_check��

�

��z#TestQuopri.test_quopri_header_checkcCr�)Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)r�rZr!Z
body_checkr�r�r�r�r4r4r5�test_quopri_body_check�r�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|��q8|jD]}|t	d
�krWqN|t�t|g��ddt|��qN|t�d
�d�dS)Nr�rtZxxxr"r�s
h@e@l@l@o@r�rtzexpected length 1 for %rr+r�zexpected length 3 for %r� )
r-r!r�rr�r�r�r�r�r��r1r2rr4r4r5�test_header_quopri_len�s0����

�

�z!TestQuopri.test_header_quopri_lencCsN|j}|jD]
}|t�t|g��d�q|jD]
}|t�t|g��d�qdS)Nrtr�)r-r�r!Zbody_lengthr�r�r�r4r4r5�test_body_quopri_lens

�zTestQuopri.test_body_quopri_lencCs2td�D]}t|�}|�t�t�|��|�qdS)Nr�)r�r�r-r!r�Zquote)r1rlrr4r4r5�test_quote_unquote_idempotent
s�z(TestQuopri.test_quote_unquote_idempotentNcCs0|dur
t�|�}nt�||�}|�||�dSrZ)r!r�r-)r1r�Zexpected_encoded_headerr;�encoded_headerr4r4r5�_test_header_encodeszTestQuopri._test_header_encodecC�|�dd�dS)Nr�r*�r�rr4r4r5�test_header_encode_null�z"TestQuopri.test_header_encode_nullcCr�)Nr�z=?iso-8859-1?q?hello?=r�rr4r4r5�test_header_encode_one_wordr�z&TestQuopri.test_header_encode_one_wordcCr�)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=r�rr4r4r5�test_header_encode_two_lines��z'TestQuopri.test_header_encode_two_linescCr�)Nshello�therez=?iso-8859-1?q?hello=C7there?=r�rr4r4r5�test_header_encode_non_ascii#r�z'TestQuopri.test_header_encode_non_asciicC�|jdddd�dS)Nr�z=?iso-8859-2?q?hello?=rcr"r�rr4r4r5�test_header_encode_alt_charset's
�z)TestQuopri.test_header_encode_alt_charsetcCst�|�}|�||�dSrZ)r!�
header_decoder-)r1r�Zexpected_decoded_headerZdecoded_headerr4r4r5�_test_header_decode+s
zTestQuopri._test_header_decodecC�|�dd�dS�Nr*�r�rr4r4r5�test_header_decode_null/r�z"TestQuopri.test_header_decode_nullcCr��Nr�r�rr4r4r5�test_header_decode_one_word2r�z&TestQuopri.test_header_decode_one_wordcCr�)Nz
hello=0Aworldr�r�rr4r4r5�test_header_decode_two_lines5r�z'TestQuopri.test_header_decode_two_linescCr�)Nz
hello=C7thereuhelloÇtherer�rr4r4r5�test_header_decode_non_ascii8r�z'TestQuopri.test_header_decode_non_asciicCr{)Na=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)r-r!r�rr4r4r5�test_header_decode_re_bug_18380;sz*TestQuopri.test_header_decode_re_bug_18380cCs2|dur
t�|�}ntj||d�}|�||�dS)Nr�)r!rPr-)r1ZencodedZexpected_decodedr��decodedr4r4r5�_test_decode?szTestQuopri._test_decodecCr�r��r�rr4r4r5�test_decode_null_wordFr�z TestQuopri.test_decode_null_wordcCr�)Nr�r)r�rr4r4r5�test_decode_null_line_null_wordIr�z*TestQuopri.test_decode_null_line_null_wordcCr�r�r�rr4r4r5�test_decode_one_wordLr�zTestQuopri.test_decode_one_wordcCs|jdddd�dS)Nr��Xr�r�rr4r4r5�test_decode_one_word_eolO�z#TestQuopri.test_decode_one_word_eolcCr��N�hello
�hello
r�rr4r4r5�test_decode_one_lineRr�zTestQuopri.test_decode_one_linecCr��Nrr�rr4r4r5�test_decode_one_line_lfUr�z"TestQuopri.test_decode_one_line_lfcCr�)Nzhello
rr�rr4r4r5�test_decode_one_line_crXr�z"TestQuopri.test_decode_one_line_crcCr�)Nr�helloXrr�r�rr4r4r5�test_decode_one_line_nl[rz"TestQuopri.test_decode_one_line_nlcCr�)Nrr
rr�r�rr4r4r5�test_decode_one_line_crnl^rz$TestQuopri.test_decode_one_line_crnlcCr�)Nr�r�r�rr4r4r5�test_decode_one_line_one_wordar�z(TestQuopri.test_decode_one_line_one_wordcCr�)Nr�ZhelloXworldrr�r�rr4r4r5�!test_decode_one_line_one_word_eoldrz,TestQuopri.test_decode_one_line_one_word_eolcCr�)N�hello
world
�hello
world
r�rr4r4r5�test_decode_two_linesgr�z TestQuopri.test_decode_two_linescCr�)NrZhelloXworldXrr�r�rr4r4r5�test_decode_two_lines_eoljrz$TestQuopri.test_decode_two_lines_eolcCr�)NA�SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamr�rr4r4r5�test_decode_one_long_linemr�z$TestQuopri.test_decode_one_long_linecCr�)Nr+r*r�rr4r4r5�test_decode_one_spacepr�z TestQuopri.test_decode_one_spacecCr�)Nz     r*r�rr4r4r5�test_decode_multiple_spacessr�z&TestQuopri.test_decode_multiple_spacescCr�)Nzhello    
rr�rr4r4r5�$test_decode_one_line_trailing_spacesvr�z/TestQuopri.test_decode_one_line_trailing_spacescCr�)Nzhello    
world   
rr�rr4r4r5�%test_decode_two_lines_trailing_spacesyr�z0TestQuopri.test_decode_two_lines_trailing_spacescCr�)Nz=22quoted=20words=22z"quoted words"r�rr4r4r5�test_decode_quoted_word|r�z"TestQuopri.test_decode_quoted_wordcCr�)Nzab=CD=EF�abÍïr�rr4r4r5�test_decode_uppercase_quotingr�z(TestQuopri.test_decode_uppercase_quotingcCr�)Nzab=cd=efrr�rr4r4r5�test_decode_lowercase_quoting�r�z(TestQuopri.test_decode_lowercase_quotingcCr�)Nzsoft line=
breakzsoft linebreakr�rr4r4r5�test_decode_soft_line_break�r�z&TestQuopri.test_decode_soft_line_breakcCr�)NzA=1,B=A ==> A+B==2r�rr4r4r5�test_decode_false_quoting�r�z$TestQuopri.test_decode_false_quotingcCs�i}|dur	d}n||d<|durd}n||d<tj|fi|��}|�||�|dks/|dkr>|��D]}|�t|�|�q3dSdS)Nr�r�r)r�r�)r!r�r-r�r�r)r1r�Zexpected_encoded_bodyr�r��kwargsZencoded_bodyr�r4r4r5�_test_encode�s�zTestQuopri._test_encodecCr�r��r"rr4r4r5�test_encode_null�r�zTestQuopri.test_encode_nullcCr�)Nz

r#rr4r4r5�test_encode_null_lines�r�z!TestQuopri.test_encode_null_linescCr�r
r#rr4r4r5�test_encode_one_line�r�zTestQuopri.test_encode_one_linecCr�rr#rr4r4r5�test_encode_one_line_crlf�r�z$TestQuopri.test_encode_one_line_crlfcCr�)Nrrr�r�r#rr4r4r5�test_encode_one_line_eol�rz#TestQuopri.test_encode_one_line_eolcCs |jd�d��d�ddd�dS)Nuhelloυ
rM�latin1z
hello=CF=85
r�r�)r"r�rPrr4r4r5�(test_encode_one_line_eol_after_non_ascii�s
�z3TestQuopri.test_encode_one_line_eol_after_non_asciicCr�)Nr+z=20r#rr4r4r5�test_encode_one_space�r�z TestQuopri.test_encode_one_spacecCr�)Nz 
z=20
r#rr4r4r5�test_encode_one_line_one_space�r�z)TestQuopri.test_encode_one_line_one_spacecCr�)Nz 
 
z=20
=20
r#rr4r4r5�test_encode_two_lines_one_space�r�z*TestQuopri.test_encode_two_lines_one_spacecCr�)Nzhello   z
hello  =20r#rr4r4r5�$test_encode_one_word_trailing_spaces�r�z/TestQuopri.test_encode_one_word_trailing_spacescCr�)Nz	hello   
zhello  =20
r#rr4r4r5�$test_encode_one_line_trailing_spaces�r�z/TestQuopri.test_encode_one_line_trailing_spacescCr�)Nzhello  	z
hello  =09r#rr4r4r5�!test_encode_one_word_trailing_tab�r�z,TestQuopri.test_encode_one_word_trailing_tabcCr�)Nz	hello  	
zhello  =09
r#rr4r4r5�!test_encode_one_line_trailing_tab�r�z,TestQuopri.test_encode_one_line_trailing_tabcCr�)N�
abcd 
1234zabcd =

1234r[r�r#rr4r4r5�,test_encode_trailing_space_before_maxlinelen�rz7TestQuopri.test_encode_trailing_space_before_maxlinelencCr�)Nr2zabcd=
=20
1234rtr�r#rr4r4r5�(test_encode_trailing_space_at_maxlinelen�rz3TestQuopri.test_encode_trailing_space_at_maxlinelencCr�)Nr2zabc=
d=20
1234r�r�r#rr4r4r5�,test_encode_trailing_space_beyond_maxlinelen�rz7TestQuopri.test_encode_trailing_space_beyond_maxlinelencCr�)Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
r#rr4r4r5�test_encode_whitespace_lines�r�z'TestQuopri.test_encode_whitespace_linescCr�)Nza = bza =3D br#rr4r4r5�test_encode_quoted_equals�r�z$TestQuopri.test_encode_quoted_equalscCr�)NZdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxr#rr4r4r5�test_encode_one_long_string�r�z&TestQuopri.test_encode_one_long_stringcCr�)Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
r#rr4r4r5�test_encode_one_long_line�r�z$TestQuopri.test_encode_one_long_linecCr�)Nz�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
z�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r#rr4r4r5�test_encode_one_very_long_line�r�z)TestQuopri.test_encode_one_very_long_linecCr�)Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr�r�r#rr4r4r5�test_encode_shortest_maxlinelen�rz*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr*r�r�)r�r%r"rr4r4r5� 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*r�r�r��dxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx r�r�zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20r�r�zlxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20zone line

two line)r-r!r�rxr4r4r5r��s�
�zTestQuopri.test_encoderZ)NN)Fr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	rrrrrrrrrrrrrrrrrr r"r$r%r&r'r(r*r+r,r-r.r/r0r1r3r4r5r6r7r8r9r:r;r<r�r4r4r4r5r��s�


r�c@r1)
�TestCharsetcCs0ddlm}z|jd=WdStyYdSw)Nrr"�fake)r�r;ZCHARSETSrc)r1�
CharsetModuler4r4r5�tearDown	s�zTestCharset.tearDowncCsN|j}td�}||�d�d�d}|�t|j|�td�}||�|�d�dS)NrG�Hello World!u¤¢¤¤¤¦¤¨¤ªrMz(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r-r	r�r�r�)r1r2rr�r4r4r5�test_codec_encodeablesz!TestCharset.test_codec_encodeablecCs�|j}td�}|d|�d��td�}|d|�d��td�}|d|�d��td	�}d
dlm}|�d|jdd�td�}|d|�d��dS)
Nr7z
hello w=F6rlduhello wörldrMr�r�rGr�r�rr"r?)r-r	r�r�r;Zadd_charsetZQP)r1r2rr@r4r4r5�test_body_encodeszTestCharset.test_body_encodecCs,td�}|�t|�d�|�tjtd�dS)NrGuascÿii)r	r-r�r�rZCharsetErrorr�r4r4r5�test_unicode_charset_name:sz%TestCharset.test_unicode_charset_nameN)r�r�r�rArCrDrEr4r4r4r5r>s
r>c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)4�
TestHeadercC�8|j}td�}||��d�|�d�||��d�dS)NrBz Goodbye World!zHello World!  Goodbye World!�r�r
r�r�r�r4r4r5�test_simpleC�

zTestHeader.test_simplecCrG)NrBzGoodbye World!zHello World! Goodbye World!rHr�r4r4r5�test_simple_surpriseJrJzTestHeader.test_simple_surprisecCsd}|�t|�|dfg�dS)Nzno decoding neededr�r�r4r4r5�test_header_needs_no_decodingQsz(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.r�r�r+)Z
splitcharsz
 )r
r�r�r�r)r1r��lr4r4r5�	test_longUs��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)Nr7rcrMr�r�r�r�r�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�rrtr�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�rrr�rPr)
r1r2r�r�r�r�r�r�r��encr�ZustrZnewhr4r4r5�test_multilingual[s0

�zTestHeader.test_multilingualcCr*r�r�r�r4r4r5�test_empty_header_encode�r�z#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|�dtd��||d�dS)Nr*r�r7)r�r
r�r	r�r4r4r5�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�r4r4r5�test_explicit_maxlinelen�sz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�d�|��}||d�||ttt|����dS)Nr7r��r;r�r=a=?iso-8859-1?q?xxx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_?=r�z�=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xxx?=
 =?iso-8859-1?q?x_xxxx_xxxx_xxxx_xxxx_?=
 =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
 =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
 =?iso-8859-1?q?_xxxx_xxxx_?=�r�r
r�r�r�rr�r1r2r�rlr�r4r4r5�test_quopri_splittable�s

3

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

#

z!TestHeader.test_base64_splittablecCs8|j}d}t|�}||dg�t|�}|||���dS)Nr�)r�N�r-rrr�)r1r2r�rlr�r4r4r5�test_us_ascii_header3szTestHeader.test_us_ascii_headercCs&|j}t�}|�dd�||d�dS)Nr�r7)r-r
r�r�r4r4r5�test_string_charset;szTestHeader.test_string_charsetcCs:|j}tdd�}||��d�tdd�}||��d�dS)NrhrMz=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=�r-r
r�r�r4r4r5�test_utf8_shortestJs


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 BigrMr�r)r�r-r�r
r�rPr�)r1rxr2rlr��er4r4r5�test_bad_8bit_headerQs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)	rPr
r�r;�UNKNOWN8BITr-r�r�r)r1rlr_r�r4r4r5�test_escaped_8bit_header]s
�z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS�Nr^r"rbrc)r
r�r;rdr-r�r�r)r1rlr�r4r4r5�&test_header_handles_binary_unknown8bites
�z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tj�tj�|��}|�t|�d�|�tj�|�|dfg�dSrf)	r
r�r;rdr�rrr-r�)r1rlr�Zh2r4r4r5�+test_make_header_handles_binary_unknown8bitls
�z6TestHeader.test_make_header_handles_binary_unknown8bitcCs2td�}tj�|�}|�d�|�t|�d�dS)Nr�)r�Ztest2)r
r�r�rr�r-r�)r1r�r5r4r4r5�0test_modify_returned_list_does_not_change_headerts
z;TestHeader.test_modify_returned_list_does_not_change_headercCsR|j}t�}|�dd�|�d�|��}||d�tt|��}||��|�dS)Nr�r7Zworldz=?iso-8859-1?q?hello?= world)r-r
r�r�rr)r1r2r�r�r4r4r5� test_encoded_adjacent_nonencodedzs

z+TestHeader.test_encoded_adjacent_nonencodedcCs:|j}d}t|�}||gd��t|�}||��d�dS)NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.))s	Subject: N)s������� � ��������rd)s zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.rY)r1r2r��partsZhdrr4r4r5�test_whitespace_keeper�s�z!TestHeader.test_whitespace_keepercCs|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r�rr�r)r1rxr�r4r4r5�test_broken_base64_header�sz$TestHeader.test_broken_base64_headercCs tddd�}|�|��d�dS)Nr��	shift_jisr"r�r�r�r4r4r5�test_shift_jis_charset�r6z!TestHeader.test_shift_jis_charsetcCst�d�}|�t|�d�dS)NzEmptyHeader:zEmptyHeader: 

)r�r�r-r�r\r4r4r5�!test_flatten_header_with_no_value�s
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\r4r4r5�)test_encode_preserves_leading_ws_on_value�rUz4TestHeader.test_encode_preserves_leading_ws_on_valuecCs|�td���d�dS)Nr+r\rr4r4r5�test_whitespace_header�sz!TestHeader.test_whitespace_headerN)r�r�r�rIrKrLrNrPrQrRrSrWrXrZr[r]r`rergrhrirjrlrmrorprqrrr4r4r4r5rFBs4?E6
	rFc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=S)>�TestRFC2231cCs8|j}|�d�}||�d�d�||jddd�d�dS)Nz
msg_29.txtr��rGr��%This is even more ***fun*** isn't it!Fr�)rGr�z'"This is even more ***fun*** isn't it!")r-r.rCr0r4r4r5r��s

��zTestRFC2231.test_get_paramcCs�|j}t�}|jdddd�||�d�d�|jddddd�||�d�d�|�d	�}|jddddd�||jd
d�d�dS)
Nr�rurGr")rGr*rur��r;�languagertrr�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
rCr.r�r0r4r4r5r�s&�
��
�
�zTestRFC2231.test_set_paramcCsft�}|�dd�|�|dd�|jdddd�|�|dd�|jdd	dd�|�|dd
�dS)Nr�r�r:ztext/plain; title="foo"r�F)Zrequoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")rr
r-r\r4r4r5�test_set_param_requote�sz"TestRFC2231.test_set_param_requotecCsX|j}|�d�}|jddddd�|jddddd�|jdd	d
�||jdd�d
�dS)Nrr�r�rGr�rvr�rur>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
rr�r0r4r4r5r�s
�zTestRFC2231.test_del_paramcCr{)Nr2rG)r-r.�get_content_charsetr0r4r4r5� test_rfc2231_get_content_charsetr�z,TestRFC2231.test_rfc2231_get_content_charsetcC�8t�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-rlr�rer4r4r5�test_rfc2231_parse_rfc_quoting
�


�z*TestRFC2231.test_rfc2231_parse_rfc_quotingcCr{)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}rer4r4r5� test_rfc2231_parse_extra_quotingrz,TestRFC2231.test_rfc2231_parse_extra_quotingcC�4d}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�rCZassertNotIsInstance�tupler-�r1r�r3Zparamr4r4r5�#test_rfc2231_no_language_or_charset(s

�z/TestRFC2231.test_rfc2231_no_language_or_charsetcC�"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�rer4r4r5�/test_rfc2231_no_language_or_charset_in_filename7�


�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamecCr�r�r�rer4r4r5�7test_rfc2231_no_language_or_charset_in_filename_encodedDr�zCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedcCr�)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�rer4r4r5�test_rfc2231_partly_encodedR�
�z'TestRFC2231.test_rfc2231_partly_encodedcCr�)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�rer4r4r5�test_rfc2231_partly_nonencoded_r�z*TestRFC2231.test_rfc2231_partly_nonencodedcCr�)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�rer4r4r5�/test_rfc2231_no_language_or_charset_in_boundarylr�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundarycCr�)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-ryrer4r4r5�.test_rfc2231_no_language_or_charset_in_charsetxs


�z:TestRFC2231.test_rfc2231_no_language_or_charset_in_charsetcCr�)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�rer4r4r5�%test_rfc2231_bad_encoding_in_filename�r�z1TestRFC2231.test_rfc2231_bad_encoding_in_filenamecC�"d}t�|�}|�|��d�dS)Nz:Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D

r�rer4r4r5�$test_rfc2231_bad_encoding_in_charset��
z0TestRFC2231.test_rfc2231_bad_encoding_in_charsetcCr�)Nz:Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D

r�rer4r4r5�%test_rfc2231_bad_character_in_charset�r�z1TestRFC2231.test_rfc2231_bad_character_in_charsetcCr�)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�rer4r4r5�&test_rfc2231_bad_character_in_filename�r�z2TestRFC2231.test_rfc2231_bad_character_in_filenamecCr�)Nz^Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt

�
myfile.txtr�rer4r4r5�test_rfc2231_unknown_encoding��
z)TestRFC2231.test_rfc2231_unknown_encodingcCr�)NucContent-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=utf-8���''myfile.txt

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

r��Frank's Documentr��r1r2r�r3r;rwr�r4r4r5�-test_rfc2231_single_tick_in_filename_extended��


z9TestRFC2231.test_rfc2231_single_tick_in_filename_extendedcCr�)NzGContent-Type: application/x-foo; name*0="Frank's"; name*1=" Document"

r�r�r�r�r4r4r5�$test_rfc2231_single_tick_in_filename�s


z0TestRFC2231.test_rfc2231_single_tick_in_filenamecCr�)NzAContent-Disposition: inline;
	filename*0*="'This%20is%20broken";
z'This is brokenr�rer4r4r5�test_rfc2231_missing_tick��
�z%TestRFC2231.test_rfc2231_missing_tickcCr�)NzAContent-Disposition: inline;
	filename*0*="'This%20is%E2broken";
u'This is�brokenr�rer4r4r5�0test_rfc2231_missing_tick_with_encoded_non_ascii�r�z<TestRFC2231.test_rfc2231_missing_tick_with_encoded_non_asciicC�F|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�rG�en-usr�r�r�r4r4r5�!test_rfc2231_tick_attack_extended�r�z-TestRFC2231.test_rfc2231_tick_attack_extendedcCr�)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�r4r4r5�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�r�r�rr4r4r5�test_rfc2231_no_extended_valuess
z+TestRFC2231.test_rfc2231_no_extended_valuescCr�)NziContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'My";
	name*1=" Document";
	name*2*=" For You"

r�rGr��My Document For Your�r�r4r4r5�,test_rfc2231_encoded_then_unencoded_segments�


z8TestRFC2231.test_rfc2231_encoded_then_unencoded_segmentscCr�)NziContent-Type: application/x-foo;
	name*0="us-ascii'en-us'My";
	name*1*=" Document";
	name*2*=" For You"

r�rGr�r�r�r�r4r4r5�,test_rfc2231_unencoded_then_encoded_segments&r�z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsc	CsLddg}|D]}|j|d��
t�|�}Wd�n1swYqdS)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�)rr�r�)r1Zmessagesr�r3r4r4r5�+test_should_not_hang_on_invalid_ew_messages5s����z7TestRFC2231.test_should_not_hang_on_invalid_ew_messagesN)!r�r�r�r�rrxrrzr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r4r4r4r5rs�s>%
!




		


rsc@r!)�
TestSignedcCsLt|dd��}|��}t�|�}Wd�||fS1swY||fSrr)r1rr��originalr3r4r4r5�_msg_and_objQs
��zTestSigned._msg_and_objcCsLddl}|�d|j|jB�}|�|��d�}|�|��d�}|�||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$r�)r�r��Sr>�search�groupr-)r1r��resultr�ZrepartZinpartZoutpartr4r4r5�_signed_parts_eqWs
zTestSigned._signed_parts_eqcCs&|�d�\}}|��}|�||�dSr:�r�r�r��r1r�r3r�r4r4r5�test_long_headers_as_string_sz&TestSigned.test_long_headers_as_stringcCs*|�d�\}}|jdd�}|�||�dS)Nr;�<r�r�r�r4r4r5�(test_long_headers_as_string_maxheaderlendsz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|�d�\}}t�}t|��|�|��}|�||�dSr:)r�rr
r�r�r�)r1r�r3r�r�r4r4r5�test_long_headers_flattenis
z$TestSigned.test_long_headers_flattenN)r�r�r�r�r�r�r�r�r4r4r4r5r�Osr�c@r�)�TestHeaderRegistrycCs(t�}|dd�}|�|jdtj�dS)Nrzattachment; 0*00="foo"r)rrhrirZInvalidHeaderDefect)r1Zregr�r4r4r5�test_HeaderRegistryrs
z&TestHeaderRegistry.test_HeaderRegistryN)r�r�r�r�r4r4r4r5r�psr��__main__)fr�rorNrer��iorr�	itertoolsrZrandomrZ	threadingrZ
unittest.mockrr�Zemail.policyZemail.utilsZ
email.charsetr	Zemail.generatorr
rrZemail.headerr
rrZemail.headerregistryrZ
email.messagerZemail.mime.applicationrZemail.mime.audiorZemail.mime.baserZemail.mime.imagerZemail.mime.messagerZemail.mime.multipartrZemail.mime.nonmultipartrZemail.mime.textrZemail.parserrrrrrr r!r"Ztest.supportr#Ztest.support.os_helperr$Ztest.test_emailr%r&r'r(r�rr�r,ZTestCaser�r�rr"r@rCrTrgr�r�r�rrrArr2r@rgr�r�r�r�r�r>rFrsr�r�r��mainr4r4r4r5�<module>s�CAO((\<09 ug0K!��4D:h*!
�