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

��g�5�@s�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZddlmZddlmZmZmZdd	lmZmZdd
lmZmZmZddlm 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/m0Z0ddlm1Z1ddlm2Z2ddlm3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddl7m8Z8m9Z9ddl:m;Z;m<Z<ddlm=Z=m>Z>dZ?dZ@dZAGd d!�d!e<�ZBGd"d#�d#ejC�ZDGd$d%�d%e<�ZEGd&d'�d'ejC�ZFGd(d)�d)ejC�ZGGd*d+�d+ejC�ZHGd,d-�d-ejC�ZIGd.d/�d/ejC�ZJGd0d1�d1e<�ZKGd2d3�d3e<�ZLGd4d5�d5e<�ZMGd6d7�d7e<�ZNGd8d9�d9e<�ZOGd:d;�d;e<�ZPGd<d=�d=e<�ZQGd>d?�d?e<�ZRGd@dA�dAe<�ZSGdBdC�dCe<�ZTGdDdE�dE�ZUGdFdG�dGeUeO�ZVGdHdI�dIeUeO�ZWGdJdK�dKejC�ZXGdLdM�dMejC�ZYGdNdO�dOejC�ZZGdPdQ�dQe<�Z[GdRdS�dSe<�Z\GdTdU�dUe<�Z]e^dVk�r�e�_�dS)W�N)�StringIO�BytesIO)�chain)�choice)�Thread)�patch)�Charset)�Header�
decode_header�make_header)�Parser�HeaderParser)�	Generator�DecodedGenerator�BytesGenerator)�Message)�MIMEApplication)�	MIMEAudio)�MIMEText)�	MIMEImage)�MIMEBase)�MIMEMessage)�
MIMEMultipart)�MIMENonMultipart)�utils)�errors)�encoders)�	iterators)�
base64mime)�
quoprimime)�unlink�
start_threads)�openfile�
TestEmailBase)�
FeedParser�BytesFeedParser�
�� c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�S)��TestMessageAPIcCs<|j}|�d�}||�d�dddg�||�dd�d�dS)Nz
msg_20.txtZcczccc@zzz.orgzddd@zzz.orgzeee@zzz.orgZxxzn/a)�assertEqual�_msgobj�get_all)�self�eq�msg�r0�6/usr/local/lib/python3.7/test/test_email/test_email.py�test_get_all6s
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)Nz
iso-8859-1zmime-versionz1.0z
text/plainzcontent-typez text/plain; charset="iso-8859-1"�charsetzcontent-transfer-encodingzquoted-printablez2.0zMIME-Versionztext/x-weirdzContent-Typezquinted-puntablezContent-Transfer-Encodingz"text/x-weird; charset="iso-8859-1")r*r�get_charsetr�set_charset�get_content_type�	get_param�
input_charset)r-r.r/r3r0r0r1�test_getset_charset<s,


z"TestMessageAPI.test_getset_charsetcCs8|j}t�}|�d�||��jd�||dd�dS)Nzus-asciizcontent-typeztext/plain; charset="us-ascii")r*rr5r4r8)r-r.r/r0r0r1�test_set_charset_from_stringVs

z+TestMessageAPI.test_set_charset_from_stringcCs0t�}td�}|�d|�|�|��jd�dS)Nz
iso-8859-1zThis is a string payload)rr�set_payloadr*r4r8)r-r/r3r0r0r1�test_set_payload_with_charset]sz,TestMessageAPI.test_set_payload_with_charsetcCsVd}td�}t�}|�||�|�|dd�|�|jdd�|�|�|��d�dS)NsАБВzutf-8zcontent-transfer-encoding�base64T)�decodez	0JDQkdCS
)rrr;r*�get_payload)r-�datar3r/r0r0r1�+test_set_payload_with_8bit_data_and_charsetcsz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsRd}td�}d|_t�}|�|�d�|�|�|dd�|�|jdd�|�dS)NsАБВzutf-8zcontent-transfer-encoding�8bitT)r>)r�
body_encodingrr;r>r*r?)r-r@r3r/r0r0r1�>test_set_payload_with_non_ascii_and_charset_body_encoding_nonelszMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCsLd}td�}d|_t�}|�||�|�|dd�|�|jdd�|�dS)NsАБВzutf-8zcontent-transfer-encodingrBT)r>)rrCrr;r*r?)r-r@r3r/r0r0r1�>test_set_payload_with_8bit_data_and_charset_body_encoding_noneuszMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs$t�}|�g�|�|��g�dS)N)rr;r*r?)r-r/r0r0r1�test_set_payload_to_list~s
z'TestMessageAPI.test_set_payload_to_listcCs8t�}d|d<|�d�tt��}|�td|j|�dS)Nzmultipart/mixedzContent-Typezstring payloadz[Aa]ttach.*non-multipart)rr;rZassertRaisesRegex�	TypeError�attach)r-r/Zsub_msgr0r0r1�"test_attach_when_payload_is_string�s

z1TestMessageAPI.test_attach_when_payload_is_stringc
Cs�|j}|�d�}|��}||dddddg�|�d�}|�d�}||dddddg�|�d�}|��}||dddddd	ddg�dS)
Nz
msg_08.txtzus-asciiz
iso-8859-1z
iso-8859-2zkoi8-rz
msg_09.txtZdingbatz
msg_12.txtz
iso-8859-3)r*r+�get_charsets)r-r.r/�charsetsr0r0r1�test_get_charsets�s



z TestMessageAPI.test_get_charsetscCsV|j}|�d�}dd�|��D�}||ddg�|�d�}|�d�}||��d�dS)Nz
msg_04.txtcSsg|]}|���qSr0)�get_filename)�.0�pr0r0r1�
<listcomp>�sz4TestMessageAPI.test_get_filename.<locals>.<listcomp>zmsg.txtz
msg_07.txt�zdingusfish.gif)r*r+r?rM)r-r.r/�	filenames�subpartr0r0r1�test_get_filename�s


z TestMessageAPI.test_get_filenamecCs4|j}|�d�}dd�|��D�}||ddg�dS)Nz
msg_44.txtcSsg|]}|���qSr0)rM)rNrOr0r0r1rP�szHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>zmsg.txt)r*r+r?)r-r.r/rRr0r0r1�%test_get_filename_with_name_parameter�s
z4TestMessageAPI.test_get_filename_with_name_parametercCs"|j}|�d�}||��d�dS)Nz
msg_07.txt�BOUNDARY)r*r+�get_boundary)r-r.r/r0r0r1�test_get_boundary�s
z TestMessageAPI.test_get_boundarycCs�|j}|�d�}|�d�|��d\}}||��d�||d�|�d�}|�d�|��d\}}||��d�||d�|�d�}|�tj|jd�dS)	Nz
msg_01.txtrV�zcontent-typez3text/plain; charset="us-ascii"; boundary="BOUNDARY"z
msg_04.txtz$multipart/mixed; boundary="BOUNDARY"z
msg_03.txt)r*r+�set_boundary�items�lower�assertRaisesr�HeaderParseError)r-r.r/�header�valuer0r0r1�test_set_boundary�s






z TestMessageAPI.test_set_boundarycCsLtd�}|�|��ddd�|��|�|��dddd�d�dS)Nz	form-datarrQzmultipart/form-data�!z!multipart/form-data; boundary="==)rr*r[�	as_string)r-r/r0r0r1�test_make_boundary�s
z!TestMessageAPI.test_make_boundaryc	Cs^td��}|��}WdQRXt�}|�|�}t�}t|dd�}|�|d�|�|��|�dS)Nz
msg_46.txtTrF)	r"�readr
�parsestrrr�flattenr*�getvalue)r-�fp�msgdata�parserr/�out�genr0r0r1�test_message_rfc822_only�s

z'TestMessageAPI.test_message_rfc822_onlyc	Csftd��}|���d�}WdQRXtj��}|�|�}t�}tj�	|�}|�
|�|�|��|�dS)Nz
msg_46.txt�ascii)
r"re�encode�emailrk�BytesHeaderParserZ
parsebytesr�	generatorrrgr*rh)r-rirjrkr/rlrmr0r0r1�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.txtT)r>rs This is a 7bit encoded message.
rQs-�This is a Quoted Printable encoded message!
�s!This is a Base64 encoded message.�s"This is a Base64 encoded message.
rYs/This has no Content-Transfer-Encoding: header.
)r*r+r?)r-r.r/r0r0r1�test_get_decoded_payload�s
z'TestMessageAPI.test_get_decoded_payloadcCs^|j}t�}|�d�x&dD]}||d<||jdd�d�qW|�d�||jdd�d�dS)	Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
)z
x-uuencode�uuencode�uuezx-uuezcontent-transfer-encodingT)r>shello world�foosfoo)r*rr;r?)r-r.r/�cter0r0r1�test_get_decoded_uu_payloads


z*TestMessageAPI.test_get_decoded_uu_payloadcCst�}|�t|jd�dS)NrQ)rr]rGr?)r-r/r0r0r1�*test_get_payload_n_raises_on_non_multipart
sz9TestMessageAPI.test_get_payload_n_raises_on_non_multipartc	CsV|j}|�d�}td��}|��}WdQRXt�}t|�}|�|�||��|�dS)Nz
msg_07.txtz
msg_17.txt)r*r+r"rerrrgrh)r-r.r/ri�text�s�gr0r0r1�test_decoded_generators


z%TestMessageAPI.test_decoded_generatorcCsbt�}d|d<d|d<|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�dS)	NZMe�FromZYou�to�fromZFROM�ToZTO)r�assertIn)r-r/r0r0r1�test__contains__szTestMessageAPI.test__contains__c	Cs~|�d�}td��}|��}WdQRX|�|t|��|jdd�}|�d�}|�|d�d��|�|t	�
|dd���dS)Nz
msg_01.txtT)�unixfromr&rzFrom rQ)r+r"rer*�strrc�split�
assertTrue�
startswith�NL�join)r-r/rir~�fullrepr�linesr0r0r1�test_as_string's


zTestMessageAPI.test_as_stringcCsT|�d�}|jjdd�}|j|d�}t�}t||d�}|�|�|�||���dS)Nz
msg_01.txtz
)�linesep)�policy)	r+r��clonercrrrgr*rh)r-r/�	newpolicyr�rr�r0r0r1�test_as_string_policy1s

z$TestMessageAPI.test_as_string_policyc	Cs�|�d�}td��}|���d�}WdQRX|�|t|��|jdd�}|�d�}|�|d�	d��|�|d�
|dd���dS)	Nz
msg_01.txtroT)r��
rsFrom rQ)r+r"rerpr*�bytes�as_bytesr�r�r�r�)r-r/rir@r�r�r0r0r1�
test_as_bytes:s


zTestMessageAPI.test_as_bytescCsT|�d�}|jjdd�}|j|d�}t�}t||d�}|�|�|�||���dS)Nz
msg_01.txtz
)r�)r�)	r+r�r�r�rrrgr*rh)r-r/r�r�rr�r0r0r1�test_as_bytes_policyDs

z#TestMessageAPI.test_as_bytes_policycCs t�d�}|�|�d�d�dS)NzContent-Type: blarg; baz; boo
�bazr')rq�message_from_stringr*r7)r-r/r0r0r1�test_bad_paramNs
zTestMessageAPI.test_bad_paramcCst�d�}|�|��d�dS)Nz
From: foo
)rqr�r*rM)r-r/r0r0r1�test_missing_filenameRs
z$TestMessageAPI.test_missing_filenamecCst�d�}|�|��d�dS)Nz%Content-Disposition: blarg; filename
r')rqr�r*rM)r-r/r0r0r1�test_bogus_filenameVsz"TestMessageAPI.test_bogus_filenamecCst�d�}|�|��d�dS)Nz
From: foo
)rqr�r*rW)r-r/r0r0r1�test_missing_boundary[s
z$TestMessageAPI.test_missing_boundarycCs~|j}t�d�}||jdd�dddg�t�d�}||jdd�dd	d
g�||��d�t�d�}||jdd�dd	d
g�dS)Nz&X-Header: foo=one; bar=two; baz=three
zx-header)r_)rz�one)�bar�two)r��threez X-Header: foo; bar=one; baz=two
)rzr')r�r�)r�r�z"X-Header: foo; bar="one"; baz=two
)r*rqr��
get_params)r-r.r/r0r0r1�test_get_params_szTestMessageAPI.test_get_paramscCs$t�}d|d<|�|�d�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"zContent-Type�boundaryZCPIMSSMTPC06p5f3tG)rr*r7)r-r/r0r0r1�test_get_param_liberalpsz%TestMessageAPI.test_get_param_liberalcCs�|j}t�d�}||jddd�d�||jddd�d�||�d�d�t�d�}||jddd�d	�||jddd�d
�||jddd�d�dS)Nz&X-Header: foo=one; bar=two; baz=three
r�zx-header)r_r�Zquuzz"X-Header: foo; bar="one"; baz=two
rzr'r�r�)r*rqr�r7)r-r.r/r0r0r1�test_get_paramuszTestMessageAPI.test_get_paramcCs&|�d�}|�|�d��d�d�dS)Nz
msg_22.txtrQ�namez
wibble.JPG)r+r*r?r7)r-r/r0r0r1�'test_get_param_funky_continuation_lines�s
z6TestMessageAPI.test_get_param_funky_continuation_linescCs6t�d�}|�|�d�d�|�|jddd�d�dS)Nz4Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"
r�zJim&amp;&amp;JillF)�unquotez"Jim&amp;&amp;Jill")rqr�r*r7)r-r/r0r0r1�#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"baz)rqr�r*r7)r-r/r0r0r1�test_get_param_with_quotes�sz)TestMessageAPI.test_get_param_with_quotescCs>t�d�}|�d|�|�d|�|�d|�|�d|�dS)NzHeader: existsr_r	ZHEADERZheaderx)rqr�r�ZassertNotIn)r-r/r0r0r1�test_field_containment�s

z%TestMessageAPI.test_field_containmentcCs�|j}t�}|�dd�||�d�d�|�dd�||�d�d�||jddd�d�||��dd	d
g�||jdd�dddg�|jdd
dd�||jddd�d
�dS)Nr3ziso-2022-jp�
importancez
high valueF)r�z"high value")z
text/plainr')r3ziso-2022-jp)r�z
high value)r3z
"iso-2022-jp")r�z"high value"ziso-9999-xxzX-Jimmy)r_)r*r�	set_paramr7r�)r-r.r/r0r0r1�test_set_param�s
zTestMessageAPI.test_set_paramcCsr|j}|�d�}||��dddg�|�d�}|�d�||��ddg�|�d|�||��ddd|fg�dS)Nz
msg_05.txt)zmultipart/reportr')zreport-typezdelivery-status)r�z%D1690A7AC1.996856090/mail.example.comzreport-type)r*r+r�r7�	del_paramr�)r-r.r/Zold_valr0r0r1�test_del_param�s


zTestMessageAPI.test_del_paramcCs6t�}|jdddd�|�dd�|�|dd�dS)NzContent-Disposition�
attachmentzbud.gif)�filenamer�zcontent-disposition)r�
add_headerr�r*)r-r/r0r0r1�test_del_param_on_other_header�sz-TestMessageAPI.test_del_param_on_other_headercCst�}|�dd�dS)Nr�zcontent-disposition)rr�)r-r/r0r0r1�$test_del_param_on_nonexistent_header�sz3TestMessageAPI.test_del_param_on_nonexistent_headercCs@t�}|jdddd�|d}|jddd�|�|d|�dS)NzContent-Typez
text/plainzutf-8)r3�foobar)r_)rr�r�r*)r-r/Zexisting_headerr0r0r1�test_del_nonexistent_param�s
z)TestMessageAPI.test_del_nonexistent_paramcCsj|j}t�}|�t|jd�|�d�||dd�|�dd�||dd�|�d�||dd�dS)	Nr~z
text/plainzcontent-typer3zus-asciiztext/plain; charset="us-ascii"z	text/htmlztext/html; charset="us-ascii")r*rr]�
ValueError�set_typer�)r-r.r/r0r0r1�
test_set_type�s

