403Webshell
Server IP : 118.27.122.248  /  Your IP : 216.73.216.240
Web Server : Apache
System : Linux web0264.sh.tyo1 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
User : c9415830 ( 11735)
PHP Version : 8.4.17
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python36/lib64/python3.6/test/test_email/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python36/lib64/python3.6/test/test_email/__pycache__/test_email.cpython-36.pyc
3

�w2_�.�
@s�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
yddlmZWn ek
r�ddlmZYnXddlZddlZddlmZddlmZmZmZdd	lmZmZdd
lmZmZm Z ddl!m"Z"ddl#m$Z$dd
l%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddlm3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddlm7Z7ddlm8Z8ddl9m:Z:m;Z;ddl<m=Z=m>Z>ddlm?Z?m@Z@dZAdZBdZCGd d!�d!e>�ZDGd"d#�d#ejE�ZFGd$d%�d%e>�ZGGd&d'�d'ejE�ZHGd(d)�d)ejE�ZIGd*d+�d+ejE�ZJGd,d-�d-ejE�ZKGd.d/�d/ejE�ZLGd0d1�d1e>�ZMGd2d3�d3e>�ZNGd4d5�d5e>�ZOGd6d7�d7e>�ZPGd8d9�d9e>�ZQGd:d;�d;e>�ZRGd<d=�d=e>�ZSGd>d?�d?e>�ZTGd@dA�dAe>�ZUGdBdC�dCe>�ZVGdDdE�dE�ZWGdFdG�dGeWeQ�ZXGdHdI�dIeWeQ�ZYGdJdK�dKejE�ZZGdLdM�dMejE�Z[GdNdO�dOejE�Z\GdPdQ�dQe>�Z]GdRdS�dSe>�Z^GdTdU�dUe>�Z_e`dVk�r�eja�dS)W�N)�StringIO�BytesIO)�chain)�choice)�getfqdn)�Thread)�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}|jd�}||jd�dddg�||jdd�d�dS)Nz
msg_20.txtZcczccc@zzz.orgzddd@zzz.orgzeee@zzz.orgZxxzn/a)�assertEqual�_msgobj�get_all)�self�eq�msg�r0�?/opt/alt/python36/lib64/python3.6/test/test_email/test_email.py�test_get_all9s
zTestMessageAPI.test_get_allcCs|j}t�}||j�d�td�}|j|�||dd�||j�d�||dd�||jd�d�||dd	�||j�jd�|jd�||j�d�||dd�t�}d
|d<d|d
<d|d<|j|�||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�}|jd�||j�jd�||dd�dS)Nzus-asciizcontent-typeztext/plain; charset="us-ascii")r*rr5r4r8)r-r.r/r0r0r1�test_set_charset_from_stringYs

z+TestMessageAPI.test_set_charset_from_stringcCs0t�}td�}|jd|�|j|j�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�}|j||�|j|dd�|j|jdd�|�|j|j�d�dS)NsАБВzutf-8zcontent-transfer-encoding�base64T)�decodez	0JDQkdCS
)rrr;r*�get_payload)r-�datar3r/r0r0r1�+test_set_payload_with_8bit_data_and_charsetfsz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsRd}td�}d|_t�}|j|jd�|�|j|dd�|j|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_noneoszMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCsLd}td�}d|_t�}|j||�|j|dd�|j|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_nonexszMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs$t�}|jg�|j|j�g�dS)N)rr;r*r?)r-r/r0r0r1�test_set_payload_to_list�s
z'TestMessageAPI.test_set_payload_to_listcCs8t�}d|d<|jd�tt��}|jtd|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}|jd�}|j�}||dddddg�|jd�}|jd�}||dddddg�|jd�}|j�}||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}|jd�}dd�|j�D�}||ddg�|jd�}|jd�}||j�d�dS)Nz
msg_04.txtcSsg|]}|j��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}|jd�}dd�|j�D�}||ddg�dS)Nz
msg_44.txtcSsg|]}|j��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}|jd�}||j�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}|jd�}|jd�|j�d\}}||j�d�||d�|jd�}|jd�|j�d\}}||j�d�||d�|jd�}|jtj|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�}|j|j�ddd�|j�|j|j�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_boundarycCs^td��}|j�}WdQRXt�}|j|�}t�}t|dd�}|j|d�|j|j�|�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��}|j�jd�}WdQRXtjj�}|j|�}t�}tjj	|�}|j
|�|j|j�|�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}|jd�}||jdd�d�||jd�jdd�d�||jd�jdd�d�||jd�jdd�d	�||jd
�jdd�d�||jd�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�}|jd�x&dD]}||d<||jdd�d	�qW|jd
�||jdd�d�dS)
Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
�
x-uuencode�uuencode�uue�x-uuezcontent-transfer-encodingT)r>shello world�foosfoo)rxryrzr{)r*rr;r?)r-r.r/�cter0r0r1�test_get_decoded_uu_payloads


z*TestMessageAPI.test_get_decoded_uu_payloadcCst�}|jt|jd�dS)NrQ)rr]rGr?)r-r/r0r0r1�*test_get_payload_n_raises_on_non_multipartsz9TestMessageAPI.test_get_payload_n_raises_on_non_multipartc
CsV|j}|jd�}td��}|j�}WdQRXt�}t|�}|j|�||j�|�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<|jd|�|jd|�|jd|�|jd|�|jd|�|jd|�dS)	NZMe�FromZYou�to�fromZFROM�ToZTO)r�assertIn)r-r/r0r0r1�test__contains__szTestMessageAPI.test__contains__c
Cs~|jd�}td��}|j�}WdQRX|j|t|��|jdd�}|jd�}|j|djd��|j|t	j
|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|jd�}|jjdd�}|j|d�}t�}t||d�}|j|�|j||j��dS)Nz
msg_01.txtz
)�linesep)�policy)	r+r��clonercrrrgr*rh)r-r/�	newpolicyr�r�r�r0r0r1�test_as_string_policy4s

z$TestMessageAPI.test_as_string_policyc
Cs�|jd�}td��}|j�jd�}WdQRX|j|t|��|jdd�}|jd�}|j|dj	d��|j|dj
|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|jd�}|jjdd�}|j|d�}t�}t||d�}|j|�|j||j��dS)Nz
msg_01.txtz
)r�)r�)	r+r�r�r�rrrgr*rh)r-r/r�r�r�r�r0r0r1�test_as_bytes_policyGs

z#TestMessageAPI.test_as_bytes_policycCs tjd�}|j|jd�d�dS)NzContent-Type: blarg; baz; boo
�bazr')rq�message_from_stringr*r7)r-r/r0r0r1�test_bad_paramQs
zTestMessageAPI.test_bad_paramcCstjd�}|j|j�d�dS)Nz
From: foo
)rqr�r*rM)r-r/r0r0r1�test_missing_filenameUs
z$TestMessageAPI.test_missing_filenamecCstjd�}|j|j�d�dS)Nz%Content-Disposition: blarg; filename
r')rqr�r*rM)r-r/r0r0r1�test_bogus_filenameYsz"TestMessageAPI.test_bogus_filenamecCstjd�}|j|j�d�dS)Nz
From: foo
)rqr�r*rW)r-r/r0r0r1�test_missing_boundary^s
z$TestMessageAPI.test_missing_boundarycCs~|j}tjd�}||jdd�d
ddg�tjd
�}||jdd�dddg�||j�d�tjd�}||jdd�dddg�dS)Nz&X-Header: foo=one; bar=two; baz=three
zx-header)r_r|�one�bar�twor��threez X-Header: foo; bar=one; baz=two
r'z"X-Header: foo; bar="one"; baz=two
)r|r�)r�r�)r�r�)r|r')r�r�)r�r�)r|r')r�r�)r�r�)r*rqr��
get_params)r-r.r/r0r0r1�test_get_paramsbszTestMessageAPI.test_get_paramscCs$t�}d|d<|j|jd�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"zContent-Type�boundaryZCPIMSSMTPC06p5f3tG)rr*r7)r-r/r0r0r1�test_get_param_liberalssz%TestMessageAPI.test_get_param_liberalcCs�|j}tjd�}||jddd�d�||jddd�d�||jd�d�tjd�}||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
r|r'r�r�)r*rqr�r7)r-r.r/r0r0r1�test_get_paramxszTestMessageAPI.test_get_paramcCs&|jd�}|j|jd�jd�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_linescCs6tjd�}|j|jd�d�|j|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<tjd�}|j|jd�d�tjd�}|j|jd�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>tjd�}|jd|�|jd|�|jd|�|jd|�dS)NzHeader: existsr_r	ZHEADERZheaderx)rqr�r�ZassertNotIn)r-r/r0r0r1�test_field_containment�s

z%TestMessageAPI.test_field_containmentcCs�|j}t�}|jdd�||jd�d�|jdd�||jd�d�||jddd�d�||j�dddg�||jdd�dddg�|jdddd
�||jddd
�d�dS)Nr3�iso-2022-jp�
importance�
high valueF)r��"high value"�
text/plainr'�
"iso-2022-jp"ziso-9999-xxzX-Jimmy)r_)r�r')r3r�)r�r�)r�r')r3r�)r�r�)r*r�	set_paramr7r�)r-r.r/r0r0r1�test_set_param�s
zTestMessageAPI.test_set_paramcCsr|j}|jd�}||j�dd	d
g�|jd�}|jd�||j�ddg�|jd|�||j�d
dd|fg�dS)Nz
msg_05.txt�multipart/reportr'�report-type�delivery-statusr��%D1690A7AC1.996856090/mail.example.com)r�r')r�r�)r�r�)r�r')r�r�)r�r')r�r�)r*r+r�r7�	del_paramr�)r-r.r/Zold_valr0r0r1�test_del_param�s


zTestMessageAPI.test_del_paramcCs6t�}|jdddd�|jdd�|j|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�}|jdd�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�|j|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�}|jt|jd�|jd�||dd�|jdd�||dd�|jd�||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<|jdd�|j|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�}|j|j�d�dS)Nz
text/plain)rr*r6)r-r/r0r0r1�test_get_content_type_missing�sz,TestMessageAPI.test_get_content_type_missingcCs$t�}|jd�|j|j�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$|jd�}|j|jd�j�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$|jd�}|j|jd�j�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|jd�}|j|j�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|jd�}|j|j�d�dS)Nz
msg_01.txtz
text/plain)r+r*r6)r-r/r0r0r1�6test_get_content_type_from_message_text_plain_explicits
zETestMessageAPI.test_get_content_type_from_message_text_plain_explicitcCst�}|j|j�d�dS)Nr�)rr*�get_content_maintype)r-r/r0r0r1�!test_get_content_maintype_missingsz0TestMessageAPI.test_get_content_maintype_missingcCs$t�}|jd�|j|j�d�dS)Nzmessage/rfc822�message)rr�r*r�)r-r/r0r0r1�3test_get_content_maintype_missing_with_default_type
s
zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCs$|jd�}|j|jd�j�d�dS)Nz
msg_30.txtrr�)r+r*r?r�)r-r/r0r0r1�/test_get_content_maintype_from_message_implicits
z>TestMessageAPI.test_get_content_maintype_from_message_implicitcCs$|jd�}|j|jd�j�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|jd�}|j|j�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|jd�}|j|j�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�}|j|j�d�dS)N�plain)rr*�get_content_subtype)r-r/r0r0r1� test_get_content_subtype_missingsz/TestMessageAPI.test_get_content_subtype_missingcCs$t�}|jd�|j|j�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$|jd�}|j|jd�j�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$|jd�}|j|jd�j�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|jd�}|j|j�d�dS)Nz
msg_03.txtr�)r+r*r�)r-r/r0r0r1�9test_get_content_subtype_from_message_text_plain_implicit0s
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCs|jd�}|j|j�d�dS)Nz
msg_01.txtr�)r+r*r�)r-r/r0r0r1�9test_get_content_subtype_from_message_text_plain_explicit4s
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitcCs"t�}d|d<|j|j�d�dS)Nzno-slash-in-this-stringzContent-Typer�)rr*r�)r-r/r0r0r1�test_get_content_maintype_error8sz.TestMessageAPI.test_get_content_maintype_errorcCs"t�}d|d<|j|j�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�}|jdd�|jdd�|jdd�||j�dddg�||j�dddg�|jdd�||j�dddg�||j�dddg�|jdd�|jdd	�||j�ddddg�||j�d	dddg�|jt|jd
d�dS)N�First�One�Second�TwoZThirdZThreeZTwentyZElevenzOne HundredZFourthZMissing)r*rr��keys�values�replace_headerr]�KeyError)r-r.r/r0r0r1�test_replace_headerBsz"TestMessageAPI.test_replace_headercCspt�}|j|j��|jdddd�|j|j�d�|jdd�|j|j�d�|jdd�|j|j�d�dS)NzContent-Dispositionr�z
random.avi)r��inlineZInlinE)r�assertIsNoneZget_content_dispositionr�r*r�)r-r/r0r0r1�test_get_content_dispositionSsz+TestMessageAPI.test_get_content_dispositioncCsPd}t�}d|d<d|d<|j|�|j|jdd�d�|j|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<|j|�|j|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_payloadks
z*TestMessageAPI.test_broken_unicode_payloadcCs>djd�}t�}d|d<d|d<||_|j|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_payloadvs
z.TestMessageAPI.test_questionable_bytes_payloadcCs*t�}|jdddd�|jd|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�|jd|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�|jd|d�dS)	NzContent-Dispositionr��
iso-8859-1r'�Fußballer.ppt)r�z1attachment; filename*=iso-8859-1''Fu%DFballer.ppt)r�r'r�)rr�r*)r-r/r0r0r1�#test_nonascii_add_header_via_triple�sz2TestMessageAPI.test_nonascii_add_header_via_triplecCs*t�}|jdddd�|jd|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�|jd|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_tspecialcCsPxJdD]B}t�}d||d<d|d<|jd�|j|jdd	�d
d|�qWdS)
N�latin-1roztext/plain; charset=%szcontent-typezquoted-printablezcontent-transfer-encodingsfoo=e6=96=87barT)r>s	foo文barz1get_payload returns wrong result with charset %s.)rro)rr;r*r?)r-r3r/r0r0r1�test_binary_quopri_payload�s


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

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



z+TestMessageAPI.test_binary_uuencode_payloadcCs*t�}|jdddd�|jd|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�}|jdd�|jd|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<|jtj|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<|jtj|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<|jt|�tjd��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�}|jt|�tjd��dS)NuÉ testabc
z�            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: base64

            w4kgdGVzdGFiYwo=
            )rr*r�rr)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~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr
rrrrr0r0r0r1r)8s�			

	


r)c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncoderscCs\tdd��}|j�}WdQRXtjjj|�}|j�}|jd�}|jt	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�}|jd�||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-encodingr$uhello ø worldr=z
iso-8859-1)�_charsetzquoted-printable)r*r)r-r.r/r0r0r1�test_default_cte
szTestEncoders.test_default_ctecCs8|j}tddd�}||dd�||j�tjd��dS)Nu文
zeuc-jp)r&zcontent-transfer-encodingr$z�            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r*rrcrr)r-r.r/r0r0r1�test_encode7or8bits
zTestEncoders.test_encode7or8bitcCs&tddd�}|jt|�tjd��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�rr)r-r/r0r0r1�test_qp_encode_latin1(sz"TestEncoders.test_qp_encode_latin1cCs&tddd�}|jt|�tjd��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�rr)r-r/r0r0r1�test_qp_encode_non_latin12sz&TestEncoders.test_qp_encode_non_latin1N)	rrrr#r%r'r(r)r*r0r0r0r1r�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}tjd�}t�}t|�}|j|�||j�d�dS)Nz�Subject: bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text

test
)�ndiffAssertEqualrqr�rrrgrh)r-r.r/�sfpr�r0r0r1�test_split_long_continuationCs
z,TestLongHeaders.test_split_long_continuationcCsF|j}d}t|dd�}||j�d�t|jdd��}||j�d�dS)Nz�bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text�	)�continuation_wsr(z�bug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)r,r	rp�replace)r-r.�hstr�hr0r0r1�,test_another_long_almost_unsplittable_headerWsz<TestLongHeaders.test_another_long_almost_unsplittable_headercCs�|j}td�}td�}td�}d}d}d}t||dd�}|j||�|j||�t�}	||	d<t�}
t|
�}|j|	�||
j�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?=)
r,rr	�appendrrrrgrhrp)r-r.r��cz�utf8�g_head�cz_head�	utf8_headr3r/r-r0r0r1�test_long_nonstringhs&

z#TestLongHeaders.test_long_nonstringcCs$|j}tddd�}||j�d�dS)Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnit)r5zjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r,r	rp)r-r.r3r0r0r1�test_long_header_encode�s
z'TestLongHeaders.test_long_header_encodecCs&|j}tdddd�}||j�d�dS)Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitr/)r5r0zjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r,r	rp)r-r.r3r0r0r1�<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�}||j�d�dS)Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitr/)r5r0zjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r,r	rp)r-r.r3r0r0r1�-test_long_header_encode_with_tab_continuation�sz=TestLongHeaders.test_long_header_encode_with_tab_continuationcCstdd�}|j|j�d�dS)Nu文zeuc-jpz=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	r*rp)r-r3r0r0r1�0test_header_encode_with_different_output_charset�s
z@TestLongHeaders.test_header_encode_with_different_output_charsetcCs(tdjd�d�}d}|j|j�|�dS)Ns6test-ja ����Ƥ��줿�᡼��ϻʲ�Ԥξ�ǧ���ԤäƤ��ޤ�zeuc-jpz�=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r	r>r*rp)r-r3�resr0r0r1�5test_long_header_encode_with_different_output_charset�s
zETestLongHeaders.test_long_header_encode_with_different_output_charsetcCs@|j}td�}d|d<t�}t|�}|j|�||j�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"

)r,rrrrgrh)r-r.r/r-r�r0r0r1�test_header_splitter�s
z$TestLongHeaders.test_header_splittercCsd|j}t�}d|d<tjdd�td�D��|d<|jd�t�}t|�}|j|�||j	�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)
r,r�SPACEr��ranger;rrrgrh)r-r.r/r-r�r0r0r1�test_no_semis_header_splitter�s

z-TestLongHeaders.test_no_semis_header_splittercCs |j}td�}||j�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)r,r	rp)r-r.r3r0r0r1�"test_last_split_chunk_does_not_fit�sz2TestLongHeaders.test_last_split_chunk_does_not_fitcCs |j}td�}||j�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)r,r	rp)r-r.r3r0r0r1�=test_splittable_leading_char_followed_by_overlong_unsplitable�szMTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplitablecCs |j}td�}||j�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)r,r	rp)r-r.r3r0r0r1�Ftest_multiple_splittable_leading_char_followed_by_overlong_unsplitable�szVTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplitablecCs |j}td�}||j�d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;)r,r	rp)r-r.r3r0r0r1�/test_trailing_splitable_on_overlong_unsplitablesz?TestLongHeaders.test_trailing_splitable_on_overlong_unsplitablecCs |j}td�}||j�d�dS)NzW; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; zX;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; )r,r	rp)r-r.r3r0r0r1�Ftest_trailing_splitable_on_overlong_unsplitable_with_leading_splitableszVTestLongHeaders.test_trailing_splitable_on_overlong_unsplitable_with_leading_splitablecCs |j}td�}||j�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)r,r	rp)r-r.r3r0r0r1�5test_long_header_with_multiple_sequential_split_charsszETestLongHeaders.test_long_header_with_multiple_sequential_split_charscCs |j}td�}||j�d�dS)NzKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points)r,r	rp)r-r.r3r0r0r1�:test_splitter_split_on_punctuation_only_if_fws_with_header szJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headercCs |j}td�}||j�d�dS)Nz�this is a  test where we need to have more than one line before; our final line that is just too big to fit;; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;z�this is a  test where we need to have more than one line before;
 our final line that is just too big to fit;;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;)r,r	rp)r-r.r3r0r0r1�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�}||j�d�dS)NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself )r,r	rp)r-r.r3r0r0r1�/test_overlong_last_part_followed_by_split_point2sz?TestLongHeaders.test_overlong_last_part_followed_by_split_pointcCs |j}td�}||j�d�dS)Nz�this_is_a__test_where_we_need_to_have_more_than_one_line_before_our_final_line_; ; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; z�this_is_a__test_where_we_need_to_have_more_than_one_line_before_our_final_line_;
 ;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; )r,r	rp)r-r.r3r0r0r1�@test_multiline_with_overlong_parts_separated_by_two_split_points9szPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointscCs |j}td�}||j�d�dS)Nz�this is a test where we need to have more than one line before our final line; ; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; z�this is a test where we need to have more than one line before our final line;
 ;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; )r,r	rp)r-r.r3r0r0r1�>test_multiline_with_overlong_last_part_followed_by_split_pointDszNTestLongHeaders.test_multiline_with_overlong_last_part_followed_by_split_pointcCs\|j}t�}d|d<tjdgd�|d<|jd�t�}t|�}|j|�||j�d�dS)Nztest@dom.ainr�z<foo@dom.ain>  rGrHrIz�From: test@dom.ain
References: <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>
   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>
   <foo@dom.ain>   <foo@dom.ain>  

Test)	r,rrJr�r;rrrgrh)r-r.r/r-r�r0r0r1�%test_long_header_with_whitespace_runsOs

z5TestLongHeaders.test_long_header_with_whitespace_runscCs`|j}t�}d|d<tjdgd�d|d<|jd�t�}t|�}|j|�||j�d�dS)	Nztest@dom.ainr�z
<foo@dom.ain>rGz; abcrHrIz�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)	r,rrJr�r;rrrgrh)r-r.r/r-r�r0r0r1�'test_long_run_with_semi_header_splitter`s

z7TestLongHeaders.test_long_run_with_semi_header_splittercCsP|j}t�}d|d<d|d<|jd�t�}t|�}|j|�||j�d�dS)Nztest@dom.ainr�zKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsrHrIzrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r,rr;rrrgrh)r-r.r/r-r�r0r0r1�.test_splitter_split_on_punctuation_only_if_fwsqs

z>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fwscCsF|j}ddd}t|�}||j�d�tdd�}||j�d�dS)NzReferences: r��Pz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r,r	rp)r-r.r2r3r0r0r1�test_no_split_long_header�sz)TestLongHeaders.test_no_split_long_headercCs(|j}d}t|dd�}||j�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/)r0a_from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST))r,r	rp)r-r.r2r3r0r0r1�"test_splitting_multiple_long_lines�s
z2TestLongHeaders.test_splitting_multiple_long_linescCs,|j}d}t|dddd�}||j�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/)r6r5r0z�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)r,r	rp)r-r.r2r3r0r0r1�&test_splitting_first_line_only_is_long�sz6TestLongHeaders.test_splitting_first_line_only_is_longcCsf|j}t�}tdddd�}|jd�||jdd�d�||d<||jdd	�d
�||jdd	�d�dS)
NzBritische Regierung gibtz
iso-8859-1r)r5u-grünes Licht für Offshore-Windkraftprojekter)r6zl=?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offs?=
 =?iso-8859-1?q?hore-Windkraftprojekte?=)�maxheaderlenzwSubject: =?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offs?=
 =?iso-8859-1?q?hore-Windkraftprojekte?=

rzdSubject: =?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offshore-Windkraftprojekte?=

)r,rr	r7rprc)r-r.r/r3r0r0r1�test_long_8bit_header�s
z%TestLongHeaders.test_long_8bit_headercCsV|j}t�}d}||d<||jdd�d�t�}t|dd�|d<||jdd�d�dS)NuhBritische Regierung gibt grünes Licht für Offshore-Windkraftprojekte <a-very-long-address@example.com>zReply-Tor^)r`z�Reply-To: =?utf-8?q?Britische_Regierung_gibt_gr=C3=BCnes_Licht_f=C3=BCr_Offs?=
 =?utf-8?q?hore-Windkraftprojekte_=3Ca-very-long-address=40example=2Ecom=3E?=

)r5)r,rrcr	)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�r^)r`z�To: "Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,
 "Someone Test #B" <someone@umich.edu>,
 "Someone Test #C" <someone@eecs.umich.edu>,
 "Someone Test #D" <someone@eecs.umich.edu>

)r,rrc)r-r.r�r/r0r0r1�test_long_to_header�sz#TestLongHeaders.test_long_to_headercCs2|j}d}t|�}|jd�||jdd�d�dS)NzIThis is an example of string which has almost the limit of header length.zAdd another line.r)r6z\This is an example of string which has almost the limit of header length.
 Add another line.)r,r	r7rp)r-r.r�r3r0r0r1�test_long_line_after_append�s
z+TestLongHeaders.test_long_line_after_appendcCs.|j}d}t|�}|jd�||j�d�dS)NzThis is a shorter line.z!Add another sentence. (Surprise?)z9This is a shorter line. Add another sentence. (Surprise?))r,r	r7rp)r-r.r�r3r0r0r1�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)r5r)r6a=?iso-8859-1?q?Die_Mieter_treten_hier_e?=
 =?iso-8859-1?q?in_werden_mit_einem_Foerderband_komfortabel_den_Korridor_e?=
 =?iso-8859-1?q?ntlang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei=2C_ge?=
 =?iso-8859-1?q?gen_die_rotierenden_Klingen_bef=F6rdert=2E_?=)r,r	rp)r-r.�fnZgsr3r0r0r1�test_long_field_namesz$TestLongHeaders.test_long_field_namecCs:d}t�}t|dd�|d<||d<|j|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/)r0z
