Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/test_email/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/test_email/__pycache__/test_email.cpython-310.pyc
o

�9j�f�@s�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZddlZddlmZddlmZmZmZdd	lmZmZmZdd
lmZddlm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2m3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddlm7Z7ddlm8Z8ddlm9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?m@Z@ddl1mAZAmBZBdZCd ZDd!ZEGd"d#�d#e@�ZFGd$d%�d%ejG�ZHGd&d'�d'e@�ZIGd(d)�d)ejG�ZJGd*d+�d+ejG�ZKGd,d-�d-ejG�ZLGd.d/�d/ejG�ZMGd0d1�d1ejG�ZNGd2d3�d3e@�ZOGd4d5�d5e@�ZPGd6d7�d7e@�ZQGd8d9�d9e@�ZRGd:d;�d;e@�ZSGd<d=�d=e@�ZTGd>d?�d?e@�ZUGd@dA�dAe@�ZVGdBdC�dCe@�ZWGdDdE�dEe@�ZXGdFdG�dGe@�ZYGdHdI�dI�ZZGdJdK�dKeZeT�Z[GdLdM�dMeZeT�Z\GdNdO�dOejG�Z]GdPdQ�dQejG�Z^GdRdS�dSejG�Z_GdTdU�dUe@�Z`GdVdW�dWe@�ZaGdXdY�dYe@�ZbGdZd[�d[e@�Zcedd\k�r�e�e�dSdS)]�N)�StringIO�BytesIO)�chain��choice)�Thread)�patch)�Charset)�	Generator�DecodedGenerator�BytesGenerator)�Header�
decode_header�make_header)�HeaderRegistry)�Message)�MIMEApplication)�	MIMEAudio)�MIMEBase)�	MIMEImage)�MIMEMessage)�
MIMEMultipart)�MIMENonMultipart)�MIMEText)�Parser�HeaderParser)�
base64mime)�encoders��errors)�	iterators)�
quoprimime)�utils)�threading_helper)�unlink)�openfile�
TestEmailBase)�
FeedParser�BytesFeedParser�
�� c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�S)��TestMessageAPIcCs:|j}|�d�}||�d�gd��||�dd�d�dS)Nz
msg_20.txt�cc)zccc@zzz.orgzddd@zzz.orgzeee@zzz.org�xxzn/a)�assertEqual�_msgobj�get_all��self�eq�msg�r6�1/usr/lib/python3.10/test/test_email/test_email.py�test_get_all9s
zTestMessageAPI.test_get_allcCs|j}t�}||��d�td�}|�|�||dd�||��d�||dd�||�d�d�||dd	�||��jd�|�d�||��d�||dd�t�}d
|d<d|d
<d|d<|�|�||dd
�||dd�||dd�dS)N�
iso-8859-1�mime-versionz1.0�
text/plain�content-typez text/plain; charset="iso-8859-1"�charset�content-transfer-encoding�quoted-printablez2.0zMIME-Versionztext/x-weird�Content-Typezquinted-puntable�Content-Transfer-Encodingz"text/x-weird; charset="iso-8859-1")r/r�get_charsetr	�set_charset�get_content_type�	get_param�
input_charset�r3r4r5r=r6r6r7�test_getset_charset?s,


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

z+TestMessageAPI.test_set_charset_from_stringcCs0t�}td�}|�d|�|�|��jd�dS)Nr9zThis is a string payload)rr	�set_payloadr/rBrF)r3r5r=r6r6r7�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	rrLr/�get_payload�r3�datar=r5r6r6r7�+test_set_payload_with_8bit_data_and_charsetfsz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsRd}td�}d|_t�}|�|�d�|�|�|dd�|�|jdd�|�dS�NrNrOr>�8bitTrQ)r	�
body_encodingrrLrRr/rSrTr6r6r7�>test_set_payload_with_non_ascii_and_charset_body_encoding_noneoszMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCsLd}td�}d|_t�}|�||�|�|dd�|�|jdd�|�dSrW)r	rYrrLr/rSrTr6r6r7�>test_set_payload_with_8bit_data_and_charset_body_encoding_nonexszMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs$t�}|�g�|�|��g�dS�N�rrLr/rS�r3r5r6r6r7�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)rrLr�assertRaisesRegex�	TypeError�attach)r3r5�sub_msgr6r6r7�"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)NrIr9�
iso-8859-2�koi8-rz
msg_09.txt�dingbat)rirIr9rirhz
msg_12.txt)NrIr9Nrgz
iso-8859-3rIrh)r/r0�get_charsets)r3r4r5�charsetsr6r6r7�test_get_charsets�s



z TestMessageAPI.test_get_charsetscCsV|j}|�d�}dd�|��D�}||ddg�|�d�}|�d�}||��d�dS)N�
msg_04.txtcS�g|]}|���qSr6��get_filename��.0�pr6r6r7�
<listcomp>��z4TestMessageAPI.test_get_filename.<locals>.<listcomp>�msg.txt�
msg_07.txt��dingusfish.gif)r/r0rSrp)r3r4r5�	filenames�subpartr6r6r7�test_get_filename�s


z TestMessageAPI.test_get_filenamecCs4|j}|�d�}dd�|��D�}||ddg�dS)Nz
msg_44.txtcSrnr6rorqr6r6r7rt�ruzHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>rv�r/r0rS)r3r4r5rzr6r6r7�%test_get_filename_with_name_parameter�s
z4TestMessageAPI.test_get_filename_with_name_parametercC�"|j}|�d�}||��d�dS)Nrw�BOUNDARY)r/r0�get_boundaryr2r6r6r7�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"rmz$multipart/mixed; boundary="BOUNDARY"�
msg_03.txt)r/r0�set_boundary�items�lower�assertRaisesr�HeaderParseError)r3r4r5�header�valuer6r6r7�test_set_boundary�s






�z TestMessageAPI.test_set_boundarycCsLtd�}|�|��ddd�|��|�|��dddd�d�dS)Nz	form-datarrxzmultipart/form-data�!z!multipart/form-data; boundary="==)rr/r��	as_stringr^r6r6r7�test_make_boundary�s�z!TestMessageAPI.test_make_boundarycCsvtddd��}|��}Wd�n1swYt�}|�|�}t�}t|dd�}|�|d�|�|��|�dS)N�
msg_46.txtrO��encodingTrF)	r%�readr�parsestrrr
�flattenr/�getvalue�r3�fp�msgdata�parserr5�out�genr6r6r7�test_message_rfc822_only�s
�
z'TestMessageAPI.test_message_rfc822_onlycCs~tddd��}|���d�}Wd�n1swYtj��}|�|�}t�}tj�	|�}|�
|�|�|��|�dS)Nr�rOr��ascii)
r%r��encode�emailr��BytesHeaderParser�
parsebytesr�	generatorrr�r/r�r�r6r6r7�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.txtTrQrs This is a 7bit encoded message.
rxs-�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.
r}r2r6r6r7�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�uuencode�uuezx-uuer>TrQ�hello world�foosfoo)r/rrLrS)r3r4r5�cter6r6r7�test_get_decoded_uu_payloads

z*TestMessageAPI.test_get_decoded_uu_payloadcCst�}|�t|jd�dS)Nrx)rr�rcrSr^r6r6r7�*test_get_payload_n_raises_on_non_multipart�z9TestMessageAPI.test_get_payload_n_raises_on_non_multipartcCsn|j}|�d�}tddd��}|��}Wd�n1swYt�}t|�}|�|�||��|�dS)Nrwz
msg_17.txtrOr�)r/r0r%r�rrr�r�)r3r4r5r��text�s�gr6r6r7�test_decoded_generators

�
z%TestMessageAPI.test_decoded_generatorcCsbt�}d|d<d|d<|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�dS)	N�Me�From�You�to�from�FROM�To�TO)r�assertInr^r6r6r7�test__contains__szTestMessageAPI.test__contains__cCs�|�d�}tddd��}|��}Wd�n1swY|�|t|��|jdd�}|�d�}|�|d�d��|�|t	�
|d	d���dS)
Nr�rOr�T��unixfromr)rzFrom rx)r0r%r�r/�strr��split�
assertTrue�
startswith�NL�join)r3r5r�r��fullrepr�linesr6r6r7�test_as_string*s

�
zTestMessageAPI.test_as_stringcC�T|�d�}|jjdd�}|j|d�}t�}t||d�}|�|�|�||���dS�Nr��
��linesep��policy)	r0r��cloner�rr
r�r/r��r3r5�	newpolicyr�r�r�r6r6r7�test_as_string_policy4�

z$TestMessageAPI.test_as_string_policycCs<t�d�}|�d�}t�d�}t�|�}|�|��|�dS)Nu�            MIME-Version: 1.0
            Content-type: text/plain; charset="iso-8859-1"

            Test if non-ascii messages with no Content-Transfer-Encoding set
            can be as_string'd:
            Föö bär
            r9a%            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��r3�m�source�expectedr5r6r6r7�#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
            r9r��replace)r�r�r�rRr�r�r/r�r�r6r6r7�4test_nonascii_as_string_without_content_type_and_cteSs