zTestMessageAPI.test_set_typecCs.t�}d|d<|�dd�|�|dd�dS)Nz
text/plainzX-Content-Typezapplication/octet-streamzx-content-type)rr�r*)r-r/r0r0r1�test_set_type_on_other_header�sz,TestMessageAPI.test_set_type_on_other_headercCst�}|�|��d�dS)Nz
text/plain)rr*r6)r-r/r0r0r1�test_get_content_type_missing�sz,TestMessageAPI.test_get_content_type_missingcCs$t�}|�d�|�|��d�dS)Nzmessage/rfc822)r�set_default_typer*r6)r-r/r0r0r1�/test_get_content_type_missing_with_default_type�s
z>TestMessageAPI.test_get_content_type_missing_with_default_typecCs$|�d�}|�|�d���d�dS)Nz
msg_30.txtrzmessage/rfc822)r+r*r?r6)r-r/r0r0r1�+test_get_content_type_from_message_implicit�s
z:TestMessageAPI.test_get_content_type_from_message_implicitcCs$|�d�}|�|�d���d�dS)Nz
msg_28.txtrzmessage/rfc822)r+r*r?r6)r-r/r0r0r1�+test_get_content_type_from_message_explicit�s
z:TestMessageAPI.test_get_content_type_from_message_explicitcCs|�d�}|�|��d�dS)Nz
msg_03.txtz
text/plain)r+r*r6)r-r/r0r0r1�6test_get_content_type_from_message_text_plain_implicit�s
zETestMessageAPI.test_get_content_type_from_message_text_plain_implicitcCs|�d�}|�|��d�dS)Nz
msg_01.txtz
text/plain)r+r*r6)r-r/r0r0r1�6test_get_content_type_from_message_text_plain_explicit�s
zETestMessageAPI.test_get_content_type_from_message_text_plain_explicitcCst�}|�|��d�dS)Nr~)rr*�get_content_maintype)r-r/r0r0r1�!test_get_content_maintype_missingsz0TestMessageAPI.test_get_content_maintype_missingcCs$t�}|�d�|�|��d�dS)Nzmessage/rfc822�message)rr�r*r�)r-r/r0r0r1�3test_get_content_maintype_missing_with_default_types
zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCs$|�d�}|�|�d���d�dS)Nz
msg_30.txtrr�)r+r*r?r�)r-r/r0r0r1�/test_get_content_maintype_from_message_implicits
z>TestMessageAPI.test_get_content_maintype_from_message_implicitcCs$|�d�}|�|�d���d�dS)Nz
msg_28.txtrr�)r+r*r?r�)r-r/r0r0r1�/test_get_content_maintype_from_message_explicits
z>TestMessageAPI.test_get_content_maintype_from_message_explicitcCs|�d�}|�|��d�dS)Nz
msg_03.txtr~)r+r*r�)r-r/r0r0r1�:test_get_content_maintype_from_message_text_plain_implicits
zITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitcCs|�d�}|�|��d�dS)Nz
msg_01.txtr~)r+r*r�)r-r/r0r0r1�:test_get_content_maintype_from_message_text_plain_explicits
zITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitcCst�}|�|��d�dS)N�plain)rr*�get_content_subtype)r-r/r0r0r1� test_get_content_subtype_missingsz/TestMessageAPI.test_get_content_subtype_missingcCs$t�}|�d�|�|��d�dS)Nzmessage/rfc822�rfc822)rr�r*r�)r-r/r0r0r1�2test_get_content_subtype_missing_with_default_type s
zATestMessageAPI.test_get_content_subtype_missing_with_default_typecCs$|�d�}|�|�d���d�dS)Nz
msg_30.txtrr�)r+r*r?r�)r-r/r0r0r1�.test_get_content_subtype_from_message_implicit%s
z=TestMessageAPI.test_get_content_subtype_from_message_implicitcCs$|�d�}|�|�d���d�dS)Nz
msg_28.txtrr�)r+r*r?r�)r-r/r0r0r1�.test_get_content_subtype_from_message_explicit)s
z=TestMessageAPI.test_get_content_subtype_from_message_explicitcCs|�d�}|�|��d�dS)Nz
msg_03.txtr�)r+r*r�)r-r/r0r0r1�9test_get_content_subtype_from_message_text_plain_implicit-s
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCs|�d�}|�|��d�dS)Nz
msg_01.txtr�)r+r*r�)r-r/r0r0r1�9test_get_content_subtype_from_message_text_plain_explicit1s
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitcCs"t�}d|d<|�|��d�dS)Nzno-slash-in-this-stringzContent-Typer~)rr*r�)r-r/r0r0r1�test_get_content_maintype_error5sz.TestMessageAPI.test_get_content_maintype_errorcCs"t�}d|d<|�|��d�dS)Nzno-slash-in-this-stringzContent-Typer�)rr*r�)r-r/r0r0r1�test_get_content_subtype_error:sz-TestMessageAPI.test_get_content_subtype_errorcCs�|j}t�}|�dd�|�dd�|�dd�||��dddg�||��dddg�|�dd�||��dddg�||��dddg�|�dd�|�dd	�||��ddddg�||��d	dddg�|�t|jd
d�dS)N�First�One�Second�TwoZThirdZThreeZTwentyZElevenzOne HundredZFourthZMissing)r*rr��keys�values�replace_headerr]�KeyError)r-r.r/r0r0r1�test_replace_header?sz"TestMessageAPI.test_replace_headercCspt�}|�|���|jdddd�|�|��d�|�dd�|�|��d�|�dd�|�|��d�dS)NzContent-Dispositionr�z
random.avi)r��inlineZInlinE)r�assertIsNoneZget_content_dispositionr�r*r�)r-r/r0r0r1�test_get_content_dispositionPsz+TestMessageAPI.test_get_content_dispositioncCsPd}t�}d|d<d|d<|�|�|�|jdd�d�|�|jd	tj�dS)
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midizcontent-typer=zcontent-transfer-encodingT)r>s����.���p���r)rr;r*r?�assertIsInstance�defectsr�InvalidBase64CharactersDefect)r-�xr/r0r0r1�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 doz
text/plainzcontent-typerBzcontent-transfer-encodingT)r>zraw-unicode-escape)rr;r*r?r�)r-r�r/r0r0r1�test_broken_unicode_payloadhs
z*TestMessageAPI.test_broken_unicode_payloadcCs>d�d�}t�}d|d<d|d<||_|�|jdd�|�dS)	Nu#this is a quéstionable thing to dozutf-8ztext/plain; charset="utf-8"zcontent-typerBzcontent-transfer-encodingT)r>)rprZ_payloadr*r?)r-r�r/r0r0r1�test_questionable_bytes_payloadss
z.TestMessageAPI.test_questionable_bytes_payloadcCs*t�}|jdddd�|�d|d�dS)NzContent-Dispositionr�zbud.gif)r�zattachment; filename="bud.gif")rr�r*)r-r/r0r0r1�test_ascii_add_header~s
z$TestMessageAPI.test_ascii_add_headercCs*t�}|jdddd�|�d|d�dS)NzContent-Dispositionr�uFußballer.ppt)r�z/attachment; filename*=utf-8''Fu%C3%9Fballer.ppt)rr�r*)r-r/r0r0r1�test_noascii_add_header�sz&TestMessageAPI.test_noascii_add_headercCs*t�}|jdddd�|�d|d�dS)NzContent-Dispositionr�)z
iso-8859-1r'uFußballer.ppt)r�z1attachment; filename*=iso-8859-1''Fu%DFballer.ppt)rr�r*)r-r/r0r0r1�#test_nonascii_add_header_via_triple�sz2TestMessageAPI.test_nonascii_add_header_via_triplecCs*t�}|jdddd�|�d|d�dS)NzContent-Dispositionr�zwindows [filename].ppt)r�z-attachment; filename="windows [filename].ppt")rr�r*)r-r/r0r0r1�#test_ascii_add_header_with_tspecial�sz2TestMessageAPI.test_ascii_add_header_with_tspecialcCs*t�}|jdddd�|�d|d�dS)NzContent-Dispositionr�uFußballer [filename].ppt)r�z@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt)rr�r*)r-r/r0r0r1�&test_nonascii_add_header_with_tspecial�sz5TestMessageAPI.test_nonascii_add_header_with_tspecialcCsPxJdD]B}t�}d||d<d|d<|�d�|�|jdd�d	d
|�qWdS)N)zlatin-1roztext/plain; charset=%szcontent-typezquoted-printablezcontent-transfer-encodingsfoo=e6=96=87barT)r>s	foo文barz1get_payload returns wrong result with charset %s.)rr;r*r?)r-r3r/r0r0r1�test_binary_quopri_payload�s


z)TestMessageAPI.test_binary_quopri_payloadcCsPxJdD]B}t�}d||d<d|d<|�d�|�|jdd�d	d
|�qWdS)N)zlatin-1roztext/plain; charset=%szcontent-typer=zcontent-transfer-encodingsZm9v5paHYmFyT)r>s	foo文barz1get_payload returns wrong result with charset %s.)rr;r*r?)r-r3r/r0r0r1�test_binary_base64_payload�s


z)TestMessageAPI.test_binary_base64_payloadc
Csfx`dD]X}xRdD]J}t�}d||d<||d<|�d�|�|jdd�d	td
��||��qWqWdS)N)zlatin-1ro)z
x-uuencoderxryzx-uueztext/plain; charset=%szcontent-typezcontent-transfer-encodings begin 666 -
)9F]OYI:'8F%R
 
end
T)r>s	foo文bar)z!get_payload returns wrong result z"with charset {0} and encoding {1}.)rr;r*r?r��format)r-r3�encodingr/r0r0r1�test_binary_uuencode_payload�s



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

            abc
            )rr*r��textwrap�dedent)r-�mr0r0r1�-test_unicode_header_defaults_to_utf8_encoding�sz<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=
            )rr*r�r�r�)r-rr0r0r1�+test_unicode_body_defaults_to_utf8_encoding�sz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)V�__name__�
__module__�__qualname__r2r9r:r<rArDrErFrIrLrTrUrXrardrnrtrwr|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�rrr0r0r0r1r)5s�			

	


r)c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncodersc	Cs\tdd��}|��}WdQRXtjj�|�}|��}|�d�}|�t	dd�|D��d�dS)NzPyBanner048.gif�rbr&cSsg|]}t|��qSr0)�len)rNr�r0r0r1rPsz;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>�L)
r"rerq�mime�imagerr?r��assertLessEqual�max)r-ri�bindataZmimedZbase64edr�r0r0r1�test_EncodersEncode_base64�s
z'TestEncoders.test_EncodersEncode_base64cCs(|j}t�}|�d�||dd�dS)Nzus-asciizcontent-transfer-encoding�7bit)r*rr5)r-r.r/r0r0r1�test_encode_empty_payloads
z&TestEncoders.test_encode_empty_payloadcCsP|j}td�}||dd�td�}||dd�tddd�}||dd�dS)	Nzhello worldzcontent-transfer-encodingruhello ø worldr=z
iso-8859-1)�_charsetzquoted-printable)r*r)r-r.r/r0r0r1�test_default_cte
szTestEncoders.test_default_ctecCs8|j}tddd�}||dd�||��t�d��dS)Nu文
zeuc-jp)rzcontent-transfer-encodingrz�            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

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

            =E1=F6
            )rr*r�r�r�)r-r/r0r0r1�test_qp_encode_latin1%sz"TestEncoders.test_qp_encode_latin1cCs&tddd�}|�t|�t�d��dS)Nuż
r~z
ISO-8859-2z�            MIME-Version: 1.0
            Content-Type: text/text; charset="iso-8859-2"
            Content-Transfer-Encoding: quoted-printable

            =BF
            )rr*r�r�r�)r-r/r0r0r1�test_qp_encode_non_latin1/sz&TestEncoders.test_qp_encode_non_latin1N)	rrrrrrrrrr0r0r0r1r�s	
rc@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
)�ndiffAssertEqualrqr�rrrgrh)r-r.r/�sfpr�r0r0r1�test_split_long_continuation@s
z,TestLongHeaders.test_split_long_continuationcCsF|j}d}t|dd�}||��d�t|�dd��}||��d�dS)Nz�bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text�	)�continuation_wsr(z�bug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)rr	rp�replace)r-r.�hstr�hr0r0r1�,test_another_long_almost_unsplittable_headerTs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)
Nz
iso-8859-1z
iso-8859-2zutf-8s�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. s;Finan�ni metropole se hroutily pod tlakem jejich d�vtipu.. u�正確に言うと翻訳はされていません。一部はドイツ語ですが、あとはでたらめです。実際には「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?=)
rrr	�appendrrrrgrhrp)r-r.r��cz�utf8�g_head�cz_head�	utf8_headrr/rr0r0r1�test_long_nonstringes&

z#TestLongHeaders.test_long_nonstringcCs$|j}tddd�}||��d�dS)Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnit)r!zjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")rr	rp)r-r.rr0r0r1�test_long_header_encode�s
z'TestLongHeaders.test_long_header_encodecCs&|j}tdddd�}||��d�dS)Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitr)r!rzjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")rr	rp)r-r.rr0r0r1�<test_long_header_encode_with_tab_continuation_is_just_a_hint�szLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hintcCs&|j}tdddd�}||��d�dS)Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitr)r!rzjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")rr	rp)r-r.rr0r0r1�-test_long_header_encode_with_tab_continuation�sz=TestLongHeaders.test_long_header_encode_with_tab_continuationcCstdd�}|�|��d�dS)Nu文zeuc-jpz=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	r*rp)r-rr0r0r1�0test_header_encode_with_different_output_charset�s
z@TestLongHeaders.test_header_encode_with_different_output_charsetcCs(td�d�d�}d}|�|��|�dS)Ns6test-ja ����Ƥ��줿�᡼��ϻʲ�Ԥξ�ǧ���ԤäƤ��ޤ�zeuc-jpz�=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r	r>r*rp)r-rZresr0r0r1�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'ziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitz�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"

)rrrrrgrh)r-r.r/rr�r0r0r1�test_header_splitter�s
z$TestLongHeaders.test_header_splittercCsd|j}t�}d|d<t�dd�td�D��|d<|�d�t�}t|�}|�|�||�	�d�dS)	Nztest@dom.ainr�css|]}d|VqdS)z<%d@dom.ain>Nr0)rN�ir0r0r1�	<genexpr>�sz@TestLongHeaders.test_no_semis_header_splitter.<locals>.<genexpr>�
�
References�Testz�From: test@dom.ain
References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
 <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>

Test)
rr�SPACEr��ranger;rrrgrh)r-r.r/rr�r0r0r1�test_no_semis_header_splitter�s

z-TestLongHeaders.test_no_semis_header_splittercCs |j}td�}||��d�dS)Nz�Subject: the first part of this is short, but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfz�Subject: the first part of this is short,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself)rr	rp)r-r.rr0r0r1�"test_last_split_chunk_does_not_fit�sz2TestLongHeaders.test_last_split_chunk_does_not_fitcCs |j}td�}||��d�dS)Nz_, but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfz`,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself)rr	rp)r-r.rr0r0r1�=test_splittable_leading_char_followed_by_overlong_unsplitable�szMTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplitablecCs |j}td�}||��d�dS)Nza, , but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itselfzb, ,
 but_the_second_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself)rr	rp)r-r.rr0r0r1�Ftest_multiple_splittable_leading_char_followed_by_overlong_unsplitable�szVTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplitablecCs |j}td�}||��d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;)rr	rp)r-r.rr0r0r1�/test_trailing_splitable_on_overlong_unsplitablesz?TestLongHeaders.test_trailing_splitable_on_overlong_unsplitablecCs |j}td�}||��d�dS)NzW; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; zX;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; )rr	rp)r-r.rr0r0r1�Ftest_trailing_splitable_on_overlong_unsplitable_with_leading_splitableszVTestLongHeaders.test_trailing_splitable_on_overlong_unsplitable_with_leading_splitablecCs |j}td�}||��d�dS)NzpThis is a long line that has two whitespaces  in a row.  This used to cause truncation of the header when foldedzqThis is a long line that has two whitespaces  in a row.  This used to cause
 truncation of the header when folded)rr	rp)r-r.rr0r0r1�5test_long_header_with_multiple_sequential_split_charsszETestLongHeaders.test_long_header_with_multiple_sequential_split_charscCs |j}td�}||��d�dS)NzKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points)rr	rp)r-r.rr0r0r1�:test_splitter_split_on_punctuation_only_if_fws_with_headerszJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headercCs |j}td�}||��d�dS)Nz�this is a  test where we need to have more than one line before; our final line that is just too big to fit;; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;z�this is a  test where we need to have more than one line before;
 our final line that is just too big to fit;;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;)rr	rp)r-r.rr0r0r1�Dtest_leading_splittable_in_the_middle_just_before_overlong_last_part$szTTestLongHeaders.test_leading_splittable_in_the_middle_just_before_overlong_last_partcCs |j}td�}||��d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself )rr	rp)r-r.rr0r0r1�/test_overlong_last_part_followed_by_split_point/sz?TestLongHeaders.test_overlong_last_part_followed_by_split_pointcCs |j}td�}||��d�dS)Nz�this_is_a__test_where_we_need_to_have_more_than_one_line_before_our_final_line_; ; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; z�this_is_a__test_where_we_need_to_have_more_than_one_line_before_our_final_line_;
 ;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; )rr	rp)r-r.rr0r0r1�@test_multiline_with_overlong_parts_separated_by_two_split_points6szPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointscCs |j}td�}||��d�dS)Nz�this is a test where we need to have more than one line before our final line; ; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; z�this is a test where we need to have more than one line before our final line;
 ;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; )rr	rp)r-r.rr0r0r1�>test_multiline_with_overlong_last_part_followed_by_split_pointAszNTestLongHeaders.test_multiline_with_overlong_last_part_followed_by_split_pointcCs\|j}t�}d|d<t�dgd�|d<|�d�t�}t|�}|�|�||��d�dS)Nztest@dom.ainr�z<foo@dom.ain>  r2r3r4z�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)	rrr5r�r;rrrgrh)r-r.r/rr�r0r0r1�%test_long_header_with_whitespace_runsLs