Received-1z
Received-2r^)r`a1Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
 Wed, 05 Mar 2003 18:10:18 -0700
Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
 Wed, 05 Mar 2003 18:10:18 -0700

)rr	r,rc)r-r3r/r0r0r1�test_long_received_headersz)TestLongHeaders.test_long_received_headercCs<d}t�}t|ddd�|d<||d<|j|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/)r5r0z
Received-2r^)r`a#Received-1: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
Received-2: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")

)rr	r,rc)r-r3r/r0r0r1�test_string_headerinst_eq!sz)TestLongHeaders.test_string_headerinst_eqcCsJ|j}t�}d}||d<t|dd�|d<d||d<||jdd�d	�dS)
Nz�iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1zFace-2)r5r(zFace-3r^)r`a�Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

)r,rr	rc)r-r.r/�tr0r0r1�-test_long_unbreakable_lines_with_continuation4sz=TestLongHeaders.test_long_unbreakable_lines_with_continuationcCs*|j}d}tj|�}||jdd�d�dS)Nz�Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700r^)r`z�Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700

)r,rqr�rc)r-r.rr/r0r0r1�"test_another_long_multiline_headerLs

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)r5r^)r`a_List: List-Unsubscribe:
 <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
List: List-Unsubscribe:
 <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>

)r,rr	rc)r-r.r3r/r0r0r1�%test_long_lines_with_different_headerYsz5TestLongHeaders.test_long_lines_with_different_headercCs6ttjd�ddd�}|j|j�dtjd�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-8rI)r3r5r&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	rrr*rp)r-r3r0r0r1�*test_long_rfc2047_header_with_embedded_fwslsz:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+rrr�maxDiffr.r4r=r>r?r@rArCrDrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr\r]r_rarbrcrdrergrhrirkrlrmrnr0r0r0r1r+?sP6	


					
r+c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestFromManglingcCs"t�|_d|jd<|jjd�dS)Nzaaa@bbb.orgr�z(From the desk of A.A.A.:
Blah blah blah
)rr/r;)r-r0r0r1�setUp}s
zTestFromMangling.setUpcCs2t�}t|dd�}|j|j�|j|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-r�r�r0r0r1�test_mangled_from�s

z"TestFromMangling.test_mangled_fromcCs2t�}t|dd�}|j|j�|j|j�d�dS)NF)rrz;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
)rrrgr/r*rh)r-r�r�r0r0r1�test_dont_mangle_from�s

z&TestFromMangling.test_dont_mangle_fromcCsTt�}t|dd�}tjtjd��}|j|�|jtdd�|j	�j
d�D��d�dS)NT)rra)            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|]}|jd�rd�qS)z>From rQ)r�)rNr�r0r0r1rP�szLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r&ru)rrrqr�rrrgr*rrhr�)r-r�r�r/r0r0r1�'test_mangle_from_in_preamble_and_epilog�s
z8TestFromMangling.test_mangle_from_in_preamble_and_epilogcCsRtjd�jd�}tj|d�}t�}t|dd�}|j|�|j|j	�|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)rrs
>From Rölli
)
rrrprq�message_from_bytesrrrgr*rh)r-�sourcer/�br�r0r0r1� test_mangled_from_with_bad_bytes�s
z1TestFromMangling.test_mangled_from_with_bad_bytesN)rrrrqrsrtruryr0r0r0r1rp|s
rpc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudioc	Cs0tdd��}|j�|_WdQRXt|j�|_dS)Nzaudiotest.aur)r"re�
_audiodatar�_au)r-rir0r0r1rq�szTestMIMEAudio.setUpcCs|j|jj�d�dS)Nzaudio/basic)r*r|r6)r-r0r0r1�test_guess_minor_type�sz#TestMIMEAudio.test_guess_minor_typecCs(|jj�}|jtjt|d��|j�dS)Nro)r|r?r*r=�decodebytesr�r{)r-�payloadr0r0r1�
test_encoding�s
zTestMIMEAudio.test_encodingcCs t|jd�}|j|j�d�dS)N�fishz
audio/fish)rr{r*r6)r-Zaur0r0r1�test_checkSetMinor�sz TestMIMEAudio.test_checkSetMinorcCs�|j}|jjdddd�||jdd�||jjdd�d
dg�||jjd	dd�d�g}||jjddd�d�|j|jjd
|dd�|�|j|jjd|�|�|j|jjd|dd�|�dS)NzContent-Dispositionr��audiotest.au)r�zcontent-dispositionz#attachment; filename="audiotest.au")r_r'r�r|)�failobjr_r�)r�r')r�r�)r*r|r�r�r7�assertIs)r-r.�missingr0r0r1�test_add_header�s 


zTestMIMEAudio.test_add_headerN)rrrrqr}r�r�r�r0r0r0r1rz�s
rzc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEImagec	Cs0tdd��}|j�|_WdQRXt|j�|_dS)NzPyBanner048.gifr)r"re�_imgdatar�_im)r-rir0r0r1rq�szTestMIMEImage.setUpcCs|j|jj�d�dS)Nz	image/gif)r*r�r6)r-r0r0r1r}�sz#TestMIMEImage.test_guess_minor_typecCs(|jj�}|jtjt|d��|j�dS)Nro)r�r?r*r=r~r�r�)r-rr0r0r1r��s
zTestMIMEImage.test_encodingcCs t|jd�}|j|j�d�dS)Nr�z
image/fish)rr�r*r6)r-Zimr0r0r1r��sz TestMIMEImage.test_checkSetMinorcCs�|j}|jjdddd�||jdd�||jjdd�d
dg�||jjd	dd�d�g}||jjddd�d�|j|jjd
|dd�|�|j|jjd|�|�|j|jjd|dd�|�dS)NzContent-Dispositionr��dingusfish.gif)r�zcontent-dispositionz%attachment; filename="dingusfish.gif")r_r'r�r|)r�r_r�)r�r')r�r�)r*r�r�r�r7r�)r-r.r�r0r0r1r��s 


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

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|tjd�}|j|j�dt|��|j|jdd�|�t�}t|�}|j|�|j	�}t
j|�}|j|j�dt|��|j|jdd�|�dS)Ns������)r�u�T)r>)rr�encode_noopr*r?rrrrgrhrqrv)r-r�r/r�r�r�r�r0r0r1�!test_binary_body_with_encode_noop2s

z5TestMIMEApplication.test_binary_body_with_encode_noopcCshd}t|tjd�}|j|jdd�|�t�}t|�}|j|�|j�}t	j
|�}|j|jdd�|�dS)Ns������)r�T)r>)rrr�r*r?rrrgrhrqrv)r-r�r/r�r�r�r�r0r0r1�0test_binary_body_with_unicode_linend_encode_noopCs

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|tjd�}|j|j�d�|j|jdd�|�|j|dd�t�}t|�}|j|�|j�}t	j
|�}|j|j�d�|j|jdd�|�|j|dd�dS)Ns������ )r�z=FA=FB=FC=FD=FE=FF=20T)r>zContent-Transfer-Encodingzquoted-printable)rrZ
encode_quoprir*r?rrrgrhrqrv)r-r�r/r�r�r�r�r0r0r1�#test_binary_body_with_encode_quopriOs

z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|tjd�}|j|j�d�|j|jdd�|�t�}t|�}|j|�|j�}t	j
|�}|j|j�d�|j|jdd�|�dS)Ns������)r�z	+vv8/f7/
T)r>)rrZ
encode_base64r*r?rrrgrhrqrv)r-r�r/r�r�r�r�r0r0r1�#test_binary_body_with_encode_base64_s

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
rrrr�r�r�r�r�r�r�r0r0r0r1r�sr�c@sVeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jd�dd��ZdS)�TestMIMETextcCstd�|_dS)Nzhello there)r�_msg)r-r0r0r1rqoszTestMIMEText.setUpcCs`|j}||jj�d�||jjd�d�g}|j|jjd|�|�|j|jjd|dd�|�dS)Nz
text/plainr3zus-asciir�)r_)r*r�r6r7r�)r-r.r�r0r0r1�
test_typesrszTestMIMEText.test_typescCs&|j|jj�d�|j|jj��dS)Nzhello there)r*r�r?�assertFalse�is_multipart)r-r0r0r1�test_payload{szTestMIMEText.test_payloadcCsz|j}tddd�}||j�jd�||dd�td�}d|_td|d�}||j�jd�||dd�||j�d�dS)Nzhello therezus-ascii)r&zcontent-typeztext/plain; charset="us-ascii"zutf-8ztext/plain; charset="utf-8")r*rr4r8rrCr?)r-r.r/r3r0r0r1�test_charsetszTestMIMEText.test_charsetcCs4|j}tddd�}||j�jd�||dd�dS)Nzhello therezus-ascii)r&zcontent-typeztext/plain; charset="us-ascii")r*rr4r8)r-r.r/r0r0r1�test_7bit_input�szTestMIMEText.test_7bit_inputcCs>|j}td�}||j�d�||dd�|jd|j��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�}||j�jd�||dd�||jdd�|jd��dS)Nuкирилицаzutf-8)r&zcontent-typeztext/plain; charset="utf-8"T)r>)r*rr4Zoutput_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}|jtt|�dS)Nuкирилица)r]�UnicodeEncodeErrorr)r-r�r0r0r1�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
rrrrqr�r�r�r�r�r��unittest�skipr�r0r0r0r1r�ns	
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��}|j�}WdQRXtdddd�}t|dd�}|jd	d
dd�td�}|j|�|j|�d
|d<d|d<d|d<d}tj|�}|ddkr�tj	}ntj
}|dkr�d}	nd}	d|	|df}
tjdtj|��|
|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 fishrg�4F�cp�ArQr�-�+z %s%04d�$z%a, %d %b %Y %H:%M:%SZDate���)r"rerrr�rrH�time�	localtimeZtimezoneZaltzone�strftimer�r��_txt)r-rir@�	containerrZintro�nowZ	timetupleZtzsecsZsignZtzoffsetr0r0r1rq�s8


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

zTestMultipart.test_hierarchycCs$d}t�j|�}|j||j��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rfr,rc)r-r�r/r0r0r1�test_empty_multipart_idempotent�s
z-TestMultipart.test_empty_multipart_idempotentcCs@tdd�}d|d<d|d<d|d<|jd	�|j|j�d
�dS)Nr�r�z	A subjectrzaperson@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--
)rrZr,rc)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	|_|jd
�|j|j�d�dS)Nr�r�z	A subjectrzaperson@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�epiloguerZr,rc)r-r�r0r0r1�0test_no_parts_in_a_multipart_with_empty_epilogues


z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguecCsV|j}tdd�}d|d<d|d<d|d<|jd	�td
�}|j|�||j�d�dS)Nr�r�z	A subjectrzaperson@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--
)r,rrZrrHrc)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
�}|j|�|jd�||j�d�dS)
Nr�r�z	A subjectrzaperson@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--
)r,rr�rrHrZrc)r-r.r�r/r0r0r1�1test_seq_parts_in_a_multipart_with_empty_preamble2s


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamblecCs\|j}tdd�}d|d<d|d<d|d<d|_td	�}|j|�|jd
�||j�d�dS)Nr�r�z	A subjectrzaperson@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--
)r,rr�rrHrZrc)r-r.r�r/r0r0r1�0test_seq_parts_in_a_multipart_with_none_preambleNs


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblecCs\|j}tdd�}d|d<d|d<d|d<d|_td	�}|j|�|jd
�||j�d�dS)Nr�r�z	A subjectrzaperson@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--
)r,rr�rrHrZrc)r-r.r�r/r0r0r1�0test_seq_parts_in_a_multipart_with_none_epilogueis


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguecCs\|j}tdd�}d|d<d|d<d|d<d	|_td
�}|j|�|jd�||j�d�dS)
Nr�r�z	A subjectrzaperson@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--
)r,rr�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
�}|j|�|jd�||j�d�dS)
Nr�r�z	A subjectrzaperson@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--

)r,rr�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}|jd�}|t|j��d�|jd�}||j�d�|t|j��d�xH|j�D]<}||j�d�|t|j��d�|jd�}||j�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"|jd�}|jt|j��d�dS)Nz
msg_37.txtrv)r+r*rr?)r-r/r0r0r1�test_double_boundary�s
z"TestMultipart.test_double_boundarycCs4|j}|jd�}t�}tj||�||j�d�dS)Nz
msg_38.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
            text/plain
        text/plain
    text/plain
    text/plain
)r,r+rr�
_structurerh)r-r.r/r-r0r0r1�)test_nested_inner_contains_outer_boundary�s
z7TestMultipart.test_nested_inner_contains_outer_boundarycCs4|j}|jd�}t�}tj||�||j�d�dS)Nz
msg_39.txtz�multipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
)r,r+rrr�rh)r-r.r/r-r0r0r1�test_nested_with_same_boundary�s
z,TestMultipart.test_nested_with_same_boundarycCs|jd�}|j|j�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}tjd�}|j|j��||j�d�|t|j��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�jd�}|j|jd�j�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�}|j|jtjj�dS)Nr�r�)rr�r�rq�compat32)r-rr0r0r1�test_mimebase_default_policy"s
z*TestMultipart.test_mimebase_default_policycCs(tddtjjd�}|j|jtjj�dS)Nr�r�)r�)rrqr��defaultr�)r-rr0r0r1�test_mimebase_custom_policy&sz)TestMultipart.test_mimebase_custom_policyN)rrrrqr�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�Zejd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�TestNonConformantcCs>|j}|jd�}||j�d�||j�d�||j�d�dS)Nz
msg_14.txtz
text/plainr�r�)r*r+r6r�r�)r-r.r/r0r0r1�test_parse_missing_minor_type-s

z/TestNonConformant.test_parse_missing_minor_typecCsN|jd�}|jd�}|jt|d��|jt|j�d�|j|jdtj	�dS)Nz
msg_15.txtrr�rQ)
r+r?r��hasattrr*rr�r�r�StartBoundaryNotFoundDefect)r-r/�innerr0r0r1�test_same_boundary_inner_outer5s

