HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/test_email/__pycache__/test_email.cpython-310.pyc
o

�iF�@s�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZddlmZddlmZmZmZdd	lmZmZmZdd
lmZddlmZddl m!Z!dd
l"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddlm3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddlm7Z7ddlm8Z8ddl9m:Z:ddl;m<Z<ddl=m>Z>m?Z?ddl0m@Z@mAZAdZBd ZCd!ZDGd"d#�d#e?�ZEGd$d%�d%ejF�ZGGd&d'�d'e?�ZHGd(d)�d)ejF�ZIGd*d+�d+ejF�ZJGd,d-�d-ejF�ZKGd.d/�d/ejF�ZLGd0d1�d1ejF�ZMGd2d3�d3e?�ZNGd4d5�d5e?�ZOGd6d7�d7e?�ZPGd8d9�d9e?�ZQGd:d;�d;e?�ZRGd<d=�d=e?�ZSGd>d?�d?e?�ZTGd@dA�dAe?�ZUGdBdC�dCe?�ZVGdDdE�dEe?�ZWGdFdG�dGe?�ZXGdHdI�dI�ZYGdJdK�dKeYeS�ZZGdLdM�dMeYeS�Z[GdNdO�dOejF�Z\GdPdQ�dQejF�Z]GdRdS�dSejF�Z^GdTdU�dUe?�Z_GdVdW�dWe?�Z`GdXdY�dYe?�ZaGdZd[�d[e?�Zbecd\k�r�e�d�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�S)��TestMessageAPIcCs:|j}|�d�}||�d�gd��||�dd�d�dS)Nz
msg_20.txtZcc)zccc@zzz.orgzddd@zzz.orgzeee@zzz.org�xxzn/a)�assertEqual�_msgobj�get_all��self�eq�msg�r5�7/usr/local/lib/python3.10/test/test_email/test_email.py�test_get_all8s
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�r2r3r4r<r5r5r6�test_getset_charset>s,


z"TestMessageAPI.test_getset_charsetcCs8|j}t�}|�d�||��jd�||dd�dS)N�us-asciir;�text/plain; charset="us-ascii")r.rrBrArEr1r5r5r6�test_set_charset_from_stringXs

z+TestMessageAPI.test_set_charset_from_stringcCs0t�}td�}|�d|�|�|��jd�dS)Nr8zThis is a string payload)rr	�set_payloadr.rArE)r2r4r<r5r5r6�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	rrKr.�get_payload�r2�datar<r4r5r5r6�+test_set_payload_with_8bit_data_and_charsetesz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsRd}td�}d|_t�}|�|�d�|�|�|dd�|�|jdd�|�dS�NrMrNr=�8bitTrP)r	�
body_encodingrrKrQr.rRrSr5r5r6�>test_set_payload_with_non_ascii_and_charset_body_encoding_nonenszMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCsLd}td�}d|_t�}|�||�|�|dd�|�|jdd�|�dSrV)r	rXrrKr.rRrSr5r5r6�>test_set_payload_with_8bit_data_and_charset_body_encoding_nonewszMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs$t�}|�g�|�|��g�dS�N�rrKr.rR�r2r4r5r5r6�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)rrKrZassertRaisesRegex�	TypeError�attach)r2r4Zsub_msgr5r5r6�"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)NrHr8�
iso-8859-2�koi8-rz
msg_09.txt�dingbat)rfrHr8rfrez
msg_12.txt)NrHr8Nrdz
iso-8859-3rHre)r.r/�get_charsets)r2r3r4�charsetsr5r5r6�test_get_charsets�s



z TestMessageAPI.test_get_charsetscCsV|j}|�d�}dd�|��D�}||ddg�|�d�}|�d�}||��d�dS)N�
msg_04.txtcS�g|]}|���qSr5��get_filename��.0�pr5r5r6�
<listcomp>��z4TestMessageAPI.test_get_filename.<locals>.<listcomp>�msg.txt�
msg_07.txt��dingusfish.gif)r.r/rRrm)r2r3r4�	filenames�subpartr5r5r6�test_get_filename�s


z TestMessageAPI.test_get_filenamecCs4|j}|�d�}dd�|��D�}||ddg�dS)Nz
msg_44.txtcSrkr5rlrnr5r5r6rq�rrzHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>rs�r.r/rR)r2r3r4rwr5r5r6�%test_get_filename_with_name_parameter�s
z4TestMessageAPI.test_get_filename_with_name_parametercC�"|j}|�d�}||��d�dS)Nrt�BOUNDARY)r.r/�get_boundaryr1r5r5r6�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"rjz$multipart/mixed; boundary="BOUNDARY"�
msg_03.txt)r.r/�set_boundary�items�lower�assertRaisesr�HeaderParseError)r2r3r4�header�valuer5r5r6�test_set_boundary�s






�z TestMessageAPI.test_set_boundarycCsLtd�}|�|��ddd�|��|�|��dddd�d�dS)Nz	form-datarruzmultipart/form-data�!z!multipart/form-data; boundary="==)rr.r��	as_stringr]r5r5r6�test_make_boundary�s�z!TestMessageAPI.test_make_boundarycCsvtddd��}|��}Wd�n1swYt�}|�|�}t�}t|dd�}|�|d�|�|��|�dS)N�
msg_46.txtrN��encodingTrF)	r%�readr�parsestrrr
�flattenr.�getvalue�r2�fpZmsgdata�parserr4�out�genr5r5r6�test_message_rfc822_only�s
�
z'TestMessageAPI.test_message_rfc822_onlycCs~tddd��}|���d�}Wd�n1swYtj��}|�|�}t�}tj�	|�}|�
|�|�|��|�dS)Nr�rNr��ascii)
r%r��encode�emailr��BytesHeaderParserZ
parsebytesr�	generatorrr�r.r�r�r5r5r6�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.txtTrPrs This is a 7bit encoded message.
rus-�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.
rzr1r5r5r6�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=TrP�hello world�foosfoo)r.rrKrR)r2r3r4�cter5r5r6�test_get_decoded_uu_payloads

z*TestMessageAPI.test_get_decoded_uu_payloadcCst�}|�t|jd�dS)Nru)rr�rarRr]r5r5r6�*test_get_payload_n_raises_on_non_multipart�z9TestMessageAPI.test_get_payload_n_raises_on_non_multipartcCsn|j}|�d�}tddd��}|��}Wd�n1swYt�}t|�}|�|�||��|�dS)Nrtz
msg_17.txtrNr�)r.r/r%r�rrr�r�)r2r3r4r��text�s�gr5r5r6�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]r5r5r6�test__contains__szTestMessageAPI.test__contains__cCs�|�d�}tddd��}|��}Wd�n1swY|�|t|��|jdd�}|�d�}|�|d�d��|�|t	�
|d	d���dS)
Nr�rNr�T��unixfromr)rzFrom ru)r/r%r�r.�strr��split�
assertTrue�
startswith�NL�join)r2r4r�r��fullrepr�linesr5r5r6�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��r2r4Z	newpolicyr�r�r�r5r5r6�test_as_string_policy3�

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
            r8a%            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��r2�m�source�expectedr4r5r5r6�#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
            r8r��replace)r�r�r�rQr�r�r.r�r�r5r5r6�4test_nonascii_as_string_without_content_type_and_cteRs



zCTestMessageAPI.test_nonascii_as_string_without_content_type_and_ctecCs�|�d�}tddd��}|���d�}Wd�n1swY|�|t|��|jdd�}|�d�}|�|d�	d	��|�|d�
|d
d���dS)Nr�rNr�r�Tr��
rsFrom ru)r/r%r�r�r.�bytes�as_bytesr�r�r�r�)r2r4r�rTr�r�r5r5r6�
test_as_bytes_s
�
zTestMessageAPI.test_as_bytescCr�r�)	r/r�r�r�rrr�r.r�r�r5r5r6�test_as_bytes_policyir�z#TestMessageAPI.test_as_bytes_policycCs t�d�}|�|�d�d�dS)NzContent-Type: blarg; baz; boo
�bazr*�r��message_from_stringr.rDr]r5r5r6�test_bad_params�
zTestMessageAPI.test_bad_paramcC�t�d�}|�|��d�dS�Nz
From: foo
�r�r�r.rmr]r5r5r6�test_missing_filenamew�
z$TestMessageAPI.test_missing_filenamecCst�d�}|�|��d�dS)Nz%Content-Disposition: blarg; filename
r*r�r]r5r5r6�test_bogus_filename{s�z"TestMessageAPI.test_bogus_filenamecCr�r��r�r�r.r~r]r5r5r6�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_paramsr1r5r5r6�test_get_params�s(������zTestMessageAPI.test_get_paramscCs$t�}d|d<|�|�d�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"r?�boundaryZCPIMSSMTPC06p5f3tG)rr.rDr]r5r5r6�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�rDr1r5r5r6�test_get_param�s��zTestMessageAPI.test_get_paramcCs&|�d�}|�|�d��d�d�dS)Nz
msg_22.txtru�namez
wibble.JPG)r/r.rRrDr]r5r5r6�'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]r5r5r6�#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]r5r5r6�test_get_param_with_quotes�s��z)TestMessageAPI.test_get_param_with_quotescCs>t�d�}|�d|�|�d|�|�d|�|�d|�dS)NzHeader: existsr�r
ZHEADERZheaderx)r�r�r�ZassertNotInr]r5r5r6�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")�r:r*)r<r�)r�r�)r)r<z
"iso-2022-jp")r�rziso-9999-xxzX-Jimmyr�)r.r�	set_paramrDr�r1r5r5r6�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�rD�	del_paramr)r2r3r4Zold_valr5r5r6�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]r5r5r6�test_del_param_on_other_header�sz-TestMessageAPI.test_del_param_on_other_headercCst�}|�dd�dS)Nrr)rrr]r5r5r6�$test_del_param_on_nonexistent_header�sz3TestMessageAPI.test_del_param_on_nonexistent_headercCs@t�}|jdddd�|d}|jddd�|�|d|�dS)Nr?r:rN�r<�foobarr�r)r2r4Zexisting_headerr5r5r6�test_del_nonexistent_param�s
z)TestMessageAPI.test_del_nonexistent_paramcCsj|j}t�}|�t|jd�|�d�||dd�|�dd�||dd�|�d�||dd�dS)	Nr�r:r;r<rHrIz	text/htmlztext/html; charset="us-ascii")r.rr��
ValueError�set_typerr1r5r5r6�
test_set_type�s