z5TestLongHeaders.test_long_header_with_whitespace_runscCs`|j}t�}d|d<t�dgd�d|d<|�d�t�}t|�}|�|�||��d�dS)	Nztest@dom.ainr�z
<foo@dom.ain>r2z; abcr3r4z�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

Test)	rrr5r�r;rrrgrh)r-r.r/rr�r0r0r1�'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)Nztest@dom.ainr�zKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr3r4zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)rrr;rrrgrh)r-r.r/rr�r0r0r1�.test_splitter_split_on_punctuation_only_if_fwsns

z>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fwscCs:|j}d}t|�}||��d�td�}||��d�dS)Nz\References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)rr	rp)r-r.rrr0r0r1�test_no_split_long_header�sz)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)ra_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))rr	rp)r-r.rrr0r0r1�"test_splitting_multiple_long_lines�s
z2TestLongHeaders.test_splitting_multiple_long_linescCs,|j}d}t|dddd�}||��d�dS)Nz�from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93] helo=cthulhu.gerg.ca)
	by kronos.mems-exchange.org with esmtp (Exim 4.05)
	id 17k4h5-00034i-00
	for test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400�NZReceivedr)r"r!rz�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)rr	rp)r-r.rrr0r0r1�&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 gibtz
iso-8859-1r�)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?=

)rrr	r#rprc)r-r.r/rr0r0r1�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-TorH)rJz�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!)rrrcr	)r-r.r/Z
header_stringr0r0r1� 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�rH)rJz�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>

)rrrc)r-r.r�r/r0r0r1�test_long_to_header�sz#TestLongHeaders.test_long_to_headercCs2|j}d}t|�}|�d�||jdd�d�dS)NzIThis is an example of string which has almost the limit of header length.zAdd another line.r	)r"z\This is an example of string which has almost the limit of header length.
 Add another line.)rr	r#rp)r-r.rrr0r0r1�test_long_line_after_append�s
z+TestLongHeaders.test_long_line_after_appendcCs.|j}d}t|�}|�d�||��d�dS)NzThis is a shorter line.z!Add another sentence. (Surprise?)z9This is a shorter line. Add another sentence. (Surprise?))rr	r#rp)r-r.rrr0r0r1�test_shorter_line_with_append�s
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. z
iso-8859-1)r!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_?=)rr	rp)r-r.�fnZgsrr0r0r1�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)rz
Received-1z
Received-2rH)rJa1Received-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	rrc)r-rr/r0r0r1�test_long_received_headers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")z
Received-1r)r!rz
Received-2rH)rJa#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")

)rr	rrc)r-rr/r0r0r1�test_string_headerinst_eqsz)TestLongHeaders.test_string_headerinst_eqcCsJ|j}t�}d}||d<t|dd�|d<d||d<||jdd�d	�dS)
Nz�iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1zFace-2)r!r(zFace-3rH)rJa�Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

)rrr	rc)r-r.r/�tr0r0r1�-test_long_unbreakable_lines_with_continuation1s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 -0700rH)rJz�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

)rrqr�rc)r-r.rr/r0r0r1�"test_another_long_multiline_headerIs

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>ZList)r!rH)rJa_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>

)rrr	rc)r-r.rr/r0r0r1�%test_long_lines_with_different_headerVs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 workszutf-8r4)r3r!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*rp)r-rr0r0r1�*test_long_rfc2047_header_with_embedded_fwsisz:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+rrr�maxDiffrr r)r*r+r,r-r.r/r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrIrKrLrMrNrOrQrRrSrUrVrWrXr0r0r0r1r<sP6	


					
rc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestFromManglingcCs"t�|_d|jd<|j�d�dS)Nzaaa@bbb.orgr�z(From the desk of A.A.A.:
Blah blah blah
)rr/r;)r-r0r0r1�setUpzs
zTestFromMangling.setUpcCs2t�}t|dd�}|�|j�|�|��d�dS)NT)�mangle_from_z<From: aaa@bbb.org

>From the desk of A.A.A.:
Blah blah blah
)rrrgr/r*rh)r-rr�r0r0r1�test_mangled_from�s

z"TestFromMangling.test_mangled_fromcCs2t�}t|dd�}|�|j�|�|��d�dS)NF)r\z;From: aaa@bbb.org

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

            From somewhere unknown

            --XXX
            Content-Type: text/plain

            foo

            --XXX--

            From somewhere unknowable
            cSsg|]}|�d�rd�qS)z>From rQ)r�)rNr�r0r0r1rP�szLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r&ru)rrrqr�r�r�rgr*rrhr�)r-rr�r/r0r0r1�'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

        zutf-8sFrom Rölli
T)r\s
>From Rölli
)
r�r�rprq�message_from_bytesrrrgr*rh)r-�sourcer/�br�r0r0r1� 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: È
        zutf-8)r�r�rprqr`)r-rar/r0r0r1�%test_mutltipart_with_bad_bytes_in_cte�sz6TestFromMangling.test_mutltipart_with_bad_bytes_in_cteN)	rrrr[r]r^r_rcrdr0r0r0r1rZysrZc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudioc	Cs0tdd��}|��|_WdQRXt|j�|_dS)Nzaudiotest.aur)r"re�
_audiodatar�_au)r-rir0r0r1r[�szTestMIMEAudio.setUpcCs|�|j��d�dS)Nzaudio/basic)r*rgr6)r-r0r0r1�test_guess_minor_type�sz#TestMIMEAudio.test_guess_minor_typecCs(|j��}|�t�t|d��|j�dS)Nro)rgr?r*r=�decodebytesr�rf)r-�payloadr0r0r1�
test_encoding�s
zTestMIMEAudio.test_encodingcCs t|jd�}|�|��d�dS)N�fishz
audio/fish)rrfr*r6)r-Zaur0r0r1�test_checkSetMinor�sz TestMIMEAudio.test_checkSetMinorcCs�|j}|jjdddd�||jdd�||jjdd�dd	g�||jjd
dd�d�g}||jjddd�d�|�|jjd|dd
�|�|�|j�d|�|�|�|jjd|dd�|�dS)NzContent-Dispositionr�zaudiotest.au)r�zcontent-dispositionz#attachment; filename="audiotest.au")r_)r�r')r�zaudiotest.aur�r'rz)�failobjr_r�)r*rgr�r�r7�assertIs)r-r.�missingr0r0r1�test_add_header�s 


zTestMIMEAudio.test_add_headerN)rrrr[rhrkrmrqr0r0r0r1re�s
rec@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEImagec	Cs0tdd��}|��|_WdQRXt|j�|_dS)NzPyBanner048.gifr)r"re�_imgdatar�_im)r-rir0r0r1r[�szTestMIMEImage.setUpcCs|�|j��d�dS)Nz	image/gif)r*rtr6)r-r0r0r1rh�sz#TestMIMEImage.test_guess_minor_typecCs(|j��}|�t�t|d��|j�dS)Nro)rtr?r*r=rir�rs)r-rjr0r0r1rk�s
zTestMIMEImage.test_encodingcCs t|jd�}|�|��d�dS)Nrlz
image/fish)rrsr*r6)r-Zimr0r0r1rm�sz TestMIMEImage.test_checkSetMinorcCs�|j}|jjdddd�||jdd�||jjdd�dd	g�||jjd
dd�d�g}||jjddd�d�|�|jjd|dd
�|�|�|j�d|�|�|�|jjd|dd�|�dS)NzContent-Dispositionr�zdingusfish.gif)r�zcontent-dispositionz%attachment; filename="dingusfish.gif")r_)r�r')r�zdingusfish.gifr�r'rz)rnr_r�)r*rtr�r�r7ro)r-r.rpr0r0r1rqs 


zTestMIMEImage.test_add_headerN)rrrr[rhrkrmrqr0r0r0r1rr�s
rrc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestMIMEApplicationcCs.|j}td�}||��d�||dd�dS)Ns������zapplication/octet-streamzcontent-transfer-encodingr=)r*rr6)r-r.r/r0r0r1�test_headerssz TestMIMEApplication.test_headerscCs:|j}d}t|�}||����d�||jdd�|�dS)Ns������z+vv8/f7/T)r>)r*rr?�strip)r-r.�	bytesdatar/r0r0r1�	test_bodys
zTestMIMEApplication.test_bodycCs�d}t|tjd�}|�|��dt|��|�|jdd�|�|�|dd�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�|�|dd�dS)Ns������)�_encoderu�T)r>zContent-Transfer-EncodingrB)rr�encode_7or8bitr*r?rrrrgrhrqr`)r-rxr/rr��wireform�msg2r0r0r1�$test_binary_body_with_encode_7or8bit's

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|tjd�}|�|��dt|��|�|jdd�|�t�}t|�}|�|�|�	�}t
�|�}|�|��dt|��|�|jdd�|�dS)Ns������)rzu�T)r>)rr�encode_noopr*r?rrrrgrhrqr`)r-rxr/rr�r|r}r0r0r1�!test_binary_body_with_encode_noop8s

z5TestMIMEApplication.test_binary_body_with_encode_noopcCshd}t|tjd�}|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|jdd�|�dS)Ns������)rzT)r>)rrrr*r?rrrgrhrqr`)r-rxr/rr�r|r}r0r0r1�0test_binary_body_with_unicode_linend_encode_noopIs

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|tjd�}|�|��d�|�|jdd�|�|�|dd�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�|�|dd�dS)Ns������ )rzz=FA=FB=FC=FD=FE=FF=20T)r>zContent-Transfer-Encodingzquoted-printable)rrZ
encode_quoprir*r?rrrgrhrqr`)r-rxr/rr�r|r}r0r0r1�#test_binary_body_with_encode_quopriUs

z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|tjd�}|�|��d�|�|jdd�|�t�}t|�}|�|�|��}t	�
|�}|�|��d�|�|jdd�|�dS)Ns������)rzz	+vv8/f7/
T)r>)rrZ
encode_base64r*r?rrrgrhrqr`)r-rxr/rr�r|r}r0r0r1�#test_binary_body_with_encode_base64es

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
rrrrvryr~r�r�r�r�r0r0r0r1rusruc@sVeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�d�dd��ZdS)�TestMIMETextcCstd�|_dS)Nzhello there)r�_msg)r-r0r0r1r[uszTestMIMEText.setUpcCs`|j}||j��d�||j�d�d�g}|�|j�d|�|�|�|jjd|dd�|�dS)Nz
text/plainr3zus-asciir�)r_)r*r�r6r7ro)r-r.rpr0r0r1�
test_typesxszTestMIMEText.test_typescCs&|�|j��d�|�|j���dS)Nzhello there)r*r�r?�assertFalse�is_multipart)r-r0r0r1�test_payload�szTestMIMEText.test_payloadcCsz|j}tddd�}||��jd�||dd�td�}d|_td|d�}||��jd�||dd�||��d�dS)Nzhello therezus-ascii)rzcontent-typeztext/plain; charset="us-ascii"zutf-8ztext/plain; charset="utf-8")r*rr4r8rrCr?)r-r.r/r3r0r0r1�test_charset�szTestMIMEText.test_charsetcCs4|j}tddd�}||��jd�||dd�dS)Nzhello therezus-ascii)rzcontent-typeztext/plain; charset="us-ascii")r*rr4r8)r-r.r/r0r0r1�test_7bit_input�szTestMIMEText.test_7bit_inputcCs>|j}td�}||��d�||dd�|�d|���dS)Nzhello therezus-asciizcontent-typeztext/plain; charset="us-ascii")r*rr4r�rc)r-r.r/r0r0r1�test_7bit_input_no_charset�s
z'TestMIMEText.test_7bit_input_no_charsetcCsPd}|j}t|dd�}||��jd�||dd�||jdd�|�d��dS)Nuкирилицаzutf-8)rzcontent-typeztext/plain; charset="utf-8"T)r>)r*rr4�output_charsetr?rp)r-�teststrr.r/r0r0r1�test_utf8_input�szTestMIMEText.test_utf8_inputzBcan't fix because of backward compat in email5, will fix in email6cCsd}|�tt|�dS)Nuкирилица)r]�UnicodeEncodeErrorr)r-r�r0r0r1�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
rrrr[r�r�r�r�r�r��unittest�skipr�r0r0r0r1r�ts	
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)S)*�
TestMultipartc	Cs�tdd��}|��}WdQRXtdddd�}t|dd�}|jd	d
dd�td�}|�|�|�|�d
|d<d|d<d|d<d}t�|�}|ddkr�tj	}ntj
}|dkr�d}	nd}	d|	|df}
t�dt�|��|
|d<||_||_
||_dS)NzPyBanner048.gifr�	multipart�mixedrV)r�zdingusfish.gif)r�zcontent-dispositionr�)r�z$Hi there,

This is the dingus fish.
zBarry <barry@digicool.com>r�z)Dingus Lovers <cravindogs@cravindogs.com>r�zHere is your dingus fishr�g�4F�cp�A���r�-�+z %s%04d�$z%a, %d %b %Y %H:%M:%SZDate)r"rerrr�rrH�time�	localtimeZtimezoneZaltzone�strftimer�rt�_txt)r-rir@�	containerrZintro�nowZ	timetupleZtzsecs�signZtzoffsetr0r0r1r[�s8


zTestMultipart.setUpcCs�|j}|j}|j}|�|���||��d�|t|���d�|t|jd�|�d�}|�d�}|�	||j
�|�	||j�||��||g�|�|���|�|���dS)Nzmultipart/mixedrurrQ)
r*r]r�r�r�r6rr?�
IndexErrorror�rtr�)r-r.�raisesrZm0Zm1r0r0r1�test_hierarchy�s

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


--BOUNDARY


--BOUNDARY--
)rrfrrc)r-r~r/r0r0r1�test_empty_multipart_idempotent�s
z-TestMultipart.test_empty_multipart_idempotentcCs@tdd�}d|d<d|d<d|d<|�d	�|�|��d
�dS)Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�rVz�Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY

--BOUNDARY--
)rrZrrc)r-�outerr0r0r1�/test_no_parts_in_a_multipart_with_none_epilogue�s



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


--BOUNDARY

--BOUNDARY--
)r�preamble�epiloguerZrrc)r-r�r0r0r1�0test_no_parts_in_a_multipart_with_empty_epilogue
s


z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguecCsV|j}tdd�}d|d<d|d<d|d<|�d	�td
�}|�|�||��d�dS)Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�rVzhello worldaContent-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--
)rrrZrrHrc)r-r.r�r/r0r0r1�test_one_part_in_a_multiparts


z*TestMultipart.test_one_part_in_a_multipartcCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�r'zhello worldrVaContent-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--
)rrr�rrHrZrc)r-r.r�r/r0r0r1�1test_seq_parts_in_a_multipart_with_empty_preamble8s


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamblecCs\|j}tdd�}d|d<d|d<d|d<d|_td	�}|�|�|�d
�||��d�dS)Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�zhello worldrVaContent-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--
)rrr�rrHrZrc)r-r.r�r/r0r0r1�0test_seq_parts_in_a_multipart_with_none_preambleTs


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblecCs\|j}tdd�}d|d<d|d<d|d<d|_td	�}|�|�|�d
�||��d�dS)Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�zhello worldrVaContent-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--
)rrr�rrHrZrc)r-r.r�r/r0r0r1�0test_seq_parts_in_a_multipart_with_none_epilogueos


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguecCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�r'zhello worldrVaContent-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--
)rrr�rrHrZrc)r-r.r�r/r0r0r1�1test_seq_parts_in_a_multipart_with_empty_epilogue�s


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epiloguecCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|�|�|�d�||��d�dS)
Nr�r�z	A subjectr�zaperson@dom.ainr�zbperson@dom.ainr�r&zhello worldrVaContent-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--

)rrr�rrHrZrc)r-r.r�r/r0r0r1�.test_seq_parts_in_a_multipart_with_nl_epilogue�s


z<TestMultipart.test_seq_parts_in_a_multipart_with_nl_epiloguecCs�|j}|�d�}|t|���d�|�d�}||��d�|t|���d�xH|��D]<}||��d�|t|���d�|�d�}||��d�qVWdS)Nz
msg_36.txtrurQzmultipart/alternativezmessage/external-bodyrz
text/plain)r*r+rr?r6)r-r.r/�msg1rS�
subsubpartr0r0r1�test_message_external_body�s


z(TestMultipart.test_message_external_bodycCs"|�d�}|�t|���d�dS)Nz
msg_37.txtrv)r+r*rr?)r-r/r0r0r1�test_double_boundary�s
z"TestMultipart.test_double_boundarycCs4|j}|�d�}t�}t�||�||��d�dS)Nz
msg_38.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
            text/plain
        text/plain
    text/plain
    text/plain
)rr+rr�
_structurerh)r-r.r/rr0r0r1�)test_nested_inner_contains_outer_boundary�s
z7TestMultipart.test_nested_inner_contains_outer_boundarycCs4|j}|�d�}t�}t�||�||��d�dS)Nz
msg_39.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
)rr+rrr�rh)r-r.r/rr0r0r1�test_nested_with_same_boundary�s
z,TestMultipart.test_nested_with_same_boundarycCs|�d�}|�|��d�dS)Nz
msg_40.txtz�MIME-Version: 1.0
Content-Type: text/html; boundary="--961284236552522269"

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

<html></html>

----961284236552522269--
)r+r*rc)r-r/r0r0r1�test_boundary_in_non_multipart�s

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    XXXXru)r*rqr�r�r�rWrr?)r-r.r/r0r0r1� test_boundary_with_leading_spacesz.TestMultipart.test_boundary_with_leading_spacecCs&t��d�}|�|�d���d�dS)Nz�Content-Type: multipart/mixed; boundary="===============0012394164=="
MIME-Version: 1.0

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

YXNkZg==
--===============0012394164==--rzYXNkZg==)rrfr*r?)r-rr0r0r1�&test_boundary_without_trailing_newlines
z4TestMultipart.test_boundary_without_trailing_newlinecCs tdd�}|�|jtjj�dS)Nr�r�)rror�rq�compat32)r-rr0r0r1�test_mimebase_default_policy(s
z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|�|jtjj�dS)Nr�r�)r�)rrqr��defaultro)r-rr0r0r1�test_mimebase_custom_policy,sz)TestMultipart.test_mimebase_custom_policyN)rrrr[r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0r0r0r1r��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.txtz
text/plainr~r�)r*r+r6r�r�)r-r.r/r0r0r1�test_parse_missing_minor_type3s