z0TestNonConformant.test_same_boundary_inner_outercCsX|jd�}|j|j�t�|jt|j�d�|j|jdtj�|j|jdtj	�dS)Nz
msg_25.txtrurrQ)
r+r�r?r�r*rr�r�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefect)r-r/r0r0r1�test_multipart_no_boundary?s
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|jjd��}|jt|j�d�|j|jdtj�dS)Nz"
Content-Transfer-Encoding: base64rQr)	�_str_msg�
multipart_msgr	r*rr�r�rZ-InvalidMultipartContentTransferEncodingDefect)r-r/r0r0r1�test_multipart_invalid_cte`s
z,TestNonConformant.test_multipart_invalid_ctecCs(|j|jjd��}|jt|j�d�dS)Nr'r)r�r�r	r*rr�)r-r/r0r0r1�test_multipart_no_cte_no_defecthsz1TestNonConformant.test_multipart_no_cte_no_defectcCs<x6dD].}|j|jjdj|���}|jt|j�d�qWdS)Nr$rB�BINaryz
Content-Transfer-Encoding: {}r)r$rBr�)r�r�r	r*rr�)r-r}r/r0r0r1�"test_multipart_valid_cte_no_defectms

z4TestNonConformant.test_multipart_valid_cte_no_defectcCs�|j}|j}t�}d|d<||j�d�||j�d�||j�d�|d=d|d<||j�d�||j�d�||j�d�t�}t|�}|j|�||j	�d�dS)Nr�zContent-Typer�z
text/plainzcontent-typer|zContent-Type: foo

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

message 1

--BOUNDARY
Content-Type: text/plain

message 2

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

counter to RFC 2822, there's no separating newline here
)r,r+rc)r-r.r/r0r0r1�test_no_separating_blank_line�s
z/TestNonConformant.test_no_separating_blank_linecCsX|jd�}|jt|d��|jt|j�d�|j|jdtj�|j|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|jd�}|jd�jd�}|jt|j�d�|j|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}tj|�}||j�dg�||j�d�|t|j�d�|j|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|jd�}|j|j�dg�|j|j�d�|j|jtjg�dS)Nz&Subject: test
not a header
To: abc

b
rznot 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�rrr�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)"�TestRFC2047cCsR|j}d}t|�}||d
ddd
g�t|�}|t|�d�|j|jdd�d	�dS)NzVRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=�Re: �
r�ksm�rg�s�mac-iceland�
 baz foo bar u+Re: räksmörgås baz foo bar räksmörgåsr)r6ziRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?=
 =?mac-iceland?q?=9Arg=8Cs?=)r�N)r�r�)r�N)r�r�)r*r
rr�r,rp)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>�Andr�
iso-8859-1� Pirard <pirard@dom.ain>uAndré Pirard <pirard@dom.ain>)r�r�)r�N)r*r
r�r)r-r.r�r�r_r0r0r1�test_whitespace_keeper_unicode�sz*TestRFC2047.test_whitespace_keeper_unicodecCs>|j}d}t|�}||dd	d
dg�tt|��}||d�dS)NzWThe =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?=�The �quick brown fox�
iso-8859-1� jumped over the �lazy dogz,The quick brown fox jumped over the lazy dog)r�N)r�r�)r�N)r�r�)r*r
r�r)r-r.r�r�Zhur0r0r1� test_whitespace_keeper_unicode_2�s
z,TestRFC2047.test_whitespace_keeper_unicode_2cCs&d}t|�}|j|dd	d
ddg�dS)
Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord�Sm���
iso-8859-1�rg���sbord)rN)rr)rN)rr)rN)r
r*)r-r�r�r0r0r1�test_rfc2047_missing_whitespace�s

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

z(TestRFC2047.test_rfc2047_with_whitespacecCsFd}d
ddd
dg}x.|D]&\}}t||�}|j||d	fg�qWdS)Nz=?iso-8859-1?B?%s?=�dm==�v�dm=�dm�dmk=�vi�dmkz
iso-8859-1)rr
)rr
)rr
)rr)rr)r
r*)r-r�r@�q�ar�r0r0r1�test_rfc2047_B_bad_padding	sz&TestRFC2047.test_rfc2047_B_bad_paddingcCsd}|jt|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=�andr�=zz�
iso-8859-1)rr)r*r
)r-r�r0r0r1�test_rfc2047_Q_invalid_digits	s
z)TestRFC2047.test_rfc2047_Q_invalid_digitscCsd}|jt|�dddg�dS)	Nz(=?ISO-8859-1?Q?a?=)�(�a�
iso-8859-1�))rN)rr)rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_1	s
z"TestRFC2047.test_rfc2047_rfc2047_1cCsd}|jt|�dddg�dS)	Nz(=?ISO-8859-1?Q?a?= b)rr�
iso-8859-1� b))rN)rr)rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_2"	s
z"TestRFC2047.test_rfc2047_rfc2047_2cCsd}|jt|�dddg�dS)	Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)r�ab�
iso-8859-1r)rN)r!r")rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_3(	s
z"TestRFC2047.test_rfc2047_rfc2047_3cCsd}|jt|�dddg�dS)	Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r�ab�
iso-8859-1r)rN)r$r%)rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_4.	s
z"TestRFC2047.test_rfc2047_rfc2047_4cCsd}|jt|�dddg�dS)	Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�ab�
iso-8859-1r)rN)r'r()rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_5a4	s
z#TestRFC2047.test_rfc2047_rfc2047_5acCsd}|jt|�dddg�dS)	Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r�ab�
iso-8859-1r)rN)r*r+)rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_5b:	s
z#TestRFC2047.test_rfc2047_rfc2047_5bcCsd}|jt|�dddg�dS)	Nz(=?ISO-8859-1?Q?a_b?=)r�a b�
iso-8859-1r)rN)r-r.)rN)r*r
)r-r�r0r0r1�test_rfc2047_rfc2047_6@	s
z"TestRFC2047.test_rfc2047_rfc2047_6cCsTd}|jt|�d	d
ddg�|jtt|��j�|j��|jttt|���d�dS)
Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=)rr�
iso-8859-1� b�
iso-8859-2rz(a b))rN)rr0)r1r2)rN)r*r
rrpr\r�)r-r�r0r0r1�test_rfc2047_rfc2047_7F	s
z"TestRFC2047.test_rfc2047_rfc2047_7cCsVd}|jt|�ddg�|jtt|��j�dj|j���|jttt|���d�dS)	Nz9=?windows-1252?q?=22M=FCller_T=22?=
 <T.Mueller@xxx.com>�
"M�ller T"�windows-1252�<T.Mueller@xxx.com>r'u"Müller T" <T.Mueller@xxx.com>)r4r5)r6N)r*r
rrpr��
splitlinesr�)r-r�r0r0r1�test_multiline_headerO	s
z!TestRFC2047.test_multiline_headerN)rrrr�r�r�rrrrrr r#r&r)r,r/r3r8r0r0r0r1r��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��}|j�|_WdQRXdS)Nz
msg_11.txt)r"reZ_text)r-rir0r0r1rq\	s
zTestMIMEMessage.setUpcCs|jttd�dS)Nza plain string)r]rGr)r-r0r0r1�test_type_error`	szTestMIMEMessage.test_type_errorcCsv|j}d}t�}||d<t|�}||j�d�|j�}|j|t�|t|�d�|d}|j||�||d|�dS)Nz
A sub-messagerzmessage/rfc822rQr�subject)	r*rrr6r?r��listrr�)r-r.r;r�rrrSr0r0r1�test_valid_argumentc	sz#TestMIMEMessage.test_valid_argumentcCs:t�}d|d<t�}d|d<t|�}|jtj|j|�dS)Nz	subpart 1rz	subpart 2)rrr]rZMultipartConversionErrorrH)r-r�r�r=r0r0r1�test_bad_multipartq	sz"TestMIMEMessage.test_bad_multipartcCsTt�}d|d<|jd�t|�}d|d<t�}t|�}|j|�|j|j�d�dS)NzAn enclosed messagerz!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=r�r�r0r0r1�
test_generatey	s


zTestMIMEMessage.test_generatecCst|j}|jd�}||j�d�|j�}|j|t�|t|�d�|d}|j|t�||dd�||j�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/rZsubmsgr0r0r1�test_parse_message_rfc822�	s
z)TestMIMEMessage.test_parse_message_rfc822cCs�|j}|jd�}||j�d�|j|j��|t|j��d�|jd�}||j�d�||j�d�|jd�}||j�d�|t|j��d	�|jd�}|j|t�||d
d�||j	dd
d�d�||j	dd
d�d�|jd�}|j|t�||dd�||j
dd�ddg�||j	ddd�d�|jd	�}||j�d�|j�}|j|t�|t|�d�|d}|j|t�||j�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-recipientr��jangel1@cougar.noc.ucla.eduzfinal-recipientzmessage/rfc822z
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r�r')rCr')r*r+r6r�r�rr?r�rr7r�r<)r-r.r/rSZdsn1Zdsn2rr�r0r0r1�test_dsn�	sB






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



zTestMIMEMessage.test_epiloguecCsv|j}t�}d|d<d|d<d|d<d|_d|_td	�}td
�}|jddd
d�|j|�|j|�||j�d�dS)Nzaperson@dom.ainr�zbperson@dom.ainr�rIrz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--
)r,rr�r�rr�rHrc)r-r.r/r�r�r0r0r1�test_no_nl_preamble�	s

z#TestMIMEMessage.test_no_nl_preamblec
Cs�|j}td��}tj|�}WdQRX|jd�}||j�d�||j�d�|jd�}||j�d�||j�d�|jd�}||j�d�||j�d�|jd�}||j�d�||j�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��}tj|�}WdQRX|jd�}||j�d�||j�d�|jd�}||j�d�||j�d�|jd�}||j�d�||j�d�|jd�}||j�d�||j�d�dS)Nz
msg_28.txtrzmessage/rfc822rQz
text/plain)r*r"rqrGr?rHr6)r-r.rir/rIrJrKrLr0r0r1�.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|�}|j|�|j|�||j�d�||j�d�||j�d�||j�d�||j	d�d�|d	=|d
=|d	=|d
=||j�d�||j�d�||j�d�||j�d�||j	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*r,rr�rrrHr6rHrc)r-r.r�r�Z	subpart1aZ	subpart2aZsubpart1Zsubpart2r0r0r1�test_default_type_non_parsed+
s4