zTestMessageAPI.test_set_typecCs.t�}d|d<|�dd�|�|dd�dS)Nr:zX-Content-Type�application/octet-streamzx-content-type)rrr.r]r5r5r6�test_set_type_on_other_headersz,TestMessageAPI.test_set_type_on_other_headercC�t�}|�|��d�dS)Nr:)rr.rCr]r5r5r6�test_get_content_type_missing
r�z,TestMessageAPI.test_get_content_type_missingcCs$t�}|�d�|�|��d�dS)N�message/rfc822)r�set_default_typer.rCr]r5r5r6�/test_get_content_type_missing_with_default_typer_z>TestMessageAPI.test_get_content_type_missing_with_default_typecC�$|�d�}|�|�d���d�dS)N�
msg_30.txtrr!�r/r.rRrCr]r5r5r6�+test_get_content_type_from_message_implicit�
�z:TestMessageAPI.test_get_content_type_from_message_implicitcCr$)N�
msg_28.txtrr!r&r]r5r5r6�+test_get_content_type_from_message_explicitr(z:TestMessageAPI.test_get_content_type_from_message_explicitcC�|�d�}|�|��d�dS)Nr�r:�r/r.rCr]r5r5r6�6test_get_content_type_from_message_text_plain_implicit r�zETestMessageAPI.test_get_content_type_from_message_text_plain_implicitcCr+)Nr�r:r,r]r5r5r6�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]r5r5r6�!test_get_content_maintype_missing(r�z0TestMessageAPI.test_get_content_maintype_missingcC�$t�}|�d�|�|��d�dS)Nr!�message)rr"r.r0r]r5r5r6�3test_get_content_maintype_missing_with_default_type,r_zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCr$)Nr%rr3�r/r.rRr0r]r5r5r6�/test_get_content_maintype_from_message_implicit1�
z>TestMessageAPI.test_get_content_maintype_from_message_implicitcCr$)Nr)rr3r5r]r5r5r6�/test_get_content_maintype_from_message_explicit5r7z>TestMessageAPI.test_get_content_maintype_from_message_explicitcCr+)Nr�r��r/r.r0r]r5r5r6�:test_get_content_maintype_from_message_text_plain_implicit9r�zITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitcCr+)Nr�r�r9r]r5r5r6�:test_get_content_maintype_from_message_text_plain_explicit=r�zITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitcCr)N�plain�rr.�get_content_subtyper]r5r5r6� test_get_content_subtype_missingAr�z/TestMessageAPI.test_get_content_subtype_missingcCr2)Nr!�rfc822)rr"r.r>r]r5r5r6�2test_get_content_subtype_missing_with_default_typeEr_zATestMessageAPI.test_get_content_subtype_missing_with_default_typecCr$)Nr%rr@�r/r.rRr>r]r5r5r6�.test_get_content_subtype_from_message_implicitJr7z=TestMessageAPI.test_get_content_subtype_from_message_implicitcCr$)Nr)rr@rBr]r5r5r6�.test_get_content_subtype_from_message_explicitNr7z=TestMessageAPI.test_get_content_subtype_from_message_explicitcCr+)Nr�r<�r/r.r>r]r5r5r6�9test_get_content_subtype_from_message_text_plain_implicitRr�zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCr+)Nr�r<rEr]r5r5r6�9test_get_content_subtype_from_message_text_plain_explicitVr�zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitcC�"t�}d|d<|�|��d�dS)N�no-slash-in-this-stringr?r�r/r]r5r5r6�test_get_content_maintype_errorZ�z.TestMessageAPI.test_get_content_maintype_errorcCrH)NrIr?r<r=r]r5r5r6�test_get_content_subtype_error_rKz-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)rMrOrQ)rNrPrR�Twenty)rNrSrR�Eleven�One Hundred)rMrOrQrM)rUrSrRrTZFourthZMissing)r.rr�keys�values�replace_headerr��KeyErrorr1r5r5r6�test_replace_headerdsz"TestMessageAPI.test_replace_headercCspt�}|�|���|jdddd�|�|��d�|�dd�|�|��d�|�dd�|�|��d�dS)Nr
rz
random.avir�inlineZInlinE)r�assertIsNoneZget_content_dispositionrr.rXr]r5r5r6�test_get_content_dispositionus�z+TestMessageAPI.test_get_content_dispositioncCsPd}t�}d|d<d|d<|�|�|�|jdd�d�|�|jd	tj�dS)
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midir;rOr=TrPs����.���p���r)rrKr.rR�assertIsInstance�defectsr�InvalidBase64CharactersDefect�r2�xr4r5r5r6�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 dor:r;rWr=TrPzraw-unicode-escape)rrKr.rRr�rar5r5r6�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 dorN�text/plain; charset="utf-8"r;rWr=TrP)r�rZ_payloadr.rRrar5r5r6�test_questionable_bytes_payload�s
z.TestMessageAPI.test_questionable_bytes_payloadcC�*t�}|jdddd�|�d|d�dS)Nr
rrrzattachment; filename="bud.gif"�rrr.r]r5r5r6�test_ascii_add_header�s��z$TestMessageAPI.test_ascii_add_headercCrg)Nr
r�Fußballer.pptrz/attachment; filename*=utf-8''Fu%C3%9Fballer.pptrhr]r5r5r6�test_noascii_add_header����z&TestMessageAPI.test_noascii_add_headercCrg)Nr
r)r8r*rjrz1attachment; filename*=iso-8859-1''Fu%DFballer.pptrhr]r5r5r6�#test_nonascii_add_header_via_triple�rlz2TestMessageAPI.test_nonascii_add_header_via_triplecCrg)Nr
rzwindows [filename].pptrz-attachment; filename="windows [filename].ppt"rhr]r5r5r6�#test_ascii_add_header_with_tspecial�rlz2TestMessageAPI.test_ascii_add_header_with_tspecialcCrg)Nr
ruFußballer [filename].pptrz@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptrhr]r5r5r6�&test_nonascii_add_header_with_tspecial�rlz5TestMessageAPI.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=87barTrP�	foo文bar�1get_payload returns wrong result with charset %s.r\�r2r<r4r5r5r6�test_binary_quopri_payload��

��z)TestMessageAPI.test_binary_quopri_payloadcCrp)Nrqrsr;rOr=sZm9v5paHYmFyTrPrtrur\rvr5r5r6�test_binary_base64_payload�rxz)TestMessageAPI.test_binary_base64_payloadc
Cs^dD]*}dD]%}t�}d||d<||d<|�d�|�|jdd�d	td
��||��qqdS)Nrqr�rsr;r=s begin 666 -
)9F]OYI:'8F%R
 
end
TrPrt)z!get_payload returns wrong result z"with charset {0} and encoding {1}.)rrKr.rRr��format)r2r<r�r4r5r5r6�test_binary_uuencode_payload�s

���z+TestMessageAPI.test_binary_uuencode_payloadcCs*t�}|jdddd�|�d|d�dS)Nr
r[)Zfoo_barzinline; foo-barrhr]r5r5r6�$test_add_header_with_name_only_param��z3TestMessageAPI.test_add_header_with_name_only_paramcCs&t�}|�dd�|�d|d�dS)NzX-Statusr*rhr]r5r5r6�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]r5r5r6�(test_embedded_header_via_Header_rejected�rz7TestMessageAPI.test_embedded_header_via_Header_rejectedcCs"t�}d|d<|�tj|j�dSr�)rr�rr�r�r]r5r5r6�(test_embedded_header_via_string_rejected�rKz7TestMessageAPI.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��r2r�r5r5r6�-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�r5r5r6�+test_unicode_body_defaults_to_utf8_encodingsz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)X�__name__�
__module__�__qualname__r7rGrJrLrUrYrZr^rcriryr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrr r#r'r*r-r.r1r4r6r8r:r;r?rArCrDrFrGrJrLrZr]rcrdrfrirkrmrnrorwryr{r|r~r�r�r�r�r5r5r5r6r,7s�			

	



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|��qSr5)�len�rorbr5r5r6rq'rrz;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>�L)
r%r�r��mime�imagerrRr��assertLessEqual�max)r2r��bindataZmimedZbase64edr�r5r5r6�test_EncodersEncode_base64 s
�
z'TestEncoders.test_EncodersEncode_base64cCs(|j}t�}|�d�||dd�dS)NrHr=�7bit)r.rrBr1r5r5r6�test_encode_empty_payload)s
z&TestEncoders.test_encode_empty_payloadcCsP|j}td�}||dd�td�}||dd�tddd�}||dd�dS)	N�hello worldr=r�uhello ø worldrOr8��_charsetr>)r.rr1r5r5r6�test_default_cte/szTestEncoders.test_default_ctecCs8|j}tddd�}||dd�||��t�d��dS)Nu文
�euc-jpr�r=r�z�            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r.rr�r�r�r1r5r5r6�test_encode7or8bit;s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]r5r5r6�test_qp_encode_latin1Js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]r5r5r6�test_qp_encode_non_latin1Tsz&TestEncoders.test_qp_encode_non_latin1N)	r�r�r�r�r�r�r�r�r�r5r5r5r6r�s	
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��r2r3r4�sfpr�r5r5r6�test_split_long_continuationes

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��r2r3Zhstr�hr5r5r6�,test_another_long_almost_unsplittable_headerys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)
Nr8rdrN�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�)r2r3r��cz�utf8�g_head�cz_head�	utf8_headr�r4r�r5r5r6�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��r2r3r�r5r5r6�test_long_header_encode�s
�z'TestLongHeaders.test_long_header_encodecC�&|j}tdddd�}||��d�dS)Nr�r�r��r�r�r�r�r�r5r5r6�<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�r5r5r6�-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��r2r�r5r5r6�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
rQr.r�)r2r��resr5r5r6�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�r5r5r6�test_header_splitter�s�
z$TestLongHeaders.test_header_splittercCsd|j}t�}d|d<t�dd�td�D��|d<|�d�t�}t|�}|�|�||�	�d�dS)	N�test@dom.ainr�css�|]}d|VqdS)z<%d@dom.ain>Nr5�ro�ir5r5r6�	<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��rangerKrr
r�r�r�r5r5r6�test_no_semis_header_splitter�s

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�r5r5r6�"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�r5r5r6�>test_splittable_leading_char_followed_by_overlong_unsplittabler�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�r5r5r6�Gtest_multiple_splittable_leading_char_followed_by_overlong_unsplittable!r�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�r5r5r6�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�r5r5r6�Itest_trailing_splittable_on_overlong_unsplittable_with_leading_splittable1r�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�r5r5r6�5test_long_header_with_multiple_sequential_split_chars:r�zETestLongHeaders.test_long_header_with_multiple_sequential_split_charscCr�)N�Kthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr�r�r5r5r6�:test_splitter_split_on_punctuation_only_if_fws_with_headerBr�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�r5r5r6�Dtest_leading_splittable_in_the_middle_just_before_overlong_last_partI�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�r5r5r6�/test_overlong_last_part_followed_by_split_pointTr�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�r5r5r6�@test_multiline_with_overlong_parts_separated_by_two_split_points[r�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�r5r5r6�>test_multiline_with_overlong_last_part_followed_by_split_pointfr�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�rKrr
r�r�r�r5r5r6�%test_long_header_with_whitespace_runsqs

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�r5r5r6�'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�rrKrr
r�r�r�r5r5r6�.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�r5r5r6�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�r5r5r6�"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�r5r5r6�&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 gibtr8r�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�)r2r3r4r�r5r5r6�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
)r2r3r4Z
header_stringr5r5r6� test_long_8bit_header_no_charset�s
�z0TestLongHeaders.test_long_8bit_header_no_charsetcCs.|j}d}t�}||d<||jdd�d�dS)Nz�"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>, "Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.edu>, "Someone Test #D" <someone@eecs.umich.edu>r�r�r�z�To: "Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,
 "Someone Test #B" <someone@umich.edu>,
 "Someone Test #C" <someone@eecs.umich.edu>,
 "Someone Test #D" <someone@eecs.umich.edu>

)r�rr�)r2r3r�r4r5r5r6�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��r2r3r�r�r5r5r6�test_long_line_after_appends

z+TestLongHeaders.test_long_line_after_appendcCs.|j}d}t|�}|�d�||��d�dS)NzThis is a shorter line.z!Add another sentence. (Surprise?)z9This is a shorter line. Add another sentence. (Surprise?)r�r�r5r5r6�test_shorter_line_with_appends
�z-TestLongHeaders.test_shorter_line_with_appendcCs2|j}d}d}t|d|d�}||jdd�d�dS)Nz!X-Very-Very-Very-Long-Header-Nameu�Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an südlündischen Wandgemälden vorbei, gegen die rotierenden Klingen befördert. r8r�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�)r2r3�fnZgsr�r5r5r6�test_long_field_name"s
z$TestLongHeaders.test_long_field_namecCs:d}t�}t|dd�|d<||d<|�|jdd�d�dS)	Nz�from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP; Wed, 05 Mar 2003 18:10:18 -0700r�r��
Received-1�
Received-2r�r�a1Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
 Wed, 05 Mar 2003 18:10:18 -0700
Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
 Wed, 05 Mar 2003 18:10:18 -0700

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