z/TestNonConformant.test_parse_missing_minor_typecCsN|�d�}|�d�}|�t|d��|�t|j�d�|�|jdtj	�dS)Nz
msg_15.txtrr�rQ)
r+r?r��hasattrr*rr�r�r�StartBoundaryNotFoundDefect)r-r/�innerr0r0r1�test_same_boundary_inner_outer;s

z0TestNonConformant.test_same_boundary_inner_outercCsX|�d�}|�|��t�|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_25.txtrurrQ)
r+r�r?r�r*rr�r�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefect)r-r/r0r0r1�test_multipart_no_boundaryEs
z,TestNonConformant.test_multipart_no_boundarya^        Date: Wed, 14 Nov 2007 12:56:23 GMT
        From: foo@bar.invalid
        To: foo@bar.invalid
        Subject: Content-Transfer-Encoding: base64 and multipart
        MIME-Version: 1.0
        Content-Type: multipart/mixed;
            boundary="===============3344438784458119861=="{}

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

        Test message

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

        YWJj

        --===============3344438784458119861==--
        cCs<|�|j�d��}|�t|j�d�|�|jdtj�dS)Nz"
Content-Transfer-Encoding: base64rQr)	�_str_msg�
multipart_msgr�r*rr�r�rZ-InvalidMultipartContentTransferEncodingDefect)r-r/r0r0r1�test_multipart_invalid_ctefs
z,TestNonConformant.test_multipart_invalid_ctecCs(|�|j�d��}|�t|j�d�dS)Nr'r)r�r�r�r*rr�)r-r/r0r0r1�test_multipart_no_cte_no_defectnsz1TestNonConformant.test_multipart_no_cte_no_defectcCs<x6dD].}|�|j�d�|���}|�t|j�d�qWdS)N)rrBZBINaryz
Content-Transfer-Encoding: {}r)r�r�r�r*rr�)r-r{r/r0r0r1�"test_multipart_valid_cte_no_defectss

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~zContent-Typer�z
text/plainzcontent-typerzzContent-Type: foo

)
r*rrr�r�r6rrrgrh)r-r.�neqr/rr�r0r0r1�test_invalid_content_type{s 
z+TestNonConformant.test_invalid_content_typecCs"|j}|�d�}||��d�dS)Nz
msg_31.txtzm--BOUNDARY
Content-Type: text/plain

message 1

--BOUNDARY
Content-Type: text/plain

message 2

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

counter to RFC 2822, there's no separating newline here
)rr+rc)r-r.r/r0r0r1�test_no_separating_blank_line�s
z/TestNonConformant.test_no_separating_blank_linecCsX|�d�}|�t|d��|�t|j�d�|�|jdtj�|�|jdtj	�dS)Nz
msg_41.txtr�rurrQ)
r+r�r�r*rr�r�rr�r�)r-r/r0r0r1�test_lying_multipart�s
z&TestNonConformant.test_lying_multipartcCsD|�d�}|�d��d�}|�t|j�d�|�|jdtj�dS)Nz
msg_42.txtrQr)r+r?r*rr�r�rr�)r-r�Zbadr0r0r1�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��bodyrQrz Line 1
)r*rqr�r�r?rr��assertDefectsEqualrZ#FirstHeaderLineIsContinuationDefect�line)r-r.rr/r0r0r1�&test_first_line_is_continuation_header�s

z8TestNonConformant.test_first_line_is_continuation_headercCsB|�d�}|�|��dg�|�|��d�|�|jtjg�dS)Nz&Subject: test
not a header
To: abc

b
r�znot a header
To: abc

b
)r�r*r�r?r�r�rZ MissingHeaderBodySeparatorDefect)r-r/r0r0r1�"test_missing_header_body_separator�s

z4TestNonConformant.test_missing_header_body_separatorN)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0r0r0r1r�1s
	
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestRFC2047cCsR|j}d}t|�}||ddddg�t|�}|t|�d�|�|jdd�d�dS)	NzVRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=)sRe: N)s
r�ksm�rg�szmac-iceland)s
 baz foo bar Nu+Re: räksmörgås baz foo bar räksmörgåsr	)r"ziRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?=
 =?mac-iceland?q?=9Arg=8Cs?=)r*r
rr�rrp)r-r.r�dhr_r0r0r1�test_rfc2047_multiline�sz"TestRFC2047.test_rfc2047_multilinecCs:|j}d}t|�}||ddg�tt|��}||d�dS)Nz0=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>)sAndr�z
iso-8859-1)s Pirard <pirard@dom.ain>NuAndré Pirard <pirard@dom.ain>)r*r
r�r)r-r.rr�r_r0r0r1�test_whitespace_keeper_unicode�sz*TestRFC2047.test_whitespace_keeper_unicodecCs>|j}d}t|�}||ddddg�tt|��}||d�dS)NzWThe =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?=)sThe N)squick brown foxz
iso-8859-1)s jumped over the N)slazy dogz
iso-8859-1z,The quick brown fox jumped over the lazy dog)r*r
r�r)r-r.rr��hur0r0r1� test_whitespace_keeper_unicode_2�s
z,TestRFC2047.test_whitespace_keeper_unicode_2cCs&d}t|�}|�|dddddg�dS)Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord)sSmN)��z
iso-8859-1)srgN)��z
iso-8859-1)ssbordN)r
r*)r-rr�r0r0r1�test_rfc2047_missing_whitespace	s

z+TestRFC2047.test_rfc2047_missing_whitespacecCs&d}t|�}|�|dddddg�dS)Nz7Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord)sSm N)r�z
iso-8859-1)s rg N)r�z
iso-8859-1)s sbordN)r
r*)r-rr�r0r0r1�test_rfc2047_with_whitespace	s

z(TestRFC2047.test_rfc2047_with_whitespacecCsFd}dddddg}x.|D]&\}}t||�}|�||dfg�qWdS)Nz=?iso-8859-1?B?%s?=)zdm==�v)zdm=r�)Zdmr�)zdmk=svi)Zdmksviz
iso-8859-1)r
r*)r-rr@�q�ar�r0r0r1�test_rfc2047_B_bad_padding	sz&TestRFC2047.test_rfc2047_B_bad_paddingcCsd}|�t|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=)sandr�=zzz
iso-8859-1)r*r
)r-rr0r0r1�test_rfc2047_Q_invalid_digits	s
z)TestRFC2047.test_rfc2047_Q_invalid_digitscCsd}|�t|�dddg�dS)Nz(=?ISO-8859-1?Q?a?=))�(N)�az
iso-8859-1)�)N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_1"	s
z"TestRFC2047.test_rfc2047_rfc2047_1cCsd}|�t|�dddg�dS)Nz(=?ISO-8859-1?Q?a?= b))r�N)r�z
iso-8859-1)s b)N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_2(	s
z"TestRFC2047.test_rfc2047_rfc2047_2cCsd}|�t|�dddg�dS)Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=))r�N)sabz
iso-8859-1)r�N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_3.	s
z"TestRFC2047.test_rfc2047_rfc2047_3cCsd}|�t|�dddg�dS)Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=))r�N)sabz
iso-8859-1)r�N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_44	s
z"TestRFC2047.test_rfc2047_rfc2047_4cCsd}|�t|�dddg�dS)Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=))r�N)sabz
iso-8859-1)r�N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_5a:	s
z#TestRFC2047.test_rfc2047_rfc2047_5acCsd}|�t|�dddg�dS)Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=))r�N)sabz
iso-8859-1)r�N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_5b@	s
z#TestRFC2047.test_rfc2047_rfc2047_5bcCsd}|�t|�dddg�dS)Nz(=?ISO-8859-1?Q?a_b?=))r�N)sa bz
iso-8859-1)r�N)r*r
)r-rr0r0r1�test_rfc2047_rfc2047_6F	s
z"TestRFC2047.test_rfc2047_rfc2047_6cCsTd}|�t|�ddddg�|�tt|����|���|�ttt|���d�dS)Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))r�N)r�z
iso-8859-1)s bz
iso-8859-2)r�Nz(a b))r*r
rrpr\r�)r-rr0r0r1�test_rfc2047_rfc2047_7L	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*r
rrpr��
splitlinesr�)r-rr0r0r1�test_multiline_headerU	s
z!TestRFC2047.test_multiline_headerN)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0r0r0r1r��s 		
	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestMIMEMessagec	Cs"td��}|��|_WdQRXdS)Nz
msg_11.txt)r"reZ_text)r-rir0r0r1r[b	s
zTestMIMEMessage.setUpcCs|�ttd�dS)Nza plain string)r]rGr)r-r0r0r1�test_type_errorf	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||��d�|��}|�|t�|t|�d�|d}|�||�||d|�dS)Nz
A sub-messager�zmessage/rfc822rQr�subject)	r*rrr6r?r��listrro)r-r.r�r�rrjrSr0r0r1�test_valid_argumenti	sz#TestMIMEMessage.test_valid_argumentcCs:t�}d|d<t�}d|d<t|�}|�tj|j|�dS)Nz	subpart 1r�z	subpart 2)rrr]rZMultipartConversionErrorrH)r-r�r}r�r0r0r1�test_bad_multipartw	sz"TestMIMEMessage.test_bad_multipartcCsTt�}d|d<|�d�t|�}d|d<t�}t|�}|�|�|�|��d�dS)NzAn enclosed messager�z!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.
)rr;rrrrgr*rh)r-rr�rr�r0r0r1�
test_generate	s


zTestMIMEMessage.test_generatecCst|j}|�d�}||��d�|��}|�|t�|t|�d�|d}|�|t�||dd�||��d�dS)Nz
msg_11.txtzmessage/rfc822rQrr�zAn enclosed messagez!Here is the body of the message.
)r*r+r6r?r�r�rr)r-r.r/rjZsubmsgr0r0r1�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)Nz
msg_16.txtzmultipart/reportrvrz
text/plaina�This report relates to a message you sent with the following header fields:

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

Your message cannot be delivered to the following recipients:

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

rQzmessage/delivery-statusruzoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnsz
reporting-mta)r_r'Znsd�actionZfailedzoriginal-recipient)r�r')zjangel1@cougar.noc.ucla.edur'r�zfinal-recipientzmessage/rfc822z
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r*r+r6r�r�rr?r�rr7r�r�)r-r.r/rSZdsn1Zdsn2rjr�r0r0r1�test_dsn�	sB






zTestMIMEMessage.test_dsnc		Cs�|j}td��}|��}WdQRXt�}d|d<d|d<d|d<d|_d	|_td
�}td�}|jdd
dd�|�|�|�|�t	�}t
|�}|�|�||��|�dS)Nz
msg_21.txtzaperson@dom.ainr�zbperson@dom.ainr�r4r�zMIME messagezEnd of MIME message
r�r�zContent-Typezmultipart/mixedrV)r�)
rr"rerr�r�rr�rHrrrgrh)	r-r.rir~r/r�r}rr�r0r0r1�
test_epilogue�	s$



zTestMIMEMessage.test_epiloguecCsv|j}t�}d|d<d|d<d|d<d|_d|_td	�}td
�}|jddd
d�|�|�|�|�||��d�dS)Nzaperson@dom.ainr�zbperson@dom.ainr�r4r�zMIME messager'r�r�zContent-Typezmultipart/mixedrV)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--
)rrr�r�rr�rHrc)r-r.r/r�r}r0r0r1�test_no_nl_preamble�	s

z#TestMIMEMessage.test_no_nl_preamblec	Cs�|j}td��}t�|�}WdQRX|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nz
msg_30.txtrzmessage/rfc822rQz
text/plain)r*r"rq�message_from_filer?�get_default_typer6)r-r.rir/�
container1�
container2�container1a�container2ar0r0r1�test_default_type
s




z!TestMIMEMessage.test_default_typec	Cs�|j}td��}t�|�}WdQRX|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�|�d�}||��d�||��d�dS)Nz
msg_28.txtrzmessage/rfc822rQz
text/plain)r*r"rqrr?rr6)r-r.rir/rrrrr0r0r1�.test_default_type_with_explicit_container_type 
s




z>TestMIMEMessage.test_default_type_with_explicit_container_typecCs�|j}|j}tdd�}d|_td�}td�}t|�}t|�}|�|�|�|�||��d�||��d�||��d�||��d�||�	d�d�|d	=|d
=|d	=|d
=||��d�||��d�||��d�||��d�||�	d�d�dS)NZdigestrVr'z
message 1
z
message 2
zmessage/rfc822ra�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--
zcontent-typezmime-versionaBContent-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*rrr�rrrHr6rrc)r-r.r�r�Z	subpart1aZ	subpart2aZsubpart1Zsubpart2r0r0r1�test_default_type_non_parsed1
s4




z,TestMIMEMessage.test_default_type_non_parsedcCsZ|j}td�}td�}t||fd�}|t|���d�||�d�|�||�d�|�dS)Nr')Z	_subpartsrurrQ)r*rrrr?)r-r.Ztext1Ztext2r/r0r0r1�$test_mime_attachments_in_constructor{
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|�|���dS)N)rr�r�)r-r/r0r0r1�"test_default_multipart_constructor�
sz2TestMIMEMessage.test_default_multipart_constructorcCs0t�}d|d<d|d<|�|�d�ddg�dS)Nza@b.comr�zc@d.comr�)rr*r,)r-r/r0r0r1�test_multipart_default_policy�
sz-TestMIMEMessage.test_multipart_default_policyc	CsJttjjd�}d|d<|�t��}d|d<WdQRX|�t|j�d�dS)N)r�za@b.comr�zc@d.comz.There may be at most 1 To headers in a message)	rrqr�r�r]r�r*r�Z	exception)r-r/�cmr0r0r1�test_multipart_custom_policy�
sz,TestMIMEMessage.test_multipart_custom_policyN)rrrr[r�r�r�r�r�r�r�rrrr	r
rrrr0r0r0r1r�a	s 9#J	r�c@s�eZdZdZdd�Zd4dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)5�TestIdempotentr&c	Cs.t|��}|��}WdQRXt�|�}||fS)N)r"rerqr�)r-r�rir@r/r0r0r1r+�
s

zTestIdempotent._msgobjFcCs8|j}t�}t|dd�}|j||d�|||���dS)Nr)rJ)r�)rrrrgrh)r-r/r~r�r.rr�r0r0r1�_idempotent�
s
zTestIdempotent._idempotentcCs�|j}|�d�\}}||��d�||��d�||��d�||��dd�||�d�d�||jd�||jd�|�	||�dS)	Nz
msg_01.txtz
text/plainr~r�rQ)r3zus-asciir3zus-ascii)
r*r+r6r�r�r�r7r�r�r)r-r.r/r~r0r0r1�test_parse_text_message�
sz&TestIdempotent.test_parse_text_messagecCsP|j}|�d�\}}||��d�||��d�||�d�d�|�||�dS)Nz
msg_03.txtz
text/plainr3)r*r+r6r�r7r)r-r.r/r~r0r0r1�test_parse_untyped_message�
sz)TestIdempotent.test_parse_untyped_messagecCs|�d�\}}|�||�dS)Nz
msg_04.txt)r+r)r-r/r~r0r0r1�test_simple_multipart�
sz$TestIdempotent.test_simple_multipartcCs|�d�\}}|�||�dS)Nz
msg_02.txt)r+r)r-r/r~r0r0r1�test_MIME_digest�
szTestIdempotent.test_MIME_digestcCs|�d�\}}|�||�dS)Nz
msg_27.txt)r+r)r-r/r~r0r0r1�test_long_header�
szTestIdempotent.test_long_headercCs|�d�\}}|�||�dS)Nz
msg_28.txt)r+r)r-r/r~r0r0r1�"test_MIME_digest_with_part_headers�
sz1TestIdempotent.test_MIME_digest_with_part_headerscCs|�d�\}}|�||�dS)Nz
msg_06.txt)r+r)r-r/r~r0r0r1�test_mixed_with_image�
sz$TestIdempotent.test_mixed_with_imagecCs|�d�\}}|�||�dS)Nz
msg_05.txt)r+r)r-r/r~r0r0r1�test_multipart_report�
sz$TestIdempotent.test_multipart_reportcCs|�d�\}}|�||�dS)Nz
msg_16.txt)r+r)r-r/r~r0r0r1r��
szTestIdempotent.test_dsncCs|�d�\}}|�||�dS)Nz
msg_21.txt)r+r)r-r/r~r0r0r1�test_preamble_epilogue�
sz%TestIdempotent.test_preamble_epiloguecCs|�d�\}}|�||�dS)Nz
msg_23.txt)r+r)r-r/r~r0r0r1�test_multipart_one_part�
sz&TestIdempotent.test_multipart_one_partcCs|�d�\}}|�||�dS)Nz
msg_24.txt)r+r)r-r/r~r0r0r1�test_multipart_no_parts�
sz&TestIdempotent.test_multipart_no_partscCs|�d�\}}|�||�dS)Nz
msg_31.txt)r+r)r-r/r~r0r0r1r��
sz%TestIdempotent.test_no_start_boundarycCs|�d�\}}|�||�dS)Nz
msg_32.txt)r+r)r-r/r~r0r0r1�test_rfc2231_charset�
sz#TestIdempotent.test_rfc2231_charsetcCs|�d�\}}|�||�dS)Nz
msg_33.txt)r+r)r-r/r~r0r0r1�test_more_rfc2231_parameters�
sz+TestIdempotent.test_more_rfc2231_parameterscCs|�d�\}}|�||�dS)Nz
msg_34.txt)r+r)r-r/r~r0r0r1�%test_text_plain_in_a_multipart_digest�
sz4TestIdempotent.test_text_plain_in_a_multipart_digestcCs|�d�\}}|�||�dS)Nzmsg_12a.txt)r+r)r-r/r~r0r0r1�test_nested_multipart_mixeds�
sz+TestIdempotent.test_nested_multipart_mixedscCs|�d�\}}|�||�dS)Nz
msg_36.txt)r+r)r-r/r~r0r0r1�%test_message_external_body_idempotent�
sz4TestIdempotent.test_message_external_body_idempotentcCs"|�d�\}}|j||dd�dS)Nz
msg_43.txtT)r�)r+r)r-r/r~r0r0r1�test_message_delivery_statussz+TestIdempotent.test_message_delivery_statuscCs|�d�\}}|�||�dS)Nz
msg_45.txt)r+r)r-r/r~r0r0r1�test_message_signed_idempotentsz-TestIdempotent.test_message_signed_idempotentcCs\|j}|�d�\}}||��d�i}x|��D]\}}|||<q0W||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)Nz
msg_05.txtzmultipart/reportzreport-typezdelivery-statusr�z%D1690A7AC1.996856090/mail.example.comz$This is a MIME-encapsulated message.rvrz
text/plainzYadda yadda yaddarQruzmessage/rfc822)r*r+r6r�r�r�r�rr?r�rr�)r-r.r/r~�paramsZpkZpvr�r}Zmsg3rjZmsg4r0r0r1�test_content_types4