z,TestMIMEMessage.test_default_type_non_parsedcCsZ|j}td�}td�}t||fd�}|t|j��d�||jd�|�||jd�|�dS)Nr')Z	_subpartsrurrQ)r*rrrr?)r-r.Ztext1Ztext2r/r0r0r1�$test_mime_attachments_in_constructoru
sz4TestMIMEMessage.test_mime_attachments_in_constructorcCst�}|j|j��dS)N)rr�r�)r-r/r0r0r1�"test_default_multipart_constructor~
sz2TestMIMEMessage.test_default_multipart_constructorcCs0t�}d|d<d|d<|j|jd�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<|jt��}d|d<WdQRX|jt|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)rrrrqr:r>r?r@rArDrErFrMrNrOrPrQrRrTr0r0r0r1r9[	s 9#J	r9c@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|��}|j�}WdQRXtj|�}||fS)N)r"rerqr�)r-r�rir@r/r0r0r1r+�
s

zTestIdempotent._msgobjFcCs8|j}t�}t|dd�}|j||d�|||j��dS)Nr)r`)r�)r,rrrgrh)r-r/r�r�r.r�r�r0r0r1�_idempotent�
s
zTestIdempotent._idempotentcCs�|j}|jd�\}}||j�d�||j�d�||j�d�||j�dd�||jd�d�||jd�||jd�|j	||�dS)	Nz
msg_01.txtz
text/plainr�r�rQr3�us-ascii)r3rW)
r*r+r6r�r�r�r7r�r�rV)r-r.r/r�r0r0r1�test_parse_text_message�
sz&TestIdempotent.test_parse_text_messagecCsP|j}|jd�\}}||j�d�||j�d�||jd�d�|j||�dS)Nz
msg_03.txtz
text/plainr3)r*r+r6r�r7rV)r-r.r/r�r0r0r1�test_parse_untyped_message�
sz)TestIdempotent.test_parse_untyped_messagecCs|jd�\}}|j||�dS)Nz
msg_04.txt)r+rV)r-r/r�r0r0r1�test_simple_multipart�
sz$TestIdempotent.test_simple_multipartcCs|jd�\}}|j||�dS)Nz
msg_02.txt)r+rV)r-r/r�r0r0r1�test_MIME_digest�
szTestIdempotent.test_MIME_digestcCs|jd�\}}|j||�dS)Nz
msg_27.txt)r+rV)r-r/r�r0r0r1�test_long_header�
szTestIdempotent.test_long_headercCs|jd�\}}|j||�dS)Nz
msg_28.txt)r+rV)r-r/r�r0r0r1�"test_MIME_digest_with_part_headers�
sz1TestIdempotent.test_MIME_digest_with_part_headerscCs|jd�\}}|j||�dS)Nz
msg_06.txt)r+rV)r-r/r�r0r0r1�test_mixed_with_image�
sz$TestIdempotent.test_mixed_with_imagecCs|jd�\}}|j||�dS)Nz
msg_05.txt)r+rV)r-r/r�r0r0r1�test_multipart_report�
sz$TestIdempotent.test_multipart_reportcCs|jd�\}}|j||�dS)Nz
msg_16.txt)r+rV)r-r/r�r0r0r1rD�
szTestIdempotent.test_dsncCs|jd�\}}|j||�dS)Nz
msg_21.txt)r+rV)r-r/r�r0r0r1�test_preamble_epilogue�
sz%TestIdempotent.test_preamble_epiloguecCs|jd�\}}|j||�dS)Nz
msg_23.txt)r+rV)r-r/r�r0r0r1�test_multipart_one_part�
sz&TestIdempotent.test_multipart_one_partcCs|jd�\}}|j||�dS)Nz
msg_24.txt)r+rV)r-r/r�r0r0r1�test_multipart_no_parts�
sz&TestIdempotent.test_multipart_no_partscCs|jd�\}}|j||�dS)Nz
msg_31.txt)r+rV)r-r/r�r0r0r1r��
sz%TestIdempotent.test_no_start_boundarycCs|jd�\}}|j||�dS)Nz
msg_32.txt)r+rV)r-r/r�r0r0r1�test_rfc2231_charset�
sz#TestIdempotent.test_rfc2231_charsetcCs|jd�\}}|j||�dS)Nz
msg_33.txt)r+rV)r-r/r�r0r0r1�test_more_rfc2231_parameters�
sz+TestIdempotent.test_more_rfc2231_parameterscCs|jd�\}}|j||�dS)Nz
msg_34.txt)r+rV)r-r/r�r0r0r1�%test_text_plain_in_a_multipart_digest�
sz4TestIdempotent.test_text_plain_in_a_multipart_digestcCs|jd�\}}|j||�dS)Nzmsg_12a.txt)r+rV)r-r/r�r0r0r1�test_nested_multipart_mixeds�
sz+TestIdempotent.test_nested_multipart_mixedscCs|jd�\}}|j||�dS)Nz
msg_36.txt)r+rV)r-r/r�r0r0r1�%test_message_external_body_idempotent�
sz4TestIdempotent.test_message_external_body_idempotentcCs"|jd�\}}|j||dd�dS)Nz
msg_43.txtT)r�)r+rV)r-r/r�r0r0r1�test_message_delivery_status�
sz+TestIdempotent.test_message_delivery_statuscCs|jd�\}}|j||�dS)Nz
msg_45.txt)r+rV)r-r/r�r0r0r1�test_message_signed_idempotent�
sz-TestIdempotent.test_message_signed_idempotentcCs\|j}|jd�\}}||j�d�i}x|j�D]\}}|||<q0W||dd�||dd�||jd|j�||j|j�|t|j��d�|jd	�}||j�d
�||j�d|j�|jd�}||j�d
�||j�d|j�|jd
�}	||	j�d�|j	|	t
�|	j�}
|j	|
t�|t|
�d�|
d	}|j	|t
�||j�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�ZparamsZpkZpvr�r�Zmsg3rZmsg4r0r0r1�test_content_types4


z TestIdempotent.test_content_typecCs�|j}|jd�\}}||j�d�|j�}|j|t�|t|�d�|d}|j|t�||j�d�|j|j�t�||j�|j	�dS)Nz
msg_06.txtzmessage/rfc822rQrz
text/plain)
r*r+r6r?r�r<rrr�r�)r-r.r/r�rr�r0r0r1�test_parser!szTestIdempotent.test_parserN)F)rrrr�r+rVrXrYrZr[r\r]r^r_rDr`rarbr�rcrdrerfrgrhrirjrkr0r0r0r1rU�
s2
rUc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!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�TestMiscellaneouscCsVtd��}|j�}WdQRXtj|�}t�}t|dd�}|j|�|j||j��dS)Nz
msg_01.txtr)r`)	r"rerqr�rrrgr*rh)r-rir�r/r�r�r0r0r1�test_message_from_string5s


z*TestMiscellaneous.test_message_from_stringcCs`td��N}|j�}|jd�tj|�}t�}t|dd�}|j|�|j||j	��WdQRXdS)Nz
msg_01.txtr)r`)
r"re�seekrqrGrrrgr*rh)r-rir�r/r�r�r0r0r1�test_message_from_file@s



z(TestMiscellaneous.test_message_from_filecCs�td��}|j�}WdQRXGdd�dt�}tj||�}|j||�td��}|j�}WdQRXtj||�}x|j�D]}|j||�qvWdS)Nz
msg_01.txtc@seZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN)rrrr0r0r0r1�	MyMessageQsrpz
msg_02.txt)r"rerrqr�r��walk)r-rir�rpr/rSr0r0r1�#test_message_from_string_with_classLs

z5TestMiscellaneous.test_message_from_string_with_classcCs~Gdd�dt�}td��}tj||�}WdQRX|j||�td��}tj||�}WdQRXx|j�D]}|j||�qfWdS)Nc@seZdZdS)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageN)rrrr0r0r0r1rp_srpz
msg_01.txtz
msg_02.txt)rr"rqrGr�rq)r-rprir/rSr0r0r1�!test_message_from_file_with_class]s

z3TestMiscellaneous.test_message_from_file_with_classcCs,Gdd�dt�}|jd|�}|j||�dS)NcseZdZ�fdd�Z�ZS)zSTestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessagecst�j�dS)N)�super�__init__)r-)�	__class__r0r1rumsz\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)rrrru�
__classcell__r0r0)rvr1rplsrpzSubject: test

test)rr�r�)r-rpr/r0r0r1�.test_custom_message_does_not_require_argumentsksz@TestMiscellaneous.test_custom_message_does_not_require_argumentscCs@td�}|jt|j�dddddddd	d
ddd
dddddg�dS)Nrqrr3rr�
feedparserrsr_rr�Zmessage_from_binary_filervrGr�rrkrr)�
__import__r*�sorted�__all__)r-�moduler0r0r1�test__all__rs
zTestMiscellaneous.test__all__cCs:tj�}|jtjtj|��dd�tj|�dd��dS)N�)r�r*r�	parsedate�
formatdate�gmtime)r-r�r0r0r1�test_formatdate|sz!TestMiscellaneous.test_formatdatecCs>tj�}|jtjtj|dd��dd�tj|�dd��dS)NT)r�r)r�r*rr�r�r�)r-r�r0r0r1�test_formatdate_localtime�sz+TestMiscellaneous.test_formatdate_localtimecCsVtj�}|jtj|dd�tjdtj|���|jtj|ddd�tjdtj|���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�|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��dS)Nr'�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|jtjd�tjd��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_compactcCs|j}|tjd�d
�dS)Nz25 Feb 2003 13:47:26 -0800��ru��
�/�rrQi�pr�透��)
r�rur�r�r�r�rrQr�r�)r*rr�)r-r.r0r0r1�test_parsedate_no_dayofweek�s
z-TestMiscellaneous.test_parsedate_no_dayofweekcCs|j}|tjd�d
�dS)Nz5 Feb 2003 13:47:26 -0800��ru�r�r�r�rrQi�pr�透��)
r�rur�r�r�r�rrQr�r�)r*rr�)r-r.r0r0r1�#test_parsedate_compact_no_dayofweek�s
z5TestMiscellaneous.test_parsedate_compact_no_dayofweekcCs|jtjd�d�dS)
NzWed, 3 Apr 2002 14:58:26+0800��rYrv��:r�rrQ�pr�)
r�rYrvr�r�r�rrQr�r�)r*rr�)r-r0r0r1�.test_parsedate_no_space_before_positive_offset�sz@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCs|jtjd�d
�dS)NzWed, 3 Apr 2002 14:58:26-0800��rYrvr�r�r�rrQi�pr�透��)
r�rYrvr�r�r�rrQr�r�)r*rr�)r-r0r0r1�.test_parsedate_no_space_before_negative_offset�sz@TestMiscellaneous.test_parsedate_no_space_before_negative_offsetcCs*|j}|tjd�d�|tjd�d�dS)Nz5 Feb 2003 13.47.26 -0800��rur�r�r�r�rrQi�pz5 Feb 2003 13.47 -0800r�透��)
r�rur�r�r�r�rrQr�r�r�透��)
r�rur�r�r�rrrQr�r�)r*rr�)r-r.r0r0r1�%test_parsedate_accepts_time_with_dots�s


z7TestMiscellaneous.test_parsedate_accepts_time_with_dotscCs�|j}tjd�}ttj|��}|tj|�dd�|dd��|ttjd|��d�tjd�}ttj|dd���}|tj|�dd�|dd��|ttjd|dd���d�dS)Nz5 Feb 2003 13:47:26 -0800rz%Yi��	)	r*rr��intr�Zmktimer�r�r�)r-r.Ztimetuprjr0r0r1�+test_parsedate_acceptable_to_time_functions�s
 
 z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCs(|jtjd�d�|jtjd�d
�dS)N�rQr��r�r�r�)
r�rQrQrrrr�r�r�rr�r�r�)
r�rQrQrrrr�r�r�r�i.���)r*rZ	mktime_tz)r-r0r0r1�test_mktime_tz�s
z TestMiscellaneous.test_mktime_tzcCs4|jtjd�tjd��|jtjd�tjd��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*rr�)r-r0r0r1�test_parsedate_y2k�sz$TestMiscellaneous.test_parsedate_y2kcCs.|jtjd�d�|jtjtjd��d�dS)Nz<>r')r'r')r*r�	parseaddr�
formataddr)r-r0r0r1�test_parseaddr_empty�sz&TestMiscellaneous.test_parseaddr_emptycCs:|jtjd�d�|jtjd�d�|jtjd�d�dS)Nza@b@cr'za@b.c@cza@172.17.0.1@c)r'r')r'r')r'r')r*rr�)r-r0r0r1�test_parseaddr_multiple_domains�sz1TestMiscellaneous.test_parseaddr_multiple_domainscCs|jtjd�d�dS)N�A Silly Person�person@dom.ainzA Silly Person <person@dom.ain>)r�r�)r*rr�)r-r0r0r1�test_noquote_dump�sz#TestMiscellaneous.test_noquote_dumpcCsP|jtjd�d�|jtjd�d�d}d}|jtjtj||f��||f�dS)N�A (Very) Silly Person�person@dom.ainz("A (Very) Silly Person" <person@dom.ain>z*"A \(Very\) Silly Person" <person@dom.ain>zA \(Special\) Person)r�r�)r�r�)r*rr�r�)r-rrxr0r0r1�test_escape_dump�sz"TestMiscellaneous.test_escape_dumpcCs>|jtjd�d�d}d}|jtjtj||f��||f�dS)N�Arthur \Backslash\ Foobar�person@dom.ainz."Arthur \\Backslash\\ Foobar" <person@dom.ain>)r�r�)r*rr�r�)r-rrxr0r0r1�test_escape_backslashes�sz)TestMiscellaneous.test_escape_backslashescCsBd}d}d}d}|jtj||f�|�|jtj||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*rr�)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}|jtj||f|�|�|jtj||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sr�z%s <%s>zutf-8)r*rr�r)r-r�r�r�r�ZmockZ
mock_expectedr0)r�r1�$test_accepts_any_charset_like_objectsz6TestMiscellaneous.test_accepts_any_charset_like_objectcCs(d}d}t�}|jttj||f|�dS)NuHäns Würstzperson@dom.ain)�objectr]�AttributeErrorrr�)r-r�r�Zbad_charsetr0r0r1�-test_invalid_charset_like_object_raises_errors
z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCs0d}|jttjd|f�|jttjd|f�dS)Nupersön@dom.in�Name)r]�UnicodeErrorrr�)r-r�r0r0r1�!test_unicode_address_raises_error&sz3TestMiscellaneous.test_unicode_address_raises_errorcCsVd}d}d\}}|jtj|�||f�|jtj|�||f�|jtj||f�|�dS)NzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>�John X. Doe�jxd@example.com)r�r�)r*rr�r�)r-r��yrrxr0r0r1�test_name_with_dot,sz$TestMiscellaneous.test_name_with_dotcCs:|j}|tjd�d�|tjd�d�|tjd�d�dS)N�""example" example"@example.comr'�!"\"example\" example"@example.com�#"\\"example\\" example"@example.com)r'r�)r'r�)r'r�)r*rr�)r-r.r0r0r1�2test_parseaddr_preserves_quoted_pairs_in_addresses5s



zDTestMiscellaneous.test_parseaddr_preserves_quoted_pairs_in_addressescCs^|jdtjd��|jd	tjd��|jd
tjd��|jdtjd��|jdtjd��dS)
Nr'�merwok wok@xample.com�merwok  wok@xample.comz merwok  wok  @xample.com�merwok"wok"  wok@xample.com�merwok.wok.wok@xample.comzmerwok. wok .  wok@xample.com)r'r�)r'r�)r'r�)r'r�)r'r�)r*rr�)r-r0r0r1�-test_parseaddr_preserves_spaces_in_local_partGsz?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_partcCs0d}d}|jtj|�|�|jtj|�|�dS)N�#'foo@example.com' (foo@example.com)�foo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>)r�r�)r*rr�r�)r-r�Zaddrstrr0r0r1�6test_formataddr_does_not_quote_parens_in_quoted_stringYs
zHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_stringcCsd}|jtj|�d�dS)NzFoo
	Bar <foo@example.com>�Foo Bar�foo@example.com)r�r�)r*rr�)r-r�r0r0r1�test_multiline_from_commentbsz-TestMiscellaneous.test_multiline_from_commentcCs|jtjd�d�dS)N�A Silly; Person�person@dom.ainz""A Silly; Person" <person@dom.ain>)r�r�)r*rr�)r-r0r0r1�test_quote_dumph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_richcomparisonsms$












z.TestMiscellaneous.test_charset_richcomparisonscCs"|j}|tjddg�ddg�dS)	Nzaperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>�	Al Person�aperson@dom.ain�
Bud Person�bperson@dom.ain)r�r�)r�r�)r*r�getaddresses)r-r.r0r0r1�test_getaddresses�s
z#TestMiscellaneous.test_getaddressescCsN|j}|tjdg�dg�|tjdg�d	d
dg�|tjddg�dd
g�dS)Nzfoo: ;r'z	[]*-- =~$�*--z#"Jason R. Mastaler" <jason@dom.ain>�Jason R. Mastaler�
jason@dom.ain)r'r')r'r')r'r')r'r�)r'r')r�r�)r*rr�)r-r.r0r0r1�test_getaddresses_nasty�sz)TestMiscellaneous.test_getaddresses_nastycCs(|j}tjdg�}||ddd�dS)z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>rrQzfoo@bar.comN)r*rr�)r-r.Zaddrsr0r0r1�"test_getaddresses_embedded_comment�sz4TestMiscellaneous.test_getaddresses_embedded_commentcsjGdd�dt���fdd�td�D�}t|��WdQRXtdd�|D�g�}|jtt|��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)�msgidsr7r�
make_msgidr�Z	monotonic)r-r7r�ZclockZtfinr0r0r1�run�s
zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)rrrr�r0r0r0r1�MsgidsThread�sr�csg|]
}���qSr0r0)rNrE)r�r0r1rP�sz@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>r�cSsg|]
}|j�qSr0)r�)rNrjr0r0r1rP�s)rrKr!�sumr*r�set)r-ZthreadsZall_idsr0)r�r1�test_make_msgid_collisions�s

z,TestMiscellaneous.test_make_msgid_collisionscCs.|j}t�}|jdddd�||j�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�}|j|j�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�|j�}|t|�d�||dd�t|d�}||j�d�|jd|d	�||j�d
�||jdd�d�||d
d�t�}d|d<|j�}|t|�d�||dd�t|d�}||j�tj	�|jd|d	�||j�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*rrJrrr�r;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�}|j|j�|j��dS)Nzus-asciizUS-ASCII)rr*r�)r-ZlcZucr0r0r1�test_charsets_case_insensitive�sz0TestMiscellaneous.test_charsets_case_insensitivecCs4|j}|jd�}t�}tj||�||j�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
)r,r+rrr�rh)r-r.r/r-r0r0r1�1test_partial_falls_inside_message_delivery_status�s
zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs"|jtjjdd�dd�d�dS)Nztestdomain-string)r��z@testdomain-string>i��)r*rqrr�)r-r0r0r1�test_make_msgid_domain�sz(TestMiscellaneous.test_make_msgid_domaincCs$|jtjjddd�dd�d�dS)Nz
test-idstringztestdomain-string)Zidstringr�rbz!.test-idstring@testdomain-string>i���)r*rqrr�)r-r0r0r1�test_make_msgid_idstring
sz*TestMiscellaneous.test_make_msgid_idstringcCs$|jtjj�jdt�d��dS)N�@�>)r�rqrr��endswithr)r-r0r0r1�test_make_msgid_default_domain

s
z0TestMiscellaneous.test_make_msgid_default_domainc
Csftddd��}|j�}WdQRX|jdd�}tj|�}t�}tjj|�}|j|�|j	|j
�|�dS)Nz
msg_26.txtr&)�newlinez
)r"rer1rqr�rrsrrgr*rh)r-�f�msgtxt�	msgtxt_nlr/r�r�r0r0r1�test_Generator_linend
s

z'TestMiscellaneous.test_Generator_linendcCsptddd��}|j�}WdQRX|jdd�}tj|�}t�}tjj|�}|j|dd�|j	|j
�jd�|�dS)Nz
msg_26.txtr&)r�z
)r�ro)r"rer1rqr�rrsrrgr*rhr>)r-r�r�r�r/r�r�r0r0r1�test_BytesGenerator_linend
s
z,TestMiscellaneous.test_BytesGenerator_linendcCsttdd��}|j�}WdQRX|jdd�}|jdd�}tj|�}t�}tjj|�}|j|dd�|j	|j
�|�dS)	Nz
msg_26.txtrswith attachmentsfo�s
r�z
)r�)r"rer1rqrvrrsrrgr*rh)r-r�r�r�r/r�r�r0r0r1�)test_BytesGenerator_linend_with_non_ascii%
s
z;TestMiscellaneous.test_BytesGenerator_linend_with_non_asciic!Cs�tdd��}|j�}WdQRXtdd��}|j�}WdQRXtdft|fft|fftt�fftdftd
fg}x�|D]~\}}|j	|j
dd�� ||�}|j|jt
jj�WdQRX|j	|j
d	d��*||d
t
jji�}|j|jt
jj�WdQRXqrWdS)Nzaudiotest.aurzPyBanner048.gifr'r�r�r�)�clsr�r�r�)r')r�r�)r')r"rerrrrrrrZsubTestrr�r�rqr�r�)r-riZ	audiodatar"�classesr�constructorrr0r0r1�!test_mime_classes_policy_argument1
s"

z3TestMiscellaneous.test_mime_classes_policy_argumentN)6rrrrmrorrrsrxr~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�rrr0r0r0r1rl4sf



			
*rlc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestIteratorsc
Cs�|j}|j}|jd�}tj|�}t|�}|t|�d�|tj|�|j	��|jd�}tj|�}t|�}|t|�d�t
d��}|tj|�|j��WdQRXdS)Nz
msg_01.txtrz
msg_02.txt�+z
msg_19.txt)r*r,r+rZbody_line_iteratorr<r�EMPTYSTRINGr�r?r"re)r-r.r�r/�itr�rir0r0r1�test_body_line_iteratorI
s




z%TestIterators.test_body_line_iteratorcCsf|j}|jd�}tj|d�}g}d}x"|D]}|d7}|j|j��q*W||d�|tj|�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_iteratorr7r?rr�)r-r.r/rr��subpartsrSr0r0r1�test_typed_subpart_iteratorZ
s



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

Do you like this message?

-Me
)r*r+rr
r7r?rr�)r-r.r/rr�rrSr0r0r1�(test_typed_subpart_iterator_default_typek
s



z6TestIterators.test_typed_subpart_iterator_default_typec	Cs�ddddddddg}ddlm}m}|�}g}d}xZ|D]R\}}|j|�||7}d}	x&t|j|�D]}
|j|
�|	d7}	qdW|j||	�q8W|jt|�|�|jdj	d
d�|D��dj	|��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.
        �a
 
rurxr�c
rQr'�d
�e
�
f�
)�BufferedSubFile�NeedMoreDatacSsg|]\}}|�qSr0r0)rN�il�nr0r0r1rP�
sz0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)rru)rxr)rrQ)r'r)rrQ)rr)rrQ)rrQ)
�email.feedparserrr�push�iter�readliner7r*rr�)r-Zimtrr�bsfZom�ntrrZn1Zolr0r0r1�test_pushCR_LF~
s,

zTestIterators.test_pushCR_LFcs�ddlm}m}d}d}d�dj�fdd�t|�D��d	}|jd
�}|�}g}xDtdt|�|�D]0}	||	|	|�}
|j|
�|jt	|j
|��qbW|j||�dS)Nr)rri'r�zabcd 	
r'c3s|]}t��VqdS)N)r)rNrE)�charsr0r1rF�
sz1TestIterators.test_push_random.<locals>.<genexpr>r&T)rrrr�rKr7rr�extendrrr*)r-rrrZ	chunksizer��targetrr�rE�chunkr0)rr1�test_push_random�
s 

zTestIterators.test_push_randomN)rrrr	rr
rr#r0r0r0r1rH
s
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCs&t�}x|D]}|j|�qW|j�S)N)r$�feed�close)r-�chunksryr"r0r0r1�parse�
s
zTestFeedParsers.parsecCs.|jd�}|j|dd�|j|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�|jdg�}|j|j�ddddg�|jdg�}|j|j�ddddg�|jddg�}|j|j�dd	g�|jd
dg�}|j|j�ddg�|jd
dg�}|j|j�ddg�|jd
g�}|j|j�dg�|jd
ddg�}|j|j�ddg�dS)Nz
a:
b:
c:
d:
rrx�c�dza:
b:
c:
d:za:
bzc:
Zbcza:
zb:
z
b:
ua:…b:
c:
�	…b:
c:ub:…r'�…c:)rr-)rr')rxr.)r(r*r�r[)r-rr0r0r1�
test_newlines�
szTestFeedParsers.test_newlinescCsd\}}|jdgd|g|�}|j|j�d
g�|j|j�d||�|jdgd|g|�}|j|j�dg�|j|j�d||�|jdgd|dg|�}|j|j�dg�|j|j�d|d|�|jd	d
gd|g|�}|j|j�ddd||fg�dS)N��� Nza:b

r�rrxza:b

�…za:
zb: r')r0r1)rrx)rrx)rrx)rr')r(r*r[r?)r-�M�Nrr0r0r1�test_long_lines�
szTestFeedParsers.test_long_linesN)rrrr(r*r/r5r0r0r0r1r$�
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�j|�}WdQRX||dd�||dd�||j�d�|j|j��|j|j�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_parsercCs�|j}tdd��}tjj�j|�}WdQRX||dd�||dd�||j�d�|j|j��|j	|j
�t�|j	|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��"}tjj�j|�|j|j�WdQRXdS)Nz
msg_02.txtr)r"rqrk�BytesParserr(r��closed)r-rir0r0r1�%test_bytes_parser_does_not_close_file�
sz1TestParsers.test_bytes_parser_does_not_close_filecCsLtdd��8}tjj}|jtjj|tjjd�j	|�|j
|j�WdQRXdS)Nz
msg_15.txtr)r�)r"rqrkr9r]rr�r��strictr(r�r:)r-riZbytesParserr0r0r1�2test_bytes_parser_on_exception_does_not_close_file�
s
z>TestParsers.test_bytes_parser_on_exception_does_not_close_filec	Cs6tdd��"}tjj�j|�|j|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}|jtjj|tjjd�j	|�|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_file
s

z8TestParsers.test_parser_on_exception_does_not_close_filecCs>|j}tjd�}||dd�||dd�||j�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}tjd�}||dd�||dd�||j�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�j|�}WdQRX|t|j��d�|jd�}||j�d�||j�d�|jd�}||j�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_separation5s

z TestParsers.test_crlf_separationcCsZtddd��}|j�}WdQRXtj|�}t�}t|�}|j|dd�|j|j�|�dS)Nz
msg_26.txtr&)r�z
)r�)	r"rerqr�rrrgr*rh)r-rir�r/r�r�r0r0r1�test_crlf_flatten@s
zTestParsers.test_crlf_flattenNc	
Cs&|j}|j}td��}tj|�}WdQRX||j�d�|t|j��d�|jd�}||j�d�||j�d�|t|j��d�|jd�}||j�d�||j�d�||j�d�|jd�}||j�d�||j�d�|t|j��d�|jd�}||j�d�||j�d�||j�d�dS)	Nz
msg_28.txtrQrurzmessage/rfc822z
text/plainz
message 1
z
message 2
)	r*r,r"rqrGr�rr?r6)	r-r.r�rir/rCZpart1arDZpart2ar0r0r1�-test_multipart_digest_with_extra_mime_headersLs,




z9TestParsers.test_multipart_digest_with_extra_mime_headerscCs.dddg}tjtj|��}|j|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_linesks
zTestParsers.test_three_linescCsH|j}d}d}d||f}tj|�}||jd�|�||jd�|�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_headersss

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

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

body�A�B�CCr�)r*rqr�r��sortr?)r-r.rr/Zheadersr0r0r1�!test_rfc2822_one_character_header�s
z-TestParsers.test_rfc2822_one_character_headercCs,d}tj|�}|j|jd�j�jd��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)rrrr7r8r;r=r>r?rArBrErFrorGrHrJrKrLrQrRr0r0r0r1r6�
s$
	r6c@s�eZdZejd�Zdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zd_Zdj
dd�eD��djd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zejd4�jd�Zd5d6�Zd7d8�Zejd9�Zd:d;�Zd<d=�Z d>d?�Z!ej"d�Z#d@ge#dAdB�<dj
e#�Z#dCdD�Z$ejdE�jdF�Z%ejdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVZ.dVS)`�Test8BitBytesHandlingz�        From: foo@bar.com
        To: baz
        Mime-Version: 1.0
        Content-Type: text/plain; charset={charset}
        Content-Transfer-Encoding: {cte}

        {bodyline}
        cCsP|jjdddd�jd�}tj|�}|j|j�d�|j|jdd�djd��dS)Nzutf-8rBupöstal)r3r}�bodylineupöstal