zCTestMessageAPI.test_nonascii_as_string_without_content_type_and_ctecCs�|�d�}tddd��}|���d�}Wd�n1swY|�|t|��|jdd�}|�d�}|�|d�	d	��|�|d�
|d
d���dS)Nr�rOr�r�Tr��
rsFrom rx)r0r%r�r�r/�bytes�as_bytesr�r�r�r�)r3r5r�rUr�r�r6r6r7�
test_as_bytes`s
�
zTestMessageAPI.test_as_bytescCr�r�)	r0r�r�r�rrr�r/r�r�r6r6r7�test_as_bytes_policyjr�z#TestMessageAPI.test_as_bytes_policycCs t�d�}|�|�d�d�dS)NzContent-Type: blarg; baz; boo
�bazr*�r��message_from_stringr/rEr^r6r6r7�test_bad_paramt�
zTestMessageAPI.test_bad_paramcC�t�d�}|�|��d�dS�Nz
From: foo
�r�r�r/rpr^r6r6r7�test_missing_filenamex�
z$TestMessageAPI.test_missing_filenamecCst�d�}|�|��d�dS)Nz%Content-Disposition: blarg; filename
r*r�r^r6r6r7�test_bogus_filename|s�z"TestMessageAPI.test_bogus_filenamecCr�r��r�r�r/r�r^r6r6r7�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��threez X-Header: foo; bar=one; baz=two
))r�r*)r�r�)r�r��"X-Header: foo; bar="one"; baz=two
)r/r�r��
get_paramsr2r6r6r7�test_get_params�s(������zTestMessageAPI.test_get_paramscCs$t�}d|d<|�|�d�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"r@�boundary�CPIMSSMTPC06p5f3tG)rr/rEr^r6r6r7�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��quuzr�r�r*r�r��r/r�r�rEr2r6r6r7�test_get_param�s��zTestMessageAPI.test_get_paramcCs&|�d�}|�|�d��d�d�dS)Nz
msg_22.txtrx�namez
wibble.JPG)r0r/rSrEr^r6r6r7�'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"
rzJim&amp;&amp;JillF��unquotez"Jim&amp;&amp;Jill"r�r^r6r6r7�#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^r6r6r7�test_get_param_with_quotes�s��z)TestMessageAPI.test_get_param_with_quotescCs>t�d�}|�d|�|�d|�|�d|�|�d|�dS)NzHeader: existsr�r
�HEADER�headerx)r�r�r��assertNotInr^r6r6r7�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)rr)r)r=z
"iso-2022-jp")rrziso-9999-xxzX-Jimmyr�)r/r�	set_paramrEr�r2r6r6r7�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/r0r�rE�	del_paramr)r3r4r5�old_valr6r6r7�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^r6r6r7�test_del_param_on_other_header�sz-TestMessageAPI.test_del_param_on_other_headercCst�}|�dd�dS)Nr#r$)rrr^r6r6r7�$test_del_param_on_nonexistent_header�sz3TestMessageAPI.test_del_param_on_nonexistent_headercCs@t�}|jdddd�|d}|jddd�|�|d|�dS)Nr@r;rO�r=�foobarr�r%)r3r5�existing_headerr6r6r7�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=rIrJz	text/htmlztext/html; charset="us-ascii")r/rr��
ValueError�set_typerr2r6r6r7�
test_set_type�s

zTestMessageAPI.test_set_typecCs.t�}d|d<|�dd�|�|dd�dS)Nr;zX-Content-Type�application/octet-streamzx-content-type)rr.r/r^r6r6r7�test_set_type_on_other_headersz,TestMessageAPI.test_set_type_on_other_headercC�t�}|�|��d�dS)Nr;)rr/rDr^r6r6r7�test_get_content_type_missingr�z,TestMessageAPI.test_get_content_type_missingcCs$t�}|�d�|�|��d�dS)N�message/rfc822)r�set_default_typer/rDr^r6r6r7�/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.txtrr4�r0r/rSrDr^r6r6r7�+test_get_content_type_from_message_implicit�
�z:TestMessageAPI.test_get_content_type_from_message_implicitcCr7)N�
msg_28.txtrr4r9r^r6r6r7�+test_get_content_type_from_message_explicitr;z:TestMessageAPI.test_get_content_type_from_message_explicitcC�|�d�}|�|��d�dS)Nr�r;�r0r/rDr^r6r6r7�6test_get_content_type_from_message_text_plain_implicit!r�zETestMessageAPI.test_get_content_type_from_message_text_plain_implicitcCr>)Nr�r;r?r^r6r6r7�6test_get_content_type_from_message_text_plain_explicit%r�zETestMessageAPI.test_get_content_type_from_message_text_plain_explicitcCr2)Nr��rr/�get_content_maintyper^r6r6r7�!test_get_content_maintype_missing)r�z0TestMessageAPI.test_get_content_maintype_missingcC�$t�}|�d�|�|��d�dS)Nr4�message)rr5r/rCr^r6r6r7�3test_get_content_maintype_missing_with_default_type-r`zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCr7)Nr8rrF�r0r/rSrCr^r6r6r7�/test_get_content_maintype_from_message_implicit2�
z>TestMessageAPI.test_get_content_maintype_from_message_implicitcCr7)Nr<rrFrHr^r6r6r7�/test_get_content_maintype_from_message_explicit6rJz>TestMessageAPI.test_get_content_maintype_from_message_explicitcCr>)Nr�r��r0r/rCr^r6r6r7�:test_get_content_maintype_from_message_text_plain_implicit:r�zITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitcCr>)Nr�r�rLr^r6r6r7�:test_get_content_maintype_from_message_text_plain_explicit>r�zITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitcCr2)N�plain�rr/�get_content_subtyper^r6r6r7� test_get_content_subtype_missingBr�z/TestMessageAPI.test_get_content_subtype_missingcCrE)Nr4�rfc822)rr5r/rQr^r6r6r7�2test_get_content_subtype_missing_with_default_typeFr`zATestMessageAPI.test_get_content_subtype_missing_with_default_typecCr7)Nr8rrS�r0r/rSrQr^r6r6r7�.test_get_content_subtype_from_message_implicitKrJz=TestMessageAPI.test_get_content_subtype_from_message_implicitcCr7)Nr<rrSrUr^r6r6r7�.test_get_content_subtype_from_message_explicitOrJz=TestMessageAPI.test_get_content_subtype_from_message_explicitcCr>)Nr�rO�r0r/rQr^r6r6r7�9test_get_content_subtype_from_message_text_plain_implicitSr�zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCr>)Nr�rOrXr^r6r6r7�9test_get_content_subtype_from_message_text_plain_explicitWr�zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitcC�"t�}d|d<|�|��d�dS)N�no-slash-in-this-stringr@r�rBr^r6r6r7�test_get_content_maintype_error[�z.TestMessageAPI.test_get_content_maintype_errorcCr[)Nr\r@rOrPr^r6r6r7�test_get_content_subtype_error`r^z-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)r`rbrd)rarcre�Twenty)rarfre�Eleven�One Hundred)r`rbrdr`)rhrfrerg�Fourth�Missing)r/rr&�keys�values�replace_headerr��KeyErrorr2r6r6r7�test_replace_headeresz"TestMessageAPI.test_replace_headercCspt�}|�|���|jdddd�|�|��d�|�dd�|�|��d�|�dd�|�|��d�dS)Nrr z
random.avir"�inline�InlinE)r�assertIsNone�get_content_dispositionr&r/rmr^r6r6r7�test_get_content_dispositionvs�z+TestMessageAPI.test_get_content_dispositioncCsPd}t�}d|d<d|d<|�|�|�|jdd�d�|�|jd	tj�dS)
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midir<rPr>TrQs����.���p���r)rrLr/rS�assertIsInstance�defectsr�InvalidBase64CharactersDefect�r3�xr5r6r6r7�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<rXr>TrQzraw-unicode-escape)rrLr/rSr�rxr6r6r7�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 dorO�text/plain; charset="utf-8"r<rXr>TrQ)r�r�_payloadr/rSrxr6r6r7�test_questionable_bytes_payload�s
z.TestMessageAPI.test_questionable_bytes_payloadcC�*t�}|jdddd�|�d|d�dS)Nrr r!r"zattachment; filename="bud.gif"�rr&r/r^r6r6r7�test_ascii_add_header�s��z$TestMessageAPI.test_ascii_add_headercCr)Nrr �Fußballer.pptr"z/attachment; filename*=utf-8''Fu%C3%9Fballer.pptr�r^r6r6r7�test_noascii_add_header����z&TestMessageAPI.test_noascii_add_headercCr)Nrr )r9r*r�r"z1attachment; filename*=iso-8859-1''Fu%DFballer.pptr�r^r6r6r7�#test_nonascii_add_header_via_triple�r�z2TestMessageAPI.test_nonascii_add_header_via_triplecCr)Nrr zwindows [filename].pptr"z-attachment; filename="windows [filename].ppt"r�r^r6r6r7�#test_ascii_add_header_with_tspecial�r�z2TestMessageAPI.test_ascii_add_header_with_tspecialcCr)Nrr uFußballer [filename].pptr"z@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptr�r^r6r6r7�&test_nonascii_add_header_with_tspecial�r�z5TestMessageAPI.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=87barTrQ�	foo文bar�1get_payload returns wrong result with charset %s.r]�r3r=r5r6r6r7�test_binary_quopri_payload��

��z)TestMessageAPI.test_binary_quopri_payloadcCr�)Nr�r�r<rPr>sZm9v5paHYmFyTrQr�r�r]r�r6r6r7�test_binary_base64_payload�r�z)TestMessageAPI.test_binary_base64_payloadc
Cs^dD]*}dD]%}t�}d||d<||d<|�d�|�|jdd�d	td
��||��qqdS)Nr�r�r�r<r>s begin 666 -
)9F]OYI:'8F%R
 
end
TrQr�)z!get_payload returns wrong result z"with charset {0} and encoding {1}.)rrLr/rSr��format)r3r=r�r5r6r6r7�test_binary_uuencode_payload�s

���z+TestMessageAPI.test_binary_uuencode_payloadcCs*t�}|jdddd�|�d|d�dS)Nrrp)�foo_barzinline; foo-barr�r^r6r6r7�$test_add_header_with_name_only_param��z3TestMessageAPI.test_add_header_with_name_only_paramcCs&t�}|�dd�|�d|d�dS)NzX-Statusr*r�r^r6r6r7�test_add_header_with_no_value��z,TestMessageAPI.test_add_header_with_no_valuecCs&t�}td�|d<|�tj|j�dS�Nzdummy
X-Injected-Header: test�Dummy)rr
r�rr�r�r^r6r6r7�(test_embedded_header_via_Header_rejected�r�z7TestMessageAPI.test_embedded_header_via_Header_rejectedcCs"t�}d|d<|�tj|j�dSr�)rr�rr�r�r^r6r6r7�(test_embedded_header_via_string_rejectedr^z7TestMessageAPI.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��r3r�r6r6r7�-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�r6r6r7�+test_unicode_body_defaults_to_utf8_encodingsz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)X�__name__�
__module__�__qualname__r8rHrKrMrVrZr[r_rfrlr|r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	r
rrr'r(r,r/r1r3r6r:r=r@rArDrGrIrKrMrNrRrTrVrWrYrZr]r_rortrzr{r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r6r6r6r7r,8s�			

	



r,c@�<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncoderscCsptdd��}|��}Wd�n1swYtjj�|�}|��}|�d�}|�t	dd�|D��d�dS)N�PyBanner048.gif�rbr)cS�g|]}t|��qSr6)�len�rrryr6r6r7rt(ruz;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>�L)
r%r�r��mime�imagerrSr��assertLessEqual�max)r3r��bindata�mimed�base64edr�r6r6r7�test_EncodersEncode_base64!s
�
z'TestEncoders.test_EncodersEncode_base64cCs(|j}t�}|�d�||dd�dS)NrIr>�7bit)r/rrCr2r6r6r7�test_encode_empty_payload*s
z&TestEncoders.test_encode_empty_payloadcCsP|j}td�}||dd�td�}||dd�tddd�}||dd�dS)	N�hello worldr>r�uhello ø worldrPr9��_charsetr?)r/rr2r6r6r7�test_default_cte0s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�r2r6r6r7�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^r6r6r7�test_qp_encode_latin1Ks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^r6r6r7�test_qp_encode_non_latin1Usz&TestEncoders.test_qp_encode_non_latin1N)	r�r�r�r�r�r�r�r�r�r6r6r6r7r�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��r3r4r5�sfpr�r6r6r7�test_split_long_continuationfs

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��r3r4�hstr�hr6r6r7�,test_another_long_almost_unsplittable_headerzs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)
Nr9rgrO�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�)r3r4r��cz�utf8�g_head�cz_head�	utf8_headr�r5r�r6r6r7�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��r3r4r�r6r6r7�test_long_header_encode�s
�z'TestLongHeaders.test_long_header_encodecC�&|j}tdddd�}||��d�dS)Nr�r�r��r�r�r�r�r�r6r6r7�<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�r6r6r7�-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��r3r�r6r6r7�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
rRr/r�)r3r��resr6r6r7�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�r6r6r7�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>Nr6�rr�ir6r6r7�	<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��rangerLrr
r�r�r�r6r6r7�test_no_semis_header_splitters

z-TestLongHeaders.test_no_semis_header_splittercC� |j}td�}||��d�dS)Nz�Subject: the first part of this is short, but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfz�Subject: the first part of this is short,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfr�r�r6r6r7�"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�r6r6r7�>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�r6r6r7�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�r6r6r7�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�r6r6r7�Itest_trailing_splittable_on_overlong_unsplittable_with_leading_splittable2r�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�r6r6r7�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�r6r6r7�:test_splitter_split_on_punctuation_only_if_fws_with_headerCr�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�r6r6r7�Dtest_leading_splittable_in_the_middle_just_before_overlong_last_partJ�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�r6r6r7�/test_overlong_last_part_followed_by_split_pointUr�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�r6r6r7�@test_multiline_with_overlong_parts_separated_by_two_split_points\rzPTestLongHeaders.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�r6r6r7�>test_multiline_with_overlong_last_part_followed_by_split_pointgrzNTestLongHeaders.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�rLrr
r�r�r�r6r6r7�%test_long_header_with_whitespace_runsrs

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�r6r6r7�'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�rr�r�zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r�rrLrr
r�r�r�r6r6r7�.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:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx�Pxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr�r�r6r6r7�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�r6r6r7�"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�N�Receivedr�)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�r6r6r7�&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 gibtr9r�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?=��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�)r3r4r5r�r6r6r7�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-Torrz�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
)r3r4r5�
header_stringr6r6r7� 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�rrz�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�)r3r4r�r5r6r6r7�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��r3r4r�r�r6r6r7�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?)rrr6r6r7�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. r9r�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�)r3r4�fn�gsr�r6r6r7�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-2rra1Received-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��r3r�r5r6r6r7�test_long_received_header2s
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!rra#Received-1: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
Received-2: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")

r"r#r6r6r7�test_string_headerinst_eqDs
�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-3rra�Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

�r�rr
r�)r3r4r5�tr6r6r7�-test_long_unbreakable_lines_with_continuationWs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 -0700rrz�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��r3r4r�r5r6r6r7�"test_another_long_multiline_headeros
z2TestLongHeaders.test_another_long_multiline_headercCs>|j}d}t�}||d<t|dd�|d<||jdd�d�dS)Nz�List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>�Listr�rra_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&)r3r4r�r5r6r6r7�%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 worksrOr�)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�r6r6r7�*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�rrrrrrrr
rrrrrrrrrrrr$r%r(r*r,r-r6r6r6r7r�bsR6	


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

>From the desk of A.A.A.:
Blah blah blah
�rr
r�r5r/r��r3r�r�r6r6r7�test_mangled_from��z"TestFromMangling.test_mangled_fromcCr2)NFr3z;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
r5r6r6r6r7�test_dont_mangle_from�r8z&TestFromMangling.test_dont_mangle_fromcCsTt�}t|dd�}t�t�d��}|�|�|�tdd�|�	��
d�D��d�dS)NTr3a)            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 rx)r�r�r6r6r7rt�s
�zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r)r�)rr
r�r�r�r�r�r/r�r�r�)r3r�r�r5r6r6r7�'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

        rOsFrom Rölli
Tr3s
>From Rölli
)
r�r�r�r�r�rrr�r/r�)r3r�r5�br�r6r6r7� 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: È
        rO)r�r�r�r�r�)r3r�r5r6r6r7�$test_multipart_with_bad_bytes_in_cte�s�z5TestFromMangling.test_multipart_with_bad_bytes_in_cteN)	r�r�r�r1r7r9r:r<r=r6r6r6r7r/�sr/c@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudiocC�Dtdd��
}|��|_Wd�n1swYt|j�|_dS)N�audiotest.aur�)r%r��
_audiodatar�_au�r3r�r6r6r7r1���zTestMIMEAudio.setUpcC�|�|j��d�dS)Nzaudio/basic)r/rCrDr0r6r6r7�test_guess_minor_type��z#TestMIMEAudio.test_guess_minor_typecC�(|j��}|�t�t|d��|j�dS�Nr�)rCrSr/rP�decodebytesr�rB�r3�payloadr6r6r7�
test_encoding��
�zTestMIMEAudio.test_encodingcC� t|jd�}|�|��d�dS)N�fishz
audio/fish)rrBr/rD)r3�aur6r6r7�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)Nrr rAr"r$z#attachment; filename="audiotest.au"r��r r*)r#rAr#r*r���failobjr�r*)r/rCr&r�rE�assertIs�r3r4�missingr6r6r7�test_add_header�4
�
�������zTestMIMEAudio.test_add_headerN�r�r�r�r1rGrNrSr\r6r6r6r7r?��r?c@r>)�
TestMIMEImagecCr@)Nr�r�)r%r��_imgdatar�_imrDr6r6r7r1rEzTestMIMEImage.setUpcCrF)Nz	image/gif)r/rbrDr0r6r6r7rGrHz#TestMIMEImage.test_guess_minor_typecCrIrJ)rbrSr/rPrKr�rarLr6r6r7rNrOzTestMIMEImage.test_encodingcCrP)NrQz
image/fish)rrar/rD)r3�imr6r6r7rS$rTz TestMIMEImage.test_checkSetMinorcCrU)Nrr ryr"r$z%attachment; filename="dingusfish.gif"r�rV)r#ryr#r*r�rWr*)r/rbr&r�rErYrZr6r6r7r\(r]zTestMIMEImage.test_add_headerNr^r6r6r6r7r`r_r`c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestMIMEApplicationcCs.|j}td�}||��d�||dd�dS)N�������r0r>rP)r/rrDr2r6r6r7�test_headers?sz TestMIMEApplication.test_headerscCs:|j}d}t|�}||����d�||jdd�|�dS)Nrez+vv8/f7/TrQ)r/rrS�strip)r3r4�	bytesdatar5r6r6r7�	test_bodyEs
zTestMIMEApplication.test_bodycCs�d}t|tjd�}|�|��dt|��|�|jdd�|�|�|dd�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�|�|dd�dS)Nre��_encoder��TrQrArX)rr�encode_7or8bitr/rSr�rrr�r�r�r��r3rhr5r�r��wireform�msg2r6r6r7�$test_binary_body_with_encode_7or8bitMs

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|tjd�}|�|��dt|��|�|jdd�|�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�dS)NrerjrlTrQ)rr�encode_noopr/rSr�rrr�r�r�r�rnr6r6r7�!test_binary_body_with_encode_noop^s

z5TestMIMEApplication.test_binary_body_with_encode_noopcCshd}t|tjd�}|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|jdd�|�dS)Ns������rjTrQ)rrrrr/rSrrr�r�r�r�rnr6r6r7�0test_binary_body_with_unicode_linend_encode_noopos

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|tjd�}|�|��d�|�|jdd�|�|�|dd�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�|�|dd�dS)Ns������ rjz=FA=FB=FC=FD=FE=FF=20TrQrAr?)rr�
encode_quoprir/rSrrr�r�r�r�rnr6r6r7�#test_binary_body_with_encode_quopri{s

z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|tjd�}|�|��d�|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�dS)Nrerjz	+vv8/f7/
TrQ)rr�
encode_base64r/rSrrr�r�r�r�rnr6r6r7�#test_binary_body_with_encode_base64�s

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
r�r�r�rfrirqrsrtrvrxr6r6r6r7rd>srdc@sVeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�d�dd��ZdS)�TestMIMETextcCstd�|_dS�N�hello there)r�_msgr0r6r6r7r1��zTestMIMEText.setUpcCs`|j}||j��d�||j�d�d�g}|�|j�d|�|�|�|jjd|dd�|�dS)Nr;r=rIr*r�)r/r|rDrErYrZr6r6r7�
test_types�s�zTestMIMEText.test_typescCs&|�|j��d�|�|j���dSrz)r/r|rS�assertFalse�is_multipartr0r6r6r7�test_payload�szTestMIMEText.test_payloadcCsz|j}tddd�}||��jd�||dd�td�}d|_td|d�}||��jd�||dd�||��d�dS)Nr{rIr�r<rJrOr|)r/rrBrFr	rYrSrGr6r6r7�test_charset�szTestMIMEText.test_charsetcCs4|j}tddd�}||��jd�||dd�dS)Nr{rIr�r<rJ)r/rrBrFr2r6r6r7�test_7bit_input�szTestMIMEText.test_7bit_inputcCs>|j}td�}||��d�||dd�|�d|���dS)Nr{rIr<rJ)r/rrBr�r�r2r6r6r7�test_7bit_input_no_charset�s
z'TestMIMEText.test_7bit_input_no_charsetcCsPd}|j}t|dd�}||��jd�||dd�||jdd�|�d��dS)N�кирилицаrOr�r<r|TrQ)r/rrB�output_charsetrSr�)r3�teststrr4r5r6r6r7�test_utf8_input�szTestMIMEText.test_utf8_inputzBcan't fix because of backward compat in email5, will fix in email6cCsd}|�tt|�dS)Nr�)r��UnicodeEncodeErrorr)r3r�r6r6r7�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
r�r�r�r1r~r�r�r�r�r��unittest�skipr�r6r6r6r7ry�s	
ryc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!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�ry)rr$r r"z$Hi there,