rrr5r5r6�test_string_headerinst_eqCs
�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�)r2r3r4�tr5r5r6�-test_long_unbreakable_lines_with_continuationVs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��r2r3r�r4r5r5r6�"test_another_long_multiline_headerns
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)r2r3r�r4r5r5r6�%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 worksrNr�)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�r5r5r6�*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�r�r�r�rrrrr	r
r5r5r5r6r�asR6	


					
r�c@r�)�TestFromManglingcCs"t�|_d|jd<|j�d�dS)Nzaaa@bbb.orgr�z(From the desk of A.A.A.:
Blah blah blah
)rr4rK�r2r5r5r6�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�r4r.r��r2r�r�r5r5r6�test_mangled_from��z"TestFromMangling.test_mangled_fromcCr)NFrz;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
rrr5r5r6�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 ru)r�r�r5r5r6rq�s
�zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r)r�)rr
r�r�r�r�r�r.r�r�r�)r2r�r�r4r5r5r6�'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

        rNsFrom Rölli
Trs
>From Rölli
)
r�r�r�r�r�rrr�r.r�)r2r�r4�br�r5r5r6� 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: È
        rN)r�r�r�r�r�)r2r�r4r5r5r6�$test_multipart_with_bad_bytes_in_cte�s�z5TestFromMangling.test_multipart_with_bad_bytes_in_cteN)	r�r�r�rrrrrrr5r5r5r6r�src@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudiocC�Dtdd��
}|��|_Wd�n1swYt|j�|_dS)N�audiotest.aur�)r%r��
_audiodatar�_au�r2r�r5r5r6r���zTestMIMEAudio.setUpcC�|�|j��d�dS)Nzaudio/basic)r.rrCr
r5r5r6�test_guess_minor_type��z#TestMIMEAudio.test_guess_minor_typecC�(|j��}|�t�t|d��|j�dS�Nr�)rrRr.rO�decodebytesr�r�r2�payloadr5r5r6�
test_encoding��
�zTestMIMEAudio.test_encodingcC� t|jd�}|�|��d�dS)N�fishz
audio/fish)rrr.rC)r2Zaur5r5r6�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)Nr
rrrrz#attachment; filename="audiotest.au"r��rr*)rrrr*r��Zfailobjr�r)r.rrr�rD�assertIs�r2r3�missingr5r5r6�test_add_header��4
�
�������zTestMIMEAudio.test_add_headerN�r�r�r�rr#r*r.r6r5r5r5r6r��rc@r)�
TestMIMEImagecCr)Nr�r�)r%r��_imgdatar�_imr r5r5r6rr!zTestMIMEImage.setUpcCr")Nz	image/gif)r.r<rCr
r5r5r6r#r$z#TestMIMEImage.test_guess_minor_typecCr%r&)r<rRr.rOr'r�r;r(r5r5r6r*r+zTestMIMEImage.test_encodingcCr,)Nr-z
image/fish)rr;r.rC)r2Zimr5r5r6r.#r/z TestMIMEImage.test_checkSetMinorcCr0)Nr
rrvrrz%attachment; filename="dingusfish.gif"r�r1)rrvrr*r�r2r)r.r<rr�rDr3r4r5r5r6r6'r7zTestMIMEImage.test_add_headerNr8r5r5r5r6r:r9r:c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestMIMEApplicationcCs.|j}td�}||��d�||dd�dS)N�������rr=rO)r.rrCr1r5r5r6�test_headers>sz TestMIMEApplication.test_headerscCs:|j}d}t|�}||����d�||jdd�|�dS)Nr>z+vv8/f7/TrP)r.rrR�strip)r2r3�	bytesdatar4r5r5r6�	test_bodyDs
zTestMIMEApplication.test_bodycCs�d}t|tjd�}|�|��dt|��|�|jdd�|�|�|dd�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�|�|dd�dS)Nr>�Z_encoder��TrPr@rW)rr�encode_7or8bitr.rRr�rrr�r�r�r��r2rAr4r�r�Zwireform�msg2r5r5r6�$test_binary_body_with_encode_7or8bitLs

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|tjd�}|�|��dt|��|�|jdd�|�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�dS)Nr>rCrDTrP)rr�encode_noopr.rRr�rrr�r�r�r�rFr5r5r6�!test_binary_body_with_encode_noop]s

z5TestMIMEApplication.test_binary_body_with_encode_noopcCshd}t|tjd�}|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|jdd�|�dS)Ns������rCTrP)rrrIr.rRrrr�r�r�r�rFr5r5r6�0test_binary_body_with_unicode_linend_encode_noopns

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|tjd�}|�|��d�|�|jdd�|�|�|dd�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�|�|dd�dS)Ns������ rCz=FA=FB=FC=FD=FE=FF=20TrPr@r>)rrZ
encode_quoprir.rRrrr�r�r�r�rFr5r5r6�#test_binary_body_with_encode_quoprizs

z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|tjd�}|�|��d�|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�dS)Nr>rCz	+vv8/f7/
TrP)rrZ
encode_base64r.rRrrr�r�r�r�rFr5r5r6�#test_binary_body_with_encode_base64�s

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
r�r�r�r?rBrHrJrKrLrMr5r5r5r6r==sr=c@sVeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�d�dd��ZdS)�TestMIMETextcCstd�|_dS�N�hello there)r�_msgr
r5r5r6r��zTestMIMEText.setUpcCs`|j}||j��d�||j�d�d�g}|�|j�d|�|�|�|jjd|dd�|�dS)Nr:r<rHrr�)r.rQrCrDr3r4r5r5r6�
test_types�s�zTestMIMEText.test_typescCs&|�|j��d�|�|j���dSrO)r.rQrR�assertFalse�is_multipartr
r5r5r6�test_payload�szTestMIMEText.test_payloadcCsz|j}tddd�}||��jd�||dd�td�}d|_td|d�}||��jd�||dd�||��d�dS)NrPrHr�r;rIrNre)r.rrArEr	rXrRrFr5r5r6�test_charset�szTestMIMEText.test_charsetcCs4|j}tddd�}||��jd�||dd�dS)NrPrHr�r;rI)r.rrArEr1r5r5r6�test_7bit_input�szTestMIMEText.test_7bit_inputcCs>|j}td�}||��d�||dd�|�d|���dS)NrPrHr;rI)r.rrAr�r�r1r5r5r6�test_7bit_input_no_charset�s
z'TestMIMEText.test_7bit_input_no_charsetcCsPd}|j}t|dd�}||��jd�||dd�||jdd�|�d��dS)N�кирилицаrNr�r;reTrP)r.rrA�output_charsetrRr�)r2�teststrr3r4r5r5r6�test_utf8_input�szTestMIMEText.test_utf8_inputzBcan't fix because of backward compat in email5, will fix in email6cCsd}|�tt|�dS)NrZ)r��UnicodeEncodeErrorr)r2r\r5r5r6�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
r�r�r�rrSrVrWrXrYr]�unittest�skipr_r5r5r5r6rN�s	
rNc@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�rv)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�rrrrrb�time�	localtime�timezone�altzone�strftimerQr<�_txt)r2r�rT�	containerr�Zintro�nowZ	timetupleZtzsecs�signZtzoffsetr5r5r6r�s@
��


��
zTestMultipart.setUpcCs�|j}|j}|j}|�|���||��d�|t|���d�|t|jd�|�d�}|�d�}|�	||j
�|�	||j�||��||g�|�|���|�|���dS)Nr`r�rru)
r.r�rQr�rUrCr�rR�
IndexErrorr3ror<rT)r2r3�raisesr�Zm0Zm1r5r5r6�test_hierarchy�s

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


--BOUNDARY


--BOUNDARY--
)rr�r�r�)r2r�r4r5r5r6�test_empty_multipart_idempotents
z-TestMultipart.test_empty_multipart_idempotentcCs@tdd�}d|d<d|d<d|d<|�d	�|�|��d
�dS)Nrcrd�	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��r2�outerr5r5r6�/test_no_parts_in_a_multipart_with_none_epilogues

z=TestMultipart.test_no_parts_in_a_multipart_with_none_epiloguecCsLtdd�}d|d<d|d<d|d<d	|_d	|_|�d
�|�|��d�dS)Nrcrdrwr�rxr�ryr�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�rzr5r5r6�0test_no_parts_in_a_multipart_with_empty_epilogue/s

z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguecCsV|j}tdd�}d|d<d|d<d|d<|�d	�td
�}|�|�||��d�dS)Nrcrdrwr�rxr�ryr�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�rrbr��r2r3r{r4r5r5r6�test_one_part_in_a_multipartDs


z*TestMultipart.test_one_part_in_a_multipartcC�\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nrcrdrwr�rxr�ryr�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}rrbr�r�r�r5r5r6�1test_seq_parts_in_a_multipart_with_empty_preamble]�


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamblecC�\|j}tdd�}d|d<d|d<d|d<d|_td	�}|�|�|�d
�||��d�dS�Nrcrdrwr�rxr�ryr�r�r}r�r�r�r5r5r6�0test_seq_parts_in_a_multipart_with_none_preambleyr�z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblecCr�r��r�rr~rrbr�r�r�r5r5r6�0test_seq_parts_in_a_multipart_with_none_epilogue�r�z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguecCr�)
Nrcrdrwr�rxr�ryr�r*r�r}r�r�r�r5r5r6�1test_seq_parts_in_a_multipart_with_empty_epilogue�r�z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epiloguecCr�)
Nrcrdrwr�rxr�ryr�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�r5r5r6�.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�ruzmultipart/alternativezmessage/external-bodyrr:)r.r/r�rRrC)r2r3r4�msg1rx�
subsubpartr5r5r6�test_message_external_body�s


�z(TestMultipart.test_message_external_bodycCs"|�d�}|�t|���d�dS)Nz
msg_37.txtr�)r/r.r�rRr]r5r5r6�test_double_boundary�s
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��r2r3r4r�r5r5r6�)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�r5r5r6�test_nested_with_same_boundarys

z,TestMultipart.test_nested_with_same_boundarycCr+)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]r5r5r6�test_boundary_in_non_multipartr�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�rUr~r�rRr1r5r5r6� test_boundary_with_leading_space,s


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

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

YXNkZg==
--===============0012394164==--rzYXNkZg==)rr�r.rRr�r5r5r6�&test_boundary_without_trailing_newline?sz4TestMultipart.test_boundary_without_trailing_newlinecCs tdd�}|�|jtjj�dS)Nrcrd)rr3r�r��compat32r�r5r5r6�test_mimebase_default_policyMr�z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|�|jtjj�dS)Nrcrdr�)rr�r��defaultr3r�r5r5r6�test_mimebase_custom_policyQ�z)TestMultipart.test_mimebase_custom_policyN)r�r�r�rrurvr|rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r5r5r5r6rb�s*$
rbc@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.txtr:r�r<)r.r/rCr0r>r1r5r5r6�test_parse_missing_minor_typeXs