T)r>)�bodytest_msgr	rprqrvr*r?)r-rr/r0r0r1�test_known_8bit_CTE�s
z)Test8BitBytesHandling.test_known_8bit_CTEcCsP|jjdddd�jd�}tj|�}|j|j�d�|j|jdd�d	jd��dS)
NZnotavalidcharsetrBupöstal)r3r}rTzutf-8up��stal
T)r>upöstal
)rUr	rprqrvr*r?)r-rr/r0r0r1�test_unknown_8bit_CTE�s
z+Test8BitBytesHandling.test_unknown_8bit_CTEcCsP|jjdddd�jd�}tj|�}|j|j�d�|j|jdd�djd��dS)	Nzutf-8zquoted-printableup=C3=B6stál)r3r}rTu
p=C3=B6stál
T)r>u	pöstál
)rUr	rprqrvr*r?)r-rr/r0r0r1�test_8bit_in_quopri_body�s

z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCsP|jjdddd�jd�}tj|�}|j|j�d�|j|jdd�d	jd��dS)
Nrozquoted-printableup=C3=B6stál)r3r}rTzutf-8up=C3=B6st��l
T)r>u	pöstál
)rUr	rprqrvr*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�jd�}tj|�}|j|jdd�djd��|j|jdt	j
�dS)	Nzutf-8r=u
cMO2c3RhbAá=)r3r}rTT)r>upöstalr)rUr	rprqrvr*r?r�r�rr�)r-rr/r0r0r1�test_8bit_in_base64_body�s
z.Test8BitBytesHandling.test_8bit_in_base64_bodycCs@|jjdddd�jd�}tj|�}|j|jdd�djd��dS)Nzutf-8ryu
<,.V<W1A; á )r3r}rTT)r>u<,.V<W1A; á 
)rUr	rprqrvr*r?)r-rr/r0r0r1�test_8bit_in_uuencode_body�s
z0Test8BitBytesHandling.test_8bit_in_uuencode_body�From: foo@bar.comr��foo@bar.com�To: bázr��=?unknown-8bit?q?b=C3=A1z?=�VSubject: Maintenant je vous présente mon collègue, le pouf célèbre
	Jean de Baddier��=?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?=�From: göst�=?unknown-8bit?b?Z8O2c3Q=?=r&cCsg|]\}}|�qSr0r0)rN�src�_r0r0r1rPsz Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
zutf-8cCs:tj|j�}|jt|jd��d�|jt|d�d�dS)Nr�ub��z)rqrv�headertest_msgr*r�rI)r-r/r0r0r1�test_get_8bit_headersz*Test8BitBytesHandling.test_get_8bit_headercCs8tj|j�}|jt|�tjd�jdd�|jD���dS)Nz�                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            cSsg|]\}}|d�qS)rQr0)rNreZexpectedr0r0r1rP$szATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	rqrvrfr*r�rrr	�headertest_headers)r-r/r0r0r1�test_print_8bit_headerss

z-Test8BitBytesHandling.test_print_8bit_headerscCs2tj|j�}|jdd�|j�D�ddddg�dS)NcSsg|]}t|��qSr0)r�)rNr�r0r0r1rP)szGTest8BitBytesHandling.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)rqrvrf�assertListEqualr�)r-r/r0r0r1�test_values_with_8bit_headers'sz3Test8BitBytesHandling.test_values_with_8bit_headerscCs2tj|j�}|jdd�|j�D�d
ddd
g�dS)NcSs g|]\}}t|�t|�f�qSr0)r�)rNr�r�r0r0r1rP4szFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>r��foo@bar.comr��b��zr�]Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie�	g��st)r�rl)r�rm)rrn)r�ro)rqrvrfrjr[)r-r/r0r0r1�test_items_with_8bit_headers2sz2Test8BitBytesHandling.test_items_with_8bit_headerscCs0tj|j�}|jdd�|jd�D�ddg�dS)NcSsg|]}t|��qSr0)r�)rNr�r0r0r1rP@szHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�zfoo@bar.comu	g��st)rqrvrfrjr,)r-r/r0r0r1�test_get_all_with_8bit_headers>sz4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsJtjtjd�jd��}|j|j�d�|j|j�d�|j|j�d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            zlatin-1utext/pl�inr�upl�in)	rqrvrrrpr*r6r�r�)r-r/r0r0r1�test_get_content_type_with_8bitDs
z5Test8BitBytesHandling.test_get_content_type_with_8bitcCsZtjdjd��}|j|jdd�d
ddg�|j|jddd�d�|j|jddd�d�dS)Nu(X-Header: foo=§ne; b§r=two; baz=three
zlatin-1zx-header)r_r|��ne�b�rr�r�r�ZFooub§r)r|rs)rtr�)r�r�)rqrvrpr*r�r7)r-r/r0r0r1�test_get_params_with_8bitMsz/Test8BitBytesHandling.test_get_params_with_8bitcCs,tjtjd�jd��}|j|jd�d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1�title�us-ascii�en�This is not f�n)rwrxry)rqrvrrrpr*r7)r-r/r0r0r1�!test_get_rfc2231_params_with_8bitWs
z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCs8tjtjd�jd��}|jdd�|j|jd�d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1rv�test)rqrvrrrpr�r*r7)r-r/r0r0r1�!test_set_rfc2231_params_with_8bit_s
z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsFtjtjd�jd��}|jd�|j|jd�d�|j|j�d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1rvr�)	rqrvrrrpr�r*r7r�)r-r/r0r0r1�!test_del_rfc2231_params_with_8bitgs
z7Test8BitBytesHandling.test_del_rfc2231_params_with_8bitcCs>tjtjd�jd��}|j|j�d�|j|jdd�d�dS)Nu�            Content-Transfer-Encoding: b§se64
            Content-Type: text/plain; charset=latin-1

            payload
            zlatin-1zpayload
T)r>spayload
)rqrvrrrpr*r?)r-r/r0r0r1�%test_get_payload_with_8bit_cte_headerpsz;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:tj|j�}t�}tjj|�j|�|j|j�|j�dS)N)	rqrv�non_latin_bin_msgrrsrrgr*rh)r-r/rlr0r0r1�test_bytes_generator�sz*Test8BitBytesHandling.test_bytes_generatorcCs6tjj�}t�}tjj|�j|�|j|j�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:tj|j�}t�}tjj|�j|�|j|j�|j	�dS)N)
rqrvrrrsrrgr*rh� non_latin_bin_msg_as7bit_wrapped)r-r/rlr0r0r1�test_generator_handles_8bit�sz1Test8BitBytesHandling.test_generator_handles_8bitcCs`tj|j�}t�}t|�j|�|j�}tt��j|�t�}t|�j|�|j	|j�|�dS)N)
rqrvrrrrgrhrrr*)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_8bitcCsntj|j�}t�}tjj|�j|dd�|j�jd�}|j	|dj�dd�|j	dj
|dd��|j�dS)NT)r�r�rsFromrQ)rqrvrrrsrrgrhr�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?=rurYcCsnd}|jt|�t|d��}|j|j�WdQRXt|d��}tjj�j|�}WdQRX|j	t
|�|j�dS)Nztest.msg�wbr)Z
addCleanupr �open�writerrqrkr9r(r*r��non_latin_bin_msg_as7bit)r-rfZtestfilerr0r0r1�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"tj|j�}|jt|�|j�dS)N)rqrv�
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_appropriatecCsDtj|j�}t�}tjj|�j|�|j|j�|jj	d�d�dS)Nzlatin-1r&)
rqrvr�rrsrrgr*rhr>)r-rrlr0r0r1�)test_decoded_generator_emits_unicode_body�s

z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCs\tjj�}x2tdt|j�d�D]}|j|j||d��qW|j�}|jt	|�|j
�dS)NrrG)rqryr%rKrr�r%r&r*r�r�)r-ZbfprErr0r0r1�test_bytes_feedparser�s

z+Test8BitBytesHandling.test_bytes_feedparsercCs\tdd��}|j�}WdQRXtj|�}t�}tjj|�}|j|dd�|j|j	�|�dS)Nz
msg_26.txtrz
)r�)
r"rerqrvrrsrrgr*rh)r-rir�r/r�r�r0r0r1rF�s
z'Test8BitBytesHandling.test_crlf_flattencCsJtjd�jd�}tj|�}t�}tjj|�}|j|�|j	|j
�|�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)rrrprqrvrrsrrgr*rh)r-rwr/r�r�r0r0r1�test_8bit_multipart�s%

z)Test8BitBytesHandling.test_8bit_multipartcCsFt�}td�|d<t�}tjj|�}|j|dd�|j|j�d�dS)Nužluťoučký kůňrz
)r�s5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

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

)	rr	rrqrsrrgr*rh)r-rr�r�r0r0r1�!test_generator_b_encoding_linesep8sz7Test8BitBytesHandling.test_generator_b_encoding_linesepN�r�r]�r\r��r�r_�r^r��rra�r`r��r�rc�rbr�)r�r�r�r�)/rrrrrrUrVrWrXrYrZr[rhr�rprfrgrirkrprqrrrurzr|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rFr�r�r�ror0r0r0r1rS�sf			

	
	




			
	.rSc@s"eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNc
Cs@t|d��}|j�}WdQRX|jj|j|�}tj|�}||fS)Nr)r"re�normalize_linesep_regex�sub�blineseprqrv)r-r�rir@r/r0r0r1r+Ks