z TestIdempotent.test_content_typecCs�|j}|�d�\}}||��d�|��}|�|t�|t|�d�|d}|�|t�||��d�|�|��t�||��|j	�dS)Nz
msg_06.txtzmessage/rfc822rQrz
text/plain)
r*r+r6r?r�r�rrr�r�)r-r.r/r~rjr�r0r0r1�test_parser'szTestIdempotent.test_parserN)F)rrrr�r+rrrrrrrrrr�rrrr�rrrrr r!r"r$r%r0r0r0r1r�
s2
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgS)h�TestMiscellaneousc	CsVtd��}|��}WdQRXt�|�}t�}t|dd�}|�|�|�||���dS)Nz
msg_01.txtr)rJ)	r"rerqr�rrrgr*rh)r-rir~r/rr�r0r0r1�test_message_from_string;s


z*TestMiscellaneous.test_message_from_stringc	Cs`td��N}|��}|�d�t�|�}t�}t|dd�}|�|�|�||�	��WdQRXdS)Nz
msg_01.txtr)rJ)
r"re�seekrqrrrrgr*rh)r-rir~r/rr�r0r0r1�test_message_from_fileFs



z(TestMiscellaneous.test_message_from_filec	Cs�td��}|��}WdQRXGdd�dt�}t�||�}|�||�td��}|��}WdQRXt�||�}x|��D]}|�||�qvWdS)Nz
msg_01.txtc@seZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN)rrrr0r0r0r1�	MyMessageWsr*z
msg_02.txt)r"rerrqr�r��walk)r-rir~r*r/rSr0r0r1�#test_message_from_string_with_classRs

z5TestMiscellaneous.test_message_from_string_with_classc	Cs~Gdd�dt�}td��}t�||�}WdQRX|�||�td��}t�||�}WdQRXx|��D]}|�||�qfWdS)Nc@seZdZdS)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageN)rrrr0r0r0r1r*esr*z
msg_01.txtz
msg_02.txt)rr"rqrr�r+)r-r*rir/rSr0r0r1�!test_message_from_file_with_classcs

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���dS)N)�super�__init__)r-)�	__class__r0r1r/ssz\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)rrrr/�
__classcell__r0r0)r0r1r*rsr*zSubject: test

test)rr�r�)r-r*r/r0r0r1�.test_custom_message_does_not_require_argumentsqsz@TestMiscellaneous.test_custom_message_does_not_require_argumentscCs@td�}|�t|j�dddddddd	d
ddd
dddddg�dS)Nrqrr3rr�
feedparserrsr_rr�Zmessage_from_binary_filer`rr�r
rkrr)�
__import__r*�sorted�__all__)r-�moduler0r0r1�test__all__xs
zTestMiscellaneous.test__all__cCs:t��}|�t�t�|��dd�t�|�dd��dS)N�)r�r*r�	parsedate�
formatdate�gmtime)r-r�r0r0r1�test_formatdate�sz!TestMiscellaneous.test_formatdatecCs>t��}|�t�tj|dd��dd�t�|�dd��dS)NT)r�r9)r�r*rr:r;r�)r-r�r0r0r1�test_formatdate_localtime�sz+TestMiscellaneous.test_formatdate_localtimec	CsVt��}|�tj|dd�t�dt�|���|�tj|ddd�t�dt�|���dS)NF)r�z%a, %d %b %Y %H:%M:%S -0000T)r�Zusegmtz%a, %d %b %Y %H:%M:%S GMT)r�r*rr;r�r<)r-r�r0r0r1�test_formatdate_usegmt�sz(TestMiscellaneous.test_formatdate_usegmtcCs�|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��|�t�d��dS)Nr'r(�0zA Complete Waste of Time)r�rr:�parsedate_tz)r-r0r0r1�/test_parsedate_returns_None_for_invalid_strings�szATestMiscellaneous.test_parsedate_returns_None_for_invalid_stringscCs|�t�d�t�d��dS)NzWed,3 Apr 2002 14:58:26 +0800zWed, 3 Apr 2002 14:58:26 +0800)r*rr:)r-r0r0r1�test_parsedate_compact�sz(TestMiscellaneous.test_parsedate_compactcCs|j}|t�d�d�dS)Nz25 Feb 2003 13:47:26 -0800)
i�ru��
�/�rrQr�i����)r*rrA)r-r.r0r0r1�test_parsedate_no_dayofweek�s
z-TestMiscellaneous.test_parsedate_no_dayofweekcCs|j}|t�d�d�dS)Nz5 Feb 2003 13:47:26 -0800)
i�ru�rErFrGrrQr�i����)r*rrA)r-r.r0r0r1�#test_parsedate_compact_no_dayofweek�s
z5TestMiscellaneous.test_parsedate_compact_no_dayofweekcCs|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26+0800)
i�rYrv��:rGrrQr�i�p)r*rrA)r-r0r0r1�.test_parsedate_no_space_before_positive_offset�sz@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCs|�t�d�d�dS)NzWed, 3 Apr 2002 14:58:26-0800)
i�rYrvrKrLrGrrQr�i����)r*rrA)r-r0r0r1�.test_parsedate_no_space_before_negative_offset�sz@TestMiscellaneous.test_parsedate_no_space_before_negative_offsetcCs*|j}|t�d�d�|t�d�d�dS)Nz5 Feb 2003 13.47.26 -0800)
i�rurIrErFrGrrQr�i����z5 Feb 2003 13.47 -0800)
i�rurIrErFrrrQr�i����)r*rrA)r-r.r0r0r1�%test_parsedate_accepts_time_with_dots�s


z7TestMiscellaneous.test_parsedate_accepts_time_with_dotscCs�|j}t�d�}tt�|��}|t�|�dd�|dd��|tt�d|��d�t�d�}tt�|dd���}|t�|�dd�|dd��|tt�d|dd���d�dS)Nz5 Feb 2003 13:47:26 -0800r9z%Yi��	)	r*rr:�intr�Zmktimer�r�rA)r-r.ZtimetuprTr0r0r1�+test_parsedate_acceptable_to_time_functions�s
 
 z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCs(|�t�d�d�|�t�d�d�dS)N)
i�rQrQrrrr�r�r�rr)
i�rQrQrrrr�r�r�i�i.���)r*rZ	mktime_tz)r-r0r0r1�test_mktime_tz�sz TestMiscellaneous.test_mktime_tzcCs4|�t�d�t�d��|�t�d�t�d��dS)aTest for parsing a date with a two-digit year.

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

        z25 Feb 03 13:47:26 -0800z25 Feb 2003 13:47:26 -0800z25 Feb 71 13:47:26 -0800z25 Feb 1971 13:47:26 -0800N)r*rrA)r-r0r0r1�test_parsedate_y2k�sz$TestMiscellaneous.test_parsedate_y2kcCs.|�t�d�d�|�t�t�d��d�dS)Nz<>)r'r'r')r*r�	parseaddr�
formataddr)r-r0r0r1�test_parseaddr_empty�sz&TestMiscellaneous.test_parseaddr_emptycCs:|�t�d�d�|�t�d�d�|�t�d�d�dS)Nza@b@c)r'r'za@b.c@cza@172.17.0.1@c)r*rrU)r-r0r0r1�test_parseaddr_multiple_domains�sz1TestMiscellaneous.test_parseaddr_multiple_domainscCs|�t�d�d�dS)N)zA Silly Personzperson@dom.ainzA Silly Person <person@dom.ain>)r*rrV)r-r0r0r1�test_noquote_dump�sz#TestMiscellaneous.test_noquote_dumpcCsP|�t�d�d�|�t�d�d�d}d}|�t�t�||f��||f�dS)N)zA (Very) Silly Personzperson@dom.ainz("A (Very) Silly Person" <person@dom.ain>z*"A \(Very\) Silly Person" <person@dom.ain>zA \(Special\) Personzperson@dom.ain)r*rrVrU)r-r�rbr0r0r1�test_escape_dump�sz"TestMiscellaneous.test_escape_dumpcCs>|�t�d�d�d}d}|�t�t�||f��||f�dS)N)zArthur \Backslash\ Foobarzperson@dom.ainz."Arthur \\Backslash\\ Foobar" <person@dom.ain>zArthur \Backslash\ Foobarzperson@dom.ain)r*rrVrU)r-r�rbr0r0r1�test_escape_backslashessz)TestMiscellaneous.test_escape_backslashescCsBd}d}d}d}|�t�||f�|�|�t�||fd�|�dS)NuHäns Würstzperson@dom.ainz-=?utf-8?b?SMOkbnMgV8O8cnN0?= <person@dom.ain>z0=?iso-8859-1?q?H=E4ns_W=FCrst?= <person@dom.ain>z
iso-8859-1)r*rrV)r-r��addr�utf8_base64Z
latin1_quoprir0r0r1�test_quotes_unicode_namessz+TestMiscellaneous.test_quotes_unicode_namescsld}d}d}d�G�fdd�d�}|�}d�|f}|�t�||f|�|�|�t�||ftd��|�dS)	NuHäns Würstzperson@dom.ainz-=?utf-8?b?SMOkbnMgV8O8cnN0?= <person@dom.ain>ZFOOBARcseZdZ�fdd�ZdS)zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockcs�S)Nr0)r-�string)r�r0r1�
header_encodeszYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)rrrr`r0)r�r0r1�CharsetMocksraz%s <%s>zutf-8)r*rrVr)r-r�r\r]raZmockZ
mock_expectedr0)r�r1�$test_accepts_any_charset_like_objectsz6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|�ttj||f|�dS)NuHäns Würstzperson@dom.ain)�objectr]�AttributeErrorrrV)r-r�r\Zbad_charsetr0r0r1�-test_invalid_charset_like_object_raises_error%s
z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|�ttjd|f�|�ttjd|f�dS)Nupersön@dom.in�Name)r]�UnicodeErrorrrV)r-r\r0r0r1�!test_unicode_address_raises_error.sz3TestMiscellaneous.test_unicode_address_raises_errorcCsVd}d}d\}}|�t�|�||f�|�t�|�||f�|�t�||f�|�dS)NzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>)zJohn X. Doezjxd@example.com)r*rrUrV)r-r��yr�rbr0r0r1�test_name_with_dot4sz$TestMiscellaneous.test_name_with_dotcCs:|j}|t�d�d�|t�d�d�|t�d�d�dS)Nz""example" example"@example.com)r'z""example" example"@example.comz!"\"example\" example"@example.com)r'z!"\"example\" example"@example.comz#"\\"example\\" example"@example.com)r'z#"\\"example\\" example"@example.com)r*rrU)r-r.r0r0r1�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'zmerwok wok@xample.comzmerwok wok@xample.com)r'zmerwok  wok@xample.comzmerwok  wok@xample.comz merwok  wok  @xample.com)r'zmerwok"wok"  wok@xample.comzmerwok"wok"  wok@xample.com)r'zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.com)r*rrU)r-r0r0r1�-test_parseaddr_preserves_spaces_in_local_partOsz?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_partcCs0d}d}|�t�|�|�|�t�|�|�dS)N)z#'foo@example.com' (foo@example.com)zfoo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>)r*rrUrV)r-r\Zaddrstrr0r0r1�6test_formataddr_does_not_quote_parens_in_quoted_stringaszHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_stringcCsd}|�t�|�d�dS)NzFoo
	Bar <foo@example.com>)zFoo Barzfoo@example.com)r*rrU)r-r�r0r0r1�test_multiline_from_commentjsz-TestMiscellaneous.test_multiline_from_commentcCs|�t�d�d�dS)N)zA Silly; Personzperson@dom.ainz""A Silly; Person" <person@dom.ain>)r*rrV)r-r0r0r1�test_quote_dumppsz!TestMiscellaneous.test_quote_dumpcCs�|j}|j}t�}t�}||d�||d�||d�|d|�|d|�|d|�||d�||d�||d�|d|�|d|�|d|�|||�|||�dS)Nzus-asciizUS-ASCIIzUs-AsCiIZusasciiZUSASCIIZUsAsCiI)r*ZassertNotEqualr)r-r.�neZcset1Zcset2r0r0r1�test_charset_richcomparisonsus$












z.TestMiscellaneous.test_charset_richcomparisonscCs"|j}|t�ddg�ddg�dS)Nzaperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>)z	Al Personzaperson@dom.ain)z
Bud Personzbperson@dom.ain)r*r�getaddresses)r-r.r0r0r1�test_getaddresses�s
z#TestMiscellaneous.test_getaddressescCsN|j}|t�dg�dg�|t�dg�dddg�|t�ddg�ddg�dS)Nzfoo: ;)r'r'z	[]*-- =~$)r'z*--z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerz
jason@dom.ain)r*rrr)r-r.r0r0r1�test_getaddresses_nasty�sz)TestMiscellaneous.test_getaddresses_nastycCs(|j}t�dg�}||ddd�dS)z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>rrQzfoo@bar.comN)r*rrr)r-r.Zaddrsr0r0r1�"test_getaddresses_embedded_comment�sz4TestMiscellaneous.test_getaddresses_embedded_commentc	sjGdd�dt���fdd�td�D�}t|��WdQRXtdd�|D�g�}|�tt|��t|��dS)Nc@seZdZdd�ZdS)zBTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadcSsFg|_|jj}tj}tj}|�d}x|�|kr@||dd��q&WdS)Ng@ztestdomain-string)�domain)�msgidsr#r�
make_msgidr�Z	monotonic)r-r#rxZclockZtfinr0r0r1�run�s
zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)rrrryr0r0r0r1�MsgidsThread�srzcsg|]
}���qSr0r0)rNr0)rzr0r1rP�sz@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>rIcSsg|]
}|j�qSr0)rw)rNrTr0r0r1rP�s)rr6r!�sumr*r�set)r-ZthreadsZall_idsr0)rzr1�test_make_msgid_collisions�s

z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||��d�dS)Nzcontent-dispositionr�zfoo\wacky"name)r�)r*rr�rM)r-r.r/r0r0r1�test_utils_quote_unquote�s
z*TestMiscellaneous.test_utils_quote_unquotecCstd�}|�|��d�dS)Nz
not a charsetr=)rr*�get_body_encoding)r-r3r0r0r1�)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-8zContent-Typezcontent-typerQrzutf-8r=shello world)r3zaGVsbG8gd29ybGQ=
T)r>zcontent-transfer-encodingztext/plain; charset="US-ASCII"zus-asciizhello worldr)
r*rrJrrrr;r?rr{)r-r.r/rKr3r0r0r1�-test_get_body_encoding_with_uppercase_charset�s.z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs(td�}td�}|�|��|���dS)Nzus-asciizUS-ASCII)rr*r)r-ZlcZucr0r0r1�test_charsets_case_insensitive�sz0TestMiscellaneous.test_charsets_case_insensitivecCs4|j}|�d�}t�}t�||�||��d�dS)Nz
msg_43.txtaBmultipart/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
)rr+rrr�rh)r-r.r/rr0r0r1�1test_partial_falls_inside_message_delivery_status�s
zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs"|�tjjdd�dd�d�dS)Nztestdomain-string)rvi��z@testdomain-string>)r*rqrrx)r-r0r0r1�test_make_msgid_domain
sz(TestMiscellaneous.test_make_msgid_domaincCs$|�tjjddd�dd�d�dS)Nz
test-idstringztestdomain-string)Zidstringrvi���z!.test-idstring@testdomain-string>)r*rqrrx)r-r0r0r1�test_make_msgid_idstring
sz*TestMiscellaneous.test_make_msgid_idstringc	Cs@td��.}d|_}|�tj���d|d��WdQRXdS)Nzsocket.getfqdnzpythontest.example.com�@�>)rZreturn_valuer�rqrrx�endswith)r-Zmock_getfqdnrvr0r0r1�test_make_msgid_default_domain
s



z0TestMiscellaneous.test_make_msgid_default_domainc	Csftddd��}|��}WdQRX|�dd�}t�|�}t�}tj�|�}|�|�|�	|�
�|�dS)Nz
msg_26.txtr&)�newlinez
)r"rerrqr�rrsrrgr*rh)r-�f�msgtxt�	msgtxt_nlr/rr�r0r0r1�test_Generator_linend
s

z'TestMiscellaneous.test_Generator_linendc	Csptddd��}|��}WdQRX|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
��d�|�dS)Nz
msg_26.txtr&)r�z
)r�ro)r"rerrqr�rrsrrgr*rhr>)r-r�r�r�r/rr�r0r0r1�test_BytesGenerator_linend$
s
z,TestMiscellaneous.test_BytesGenerator_linendc	Csttdd��}|��}WdQRX|�dd�}|�dd�}t�|�}t�}tj�|�}|j|dd�|�	|�
�|�dS)	Nz
msg_26.txtrswith attachmentsfo�s
r�z
)r�)r"rerrqr`rrsrrgr*rh)r-r�r�r�r/rr�r0r0r1�)test_BytesGenerator_linend_with_non_ascii/
s
z;TestMiscellaneous.test_BytesGenerator_linend_with_non_asciic
Cs�tdd��}|��}WdQRXtdd��}|��}WdQRXtdft|fft|fftt�fftdftdfg}x�|D]~\}}|j	|j
dd�� ||�}|�|jt
jj�WdQRX|j	|j
dd��*||d	t
jji�}|�|jt
jj�WdQRXqrWdS)
Nzaudiotest.aurzPyBanner048.gif)r')r�r�r�)�clsr�r�r�)r"rerrrrrrr�subTestrror�rqr�r�)r-riZ	audiodatar�classesr��constructorrr0r0r1�!test_mime_classes_policy_argument;
s"