This is the dingus fish.
zBarry <barry@digicool.com>r�z)Dingus Lovers <cravindogs@cravindogs.com>r�zHere is your dingus fishr�g�4F�cp�A���r�-�+z %s%04d�$z%a, %d %b %Y %H:%M:%S�Date)r%r�rrr&rrd�time�	localtime�timezone�altzone�strftimer|rb�_txt)r3r�rU�	containerr��intro�now�	timetuple�tzsecs�sign�tzoffsetr6r6r7r1�s@
��


��
zTestMultipart.setUpcCs�|j}|j}|j}|�|���||��d�|t|���d�|t|jd�|�d�}|�d�}|�	||j
�|�	||j�||��||g�|�|���|�|���dS)Nrar�rrx)
r/r�r|r�r�rDr�rS�
IndexErrorrYr�rbr)r3r4�raisesr��m0�m1r6r6r7�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�)r3r�r5r6r6r7�test_empty_multipart_idempotent
s
z-TestMultipart.test_empty_multipart_idempotentcCs@tdd�}d|d<d|d<d|d<|�d	�|�|��d
�dS)Nr�r��	A subjectr��aperson@dom.ainr��bperson@dom.ainr�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��r3�outerr6r6r7�/test_no_parts_in_a_multipart_with_none_epilogues

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


--BOUNDARY

--BOUNDARY--
)r�preamble�epiloguer�r�r�r�r6r6r7�0test_no_parts_in_a_multipart_with_empty_epilogue0s

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

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

hello world
--BOUNDARY--
)r�rr�rrdr��r3r4r�r5r6r6r7�test_one_part_in_a_multipartEs


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


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

hello world
--BOUNDARY--
�r�rr�rrdr�r�r�r6r6r7�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�Nr�r�r�r�r�r�r�r�r�r�r�r�r�r6r6r7�0test_seq_parts_in_a_multipart_with_none_preamblezr�z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblecCr�r��r�rr�rrdr�r�r�r6r6r7�0test_seq_parts_in_a_multipart_with_none_epilogue�r�z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguecCr�)
Nr�r�r�r�r�r�r�r�r*r�r�r�r�r�r6r6r7�1test_seq_parts_in_a_multipart_with_empty_epilogue�r�z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epiloguecCr�)
Nr�r�r�r�r�r�r�r�r)r�r�aContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

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

hello world
--BOUNDARY--

r�r�r6r6r7�.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�rxzmultipart/alternativezmessage/external-bodyrr;)r/r0r�rSrD)r3r4r5�msg1r{�
subsubpartr6r6r7�test_message_external_body�s


�z(TestMultipart.test_message_external_bodycCs"|�d�}|�t|���d�dS)Nz
msg_37.txtr�)r0r/r�rSr^r6r6r7�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�r0rr �
_structurer��r3r4r5r�r6r6r7�)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�r6r6r7�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--
)r0r/r�r^r6r6r7�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�r�r�r�rSr2r6r6r7� 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/rSr�r6r6r7�&test_boundary_without_trailing_newline@sz4TestMultipart.test_boundary_without_trailing_newlinecCs tdd�}|�|jtjj�dS)Nr�r�)rrYr�r��compat32r�r6r6r7�test_mimebase_default_policyNr�z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|�|jtjj�dS)Nr�r�r�)rr�r��defaultrYr�r6r6r7�test_mimebase_custom_policyR�z)TestMultipart.test_mimebase_custom_policyN)r�r�r�r1r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r6r6r6r7r��s*$
r�c@s~eZdZdd�Zdd�Zdd�Ze�d�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�TestNonConformantcCs>|j}|�d�}||��d�||��d�||��d�dS)Nz
msg_14.txtr;r�rO)r/r0rDrCrQr2r6r6r7�test_parse_missing_minor_typeYs

z/TestNonConformant.test_parse_missing_minor_typecCsN|�d�}|�d�}|�t|d��|�t|j�d�|�|jdtj	�dS)N�
msg_15.txtrrvrx)
r0rSr��hasattrr/r�rvrur�StartBoundaryNotFoundDefect)r3r5�innerr6r6r7�test_same_boundary_inner_outeras