z(BaseTestBytesGeneratorIdempotent._msgobjFcCs<t�}tjj|dd�}|j|||jd�|j||j��dS)Nr)r`)r�r�)rrqrsrrgr�r*rh)r-r/r@r�rxr�r0r0r1rVRsz,BaseTestBytesGeneratorIdempotent._idempotent)F)rrrror+rVr0r0r0r1r�Gsr�c@seZdZdZdZejd�ZdS)�TestBytesGeneratorIdempotentNLr&r�s\r\nN)rrrr�r��re�compiler�r0r0r0r1r�Ysr�c@seZdZdZdZejd�ZdS)� TestBytesGeneratorIdempotentCRLFz
s
s	(?<!\r)\nN)rrrr�r�r�r�r�r0r0r0r1r�`sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TestBase64cCs�|j}|tjd�ttjddd���xntd�D]b}|dkr@d}n<|dkrNd}n.|d	kr\d
}n |dkrjd}n|dkrxd
}nd}|tjd|�|�q.WdS)N�helloshellor')�eol�rrvrYr�r����r�)r*r�
header_lengthr�body_encoderK)r-r.�sizeZbsizer0r0r1�test_lenhs 
zTestBase64.test_lencCs*|j}|tjd�d�|tjd�d�dS)Nr'�zaGVsbG8=shello)r*rr>)r-r.r0r0r1�test_decodeuszTestBase64.test_decodecCsl|j}|tjd�d�|tjd�d�|tjd�d�|tjdddd	�d
�|tjddddd�d
�dS)Nr�shelloz	aGVsbG8=
shello
z	aGVsbG8K
sxxxx r��()r6z�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
z
)r6r�z�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r*rr�)r-r.r0r0r1�test_encodezszTestBase64.test_encodecCsZ|j}tj}||d�d�||d�d�||d�d�||ddd�d	�||d�d�dS)
Nr�z=?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.Zher0r0r1�test_header_encode�szTestBase64.test_header_encodeN)rrrr�r�r�r�r0r0r0r1r�gs
r�c@s*eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd�dd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd�d&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,d�dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4dfdg�Z5dhdi�Z6djdk�Z7dldm�Z8dndo�Z9dpdq�Z:drds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd
S)��
TestQuoprics�ttttd�td�d�ttd�td�d�ttd�td�d�dd	�d
D����_�fdd�td
�D��_t�j�t�j�d
ks�t�tttd�td�d���_�jj	td���jj
td���fdd�td
�D��_t�j�t�j�d
ks�t�dS)Nr�zrQrM�Zr��9css|]
}|VqdS)Nr0)rNr+r0r0r1rF�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<rrK�ordr��hnonr�AssertionErrorr�r7�remove�bnon)r-r0)r-r1rq�szTestQuopri.setUpcCsXx(|jD]}|jtj|�dt|��qWx(|jD]}|jtj|�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]}|jtj|�dt|��qWx(|jD]}|jtj|�dt|��q2WdS)Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)r�r�rZ
body_checkr�r�r�)r-r+r0r0r1�test_quopri_body_check�sz!TestQuopri.test_quopri_body_checkcCs�|j}|tjd�d�|ttjddd��tjd�d�|tjd�d�|ttjddd��tjd�d�x.|jD]$}|tjt|g��dd	t|��qrWx<|jD]2}|t	d
�kr�q�|tjt|g��ddt|��q�W|tjd
�d�dS)Nshellor�Zxxx)r3rGs
h@e@l@l@o@r�rQzexpected length 1 for %rr(rvzexpected length 3 for %r� )
r*rr�rr�r�r�r�r�r�)r-r.r+r0r0r1�test_header_quopri_len�s$z!TestQuopri.test_header_quopri_lencCsV|j}x$|jD]}|tjt|g��d�qWx$|jD]}|tjt|g��d�q4WdS)NrQrv)r*r�rZbody_lengthr�r�)r-r.r+r0r0r1�test_body_quopri_len�s
zTestQuopri.test_body_quopri_lencCs6x0td�D]$}t|�}|jtjtj|��|�q
WdS)Nr�)rKr�r*rr�Zquote)r-r�r+r0r0r1�test_quote_unquote_idempotent�sz(TestQuopri.test_quote_unquote_idempotentNcCs0|dkrtj|�}ntj||�}|j||�dS)N)rr�r*)r-r_Zexpected_encoded_headerr3�encoded_headerr0r0r1�_test_header_encode�szTestQuopri._test_header_encodecCs|jdd�dS)Nr�r')r�)r-r0r0r1�test_header_encode_null�sz"TestQuopri.test_header_encode_nullcCs|jdd�dS)Nshelloz=?iso-8859-1?q?hello?=)r�)r-r0r0r1�test_header_encode_one_word�sz&TestQuopri.test_header_encode_one_wordcCs|jdd�dS)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=)r�)r-r0r0r1�test_header_encode_two_lines�sz'TestQuopri.test_header_encode_two_linescCs|jdd�dS)Nshello�therez=?iso-8859-1?q?hello=C7there?=)r�)r-r0r0r1�test_header_encode_non_ascii�sz'TestQuopri.test_header_encode_non_asciicCs|jdddd�dS)Nshelloz=?iso-8859-2?q?hello?=z
iso-8859-2)r3)r�)r-r0r0r1�test_header_encode_alt_charset�sz)TestQuopri.test_header_encode_alt_charsetcCstj|�}|j||�dS)N)r�
header_decoder*)r-r�Zexpected_decoded_headerZdecoded_headerr0r0r1�_test_header_decodes
zTestQuopri._test_header_decodecCs|jdd�dS)Nr')r�)r-r0r0r1�test_header_decode_nullsz"TestQuopri.test_header_decode_nullcCs|jdd�dS)Nr�)r�)r-r0r0r1�test_header_decode_one_wordsz&TestQuopri.test_header_decode_one_wordcCs|jdd�dS)Nz
hello=0Aworldzhello
world)r�)r-r0r0r1�test_header_decode_two_linessz'TestQuopri.test_header_decode_two_linescCs|jdd�dS)Nz
hello=C7thereuhelloÇthere)r�)r-r0r0r1�test_header_decode_non_asciisz'TestQuopri.test_header_decode_non_asciicCs|jtjdd�dd�dS)Nz=30ir�)r*rr�)r-r0r0r1�test_header_decode_re_bug_18380sz*TestQuopri.test_header_decode_re_bug_18380cCs2|dkrtj|�}ntj||d�}|j||�dS)N)r�)rr>r*)r-ZencodedZexpected_decodedr��decodedr0r0r1�_test_decodeszTestQuopri._test_decodecCs|jdd�dS)Nr')r�)r-r0r0r1�test_decode_null_wordsz TestQuopri.test_decode_null_wordcCs|jdd�dS)Nz
r&)r�)r-r0r0r1�test_decode_null_line_null_wordsz*TestQuopri.test_decode_null_line_null_wordcCs|jdd�dS)Nr�)r�)r-r0r0r1�test_decode_one_word"szTestQuopri.test_decode_one_wordcCs|jdddd�dS)Nr��X)r�)r�)r-r0r0r1�test_decode_one_word_eol%sz#TestQuopri.test_decode_one_word_eolcCs|jdd�dS)Nzhello
zhello
)r�)r-r0r0r1�test_decode_one_line(szTestQuopri.test_decode_one_linecCs|jdd�dS)Nzhello
)r�)r-r0r0r1�test_decode_one_line_lf+sz"TestQuopri.test_decode_one_line_lfcCs|jdd�dS)Nzhello
zhello
)r�)r-r0r0r1�test_decode_one_line_cr.sz"TestQuopri.test_decode_one_line_crcCs|jdddd�dS)Nzhello
�helloXr�)r�)r�)r-r0r0r1�test_decode_one_line_nl1sz"TestQuopri.test_decode_one_line_nlcCs|jdddd�dS)Nzhello
r�r�)r�)r�)r-r0r0r1�test_decode_one_line_crnl4sz$TestQuopri.test_decode_one_line_crnlcCs|jdd�dS)Nzhello
worldzhello
world)r�)r-r0r0r1�test_decode_one_line_one_word7sz(TestQuopri.test_decode_one_line_one_wordcCs|jdddd�dS)Nzhello
worldZhelloXworldr�)r�)r�)r-r0r0r1�!test_decode_one_line_one_word_eol:sz,TestQuopri.test_decode_one_line_one_word_eolcCs|jdd�dS)Nzhello
world
zhello
world
)r�)r-r0r0r1�test_decode_two_lines=sz TestQuopri.test_decode_two_linescCs|jdddd�dS)Nzhello
world
ZhelloXworldXr�)r�)r�)r-r0r0r1�test_decode_two_lines_eol@sz$TestQuopri.test_decode_two_lines_eolcCs|jdddd�dS)NZSpam�)r�)r-r0r0r1�test_decode_one_long_lineCsz$TestQuopri.test_decode_one_long_linecCs|jdd�dS)Nr(r')r�)r-r0r0r1�test_decode_one_spaceFsz TestQuopri.test_decode_one_spacecCs|jdd�dS)Nr(r�r'z     )r�)r-r0r0r1�test_decode_multiple_spacesIsz&TestQuopri.test_decode_multiple_spacescCs|jdd�dS)Nzhello    
zhello
)r�)r-r0r0r1�$test_decode_one_line_trailing_spacesLsz/TestQuopri.test_decode_one_line_trailing_spacescCs|jdd�dS)Nzhello    
world   
zhello
world
)r�)r-r0r0r1�%test_decode_two_lines_trailing_spacesOsz0TestQuopri.test_decode_two_lines_trailing_spacescCs|jdd�dS)Nz=22quoted=20words=22z"quoted words")r�)r-r0r0r1�test_decode_quoted_wordRsz"TestQuopri.test_decode_quoted_wordcCs|jdd�dS)Nzab=CD=EFuabÍï)r�)r-r0r0r1�test_decode_uppercase_quotingUsz(TestQuopri.test_decode_uppercase_quotingcCs|jdd�dS)Nzab=cd=efuabÍï)r�)r-r0r0r1�test_decode_lowercase_quotingXsz(TestQuopri.test_decode_lowercase_quotingcCs|jdd�dS)Nzsoft line=
breakzsoft linebreak)r�)r-r0r0r1�test_decode_soft_line_break[sz&TestQuopri.test_decode_soft_line_breakcCs|jdd�dS)NzA=1,B=A ==> A+B==2)r�)r-r0r0r1�test_decode_false_quoting^sz$TestQuopri.test_decode_false_quotingcCs�i}|dkrd}n||d<|dkr(d}n||d<tj|f|�}|j||�|dksZ|dkr|x |j�D]}|jt|�|�qdWdS)Nrr6r&r�z
)rr�r*r7r r)r-r�Zexpected_encoded_bodyr6r��kwargsZencoded_bodyr�r0r0r1�_test_encodeaszTestQuopri._test_encodecCs|jdd�dS)Nr')r�)r-r0r0r1�test_encode_nulluszTestQuopri.test_encode_nullcCs|jdd�dS)Nz

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

1234r)r6)r�)r-r0r0r1�,test_encode_trailing_space_before_maxlinelen�sz7TestQuopri.test_encode_trailing_space_before_maxlinelencCs|jdddd�dS)Nz
abcd 
1234zabcd=
=20
1234r�)r6)r�)r-r0r0r1�(test_encode_trailing_space_at_maxlinelen�sz3TestQuopri.test_encode_trailing_space_at_maxlinelencCs|jdddd�dS)Nz
abcd 
1234zabc=
d=20
1234rY)r6)r�)r-r0r0r1�,test_encode_trailing_space_beyond_maxlinelen�sz7TestQuopri.test_encode_trailing_space_beyond_maxlinelencCs|jdd�dS)Nz 
r�z=20
z
 
 
 
 
 
z=20
=20
=20
=20
=20
)r�)r-r0r0r1�test_encode_whitespace_lines�sz'TestQuopri.test_encode_whitespace_linescCs|jdd�dS)Nza = bza =3D b)r�)r-r0r0r1�test_encode_quoted_equals�sz$TestQuopri.test_encode_quoted_equalscCs$|jddddddd�dS)Nr��d�Kz=
r�)r�)r-r0r0r1�test_encode_one_long_string�sz&TestQuopri.test_encode_one_long_stringcCs,|jddddddddd�dS)Nr�rr&r	z=
r�)r�)r-r0r0r1�test_encode_one_long_line�sz$TestQuopri.test_encode_one_long_linecCs0|jdddddddddd�dS)Nr���r&rur	z=
�2)r�)r-r0r0r1�test_encode_one_very_long_line�sz)TestQuopri.test_encode_one_very_long_linecCs|jdd	dd�dS)
Nr�r�z=3D=
rYz=3D)r6z=====z=3D=
=3D=
=3D=
=3D=
z=3D=
=3D=
=3D=
=3D=
=3D)r�)r-r0r0r1�test_encode_shortest_maxlinelen�sz*TestQuopri.test_encode_shortest_maxlinelencCs|jt|jdddd�dS)Nr'rv)r6)r]r�r�)r-r0r0r1� test_encode_maxlinelen_too_small�sz+TestQuopri.test_encode_maxlinelen_too_smallcCs||j}|tjd�d�|tjd�d�|tjd�d�|tjdddd�d	�|tjdddd
d�d�|tjd
�d
�dS)Nr'r�zhello
worldzhello
worldzxxxx r�r�)r6zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20z
)r6r�zlxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20zone line