z/TestNonConformant.test_parse_missing_minor_typecCsN|�d�}|�d�}|�t|d��|�t|j�d�|�|jdtj	�dS)N�
msg_15.txtrr_ru)
r/rRr��hasattrr.r�r_r^r�StartBoundaryNotFoundDefect)r2r4�innerr5r5r6�test_same_boundary_inner_outer`s

�z0TestNonConformant.test_same_boundary_inner_outercCsX|�d�}|�|��t�|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_25.txtr�rru)
r/r^rRr�r.r�r_r�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefectr]r5r5r6�test_multipart_no_boundaryj�
��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: base64rur)	�_str_msg�
multipart_msgrzr.r�r_r^rZ-InvalidMultipartContentTransferEncodingDefectr]r5r5r6�test_multipart_invalid_cte�s
��z,TestNonConformant.test_multipart_invalid_ctecCs(|�|j�d��}|�t|j�d�dS)Nr*r�r�r�rzr.r�r_r]r5r5r6�test_multipart_no_cte_no_defect�r�z1TestNonConformant.test_multipart_no_cte_no_defectcCs8dD]}|�|j�d�|���}|�t|j�d�qdS)N)r�rWZBINaryz
Content-Transfer-Encoding: {}rr�)r2r�r4r5r5r6�"test_multipart_valid_cte_no_defect�s���z4TestNonConformant.test_multipart_valid_cte_no_defectcCs�|j}|j}t�}d|d<||��d�||��d�||��d�|d=d|d<||��d�||��d�||��d�t�}t|�}|�|�||�	�d�dS)Nr�r?r<r:r;r�zContent-Type: foo

)
r.r�rr0r>rCrr
r�r�)r2r3�neqr4r�r�r5r5r6�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/rRr1r5r5r6�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�r1r5r5r6�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.txtr_r�rru)
r/r�r�r.r�r_r^rr�r�r]r5r5r6�test_lying_multipart�r�z&TestNonConformant.test_lying_multipartcCsD|�d�}|�d��d�}|�t|j�d�|�|jdtj�dS)Nz
msg_42.txtrur)r/rRr.r�r_r^rr�)r2r{Zbadr5r5r6�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��bodyrurz Line 1
)r.r�r�rVrRr�r_�assertDefectsEqualrZ#FirstHeaderLineIsContinuationDefect�linerr5r5r6�&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.rVrRr�r_rZ MissingHeaderBodySeparatorDefectr]r5r5r6�"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�r5r5r5r6r�Vs

	
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��r2r3r��dhr�r5r5r6�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�r8)s Pirard <pirard@dom.ain>NuAndré Pirard <pirard@dom.ain>�r.rr�rr�r5r5r6�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 foxr8)s jumped over the N)slazy dogr8z,The quick brown fox jumped over the lazy dogr�)r2r3r�r��hur5r5r6� test_whitespace_keeper_unicode_2 	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���r8)srgN���r8)ssbordN�rr.�r2r�r�r5r5r6�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�r5r5r6�test_rfc2047_with_whitespace0	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�r8r�)r2r�rT�q�ar�r5r5r6�test_rfc2047_B_bad_padding7	s�z&TestRFC2047.test_rfc2047_B_bad_paddingcCsd}|�t|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=)sandr�=zzr8�r.r�r2r�r5r5r6�test_rfc2047_Q_invalid_digitsA	s
�z)TestRFC2047.test_rfc2047_Q_invalid_digitscC�d}|�t|�gd��dS)Nz(=?ISO-8859-1?Q?a?=))��(N��ar8��)Nr�r�r5r5r6�test_rfc2047_rfc2047_1G	�
�z"TestRFC2047.test_rfc2047_rfc2047_1cCr�)Nz(=?ISO-8859-1?Q?a?= b))r�r�)s b)Nr�r�r5r5r6�test_rfc2047_rfc2047_2M	r�z"TestRFC2047.test_rfc2047_rfc2047_2cCr�)Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)�r�)sabr8r�r�r�r5r5r6�test_rfc2047_rfc2047_3S	r�z"TestRFC2047.test_rfc2047_rfc2047_3cCr�)Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r�r�r�r5r5r6�test_rfc2047_rfc2047_4Y	r�z"TestRFC2047.test_rfc2047_rfc2047_4cCr�)Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r5r5r6�test_rfc2047_rfc2047_5a_	r�z#TestRFC2047.test_rfc2047_rfc2047_5acCr�)Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�r�r�r5r5r6�test_rfc2047_rfc2047_5be	r�z#TestRFC2047.test_rfc2047_rfc2047_5bcCr�)Nz(=?ISO-8859-1?Q?a_b?=))r�)sa br8r�r�r�r5r5r6�test_rfc2047_rfc2047_6k	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 brdr�z(a b))r.rrr�r�r�r�r5r5r6�test_rfc2047_rfc2047_7q	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�r5r5r6�test_multiline_headerz	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�r5r5r5r6r�	s"		
	r�c@r�)"�TestMIMEMessagecCs<tddd��}|��|_Wd�dS1swYdS)N�
msg_11.txtrNr�)r%r�Z_textr r5r5r6r�	s"�zTestMIMEMessage.setUpcCs|�ttd�dS)Nza plain string)r�rarr
r5r5r6�test_type_error�	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||��d�|��}|�|t�|t|�d�|d}|�||�||d|�dS)Nz
A sub-messager�r!rur�subject)	r.rrrCrRr^�listr�r3)r2r3r�r��rr)rxr5r5r6�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�MultipartConversionErrorrb)r2r�rGr�r5r5r6�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.
)rrKrrr
r�r.r�)r2r�r�r�r�r5r5r6�
test_generate�	s

zTestMIMEMessage.test_generatecCst|j}|�d�}||��d�|��}|�|t�|t|�d�|d}|�|t�||dd�||��d�dS)Nr�r!rurr�r�r�)r.r/rCrRr^r�r�r)r2r3r4r)Zsubmsgr5r5r6�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�rr:a�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

ruzmessage/delivery-statusr�zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnsz
reporting-mtar�r*Znsd�actionZfailedzoriginal-recipient)r@r*)zjangel1@cougar.noc.ucla.edur*r@zfinal-recipientr!�
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r.r/rCr�rUr�rRr^rrDr�r�)r2r3r4rxZdsn1Zdsn2r)r�r5r5r6�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.txtrNr�rxr�ryr�r�r��MIME messagezEnd of MIME message
rNrPr?r`r}re)
r�r%r�rr}r~rrrbrr
r�r�)	r2r3r�r�r4r�rGr�r�r5r5r6�
test_epilogue�	s&
�


zTestMIMEMessage.test_epiloguecCsv|j}t�}d|d<d|d<d|d<d|_d|_td	�}td
�}|jddd
d�|�|�|�|�||��d�dS)Nrxr�ryr�r�r�rr*rNrPr?r`r}readFrom: 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~rrrbr�)r2r3r4r�rGr5r5r6�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)Nr%rNr�rr!rur:�r.r%r��message_from_filerR�get_default_typerC�r2r3r�r4Z
container1Z
container2Zcontainer1aZcontainer2ar5r5r6�test_default_type4
� �



z!TestMIMEMessage.test_default_typecCr)Nr)rNr�rr!rur:rrr5r5r6�.test_default_type_with_explicit_container_typeE
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)N�digestr}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;r9aBContent-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~rrrbrCrr�)r2r3r�rpZ	subpart1aZ	subpart2aZsubpart1Zsubpart2r5r5r6�test_default_type_non_parsedV
s0


z,TestMIMEMessage.test_default_type_non_parsedcCsZ|j}td�}td�}t||fd�}|t|���d�||�d�|�||�d�|�dS)Nr*)Z	_subpartsr�rru)r.rrr�rR)r2r3Ztext1Ztext2r4r5r5r6�$test_mime_attachments_in_constructor�
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|�|���dSr[)rr�rUr]r5r5r6�"test_default_multipart_constructor�
sz2TestMIMEMessage.test_default_multipart_constructorcCs0t�}d|d<d|d<|�|�d�ddg�dS)N�a@b.comr��c@d.comr�)rr.r0r]r5r5r6�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�rr.r��	exception)r2r4�cmr5r5r6�test_multipart_custom_policy�
s
��z,TestMIMEMessage.test_multipart_custom_policyN)r�r�r�rr�r�r�r�r�r�rrr	rrrrrrr5r5r5r6r��	s"9#J	r�c@seZdZdd�Zdd�ZdS)�TestNonMultipartcCstdd�}|�|���dS)Nr�r<)rrTrUr]r5r5r6�"test_nonmultipart_is_not_multipart�
s
z3TestNonMultipart.test_nonmultipart_is_not_multipartcCs.t�}d|d<tdd�}|�tj|j|�dS)Nr�r�r�r<)rrr�rr�rb)r2r4r�r5r5r6�test_attach_raises_exception�
s
z-TestNonMultipart.test_attach_raises_exceptionN)r�r�r�rrr5r5r5r6r�
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�NrNr��r%r�r�r��r2rr�rTr4r5r5r6r/�
s

�
zTestIdempotent._msgobjFcCs8|j}t�}t|dd�}|j||d�|||���dS)Nrr�r�)r�rr
r�r�)r2r4r�r�r3r�r�r5r5r6�_idempotent�
s
zTestIdempotent._idempotentcCs�|j}|�d�\}}||��d�||��d�||��d�||��dd�||�d�d�||jd�||jd�|�	||�dS)	Nr�r:r�r<ru)r<rHr<rH)
r.r/rCr0r>r�rDr}r~r�r2r3r4r�r5r5r6�test_parse_text_message�
sz&TestIdempotent.test_parse_text_messagecCsP|j}|�d�\}}||��d�||��d�||�d�d�|�||�dS)Nr�r:r<)r.r/rCr�rDrr r5r5r6�test_parse_untyped_message�
sz)TestIdempotent.test_parse_untyped_messagecC�|�d�\}}|�||�dS)Nrj�r/r�r2r4r�r5r5r6�test_simple_multipart�
�z$TestIdempotent.test_simple_multipartcCr#)N�
msg_02.txtr$r%r5r5r6�test_MIME_digest�
r'zTestIdempotent.test_MIME_digestcCr#)Nz
msg_27.txtr$r%r5r5r6�test_long_header�
r'zTestIdempotent.test_long_headercCr#)Nr)r$r%r5r5r6�"test_MIME_digest_with_part_headers�
r'z1TestIdempotent.test_MIME_digest_with_part_headerscCr#)N�
msg_06.txtr$r%r5r5r6�test_mixed_with_imager'z$TestIdempotent.test_mixed_with_imagecCr#)Nrr$r%r5r5r6�test_multipart_reportr'z$TestIdempotent.test_multipart_reportcCr#)Nr�r$r%r5r5r6r�r'zTestIdempotent.test_dsncCr#)Nrr$r%r5r5r6�test_preamble_epiloguer'z%TestIdempotent.test_preamble_epiloguecCr#)Nz
msg_23.txtr$r%r5r5r6�test_multipart_one_partr'z&TestIdempotent.test_multipart_one_partcCr#)Nz
msg_24.txtr$r%r5r5r6�test_multipart_no_partsr'z&TestIdempotent.test_multipart_no_partscCr#)Nr�r$r%r5r5r6r�r'z%TestIdempotent.test_no_start_boundarycCr#)N�
msg_32.txtr$r%r5r5r6�test_rfc2231_charsetr'z#TestIdempotent.test_rfc2231_charsetcCr#)Nz
msg_33.txtr$r%r5r5r6�test_more_rfc2231_parameters#r'z+TestIdempotent.test_more_rfc2231_parameterscCr#)Nz
msg_34.txtr$r%r5r5r6�%test_text_plain_in_a_multipart_digest'r'z4TestIdempotent.test_text_plain_in_a_multipart_digestcCr#)Nzmsg_12a.txtr$r%r5r5r6�test_nested_multipart_mixeds+r'z+TestIdempotent.test_nested_multipart_mixedscCr#)Nr�r$r%r5r5r6�%test_message_external_body_idempotent/r'z4TestIdempotent.test_message_external_body_idempotentcCs"|�d�\}}|j||dd�dS)N�
msg_43.txtTr�r$r%r5r5r6�test_message_delivery_status3sz+TestIdempotent.test_message_delivery_statuscCr#�N�
msg_45.txtr$r%r5r5r6�test_message_signed_idempotent7r'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�r
z$This is a MIME-encapsulated message.r�rr:zYadda yadda yaddarur�r!)r.r/rCr�r}r�r~r�rRr^rr�)r2r3r4r��paramsZpkZpvr�rGZmsg3r)Zmsg4r5r5r6�test_content_type;s4



z TestIdempotent.test_content_typecCs�|j}|�d�\}}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�|�|��t�||��|j	�dS)Nr,r!rurr:)
r.r/rCrRr^r�r�rr�r�)r2r3r4r�r)r�r5r5r6�test_parserZszTestIdempotent.test_parserN�F)r�r�r�r�r/rr!r"r&r)r*r+r-r.r�r/r0r1r�r3r4r5r6r7r9r<r>r?r5r5r5r6r�
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�Z8dmS)n�TestMiscellaneouscCsntddd��}|��}Wd�n1swYt�|�}t�}t|dd�}|�|�|�||���dS�Nr�rNr�rr��	r%r�r�r�rr
r�r.r��r2r�r�r4r�r�r5r5r6�test_message_from_stringns
�

z*TestMiscellaneous.test_message_from_stringcCsztddd��-}|��}|�d�t�|�}t�}t|dd�}|�|�|�||�	��Wd�dS1s6wYdSrB)
r%r��seekr�rrr
r�r.r�rDr5r5r6�test_message_from_fileys


"�z(TestMiscellaneous.test_message_from_filecCs�tddd��}|��}Wd�n1swYGdd�dt�}t�||�}|�||�tddd��}|��}Wd�n1sCwYt�||�}|��D]}|�||�qRdS)Nr�rNr�c@�eZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN�r�r�r�r5r5r5r6�	MyMessage��rJr()r%r�rr�r�r^�walk)r2r�r�rJr4rxr5r5r6�#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>.MyMessageNrIr5r5r5r6rJ�rKrJr�rNr�r()rr%r�rr^rL)r2rJr�r4rxr5r5r6�!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���dSr[)�super�__init__r
��	__class__r5r6rP�rRz\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)r�r�r�rP�
__classcell__r5r5rQr6rJ�srJzSubject: test

test)rr�r^)r2rJr4r5r5r6�.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 r3Zmessage_from_binary_filer�rr�r�r�r!r")�
__import__r.�sorted�__all__)r2�moduler5r5r6�test__all__�szTestMiscellaneous.test__all__cCs:t��}|�t�t�|��dd�t�|�dd��dS)N�)rjr.r"�	parsedate�
formatdate�gmtime�r2rqr5r5r6�test_formatdate�s�z!TestMiscellaneous.test_formatdatecCs>t��}|�t�tj|dd��dd�t�|�dd��dS)NT�rkr[)rjr.r"r\r]rkr_r5r5r6�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)rkZusegmtz%a, %d %b %Y %H:%M:%S GMT)rjr.r"r]rnr^r_r5r5r6�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)�subTestr\r"r\�parsedate_tz)r2Z
invalid_datesrer5r5r6�/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���:�rrurf�pzWed,3 Apr 2002 14:58:26 +0800zWed 3 Apr 2002 14:58:26 +0800�r.r"rgr
r5r5r6�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���
�/rnrrurf透��zFebruary 5, 2003 13:47:26 -0800rp�r2r3r5r5r6�test_parsedate_no_dayofweek��
�
�z-TestMiscellaneous.test_parsedate_no_dayofweekcC�|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26+0800rjrpr
r5r5r6�.test_parsedate_no_space_before_positive_offset���z@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCr|)NzWed, 3 Apr 2002 14:58:26-0800)
rkr�r�rlrmrnrrurfrxrpr
r5r5r6�.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 -0800rsz5 Feb 2003 13.47 -0800)
rtr�rurvrwrrrurfrxrpryr5r5r6�%test_parsedate_accepts_time_with_dots�r{z7TestMiscellaneous.test_parsedate_accepts_time_with_dotscCr|)NzFriday, 19-Nov-82 16:14:55 EST)
i����rl�7rrurfi����rpr
r5r5r6�test_parsedate_rfc_850r~z(TestMiscellaneous.test_parsedate_rfc_850cCr|)NzWed, 3 Apr 2002 14:58 +0800�
rkr�r�rlrmrrrurfrorpr
r5r5r6�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 +0800rjzWed, 3 Apr 2002 14.58 +0800r�rpr
r5r5r6�!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)Nrrr[z%Yrt�	)	r.r"r\�intrj�mktimerkrnrg)r2r3Ztimetuprr5r5r6�+test_parsedate_acceptable_to_time_functionss
 
 "z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCr�)N)
�rururrrrfrfrfrr)
r�rururrrrfrfrfi�i.���)r.r"Z	mktime_tzr
r5r5r6�test_mktime_tz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 -0800Nrpr
r5r5r6�test_parsedate_y2k s��z$TestMiscellaneous.test_parsedate_y2kcCs.|�t�d�d�|�t�t�d��d�dS)Nz<>�r*r*r*�r.r"�	parseaddr�
formataddrr
r5r5r6�test_parseaddr_empty-sz&TestMiscellaneous.test_parseaddr_emptycCri)Nza@b@cr�za@b.c@cza@172.17.0.1@c�r.r"r�r
r5r5r6�test_parseaddr_multiple_domains1s���z1TestMiscellaneous.test_parseaddr_multiple_domainscCr|)N)zA Silly Person�person@dom.ainzA Silly Person <person@dom.ain>�r.r"r�r
r5r5r6�test_noquote_dump?��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��r2r�rr5r5r6�test_escape_dumpD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�r5r5r6�test_escape_backslashesO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>r8r�)r2r��addr�utf8_base64Z
latin1_quoprir5r5r6�test_quotes_unicode_namesW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�Sr[r5)r2�string�rr5r6�
header_encodehszYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)r�r�r�r�r5r�r5r6�CharsetMockgsr�z%s <%s>rN)r.r"r�r	)r2r�r�r�r�ZmockZ
mock_expectedr5r�r6�$test_accepts_any_charset_like_objectas�z6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|�ttj||f|�dS)Nr�r�)�objectr��AttributeErrorr"r�)r2r�r�Zbad_charsetr5r5r6�-test_invalid_charset_like_object_raises_errorps�z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|�ttjd|f�|�ttjd|f�dS)Nupersön@dom.in�Name)r��UnicodeErrorr"r�)r2r�r5r5r6�!test_unicode_address_raises_errory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�)r2rb�yr�rr5r5r6�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�ryr5r5r6�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�r
r5r5r6�-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�)r2r�Zaddrstrr5r5r6�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�)r2rbr5r5r6�test_multiline_from_comment�sz-TestMiscellaneous.test_multiline_from_commentcCr|)N)zA Silly; Personr�z""A Silly; Person" <person@dom.ain>r�r
r5r5r6�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)NrH�US-ASCIIzUs-AsCiIZusasciiZUSASCIIZUsAsCiI)r.ZassertNotEqualr	)r2r3�neZcset1Zcset2r5r5r6�test_charset_richcomparisons�s$












z.TestMiscellaneous.test_charset_richcomparisonscCs"|j}|t�ddg�ddg�dS)Nzaperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>)z	Al Personrx)z
Bud Personry�r.r"�getaddressesryr5r5r6�test_getaddresses�s���z#TestMiscellaneous.test_getaddressescCsL|j}|t�dg�dg�|t�dg�gd��|t�ddg�ddg�dS)Nzfoo: ;r�z	[]*-- =~$)r�r�)r*z*--z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerz
jason@dom.ainr�ryr5r5r6�test_getaddresses_nasty�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>rru�foo@bar.comNr�)r2r3�addrsr5r5r6�"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>rrurxN)r"r�r
r.)r2r�r5r5r6�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_msgidrj�	monotonic)r2r�r�ZclockZtfinr5r5r6�run�s

�zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)r�r�r�r�r5r5r5r6�MsgidsThread�sr�csg|]}���qSr5r5r��r�r5r6rq��z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>rucSsg|]}|j�qSr5)r�)rorr5r5r6rq
r�)rr�r#Z
start_threads�sumr.r��set)r2�threadsZall_idsr5r�r6�test_make_msgid_collisions�s�z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||��d�dS)Nrrzfoo\wacky"namer)r.rrrmr1r5r5r6�test_utils_quote_unquote
s�z*TestMiscellaneous.test_utils_quote_unquotecCstd�}|�|��d�dS)Nz
not a charsetrO�r	r.�get_body_encoding�r2r<r5r5r6�)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;rurrNrOr�r�aGVsbG8gd29ybGQ=
TrPr=ztext/plain; charset="US-ASCII"rHr�r�)
r.rrgr�r	r�rKrRrrE)r2r3r4rhr<r5r5r6�-test_get_body_encoding_with_uppercase_charset
s.z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs(td�}td�}|�|��|���dS)NrHr�r�)r2ZlcZucr5r5r6�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�r5r5r6�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�r
r5r5r6�test_make_msgid_domainW
s�z(TestMiscellaneous.test_make_msgid_domaincCs$|�tjjddd�dd�d�dS)Nz
test-idstringr�)Zidstringr�i���z!.test-idstring@testdomain-string>r�r
r5r5r6�test_make_msgid_idstring\
s���z*TestMiscellaneous.test_make_msgid_idstringcCsVtd��}d|_}|�tj���d|d��Wd�dS1s$wYdS)Nzsocket.getfqdnzpythontest.example.com�@�>)rZreturn_valuer�r�r"r��endswith)r2Zmock_getfqdnr�r5r5r6�test_make_msgid_default_domainb
s



��"�z0TestMiscellaneous.test_make_msgid_default_domaincCs|tdddd��}|��}Wd�n1swY|�dd�}t�|�}t�}tj�|�}|�|�|�	|�
�|�dS)N�
msg_26.txtrNr)�r��newliner�)r%r�r�r�r�rr�r
r�r.r��r2�fZmsgtxtZ	msgtxt_nlr4r�r�r5r5r6�test_Generator_linendi
s
�

z'TestMiscellaneous.test_Generator_linendcCs�tdddd��}|��}Wd�n1swY|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
��d�|�dS)Nr�rNr)r�r�r�r�)r%r�r�r�r�rr�rr�r.r�rQr�r5r5r6�test_BytesGenerator_linendt
s
�
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�r�r5r5r6�)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)
Nrr�r�)r*)rcrdr�)�clsr�r�r�)r%r�rrrrrrrrfr�r3r�r�r�r�)r2r�Z	audiodatar�Zclassesr��constructorr�r5r5r6�!test_mime_classes_policy_argument�
s0
�
�
�����z3TestMiscellaneous.test_mime_classes_policy_argumentN)9r�r�r�rErGrMrNrTrZr`rbrcrhrqrzr}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r5r5r5r6rAmsn




			
*rAc@r)�
TestIteratorscCs�|j}|j}|�d�}t�|�}t|�}|t|�d�|t�|�|�	��|�d�}t�|�}t|�}|t|�d�t
ddd��}|t�|�|���Wd�dS1sVwYdS)Nr�r[r(�+z
msg_19.txtrNr�)r.r�r/r Zbody_line_iteratorr�r��EMPTYSTRINGr�rRr%r�)r2r3r�r4�itr�r�r5r5r6�test_body_line_iterator�
s