�z0TestNonConformant.test_same_boundary_inner_outercCsX|�d�}|�|��t�|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_25.txtr�rrx)
r0rurSr�r/r�rvr�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefectr^r6r6r7�test_multipart_no_boundaryk�
��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: base64rxr)	�_str_msg�
multipart_msgr�r/r�rvrur�-InvalidMultipartContentTransferEncodingDefectr^r6r6r7�test_multipart_invalid_cte�s
��z,TestNonConformant.test_multipart_invalid_ctecCs(|�|j�d��}|�t|j�d�dS)Nr*r�r�r�r�r/r�rvr^r6r6r7�test_multipart_no_cte_no_defect�r�z1TestNonConformant.test_multipart_no_cte_no_defectcCs8dD]}|�|j�d�|���}|�t|j�d�qdS)N)r�rX�BINaryz
Content-Transfer-Encoding: {}rr�)r3r�r5r6r6r7�"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@rOr;r<r�zContent-Type: foo

)
r/r�rrCrQrDrr
r�r�)r3r4�neqr5r�r�r6r6r7�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�r0rSr2r6r6r7�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�r0r�r2r6r6r7�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.txtrvr�rrx)
r0r�r�r/r�rvrurr�r�r^r6r6r7�test_lying_multipart�r�z&TestNonConformant.test_lying_multipartcCsD|�d�}|�d��d�}|�t|j�d�|�|jdtj�dS)Nz
msg_42.txtrxr)r0rSr/r�rvrurr�)r3r��badr6r6r7�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��bodyrxrz Line 1
)r/r�r�rkrSr�rv�assertDefectsEqualr�#FirstHeaderLineIsContinuationDefect�liner)r6r6r7�&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/rkrSr�rvr� MissingHeaderBodySeparatorDefectr^r6r6r7�"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�r6r6r6r7r�Ws

	
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��r3r4r��dhr�r6r6r7�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�r9)s Pirard <pirard@dom.ain>NuAndré Pirard <pirard@dom.ain>�r/rr�rr�r6r6r7�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 foxr9)s jumped over the N)slazy dogr9z,The quick brown fox jumped over the lazy dogr�)r3r4r�r��hur6r6r7� 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���r9)srgN���r9)ssbordN�rr/�r3r�r�r6r6r7�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 sbordNrrr6r6r7�test_rfc2047_with_whitespace1	r	z(TestRFC2047.test_rfc2047_with_whitespacecCs<d}gd�}|D]\}}t||�}|�||dfg�qdS)Nz=?iso-8859-1?B?%s?=))zdm==�v)zdm=r)�dmr)zdmk=�vi)�dmkr
r9r)r3r�rU�q�ar�r6r6r7�test_rfc2047_B_bad_padding8	s�z&TestRFC2047.test_rfc2047_B_bad_paddingcCsd}|�t|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=)sandr�=zzr9�r/r�r3r�r6r6r7�test_rfc2047_Q_invalid_digitsB	s
�z)TestRFC2047.test_rfc2047_Q_invalid_digitscC�d}|�t|�gd��dS)Nz(=?ISO-8859-1?Q?a?=))��(N��ar9��)Nrrr6r6r7�test_rfc2047_rfc2047_1H	�
�z"TestRFC2047.test_rfc2047_rfc2047_1cCr)Nz(=?ISO-8859-1?Q?a?= b))rr)s b)Nrrr6r6r7�test_rfc2047_rfc2047_2N	rz"TestRFC2047.test_rfc2047_rfc2047_2cCr)Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)�r)sabr9rrrr6r6r7�test_rfc2047_rfc2047_3T	rz"TestRFC2047.test_rfc2047_rfc2047_3cCr)Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)rrrr6r6r7�test_rfc2047_rfc2047_4Z	rz"TestRFC2047.test_rfc2047_rfc2047_4cCr)Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)rrrr6r6r7�test_rfc2047_rfc2047_5a`	rz#TestRFC2047.test_rfc2047_rfc2047_5acCr)Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)rrrr6r6r7�test_rfc2047_rfc2047_5bf	rz#TestRFC2047.test_rfc2047_rfc2047_5bcCr)Nz(=?ISO-8859-1?Q?a_b?=))r)sa br9rrrr6r6r7�test_rfc2047_rfc2047_6l	rz"TestRFC2047.test_rfc2047_rfc2047_6cCsPd}|�t|�gd��|�tt|����|���|�ttt|���d�dS)Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))rr)s brgrz(a b))r/rrr�r�r�rr6r6r7�test_rfc2047_rfc2047_7r	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�rr6r6r7�test_multiline_header{	s
����z!TestRFC2047.test_multiline_headerN)r�r�r�r�r�rrr
rrrrr r!r"r#r$r%r'r6r6r6r7r�	s"		
	r�c@r�)"�TestMIMEMessagecCs<tddd��}|��|_Wd�dS1swYdS)N�
msg_11.txtrOr�)r%r��_textrDr6r6r7r1�	s"�zTestMIMEMessage.setUpcCs|�ttd�dS)Nza plain string)r�rcrr0r6r6r7�test_type_error�	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||��d�|��}|�|t�|t|�d�|d}|�||�||d|�dS)Nz
A sub-messager�r4rxr�subject)	r/rrrDrSru�listr�rY)r3r4r,r��rrMr{r6r6r7�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�MultipartConversionErrorrd)r3r�rpr.r6r6r7�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.
)rrLrrr
r�r/r�)r3r�r.r�r�r6r6r7�
test_generate�	s

zTestMIMEMessage.test_generatecCst|j}|�d�}||��d�|��}|�|t�|t|�d�|d}|�|t�||dd�||��d�dS)Nr)r4rxrr,r3r4)r/r0rDrSrur-r�r)r3r4r5rM�submsgr6r6r7�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

rxzmessage/delivery-statusr�zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.edu�dnsz
reporting-mtar�r*�nsd�action�failedzoriginal-recipient)rSr*)zjangel1@cougar.noc.ucla.edur*rSzfinal-recipientr4�
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r/r0rDr�r�r�rSrurrEr�r-)r3r4r5r{�dsn1�dsn2rMr�r6r6r7�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.txtrOr�r�r�r�r�r�r��MIME messagezEnd of MIME message
rarcr@rar�r�)
r�r%r�rr�r�rr&rdrr
r�r�)	r3r4r�r�r5r�rpr�r�r6r6r7�
test_epilogue�	s&
�


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

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

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

Two
--BOUNDARY--
)r�rr�r�rr&rdr�)r3r4r5r�rpr6r6r7�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)Nr8rOr�rr4rxr;�r/r%r��message_from_filerS�get_default_typerD�r3r4r�r5�
container1�
container2�container1a�container2ar6r6r7�test_default_type5
� �



z!TestMIMEMessage.test_default_typecCrE)Nr<rOr�rr4rxr;rFrIr6r6r7�.test_default_type_with_explicit_container_typeF
rOz>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
r4ra�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<r:aBContent-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�rrrdrDrHr�)r3r4r�r��	subpart1a�	subpart2a�subpart1�subpart2r6r6r7�test_default_type_non_parsedW
s0


z,TestMIMEMessage.test_default_type_non_parsedcCsZ|j}td�}td�}t||fd�}|t|���d�||�d�|�||�d�|�dS)Nr*)�	_subpartsr�rrx)r/rrr�rS)r3r4�text1�text2r5r6r6r7�$test_mime_attachments_in_constructor�
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|�|���dSr\)rr�r�r^r6r6r7�"test_default_multipart_constructor�
sz2TestMIMEMessage.test_default_multipart_constructorcCs0t�}d|d<d|d<|�|�d�ddg�dS)N�a@b.comr��c@d.comr�)rr/r1r^r6r6r7�test_multipart_default_policy�
sz-TestMIMEMessage.test_multipart_default_policycCs^ttjjd�}d|d<|�t��}d|d<Wd�n1swY|�t|j�d�dS)Nr�r^r�r_z.There may be at most 1 To headers in a message)	rr�r�r�r�r-r/r��	exception)r3r5�cmr6r6r7�test_multipart_custom_policy�
s
��z,TestMIMEMessage.test_multipart_custom_policyN)r�r�r�r1r+r/r2r5r7r@rCrDrNrPrXr\r]r`rcr6r6r6r7r(�	s"9#J	r(c@seZdZdd�Zdd�ZdS)�TestNonMultipartcCstdd�}|�|���dS)Nr�rO)rrr�r^r6r6r7�"test_nonmultipart_is_not_multipart�
s
z3TestNonMultipart.test_nonmultipart_is_not_multipartcCs.t�}d|d<tdd�}|�tj|j|�dS)Nr0r�r�rO)rrr�rr1rd)r3r5r.r6r6r7�test_attach_raises_exception�
s
z-TestNonMultipart.test_attach_raises_exceptionN)r�r�r�rerfr6r6r6r7rd�
srdc@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�NrOr��r%r�r�r��r3r#r�rUr5r6r6r7r0�
s

�
zTestIdempotent._msgobjFcCs8|j}t�}t|dd�}|j||d�|||���dS)Nrrr�)r�rr
r�r�)r3r5r�r�r4r�r�r6r6r7�_idempotent�
s
zTestIdempotent._idempotentcCs�|j}|�d�\}}||��d�||��d�||��d�||��dd�||�d�d�||jd�||jd�|�	||�dS)	Nr�r;r�rOrx)r=rIr=rI)
r/r0rDrCrQr�rEr�r�rk�r3r4r5r�r6r6r7�test_parse_text_message�
sz&TestIdempotent.test_parse_text_messagecCsP|j}|�d�\}}||��d�||��d�||�d�d�|�||�dS)Nr�r;r=)r/r0rDr�rErkrlr6r6r7�test_parse_untyped_message�
sz)TestIdempotent.test_parse_untyped_messagecC�|�d�\}}|�||�dS)Nrm�r0rk�r3r5r�r6r6r7�test_simple_multipart�
�z$TestIdempotent.test_simple_multipartcCro)N�
msg_02.txtrprqr6r6r7�test_MIME_digest�
rszTestIdempotent.test_MIME_digestcCro)Nz
msg_27.txtrprqr6r6r7�test_long_header�
rszTestIdempotent.test_long_headercCro)Nr<rprqr6r6r7�"test_MIME_digest_with_part_headersrsz1TestIdempotent.test_MIME_digest_with_part_headerscCro)N�
msg_06.txtrprqr6r6r7�test_mixed_with_imagersz$TestIdempotent.test_mixed_with_imagecCro)Nrrprqr6r6r7�test_multipart_reportrsz$TestIdempotent.test_multipart_reportcCro)Nr8rprqr6r6r7r@rszTestIdempotent.test_dsncCro)NrArprqr6r6r7�test_preamble_epiloguersz%TestIdempotent.test_preamble_epiloguecCro)Nz
msg_23.txtrprqr6r6r7�test_multipart_one_partrsz&TestIdempotent.test_multipart_one_partcCro)Nz
msg_24.txtrprqr6r6r7�test_multipart_no_partsrsz&TestIdempotent.test_multipart_no_partscCro)Nr�rprqr6r6r7r�rsz%TestIdempotent.test_no_start_boundarycCro)N�
msg_32.txtrprqr6r6r7�test_rfc2231_charset rsz#TestIdempotent.test_rfc2231_charsetcCro)Nz
msg_33.txtrprqr6r6r7�test_more_rfc2231_parameters$rsz+TestIdempotent.test_more_rfc2231_parameterscCro)Nz
msg_34.txtrprqr6r6r7�%test_text_plain_in_a_multipart_digest(rsz4TestIdempotent.test_text_plain_in_a_multipart_digestcCro)Nzmsg_12a.txtrprqr6r6r7�test_nested_multipart_mixeds,rsz+TestIdempotent.test_nested_multipart_mixedscCro)Nr�rprqr6r6r7�%test_message_external_body_idempotent0rsz4TestIdempotent.test_message_external_body_idempotentcCs"|�d�\}}|j||dd�dS)N�
msg_43.txtTr�rprqr6r6r7�test_message_delivery_status4sz+TestIdempotent.test_message_delivery_statuscCro�N�
msg_45.txtrprqr6r6r7�test_message_signed_idempotent8rsz-TestIdempotent.test_message_signed_idempotentcCsX|j}|�d�\}}||��d�i}|��D]\}}|||<q||dd�||dd�||jd|j�||j|j�|t|���d�|�d	�}||��d
�||��d|j�|�d�}||��d
�||��d|j�|�d
�}	||	��d�|�	|	t
�|	��}
|�	|
t�|t|
�d�|
d	}|�	|t
�||��d|j�dS)Nrrrrr�rz$This is a MIME-encapsulated message.r�rr;zYadda yadda yaddarxr�r4)r/r0rDr�r�r�r�r�rSrurr-)r3r4r5r��params�pk�pvr�rp�msg3rM�msg4r6r6r7�test_content_type<s4



z TestIdempotent.test_content_typecCs�|j}|�d�\}}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�|�|��t�||��|j	�dS)Nrxr4rxrr;)
r/r0rDrSrur-r�rr�r�)r3r4r5r�rMr�r6r6r7�test_parser[szTestIdempotent.test_parserN�F)r�r�r�r�r0rkrmrnrrrurvrwryrzr@r{r|r}r�rr�r�r�r�r�r�r�r�r6r6r6r7rg�
s4
rgc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwS)x�TestMiscellaneouscCsntddd��}|��}Wd�n1swYt�|�}t�}t|dd�}|�|�|�||���dS�Nr�rOr�rr�	r%r�r�r�rr
r�r/r��r3r�r�r5r�r�r6r6r7�test_message_from_stringos
�

z*TestMiscellaneous.test_message_from_stringcCsztddd��-}|��}|�d�t�|�}t�}t|dd�}|�|�|�||�	��Wd�dS1s6wYdSr�)
r%r��seekr�rGrr
r�r/r�r�r6r6r7�test_message_from_filezs


"�z(TestMiscellaneous.test_message_from_filecCs�tddd��}|��}Wd�n1swYGdd�dt�}t�||�}|�||�tddd��}|��}Wd�n1sCwYt�||�}|��D]}|�||�qRdS)Nr�rOr�c@�eZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN�r�r�r�r6r6r6r7�	MyMessage��r�rt)r%r�rr�r�ru�walk)r3r�r�r�r5r{r6r6r7�#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@r�)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageNr�r6r6r6r7r��r�r�r�rOr�rt)rr%r�rGrur�)r3r�r�r5r{r6r6r7�!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__r0��	__class__r6r7r��r}z\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)r�r�r�r��
__classcell__r6r6r�r7r��sr�zSubject: test

test)rr�ru)r3r�r5r6r6r7�.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 rF�message_from_binary_filer�rGr�r�r�r!r")�
__import__r/�sorted�__all__)r3�moduler6r6r7�test__all__�szTestMiscellaneous.test__all__cCs:t��}|�t�t�|��dd�t�|�dd��dS)N�)r�r/r"�	parsedate�
formatdate�gmtime�r3r�r6r6r7�test_formatdate�s�z!TestMiscellaneous.test_formatdatecCs>t��}|�t�tj|dd��dd�t�|�dd��dS)NT�r�r�)r�r/r"r�r�r�r�r6r6r7�test_formatdate_localtime�s
�z+TestMiscellaneous.test_formatdate_localtimec	CsVt��}|�tj|dd�t�dt�|���|�tj|ddd�t�dt�|���dS)NFr�z%a, %d %b %Y %H:%M:%S -0000T)r��usegmtz%a, %d %b %Y %H:%M:%S GMT)r�r/r"r�r�r�r�r6r6r7�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)�subTestrrr"r��parsedate_tz)r3�
invalid_datesr�r6r6r7�/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���:�rrxr��pzWed,3 Apr 2002 14:58:26 +0800zWed 3 Apr 2002 14:58:26 +0800�r/r"r�r0r6r6r7�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���
�/r�rrxr�透��zFebruary 5, 2003 13:47:26 -0800r��r3r4r6r6r7�test_parsedate_no_dayofweek��
�
�z-TestMiscellaneous.test_parsedate_no_dayofweekcC�|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26+0800r�r�r0r6r6r7�.test_parsedate_no_space_before_positive_offset���z@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCr�)NzWed, 3 Apr 2002 14:58:26-0800)
r�r�r�r�r�r�rrxr�r�r�r0r6r6r7�.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 -0800r�z5 Feb 2003 13.47 -0800)
r�r�r�r�r�rrrxr�r�r�r�r6r6r7�%test_parsedate_accepts_time_with_dots�r�z7TestMiscellaneous.test_parsedate_accepts_time_with_dotscCr�)NzFriday, 19-Nov-82 16:14:55 EST)
i����r��7rrxr�i����r�r0r6r6r7�test_parsedate_rfc_850r�z(TestMiscellaneous.test_parsedate_rfc_850cCr�)NzWed, 3 Apr 2002 14:58 +0800�
r�r�r�r�r�rrrxr�r�r�r0r6r6r7�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 +0800r�zWed, 3 Apr 2002 14.58 +0800r�r�r0r6r6r7�!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)Nr�r�z%Yr��	)	r/r"r��intr��mktimer�r�r�)r3r4�timetupr'r6r6r7�+test_parsedate_acceptable_to_time_functionss
 
 "z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCr�)N)