two line)r*rr�)r-r.r0r0r1r��szTestQuopri.test_encode)N)N)NN)Frrrrqr�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�rrrrrrrrr
rrrrr�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�}||jd�d�d}|jt|j|�td�}||j|�d�dS)Nzus-asciizHello World!u¤¢¤¤¤¦¤¨¤ªzutf-8z(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r*rr�r]r�)r-r.r+r�r0r0r1�test_codec_encodeable�sz!TestCharset.test_codec_encodeablecCs�|j}td�}|d|jd��td�}|d|jd��td�}|d|jd��td	�}d
dlm}|jd|jdd�td�}|d|jd��dS)
Nz
iso-8859-1z
hello w=F6rlduhello wörldzutf-8zaGVsbG8gd29ybGQ=
shello worldzus-asciizhello worldzeuc-jpr)r3r)r*rr�rqr3Zadd_charsetZQP)r-r.r+rr0r0r1�test_body_encode�szTestCharset.test_body_encodecCs,td�}|jt|�d�|jtjtd�dS)Nzus-asciiuascÿii)rr*r�r]rZCharsetError)r-r3r0r0r1�test_unicode_charset_namesz%TestCharset.test_unicode_charset_nameN)rrrrrrrr0r0r0r1r�src@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�Zd1S)2�
TestHeadercCs8|j}td�}||j�d�|jd�||j�d�dS)NzHello World!z Goodbye World!zHello World!  Goodbye World!)r,r	rpr7)r-r.r3r0r0r1�test_simples

zTestHeader.test_simplecCs8|j}td�}||j�d�|jd�||j�d�dS)NzHello World!zGoodbye World!zHello World! Goodbye World!)r,r	rpr7)r-r.r3r0r0r1�test_simple_surprise s

zTestHeader.test_simple_surprisecCsd}|jt|�|dfg�dS)Nzno decoding needed)r*r
)r-r3r0r0r1�test_header_needs_no_decoding'sz(TestHeader.test_header_needs_no_decodingcCs<tddd�}x*|jdd�jd�D]}|jt|�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)r6r()Z
splitcharsz
 )r	rpr�r r)r-r3�lr0r0r1�	test_long+szTestHeader.test_longc
Cs�|j}td�}td�}td�}d}d}d}t||�}|j||�|j||�|jdd�}	||	d	�t|	�}
|t|
�d
�||
d|df�||
d|df�||
d
|jd�df�t|�}||djd��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)r6a=?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.」と言っています。)
r,rr	r7rpr
rr�r>r)
r-r.r�r8r9r:r;r<r3�encr�ZustrZnewhr0r0r1�test_multilingual1s0
zTestHeader.test_multilingualcCst�}|j|j�d�dS)Nr')r	r*rp)r-r3r0r0r1�test_empty_header_encodepsz#TestHeader.test_empty_header_encodecCs4|j}t�}||d�|jdtd��||d�dS)Nr'r|z
iso-8859-1)r,r	r7r)r-r.r3r0r0r1�test_header_ctor_default_argsts

z(TestHeader.test_header_ctor_default_argscCs�|j}d}t|�}||j�d�|t|�|�t|dd�}||j�d�|t|�|�t|ddd�}||j�|�|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)r5z}A very long line that must get split to something other than at the
 76th character boundary to test the non-default behaviori)r6r5)r,r	rpr�)r-r.r2r3r0r0r1�test_explicit_maxlinelen{sz#TestHeader.test_explicit_maxlinelencCs�|j}tddd�}dd}|j|�|j�}||d�||ttt|����tddd�}|jdd�|j�}||d�||ttt|����dS)Nz
iso-8859-1r�)r3r6zxxxx a=?iso-8859-1?q?xxx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_?=r�z�=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xxx?=
 =?iso-8859-1?q?x_xxxx_xxxx_xxxx_xxxx_?=
 =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
 =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
 =?iso-8859-1?q?_xxxx_xxxx_?=)r,r	r7rpr�rr
)r-r.r3r�r�r0r0r1�test_quopri_splittable�s
2z!TestHeader.test_quopri_splittablecCs�|j}tddd�}dd}|j|�|j�}||d�||ttt|����tddd�}|j|�|j�}||d�||ttt|����dS)Nzkoi8-rr�)r3r6zxxxx a�=?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IA==?=r�z�=?koi8-r?b?eHh4eCB4eHh4IHh4eHggeHh4?=
 =?koi8-r?b?eCB4eHh4IHh4eHggeHh4eCB4?=
 =?koi8-r?b?eHh4IHh4eHggeHh4eCB4eHh4?=
 =?koi8-r?b?IHh4eHggeHh4eCB4eHh4IHh4?=
 =?koi8-r?b?eHggeHh4eCB4eHh4IHh4eHgg?=
 =?koi8-r?b?eHh4eCB4eHh4IA==?=)r,r	r7rpr�rr
)r-r.r3r�r�r0r0r1�test_base64_splittable�s
"
z!TestHeader.test_base64_splittablecCs8|j}d}t|�}||dg�t|�}|||j��dS)Nr�)r�N)r*r
rrp)r-r.r�r�r3r0r0r1�test_us_ascii_header	szTestHeader.test_us_ascii_headercCs&|j}t�}|jdd�||d�dS)Nr�z
iso-8859-1)r*r	r7)r-r.r3r0r0r1�test_string_charsetszTestHeader.test_string_charsetcCs:|j}tdd�}||j�d�tdd�}||j�d�dS)Nupöstalzutf-8z=?utf-8?q?p=C3=B6stal?=u菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=)r*r	rp)r-r.r3r0r0r1�test_utf8_shortest s


zTestHeader.test_utf8_shortestcCsr|j}|j}d}|tt|�t�}|t|j|�|jdd�}|tt|dd��|�|j|dd�|t|�|�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzutf-8r1)r)r]r*r�r	r7r>r�)r-r�r.r�r3�er0r0r1�test_bad_8bit_header'szTestHeader.test_bad_8bit_headercCsNd}|jdd�}t|tjjd�}|jt|�d�|jtjj|�|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(r3r0r0r1�test_escaped_8bit_header3s
z#TestHeader.test_escaped_8bit_headercCsBd}t|tjjd�}|jt|�d�|jtjj|�|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�r3r0r0r1�&test_header_handles_binary_unknown8bit;s

z1TestHeader.test_header_handles_binary_unknown8bitcCsVd}t|tjjd�}tjjtjj|��}|jt|�d�|jtjj|�|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�r3Zh2r0r0r1�+test_make_header_handles_binary_unknown8bitBs
z6TestHeader.test_make_header_handles_binary_unknown8bitcCs2td�}tjj|�}|jd�|jt|�d�dS)Nr{ro�test2)ror/)r	rqr_r
r7r*r�)r-r3r'r0r0r1�0test_modify_returned_list_does_not_change_headerJs
z;TestHeader.test_modify_returned_list_does_not_change_headercCsR|j}t�}|jdd�|jd�|j�}||d�tt|��}||j�|�dS)Nr�z
iso-8859-1Zworldz=?iso-8859-1?q?hello?= world)r*r	r7rprr
)r-r.r3r�r0r0r1� test_encoded_adjacent_nonencodedPs

z+TestHeader.test_encoded_adjacent_nonencodedcCs<|j}d}t|�}||ddd	g�t|�}||j�d�dS)
NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.�	Subject: �������� � ��������koi8-r� zz.z6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.)r2N)r3r4)r5N)r*r
rrp)r-r.r��partsZhdrr0r0r1�test_whitespace_keeperZsz!TestHeader.test_whitespace_keepercCs|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r]rr^r
)r-r�r�r0r0r1�test_broken_base64_headercsz$TestHeader.test_broken_base64_headercCs tddd�}|j|j�d�dS)Nu文�	shift_jis)r3z=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	r*rp)r-r3r0r0r1�test_shift_jis_charsethsz!TestHeader.test_shift_jis_charsetcCstjd�}|jt|�d�dS)NzEmptyHeader:zEmptyHeader: 

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

)rr*r�)r-r/r0r0r1�)test_encode_preserves_leading_ws_on_valuessz4TestHeader.test_encode_preserves_leading_ws_on_valueN)rrrrrrrrr r!r"r#r$r%r&r'r)r,r-r.r0r1r7r8r:r;r<r0r0r0r1rs0?E6
	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�Zd9S):�TestRFC2231cCs8|j}|jd�}||jd�d	�||jddd�d
�dS)Nz
msg_29.txtrv�us-asciirx�%This is even more ***fun*** isn't it!F)r��'"This is even more ***fun*** isn't it!")r>rxr?)r>rxr@)r*r+r7)r-r.r/r0r0r1r�s

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


Hi,

Do you like this message?

-Me
)rBr'rA)rBrxrA)r,rr�r7r+rc)r-r.r/r0r0r1r��s




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


Hi,

Do you like this message?

-Me
)r,r+r�r�rc)r-r.r/r0r0r1r��s

zTestRFC2231.test_del_paramcCs"|j}|jd�}||j�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_charsetcCs8tjd�}tj|�}|j|j�d�|j||j��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)rrrqr�r*rMrc)r-rr/r0r0r1�test_rfc2231_parse_rfc_quoting�s

z*TestRFC2231.test_rfc2231_parse_rfc_quotingcCs8tjd�}tj|�}|j|j�d�|j||j��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)rrrqr�r*rMrc)r-rr/r0r0r1� test_rfc2231_parse_extra_quoting�s

z,TestRFC2231.test_rfc2231_parse_extra_quotingcCs4d}tj|�}|jd�}|j|t�|j|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_charset�s

z/TestRFC2231.test_rfc2231_no_language_or_charsetcCs"d}tj|�}|j|j�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_filename
s

z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamecCs"d}tj|�}|j|j�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_encodeds

zCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedcCs"d}tj|�}|j|j�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_encoded%s

z'TestRFC2231.test_rfc2231_partly_encodedcCs"d}tj|�}|j|j�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_nonencoded2s

z*TestRFC2231.test_rfc2231_partly_nonencodedcCs"d}tj|�}|j|j�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_boundary?s

z;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundarycCs"d}tj|�}|j|j�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*rE)r-rr/r0r0r1�.test_rfc2231_no_language_or_charset_in_charsetKs

z:TestRFC2231.test_rfc2231_no_language_or_charset_in_charsetcCs"d}tj|�}|j|j�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_filenameYs

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

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

)rqr�r*rE)r-rr/r0r0r1�%test_rfc2231_bad_character_in_charsetos
z1TestRFC2231.test_rfc2231_bad_character_in_charsetcCs"d}tj|�}|j|j�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_filenameys

z2TestRFC2231.test_rfc2231_bad_character_in_filenamecCs"d}tj|�}|j|j�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}tj|�}|jd�\}}}||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/r3rCr�r0r0r1�-test_rfc2231_single_tick_in_filename_extended�s


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

r�zFrank's Document)rqr�r7rJrKr*)r-rr/rLr0r0r1�$test_rfc2231_single_tick_in_filename�s


z0TestRFC2231.test_rfc2231_single_tick_in_filenamecCs"d}tj|�}|j|j�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}tj|�}|j|j�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}tj|�}|jd�\}}}||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/r3rCr�r0r0r1�!test_rfc2231_tick_attack_extended�s


z-TestRFC2231.test_rfc2231_tick_attack_extendedcCs4d}tj|�}|jd�}|j|t�|j|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�r7rJrKr*)r-rr/rLr0r0r1�test_rfc2231_tick_attack�s


z$TestRFC2231.test_rfc2231_tick_attackcCs(|j}d}tj|�}||jd�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}tj|�}|jd�\}}}||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/r3rCr�r0r0r1�,test_rfc2231_encoded_then_unencoded_segments�s


z8TestRFC2231.test_rfc2231_encoded_then_unencoded_segmentscCsF|j}d}tj|�}|jd�\}}}||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/r3rCr�r0r0r1�,test_rfc2231_unencoded_then_encoded_segments�s


z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsN)rrrr�r�rDr�rFrGrHrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rar0r0r0r1r={s8%
!




	


r=c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestSignedc	Cs.t|��}|j�}tj|�}WdQRX||fS)N)r"rerqr�)r-r�ri�originalr/r0r0r1�_msg_and_objs
zTestSigned._msg_and_objcCsLddl}|jd|j|jB�}|j|�jd�}|j|�jd�}|j||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$ru)r�r��Sr3�search�groupr*)r-rc�resultr�ZrepartZinpartZoutpartr0r0r1�_signed_parts_eqs
zTestSigned._signed_parts_eqcCs&|jd�\}}|j�}|j||�dS)Nz
msg_45.txt)rdrcri)r-rcr/rhr0r0r1�test_long_headers_as_stringsz&TestSigned.test_long_headers_as_stringcCs*|jd�\}}|jdd�}|j||�dS)Nz
msg_45.txt�<)r`)rdrcri)r-rcr/rhr0r0r1�(test_long_headers_as_string_maxheaderlensz3TestSigned.test_long_headers_as_string_maxheaderlencCs:|jd�\}}t�}t|�j|�|j�}|j||�dS)Nz
msg_45.txt)rdrrrgrhri)r-rcr/rirhr0r0r1�test_long_headers_flattens
z$TestSigned.test_long_headers_flattenN)rrrrdrirjrlrmr0r0r0r1rbs
rb�__main__)br�r�r=r�r�iorr�	itertoolsrZrandomrZsocketrZ	threadingr�ImportErrorZdummy_threadingrqZ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�rrJr)ZTestCaserr+rprzr�r�r�r�r�r�r9rUrlrr$r6rSr�r�r�r�r�rrr=rbr�mainr0r0r0r1�<module>s�ICAF((\<0< g0K!5D:e#


Youez - 2016 - github.com/yon3zu
LinuXploit