z3TestMiscellaneous.test_mime_classes_policy_argumentN)6rrrr'r)r,r-r2r8r=r>r?rBrCrHrJrMrNrOrRrSrTrWrXrYrZr[r^rbrerhrjrkrlrmrnrorqrsrtrur}r~r�r�r�r�r�r�r�r�r�r�r�r0r0r0r1r&:sf




			
*r&c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestIteratorsc	Cs�|j}|j}|�d�}t�|�}t|�}|t|�d�|t�|�|�	��|�d�}t�|�}t|�}|t|�d�t
d��}|t�|�|���WdQRXdS)Nz
msg_01.txtr9z
msg_02.txt�+z
msg_19.txt)r*rr+rZbody_line_iteratorr�r�EMPTYSTRINGr�r?r"re)r-r.r�r/�itr�rir0r0r1�test_body_line_iteratorS
s




z%TestIterators.test_body_line_iteratorcCsf|j}|�d�}t�|d�}g}d}x"|D]}|d7}|�|���q*W||d�|t�|�d�dS)Nz
msg_04.txtr~rrQruz`a simple kind of mirror
to reflect upon our own
a simple kind of mirror
to reflect upon our own
)r*r+r�typed_subpart_iteratorr#r?r�r�)r-r.r/r�r��subpartsrSr0r0r1�test_typed_subpart_iteratord
s



z)TestIterators.test_typed_subpart_iteratorcCsh|j}|�d�}t�|dd�}g}d}x"|D]}|d7}|�|���q,W||d�|t�|�d�dS)Nz
msg_03.txtr~r�rrQz%
Hi,

Do you like this message?

-Me
)r*r+rr�r#r?r�r�)r-r.r/r�r�r�rSr0r0r1�(test_typed_subpart_iterator_default_typeu
s



z6TestIterators.test_typed_subpart_iterator_default_typecCs�ddddddddg}d	d
lm}m}|�}g}d	}xZ|D]R\}}|�|�||7}d	}	x&t|j|�D]}
|�|
�|	d7}	qdW|�||	�q8W|�t|�|�|�d�	d
d�|D��d�	|��dS)z�FeedParser BufferedSubFile.push() assumed it received complete
           line endings.  A CR ending one push() followed by a LF starting
           the next push() added an empty line.
        )za
 
ru)rbr)zc
rQ)r'r)zd
rQ)ze
r)z
frQ)z
rQr)�BufferedSubFile�NeedMoreDatarQr'cSsg|]\}}|�qSr0r0)rN�il�nr0r0r1rP�
sz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
�email.feedparserr�r��push�iter�readliner#r*rr�)r-Zimtr�r��bsfZom�ntr�r�Zn1Zolr0r0r1�test_pushCR_LF�
s,

zTestIterators.test_pushCR_LFcs�ddlm}m}d}d}d�d��fdd�t|�D��d	}|�d
�}|�}g}xDtdt|�|�D]0}	||	|	|�}
|�|
�|�t	|j
|��qbW|�||�dS)Nr)r�r�i'rIzabcd 	
r'c3s|]}t��VqdS)N)r)rNr0)�charsr0r1r1�
sz1TestIterators.test_push_random.<locals>.<genexpr>r&T)r�r�r�r�r6r�rr��extendr�r�r*)r-r�r�r�Z	chunksizer�targetr�r�r0�chunkr0)r�r1�test_push_random�
s 

zTestIterators.test_push_randomN)rrrr�r�r�r�r�r0r0r0r1r�R
s
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs&t�}x|D]}|�|�qW|��S)N)r$�feed�close)r-�chunksr3r�r0r0r1�parse�
s
zTestFeedParsers.parsecCs.|�d�}|�|dd�|�|dd�dS)NzFirst: val
: bad
Second: valr��valr�)r�r*)r-r/r0r0r1�test_empty_header_name_handled�
s
z.TestFeedParsers.test_empty_header_name_handledcCs�|�dg�}|�|��ddddg�|�dg�}|�|��ddddg�|�ddg�}|�|��dd	g�|�d
dg�}|�|��ddg�|�d
dg�}|�|��ddg�|�d
g�}|�|��dg�|�d
ddg�}|�|��ddg�dS)Nz
a:
b:
c:
d:
r�rb�c�dza:
b:
c:
d:za:
bzc:
Zbcza:
zb:
z
b:
ua:…b:
c:
)r�u	…b:
c:ub:…)r�r')rbu…c:)r�r*r�r[)r-rr0r0r1�
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

r�)r�rbza:b

�…za:
zb: )r�r'rb)r�r*r[r?)r-�M�Nrr0r0r1�test_long_lines�
szTestFeedParsers.test_long_linesN)rrrr�r�r�r�r0r0r0r1r��
sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdZ
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�TestParsersc	Csr|j}td��}t��|�}WdQRX||dd�||dd�||��d�|�|���|�|��t	�dS)Nz
msg_02.txtr�zppp-request@zzz.orgr�zppp@zzz.orgzmultipart/mixed)
r*r"r
r�r6r�r�r�r?r�)r-r.rir/r0r0r1�test_header_parser�
s
zTestParsers.test_header_parserc	Cs�|j}tdd��}tj���|�}WdQRX||dd�||dd�||��d�|�|���|�	|�
�t�|�	|j
dd	�t�dS)
Nz
msg_02.txtrr�zppp-request@zzz.orgr�zppp@zzz.orgzmultipart/mixedT)r>)
r*r"rqrkrrr�r6r�r�r�r?r�r�)r-r.rir/r0r0r1�test_bytes_header_parser�
sz$TestParsers.test_bytes_header_parserc	Cs6tdd��"}tj���|�|�|j�WdQRXdS)Nz
msg_02.txtr)r"rqrk�BytesParserr�r��closed)r-rir0r0r1�%test_bytes_parser_does_not_close_filesz1TestParsers.test_bytes_parser_does_not_close_filec	CsLtdd��8}tjj}|�tjj|tjjd�j	|�|�
|j�WdQRXdS)Nz
msg_15.txtr)r�)r"rqrkr�r]rr�r��strictr�r�r�)r-riZbytesParserr0r0r1�2test_bytes_parser_on_exception_does_not_close_files
z>TestParsers.test_bytes_parser_on_exception_does_not_close_filec	Cs6tdd��"}tj���|�|�|j�WdQRXdS)Nz
msg_02.txtr�)r"rqrkrr�r�r�)r-rir0r0r1�test_parser_does_not_close_filesz+TestParsers.test_parser_does_not_close_filec	CsLtdd��8}tjj}|�tjj|tjjd�j	|�|�
|j�WdQRXdS)Nz
msg_15.txtr�)r�)r"rqrkrr]rr�r�r�r�r�r�)r-rirkr0r0r1�,test_parser_on_exception_does_not_close_files

z8TestParsers.test_parser_on_exception_does_not_close_filecCs>|j}t�d�}||dd�||dd�||��d�dS)Nz�From: aperson@dom.ain
To: bperson@dom.ain
Subject: the next line has a space on it
 
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam

Here's the message body
r�z!the next line has a space on it
 z
message-id�spamzHere's the message body
)r*rqr�r?)r-r.r/r0r0r1�test_whitespace_continuations	z(TestParsers.test_whitespace_continuationcCs>|j}t�d�}||dd�||dd�||��d�dS)Nz�From: aperson@dom.ain
To: bperson@dom.ain
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam
Subject: the next line has a space on it
 

Here's the message body
r�z!the next line has a space on it
 z
message-idr�zHere's the message body
)r*rqr�r?)r-r.r/r0r0r1�(test_whitespace_continuation_last_header-s	z4TestParsers.test_whitespace_continuation_last_headerc	Cs~|j}tddd��}t��|�}WdQRX|t|���d�|�d�}||��d�||��d�|�d�}||��d	�dS)
Nz
msg_26.txtr&)r�rurz
text/plainz!Simple email with attachment.

rQzapplication/riscos)r*r"rr�rr?r6)r-r.rir/�part1�part2r0r0r1�test_crlf_separation?s

z TestParsers.test_crlf_separationc	CsZtddd��}|��}WdQRXt�|�}t�}t|�}|j|dd�|�|��|�dS)Nz
msg_26.txtr&)r�z
)r�)	r"rerqr�rrrgr*rh)r-rir~r/rr�r0r0r1�test_crlf_flattenJs
zTestParsers.test_crlf_flattenNc		Cs&|j}|j}td��}t�|�}WdQRX||��d�|t|���d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d�|�d�}||��d�||��d�|t|���d�|�d�}||��d�||��d�||��d�dS)	Nz
msg_28.txtrQrurzmessage/rfc822z
text/plainz
message 1
z
message 2
)	r*rr"rqrr�rr?r6)	r-r.r�rir/r�Zpart1ar�Zpart2ar0r0r1�-test_multipart_digest_with_extra_mime_headersVs,




z9TestParsers.test_multipart_digest_with_extra_mime_headerscCs.dddg}t�t�|��}|�|dd�dS)Nz$From: Andrew Person <aperson@dom.ainz
Subject: Testz%Date: Tue, 20 Aug 2002 16:43:45 +1000ZdatezTue, 20 Aug 2002 16:43:45 +1000)rqr�r�r�r*)r-r�r/r0r0r1�test_three_linesus
zTestParsers.test_three_linescCsH|j}d}d}d||f}t�|�}||�d�|�||�d�|�dS)Nr~z	more textz'Header: %s
Next-Header: %s

Body

r	zNext-Header)r*rqr��get)r-r.Zvalue1Zvalue2rr/r0r0r1�3test_strip_line_feed_and_carriage_return_in_headers}s

z?TestParsers.test_strip_line_feed_and_carriage_return_in_headerscCsR|j}d}t�|�}|t|�d�|tdd�|D��dddg�||��d�dS)	Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyrvcss|]
}|VqdS)Nr0)rNZfieldr0r0r1r1�sz9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>z!"#QUX;~z>Fromr�r�)r*rqr�rr5r?)r-r.rr/r0r0r1�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*rqr�rr�)r-r.rr/r0r0r1�(test_rfc2822_space_not_allowed_in_header�s
z4TestParsers.test_rfc2822_space_not_allowed_in_headercCsF|j}d}t�|�}|��}|��||dddg�||��d�dS)Nz7A: first header
B: second header
CC: third header

body�A�BZCCr�)r*rqr�r��sortr?)r-r.rr/Zheadersr0r0r1�!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--
rz
)rqr�r�r?r�)r-rr/r0r0r1�test_CRLFLF_at_end_of_part�s
z&TestParsers.test_CRLFLF_at_end_of_part)rrrr�r�r�r�r�r�r�r�r�r�rYr�r�r�r�r�r�r�r0r0r0r1r��
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)Nzutf-8rBupöstal)r3r{�bodylineupöstal
T)r>)�bodytest_msgr�rprqr`r*r?)r-rr/r0r0r1�test_known_8bit_CTE�s
z)Test8BitBytesHandling.test_known_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
NZnotavalidcharsetrBupöstal)r3r{r�zutf-8up��stal
T)r>upöstal
)r�r�rprqr`r*r?)r-rr/r0r0r1�test_unknown_8bit_CTE�s
z+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d�d��dS)	Nzutf-8zquoted-printableup=C3=B6stál)r3r{r�u
p=C3=B6stál
T)r>u	pöstál
)r�r�rprqr`r*r?)r-rr/r0r0r1�test_8bit_in_quopri_body�s

z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCsP|jjdddd��d�}t�|�}|�|��d�|�|jdd�d	�d��dS)
Nrozquoted-printableup=C3=B6stál)r3r{r�zutf-8up=C3=B6st��l
T)r>u	pöstál
)r�r�rprqr`r*r?)r-rr/r0r0r1�.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)	Nzutf-8r=u
cMO2c3RhbAá=)r3r{r�T)r>upöstalr)r�r�rprqr`r*r?r�r�rr�)r-rr/r0r0r1�test_8bit_in_base64_body�s
z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd��d�}t�|�}|�|jdd�d�d��dS)Nzutf-8rxu
<,.V<W1A; á )r3r{r�T)r>u<,.V<W1A; á 
)r�r�rprqr`r*r?)r-rr/r0r0r1�test_8bit_in_uuencode_bodys
z0Test8BitBytesHandling.test_8bit_in_uuencode_body))zFrom: foo@bar.com)r�zfoo@bar.com)uTo: báz)r�z=?unknown-8bit?q?b=C3=A1z?=)uVSubject: Maintenant je vous présente mon collègue, le pouf célèbre
	Jean de Baddie)r�z�=?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=
 =?unknown-8bit?q?_Jean_de_Baddie?=)uFrom: göst)r�z=?unknown-8bit?b?Z8O2c3Q=?=r&cCsg|]\}}|�qSr0r0)rN�src�_r0r0r1rPsz Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
zutf-8cCs:t�|j�}|�t|�d��d�|�t|d�d�dS)Nr�ub��z)rqr`�headertest_msgr*r�r�)r-r/r0r0r1�test_get_8bit_headersz*Test8BitBytesHandling.test_get_8bit_headercCs8t�|j�}|�t|�t�d�jdd�|jD���dS)Nz�                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            cSsg|]\}}|d�qS)rQr0)rNr�Zexpectedr0r0r1rP.szATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	rqr`r�r*r�r�r�r��headertest_headers)r-r/r0r0r1�test_print_8bit_headers$s

z-Test8BitBytesHandling.test_print_8bit_headerscCs2t�|j�}|�dd�|��D�ddddg�dS)NcSsg|]}t|��qSr0)r�)rNr�r0r0r1rP3szGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>zfoo@bar.comub��zu]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddieu	g��st)rqr`r��assertListEqualr�)r-r/r0r0r1�test_values_with_8bit_headers1sz3Test8BitBytesHandling.test_values_with_8bit_headerscCs2t�|j�}|�dd�|��D�ddddg�dS)NcSs g|]\}}t|�t|�f�qSr0)r�)rNr�rir0r0r1rP>szFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>)r�zfoo@bar.com)r�ub��z)r�u]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie)r�u	g��st)rqr`r�r�r[)r-r/r0r0r1�test_items_with_8bit_headers<sz2Test8BitBytesHandling.test_items_with_8bit_headerscCs0t�|j�}|�dd�|�d�D�ddg�dS)NcSsg|]}t|��qSr0)r�)rNr�r0r0r1rPJszHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�zfoo@bar.comu	g��st)rqr`r�r�r,)r-r/r0r0r1�test_get_all_with_8bit_headersHsz4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsJt�t�d��d��}|�|��d�|�|��d�|�|��d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            zlatin-1utext/pl�inr~upl�in)	rqr`r�r�rpr*r6r�r�)r-r/r0r0r1�test_get_content_type_with_8bitNs
z5Test8BitBytesHandling.test_get_content_type_with_8bitcCsZt�d�d��}|�|jdd�dddg�|�|jddd�d	�|�|jd
dd�d�dS)Nu(X-Header: foo=§ne; b§r=two; baz=three
zlatin-1zx-header)r_)rzu�ne)ub�rr�)r�r�ZFoou�neub§r)rqr`rpr*r�r7)r-r/r0r0r1�test_get_params_with_8bitWsz/Test8BitBytesHandling.test_get_params_with_8bitcCs,t�t�d��d��}|�|�d�d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1�title)zus-ascii�enuThis is not f�n)rqr`r�r�rpr*r7)r-r/r0r0r1�!test_get_rfc2231_params_with_8bitas
z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8t�t�d��d��}|�dd�|�|�d�d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1r��test)rqr`r�r�rpr�r*r7)r-r/r0r0r1�!test_set_rfc2231_params_with_8bitis
z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFt�t�d��d��}|�d�|�|�d�d�|�|��d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1r�r~)	rqr`r�r�rpr�r*r7r�)r-r/r0r0r1�!test_del_rfc2231_params_with_8bitqs
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
            zlatin-1zpayload
T)r>spayload
)rqr`r�r�rpr*r?)r-r/r0r0r1�%test_get_payload_with_8bit_cte_headerzsz;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�dS)N)	rqr`�non_latin_bin_msgrrsrrgr*rh)r-r/rlr0r0r1�test_bytes_generator�sz*Test8BitBytesHandling.test_bytes_generatorcCs6tj��}t�}tj�|��|�|�|��d�dS)Nr�)	rqr�rrrsrrgr*rh)r-r/rlr0r0r1�&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	�dS)N)
rqr`r�rrsrrgr*rh� non_latin_bin_msg_as7bit_wrapped)r-r/rlr0r0r1�test_generator_handles_8bit�sz1Test8BitBytesHandling.test_generator_handles_8bitcCs`t�|j�}t�}t|��|�|��}tt���|�t�}t|��|�|�	|��|�dS)N)
rqr`r�rrrgrhrrr*)r-r/rlZ
orig_valuer0r0r1�;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)NT)r�r�rsFromrQ)rqr`r�rrsrrgrhr�r*r�)r-r/rlr�r0r0r1�#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?=rurYc	Csnd}|�t|�t|d��}|�|j�WdQRXt|d��}tj���|�}WdQRX|�	t
|�|j�dS)Nztest.msg�wbr)Z
addCleanupr �open�writer�rqrkr�r�r*r��non_latin_bin_msg_as7bit)r-rPZtestfilerr0r0r1�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?
        zlatin-1a         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�dS)N)rqr`�
latin_bin_msgr*r��latin_bin_msg_as7bit)r-rr0r0r1�: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)Nzlatin-1r&)
rqr`rrrsrrgr*rhr>)r-rrlr0r0r1�)test_decoded_generator_emits_unicode_body�s

z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCs\tj��}x2tdt|j�d�D]}|�|j||d��qW|��}|�t	|�|j
�dS)Nrr2)rqr3r%r6rrr�r�r*r�r)r-Zbfpr0rr0r0r1�test_bytes_feedparser�s

z+Test8BitBytesHandling.test_bytes_feedparserc	Cs\tdd��}|��}WdQRXt�|�}t�}tj�|�}|j|dd�|�|�	�|�dS)Nz
msg_26.txtrz
)r�)
r"rerqr`rrsrrgr*rh)r-rir~r/rr�r0r0r1r��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--

            zutf-8)r�r�rprqr`rrsrrgr*rh)r-rar/rr�r0r0r1�test_8bit_multiparts%

z)Test8BitBytesHandling.test_8bit_multipartcCsFt�}td�|d<t�}tj�|�}|j|dd�|�|��d�dS)Nužluťoučký kůňr�z
)r�s5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr	rrqrsrrgr*rh)r-rrr�r0r0r1�'test_bytes_generator_b_encoding_linesep6sz=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesepcCsFt�}td�|d<t�}tj�|�}|j|dd�|�|��d�dS)Nužluťoučký kůňr�z
)r�z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr	rrqrsrrgr*rh)r-rrr�r0r0r1�!test_generator_b_encoding_linesepBsz7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/rrrr�r�r�r�r�r�r�r�r�r�r�rpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr�rrrrYr0r0r0r1r��s^			
	
	
	




			
	.r�c@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNc	Cs@t|d��}|��}WdQRX|j�|j|�}t�|�}||fS)Nr)r"re�normalize_linesep_regex�sub�blineseprqr`)r-r�rir@r/r0r0r1r+Us

z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|�||���dS)Nr)rJ)r�r�)rrqrsrrgr�r*rh)r-r/r@r�rbr�r0r0r1r\sz,BaseTestBytesGeneratorIdempotent._idempotent)F)rrrrYr+rr0r0r0r1r	Qsr	c@seZdZdZdZe�d�ZdS)�TestBytesGeneratorIdempotentNLr&r�s\r\nN)rrrr�r�re�compiler
r0r0r0r1r
csr
c@seZdZdZdZe�d�ZdS)� TestBytesGeneratorIdempotentCRLFz
s
s	(?<!\r)\nN)rrrr�rrrr
r0r0r0r1rjsrc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TestBase64cCs�|j}|t�d�ttjddd���xntd�D]b}|dkr@d}n<|dkrNd}n.|d	kr\d
}n |dkrjd}n|dkrxd
}nd}|t�d|�|�q.WdS)N�helloshellor')�eol�rrvrYr9�rP���r�)r*r�
header_lengthr�body_encoder6)r-r.�sizeZbsizer0r0r1�test_lenrs 
zTestBase64.test_lencCs*|j}|t�d�d�|t�d�d�dS)Nr'�zaGVsbG8=shello)r*rr>)r-r.r0r0r1�test_decodeszTestBase64.test_decodecCsd|j}|t�d�d�|t�d�d�|t�d�d�|tjddd�d	�|tjddd
d�d�dS)
Nrshelloz	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==
z
)r"rz�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r*rr)r-r.r0r0r1�test_encode�szTestBase64.test_encodecCsZ|j}tj}||d�d�||d�d�||d�d�||ddd�d	�||d�d�dS)
Nrz=?iso-8859-1?b?aGVsbG8=?=zhello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=zhello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=z
iso-8859-2)r3z=?iso-8859-2?b?aGVsbG8=?=)r*rr`)r-r.�her0r0r1�test_header_encode�szTestBase64.test_header_encodeN)rrrrrr r"r0r0r0r1rqs
rc@s*eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd�dd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd�d&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,d�dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4dfdg�Z5dhdi�Z6djdk�Z7dldm�Z8dndo�Z9dpdq�Z:drds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd
S)��
TestQuoprics�ttttd�td�d�ttd�td�d�ttd�td�d�dd	�d
D����_�fdd�td
�D��_t�j�t�j�d
ks�t�tttd�td�d���_�j�	td���j�
td���fdd�td
�D��_t�j�t�j�d
ks�t�dS)Nr��zrQr��Zr@�9css|]
}|VqdS)Nr0)rNr�r0r0r1r1�sz#TestQuopri.setUp.<locals>.<genexpr>s!*+-/csg|]}|�jkr|�qSr0)�hlit)rNr�)r-r0r1rP�sz$TestQuopri.setUp.<locals>.<listcomp>�r(�~r�=csg|]}|�jkr|�qSr0)�blit)rNr�)r-r0r1rP�s)r�rr6�ordr'�hnonr�AssertionErrorr+r#�remove�bnon)r-r0)r-r1r[�szTestQuopri.setUpcCsXx(|jD]}|�t�|�dt|��qWx(|jD]}|�t�|�dt|��q2WdS)Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)r'r�rZheader_check�chrr-r�)r-r�r0r0r1�test_quopri_header_check�sz#TestQuopri.test_quopri_header_checkcCsXx(|jD]}|�t�|�dt|��qWx(|jD]}|�t�|�dt|��q2WdS)Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)r+r�rZ
body_checkr1r0r�)r-r�r0r0r1�test_quopri_body_check�sz!TestQuopri.test_quopri_body_checkcCs�|j}|t�d�d�|ttjddd��t�d�d�|t�d�d�|ttjddd��t�d�d�x.|jD]$}|t�t|g��dd	t|��qrWx<|jD]2}|t	d
�kr�q�|t�t|g��ddt|��q�W|t�d
�d�dS)NshellorIZxxx)r3r2s
h@e@l@l@o@rrQzexpected length 1 for %rr(rvzexpected length 3 for %r� )
r*rrrr`r'r�r1r-r,)r-r.r�r0r0r1�test_header_quopri_len�s$z!TestQuopri.test_header_quopri_lencCsV|j}x$|jD]}|t�t|g��d�qWx$|jD]}|t�t|g��d�q4WdS)NrQrv)r*r+rZbody_lengthr�r0)r-r.r�r0r0r1�test_body_quopri_len�s
zTestQuopri.test_body_quopri_lencCs6x0td�D]$}t|�}|�t�t�|��|�q
WdS)Nr()r6r1r*rr�Zquote)r-r�r�r0r0r1�test_quote_unquote_idempotent�sz(TestQuopri.test_quote_unquote_idempotentNcCs0|dkrt�|�}nt�||�}|�||�dS)N)rr`r*)r-r_Zexpected_encoded_headerr3�encoded_headerr0r0r1�_test_header_encode�szTestQuopri._test_header_encodecCs|�dd�dS)Nrr')r9)r-r0r0r1�test_header_encode_null�sz"TestQuopri.test_header_encode_nullcCs|�dd�dS)Nshelloz=?iso-8859-1?q?hello?=)r9)r-r0r0r1�test_header_encode_one_word�sz&TestQuopri.test_header_encode_one_wordcCs|�dd�dS)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=)r9)r-r0r0r1�test_header_encode_two_lines�sz'TestQuopri.test_header_encode_two_linescCs|�dd�dS)Nshello�therez=?iso-8859-1?q?hello=C7there?=)r9)r-r0r0r1�test_header_encode_non_asciisz'TestQuopri.test_header_encode_non_asciicCs|jdddd�dS)Nshelloz=?iso-8859-2?q?hello?=z
iso-8859-2)r3)r9)r-r0r0r1�test_header_encode_alt_charsetsz)TestQuopri.test_header_encode_alt_charsetcCst�|�}|�||�dS)N)r�
header_decoder*)r-r8Zexpected_decoded_headerZdecoded_headerr0r0r1�_test_header_decodes
zTestQuopri._test_header_decodecCs|�dd�dS)Nr')r@)r-r0r0r1�test_header_decode_nullsz"TestQuopri.test_header_decode_nullcCs|�dd�dS)Nr)r@)r-r0r0r1�test_header_decode_one_wordsz&TestQuopri.test_header_decode_one_wordcCs|�dd�dS)Nz
hello=0Aworldzhello
world)r@)r-r0r0r1�test_header_decode_two_linessz'TestQuopri.test_header_decode_two_linescCs|�dd�dS)Nz
hello=C7thereuhelloÇthere)r@)r-r0r0r1�test_header_decode_non_asciisz'TestQuopri.test_header_decode_non_asciicCs|�t�d�d�dS)Na=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)r*rr?)r-r0r0r1�test_header_decode_re_bug_18380sz*TestQuopri.test_header_decode_re_bug_18380cCs2|dkrt�|�}ntj||d�}|�||�dS)N)r)rr>r*)r-ZencodedZexpected_decodedr�decodedr0r0r1�_test_decodeszTestQuopri._test_decodecCs|�dd�dS)Nr')rG)r-r0r0r1�test_decode_null_word&sz TestQuopri.test_decode_null_wordcCs|�dd�dS)Nz
r&)rG)r-r0r0r1�test_decode_null_line_null_word)sz*TestQuopri.test_decode_null_line_null_wordcCs|�dd�dS)Nr)rG)r-r0r0r1�test_decode_one_word,szTestQuopri.test_decode_one_wordcCs|jdddd�dS)Nr�X)r)rG)r-r0r0r1�test_decode_one_word_eol/sz#TestQuopri.test_decode_one_word_eolcCs|�dd�dS)Nzhello
zhello
)rG)r-r0r0r1�test_decode_one_line2szTestQuopri.test_decode_one_linecCs|�dd�dS)Nzhello
)rG)r-r0r0r1�test_decode_one_line_lf5sz"TestQuopri.test_decode_one_line_lfcCs|�dd�dS)Nzhello
zhello
)rG)r-r0r0r1�test_decode_one_line_cr8sz"TestQuopri.test_decode_one_line_crcCs|jdddd�dS)Nzhello
�helloXrK)r)rG)r-r0r0r1�test_decode_one_line_nl;sz"TestQuopri.test_decode_one_line_nlcCs|jdddd�dS)Nzhello
rPrK)r)rG)r-r0r0r1�test_decode_one_line_crnl>sz$TestQuopri.test_decode_one_line_crnlcCs|�dd�dS)Nzhello
worldzhello
world)rG)r-r0r0r1�test_decode_one_line_one_wordAsz(TestQuopri.test_decode_one_line_one_wordcCs|jdddd�dS)Nzhello
worldZhelloXworldrK)r)rG)r-r0r0r1�!test_decode_one_line_one_word_eolDsz,TestQuopri.test_decode_one_line_one_word_eolcCs|�dd�dS)Nzhello
world
zhello
world
)rG)r-r0r0r1�test_decode_two_linesGsz TestQuopri.test_decode_two_linescCs|jdddd�dS)Nzhello
world
ZhelloXworldXrK)r)rG)r-r0r0r1�test_decode_two_lines_eolJsz$TestQuopri.test_decode_two_lines_eolcCs|�dd�dS)NA�SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam)rG)r-r0r0r1�test_decode_one_long_lineMsz$TestQuopri.test_decode_one_long_linecCs|�dd�dS)Nr(r')rG)r-r0r0r1�test_decode_one_spacePsz TestQuopri.test_decode_one_spacecCs|�dd�dS)Nz     r')rG)r-r0r0r1�test_decode_multiple_spacesSsz&TestQuopri.test_decode_multiple_spacescCs|�dd�dS)Nzhello    
zhello
)rG)r-r0r0r1�$test_decode_one_line_trailing_spacesVsz/TestQuopri.test_decode_one_line_trailing_spacescCs|�dd�dS)Nzhello    
world   
zhello
world
)rG)r-r0r0r1�%test_decode_two_lines_trailing_spacesYsz0TestQuopri.test_decode_two_lines_trailing_spacescCs|�dd�dS)Nz=22quoted=20words=22z"quoted words")rG)r-r0r0r1�test_decode_quoted_word\sz"TestQuopri.test_decode_quoted_wordcCs|�dd�dS)Nzab=CD=EFuabÍï)rG)r-r0r0r1�test_decode_uppercase_quoting_sz(TestQuopri.test_decode_uppercase_quotingcCs|�dd�dS)Nzab=cd=efuabÍï)rG)r-r0r0r1�test_decode_lowercase_quotingbsz(TestQuopri.test_decode_lowercase_quotingcCs|�dd�dS)Nzsoft line=
breakzsoft linebreak)rG)r-r0r0r1�test_decode_soft_line_breakesz&TestQuopri.test_decode_soft_line_breakcCs|�dd�dS)NzA=1,B=A ==> A+B==2)rG)r-r0r0r1�test_decode_false_quotinghsz$TestQuopri.test_decode_false_quotingcCs�i}|dkrd}n||d<|dkr(d}n||d<tj|f|�}|�||�|dksZ|dkr|x |��D]}|�t|�|�qdWdS)Nr	r"r&rz
)rrr*r�rr)r-r�Zexpected_encoded_bodyr"r�kwargsZencoded_bodyr�r0r0r1�_test_encodekszTestQuopri._test_encodecCs|�dd�dS)Nr')rb)r-r0r0r1�test_encode_nullszTestQuopri.test_encode_nullcCs|�dd�dS)Nz

)rb)r-r0r0r1�test_encode_null_lines�sz!TestQuopri.test_encode_null_linescCs|�dd�dS)Nzhello
)rb)r-r0r0r1�test_encode_one_line�szTestQuopri.test_encode_one_linecCs|�dd�dS)Nzhello
zhello
)rb)r-r0r0r1�test_encode_one_line_crlf�sz$TestQuopri.test_encode_one_line_crlfcCs|jdddd�dS)Nzhello
zhello
z
)r)rb)r-r0r0r1�test_encode_one_line_eol�sz#TestQuopri.test_encode_one_line_eolcCs |jd�d��d�ddd�dS)Nuhelloυ
zutf-8�latin1z
hello=CF=85
z
)r)rbrpr>)r-r0r0r1�(test_encode_one_line_eol_after_non_ascii�sz3TestQuopri.test_encode_one_line_eol_after_non_asciicCs|�dd�dS)Nr(z=20)rb)r-r0r0r1�test_encode_one_space�sz TestQuopri.test_encode_one_spacecCs|�dd�dS)Nz 
z=20
)rb)r-r0r0r1�test_encode_one_line_one_space�sz)TestQuopri.test_encode_one_line_one_spacecCs|�dd�dS)Nz 
 
z=20
=20
)rb)r-r0r0r1�test_encode_two_lines_one_space�sz*TestQuopri.test_encode_two_lines_one_spacecCs|�dd�dS)Nzhello   z
hello  =20)rb)r-r0r0r1�$test_encode_one_word_trailing_spaces�sz/TestQuopri.test_encode_one_word_trailing_spacescCs|�dd�dS)Nz	hello   
zhello  =20
)rb)r-r0r0r1�$test_encode_one_line_trailing_spaces�sz/TestQuopri.test_encode_one_line_trailing_spacescCs|�dd�dS)Nzhello  	z
hello  =09)rb)r-r0r0r1�!test_encode_one_word_trailing_tab�sz,TestQuopri.test_encode_one_word_trailing_tabcCs|�dd�dS)Nz	hello  	
zhello  =09
)rb)r-r0r0r1�!test_encode_one_line_trailing_tab�sz,TestQuopri.test_encode_one_line_trailing_tabcCs|jdddd�dS)Nz
abcd 
1234zabcd =

1234r9)r")rb)r-r0r0r1�,test_encode_trailing_space_before_maxlinelen�sz7TestQuopri.test_encode_trailing_space_before_maxlinelencCs|jdddd�dS)Nz
abcd 
1234zabcd=
=20
1234rI)r")rb)r-r0r0r1�(test_encode_trailing_space_at_maxlinelen�sz3TestQuopri.test_encode_trailing_space_at_maxlinelencCs|jdddd�dS)Nz
abcd 
1234zabc=
d=20
1234rY)r")rb)r-r0r0r1�,test_encode_trailing_space_beyond_maxlinelen�sz7TestQuopri.test_encode_trailing_space_beyond_maxlinelencCs|�dd�dS)Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
)rb)r-r0r0r1�test_encode_whitespace_lines�sz'TestQuopri.test_encode_whitespace_linescCs|�dd�dS)Nza = bza =3D b)rb)r-r0r0r1�test_encode_quoted_equals�sz$TestQuopri.test_encode_quoted_equalscCs|�dd�dS)NZdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx)rb)r-r0r0r1�test_encode_one_long_string�sz&TestQuopri.test_encode_one_long_stringcCs|�dd�dS)Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
)rb)r-r0r0r1�test_encode_one_long_line�sz$TestQuopri.test_encode_one_long_linecCs|�dd�dS)Nz�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
z�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
)rb)r-r0r0r1�test_encode_one_very_long_line�sz)TestQuopri.test_encode_one_very_long_linecCs|jdddd�dS)Nz=====z=3D=
=3D=
=3D=
=3D=
=3DrY)r")rb)r-r0r0r1�test_encode_shortest_maxlinelen�sz*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr'rv)r")r]r�rb)r-r0r0r1� 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'rzhello
worldzhello
worldzdxxxx 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=20z
)r"rzlxxxx 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*rr)r-r.r0r0r1r �szTestQuopri.test_encode)N)N)NN)Frrrr[r2r3r5r6r7r9r:r;r<r=r>r@rArBrCrDrErGrHrIrJrLrMrNrOrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rbrcrdrerfrgrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr r0r0r0r1r#�s�


r#c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestCharsetcCs2ddlm}y|jd=Wntk
r,YnXdS)Nr)r3�fake)rqr3ZCHARSETSr�)r-�
CharsetModuler0r0r1�tearDown�s
zTestCharset.tearDowncCsN|j}td�}||�d�d�d}|�t|j|�td�}||�|�d�dS)Nzus-asciizHello World!u¤¢¤¤¤¦¤¨¤ªzutf-8z(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r*rr`r]rg)r-r.r�rr0r0r1�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)
Nz
iso-8859-1z
hello w=F6rlduhello wörldzutf-8zaGVsbG8gd29ybGQ=
shello worldzus-asciizhello worldzeuc-jpr)r3r|)r*rrrqr3Zadd_charsetZQP)r-r.r�r}r0r0r1�test_body_encode�szTestCharset.test_body_encodecCs,td�}|�t|�d�|�tjtd�dS)Nzus-asciiuascÿii)rr*r�r]rZCharsetError)r-r3r0r0r1�test_unicode_charset_namesz%TestCharset.test_unicode_charset_nameN)rrrr~rr�r�r0r0r0r1r{�sr{c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)4�
TestHeadercCs8|j}td�}||��d�|�d�||��d�dS)NzHello World!z Goodbye World!zHello World!  Goodbye World!)rr	rpr#)r-r.rr0r0r1�test_simple#s