�rxrxrrrr�r�r�rr)
r�rxrxrrrr�r�r�i�i.���)r/r"�	mktime_tzr0r6r6r7�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 -0800Nr�r0r6r6r7�test_parsedate_y2k!s��z$TestMiscellaneous.test_parsedate_y2kcCs.|�t�d�d�|�t�t�d��d�dS)Nz<>�r*r*r*�r/r"�	parseaddr�
formataddrr0r6r6r7�test_parseaddr_empty.sz&TestMiscellaneous.test_parseaddr_emptycCr�)Nza@b@cr�za@b.c@cza@172.17.0.1@c�r/r"r�r0r6r6r7�test_parseaddr_multiple_domains2s���z1TestMiscellaneous.test_parseaddr_multiple_domainscCr�)N)zA Silly Person�person@dom.ainzA Silly Person <person@dom.ain>�r/r"r�r0r6r6r7�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��r3rr;r6r6r7�test_escape_dumpE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�r6r6r7�test_escape_backslashesP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>r9r�)r3r�addr�utf8_base64�
latin1_quoprir6r6r7�test_quotes_unicode_namesXs�z+TestMiscellaneous.test_quotes_unicode_namescsld}d}d}d�G�fdd�d�}|�}d�|f}|�t�||f|�|�|�t�||ftd��|�dS)	Nr�r�r��FOOBARcseZdZ�fdd�ZdS)zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockcs�Sr\r6)r3�string�r*r6r7�
header_encodeiszYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)r�r�r�rr6rr6r7�CharsetMockhsrz%s <%s>rO)r/r"r�r	)r3rr�r�r�mock�
mock_expectedr6rr7�$test_accepts_any_charset_like_objectbs�z6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|�ttj||f|�dS)Nr�r�)�objectr��AttributeErrorr"r�)r3rr��bad_charsetr6r6r7�-test_invalid_charset_like_object_raises_errorqs�z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|�ttjd|f�|�ttjd|f�dS)Nupersön@dom.in�Name)r��UnicodeErrorr"r��r3r�r6r6r7�!test_unicode_address_raises_errorz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�)r3ry�yrr;r6r6r7�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*rr�r�r6r6r7�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.comrz merwok  wok  @xample.com)r*�merwok"wok"  wok@xample.comr)r*zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.comr�r0r6r6r7�-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�)r3r��addrstrr6r6r7�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 Barrr�)r3ryr6r6r7�test_multiline_from_comment�sz-TestMiscellaneous.test_multiline_from_commentcCr�)N)zA Silly; Personr�z""A Silly; Person" <person@dom.ain>r�r0r6r6r7�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)NrI�US-ASCIIzUs-AsCiI�usascii�USASCII�UsAsCiI)r/�assertNotEqualr	)r3r4�ne�cset1�cset2r6r6r7�test_charset_richcomparisons�s$












z.TestMiscellaneous.test_charset_richcomparisonscCs"|j}|t�ddg�ddg�dS)N�aperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>�z	Al Personr�)z
Bud Personr��r/r"�getaddressesr�r6r6r7�test_getaddresses�s���z#TestMiscellaneous.test_getaddressescCs|�t�gd��gd��dS)zGH-106669 regression test.)z"Bud, Person" <bperson@dom.ain>r&z#"Mariusz Felisiak" <to@example.com>))zBud, Personr�r')zMariusz Felisiak�to@example.comNr(r0r6r6r7�test_getaddresses_comma_in_name�s��z1TestMiscellaneous.test_getaddresses_comma_in_namecCs�d}d}d}dd|�d�|fgfdd|f|d|fgfdd|f|d|f|gfdd|f|d|fgfd	d|�d
|�d�fgfdd|f|d|fgfd
||d|fgfdd|f|d|fgfdd|fd|fgfdd|dfd|fgfdd|fdd|�d�fgffD]S\}}|�|�d|�d�}|j|d��7|�t�|g�|g�|�tj|gdd�|�|�t�|g�|�|�tj|gdd�d|f�Wd�n1s�wYqz|�d|�d�}|�t�|g�d|fd|fg�|�tj|gdd�d|fd|fg�|�t�|g�|�|�tj|gdd�d|f�d}d}|�t�|g�|g�|�tj|gdd�|g�|�t�|g�|�|�tj|gdd�d|f�d}d}|�t�|g�|g�|�tj|gdd�|g�|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�|g�|�tj|gdd�gd��|�t�|g�|�|�tj|gdd�d|f�d}|�t�|g�ddg�|�tj|gdd�ddg�|�t�|g�|�|�tj|gdd�d|f�|�tjjd �dS)!z>Test for parsing errors from CVE-2023-27043 and CVE-2019-16056�alice@example.org�bob@example.comr��(�<�>�)r*�[z[<z>]�]�@�;�:�.�")�addressF��strictNz,<z,"Alice, alice@example.org" <bob@example.com>)zAlice, alice@example.orgr.zalice@example.org (Alice))�Alicer-zalice@example.org )Alice())r*r-r�)r*r=�<"Jane Doe" <jane@example.net>, "John Doe" <john@example.net>)zJane Doezjane@example.net)zJohn Doezjohn@example.netT)r�r/r"r)r�r��supports_strict_parsing)r3�alice�bob�empty�invalid_separator�expected_non_strictr:�expected_strictr6r6r7�test_parsing_errors�s��
������
�������������z%TestMiscellaneous.test_parsing_errorscCsdgdgfdgdgfddgddgfdgdgfd	gdgfd
ggd�fdgd
gfdgdgfdgdgfdgddgff
D].\}}|j|d��|�t�|�|�|�tj|dd�|�Wd�n1sawYq8dg}|�t�|�dg�|�tj|dd�gd��dS)Nu&"Sürname, Firstname" <to@example.com>)uSürname, Firstnamer+zfoo: ;r�z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerz
jason@dom.ainz=Pete(A nice \) chap) <pete(his account)@silly.test(his host)>)z)Pete (A nice ) chap his account his host)zpete@silly.testz<(Empty list)(start)Undisclosed recipients  :(nobody(I know))z=Mary <@machine.tld:mary@example.net>, , jdoe@test   . example))�Maryzmary@example.netr�)r*zjdoe@test.examplez*John Doe <jdoe@machine(comment).  example>)zJohn Doe (comment)zjdoe@machine.examplez3"Mary Smith: Personal Account" <smith@home.example>)zMary Smith: Personal Accountzsmith@home.examplezUndisclosed recipients:;z7<boss@nil.test>, "Giant; \"Big\" Box" <bob@example.net>)r*z
boss@nil.test)zGiant; "Big" Boxzbob@example.net)�	addressesFr;z	[]*-- =~$)r�r�)r*z*--)r�r/r"r))r3rHr�r6r6r7�test_getaddresses_nastyE
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>rrx�foo@bar.comNr()r3r4�addrsr6r6r7�"test_getaddresses_embedded_commentq
sz4TestMiscellaneous.test_getaddresses_embedded_commentcCs(t�td�g�}|�|ddd�dS)z%Test the handling of a Header object.zAl Person <aperson@dom.ain>rrxr�N)r"r)r
r/)r3rKr6r6r7�test_getaddresses_header_objw
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_msgidr��	monotonic)r3r�rS�clock�tfinr6r6r7�run
s

�zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)r�r�r�rWr6r6r6r7�MsgidsThread~
srXcsg|]}���qSr6r6r��rXr6r7rt�
�z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>r�cSsg|]}|j�qSr6)rR)rrr'r6r6r7rt�
rZ)rr�r#�
start_threads�sumr/r��set)r3�threads�all_idsr6rYr7�test_make_msgid_collisions|
s�z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||��d�dS)Nr$r zfoo\wacky"namer")r/rr&rpr2r6r6r7�test_utils_quote_unquote�
s�z*TestMiscellaneous.test_utils_quote_unquotecCstd�}|�|��d�dS)Nz
not a charsetrP�r	r/�get_body_encoding�r3r=r6r6r7�)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<rxrrOrPr�r)�aGVsbG8gd29ybGQ=
TrQr>ztext/plain; charset="US-ASCII"rIr�r�)
r/rrjr�r	rcrLrSrrm)r3r4r5rkr=r6r6r7�-test_get_body_encoding_with_uppercase_charset�
s.z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs(td�}td�}|�|��|���dS)NrIrrb)r3�lc�ucr6r6r7�test_charsets_case_insensitive�
sz0TestMiscellaneous.test_charsets_case_insensitivecCr�)Nr�aBmultipart/report
    text/plain
    message/delivery-status
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
        text/plain
    text/rfc822-headers
r�r�r6r6r7�1test_partial_falls_inside_message_delivery_status�
r�zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs"|�tjjdd�dd�d�dS)NrOrPi��z@testdomain-string>�r/r�r"rSr0r6r6r7�test_make_msgid_domain�
s�z(TestMiscellaneous.test_make_msgid_domaincCs$|�tjjddd�dd�d�dS)Nz
test-idstringrO)�idstringrQi���z!.test-idstring@testdomain-string>rlr0r6r6r7�test_make_msgid_idstring�
s���z*TestMiscellaneous.test_make_msgid_idstringcCsVtd��}d|_}|�tj���d|d��Wd�dS1s$wYdS)Nzsocket.getfqdnzpythontest.example.comr5r1)r�return_valuer�r�r"rS�endswith)r3�mock_getfqdnrQr6r6r7�test_make_msgid_default_domain�
s



��"�z0TestMiscellaneous.test_make_msgid_default_domaincCs|tdddd��}|��}Wd�n1swY|�dd�}t�|�}t�}tj�|�}|�|�|�	|�
�|�dS)N�
msg_26.txtrOr)�r��newliner�)r%r�r�r�r�rr�r
r�r/r��r3�f�msgtxt�	msgtxt_nlr5r�r�r6r6r7�test_Generator_linend�
s
�

z'TestMiscellaneous.test_Generator_linendcCs�tdddd��}|��}Wd�n1swY|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
��d�|�dS)NrtrOr)rur�r�r�)r%r�r�r�r�rr�rr�r/r�rRrwr6r6r7�test_BytesGenerator_linends
�
z,TestMiscellaneous.test_BytesGenerator_linendcCs�tdd��}|��}Wd�n1swY|�dd�}|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
�|�dS)	Nrtr�swith attachmentsfo��
r�r�r�)r%r�r�r�r�rr�rr�r/r�rwr6r6r7�)test_BytesGenerator_linend_with_non_asciis
�
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)
NrAr�r�)r*)r�r�r�)�clsr�r�r�)r%r�rrrrrrrr�r�rYr�r�r�r�)r3r��	audiodatar��classesr�constructorr�r6r6r7�!test_mime_classes_policy_arguments0
�
�
�����z3TestMiscellaneous.test_mime_classes_policy_argumentcCs8|�tt�d��gd��|�tt�d��ddg�dS)Nza\\b\"c\\"d)�rr)r��\\)r�r;)r�z\")r��c)�r�)r�r9)r��dza\r�)rx�\)r/r-r"�_iter_escaped_charsr0r6r6r7�test_iter_escaped_chars,s�	�z)TestMiscellaneous.test_iter_escaped_charscs|�fdd�}|dd�|dd�|dd�|d	d
�|dd�|d
d�|dd�|dd�dD]}��t�|�|�q0dS)Ncs��t�|�|�dSr\�r/r"�_strip_quoted_realnames)r�r�r0r6r7�check:rHz<TestMiscellaneous.test_strip_quoted_realnames.<locals>.checkr>z( <jane@example.net>,  <john@example.net>z""Jane \"Doe\"." <jane@example.net>z <jane@example.net>zbefore"name"after�beforeafterzbefore"name"�beforezb"name"r;z"name"after�afterz"name"arz"name"r*)z8Jane Doe <jane@example.net>, John Doe <john@example.net>zlone " quoter�)r3r�r�r6r0r7�test_strip_quoted_realnames9s ��





�z-TestMiscellaneous.test_strip_quoted_realnamescCsvd}|�t�|�d���|�t�|�d���|�t�|�d���|�t�|�d���|�t�d|����dS)Nzalice@example.netz (Alice)z )Alice(z	 (Alice))z	 ((Alice)z")Alice((" )r�r"�_check_parenthesisrrr6r6r7�test_check_parenthesisRsz(TestMiscellaneous.test_check_parenthesisN)>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�rr	r
rrrrrrr%r*r,rFrIrLrMr`rarergrjrkrmrorsr{r|r~r�r�r�r�r6r6r6r7r�nsx




			X,*
r�c@r>)�
TestIteratorscCs�|j}|j}|�d�}t�|�}t|�}|t|�d�|t�|�|�	��|�d�}t�|�}t|�}|t|�d�t
ddd��}|t�|�|���Wd�dS1sVwYdS)Nr�r�rt�+z
msg_19.txtrOr�)r/r�r0r �body_line_iteratorr-r��EMPTYSTRINGr�rSr%r�)r3r4r�r5�itr�r�r6r6r7�test_body_line_iterator_s



"�z%TestIterators.test_body_line_iteratorcCsb|j}|�d�}t�|d�}g}d}|D]
}|d7}|�|���q||d�|t�|�d�dS)Nrmr�rrxr�z`a simple kind of mirror
to reflect upon our own
a simple kind of mirror
to reflect upon our own
�r/r0r �typed_subpart_iteratorr�rSr�r��r3r4r5r�r��subpartsr{r6r6r7�test_typed_subpart_iteratorps

z)TestIterators.test_typed_subpart_iteratorcCsd|j}|�d�}t�|dd�}g}d}|D]
}|d7}|�|���q||d�|t�|�d�dS)Nr�r�rOrrxz%
Hi,

Do you like this message?

-Me
r�r�r6r6r7�(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�)r;r)zc
rx)r*r)zd
rx)ze
r)z
frx)r�rxr��BufferedSubFile�NeedMoreDatarxr*cS�g|]\}}|�qSr6r6)rr�il�nr6r6r7rt�ruz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
�email.feedparserr�r��push�iter�readliner�r/r�r�)r3�imtr�r��bsf�om�ntr�r��n1�olr6r6r7�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)Nrr�i'r�zabcd 	
r*c3s�|]}t��VqdSr\rr���charsr6r7r��r�z1TestIterators.test_push_random.<locals>.<genexpr>r)T)r�r�r�r�r�r&r�r��extendr�r�r/)r3r�r�r��	chunksizer��targetr�r�r��chunkr6r�r7�test_push_random�s 

zTestIterators.test_push_randomN)r�r�r�r�r�r�r�r�r6r6r6r7r�^sr�c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs"t�}|D]}|�|�q|��Sr\)r'�feed�close)r3�chunksr�r�r6r6r7�parse�szTestFeedParsers.parsecCs.|�d�}|�|dd�|�|dd�dS)NzFirst: val
: bad
Second: valr`�valrb)r�r/r^r6r6r7�test_empty_header_name_handled�s
z.TestFeedParsers.test_empty_header_name_handledcCs�|�dg�}|�|��gd��|�dg�}|�|��gd��|�ddg�}|�|��ddg�|�dd	g�}|�|��dd
g�|�ddg�}|�|��dd
g�|�dg�}|�|��d
g�|�gd��}|�|��ddg�dS)Nz
a:
b:
c:
d:
)rr;r�r�za:
b:
c:
d:za:
b�c:
r�bc�a:
zb:
r;z
b:
ua:…b:
c:
)ru	…b:
c:)r�ub:…r��rr*)r;u…c:)r�r/rkr�r�r6r6r7�
test_newlines�szTestFeedParsers.test_newlinescCsd\}}|�dgd|g|�}|�|��dg�|�|��d||�|�dgd|g|�}|�|��dg�|�|��d||�|�dgd|dg|�}|�|��dg�|�|��d|d|�|�ddgd|g|�}|�|��d	d
d||fg�dS)N)i�i Nza:b

ry)rr;za:b

�…r�zb: r�r;)r�r/r�rS)r3�M�Nr�r6r6r7�test_long_lines�s$zTestFeedParsers.test_long_linesN)r�r�r�r�r�r�r�r6r6r6r7r��s
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdZ
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�TestParserscCs�|j}tddd��}t��|�}Wd�n1swY||dd�||dd�||��d�|�|���|�|��t	�dS)	NrtrOr�r��ppp-request@zzz.orgr��ppp@zzz.orgra)
r/r%rr�rDrr�rurSr��r3r4r�r5r6r6r7�test_header_parser�s�zTestParsers.test_header_parsercCs�|j}tdd��}tj���|�}Wd�n1swY||dd�||dd�||��d�|�|���|�	|�
�t�|�	|j
dd	�t�dS)
Nrtr�r�r�r�r�raTrQ)
r/r%r�r�r�r�rDrr�rurSr�r�r�r6r6r7�test_bytes_header_parsers�z$TestParsers.test_bytes_header_parsercCsLtdd��}tj���|�|�|j�Wd�dS1swYdS)Nrtr�)r%r�r��BytesParserr�r�closedrDr6r6r7�%test_bytes_parser_does_not_close_files"�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�r<r�rr�)r3r��bytesParserr6r6r7�2test_bytes_parser_on_exception_does_not_close_files
�"�z>TestParsers.test_bytes_parser_on_exception_does_not_close_filecCsNtddd��}tj���|�|�|j�Wd�dS1s wYdS)NrtrOr�)r%r�r�rr�rr�rDr6r6r7�test_parser_does_not_close_files"�z+TestParsers.test_parser_does_not_close_filecCsdtddd��"}tjj}|�tjj|tjjd�j	|�|�
|j�Wd�dS1s+wYdS)Nr�rOr�r�)r%r�r�rr�rr�r�r<r�rr�)r3r�r�r6r6r7�,test_parser_on_exception_does_not_close_file s
�"�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�rSr2r6r6r7�test_whitespace_continuation'�


z(TestParsers.test_whitespace_continuationcCr�)Nz�From: aperson@dom.ain
To: bperson@dom.ain
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam
Subject: the next line has a space on it
 

Here's the message body
r,r�r=r�r�r�r2r6r6r7�(test_whitespace_continuation_last_header9r�z4TestParsers.test_whitespace_continuation_last_headercCs�|j}tdddd��}t��|�}Wd�n1swY|t|���d�|�d�}||��d�||��d�|�d	�}||��d
�dS)NrtrOr)rur�rr;z!Simple email with attachment.

rxzapplication/riscos)r/r%rr�r�rSrD)r3r4r�r5�part1�part2r6r6r7�test_crlf_separationKs�

z TestParsers.test_crlf_separationcCsptdddd��}|��}Wd�n1swYt�|�}t�}t|�}|j|dd�|�|��|�dS)NrtrOr)rur�r�r�r�r6r6r7�test_crlf_flattenVs
�
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<rOr�rxr�rr4r;rRrS)	r/r�r%r�rGr�r�rSrD)	r3r4r�r�r5r��part1ar��part2ar6r6r7�-test_multipart_digest_with_extra_mime_headersbs.�



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/)r3r�r5r6r6r7�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)r3r4�value1�value2r�r5r6r6r7�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\r6)rr�fieldr6r6r7r����z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>)z!"#QUX;~z>Fromr�r�)r/r�r�r�r�rSr)r6r6r7�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�rkr)r6r6r7�(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�B�CCr�)r/r�r�rk�sortrS)r3r4r�r5�headersr6r6r7�!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�rSrq�r3r�r5r6r6r7�test_CRLFLF_at_end_of_part�s�

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

        {bodyline}
        cCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)NrOrX�pöstal�r=r��bodyline�pöstal
TrQ��bodytest_msgr�r�r�r�r/rSr�r6r6r7�test_known_8bit_CTE����
�z)Test8BitBytesHandling.test_known_8bit_CTEcC�P|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
N�notavalidcharsetrXr�r�rOup��stal
TrQr�r�r�r6r6r7�test_unknown_8bit_CTE�rz+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)	NrOr?�p=C3=B6stálr�u
p=C3=B6stál
TrQ�	pöstál
r�r�r6r6r7�test_8bit_in_quopri_body�s
��
�z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCr)
Nr�r?rr�rOup=C3=B6st��l
TrQrr�r�r6r6r7�.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)	NrOrPu
cMO2c3RhbAá=r�TrQr�r)r�r�r�r�r�r/rSrurvrrwr�r6r6r7�test_8bit_in_base64_bodys��
��z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd��d�}t�|�}|�|jdd�d�d��dS)NrOr�u
<,.V<W1A; á r�TrQu<,.V<W1A; á 
r�r�r6r6r7�test_8bit_in_uuencode_bodys��
�z0Test8BitBytesHandling.test_8bit_in_uuencode_body))zFrom: foo@bar.com�r�rJ)uTo: báz)r�z=?unknown-8bit?q?b=C3=A1z?=)uVSubject: Maintenant je vous présente mon collègue, le pouf célèbre
	Jean de Baddie)r�z�=?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=
 =?unknown-8bit?q?_Jean_de_Baddie?=)uFrom: göst)r�z=?unknown-8bit?b?Z8O2c3Q=?=r)cCr�r6r6)rr�src�_r6r6r7rt(ruz Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
rOcCs:t�|j�}|�t|�d��d�|�t|d�d�dS)Nr��b��z)r�r��headertest_msgr/r�r�r^r6r6r7�test_get_8bit_header+sz*Test8BitBytesHandling.test_get_8bit_headercCs8t�|j�}|�t|�t�d�jdd�|jD���dS)Nz�                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            cSsg|]\}}|d�qS)rxr6)rrr
r�r6r6r7rt:szATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	r�r�rr/r�r�r�r��headertest_headersr^r6r6r7�test_print_8bit_headers0s
���z-Test8BitBytesHandling.test_print_8bit_headerscC�.t�|j�}|�dd�|��D�gd��dS)NcSr�r6�r�r�r6r6r7rt?ruzGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>)rJr�]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie�	g��st)r�r�r�assertListEqualrlr^r6r6r7�test_values_with_8bit_headers=��z3Test8BitBytesHandling.test_values_with_8bit_headerscCr)NcSs g|]\}}t|�t|�f�qSr6r)rrryrr6r6r7rtJs zFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>)r)r�r)r�r)r�r)r�r�rrr�r^r6r6r7�test_items_with_8bit_headersHrz2Test8BitBytesHandling.test_items_with_8bit_headerscCs0t�|j�}|�dd�|�d�D�ddg�dS)NcSr�r6rr�r6r6r7rtVruzHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�rJr)r�r�rrr1r^r6r6r7�test_get_all_with_8bit_headersTs��z4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsJt�t�d��d��}|�|��d�|�|��d�|�|��d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            r�utext/pl�inr�upl�in)	r�r�r�r�r�r/rDrCrQr^r6r6r7�test_get_content_type_with_8bitZs�z5Test8BitBytesHandling.test_get_content_type_with_8bitcCsXt�d�d��}|�|jdd�gd��|�|jddd�d�|�|jddd�d�dS)	Nu(X-Header: foo=§ne; b§r=two; baz=three
r�r�r�))r���ne)ub�rr�r��Foorub§r)r�r�r�r/r�rEr^r6r6r7�test_get_params_with_8bitcs��z/Test8BitBytesHandling.test_get_params_with_8bitcCs,t�t�d��d��}|�|�d�d�dS)N�n            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nr��title)rI�enuThis is not f�n)r�r�r�r�r�r/rEr^r6r6r7�!test_get_rfc2231_params_with_8bitms��z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8t�t�d��d��}|�dd�|�|�d�d�dS)Nr r�r!�test)r�r�r�r�r�rr/rEr^r6r6r7�!test_set_rfc2231_params_with_8bitus
�z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFt�t�d��d��}|�d�|�|�d�d�|�|��d�dS)Nr r�r!r�)	r�r�r�r�r�rr/rErCr^r6r6r7�!test_del_rfc2231_params_with_8bit}s�
z7Test8BitBytesHandling.test_del_rfc2231_params_with_8bitcCs>t�t�d��d��}|�|��d�|�|jdd�d�dS)Nu�            Content-Transfer-Encoding: b§se64
            Content-Type: text/plain; charset=latin-1

            payload
            r�zpayload
TrQspayload
)r�r�r�r�r�r/rSr^r6r6r7�%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��r3r5r�r6r6r7�test_bytes_generator��z*Test8BitBytesHandling.test_bytes_generatorcCs6tj��}t�}tj�|��|�|�|��d�dS)Nr�)	r�rFrrr�rr�r/r�r)r6r6r7�&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�r(rr�r
r�r/r�� non_latin_bin_msg_as7bit_wrappedr)r6r6r7�test_generator_handles_8bit�r+z1Test8BitBytesHandling.test_generator_handles_8bitcCs`t�|j�}t�}t|��|�|��}tt���|�t�}t|��|�|�	|��|�dSr\)
r�r�r(rrr�r�r
rr/)r3r5r��
orig_valuer6r6r7�;test_str_generator_should_not_mutate_msg_when_handling_8bit�szQTest8BitBytesHandling.test_str_generator_should_not_mutate_msg_when_handling_8bitcCsnt�|j�}t�}tj�|�j|dd�|���d�}|�	|d��dd�|�	d�
|dd��|j�dS)NTr�r�rsFromrx)r�r�r(rr�rr�r�r�r/r�)r3r5r�r�r6r6r7�#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�)�
addCleanupr$�open�writer(r�r�r�r�r/r��non_latin_bin_msg_as7bit)r3r�testfiler�r6r6r7�test_message_from_binary_file�s��z3Test8BitBytesHandling.test_message_from_binary_fileu        From: foo@bar.com
        To: Dinsdale
        Subject: Nudge nudge, wink, wink
        Mime-Version: 1.0
        Content-Type: text/plain; charset="latin-1"
        Content-Transfer-Encoding: 8bit

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

        oh l=E0 l=E0, know what I mean, know what I mean?
        cCs"t�|j�}|�t|�|j�dSr\)r�r��
latin_bin_msgr/r��latin_bin_msg_as7bitr�r6r6r7�: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)Nr�r))
r�r�r9rr�rr�r/r�rR)r3r�r�r6r6r7�)test_decoded_generator_emits_unicode_body�s
�z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCsXtj��}tdt|j�d�D]}|�|j||d��q|��}|�t	|�|j
�dS)Nrr�)r�r�r(r�r�r9r�r�r/r�r:)r3�bfpr�r�r6r6r7�test_bytes_feedparsers

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

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

            Guten Tag, ,

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


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

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

            rO)r�r�r�r�r�rr�rr�r/r�)r3r�r5r�r�r6r6r7�test_8bit_multiparts%�
&
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��r3r�r�r�r6r6r7�'test_bytes_generator_b_encoding_linesepB��z=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesepcCr@)NrAr�r�r�z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr
rr�r�r
r�r/r�rBr6r6r7�!test_generator_b_encoding_linesepNrDz7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/r�r�r�r�r�r�rrrrr	r
rr�r�rrrrrrrrr#r%r&r'r(r*r,r-r.r0r1r�r6r8r9r:r;r<r>r�r?rCrEr.r6r6r6r7r��sf
	
		

��
	
	

�



�
		�

	.r�c@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNcCsTt|d��}|��}Wd�n1swY|j�|j|�}t�|�}||fS)Nr�)r%r��normalize_linesep_regex�sub�blinesepr�r�rjr6r6r7r0as
�
z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|�||���dS)Nrr)r�r�)rr�r�rr�r�r/r�)r3r5rUr�r;r�r6r6r7rkhsz,BaseTestBytesGeneratorIdempotent._idempotentr�)r�r�r�r.r0rkr6r6r6r7rF]srFc@�eZdZdZdZe�d�ZdS)�TestBytesGeneratorIdempotentNLr)r�s\r\nN�r�r�r�r�rI�re�compilerGr6r6r6r7rKo�rKc@rJ)� TestBytesGeneratorIdempotentCRLFr�r}s	(?<!\r)\nNrLr6r6r6r7rPvrOrPc@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��r��ry)r/r�
header_lengthr��body_encoder�)r3r4�size�bsizer6r6r7�test_len~s
��zTestBase64.test_lencCr�)Nr*�zaGVsbG8=rS)r/rrRr�r6r6r7�test_decode�r�zTestBase64.test_decodecCsd|j}|t�d�d�|t�d�d�|t�d�d�|tjddd	�d
�|tjdddd�d
�dS)Nr^r*rSz	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�rUz�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r/rrZr�r6r6r7�test_encode�s�zTestBase64.test_encodecCsZ|j}tj}||d�d�||d�d�||d�d�||ddd�d	�||d�d�dS)
NrRz=?iso-8859-1?b?aGVsbG8=?=�hello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=�hello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=rgr)z=?iso-8859-2?b?aGVsbG8=?=)r/rr)r3r4�her6r6r7�test_header_encode�szTestBase64.test_header_encodeN)r�r�r�r]r_rbrfr6r6r6r7rQ}s

rQc@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�zrxr��Zr��9csr�r\r6�rrr�r6r6r7r��r�z#TestQuopri.setUp.<locals>.<genexpr>s!*+-/c�g|]	}|�jvr|�qSr6)�hlitrkr0r6r7rt��z$TestQuopri.setUp.<locals>.<listcomp>�r+�~r��=crlr6)�blitrkr0r6r7rt�rn)r-rr��ordrm�hnonr�rrr��remove�bnonr0r6r0r7r1�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)rmrr!�header_check�chrrtr��r3r�r6r6r7�test_quopri_header_check��

�

��z#TestQuopri.test_quopri_header_checkcCrw)Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)rrrr!�
body_checkryrvr�rzr6r6r7�test_quopri_body_check�r|z!TestQuopri.test_quopri_body_checkcCs�|j}|t�d�d�|ttjddd��t�d�d�|t�d�d�|ttjddd��t�d�d�|jD]}|t�t|g��dd	t|��q8|jD]}|t	d
�krWqN|t�t|g��ddt|��qN|t�d
�d�dS)NrSr��xxxr)r�s
h@e@l@l@o@rXrxzexpected length 1 for %rr+r�zexpected length 3 for %r� )
r/r!rYr�rrmr�ryrtrs�r3r4r�r6r6r7�test_header_quopri_len�s0����

�

�z!TestQuopri.test_header_quopri_lencCsN|j}|jD]
}|t�t|g��d�q|jD]
}|t�t|g��d�qdS)Nrxr�)r/rrr!�body_lengthr�rvr�r6r6r7�test_body_quopri_len�s

�zTestQuopri.test_body_quopri_lencCs2td�D]}t|�}|�t�t�|��|�qdS)Nro)r�ryr/r!r�quote)r3ryr�r6r6r7�test_quote_unquote_idempotent�s�z(TestQuopri.test_quote_unquote_idempotentNcCs0|dur
t�|�}nt�||�}|�||�dSr\)r!rr/)r3r��expected_encoded_headerr=�encoded_headerr6r6r7�_test_header_encode�szTestQuopri._test_header_encodecC�|�dd�dS)Nr^r*�r�r0r6r6r7�test_header_encode_null�z"TestQuopri.test_header_encode_nullcCr�)NrSz=?iso-8859-1?q?hello?=r�r0r6r6r7�test_header_encode_one_wordr�z&TestQuopri.test_header_encode_one_wordcCr�)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=r�r0r6r6r7�test_header_encode_two_lines
��z'TestQuopri.test_header_encode_two_linescCr�)Nshello�therez=?iso-8859-1?q?hello=C7there?=r�r0r6r6r7�test_header_encode_non_asciir�z'TestQuopri.test_header_encode_non_asciicC�|jdddd�dS)NrSz=?iso-8859-2?q?hello?=rgr)r�r0r6r6r7�test_header_encode_alt_charsets
�z)TestQuopri.test_header_encode_alt_charsetcCst�|�}|�||�dSr\)r!�
header_decoder/)r3r��expected_decoded_header�decoded_headerr6r6r7�_test_header_decodes
zTestQuopri._test_header_decodecC�|�dd�dS�Nr*�r�r0r6r6r7�test_header_decode_nullr�z"TestQuopri.test_header_decode_nullcCr��NrRr�r0r6r6r7�test_header_decode_one_wordr�z&TestQuopri.test_header_decode_one_wordcCr�)Nz
hello=0Aworldrdr�r0r6r6r7�test_header_decode_two_lines r�z'TestQuopri.test_header_decode_two_linescCr�)Nz
hello=C7thereuhelloÇtherer�r0r6r6r7�test_header_decode_non_ascii#r�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=30�00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)r/r!r�r0r6r6r7�test_header_decode_re_bug_18380&sz*TestQuopri.test_header_decode_re_bug_18380cCs2|dur
t�|�}ntj||d�}|�||�dS)NrT)r!rRr/)r3�encoded�expected_decodedrU�decodedr6r6r7�_test_decode*szTestQuopri._test_decodecCr�r��r�r0r6r6r7�test_decode_null_word1r�z TestQuopri.test_decode_null_wordcCr�)Nr�r)r�r0r6r6r7�test_decode_null_line_null_word4r�z*TestQuopri.test_decode_null_line_null_wordcCr�r�r�r0r6r6r7�test_decode_one_word7r�zTestQuopri.test_decode_one_wordcCs|jdddd�dS)NrR�XrTr�r0r6r6r7�test_decode_one_word_eol:�z#TestQuopri.test_decode_one_word_eolcCr��N�hello
�hello
r�r0r6r6r7�test_decode_one_line=r�zTestQuopri.test_decode_one_linecCr��Nr�r�r0r6r6r7�test_decode_one_line_lf@r�z"TestQuopri.test_decode_one_line_lfcCr�)Nzhello
r�r�r0r6r6r7�test_decode_one_line_crCr�z"TestQuopri.test_decode_one_line_crcCr�)Nr��helloXr�rTr�r0r6r6r7�test_decode_one_line_nlFr�z"TestQuopri.test_decode_one_line_nlcCr�)Nr�r�r�rTr�r0r6r6r7�test_decode_one_line_crnlIr�z$TestQuopri.test_decode_one_line_crnlcCr�)Nrcrdr�r0r6r6r7�test_decode_one_line_one_wordLr�z(TestQuopri.test_decode_one_line_one_wordcCr�)Nrc�helloXworldr�rTr�r0r6r6r7�!test_decode_one_line_one_word_eolOr�z,TestQuopri.test_decode_one_line_one_word_eolcCr�)N�hello
world
�hello
world
r�r0r6r6r7�test_decode_two_linesRr�z TestQuopri.test_decode_two_linescCr�)Nr��helloXworldXr�rTr�r0r6r6r7�test_decode_two_lines_eolUr�z$TestQuopri.test_decode_two_lines_eolcCr�)N��SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamr�r0r6r6r7�test_decode_one_long_lineXr�z$TestQuopri.test_decode_one_long_linecCr�)Nr+r*r�r0r6r6r7�test_decode_one_space[r�z TestQuopri.test_decode_one_spacecCr�)Nz     r*r�r0r6r6r7�test_decode_multiple_spaces^r�z&TestQuopri.test_decode_multiple_spacescCr�)Nzhello    
r�r�r0r6r6r7�$test_decode_one_line_trailing_spacesar�z/TestQuopri.test_decode_one_line_trailing_spacescCr�)Nzhello    
world   
r�r�r0r6r6r7�%test_decode_two_lines_trailing_spacesdr�z0TestQuopri.test_decode_two_lines_trailing_spacescCr�)Nz=22quoted=20words=22z"quoted words"r�r0r6r6r7�test_decode_quoted_wordgr�z"TestQuopri.test_decode_quoted_wordcCr�)Nzab=CD=EF�abÍïr�r0r6r6r7�test_decode_uppercase_quotingjr�z(TestQuopri.test_decode_uppercase_quotingcCr�)Nzab=cd=efr�r�r0r6r6r7�test_decode_lowercase_quotingmr�z(TestQuopri.test_decode_lowercase_quotingcCr�)Nzsoft line=
breakzsoft linebreakr�r0r6r6r7�test_decode_soft_line_breakpr�z&TestQuopri.test_decode_soft_line_breakcCr�)NzA=1,B=A ==> A+B==2r�r0r6r6r7�test_decode_false_quotingsr�z$TestQuopri.test_decode_false_quotingcCs�i}|dur	d}n||d<|durd}n||d<tj|fi|��}|�||�|dks/|dkr>|��D]}|�t|�|�q3dSdS)Nr�r�r)rUr�)r!rZr/r&r�r�)r3r��expected_encoded_bodyr�rU�kwargs�encoded_bodyr�r6r6r7�_test_encodevs�zTestQuopri._test_encodecCr�r��r�r0r6r6r7�test_encode_null�r�zTestQuopri.test_encode_nullcCr�)Nz

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