"�z%TestIterators.test_body_line_iteratorcCsb|j}|�d�}t�|d�}g}d}|D]
}|d7}|�|���q||d�|t�|�d�dS)Nrjr�rrur�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�rRr�r��r2r3r4r�r�Zsubpartsrxr5r5r6�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�r<rruz%
Hi,

Do you like this message?

-Me
r�r�r5r5r6�(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
ru)r*r)zd
ru)ze
r)z
fru)r�rur��BufferedSubFile�NeedMoreDatarur*cS�g|]\}}|�qSr5r5)ro�il�nr5r5r6rq�
rrz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
�email.feedparserrr�push�iter�readliner�r.r�r�)r2Zimtrr�bsfZom�ntrrZn1Zolr5r5r6�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'ruzabcd 	
r*c3s�|]}t��VqdSr[rr���charsr5r6r��
r�z1TestIterators.test_push_random.<locals>.<genexpr>r)T)rrrr�r�r�r�r�extendrr	r.)r2rrr�	chunksizer��targetr
r�r��chunkr5r
r6�test_push_random�
s 

zTestIterators.test_push_randomN)r�r�r�r�r�r�rrr5r5r5r6r��
sr�c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs"t�}|D]}|�|�q|��Sr[)r'�feed�close)r2�chunksrUrr5r5r6�parseszTestFeedParsers.parsecCs.|�d�}|�|dd�|�|dd�dS)NzFirst: val
: bad
Second: valrM�valrO)rr.r]r5r5r6�test_empty_header_name_handleds
z.TestFeedParsers.test_empty_header_name_handledcCs�|�dg�}|�|��gd��|�dg�}|�|��gd��|�ddg�}|�|��ddg�|�dd	g�}|�|��dd
g�|�ddg�}|�|��dd
g�|�dg�}|�|��d
g�|�gd��}|�|��ddg�dS)Nz
a:
b:
c:
d:
)r�r�c�dza:
b:
c:
d:za:
b�c:
r�Zbc�a:
zb:
rz
b:
ua:…b:
c:
)r�u	…b:
c:)rub:…r�r�r*)ru…c:)rr.rVr�r�r5r5r6�
test_newliness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

rb)r�rza:b

�…rzb: r r)rr.r�rR)r2�M�Nr�r5r5r6�test_long_lines)s$zTestFeedParsers.test_long_linesN)r�r�r�rrr!r%r5r5r5r6r	s
rc@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(rNr�r��ppp-request@zzz.orgr��ppp@zzz.orgr`)
r.r%rrrCrTrUr^rRr��r2r3r�r4r5r5r6�test_header_parser;s�zTestParsers.test_header_parsercCs�|j}tdd��}tj���|�}Wd�n1swY||dd�||dd�||��d�|�|���|�	|�
�t�|�	|j
dd	�t�dS)
Nr(r�r�r'r�r(r`TrP)
r.r%r�r�r�rrCrTrUr^rRr�r�r)r5r5r6�test_bytes_header_parserFs�z$TestParsers.test_bytes_header_parsercCsLtdd��}tj���|�|�|j�Wd�dS1swYdS)Nr(r�)r%r�r��BytesParserrrT�closedr r5r5r6�%test_bytes_parser_does_not_close_fileRs"�z1TestParsers.test_bytes_parser_does_not_close_filecCsbtdd��"}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�dS1s*wYdS)Nr�r�r�)r%r�r�r,r�rr�r��strictrrTr-)r2r�ZbytesParserr5r5r6�2test_bytes_parser_on_exception_does_not_close_fileWs
�"�z>TestParsers.test_bytes_parser_on_exception_does_not_close_filecCsNtddd��}tj���|�|�|j�Wd�dS1s wYdS)Nr(rNr�)r%r�r�rrrTr-r r5r5r6�test_parser_does_not_close_file_s"�z+TestParsers.test_parser_does_not_close_filecCsdtddd��"}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�dS1s+wYdS)Nr�rNr�r�)r%r�r�rr�rr�r�r/rrTr-)r2r�r�r5r5r6�,test_parser_on_exception_does_not_close_fileds
�"�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�rRr1r5r5r6�test_whitespace_continuationk�


z(TestParsers.test_whitespace_continuationcCr3)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�r4r�r5r6r7r1r5r5r6�(test_whitespace_continuation_last_header}r9z4TestParsers.test_whitespace_continuation_last_headercCs�|j}tdddd��}t��|�}Wd�n1swY|t|���d�|�d�}||��d�||��d�|�d	�}||��d
�dS)Nr�rNr)r�r�rr:z!Simple email with attachment.

ruzapplication/riscos)r.r%rrr�rRrC)r2r3r�r4�part1�part2r5r5r6�test_crlf_separation�s�

z TestParsers.test_crlf_separationcCsptdddd��}|��}Wd�n1swYt�|�}t�}t|�}|j|dd�|�|��|�dS)Nr�rNr)r�r�r�rCrDr5r5r6�test_crlf_flatten�s
�
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)Nr)rNr�rur�rr!r:r
r)	r.r�r%r�rrUr�rRrC)	r2r3r�r�r4r;Zpart1ar<Zpart2ar5r5r6�-test_multipart_digest_with_extra_mime_headers�s.�



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.)r2r�r4r5r5r6�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)r2r3Zvalue1Zvalue2r�r4r5r5r6�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��|]}|VqdSr[r5)roZfieldr5r5r6r����z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>)z!"#QUX;~z>Fromr�r�)r.r�r�r�rWrRrr5r5r6�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�r�rVrr5r5r6�(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�rV�sortrR)r2r3r�r4Zheadersr5r5r6�!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�rRr��r2r�r4r5r5r6�test_CRLFLF_at_end_of_part�s�

z&TestParsers.test_CRLFLF_at_end_of_part)r�r�r�r*r+r.r0r1r2r8r:r=r>rr?rArCrFrGrKrMr5r5r5r6r&9s&
	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)NrNrW�pöstal�r<r�Zbodyline�pöstal
TrP��bodytest_msgrzr�r�r�r.rRrLr5r5r6�test_known_8bit_CTE���
�z)Test8BitBytesHandling.test_known_8bit_CTEcC�P|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
NZnotavalidcharsetrWrOrPrNup��stal
TrPrQrRrLr5r5r6�test_unknown_8bit_CTErUz+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)	NrNr>�p=C3=B6stálrPu
p=C3=B6stál
TrP�	pöstál
rRrLr5r5r6�test_8bit_in_quopri_body(s
��
�z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCrV)
Nr�r>rXrPrNup=C3=B6st��l
TrPrYrRrLr5r5r6�.test_invalid_8bit_in_non_8bit_cte_uses_replace:s��
�zDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replacecCsT|jjdddd��d�}t�|�}|�|jdd�d�d��|�|jdt	j
�dS)	NrNrOu
cMO2c3RhbAá=rPTrPrOr)rSrzr�r�r�r.rRr^r_rr`rLr5r5r6�test_8bit_in_base64_bodyJs��
��z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd��d�}t�|�}|�|jdd�d�d��dS)NrNr�u
<,.V<W1A; á rPTrPu<,.V<W1A; á 
rRrLr5r5r6�test_8bit_in_uuencode_bodyWs��
�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)cCrr5r5)ro�src�_r5r5r6rqlrrz Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
rNcCs:t�|j�}|�t|�d��d�|�t|d�d�dS)Nr��b��z)r�r��headertest_msgr.r�rBr]r5r5r6�test_get_8bit_headeros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)rur5)ror`r�r5r5r6rq~szATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	r�r�rbr.r�r�r�rz�headertest_headersr]r5r5r6�test_print_8bit_headersts
���z-Test8BitBytesHandling.test_print_8bit_headerscC�.t�|j�}|�dd�|��D�gd��dS)NcSr�r5�r�r�r5r5r6rq�rrzGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>)r�ra�]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie�	g��st)r�r�rb�assertListEqualrWr]r5r5r6�test_values_with_8bit_headers���z3Test8BitBytesHandling.test_values_with_8bit_headerscCrf)NcSs g|]\}}t|�t|�f�qSr5rg)rorbr�r5r5r6rq�s zFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>)r^)r�ra)r�rh)r�ri)r�r�rbrjr�r]r5r5r6�test_items_with_8bit_headers�rlz2Test8BitBytesHandling.test_items_with_8bit_headerscCs0t�|j�}|�dd�|�d�D�ddg�dS)NcSr�r5rgr�r5r5r6rq�rrzHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�r�ri)r�r�rbrjr0r]r5r5r6�test_get_all_with_8bit_headers�s��z4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsJt�t�d��d��}|�|��d�|�|��d�|�|��d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            rrutext/pl�inr�upl�in)	r�r�r�r�r�r.rCr0r>r]r5r5r6�test_get_content_type_with_8bit�s�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
rrr�r�))r���ne)ub�rr�r�ZFoorpub§r)r�r�r�r.r�rDr]r5r5r6�test_get_params_with_8bit�s��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§nrr�title)rH�enuThis is not f�n)r�r�r�r�r�r.rDr]r5r5r6�!test_get_rfc2231_params_with_8bit�s��z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8t�t�d��d��}|�dd�|�|�d�d�dS)Nrrrrrs�test)r�r�r�r�r�rr.rDr]r5r5r6�!test_set_rfc2231_params_with_8bit�s
�z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFt�t�d��d��}|�d�|�|�d�d�|�|��d�dS)Nrrrrrsr�)	r�r�r�r�r�rr.rDr0r]r5r5r6�!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
            rrzpayload