zTestHeader.test_simplecCs8|j}td�}||��d�|�d�||��d�dS)NzHello World!zGoodbye World!zHello World! Goodbye World!)rr	rpr#)r-r.rr0r0r1�test_simple_surprise*s

zTestHeader.test_simple_surprisecCsd}|�t|�|dfg�dS)Nzno decoding needed)r*r
)r-rr0r0r1�test_header_needs_no_decoding1sz(TestHeader.test_header_needs_no_decodingcCs<tddd�}x*|jdd��d�D]}|�t|�d�q WdS)Na�I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.r	)r"r()Z
splitcharsz
 )r	rpr�rr)r-r�lr0r0r1�	test_long5szTestHeader.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)Nz
iso-8859-1z
iso-8859-2zutf-8s�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. s;Finan�ni metropole se hroutily pod tlakem jejich d�vtipu.. u�正確に言うと翻訳はされていません。一部はドイツ語ですが、あとはでたらめです。実際には「Wenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.」と言っています。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?=rvrrQrus�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.」と言っています。)
rrr	r#rpr
rr�r>r)
r-r.r�r$r%r&r'r(r�encrFZustrZnewhr0r0r1�test_multilingual;s0
zTestHeader.test_multilingualcCst�}|�|��d�dS)Nr')r	r*rp)r-rr0r0r1�test_empty_header_encodezsz#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|�dtd��||d�dS)Nr'rzz
iso-8859-1)rr	r#r)r-r.rr0r0r1�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!)rr	rpr�)r-r.rrr0r0r1�test_explicit_maxlinelen�sz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�d�|��}||d�||ttt|����dS)Nz
iso-8859-1r)r3r"zdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 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?_?=rz�=?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_?=)rr	r#rpr�rr
)r-r.rr�rr0r0r1�test_quopri_splittable�s
2
z!TestHeader.test_quopri_splittablecCs�|j}tddd�}d}|�|�|��}||d�||ttt|����tddd�}|�|�|��}||d�||ttt|����dS)Nzkoi8-rr)r3r"zdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 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==?=rz�=?koi8-r?b?eHh4eCB4eHh4IHh4eHggeHh4?=
 =?koi8-r?b?eCB4eHh4IHh4eHggeHh4eCB4?=
 =?koi8-r?b?eHh4IHh4eHggeHh4eCB4eHh4?=
 =?koi8-r?b?IHh4eHggeHh4eCB4eHh4IHh4?=
 =?koi8-r?b?eHggeHh4eCB4eHh4IHh4eHgg?=
 =?koi8-r?b?eHh4eCB4eHh4IA==?=)rr	r#rpr�rr
)r-r.rr�rr0r0r1�test_base64_splittable�s
"
z!TestHeader.test_base64_splittablecCs8|j}d}t|�}||dg�t|�}|||���dS)Nr)rN)r*r
rrp)r-r.rr�rr0r0r1�test_us_ascii_headerszTestHeader.test_us_ascii_headercCs&|j}t�}|�dd�||d�dS)Nrz
iso-8859-1)r*r	r#)r-r.rr0r0r1�test_string_charsetszTestHeader.test_string_charsetcCs:|j}tdd�}||��d�tdd�}||��d�dS)Nupöstalzutf-8z=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=)r*r	rp)r-r.rr0r0r1�test_utf8_shortest*s


zTestHeader.test_utf8_shortestcCsr|j}|j}d}|tt|�t�}|t|j|�|�dd�}|tt|dd��|�|j|dd�|t|�|�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzutf-8r)r)r]r*rgr	r#r>r�)r-r�r.r�r�er0r0r1�test_bad_8bit_header1szTestHeader.test_bad_8bit_headercCsNd}|�dd�}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigro�surrogateescape)r3u2Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzunknown-8bit)	r>r	rqr3�UNKNOWN8BITr*r�r_r
)r-r�r�rr0r0r1�test_escaped_8bit_header=s
z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|�t|�d�|�tj�|�|dfg�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Big)r3u2Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzunknown-8bit)r	rqr3r�r*r�r_r
)r-r�rr0r0r1�&test_header_handles_binary_unknown8bitEs

z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tj�tj�|��}|�t|�d�|�tj�|�|dfg�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Big)r3u2Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzunknown-8bit)	r	rqr3r�r_rr
r*r�)r-r�rZh2r0r0r1�+test_make_header_handles_binary_unknown8bitLs
z6TestHeader.test_make_header_handles_binary_unknown8bitcCs2td�}tj�|�}|�d�|�t|�d�dS)Nr�)roZtest2)r	rqr_r
r#r*r�)r-rr�r0r0r1�0test_modify_returned_list_does_not_change_headerTs
z;TestHeader.test_modify_returned_list_does_not_change_headercCsR|j}t�}|�dd�|�d�|��}||d�tt|��}||��|�dS)Nrz
iso-8859-1Zworldz=?iso-8859-1?q?hello?= world)r*r	r#rprr
)r-r.rrr0r0r1� test_encoded_adjacent_nonencodedZs

z+TestHeader.test_encoded_adjacent_nonencodedcCs<|j}d}t|�}||dddg�t|�}||��d�dS)NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.)s	Subject: N)s������� � ��������zkoi8-r)s zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.)r*r
rrp)r-r.r�partsZhdrr0r0r1�test_whitespace_keeperdsz!TestHeader.test_whitespace_keepercCs|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r]rr^r
)r-r�rr0r0r1�test_broken_base64_headermsz$TestHeader.test_broken_base64_headercCs tddd�}|�|��d�dS)Nu文�	shift_jis)r3z=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	r*rp)r-rr0r0r1�test_shift_jis_charsetrsz!TestHeader.test_shift_jis_charsetcCst�d�}|�t|�d�dS)NzEmptyHeader:zEmptyHeader: 

)rqr�r*r�)r-r/r0r0r1�!test_flatten_header_with_no_valuevs
z,TestHeader.test_flatten_header_with_no_valuecCs"t�}d|d<|�t|�d�dS)Nz   value with leading wsZ
SomeHeaderz&SomeHeader:    value with leading ws

)rr*r�)r-r/r0r0r1�)test_encode_preserves_leading_ws_on_value}sz4TestHeader.test_encode_preserves_leading_ws_on_valuecCs|�td���d�dS)Nr()r*r	rp)r-r0r0r1�test_whitespace_header�sz!TestHeader.test_whitespace_headerN)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0r0r0r1r�"s2?E6
	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;S)<�TestRFC2231cCs8|j}|�d�}||�d�d�||jddd�d�dS)Nz
msg_29.txtr�)zus-asciir�z%This is even more ***fun*** isn't it!F)r�)zus-asciir�z'"This is even more ***fun*** isn't it!")r*r+r7)r-r.r/r0r0r1r��s

zTestRFC2231.test_get_paramcCs�|j}t�}|jdddd�||�d�d�|jddddd�||�d�d�|�d	�}|jddddd�||jd
d�d�dS)
Nr�z%This is even more ***fun*** isn't it!zus-ascii)r3)zus-asciir'z%This is even more ***fun*** isn't it!r�)r3�language)zus-asciir�z%This is even more ***fun*** isn't it!z
msg_01.txtrH)rJa"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
)rrr�r7r+rc)r-r.r/r0r0r1r��s




zTestRFC2231.test_set_paramcCsft�}|�dd�|�|dd�|jdddd�|�|dd�|jdd	dd�|�|dd
�dS)Nr�rzzcontent-typeztext/plain; title="foo"r�F)Zrequoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")rr�r*)r-r/r0r0r1�test_set_param_requote�sz"TestRFC2231.test_set_param_requotecCsX|j}|�d�}|jddddd�|jddddd�|jdd	d
�||jdd�d
�dS)Nz
msg_01.txtrzr�zus-asciir�)r3r�r�z%This is even more ***fun*** isn't it!zContent-Type)r_rH)rJa$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
)rr+r�r�rc)r-r.r/r0r0r1r��s

zTestRFC2231.test_del_paramcCs"|j}|�d�}||��d�dS)Nz
msg_32.txtzus-ascii)r*r+�get_content_charset)r-r.r/r0r0r1� test_rfc2231_get_content_charset�s
z,TestRFC2231.test_rfc2231_get_content_charsetcCs8t�d�}t�|�}|�|��d�|�||���dS)Nz�            Content-Disposition: inline;
            	filename*0*=''This%20is%20even%20more%20;
            	filename*1*=%2A%2A%2Afun%2A%2A%2A%20;
            	filename*2="is it not.pdf"

            z)This is even more ***fun*** is it not.pdf)r�r�rqr�r*rMrc)r-rr/r0r0r1�test_rfc2231_parse_rfc_quoting�s

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

            z)This is even more ***fun*** is it not.pdf)r�r�rqr�r*rMrc)r-rr/r0r0r1� test_rfc2231_parse_extra_quoting�s

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

�NAMEzMfile____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm)rqr�r7�assertNotIsInstance�tupler*)r-rr/�paramr0r0r1�#test_rfc2231_no_language_or_charsets

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

z)This is even more ***fun*** is it not.pdf)rqr�r*rM)r-rr/r0r0r1�/test_rfc2231_no_language_or_charset_in_filenames

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

z)This is even more ***fun*** is it not.pdf)rqr�r*rM)r-rr/r0r0r1�7test_rfc2231_no_language_or_charset_in_filename_encoded$s

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

z1This%20is%20even%20more%20***fun*** is it not.pdf)rqr�r*rM)r-rr/r0r0r1�test_rfc2231_partly_encoded2s

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

z?This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdf)rqr�r*rM)r-rr/r0r0r1�test_rfc2231_partly_nonencoded?s

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

z)This is even more ***fun*** is it not.pdf)rqr�r*rW)r-rr/r0r0r1�/test_rfc2231_no_language_or_charset_in_boundaryLs

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

z)this is even more ***fun*** is it not.pdf)rqr�r*r�)r-rr/r0r0r1�.test_rfc2231_no_language_or_charset_in_charsetXs

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

z)This is even more ***fun*** is it not.pdf)rqr�r*rM)r-rr/r0r0r1�%test_rfc2231_bad_encoding_in_filenamefs

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

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

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

u,This is even more ***fun*** is it not.pdf�)rqr�r*rM)r-rr/r0r0r1�&test_rfc2231_bad_character_in_filename�s

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

z
myfile.txt)rqr�r*rM)r-rr/r0r0r1�test_rfc2231_unknown_encoding�s
z)TestRFC2231.test_rfc2231_unknown_encodingcCsF|j}d}t�|�}|�d�\}}}||d�||d�||d�dS)NzJContent-Type: application/x-foo;
	name*0*="Frank's"; name*1*=" Document"

r�zFrank's Document)r*rqr�r7)r-r.rr/r3r�rr0r0r1�-test_rfc2231_single_tick_in_filename_extended�s


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

r�zFrank's Document)rqr�r7r�r�r*)r-rr/r�r0r0r1�$test_rfc2231_single_tick_in_filename�s


z0TestRFC2231.test_rfc2231_single_tick_in_filenamecCs"d}t�|�}|�|��d�dS)NzAContent-Disposition: inline;
	filename*0*="'This%20is%20broken";
z'This is broken)rqr�r*rM)r-rr/r0r0r1�test_rfc2231_missing_tick�s

z%TestRFC2231.test_rfc2231_missing_tickcCs"d}t�|�}|�|��d�dS)NzAContent-Disposition: inline;
	filename*0*="'This%20is%E2broken";
u'This is�broken)rqr�r*rM)r-rr/r0r0r1�0test_rfc2231_missing_tick_with_encoded_non_ascii�s

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

r�zus-asciizen-uszFrank's Document)r*rqr�r7)r-r.rr/r3r�rr0r0r1�!test_rfc2231_tick_attack_extended�s


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

r�zus-ascii'en-us'Frank's Document)rqr�r7r�r�r*)r-rr/r�r0r0r1�test_rfc2231_tick_attack�s


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

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

r�zus-asciizen-uszMy Document For You)r*rqr�r7)r-r.rr/r3r�rr0r0r1�,test_rfc2231_encoded_then_unencoded_segments�s


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

r�zus-asciizen-uszMy Document For You)r*rqr�r7)r-r.rr/r3r�rr0r0r1�,test_rfc2231_unencoded_then_encoded_segments�s


z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsc
Cs<ddg}x.|D]&}|j|d��t�|�}WdQRXqWdS)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�rqr�)r-�messagesrr/r0r0r1�+test_should_not_hang_on_invalid_ew_messagess
	
z7TestRFC2231.test_should_not_hang_on_invalid_ew_messagesN) rrrr�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�r0r0r0r1r��s:%
!




	


r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestSignedc	Cs.t|��}|��}t�|�}WdQRX||fS)N)r"rerqr�)r-r�ri�originalr/r0r0r1�_msg_and_obj(s
zTestSigned._msg_and_objcCsLddl}|�d|j|jB�}|�|��d�}|�|��d�}|�||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$ru)rr�Sr��search�groupr*)r-r��resultrZrepartZinpartZoutpartr0r0r1�_signed_parts_eq.s
zTestSigned._signed_parts_eqcCs&|�d�\}}|��}|�||�dS)Nz
msg_45.txt)r�rcr�)r-r�r/r�r0r0r1�test_long_headers_as_string6sz&TestSigned.test_long_headers_as_stringcCs*|�d�\}}|jdd�}|�||�dS)Nz
msg_45.txt�<)rJ)r�rcr�)r-r�r/r�r0r0r1�(test_long_headers_as_string_maxheaderlen;sz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|�d�\}}t�}t|��|�|��}|�||�dS)Nz
msg_45.txt)r�rrrgrhr�)r-r�r/rir�r0r0r1�test_long_headers_flatten@s
z$TestSigned.test_long_headers_flattenN)rrrr�r�r�r�r�r0r0r0r1r�&s
r��__main__)`rr�r=r�r��iorr�	itertoolsrZrandomrZ	threadingrZ
unittest.mockrrqZemail.policyZ
email.charsetrZemail.headerr	r
rZemail.parserrr
Zemail.generatorrrrZ
email.messagerZemail.mime.applicationrZemail.mime.audiorZemail.mime.textrZemail.mime.imagerZemail.mime.baserZemail.mime.messagerZemail.mime.multipartrZemail.mime.nonmultipartrrrrrrrZtest.supportr r!Ztest.test_emailr"r#r$r%r�r�r5r)ZTestCaserrrZrerrrur�r�r�r�r�rr&r�r�r�r�r	r
rrr#r{r�r�r�r�mainr0r0r0r1�<module>s�ICAO((\<0< g0K!5D:h!#