1234r�r�r�r0r6r6r7�,test_encode_trailing_space_before_maxlinelen�r�z7TestQuopri.test_encode_trailing_space_before_maxlinelencCr�)Nr�zabcd=
=20
1234r�r�r�r0r6r6r7�(test_encode_trailing_space_at_maxlinelen�r�z3TestQuopri.test_encode_trailing_space_at_maxlinelencCr�)Nr�zabc=
d=20
1234r�r�r�r0r6r6r7�,test_encode_trailing_space_beyond_maxlinelen�r�z7TestQuopri.test_encode_trailing_space_beyond_maxlinelencCr�)Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
r�r0r6r6r7�test_encode_whitespace_lines�r�z'TestQuopri.test_encode_whitespace_linescCr�)Nza = bza =3D br�r0r6r6r7�test_encode_quoted_equals�r�z$TestQuopri.test_encode_quoted_equalscCr�)N�dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxr�r0r6r6r7�test_encode_one_long_string�r�z&TestQuopri.test_encode_one_long_stringcCr�)Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
r�r0r6r6r7�test_encode_one_long_line�r�z$TestQuopri.test_encode_one_long_linecCr�)Nz�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
z�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r�r0r6r6r7�test_encode_one_very_long_line�r�z)TestQuopri.test_encode_one_very_long_linecCr�)Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr�r�r�r0r6r6r7�test_encode_shortest_maxlinelen�r�z*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr*r�r�)r�r-r�r0r6r6r7� test_encode_maxlinelen_too_small�sz+TestQuopri.test_encode_maxlinelen_too_smallcCst|j}|t�d�d�|t�d�d�|t�d�d�|tjddd�d�|tjddd	d
�d�|t�d�d�dS)
Nr*rRrcrd�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�razlxxxx 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!rZr�r6r6r7rb�s�
�zTestQuopri.test_encoder\)NN)Fr�r�r�r1r{r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rbr6r6r6r7rg�s�


rgc@r�)
�TestCharsetcCs0ddlm}z|jd=WdStyYdSw)Nrr)�fake)r�r=�CHARSETSrn)r3�
CharsetModuler6r6r7�tearDown�s�zTestCharset.tearDowncCsN|j}td�}||�d�d�d}|�t|j|�td�}||�|�d�dS)NrI�Hello World!u¤¢¤¤¤¦¤¨¤ªrOz(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r/r	rr�r)r3r4r�r�r6r6r7�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)
Nr9z
hello w=F6rlduhello wörldrOrfr�rIr�r�rr)r�)r/r	rZr�r=�add_charset�QP)r3r4r�r�r6r6r7�test_body_encodeszTestCharset.test_body_encodecCs,td�}|�t|�d�|�tjtd�dS)NrIuascÿii)r	r/r�r�r�CharsetErrorrdr6r6r7�test_unicode_charset_name%sz%TestCharset.test_unicode_charset_nameN)r�r�r�r�r�r�r�r6r6r6r7r��s
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)4�
TestHeadercC�8|j}td�}||��d�|�d�||��d�dS)Nr�z Goodbye World!zHello World!  Goodbye World!�r�r
r�r�r�r6r6r7�test_simple.�

zTestHeader.test_simplecCr�)Nr�zGoodbye World!zHello World! Goodbye World!r�r�r6r6r7�test_simple_surprise5r�zTestHeader.test_simple_surprisecCsd}|�t|�|dfg�dS)Nzno decoding neededrr�r6r6r7�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+)�
splitcharsz
 )r
r�r�r�r�)r3r��lr6r6r7�	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)Nr9rgrOr�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�rrxr�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�rRr)
r3r4r�r�r�r�r�r�r��encr��ustr�newhr6r6r7�test_multilingualFs0

�zTestHeader.test_multilingualcCr2r�r�r�r6r6r7�test_empty_header_encode�r�z#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|�dtd��||d�dS)Nr*r�r9)r�r
r�r	r�r6r6r7�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�r6r6r7�test_explicit_maxlinelen�sz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�d�|��}||d�||ttt|����dS)Nr9rX�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�r3r4r�ryr�r6r6r7�test_quopri_splittable�s

3

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

#

z!TestHeader.test_base64_splittablecCs8|j}d}t|�}||dg�t|�}|||���dS)NrR)rRN�r/rrr�)r3r4r�ryr�r6r6r7�test_us_ascii_headerszTestHeader.test_us_ascii_headercCs&|j}t�}|�dd�||d�dS)NrRr9)r/r
r�r�r6r6r7�test_string_charset&szTestHeader.test_string_charsetcCs:|j}tdd�}||��d�tdd�}||��d�dS)Nr�rOz=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=�r/r
r�r�r6r6r7�test_utf8_shortest5s


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 BigrOr�r)r�r/rr
r�rRr�)r3r�r4ryr��er6r6r7�test_bad_8bit_header<szTestHeader.test_bad_8bit_headercCsNd}|�dd�}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS)Nrr��surrogateescaper)�2Ynwp4dUEbay Auction Semiar- No Charge � Earn Big�unknown-8bit)	rRr
r�r=�UNKNOWN8BITr/r�r�r)r3ryrr�r6r6r7�test_escaped_8bit_headerHs
�z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS�Nrr)rr)r
r�r=rr/r�r�r)r3ryr�r6r6r7�&test_header_handles_binary_unknown8bitPs
�z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tj�tj�|��}|�t|�d�|�tj�|�|dfg�dSr)	r
r�r=rr�rrr/r�)r3ryr��h2r6r6r7�+test_make_header_handles_binary_unknown8bitWs
�z6TestHeader.test_make_header_handles_binary_unknown8bitcCs2td�}tj�|�}|�d�|�t|�d�dS)Nr$)r��test2)r
r�r�rr�r/r�)r3r�r�r6r6r7�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)NrRr9�worldz=?iso-8859-1?q?hello?= world)r/r
r�r�rr)r3r4r�r�r6r6r7� test_encoded_adjacent_nonencodedes

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������� � ��������rh)s zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.r
)r3r4r��parts�hdrr6r6r7�test_whitespace_keeperos�z!TestHeader.test_whitespace_keepercCs|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r�rr�r)r3r�r�r6r6r7�test_broken_base64_headerxsz$TestHeader.test_broken_base64_headercCs tddd�}|�|��d�dS)Nr��	shift_jisr)r�r�r�r6r6r7�test_shift_jis_charset}rTz!TestHeader.test_shift_jis_charsetcCst�d�}|�t|�d�dS)NzEmptyHeader:zEmptyHeader: 

)r�r�r/r�r^r6r6r7�!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 ws�
SomeHeaderz&SomeHeader:    value with leading ws

)rr/r�r^r6r6r7�)test_encode_preserves_leading_ws_on_value�r^z4TestHeader.test_encode_preserves_leading_ws_on_valuecCs|�td���d�dS)Nr+rr0r6r6r7�test_whitespace_header�sz!TestHeader.test_whitespace_headerN)r�r�r�r�r�r�rrrrrrrrrrrrrrrr!r$r%r'r(r*r+r6r6r6r7r�-s4?E6
	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=S)>�TestRFC2231cCs8|j}|�d�}||�d�d�||jddd�d�dS)Nz
msg_29.txtr!�rIr"�%This is even more ***fun*** isn't it!Fr)rIr"z'"This is even more ***fun*** isn't it!")r/r0rEr2r6r6r7r�s

��zTestRFC2231.test_get_paramcCs�|j}t�}|jdddd�||�d�d�|jddddd�||�d�d�|�d	�}|jddddd�||jd
d�d�dS)
Nr!r.rIr))rIr*r.r"�r=�languager-r�rra"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�rrrEr0r�r2r6r6r7r�s&�
��
�
�zTestRFC2231.test_set_paramcCsft�}|�dd�|�|dd�|jdddd�|�|dd�|jdd	dd�|�|dd
�dS)Nr!r�r<ztext/plain; title="foo"r�F)�requoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")rrr/r^r6r6r7�test_set_param_requote�sz"TestRFC2231.test_set_param_requotecCsX|j}|�d�}|jddddd�|jddddd�|jdd	d
�||jdd�d
�dS)Nr�r�r�rIr"r/r!r.r@r�rra$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�r0rrr�r2r6r6r7r�s
�zTestRFC2231.test_del_paramcCr)Nr~rI)r/r0�get_content_charsetr2r6r6r7� test_rfc2231_get_content_charset�r�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/rpr�r�r6r6r7�test_rfc2231_parse_rfc_quoting��


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

            r6r7r�r6r6r7� test_rfc2231_parse_extra_quotingr9z,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�rE�assertNotIsInstance�tupler/�r3r�r5�paramr6r6r7�#test_rfc2231_no_language_or_charsets

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

r6r�r�r6r6r7�/test_rfc2231_no_language_or_charset_in_filename"�


�z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamecCrCrDr�r�r6r6r7�7test_rfc2231_no_language_or_charset_in_filename_encoded/rFzCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedcCrC)Nz�Content-Disposition: inline;
	filename*0="''This%20is%20even%20more%20";
	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2="is it not.pdf"

z1This%20is%20even%20more%20***fun*** is it not.pdfr�r�r6r6r7�test_rfc2231_partly_encoded=�
�z'TestRFC2231.test_rfc2231_partly_encodedcCrC)Nz�Content-Disposition: inline;
	filename*0="This%20is%20even%20more%20";
	filename*1="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2="is it not.pdf"

z?This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdfr�r�r6r6r7�test_rfc2231_partly_nonencodedJrIz*TestRFC2231.test_rfc2231_partly_nonencodedcCrC)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"

r6r�r�r6r6r7�/test_rfc2231_no_language_or_charset_in_boundaryWrFz;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundarycCrC)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/r3r�r6r6r7�.test_rfc2231_no_language_or_charset_in_charsetcs


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

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

rLr�r6r6r7�$test_rfc2231_bad_encoding_in_charset}�
z0TestRFC2231.test_rfc2231_bad_encoding_in_charsetcCrO)Nz:Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D

rLr�r6r6r7�%test_rfc2231_bad_character_in_charset�rQz1TestRFC2231.test_rfc2231_bad_character_in_charsetcCrC)Nz�Content-Disposition: inline;
	filename*0*="ascii'xx'This%20is%20even%20more%20";
	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
	filename*2*="is it not.pdf%E2"

u,This is even more ***fun*** is it not.pdf�r�r�r6r6r7�&test_rfc2231_bad_character_in_filename�rFz2TestRFC2231.test_rfc2231_bad_character_in_filenamecCrC)Nz^Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt

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

rTr�r�r6r6r7�&test_rfc2231_bad_character_in_encoding�rVz2TestRFC2231.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�r3r4r�r5r=r0r�r6r6r7�-test_rfc2231_single_tick_in_filename_extended��


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

rrXr=r@r6r6r7�$test_rfc2231_single_tick_in_filename�s


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

rrI�en-usrXrrYr6r6r7�!test_rfc2231_tick_attack_extended�r[z-TestRFC2231.test_rfc2231_tick_attack_extendedcCr;)NzWContent-Type: application/x-foo;
	name*0="us-ascii'en-us'Frank's"; name*1=" Document"

rzus-ascii'en-us'Frank's Documentr=r@r6r6r7�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"

rrXrr)r6r6r7�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"

rrIra�My Document For YourrYr6r6r7�,test_rfc2231_encoded_then_unencoded_segments�


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

rrIrarerrYr6r6r7�,test_rfc2231_unencoded_then_encoded_segmentsrgz8TestRFC2231.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�)r�r�r�)r3�messagesr�r5r6r6r7�+test_should_not_hang_on_invalid_ew_messages s����z7TestRFC2231.test_should_not_hang_on_invalid_ew_messagesN)!r�r�r�rrr2rr4r8r:rBrErGrHrJrKrMrNrPrRrSrUrWrZr\r]r_rbrcrdrfrhrjr6r6r6r7r,�s>%
!




		


r,c@r>)�
TestSignedcCsLt|dd��}|��}t�|�}Wd�||fS1swY||fSrhri)r3r#r��originalr5r6r6r7�_msg_and_obj<s
��zTestSigned._msg_and_objcCsLddl}|�d|j|jB�}|�|��d�}|�|��d�}|�||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$r�)rMrN�Sr��search�groupr/)r3rl�resultrM�repart�inpart�outpartr6r6r7�_signed_parts_eqBs
zTestSigned._signed_parts_eqcCs&|�d�\}}|��}|�||�dSr��rmr�ru�r3rlr5rqr6r6r7�test_long_headers_as_stringJsz&TestSigned.test_long_headers_as_stringcCs*|�d�\}}|jdd�}|�||�dS)Nr��<rrvrwr6r6r7�(test_long_headers_as_string_maxheaderlenOsz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|�d�\}}t�}t|��|�|��}|�||�dSr�)rmrr
r�r�ru)r3rlr5r�rqr6r6r7�test_long_headers_flattenTs
z$TestSigned.test_long_headers_flattenN)r�r�r�rmrurxrzr{r6r6r6r7rk:srkc@rN)�TestHeaderRegistrycCs(t�}|dd�}|�|jdtj�dS)Nrzattachment; 0*00="foo"r)rrurvr�InvalidHeaderDefect)r3�regrr6r6r7�test_HeaderRegistry]s
z&TestHeaderRegistry.test_HeaderRegistryN)r�r�r�rr6r6r6r7r|[sr|�__main__)frMr�rPr�r��iorr�	itertoolsr�randomr�	threadingr�
unittest.mockrr��email.policy�email.utils�
email.charsetr	�email.generatorr
rr�email.headerr
rr�email.headerregistryr�
email.messager�email.mime.applicationr�email.mime.audior�email.mime.baser�email.mime.imager�email.mime.messager�email.mime.multipartr�email.mime.nonmultipartr�email.mime.textr�email.parserrrrrrr r!r"�test.supportr#�test.support.os_helperr$�test.test_emailr%r&r'r(r�r�r�r,�TestCaser�r�r/r?r`rdryr�r�r�r(rdrgr�r�r�r�r�rFrKrPrQrgr�r�r,rkr|r��mainr6r6r6r7�<module>s�lCAO((\<09 ug0K!��4D:h*!
�

Youez - 2016 - github.com/yon3zu
LinuXploit