TrPspayload
)r�r�r�r�r�r.rRr]r5r5r6�%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�dSr[)	r�r��non_latin_bin_msgrr�rr�r.r��r2r4r�r5r5r6�test_bytes_generator��z*Test8BitBytesHandling.test_bytes_generatorcCs6tj��}t�}tj�|��|�|�|��d�dS)Nr�)	r�r3rrr�rr�r.r�r{r5r5r6�&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	�dSr[)
r�r�rzrr�r
r�r.r�� non_latin_bin_msg_as7bit_wrappedr{r5r5r6�test_generator_handles_8bit�r}z1Test8BitBytesHandling.test_generator_handles_8bitcCs`t�|j�}t�}t|��|�|��}tt���|�t�}t|��|�|�	|��|�dSr[)
r�r�rzrrr�r�r
rr.)r2r4r�Z
orig_valuer5r5r6�;test_str_generator_should_not_mutate_msg_when_handling_8bits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�rsFromru)r�r�rzrr�rr�r�r�r.r�)r2r4r�r�r5r5r6�#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�writerzr�r�r,rr.r��non_latin_bin_msg_as7bit)r2r�Ztestfiler�r5r5r6�test_message_from_binary_files��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?
        rra         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�dSr[)r�r��
latin_bin_msgr.r��latin_bin_msg_as7bitr�r5r5r6�:test_string_generator_reencodes_to_quopri_when_appropriate:szPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriatecCsDt�|j�}t�}tj�|��|�|�|��|j�	d�d�dS)Nrrr))
r�r�r�rr�rr�r.r�rQ)r2r�r�r5r5r6�)test_decoded_generator_emits_unicode_body>s
�z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCsXtj��}tdt|j�d�D]}|�|j||d��q|��}|�t	|�|j
�dS)Nrr�)r�rUr(r�r�r�rrr.r�r�)r2Zbfpr�r�r5r5r6�test_bytes_feedparserHs

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�rDr5r5r6r>Os
�
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--

            rN)r�r�r�r�r�rr�rr�r.r�)r2r�r4r�r�r5r5r6�test_8bit_multipartXs%�
&
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��r2r�r�r�r5r5r6�'test_bytes_generator_b_encoding_linesep���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�r5r5r6�!test_generator_b_encoding_linesep�r�z7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/r�r�r�r�r�rSrTrWrZr[r\r]rdr�r�rbrcrerkrmrnrorqrurwrxryrzr|r~rr�r�r�r�r�r�r�r�r�r�r�r>r�r�r�rr5r5r5r6rNsf
	
		

��
	
	

�



�
		�

	.rNc@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNcCsTt|d��}|��}Wd�n1swY|j�|j|�}t�|�}||fS)Nr�)r%r��normalize_linesep_regex�sub�blinesepr�r�rr5r5r6r/�s
�
z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|�||���dS)Nrr�)r�r�)rr�r�rr�r�r.r�)r2r4rTr�rr�r5r5r6r�sz,BaseTestBytesGeneratorIdempotent._idempotentr@)r�r�r�rr/rr5r5r5r6r��sr�c@�eZdZdZdZe�d�ZdS)�TestBytesGeneratorIdempotentNLr)r�s\r\nN�r�r�r�r�r��re�compiler�r5r5r5r6r���r�c@r�)� TestBytesGeneratorIdempotentCRLFr�r�s	(?<!\r)\nNr�r5r5r5r6r��r�r�c@r)
�
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��rb)r.r�
header_lengthr��body_encoder�)r2r3�sizeZbsizer5r5r6�test_len�s
��zTestBase64.test_lencCr�)Nr*�zaGVsbG8=r�)r.rrQryr5r5r6�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�ryr5r5r6�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=?=rdrz=?iso-8859-2?b?aGVsbG8=?=)r.rr�)r2r3�her5r5r6�test_header_encode�szTestBase64.test_header_encodeN)r�r�r�r�r�r�r�r5r5r5r6r��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��_t�j�t�j�d
ksDJ�tttd�td�d���_�j�td���j�	td���fdd�td
�D��_
t�j�t�j
�d
ks|J�dS)Nr��zrurH�Zrd�9csrDr[r5�rorr5r5r6r��rEz#TestQuopri.setUp.<locals>.<genexpr>s!*+-/c�g|]	}|�jvr|�qSr5)�hlitr�r
r5r6rq�z$TestQuopri.setUp.<locals>.<listcomp>�r+�~r��=cr�r5)�blitr�r
r5r6rq	r�)r�rr��ordr��hnonr�r�r��remove�bnonr
r5r
r6r�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�rTr!Zheader_check�chrr�r��r2rr5r5r6�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�rTr!Z
body_checkr�r�r�r�r5r5r6�test_quopri_body_checkr�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�ruZxxxrr�s
h@e@l@l@o@r�ruzexpected length 1 for %rr+r�zexpected length 3 for %r� )
r.r!r�r�r�r�r�r�r�r��r2r3rr5r5r6�test_header_quopri_lens0����

�

�z!TestQuopri.test_header_quopri_lencCsN|j}|jD]
}|t�t|g��d�q|jD]
}|t�t|g��d�qdS)Nrur�)r.r�r!Zbody_lengthr�r�r�r5r5r6�test_body_quopri_len5s

�zTestQuopri.test_body_quopri_lencCs2td�D]}t|�}|�t�t�|��|�qdS)Nr�)r�r�r.r!r��quote)r2rbrr5r5r6�test_quote_unquote_idempotent<s�z(TestQuopri.test_quote_unquote_idempotentNcCs0|dur
t�|�}nt�||�}|�||�dSr[)r!r�r.)r2r�Zexpected_encoded_headerr<�encoded_headerr5r5r6�_test_header_encodeAszTestQuopri._test_header_encodecC�|�dd�dS)Nr�r*�r�r
r5r5r6�test_header_encode_nullH�z"TestQuopri.test_header_encode_nullcCr�)Nr�z=?iso-8859-1?q?hello?=r�r
r5r5r6�test_header_encode_one_wordKr�z&TestQuopri.test_header_encode_one_wordcCr�)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=r�r
r5r5r6�test_header_encode_two_linesN��z'TestQuopri.test_header_encode_two_linescCr�)Nshello�therez=?iso-8859-1?q?hello=C7there?=r�r
r5r5r6�test_header_encode_non_asciiRr�z'TestQuopri.test_header_encode_non_asciicC�|jdddd�dS)Nr�z=?iso-8859-2?q?hello?=rdrr�r
r5r5r6�test_header_encode_alt_charsetVs
�z)TestQuopri.test_header_encode_alt_charsetcCst�|�}|�||�dSr[)r!�
header_decoder.)r2r�Zexpected_decoded_headerZdecoded_headerr5r5r6�_test_header_decodeZs
zTestQuopri._test_header_decodecC�|�dd�dS�Nr*�r�r
r5r5r6�test_header_decode_null^r�z"TestQuopri.test_header_decode_nullcCr��Nr�r�r
r5r5r6�test_header_decode_one_wordar�z&TestQuopri.test_header_decode_one_wordcCr�)Nz
hello=0Aworldr�r�r
r5r5r6�test_header_decode_two_linesdr�z'TestQuopri.test_header_decode_two_linescCr�)Nz
hello=C7thereuhelloÇtherer�r
r5r5r6�test_header_decode_non_asciigr�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�r
r5r5r6�test_header_decode_re_bug_18380jsz*TestQuopri.test_header_decode_re_bug_18380cCs2|dur
t�|�}ntj||d�}|�||�dS)Nr�)r!rQr.)r2�encodedZexpected_decodedr��decodedr5r5r6�_test_decodenszTestQuopri._test_decodecCr�r��r�r
r5r5r6�test_decode_null_wordur�z TestQuopri.test_decode_null_wordcCr�)Nr�r)r�r
r5r5r6�test_decode_null_line_null_wordxr�z*TestQuopri.test_decode_null_line_null_wordcCr�r�r�r
r5r5r6�test_decode_one_word{r�zTestQuopri.test_decode_one_wordcCs|jdddd�dS)Nr��Xr�r�r
r5r5r6�test_decode_one_word_eol~�z#TestQuopri.test_decode_one_word_eolcCr��N�hello
�hello
r�r
r5r5r6�test_decode_one_line�r�zTestQuopri.test_decode_one_linecCr��Nr�r�r
r5r5r6�test_decode_one_line_lf�r�z"TestQuopri.test_decode_one_line_lfcCr�)Nzhello
r�r�r
r5r5r6�test_decode_one_line_cr�r�z"TestQuopri.test_decode_one_line_crcCr�)Nr��helloXr�r�r�r
r5r5r6�test_decode_one_line_nl�r�z"TestQuopri.test_decode_one_line_nlcCr�)Nr�r�r�r�r�r
r5r5r6�test_decode_one_line_crnl�r�z$TestQuopri.test_decode_one_line_crnlcCr�)Nr�r�r�r
r5r5r6�test_decode_one_line_one_word�r�z(TestQuopri.test_decode_one_line_one_wordcCr�)Nr�ZhelloXworldr�r�r�r
r5r5r6�!test_decode_one_line_one_word_eol�r�z,TestQuopri.test_decode_one_line_one_word_eolcCr�)N�hello
world
�hello
world
r�r
r5r5r6�test_decode_two_lines�r�z TestQuopri.test_decode_two_linescCr�)Nr�ZhelloXworldXr�r�r�r
r5r5r6�test_decode_two_lines_eol�r�z$TestQuopri.test_decode_two_lines_eolcCr�)NA�SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamr�r
r5r5r6�test_decode_one_long_line�r�z$TestQuopri.test_decode_one_long_linecCr�)Nr+r*r�r
r5r5r6�test_decode_one_space�r�z TestQuopri.test_decode_one_spacecCr�)Nz     r*r�r
r5r5r6�test_decode_multiple_spaces�r�z&TestQuopri.test_decode_multiple_spacescCr�)Nzhello    
r�r�r
r5r5r6�$test_decode_one_line_trailing_spaces�r�z/TestQuopri.test_decode_one_line_trailing_spacescCr�)Nzhello    
world   
r�r�r
r5r5r6�%test_decode_two_lines_trailing_spaces�r�z0TestQuopri.test_decode_two_lines_trailing_spacescCr�)Nz=22quoted=20words=22z"quoted words"r�r
r5r5r6�test_decode_quoted_word�r�z"TestQuopri.test_decode_quoted_wordcCr�)Nzab=CD=EF�abÍïr�r
r5r5r6�test_decode_uppercase_quoting�r�z(TestQuopri.test_decode_uppercase_quotingcCr�)Nzab=cd=efrr�r
r5r5r6�test_decode_lowercase_quoting�r�z(TestQuopri.test_decode_lowercase_quotingcCr�)Nzsoft line=
breakzsoft linebreakr�r
r5r5r6�test_decode_soft_line_break�r�z&TestQuopri.test_decode_soft_line_breakcCr�)NzA=1,B=A ==> A+B==2r�r
r5r5r6�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�)r2r�Zexpected_encoded_bodyr�r��kwargsZencoded_bodyr�r5r5r6�_test_encode�s�zTestQuopri._test_encodecCr�r��rr
r5r5r6�test_encode_null�r�zTestQuopri.test_encode_nullcCr�)Nz

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

1234r[r�rr
r5r5r6�,test_encode_trailing_space_before_maxlinelen�r�z7TestQuopri.test_encode_trailing_space_before_maxlinelencCr�)Nrzabcd=
=20
1234rur�rr
r5r5r6�(test_encode_trailing_space_at_maxlinelen�r�z3TestQuopri.test_encode_trailing_space_at_maxlinelencCr�)Nrzabc=
d=20
1234r�r�rr
r5r5r6�,test_encode_trailing_space_beyond_maxlinelenr�z7TestQuopri.test_encode_trailing_space_beyond_maxlinelencCr�)Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
rr
r5r5r6�test_encode_whitespace_linesr�z'TestQuopri.test_encode_whitespace_linescCr�)Nza = bza =3D brr
r5r5r6�test_encode_quoted_equalsr�z$TestQuopri.test_encode_quoted_equalscCr�)NZdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxrr
r5r5r6�test_encode_one_long_stringr�z&TestQuopri.test_encode_one_long_stringcCr�)Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
rr
r5r5r6�test_encode_one_long_liner�z$TestQuopri.test_encode_one_long_linecCr�)Nz�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
z�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
rr
r5r5r6�test_encode_one_very_long_liner�z)TestQuopri.test_encode_one_very_long_linecCr�)Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr�r�rr
r5r5r6�test_encode_shortest_maxlinelenr�z*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr*r�r�)r�rrr
r5r5r6� test_encode_maxlinelen_too_smallsz+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�ryr5r5r6r�s�
�zTestQuopri.test_encoder[)NN)Fr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr	r
rrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r�r5r5r5r6r��s�


r�c@r)
�TestCharsetcCs0ddlm}z|jd=WdStyYdSw)Nrr�fake)r�r<ZCHARSETSrY)r2�
CharsetModuler5r5r6�tearDown8s�zTestCharset.tearDowncCsN|j}td�}||�d�d�d}|�t|j|�td�}||�|�d�dS)NrH�Hello World!u¤¢¤¤¤¦¤¨¤ªrNz(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r.r	r�r�r�)r2r3rr�r5r5r6�test_codec_encodeable?sz!TestCharset.test_codec_encodeablecCs�|j}td�}|d|�d��td�}|d|�d��td�}|d|�d��td	�}d
dlm}|�d|jdd�td�}|d|�d��dS)
Nr8z
hello w=F6rlduhello wörldrNr�r�rHr�r�rrr+)r.r	r�r�r<Zadd_charsetZQP)r2r3rr,r5r5r6�test_body_encodeJszTestCharset.test_body_encodecCs,td�}|�t|�d�|�tjtd�dS)NrHuascÿii)r	r.r�r�rZCharsetErrorr�r5r5r6�test_unicode_charset_nameisz%TestCharset.test_unicode_charset_nameN)r�r�r�r-r/r0r1r5r5r5r6r*7s
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)Nr.z Goodbye World!zHello World!  Goodbye World!�r�r
r�r�r�r5r5r6�test_simpler�

zTestHeader.test_simplecCr3)Nr.zGoodbye World!zHello World! Goodbye World!r4r�r5r5r6�test_simple_surpriseyr6zTestHeader.test_simple_surprisecCsd}|�t|�|dfg�dS)Nzno decoding neededr�r�r5r5r6�test_header_needs_no_decoding�sz(TestHeader.test_header_needs_no_decodingcCs8tddd�}|jdd��d�D]
}|�t|�d�qdS)Na�I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.r�r�r+)Z
splitcharsz
 )r
r�r�r�r�)r2r��lr5r5r6�	test_long�s��zTestHeader.test_longc
Cs�|j}td�}td�}td�}d}d}d}t||�}|�||�|�||�|jdd�}	||	d	�t|	�}
|t|
�d
�||
d|df�||
d|df�||
d
|�d�df�t|�}||d�d��t	t|	��}|||�dS)Nr8rdrNr�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�rrur�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�rr�r�rQr)
r2r3r�r�r�r�r�r�r��encr�ZustrZnewhr5r5r6�test_multilingual�s0

�zTestHeader.test_multilingualcCrr�r�r�r5r5r6�test_empty_header_encode�r�z#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|�dtd��||d�dS)Nr*r�r8)r�r
r�r	r�r5r5r6�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�r5r5r6�test_explicit_maxlinelen�sz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�d�|��}||d�||ttt|����dS)Nr8r��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�r2r3r�rbr�r5r5r6�test_quopri_splittable�s

3

z!TestHeader.test_quopri_splittablecCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�|�|��}||d�||ttt|����dS)Nrer�r@r)a�=?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IA==?=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==?=rArBr5r5r6�test_base64_splittable,s

#

z!TestHeader.test_base64_splittablecCs8|j}d}t|�}||dg�t|�}|||���dS)Nr�)r�N�r.rrr�)r2r3r�rbr�r5r5r6�test_us_ascii_headerbszTestHeader.test_us_ascii_headercCs&|j}t�}|�dd�||d�dS)Nr�r8)r.r
r�r�r5r5r6�test_string_charsetjszTestHeader.test_string_charsetcCs:|j}tdd�}||��d�tdd�}||��d�dS)NrOrNz=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=�r.r
r�r�r5r5r6�test_utf8_shortestys


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 BigrNr�r)r�r.r�r
r�rQr�)r2rtr3rbr��er5r5r6�test_bad_8bit_header�szTestHeader.test_bad_8bit_headercCsNd}|�dd�}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS)NrJr��surrogateescaper�2Ynwp4dUEbay Auction Semiar- No Charge � Earn Big�unknown-8bit)	rQr
r�r<�UNKNOWN8BITr.r�r�r)r2rbrKr�r5r5r6�test_escaped_8bit_header�s
�z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS�NrJrrNrO)r
r�r<rPr.r�r�r)r2rbr�r5r5r6�&test_header_handles_binary_unknown8bit�s
�z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tj�tj�|��}|�t|�d�|�tj�|�|dfg�dSrR)	r
r�r<rPr�rrr.r�)r2rbr�Zh2r5r5r6�+test_make_header_handles_binary_unknown8bit�s
�z6TestHeader.test_make_header_handles_binary_unknown8bitcCs2td�}tj�|�}|�d�|�t|�d�dS)Nrv)r�Ztest2)r
r�r�rr�r.r�)r2r�rr5r5r6�0test_modify_returned_list_does_not_change_header�s
z;TestHeader.test_modify_returned_list_does_not_change_headercCsR|j}t�}|�dd�|�d�|��}||d�tt|��}||��|�dS)Nr�r8Zworldz=?iso-8859-1?q?hello?= world)r.r
r�r�rr)r2r3r�r�r5r5r6� test_encoded_adjacent_nonencoded�s

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������� � ��������re)s zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.rE)r2r3r��partsZhdrr5r5r6�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)r2rtr�r5r5r6�test_broken_base64_header�sz$TestHeader.test_broken_base64_headercCs tddd�}|�|��d�dS)Nr��	shift_jisrr�r�r�r5r5r6�test_shift_jis_charset�r/z!TestHeader.test_shift_jis_charsetcCst�d�}|�t|�d�dS)NzEmptyHeader:zEmptyHeader: 

)r�r�r.r�r]r5r5r6�!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]r5r5r6�)test_encode_preserves_leading_ws_on_value�rKz4TestHeader.test_encode_preserves_leading_ws_on_valuecCs|�td���d�dS)Nr+rHr
r5r5r6�test_whitespace_header�sz!TestHeader.test_whitespace_headerN)r�r�r�r5r7r8r:r<r=r>r?rCrDrFrGrIrLrQrSrTrUrVrXrYr[r\r]r^r5r5r5r6r2qs4?E6
	r2c@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.txtrs�rHrt�%This is even more ***fun*** isn't it!Fr�)rHrtz'"This is even more ***fun*** isn't it!")r.r/rDr1r5r5r6r��s

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


Hi,

Do you like this message?

-Me
)r�rrrDr/r�r1r5r5r6r�s&�
��
�
�zTestRFC2231.test_set_paramcCsft�}|�dd�|�|dd�|jdddd�|�|dd�|jdd	dd�|�|dd
�dS)Nrsr�r;ztext/plain; title="foo"r�F)Zrequoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")rrr.r]r5r5r6�test_set_param_requotesz"TestRFC2231.test_set_param_requotecCsX|j}|�d�}|jddddd�|jddddd�|jdd	d
�||jdd�d
�dS)Nr�r�r�rHrtrbrsrar?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/rrr�r1r5r5r6rs
�zTestRFC2231.test_del_paramcCr|)Nr2rH)r.r/�get_content_charsetr1r5r5r6� test_rfc2231_get_content_charset3r�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.rmr�rLr5r5r6�test_rfc2231_parse_rfc_quoting9�


�z*TestRFC2231.test_rfc2231_parse_rfc_quotingcCrg)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"

            rhrirLr5r5r6� test_rfc2231_parse_extra_quotingGrkz,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�rDZassertNotIsInstance�tupler.�r2r�r4Zparamr5r5r6�#test_rfc2231_no_language_or_charsetWs

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

rhr�rLr5r5r6�/test_rfc2231_no_language_or_charset_in_filenamef�


�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamecCrsrtr�rLr5r5r6�7test_rfc2231_no_language_or_charset_in_filename_encodedsrvzCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedcCrs)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�rLr5r5r6�test_rfc2231_partly_encoded��
�z'TestRFC2231.test_rfc2231_partly_encodedcCrs)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�rLr5r5r6�test_rfc2231_partly_nonencoded�ryz*TestRFC2231.test_rfc2231_partly_nonencodedcCrs)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"

rhr�rLr5r5r6�/test_rfc2231_no_language_or_charset_in_boundary�rvz;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundarycCrs)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.rerLr5r5r6�.test_rfc2231_no_language_or_charset_in_charset�s


�z:TestRFC2231.test_rfc2231_no_language_or_charset_in_charsetcCrs)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"

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

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

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

r�r�rLr5r5r6�&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��r2r3r�r4r<rcr�r5r5r6�-test_rfc2231_single_tick_in_filename_extended��


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

r�r�rorqr5r5r6�$test_rfc2231_single_tick_in_filenames


z0TestRFC2231.test_rfc2231_single_tick_in_filenamecCrs)NzAContent-Disposition: inline;
	filename*0*="'This%20is%20broken";
z'This is brokenr�rLr5r5r6�test_rfc2231_missing_tick�
�z%TestRFC2231.test_rfc2231_missing_tickcCrs)NzAContent-Disposition: inline;
	filename*0*="'This%20is%E2broken";
u'This is�brokenr�rLr5r5r6�0test_rfc2231_missing_tick_with_encoded_non_asciir�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�rH�en-usr�r�r�r5r5r6�!test_rfc2231_tick_attack_extended r�z-TestRFC2231.test_rfc2231_tick_attack_extendedcCrm)NzWContent-Type: application/x-foo;
	name*0="us-ascii'en-us'Frank's"; name*1=" Document"

r�zus-ascii'en-us'Frank's Documentrorqr5r5r6�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�rr5r5r6�test_rfc2231_no_extended_values:s
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�rHr��My Document For Your�r�r5r5r6�,test_rfc2231_encoded_then_unencoded_segmentsD�


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�rHr�r�r�r�r5r5r6�,test_rfc2231_unencoded_then_encoded_segmentsUr�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�)rfr�r�)r2�messagesr�r4r5r5r6�+test_should_not_hang_on_invalid_ew_messagesds����z7TestRFC2231.test_should_not_hang_on_invalid_ew_messagesN)!r�r�r�r�rrdrrfrjrlrrrurwrxrzr{r}r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r5r5r5r6r_�s>%
!




		


r_c@r)�
TestSignedcCsLt|dd��}|��}t�|�}Wd�||fS1swY||fSrr)r2rr��originalr4r5r5r6�_msg_and_obj�s
��zTestSigned._msg_and_objcCsLddl}|�d|j|jB�}|�|��d�}|�|��d�}|�||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$r�)r�r��Sr#�search�groupr.)r2r��resultr�ZrepartZinpartZoutpartr5r5r6�_signed_parts_eq�s
zTestSigned._signed_parts_eqcCs&|�d�\}}|��}|�||�dSr:�r�r�r��r2r�r4r�r5r5r6�test_long_headers_as_string�sz&TestSigned.test_long_headers_as_stringcCs*|�d�\}}|jdd�}|�||�dS)Nr;�<r�r�r�r5r5r6�(test_long_headers_as_string_maxheaderlen�sz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|�d�\}}t�}t|��|�|��}|�||�dSr:)r�rr
r�r�r�)r2r�r4r�r�r5r5r6�test_long_headers_flatten�s
z$TestSigned.test_long_headers_flattenN)r�r�r�r�r�r�r�r�r5r5r5r6r�~sr�c@r�)�TestHeaderRegistrycCs(t�}|dd�}|�|jdtj�dS)Nr
zattachment; 0*00="foo"r)rr^r_rZInvalidHeaderDefect)r2Zregr�r5r5r6�test_HeaderRegistry�s
z&TestHeaderRegistry.test_HeaderRegistryN)r�r�r�r�r5r5r5r6r��sr��__main__)er�rjrOr`r��iorr�	itertoolsr�randomr�	threadingrZ
unittest.mockrr�Zemail.policyZ
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�r�r�r,ZTestCaser�r�rrr:r=rNrbr�r�r�rrrAr�rr&rNr�r�r�r�r�r*r2r_r�r�r��mainr5r5r5r6�<module>s�lCAO((\<09 9g0K!��4D:h*!
