Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_email/__pycache__/test_email.cpython-35.pyc



��Yf(�
@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/m0Z0ddlm1Z1ddlm2Z2ddlm3Z3ddlm4Z4ddlm5Z5ddlm6Z6ddl7m8Z8m9Z9ddl:m;Z;m<Z<ddlm=Z=m>Z>dZ?dZ@dZAGdd �d e<�ZBGd!d"�d"ejC�ZDGd#d$�d$e<�ZEGd%d&�d&ejC�ZFGd'd(�d(ejC�ZGGd)d*�d*ejC�ZHGd+d,�d,ejC�ZIGd-d.�d.ejC�ZJGd/d0�d0e<�ZKGd1d2�d2e<�ZLGd3d4�d4e<�ZMGd5d6�d6e<�ZNGd7d8�d8e<�ZOGd9d:�d:e<�ZPGd;d<�d<e<�ZQGd=d>�d>e<�ZRGd?d@�d@e<�ZSGdAdB�dBe<�ZTGdCdD�dD�ZUGdEdF�dFeUeO�ZVGdGdH�dHeUeO�ZWGdIdJ�dJejC�ZXGdKdL�dLejC�ZYGdMdN�dNejC�ZZGdOdP�dPe<�Z[GdQdR�dRe<�Z\GdSdT�dTe<�Z]e^dUkr�ej_�dS)V�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)�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)��TestMessageAPIcCsT|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�r/�?/opt/alt/python35/lib64/python3.5/test/test_email/test_email.py�test_get_all8s	zTestMessageAPI.test_get_allcCsL|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.r2r/r/r0�test_getset_charset>s,		

	



z"TestMessageAPI.test_getset_charsetcCsJ|j}t�}|jd�||j�jd�||dd�dS)Nzus-asciizcontent-typeztext/plain; charset="us-ascii")r)rr4r3r7)r,r-r.r/r/r0�test_set_charset_from_stringXs
		
z+TestMessageAPI.test_set_charset_from_stringcCsBt�}td�}|jd|�|j|j�jd�dS)Nz
iso-8859-1zThis is a string payload)rr�set_payloadr)r3r7)r,r.r2r/r/r0�test_set_payload_with_charset_s	z,TestMessageAPI.test_set_payload_with_charsetcCsud}td�}t�}|j||�|j|dd�|j|jdd�|�|j|j�d�dS)NsАБВzutf-8zcontent-transfer-encoding�base64�decodeTz	0JDQkdCS
)rrr:r)�get_payload)r,�datar2r.r/r/r0�+test_set_payload_with_8bit_data_and_charsetes	z:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetcCsqd}td�}d|_t�}|j|jd�|�|j|dd�|j|jdd�|�dS)NsАБВzutf-8zcontent-transfer-encoding�8bitr=T)r�
body_encodingrr:r=r)r>)r,r?r2r.r/r/r0�>test_set_payload_with_non_ascii_and_charset_body_encoding_nonens		zMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonecCshd}td�}d|_t�}|j||�|j|dd�|j|jdd�|�dS)NsАБВzutf-8zcontent-transfer-encodingrAr=T)rrBrr:r)r>)r,r?r2r.r/r/r0�>test_set_payload_with_8bit_data_and_charset_body_encoding_nonews		zMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonecCs0t�}|jg�|j|j�g�dS)N)rr:r)r>)r,r.r/r/r0�test_set_payload_to_list�s	
z'TestMessageAPI.test_set_payload_to_listcCsLt�}d|d<|jd�tt��}|jtd|j|�dS)Nzmultipart/mixedzContent-Typezstring payloadz[Aa]ttach.*non-multipart)rr:rZassertRaisesRegex�	TypeError�attach)r,r.Zsub_msgr/r/r0�"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.�charsetsr/r/r0�test_get_charsets�s	
z TestMessageAPI.test_get_charsetscCsy|j}|jd�}dd�|j�D�}||ddg�|jd�}|jd�}||j�d�dS)Nz
msg_04.txtcSsg|]}|j��qSr/)�get_filename)�.0�pr/r/r0�
<listcomp>�s	z4TestMessageAPI.test_get_filename.<locals>.<listcomp>zmsg.txtz
msg_07.txt�zdingusfish.gif)r)r*r>rL)r,r-r.�	filenames�subpartr/r/r0�test_get_filename�s	z TestMessageAPI.test_get_filenamecCsH|j}|jd�}dd�|j�D�}||ddg�dS)Nz
msg_44.txtcSsg|]}|j��qSr/)rL)rMrNr/r/r0rO�s	zHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>zmsg.txt)r)r*r>)r,r-r.rQr/r/r0�%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.r/r/r0�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.txtrU�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�valuer/r/r0�test_set_boundary�s	



z TestMessageAPI.test_set_boundarycCs`td�}|j|j�ddd�|j�|j|j�dddd�d�dS)Nz	form-datarrPzmultipart/form-data�!z!multipart/form-data; boundary="==)rr)rZ�	as_string)r,r.r/r/r0�test_make_boundary�s

!z!TestMessageAPI.test_make_boundarycCstd��}|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�genr/r/r0�test_message_rfc822_only�s		z'TestMessageAPI.test_message_rfc822_onlyc
Cs�td��}|j�jd�}WdQRXtjj�}|j|�}t�}tjj	|�}|j
|�|j|j�|�dS)Nz
msg_46.txt�ascii)
r!rd�encode�emailrj�BytesHeaderParserZ
parsebytesr�	generatorrrfr)rg)r,rhrirjr.rkrlr/r/r0�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.txtr=Trs This is a 7bit encoded message.
rPs-�This is a Quoted Printable encoded message!
�s!This is a Base64 encoded message.�s"This is a Base64 encoded message.
rXs/This has no Content-Transfer-Encoding: header.
)r)r*r>)r,r-r.r/r/r0�test_get_decoded_payload�s	z'TestMessageAPI.test_get_decoded_payloadcCs}|j}t�}|jd�x1dD])}||d<||jdd�d	�q&W|jd
�||jdd�d�dS)
Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
�
x-uuencode�uuencode�uue�x-uuezcontent-transfer-encodingr=Tshello world�foosfoo)rwrxryrz)r)rr:r>)r,r-r.�cter/r/r0�test_get_decoded_uu_payloads		



z*TestMessageAPI.test_get_decoded_uu_payloadcCs#t�}|jt|jd�dS)NrP)rr\rFr>)r,r.r/r/r0�*test_get_payload_n_raises_on_non_multiparts	z9TestMessageAPI.test_get_payload_n_raises_on_non_multipartc
Css|j}|jd�}td��}|j�}WdQRXt�}t|�}|j|�||j�|�dS)Nz
msg_07.txtz
msg_17.txt)r)r*r!rdrrrfrg)r,r-r.rh�text�s�gr/r/r0�test_decoded_generators		
z%TestMessageAPI.test_decoded_generatorcCs�t�}d|d<d|d<|jd|�|jd|�|jd|�|jd|�|jd|�|jd|�dS)	NZMe�FromZYou�to�fromZFROM�ToZTO)r�assertIn)r,r.r/r/r0�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.txt�unixfromTr%rzFrom rP)r*r!rdr)�strrb�split�
assertTrue�
startswith�NL�join)r,r.rhr�fullrepr�linesr/r/r0�test_as_string)szTestMessageAPI.test_as_stringcCsx|jd�}|jjdd�}|jd|�}t�}t|d|�}|j|�|j||j��dS)Nz
msg_01.txt�linesepz
�policy)	r*r��clonerbrrrfr)rg)r,r.�	newpolicyr�r�r�r/r/r0�test_as_string_policy3s	
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.txtrnr�Ts
rsFrom rP)r*r!rdror)�bytes�as_bytesr�r�r�r�)r,r.rhr?r�r�r/r/r0�
test_as_bytes<szTestMessageAPI.test_as_bytescCsx|jd�}|jjdd�}|jd|�}t�}t|d|�}|j|�|j||j��dS)Nz
msg_01.txtr�z
r�)	r*r�r�r�rrrfr)rg)r,r.r�r�r�r�r/r/r0�test_as_bytes_policyFs	
z#TestMessageAPI.test_as_bytes_policycCs,tjd�}|j|jd�d�dS)NzContent-Type: blarg; baz; boo
�bazr&)rp�message_from_stringr)r6)r,r.r/r/r0�test_bad_paramPszTestMessageAPI.test_bad_paramcCs)tjd�}|j|j�d�dS)Nz
From: foo
)rpr�r)rL)r,r.r/r/r0�test_missing_filenameTsz$TestMessageAPI.test_missing_filenamecCs)tjd�}|j|j�d�dS)Nz%Content-Disposition: blarg; filename
r&)rpr�r)rL)r,r.r/r/r0�test_bogus_filenameXs	z"TestMessageAPI.test_bogus_filenamecCs)tjd�}|j|j�d�dS)Nz
From: foo
)rpr�r)rV)r,r.r/r/r0�test_missing_boundary]sz$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
r^zx-headerr{�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)rpr��
get_params)r,r-r.r/r/r0�test_get_paramsas				zTestMessageAPI.test_get_paramscCs0t�}d|d<|j|jd�d�dS)Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"zContent-Type�boundaryZCPIMSSMTPC06p5f3tG)rr)r6)r,r.r/r/r0�test_get_param_liberalrs	
z%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�r^zx-headerr�Zquuzz"X-Header: foo; bar="one"; baz=two
r{r&r�r�)r)rpr�r6)r,r-r.r/r/r0�test_get_paramws			zTestMessageAPI.test_get_paramcCs5|jd�}|j|jd�jd�d�dS)Nz
msg_22.txtrP�namez
wibble.JPG)r*r)r>r6)r,r.r/r/r0�'test_get_param_funky_continuation_lines�sz6TestMessageAPI.test_get_param_funky_continuation_linescCsKtjd�}|j|jd�d�|j|jddd�d�dS)Nz4Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"
r�zJim&amp;&amp;Jill�unquoteFz"Jim&amp;&amp;Jill")rpr�r)r6)r,r.r/r/r0�#test_get_param_with_semis_in_quotes�s
	z2TestMessageAPI.test_get_param_with_semis_in_quotescCsTtjd�}|j|jd�d�tjd�}|j|jd�d�dS)Nz5Content-Type: foo; bar*0="baz\"foobar"; bar*1="\"baz"r�zbaz"foobar"baz)rpr�r)r6)r,r.r/r/r0�test_get_param_with_quotes�s		z)TestMessageAPI.test_get_param_with_quotescCsStjd�}|jd|�|jd|�|jd|�|jd|�dS)NzHeader: existsr^r	ZHEADERZheaderx)rpr�r�ZassertNotIn)r,r.r/r/r0�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)Nr2�iso-2022-jp�
importance�
high valuer�F�"high value"�
text/plainr&�
"iso-2022-jp"ziso-9999-xxr^zX-Jimmy)r�r&)r2r�)r�r�)r�r&)r2r�)r�r�)r)r�	set_paramr6r�)r,r-r.r/r/r0�test_set_param�s		

zTestMessageAPI.test_set_paramcCs�|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�r6�	del_paramr�)r,r-r.Zold_valr/r/r0�test_del_param�s	


zTestMessageAPI.test_del_paramcCsGt�}|jdddd�|jdd�|j|dd�dS)NzContent-Disposition�
attachment�filenamezbud.gifzcontent-disposition)r�
add_headerr�r))r,r.r/r/r0�test_del_param_on_other_header�s	z-TestMessageAPI.test_del_param_on_other_headercCst�}|jdd�dS)Nr�zcontent-disposition)rr�)r,r.r/r/r0�$test_del_param_on_nonexistent_header�s	z3TestMessageAPI.test_del_param_on_nonexistent_headercCsTt�}|jdddd�|d}|jddd�|j|d|�dS)NzContent-Typez
text/plainr2zutf-8�foobarr^)rr�r�r))r,r.Zexisting_headerr/r/r0�test_del_nonexistent_param�s
	
z)TestMessageAPI.test_del_nonexistent_paramcCs�|j}t�}|jt|jd�|jd�||dd�|jdd�||dd�|jd�||dd�dS)	Nrz
text/plainzcontent-typer2zus-asciiztext/plain; charset="us-ascii"z	text/htmlztext/html; charset="us-ascii")r)rr\�
ValueError�set_typer�)r,r-r.r/r/r0�
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.r/r/r0�test_set_type_on_other_header�s	
z,TestMessageAPI.test_set_type_on_other_headercCs#t�}|j|j�d�dS)Nz
text/plain)rr)r5)r,r.r/r/r0�test_get_content_type_missing�s	z,TestMessageAPI.test_get_content_type_missingcCs0t�}|jd�|j|j�d�dS)Nzmessage/rfc822)r�set_default_typer)r5)r,r.r/r/r0�/test_get_content_type_missing_with_default_type�s	
z>TestMessageAPI.test_get_content_type_missing_with_default_typecCs2|jd�}|j|jd�j�d�dS)Nz
msg_30.txtrzmessage/rfc822)r*r)r>r5)r,r.r/r/r0�+test_get_content_type_from_message_implicit�sz:TestMessageAPI.test_get_content_type_from_message_implicitcCs2|jd�}|j|jd�j�d�dS)Nz
msg_28.txtrzmessage/rfc822)r*r)r>r5)r,r.r/r/r0�+test_get_content_type_from_message_explicit�sz:TestMessageAPI.test_get_content_type_from_message_explicitcCs)|jd�}|j|j�d�dS)Nz
msg_03.txtz
text/plain)r*r)r5)r,r.r/r/r0�6test_get_content_type_from_message_text_plain_implicit�szETestMessageAPI.test_get_content_type_from_message_text_plain_implicitcCs)|jd�}|j|j�d�dS)Nz
msg_01.txtz
text/plain)r*r)r5)r,r.r/r/r0�6test_get_content_type_from_message_text_plain_explicitszETestMessageAPI.test_get_content_type_from_message_text_plain_explicitcCs#t�}|j|j�d�dS)Nr)rr)�get_content_maintype)r,r.r/r/r0�!test_get_content_maintype_missings	z0TestMessageAPI.test_get_content_maintype_missingcCs0t�}|jd�|j|j�d�dS)Nzmessage/rfc822�message)rr�r)r�)r,r.r/r/r0�3test_get_content_maintype_missing_with_default_type	s	
zBTestMessageAPI.test_get_content_maintype_missing_with_default_typecCs2|jd�}|j|jd�j�d�dS)Nz
msg_30.txtrr�)r*r)r>r�)r,r.r/r/r0�/test_get_content_maintype_from_message_implicitsz>TestMessageAPI.test_get_content_maintype_from_message_implicitcCs2|jd�}|j|jd�j�d�dS)Nz
msg_28.txtrr�)r*r)r>r�)r,r.r/r/r0�/test_get_content_maintype_from_message_explicitsz>TestMessageAPI.test_get_content_maintype_from_message_explicitcCs)|jd�}|j|j�d�dS)Nz
msg_03.txtr)r*r)r�)r,r.r/r/r0�:test_get_content_maintype_from_message_text_plain_implicitszITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitcCs)|jd�}|j|j�d�dS)Nz
msg_01.txtr)r*r)r�)r,r.r/r/r0�:test_get_content_maintype_from_message_text_plain_explicitszITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitcCs#t�}|j|j�d�dS)N�plain)rr)�get_content_subtype)r,r.r/r/r0� test_get_content_subtype_missings	z/TestMessageAPI.test_get_content_subtype_missingcCs0t�}|jd�|j|j�d�dS)Nzmessage/rfc822�rfc822)rr�r)r�)r,r.r/r/r0�2test_get_content_subtype_missing_with_default_type"s	
zATestMessageAPI.test_get_content_subtype_missing_with_default_typecCs2|jd�}|j|jd�j�d�dS)Nz
msg_30.txtrr�)r*r)r>r�)r,r.r/r/r0�.test_get_content_subtype_from_message_implicit'sz=TestMessageAPI.test_get_content_subtype_from_message_implicitcCs2|jd�}|j|jd�j�d�dS)Nz
msg_28.txtrr�)r*r)r>r�)r,r.r/r/r0�.test_get_content_subtype_from_message_explicit+sz=TestMessageAPI.test_get_content_subtype_from_message_explicitcCs)|jd�}|j|j�d�dS)Nz
msg_03.txtr�)r*r)r�)r,r.r/r/r0�9test_get_content_subtype_from_message_text_plain_implicit/szHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitcCs)|jd�}|j|j�d�dS)Nz
msg_01.txtr�)r*r)r�)r,r.r/r/r0�9test_get_content_subtype_from_message_text_plain_explicit3szHTestMessageAPI.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.r/r/r0�test_get_content_maintype_error7s	
z.TestMessageAPI.test_get_content_maintype_errorcCs-t�}d|d<|j|j�d�dS)Nzno-slash-in-this-stringzContent-Typer�)rr)r�)r,r.r/r/r0�test_get_content_subtype_error<s	
z-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.r/r/r0�test_replace_headerAs		z"TestMessageAPI.test_replace_headercCs�t�}|j|j��|jdddd�|j|j�d�|jdd�|j|j�d�|jdd�|j|j�d�dS)NzContent-Dispositionr�r�z
random.avi�inlineZInlinE)r�assertIsNoneZget_content_dispositionr�r)r�)r,r.r/r/r0�test_get_content_dispositionRs	z+TestMessageAPI.test_get_content_dispositioncCsjd}t�}d|d<d|d<|j|�|j|jdd�d�|j|jd	tj�dS)
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midizcontent-typer<zcontent-transfer-encodingr=Ts����.���p���r)rr:r)r>�assertIsInstance�defectsr�InvalidBase64CharactersDefect)r,�xr.r/r/r0�test_broken_base64_payload^s	


z)TestMessageAPI.test_broken_base64_payloadcCsYd}t�}d|d<d|d<|j|�|j|jdd�t|d��dS)	Nuthis is a bröken thing to doz
text/plainzcontent-typerAzcontent-transfer-encodingr=Tzraw-unicode-escape)rr:r)r>r�)r,r�r.r/r/r0�test_broken_unicode_payloadjs	


z*TestMessageAPI.test_broken_unicode_payloadcCsUdjd�}t�}d|d<d|d<||_|j|jdd�|�dS)	Nu#this is a quéstionable thing to dozutf-8ztext/plain; charset="utf-8"zcontent-typerAzcontent-transfer-encodingr=T)rorZ_payloadr)r>)r,r�r.r/r/r0�test_questionable_bytes_payloadus	

	z.TestMessageAPI.test_questionable_bytes_payloadcCs7t�}|jdddd�|jd|d�dS)NzContent-Dispositionr�r�zbud.gifzattachment; filename="bud.gif")rr�r))r,r.r/r/r0�test_ascii_add_header�s
		z$TestMessageAPI.test_ascii_add_headercCs7t�}|jdddd�|jd|d�dS)NzContent-Dispositionr�r�uFußballer.pptz/attachment; filename*=utf-8''Fu%C3%9Fballer.ppt)rr�r))r,r.r/r/r0�test_noascii_add_header�s	z&TestMessageAPI.test_noascii_add_headercCs7t�}|jdddd�|jd|d�dS)	NzContent-Dispositionr�r��
iso-8859-1r&�Fußballer.pptz1attachment; filename*=iso-8859-1''Fu%DFballer.ppt)r�r&r�)rr�r))r,r.r/r/r0�#test_nonascii_add_header_via_triple�s	z2TestMessageAPI.test_nonascii_add_header_via_triplecCs7t�}|jdddd�|jd|d�dS)NzContent-Dispositionr�r�zwindows [filename].pptz-attachment; filename="windows [filename].ppt")rr�r))r,r.r/r/r0�#test_ascii_add_header_with_tspecial�s	z2TestMessageAPI.test_ascii_add_header_with_tspecialcCs7t�}|jdddd�|jd|d�dS)NzContent-Dispositionr�r�uFußballer [filename].pptz@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt)rr�r))r,r.r/r/r0�&test_nonascii_add_header_with_tspecial�s	z5TestMessageAPI.test_nonascii_add_header_with_tspecialcCsfx_dD]W}t�}d||d<d|d<|jd�|j|jdd	�d
d|�qWdS)
N�latin-1rnztext/plain; charset=%szcontent-typezquoted-printablezcontent-transfer-encodingsfoo=e6=96=87barr=Ts	foo文barz1get_payload returns wrong result with charset %s.)r�rn)rr:r)r>)r,r2r.r/r/r0�test_binary_quopri_payload�s
	

z)TestMessageAPI.test_binary_quopri_payloadcCsfx_dD]W}t�}d||d<d|d<|jd�|j|jdd	�d
d|�qWdS)
N�latin-1rnztext/plain; charset=%szcontent-typer<zcontent-transfer-encodingsZm9v5paHYmFyr=Ts	foo文barz1get_payload returns wrong result with charset %s.)rrn)rr:r)r>)r,r2r.r/r/r0�test_binary_base64_payload�s
	

z)TestMessageAPI.test_binary_base64_payloadcCs�x~dD]v}xmdD]e}t�}d||d<||d	<|jd
�|j|jdd�d
td�j||��qWqWdS)N�latin-1rn�
x-uuencoderxry�x-uueztext/plain; charset=%szcontent-typezcontent-transfer-encodings begin 666 -
)9F]OYI:'8F%R
 
end
r=Ts	foo文bar�!get_payload returns wrong result �"with charset {0} and encoding {1}.)rrn)rrxryr)rr)rr:r)r>r��format)r,r2�encodingr.r/r/r0�test_binary_uuencode_payload�s

	

	z+TestMessageAPI.test_binary_uuencode_payloadcCs7t�}|jdddd�|jd|d�dS)NzContent-Dispositionr�Zfoo_barzinline; foo-bar)rr�r))r,r.r/r/r0�$test_add_header_with_name_only_param�s	z3TestMessageAPI.test_add_header_with_name_only_paramcCs1t�}|jdd�|jd|d�dS)NzX-Statusr&)rr�r))r,r.r/r/r0�test_add_header_with_no_value�s	z,TestMessageAPI.test_add_header_with_no_valuecCs3t�}td�|d<|jtj|j�dS)Nzdummy
X-Injected-Header: test�Dummy)rr	r\rr]rb)r,r.r/r/r0�(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]rb)r,r.r/r/r0�(test_embedded_header_via_string_rejected�s	
z7TestMessageAPI.test_embedded_header_via_string_rejectedcCs9td�}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,�mr/r/r0�-test_unicode_header_defaults_to_utf8_encoding�s
z<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,rr/r/r0�+test_unicode_body_defaults_to_utf8_encoding�sz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)V�__name__�
__module__�__qualname__r1r8r9r;r@rCrDrErHrKrSrTrWr`rcrmrsrvr}r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr	r
rr
rrrr/r/r/r0r(7s�			

	


r(c@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestEncoderscCs|tdd��}|j�}WdQRXtjjj|�}|j�}|jd�}|jt	dd�|D��d�dS)NzPyBanner048.gif�rbr%cSsg|]}t|��qSr/)�len)rMr�r/r/r0rOs	z;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>�L)
r!rdrp�mime�imagerr>r��assertLessEqual�max)r,rhZbindataZmimedZbase64edr�r/r/r0�test_EncodersEncode_base64�sz'TestEncoders.test_EncodersEncode_base64cCs4|j}t�}|jd�||dd�dS)Nzus-asciizcontent-transfer-encoding�7bit)r)rr4)r,r-r.r/r/r0�test_encode_empty_payloads		
z&TestEncoders.test_encode_empty_payloadcCsj|j}td�}||dd�td�}||dd�tddd�}||dd�dS)	Nzhello worldzcontent-transfer-encodingr!uhello ø worldr<�_charsetz
iso-8859-1zquoted-printable)r)r)r,r-r.r/r/r0�test_default_ctes	zTestEncoders.test_default_ctecCsL|j}tddd�}||dd�||j�tjd��dS)Nu文
r#zeuc-jpzcontent-transfer-encodingr!z�            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r)rrbrr)r,r-r.r/r/r0�test_encode7or8bits
	zTestEncoders.test_encode7or8bitcCs5tddd�}|jt|�tjd��dS)Nuáö
rz
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.r/r/r0�test_qp_encode_latin1'sz"TestEncoders.test_qp_encode_latin1cCs5tddd�}|jt|�tjd��dS)Nuż
rz
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.r/r/r0�test_qp_encode_non_latin11sz&TestEncoders.test_qp_encode_non_latin1N)	rrrr r"r$r%r&r'r/r/r/r0r�s	
rc@s�eZdZdZdd�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�TestLongHeadersNcCsQ|j}tjd�}t�}t|�}|j|�||j�d�dS)Nz�Subject: bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text

test
)�ndiffAssertEqualrpr�rrrfrg)r,r-r.�sfpr�r/r/r0�test_split_long_continuationBs			
z,TestLongHeaders.test_split_long_continuationcCsc|j}d}t|dd�}||j�d�t|jdd��}||j�d�dS)Nz�bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text�continuation_ws�	r'z�bug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)r)r	ro�replace)r,r-�hstr�hr/r/r0�,test_another_long_almost_unsplittable_headerVs	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.」と言っています。�header_namera!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?=

�
maxlinelenra	=?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	�appendrrrrfrgro)r,r-r��cz�utf8�g_head�cz_head�	utf8_headr0r.r*r/r/r0�test_long_nonstringgs&		
	

z#TestLongHeaders.test_long_nonstringcCs2|j}tddd�}||j�d�dS)Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r2zX-Foobar-Spoink-Defrobnitzjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r)r	ro)r,r-r0r/r/r0�test_long_header_encode�s
			z'TestLongHeaders.test_long_header_encodecCs8|j}tddddd�}||j�d�dS)Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r2zX-Foobar-Spoink-Defrobnitr,r-zjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r)r	ro)r,r-r0r/r/r0�<test_long_header_encode_with_tab_continuation_is_just_a_hint�s			zLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hintcCs8|j}tddddd�}||j�d�dS)Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r2zX-Foobar-Spoink-Defrobnitr,r-zjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r)r	ro)r,r-r0r/r/r0�-test_long_header_encode_with_tab_continuation�s			z=TestLongHeaders.test_long_header_encode_with_tab_continuationcCs)tdd�}|j|j�d�dS)Nu文zeuc-jpz=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	r)ro)r,r0r/r/r0�0test_header_encode_with_different_output_charset�sz@TestLongHeaders.test_header_encode_with_different_output_charsetcCs8tdjd�d�}d}|j|j�|�dS)Ns6test-ja ����Ƥ��줿�᡼��ϻʲ�Ԥξ�ǧ���ԤäƤ��ޤ�zeuc-jpz�=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r	r=r)ro)r,r0�resr/r/r0�5test_long_header_encode_with_different_output_charset�s	zETestLongHeaders.test_long_header_encode_with_different_output_charsetcCsX|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)rrrrfrg)r,r-r.r*r�r/r/r0�test_header_splitter�s	
	
z$TestLongHeaders.test_header_splittercCs�|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>Nr/)rM�ir/r/r0�	<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:rrrfrg)r,r-r.r*r�r/r/r0�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	ro)r,r-r0r/r/r0�"test_last_split_chunk_does_not_fit�s	z2TestLongHeaders.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	ro)r,r-r0r/r/r0�=test_splittable_leading_char_followed_by_overlong_unsplitable�s	zMTestLongHeaders.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	ro)r,r-r0r/r/r0�Ftest_multiple_splittable_leading_char_followed_by_overlong_unsplitable�s	zVTestLongHeaders.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	ro)r,r-r0r/r/r0�/test_trailing_splitable_on_overlong_unsplitables	z?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	ro)r,r-r0r/r/r0�Ftest_trailing_splitable_on_overlong_unsplitable_with_leading_splitables	zVTestLongHeaders.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	ro)r,r-r0r/r/r0�5test_long_header_with_multiple_sequential_split_charss	zETestLongHeaders.test_long_header_with_multiple_sequential_split_charscCs,|j}td�}||j�d�dS)NzKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points)r)r	ro)r,r-r0r/r/r0�:test_splitter_split_on_punctuation_only_if_fws_with_headers	zJTestLongHeaders.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	ro)r,r-r0r/r/r0�Dtest_leading_splittable_in_the_middle_just_before_overlong_last_part&s	zTTestLongHeaders.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	ro)r,r-r0r/r/r0�/test_overlong_last_part_followed_by_split_point1s	z?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	ro)r,r-r0r/r/r0�@test_multiline_with_overlong_parts_separated_by_two_split_points8s	zPTestLongHeaders.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	ro)r,r-r0r/r/r0�>test_multiline_with_overlong_last_part_followed_by_split_pointCs	zNTestLongHeaders.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>  rDrErFz�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)rrGr�r:rrrfrg)r,r-r.r*r�r/r/r0�%test_long_header_with_whitespace_runsNs		

	
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>rDz; abcrErFz�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)rrGr�r:rrrfrg)r,r-r.r*r�r/r/r0�'test_long_run_with_semi_header_splitter_s		

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

Test)r)rr:rrrfrg)r,r-r.r*r�r/r/r0�.test_splitter_split_on_punctuation_only_if_fwsps		


	
z>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fwscCs]|j}ddd}t|�}||j�d�tdd�}||j�d�dS)NzReferences: r��Pz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r)r	ro)r,r-r/r0r/r/r0�test_no_split_long_header�s	z)TestLongHeaders.test_no_split_long_headercCs8|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,r-a_from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST))r)r	ro)r,r-r/r0r/r/r0�"test_splitting_multiple_long_lines�s
	z2TestLongHeaders.test_splitting_multiple_long_linescCsD|j}d}t|dddddd�}||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 -0400r3�Nr2ZReceivedr,r-z�from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93]
 helo=cthulhu.gerg.ca)
	by kronos.mems-exchange.org with esmtp (Exim 4.05)
	id 17k4h5-00034i-00
	for test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400)r)r	ro)r,r-r/r0r/r/r0�&test_splitting_first_line_only_is_long�s		z6TestLongHeaders.test_splitting_first_line_only_is_longcCs�|j}t�}tdddd�}|jd�||jdd�d�||d<||jd	d�d
�||jd	d�d�dS)
NzBritische Regierung gibtz
iso-8859-1r2ru-grünes Licht für Offshore-Windkraftprojekter3rzl=?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	r4rorb)r,r-r.r0r/r/r0�test_long_8bit_header�s			

z%TestLongHeaders.test_long_8bit_headercCsw|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?=

r2)r)rrbr	)r,r-r.Z
header_stringr/r/r0� 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)rrb)r,r-r�r.r/r/r0�test_long_to_header�s		
z#TestLongHeaders.test_long_to_headercCsE|j}d}t|�}|jd�||jdd�d�dS)NzIThis is an example of string which has almost the limit of header length.zAdd another line.r3rz\This is an example of string which has almost the limit of header length.
 Add another line.)r)r	r4ro)r,r-r�r0r/r/r0�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	r4ro)r,r-r�r0r/r/r0�test_shorter_line_with_append�s	
z-TestLongHeaders.test_shorter_line_with_appendcCsG|j}d}d}t|dd|�}||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-1r2r3ra=?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	ro)r,r-�fnZgsr0r/r/r0�test_long_field_name�s	z$TestLongHeaders.test_long_field_namecCsOd}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,r-z
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)rb)r,r0r.r/r/r0�test_long_received_headers	
z)TestLongHeaders.test_long_received_headercCsUd}t�}t|dddd�|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")r2z
Received-1r,r-z
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)rb)r,r0r.r/r/r0�test_string_headerinst_eq s	

z)TestLongHeaders.test_string_headerinst_eqcCsc|j}t�}d}||d<t|dd�|d<d||d<||jdd�d	�dS)
Nz�iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1r2zFace-2r'zFace-3r]r[a�Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

)r)rr	rb)r,r-r.�tr/r/r0�-test_long_unbreakable_lines_with_continuation3s		
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)rpr�rb)r,r-rr.r/r/r0�"test_another_long_multiline_headerKs
	z2TestLongHeaders.test_another_long_multiline_headercCsU|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>ZListr2r]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	rb)r,r-r0r.r/r/r0�%test_long_lines_with_different_headerXs		
z5TestLongHeaders.test_long_lines_with_different_headercCsLttjd�dddd�}|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 worksr2zutf-8r2rFr%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)ro)r,r0r/r/r0�*test_long_rfc2047_header_with_embedded_fwsks			z:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+rrr�maxDiffr+r1r:r;r<r=r>r@rArIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrYrZr\r^r_r`rarbrdrerfrhrirjrkr/r/r/r0r(>sP6	


					
r(c@sLeZdZdd�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,r/r/r0�setUp|s
	zTestFromMangling.setUpcCsEt�}t|dd�}|j|j�|j|j�d�dS)N�mangle_from_Tz<From: aaa@bbb.org

>From the desk of A.A.A.:
Blah blah blah
)rrrfr.r)rg)r,r�r�r/r/r0�test_mangled_from�s
	z"TestFromMangling.test_mangled_fromcCsEt�}t|dd�}|j|j�|j|j�d�dS)NroFz;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
)rrrfr.r)rg)r,r�r�r/r/r0�test_dont_mangle_from�s
	z&TestFromMangling.test_dont_mangle_fromcCsvt�}t|dd�}tjtjd��}|j|�|jtdd�|j	�j
d�D��d�dS)NroTa)            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
            cSs%g|]}|jd�rd�qS)z>From rP)r�)rMr�r/r/r0rO�s	zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r%rt)rrrpr�rrrfr)rrgr�)r,r�r�r.r/r/r0�'test_mangle_from_in_preamble_and_epilog�s	
+z8TestFromMangling.test_mangle_from_in_preamble_and_epilogcCsqtjd�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
roTs
>From Rölli
)
rrrorp�message_from_bytesrrrfr)rg)r,�sourcer.�br�r/r/r0� test_mangled_from_with_bad_bytes�s	
z1TestFromMangling.test_mangled_from_with_bad_bytesN)rrrrnrprqrrrvr/r/r/r0rm{s
rmc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEAudioc	Cs>tdd��}|j�|_WdQRXt|j�|_dS)Nzaudiotest.aur)r!rd�
_audiodatar�_au)r,rhr/r/r0rn�szTestMIMEAudio.setUpcCs|j|jj�d�dS)Nzaudio/basic)r)ryr5)r,r/r/r0�test_guess_minor_type�sz#TestMIMEAudio.test_guess_minor_typecCs8|jj�}|jtjt|d��|j�dS)Nrn)ryr>r)r<�decodebytesr�rx)r,�payloadr/r/r0�
test_encoding�szTestMIMEAudio.test_encodingcCs,t|jd�}|j|j�d�dS)N�fishz
audio/fish)rrxr)r5)r,Zaur/r/r0�test_checkSetMinor�sz TestMIMEAudio.test_checkSetMinorcCs|j}|jjdddd�||jdd�||jjdd�dd
g�||jjddd�d�g}||jjddd�d�|j|jjd	d
|dd�|�|j|jjd|�|�|j|jjd|dd�|�dS)NzContent-Dispositionr�r��audiotest.auzcontent-dispositionz#attachment; filename="audiotest.au"r^r&r{�failobjr�)r�r&)r�r�)r)ryr�r�r6�assertIs)r,r-�missingr/r/r0�test_add_header�s 	


zTestMIMEAudio.test_add_headerN)rrrrnrzr}rr�r/r/r/r0rw�s
rwc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestMIMEImagec	Cs>tdd��}|j�|_WdQRXt|j�|_dS)NzPyBanner048.gifr)r!rd�_imgdatar�_im)r,rhr/r/r0rn�szTestMIMEImage.setUpcCs|j|jj�d�dS)Nz	image/gif)r)r�r5)r,r/r/r0rz�sz#TestMIMEImage.test_guess_minor_typecCs8|jj�}|jtjt|d��|j�dS)Nrn)r�r>r)r<r{r�r�)r,r|r/r/r0r}�szTestMIMEImage.test_encodingcCs,t|jd�}|j|j�d�dS)Nr~z
image/fish)rr�r)r5)r,Zimr/r/r0r�sz TestMIMEImage.test_checkSetMinorcCs|j}|jjdddd�||jdd�||jjdd�dd
g�||jjddd�d�g}||jjddd�d�|j|jjd	d
|dd�|�|j|jjd|�|�|j|jjd|dd�|�dS)NzContent-Dispositionr�r��dingusfish.gifzcontent-dispositionz%attachment; filename="dingusfish.gif"r^r&r{r�r�)r�r&)r�r�)r)r�r�r�r6r�)r,r-r�r/r/r0r��s 	


zTestMIMEImage.test_add_headerN)rrrrnrzr}rr�r/r/r/r0r��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)rr5)r,r-r.r/r/r0�test_headerss	z TestMIMEApplication.test_headerscCsQ|j}d}t|�}||j�j�d�||jdd�|�dS)Ns������z+vv8/f7/r=T)r)rr>�strip)r,r-�	bytesdatar.r/r/r0�	test_bodys
	zTestMIMEApplication.test_bodycCs�d}t|dtj�}|j|j�dt|��|j|jdd�|�|j|dd�t�}t|�}|j|�|j	�}t
j|�}|j|j�dt|��|j|jdd�|�|j|dd�dS)Ns�������_encoderu�r=TzContent-Transfer-EncodingrA)rr�encode_7or8bitr)r>rrrrfrgrprs)r,r�r.r�r��wireform�msg2r/r/r0�$test_binary_body_with_encode_7or8bit s 	
 z8TestMIMEApplication.test_binary_body_with_encode_7or8bitcCs�d}t|dtj�}|j|j�dt|��|j|jdd�|�t�}t|�}|j|�|j	�}t
j|�}|j|j�dt|��|j|jdd�|�dS)Ns������r�u�r=T)rr�encode_noopr)r>rrrrfrgrprs)r,r�r.r�r�r�r�r/r/r0�!test_binary_body_with_encode_noop1s 	
 z5TestMIMEApplication.test_binary_body_with_encode_noopcCs�d}t|dtj�}|j|jdd�|�t�}t|�}|j|�|j�}t	j
|�}|j|jdd�|�dS)Ns������r�r=T)rrr�r)r>rrrfrgrprs)r,r�r.r�r�r�r�r/r/r0�0test_binary_body_with_unicode_linend_encode_noopBs	
zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopcCs�d}t|dtj�}|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=20r=TzContent-Transfer-Encodingzquoted-printable)rrZ
encode_quoprir)r>rrrfrgrprs)r,r�r.r�r�r�r�r/r/r0�#test_binary_body_with_encode_quopriNs	
z7TestMIMEApplication.test_binary_body_with_encode_quopricCs�d}t|dtj�}|j|j�d�|j|jdd�|�t�}t|�}|j|�|j�}t	j
|�}|j|j�d�|j|jdd�|�dS)Ns������r�z	+vv8/f7/
r=T)rrZ
encode_base64r)r>rrrfrgrprs)r,r�r.r�r�r�r�r/r/r0�#test_binary_body_with_encode_base64^s	
z7TestMIMEApplication.test_binary_body_with_encode_base64N)
rrrr�r�r�r�r�r�r�r/r/r/r0r�sr�c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jd�dd��ZdS)�TestMIMETextcCstd�|_dS)Nzhello there)r�_msg)r,r/r/r0rnnszTestMIMEText.setUpcCs�|j}||jj�d�||jjd�d�g}|j|jjd|�|�|j|jjd|dd�|�dS)Nz
text/plainr2zus-asciir�r^)r)r�r5r6r�)r,r-r�r/r/r0�
test_typesqs	zTestMIMEText.test_typescCs3|j|jj�d�|j|jj��dS)Nzhello there)r)r�r>�assertFalse�is_multipart)r,r/r/r0�test_payloadzszTestMIMEText.test_payloadcCs�|j}tddd�}||j�jd�||dd�td�}d|_tdd|�}||j�jd�||dd�||j�d�dS)Nzhello therer#zus-asciizcontent-typeztext/plain; charset="us-ascii"zutf-8ztext/plain; charset="utf-8")r)rr3r7rrBr>)r,r-r.r2r/r/r0�test_charset~s		zTestMIMEText.test_charsetcCsF|j}tddd�}||j�jd�||dd�dS)Nzhello therer#zus-asciizcontent-typeztext/plain; charset="us-ascii")r)rr3r7)r,r-r.r/r/r0�test_7bit_input�s	zTestMIMEText.test_7bit_inputcCsS|j}td�}||j�d�||dd�|jd|j��dS)Nzhello therezus-asciizcontent-typeztext/plain; charset="us-ascii")r)rr3r�rb)r,r-r.r/r/r0�test_7bit_input_no_charset�s
	z'TestMIMEText.test_7bit_input_no_charsetcCsnd}|j}t|dd�}||j�jd�||dd�||jdd�|jd��dS)Nuкирилицаr#zutf-8zcontent-typeztext/plain; charset="utf-8"r=T)r)rr3Zoutput_charsetr>ro)r,�teststrr-r.r/r/r0�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�r/r/r0�test_utf8_input_no_charset�sz'TestMIMEText.test_utf8_input_no_charsetN)
rrrrnr�r�r�r�r�r��unittest�skipr�r/r/r/r0r�ms	
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%S)&�
TestMultipartcCsQtdd��}|j�}WdQRXtdddd�}t|dd�}|jd	d
dd�td�}|j|�|j|�d
|d<d|d<d|d<d}tj|�}|ddkr�tj	}n	tj
}|dkr�d}	nd}	d|	|df}
tjdtj|��|
|d<||_||_
||_dS)NzPyBanner048.gifr�	multipart�mixedr�rUr�zdingusfish.gifzcontent-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�ArPr�-�+z %s%04d�$z%a, %d %b %Y %H:%M:%SZDate���)r!rdrrr�rrG�time�	localtimeZtimezoneZaltzone�strftimer�r��_txt)r,rhr?�	containerrZintro�nowZ	timetupleZtzsecsZsignZtzoffsetr/r/r0rn�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/mixedrtrrP)
r)r\r�r�r�r5rr>�
IndexErrorr�r�r�r�)r,r-�raisesrZm0�m1r/r/r0�test_hierarchy�s			zTestMultipart.test_hierarchycCs2d}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rer)rb)r,rr.r/r/r0�test_empty_multipart_idempotent�s
z-TestMultipart.test_empty_multipart_idempotentcCsTtdd�}d|d<d|d<d|d<|jd	�|j|j�d
�dS)Nr�r�z	A subjectrzaperson@dom.ainr�zbperson@dom.ainr�rUz�Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY

--BOUNDARY--
)rrYr)rb)r,�outerr/r/r0�/test_no_parts_in_a_multipart_with_none_epilogue�s




z=TestMultipart.test_no_parts_in_a_multipart_with_none_epiloguecCsftdd�}d|d<d|d<d|d<d	|_d	|_|jd
�|j|j�d�dS)Nr�r�z	A subjectrzaperson@dom.ainr�zbperson@dom.ainr�r&rUz�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�epiloguerYr)rb)r,r�r/r/r0�0test_no_parts_in_a_multipart_with_empty_epilogues


		
z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguecCss|j}tdd�}d|d<d|d<d|d<|jd	�td
�}|j|�||j�d�dS)Nr�r�z	A subjectrzaperson@dom.ainr�zbperson@dom.ainr�rUzhello 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)rrYrrGrb)r,r-r�r.r/r/r0�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 worldrUaContent-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�rrGrYrb)r,r-r�r.r/r/r0�1test_seq_parts_in_a_multipart_with_empty_preamble1s	


	

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 worldrUaContent-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�rrGrYrb)r,r-r�r.r/r/r0�0test_seq_parts_in_a_multipart_with_none_preambleMs	


	

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 worldrUaContent-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�rrGrYrb)r,r-r�r.r/r/r0�0test_seq_parts_in_a_multipart_with_none_epiloguehs	


	

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 worldrUaContent-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�rrGrYrb)r,r-r�r.r/r/r0�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 worldrUaContent-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�rrGrYrb)r,r-r�r.r/r/r0�.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�xb|j�D]T}||j�d�|t|j��d�|jd�}||j�d�qyWdS)Nz
msg_36.txtrtrPzmultipart/alternativezmessage/external-bodyrz
text/plain)r)r*rr>r5)r,r-r.�msg1rR�
subsubpartr/r/r0�test_message_external_body�s	z(TestMultipart.test_message_external_bodycCs/|jd�}|jt|j��d�dS)Nz
msg_37.txtru)r*r)rr>)r,r.r/r/r0�test_double_boundary�sz"TestMultipart.test_double_boundarycCsH|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�
_structurerg)r,r-r.r*r/r/r0�)test_nested_inner_contains_outer_boundary�s		z7TestMultipart.test_nested_inner_contains_outer_boundarycCsH|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�rg)r,r-r.r*r/r/r0�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)rb)r,r.r/r/r0�test_boundary_in_non_multipart�sz,TestMultipart.test_boundary_in_non_multipartcCs[|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    XXXXrt)r)rpr�r�r�rVrr>)r,r-r.r/r/r0� test_boundary_with_leading_spaces		z.TestMultipart.test_boundary_with_leading_spacecCs5t�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rer)r>)r,rr/r/r0�&test_boundary_without_trailing_newlines	
	z4TestMultipart.test_boundary_without_trailing_newlineN)rrrrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r/r/r/r0r��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)�TestNonConformantcCsU|j}|jd�}||j�d�||j�d�||j�d�dS)Nz
msg_14.txtz
text/plainrr�)r)r*r5r�r�)r,r-r.r/r/r0�test_parse_missing_minor_type&s
	z/TestNonConformant.test_parse_missing_minor_typecCsk|jd�}|jd�}|jt|d��|jt|j�d�|j|jdtj	�dS)Nz
msg_15.txtrr�rP)
r*r>r��hasattrr)rr�r�r�StartBoundaryNotFoundDefect)r,r.�innerr/r/r0�test_same_boundary_inner_outer.sz0TestNonConformant.test_same_boundary_inner_outercCsv|jd�}|j|j�t�|jt|j�d�|j|jdtj�|j|jdtj	�dS)Nz
msg_25.txtrtrrP)
r*r�r>r�r)rr�r�NoBoundaryInMultipartDefect�!MultipartInvariantViolationDefect)r,r.r/r/r0�test_multipart_no_boundary8s
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==--
        cCsR|j|jjd��}|jt|j�d�|j|jdtj�dS)Nz"
Content-Transfer-Encoding: base64rPr)	�_str_msg�
multipart_msgrr)rr�r�rZ-InvalidMultipartContentTransferEncodingDefect)r,r.r/r/r0�test_multipart_invalid_cteYs
z,TestNonConformant.test_multipart_invalid_ctecCs8|j|jjd��}|jt|j�d�dS)Nr&r)r�r�rr)rr�)r,r.r/r/r0�test_multipart_no_cte_no_defectasz1TestNonConformant.test_multipart_no_cte_no_defectcCsRxKdD]C}|j|jjdj|���}|jt|j�d�qWdS)Nr!rA�BINaryz
Content-Transfer-Encoding: {}r)r!rAr�)r�r�rr)rr�)r,r|r.r/r/r0�"test_multipart_valid_cte_no_defectfs

	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)NrzContent-Typer�z
text/plainzcontent-typer{zContent-Type: foo

)
r)r)rr�r�r5rrrfrg)r,r-�neqr.r�r�r/r/r0�test_invalid_content_typens 			

	
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.r/r/r0�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*rb)r,r-r.r/r/r0�test_no_separating_blank_line�s	z/TestNonConformant.test_no_separating_blank_linecCsv|jd�}|jt|d��|jt|j�d�|j|jdtj�|j|jdtj	�dS)Nz
msg_41.txtr�rtrrP)
r*r�r�r)rr�r�rr�r�)r,r.r/r/r0�test_lying_multipart�s
z&TestNonConformant.test_lying_multipartcCs^|jd�}|jd�jd�}|jt|j�d�|j|jdtj�dS)Nz
msg_42.txtrPr)r*r>r)rr�r�rr�)r,r�Zbadr/r/r0�test_missing_start_boundary�s
	z-TestNonConformant.test_missing_start_boundarycCs�|j}d}tj|�}||j�dg�||j�d�|t|j�d�|j|jtj	g�||jdj
d�dS)Nz Line 1
Subject: test

bodyr�bodyrPrz Line 1
)r)rpr�r�r>rr��assertDefectsEqualrZ#FirstHeaderLineIsContinuationDefect�line)r,r-rr.r/r/r0�&test_first_line_is_continuation_header�s	
z8TestNonConformant.test_first_line_is_continuation_headercCs[|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.r/r/r0�"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�r/r/r/r0r�$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)"�TestRFC2047cCss|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åsr3rziRe: =?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)ro)r,r-r��dhr^r/r/r0�test_rfc2047_multiline�s	
z"TestRFC2047.test_rfc2047_multilinecCsQ|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^r/r/r0�test_whitespace_keeper_unicode�s		
z*TestRFC2047.test_whitespace_keeper_unicodecCsW|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�Zhur/r/r0� test_whitespace_keeper_unicode_2�s	
z,TestRFC2047.test_whitespace_keeper_unicode_2cCs5d}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)r�N)r�r�)r�N)r�r�)r�N)r
r))r,r�r�r/r/r0�test_rfc2047_missing_whitespace�s
z+TestRFC2047.test_rfc2047_missing_whitespacecCs5d}t|�}|j|dd	d
ddg�dS)
Nz7Sm =?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�r/r/r0�test_rfc2047_with_whitespace�s
z(TestRFC2047.test_rfc2047_with_whitespacecCs_d}d
ddd
dg}x=|D]5\}}t||�}|j||d	fg�q"WdS)Nz=?iso-8859-1?B?%s?=�dm==�v�dm=�dm�dmk=�vi�dmkz
iso-8859-1)rr)r	r)r
r)rr)r
r)r
r))r,r�r?�q�ar�r/r/r0�test_rfc2047_B_bad_padding	s	z&TestRFC2047.test_rfc2047_B_bad_paddingcCs#d}|jt|�dg�dS)Nz=?iso-8859-1?Q?andr=e9=zz?=�andr�=zz�
iso-8859-1)rr)r)r
)r,r�r/r/r0�test_rfc2047_Q_invalid_digits	sz)TestRFC2047.test_rfc2047_Q_invalid_digitscCs)d}|jt|�dddg�dS)	Nz(=?ISO-8859-1?Q?a?=)�(�a�
iso-8859-1�))rN)rr)rN)r)r
)r,r�r/r/r0�test_rfc2047_rfc2047_1	sz"TestRFC2047.test_rfc2047_rfc2047_1cCs)d}|jt|�dddg�dS)	Nz(=?ISO-8859-1?Q?a?= b)rr�
iso-8859-1� b))rN)rr)rN)r)r
)r,r�r/r/r0�test_rfc2047_rfc2047_2	sz"TestRFC2047.test_rfc2047_rfc2047_2cCs)d}|jt|�dddg�dS)	Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)r�ab�
iso-8859-1r)rN)rr)rN)r)r
)r,r�r/r/r0�test_rfc2047_rfc2047_3!	sz"TestRFC2047.test_rfc2047_rfc2047_3cCs)d}|jt|�dddg�dS)	Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r�ab�
iso-8859-1r)rN)rr )rN)r)r
)r,r�r/r/r0�test_rfc2047_rfc2047_4'	sz"TestRFC2047.test_rfc2047_rfc2047_4cCs)d}|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�r/r/r0�test_rfc2047_rfc2047_5a-	sz#TestRFC2047.test_rfc2047_rfc2047_5acCs)d}|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�r/r/r0�test_rfc2047_rfc2047_5b3	sz#TestRFC2047.test_rfc2047_rfc2047_5bcCs)d}|jt|�dddg�dS)	Nz(=?ISO-8859-1?Q?a_b?=)r�a b�
iso-8859-1r)rN)r(r))rN)r)r
)r,r�r/r/r0�test_rfc2047_rfc2047_69	sz"TestRFC2047.test_rfc2047_rfc2047_6cCsvd}|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)rr+)r,r-)rN)r)r
rror[r�)r,r�r/r/r0�test_rfc2047_rfc2047_7?	s	
(z"TestRFC2047.test_rfc2047_rfc2047_7cCsyd}|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>)r/r0)r1N)r)r
rror��
splitlinesr�)r,r�r/r/r0�test_multiline_headerH	s
z!TestRFC2047.test_multiline_headerN)rrrr�r�r�r�rrrrrrr!r$r'r*r.r3r/r/r/r0r��s 		
	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�TestMIMEMessagec	Cs)td��}|j�|_WdQRXdS)Nz
msg_11.txt)r!rdZ_text)r,rhr/r/r0rnU	szTestMIMEMessage.setUpcCs|jttd�dS)Nza plain string)r\rFr)r,r/r/r0�test_type_errorY	szTestMIMEMessage.test_type_errorcCs�|j}d}t�}||d<t|�}||j�d�|j�}|j|t�|t|�d�|d}|j||�||d|�dS)Nz
A sub-messagerzmessage/rfc822rPr�subject)	r)rrr5r>r��listrr�)r,r-r6r�rr|rRr/r/r0�test_valid_argument\	s		

z#TestMIMEMessage.test_valid_argumentcCsOt�}d|d<t�}d|d<t|�}|jtj|j|�dS)Nz	subpart 1rz	subpart 2)rrr\rZMultipartConversionErrorrG)r,r�r�r8r/r/r0�test_bad_multipartj	s	
	
z"TestMIMEMessage.test_bad_multipartcCsrt�}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:rrrrfr)rg)r,rr8r�r�r/r/r0�
test_generater	s	


	
zTestMIMEMessage.test_generatecCs�|j}|jd�}||j�d�|j�}|j|t�|t|�d�|d}|j|t�||dd�||j�d�dS)Nz
msg_11.txtzmessage/rfc822rPrr6zAn enclosed messagez!Here is the body of the message.
)r)r*r5r>r�r7rr)r,r-r.r|Zsubmsgr/r/r0�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
d
d�ddg�||j	dd
d�d�|jd	�}||j�d�|j�}|j|t�|t|�d�|d}|j|t�||j�d�||dd�dS)Nz
msg_16.txtzmultipart/reportrurz
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

rPzmessage/delivery-statusrtzoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnsr^z
reporting-mtar&Znsd�actionZfailedzoriginal-recipientr��jangel1@cougar.noc.ucla.eduzfinal-recipientzmessage/rfc822z
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r�r&)r>r&)r)r*r5r�r�rr>r�rr6r�r7)r,r-r.rRZdsn1Zdsn2r|r�r/r/r0�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�rFrzMIME messagezEnd of MIME message
r�r�zContent-Typezmultipart/mixedr�rU)
r)r!rdrr�r�rr�rGrrrfrg)	r,r-rhrr.r�r�r*r�r/r/r0�
test_epilogue�	s$		


		

	
zTestMIMEMessage.test_epiloguecCs�|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�rFrzMIME messager&r�r�zContent-Typezmultipart/mixedr�rUadFrom: 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�rGrb)r,r-r.r�r�r/r/r0�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/rfc822rPz
text/plain)r)r!rp�message_from_filer>�get_default_typer5)r,r-rhr.�
container1�
container2�container1a�container2ar/r/r0�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/rfc822rPz
text/plain)r)r!rprBr>rCr5)r,r-rhr.rDrErFrGr/r/r0�.test_default_type_with_explicit_container_type
s	z>TestMIMEMessage.test_default_type_with_explicit_container_typecCsX|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)NZdigestrUr&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�rrrGr5rCrb)r,r-r�r�Z	subpart1aZ	subpart2aZsubpart1Zsubpart2r/r/r0�test_default_type_non_parsed$
s4			

z,TestMIMEMessage.test_default_type_non_parsedcCs|j}td�}td�}td||f�}|t|j��d�||jd�|�||jd�|�dS)Nr&Z	_subpartsrtrrP)r)rrrr>)r,r-Ztext1Ztext2r.r/r/r0�$test_mime_attachments_in_constructorn
s	z4TestMIMEMessage.test_mime_attachments_in_constructorcCs t�}|j|j��dS)N)rr�r�)r,r.r/r/r0�"test_default_multipart_constructorw
s	z2TestMIMEMessage.test_default_multipart_constructorN)rrrrnr5r9r:r;r<r?r@rArHrIrJrKrLr/r/r/r0r4T	s9#J	r4c@s9eZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)4�TestIdempotentr%c	Cs;t|��}|j�}WdQRXtj|�}||fS)N)r!rdrpr�)r,r�rhr?r.r/r/r0r*�
szTestIdempotent._msgobjFcCsN|j}t�}t|dd�}|j|d|�|||j��dS)Nr]rr�)r)rrrfrg)r,r.rr�r-r�r�r/r/r0�_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/plainrr�rPr2�us-ascii)r2rO)
r)r*r5r�r�r�r6r�r�rN)r,r-r.rr/r/r0�test_parse_text_message�
s	z&TestIdempotent.test_parse_text_messagecCsn|j}|jd�\}}||j�d�||j�d�||jd�d�|j||�dS)Nz
msg_03.txtz
text/plainr2)r)r*r5r�r6rN)r,r-r.rr/r/r0�test_parse_untyped_message�
s	z)TestIdempotent.test_parse_untyped_messagecCs)|jd�\}}|j||�dS)Nz
msg_04.txt)r*rN)r,r.rr/r/r0�test_simple_multipart�
sz$TestIdempotent.test_simple_multipartcCs)|jd�\}}|j||�dS)Nz
msg_02.txt)r*rN)r,r.rr/r/r0�test_MIME_digest�
szTestIdempotent.test_MIME_digestcCs)|jd�\}}|j||�dS)Nz
msg_27.txt)r*rN)r,r.rr/r/r0�test_long_header�
szTestIdempotent.test_long_headercCs)|jd�\}}|j||�dS)Nz
msg_28.txt)r*rN)r,r.rr/r/r0�"test_MIME_digest_with_part_headers�
sz1TestIdempotent.test_MIME_digest_with_part_headerscCs)|jd�\}}|j||�dS)Nz
msg_06.txt)r*rN)r,r.rr/r/r0�test_mixed_with_image�
sz$TestIdempotent.test_mixed_with_imagecCs)|jd�\}}|j||�dS)Nz
msg_05.txt)r*rN)r,r.rr/r/r0�test_multipart_report�
sz$TestIdempotent.test_multipart_reportcCs)|jd�\}}|j||�dS)Nz
msg_16.txt)r*rN)r,r.rr/r/r0r?�
szTestIdempotent.test_dsncCs)|jd�\}}|j||�dS)Nz
msg_21.txt)r*rN)r,r.rr/r/r0�test_preamble_epilogue�
sz%TestIdempotent.test_preamble_epiloguecCs)|jd�\}}|j||�dS)Nz
msg_23.txt)r*rN)r,r.rr/r/r0�test_multipart_one_part�
sz&TestIdempotent.test_multipart_one_partcCs)|jd�\}}|j||�dS)Nz
msg_24.txt)r*rN)r,r.rr/r/r0�test_multipart_no_parts�
sz&TestIdempotent.test_multipart_no_partscCs)|jd�\}}|j||�dS)Nz
msg_31.txt)r*rN)r,r.rr/r/r0r��
sz%TestIdempotent.test_no_start_boundarycCs)|jd�\}}|j||�dS)Nz
msg_32.txt)r*rN)r,r.rr/r/r0�test_rfc2231_charset�
sz#TestIdempotent.test_rfc2231_charsetcCs)|jd�\}}|j||�dS)Nz
msg_33.txt)r*rN)r,r.rr/r/r0�test_more_rfc2231_parameters�
sz+TestIdempotent.test_more_rfc2231_parameterscCs)|jd�\}}|j||�dS)Nz
msg_34.txt)r*rN)r,r.rr/r/r0�%test_text_plain_in_a_multipart_digest�
sz4TestIdempotent.test_text_plain_in_a_multipart_digestcCs)|jd�\}}|j||�dS)Nzmsg_12a.txt)r*rN)r,r.rr/r/r0�test_nested_multipart_mixeds�
sz+TestIdempotent.test_nested_multipart_mixedscCs)|jd�\}}|j||�dS)Nz
msg_36.txt)r*rN)r,r.rr/r/r0�%test_message_external_body_idempotent�
sz4TestIdempotent.test_message_external_body_idempotentcCs/|jd�\}}|j||dd�dS)Nz
msg_43.txtr�T)r*rN)r,r.rr/r/r0�test_message_delivery_status�
sz+TestIdempotent.test_message_delivery_statuscCs)|jd�\}}|j||�dS)Nz
msg_45.txt)r*rN)r,r.rr/r/r0�test_message_signed_idempotent�
sz-TestIdempotent.test_message_signed_idempotentcCs�|j}|jd�\}}||j�d�i}x$|j�D]\}}|||<qDW||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.rurz
text/plainzYadda yadda yaddarPrtzmessage/rfc822)r)r*r5r�r�r�r�rr>r�rr7)r,r-r.rZparamsZpkZpvr�r�Zmsg3r|Zmsg4r/r/r0�test_content_type�
s4	
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/rfc822rPrz
text/plain)
r)r*r5r>r�r7rrr�r�)r,r-r.rr|r�r/r/r0�test_parser
s	
zTestIdempotent.test_parserN)rrrr�r*rNrPrQrRrSrTrUrVrWr?rXrYrZr�r[r\r]r^r_r`rarbrcr/r/r/r0rM�
s2rMc@sheZdZdd�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�Z4deS)f�TestMiscellaneouscCsstd��}|j�}WdQRXtj|�}t�}t|dd�}|j|�|j||j��dS)Nz
msg_01.txtr]r)	r!rdrpr�rrrfr)rg)r,rhrr.r�r�r/r/r0�test_message_from_string!s	
z*TestMiscellaneous.test_message_from_stringcCs�td��m}|j�}|jd�tj|�}t�}t|dd�}|j|�|j||j	��WdQRXdS)Nz
msg_01.txtrr])
r!rd�seekrprBrrrfr)rg)r,rhrr.r�r�r/r/r0�test_message_from_file,s
	
z(TestMiscellaneous.test_message_from_filecCs�td��}|j�}WdQRXGdd�dt�}tj||�}|j||�td��}|j�}WdQRXtj||�}x$|j�D]}|j||�q�WdS)Nz
msg_01.txtc@seZdZdS)zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN)rrrr/r/r/r0�	MyMessage=srhz
msg_02.txt)r!rdrrpr�r��walk)r,rhrrhr.rRr/r/r0�#test_message_from_string_with_class8sz5TestMiscellaneous.test_message_from_string_with_classcCs�Gdd�dt�}td��}tj||�}WdQRX|j||�td��}tj||�}WdQRXx$|j�D]}|j||�q�WdS)Nc@seZdZdS)zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageN)rrrr/r/r/r0rhKsrhz
msg_01.txtz
msg_02.txt)rr!rprBr�ri)r,rhrhr.rRr/r/r0�!test_message_from_file_with_classIsz3TestMiscellaneous.test_message_from_file_with_classcCs<Gdd�dt�}|jd|�}|j||�dS)Ncs"eZdZ�fdd�Z�S)zSTestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessagecst�j�dS)N)�super�__init__)r,)�	__class__r/r0rmYsz\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)rrrrmr/r/)rnr0rhXsrhzSubject: test

test)rr�r�)r,rhr.r/r/r0�.test_custom_message_does_not_require_argumentsWsz@TestMiscellaneous.test_custom_message_does_not_require_argumentscCs\td�}|jt|j�dddddddd	d
ddd
dddddg�dS)Nrprr2rr�
feedparserrrr^rr�Zmessage_from_binary_filersrBr�rrjrr)�
__import__r)�sorted�__all__)r,�moduler/r/r0�test__all__^szTestMiscellaneous.test__all__cCsOtj�}|jtjtj|��dd�tj|�dd��dS)N�)r�r)r�	parsedate�
formatdate�gmtime)r,r�r/r/r0�test_formatdatehs%z!TestMiscellaneous.test_formatdatecCsUtj�}|jtjtj|dd��dd�tj|�dd��dS)Nr�Trv)r�r)rrwrxr�)r,r�r/r/r0�test_formatdate_localtimems%z+TestMiscellaneous.test_formatdate_localtimecCs~tj�}|jtj|dd�tjdtj|���|jtj|dddd�tjdtj|���dS)Nr�Fz%a, %d %b %Y %H:%M:%S -0000ZusegmtTz%a, %d %b %Y %H:%M:%S GMT)r�r)rrxr�ry)r,r�r/r/r0�test_formatdate_usegmtssz(TestMiscellaneous.test_formatdate_usegmtcCs�|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��dS)Nr&�0zA Complete Waste of Time)r�rrw�parsedate_tz)r,r/r/r0�/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)rrw)r,r/r/r0�test_parsedate_compact�sz(TestMiscellaneous.test_parsedate_compactcCs#|j}|tjd�d
�dS)Nz25 Feb 2003 13:47:26 -0800��rt��
�/�rrPi�pr�透��)
r�rtr�r�r�r�rrPr�r�)r)rr~)r,r-r/r/r0�test_parsedate_no_dayofweek�s	z-TestMiscellaneous.test_parsedate_no_dayofweekcCs#|j}|tjd�d
�dS)Nz5 Feb 2003 13:47:26 -0800��rt�r�r�r�rrPi�pr�透��)
r�rtr�r�r�r�rrPr�r�)r)rr~)r,r-r/r/r0�#test_parsedate_compact_no_dayofweek�s	z5TestMiscellaneous.test_parsedate_compact_no_dayofweekcCs|jtjd�d�dS)
NzWed, 3 Apr 2002 14:58:26+0800��rXru��:r�rrP�pr�)
r�rXrur�r�r�rrPr�r�)r)rr~)r,r/r/r0�.test_parsedate_no_space_before_positive_offset�sz@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetcCs|jtjd�d
�dS)NzWed, 3 Apr 2002 14:58:26-0800��rXrur�r�r�rrPi�pr�透��)
r�rXrur�r�r�rrPr�r�)r)rr~)r,r/r/r0�.test_parsedate_no_space_before_negative_offset�sz@TestMiscellaneous.test_parsedate_no_space_before_negative_offsetcCs9|j}|tjd�d�|tjd�d�dS)Nz5 Feb 2003 13.47.26 -0800��rtr�r�r�r�rrPi�pz5 Feb 2003 13.47 -0800r�透��)
r�rtr�r�r�r�rrPr�r�r�透��)
r�rtr�r�r�rrrPr�r�)r)rr~)r,r-r/r/r0�%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 -0800rvz%Yi��	)	r)rrw�intr�Zmktimer�r�r~)r,r-Ztimetuprgr/r/r0�+test_parsedate_acceptable_to_time_functions�s	**z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionscCs6|jtjd�d�|jtjd�d
�dS)N�rPr��r�r�r�)
r�rPrPrrrr�r�r�rr�r�r�)
r�rPrPrrrr�r�r�r�i.���)r)rZ	mktime_tz)r,r/r/r0�test_mktime_tz�s
z TestMiscellaneous.test_mktime_tzcCsH|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,r/r/r0�test_parsedate_y2k�sz$TestMiscellaneous.test_parsedate_y2kcCs?|jtjd�d�|jtjtjd��d�dS)Nz<>r&)r&r&)r)r�	parseaddr�
formataddr)r,r/r/r0�test_parseaddr_empty�sz&TestMiscellaneous.test_parseaddr_emptycCsO|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,r/r/r0�test_parseaddr_multiple_domains�sz1TestMiscellaneous.test_parseaddr_multiple_domainscCs|jtjd�d�dS)N�A Silly Person�person@dom.ainzA Silly Person <person@dom.ain>)r�r�)r)rr�)r,r/r/r0�test_noquote_dump�sz#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,rrur/r/r0�test_escape_dump�sz"TestMiscellaneous.test_escape_dumpcCsW|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,rrur/r/r0�test_escape_backslashes�sz)TestMiscellaneous.test_escape_backslashescCs]d}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_quoprir/r/r0�test_quotes_unicode_names�sz+TestMiscellaneous.test_quotes_unicode_namescs�d}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>ZFOOBARcs"eZdZ�fdd�ZdS)zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockcs�S)Nr/)r,�string)r�r/r0�
header_encodeszYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)rrrr�r/)r�r/r0�CharsetMocksr�z%s <%s>zutf-8)r)rr�r)r,r�r�r�r�ZmockZ
mock_expectedr/)r�r0�$test_accepts_any_charset_like_object�s	"!z6TestMiscellaneous.test_accepts_any_charset_like_objectcCs8d}d}t�}|jttj||f|�dS)NuHäns Würstzperson@dom.ain)�objectr\�AttributeErrorrr�)r,r�r�Zbad_charsetr/r/r0�-test_invalid_charset_like_object_raises_error	s
	z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorcCsBd}|jttjd|f�|jttjd|f�dS)Nupersön@dom.in�Name)r\�UnicodeErrorrr�)r,r�r/r/r0�!test_unicode_address_raises_errorsz3TestMiscellaneous.test_unicode_address_raises_errorcCsyd}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��yrrur/r/r0�test_name_with_dotsz$TestMiscellaneous.test_name_with_dotcCsO|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-r/r/r0�2test_parseaddr_preserves_quoted_pairs_in_addresses!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,r/r/r0�-test_parseaddr_preserves_spaces_in_local_part3s					z?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_partcCsBd}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�Zaddrstrr/r/r0�6test_formataddr_does_not_quote_parens_in_quoted_stringEs
zHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_stringcCs#d}|jtj|�d�dS)NzFoo
	Bar <foo@example.com>�Foo Bar�foo@example.com)r�r�)r)rr�)r,r�r/r/r0�test_multiline_from_commentN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,r/r/r0�test_quote_dumpTsz!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-�neZcset1Zcset2r/r/r0�test_charset_richcomparisonsY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-r/r/r0�test_getaddressesms
		z#TestMiscellaneous.test_getaddressescCsm|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-r/r/r0�test_getaddresses_nastyts				z)TestMiscellaneous.test_getaddresses_nastycCs4|j}tjdg�}||ddd�dS)z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>rrPzfoo@bar.comN)r)rr�)r,r-Zaddrsr/r/r0�"test_getaddresses_embedded_comment~s	z4TestMiscellaneous.test_getaddresses_embedded_commentcs�Gdd�dt���fdd�td�D�}t|��WdQRXtdd�|D�g�}|jtt|��t|��dS)Nc@seZdZdd�ZdS)zBTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadcSsag|_|jj}tj}tj}|�d}x&|�|kr\||dd��q7WdS)Ng@�domainztestdomain-string)�msgidsr4r�
make_msgidr�Z	monotonic)r,r4r�ZclockZtfinr/r/r0�run�s			
zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)rrrr�r/r/r/r0�MsgidsThread�sr�csg|]}���qSr/r/)rMrB)r�r/r0rO�s	z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>r�cSsg|]}|j�qSr/)r�)rMrgr/r/r0rO�s	)rrHr �sumr)r�set)r,ZthreadsZall_idsr/)r�r0�test_make_msgid_collisions�s
z,TestMiscellaneous.test_make_msgid_collisionscCs?|j}t�}|jdddd�||j�d�dS)Nzcontent-dispositionr�r�zfoo\wacky"name)r)rr�rL)r,r-r.r/r/r0�test_utils_quote_unquote�s
		z*TestMiscellaneous.test_utils_quote_unquotecCs&td�}|j|j�d�dS)Nz
not a charsetr<)rr)�get_body_encoding)r,r2r/r/r0�)test_get_body_encoding_with_bogus_charset�sz;TestMiscellaneous.test_get_body_encoding_with_bogus_charsetcCst|j}t�}d|d<||dd�|j�}|t|�d�||dd�t|d�}||j�d�|jdd	|�||j�d
�||jdd�d�||d
d�t�}d|d<|j�}|t|�d�||dd�t|d�}||j�tj	�|jdd	|�||j�d�||d
d�dS)Nztext/plain; charset=UTF-8zContent-Typezcontent-typerPrzutf-8r<shello worldr2zaGVsbG8gd29ybGQ=
r=Tzcontent-transfer-encodingztext/plain; charset="US-ASCII"zus-asciizhello worldr!)
r)rrIrrr�r:r>rr�)r,r-r.rJr2r/r/r0�-test_get_body_encoding_with_uppercase_charset�s.		
	
z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetcCs8td�}td�}|j|j�|j��dS)Nzus-asciizUS-ASCII)rr)r�)r,ZlcZucr/r/r0�test_charsets_case_insensitive�sz0TestMiscellaneous.test_charsets_case_insensitivecCsH|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�rg)r,r-r.r*r/r/r0�1test_partial_falls_inside_message_delivery_status�s		zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuscCs-|jtjjdd�dd�d�dS)Nr�ztestdomain-string�z@testdomain-string>i��)r)rprr�)r,r/r/r0�test_make_msgid_domain�sz(TestMiscellaneous.test_make_msgid_domaincCs3|jtjjdddd�dd�d�dS)NZidstringz
test-idstringr�ztestdomain-stringraz!.test-idstring@testdomain-string>i���)r)rprr�)r,r/r/r0�test_make_msgid_idstring�sz*TestMiscellaneous.test_make_msgid_idstringcCs.|jtjj�jdt�d��dS)N�@�>)r�rprr��endswithr)r,r/r/r0�test_make_msgid_default_domain�sz0TestMiscellaneous.test_make_msgid_default_domainc
Cs�tddd��}|j�}WdQRX|jdd�}tj|�}t�}tjj|�}|j|�|j	|j
�|�dS)Nz
msg_26.txt�newliner%z
)r!rdr.rpr�rrrrrfr)rg)r,�f�msgtxt�	msgtxt_nlr.r�r�r/r/r0�test_Generator_linend�s	
z'TestMiscellaneous.test_Generator_linendcCs�tddd��}|j�}WdQRX|jdd�}tj|�}t�}tjj|�}|j|dd�|j	|j
�jd�|�dS)Nz
msg_26.txtr�r%z
r�rn)r!rdr.rpr�rrrrrfr)rgr=)r,r�r�r�r.r�r�r/r/r0�test_BytesGenerator_linend
s	z,TestMiscellaneous.test_BytesGenerator_linendcCs�tdd��}|j�}WdQRX|jdd�}|jdd�}tj|�}t�}tjj|�}|j|dd�|j	|j
�|�dS)	Nz
msg_26.txtrswith attachmentsfo�s
s
r�z
)r!rdr.rprsrrrrrfr)rg)r,r�r�r�r.r�r�r/r/r0�)test_BytesGenerator_linend_with_non_ascii
s	z;TestMiscellaneous.test_BytesGenerator_linend_with_non_asciiN)5rrrrergrjrkrorurzr{r|rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r/r/r/r0rd sd



			
*rdc@sLeZdZdd�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.txtrvz
msg_02.txt�+z
msg_19.txt)r)r)r*rZbody_line_iteratorr7r�EMPTYSTRINGr�r>r!rd)r,r-r�r.�itr�rhr/r/r0�test_body_line_iterator 
s		z%TestIterators.test_body_line_iteratorcCs�|j}|jd�}tj|d�}g}d}x+|D]#}|d7}|j|j��q=W||d�|tj|�d�dS)Nz
msg_04.txtrrrPrtz`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_iteratorr4r>r�r�)r,r-r.r�r��subpartsrRr/r/r0�test_typed_subpart_iterator1
s	


z)TestIterators.test_typed_subpart_iteratorcCs�|j}|jd�}tj|dd�}g}d}x+|D]#}|d7}|j|j��q@W||d�|tj|�d�dS)Nz
msg_03.txtrr�rrPz%
Hi,

Do you like this message?

-Me
)r)r*rr�r4r>r�r�)r,r-r.r�r�r�rRr/r/r0�(test_typed_subpart_iterator_default_typeB
s	


z6TestIterators.test_typed_subpart_iterator_default_typec	Cs
ddddddddg}ddlm}m}|�}g}d}xu|D]m\}}|j|�||7}d}	x1t|j|�D]}
|j|
�|	d7}	q�W|j||	�qPW|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
 
rtrur�c
rPr&�d
�e
�
f�
)�BufferedSubFile�NeedMoreDatacSsg|]\}}|�qSr/r/)rM�il�nr/r/r0rOq
s	z0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)rrt)rur)rrP)r&r)rrP)rr)rrP)rrP)
�email.feedparserrr�push�iter�readliner4r)rr�)r,Zimtrr�bsfZom�ntr	r
Zn1Zolr/r/r0�test_pushCR_LFU
s,		


zTestIterators.test_pushCR_LFcs�ddlm}m}d}d}d�dj�fdd�t|�D��d	}|jd
�}|�}g}xZtdt|�|�D]@}	||	|	|�}
|j|
�|jt	|j
|��q�W|j||�dS)Nr)rri'r�zabcd 	
r&c3s|]}t��VqdS)N)r)rMrB)�charsr/r0rCz
sz1TestIterators.test_push_random.<locals>.<genexpr>r%T)rrrr�rHr2rr�extendr
rr))r,rrr
Z	chunksizer��targetrr�rB�chunkr/)rr0�test_push_randoms
s,	
zTestIterators.test_push_randomN)rrrr�r�rrrr/r/r/r0r�
s
r�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFeedParserscCsAddlm}|�}x|D]}|j|�q W|j�S)Nr)r#)rr#�feed�close)r,�chunksr#rprr/r/r0�parse�
s
	
zTestFeedParsers.parsecCs;|jd�}|j|dd�|j|dd�dS)NzFirst: val
: bad
Second: valr��valr�)rr))r,r.r/r/r0�test_empty_header_name_handled�
sz.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:
rru�c�dza:
b:
c:
d:za:
bzc:
Zbcza:
zb:
z
b:
ua:…b:
c:
�	…b:
c:ub:…r&�…c:)rr )rr&)rur!)rr)r�rZ)r,rr/r/r0�
test_newlines�
s""zTestFeedParsers.test_newlinescCsnd\}}|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�rruza:b

�…za:
zb: r&)r#r$)rru)rru)rru)rr&)rr)rZr>)r,�M�Nrr/r/r0�test_long_lines�
s!!%"$zTestFeedParsers.test_long_linesN)rrrrrr"r(r/r/r/r0r�
src@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdZ
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�TestParsersc
Cs�|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
rr5r�r�r�r>r�)r,r-rhr.r/r/r0�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/mixedr=T)
r)r!rprjrqrr5r�r�r�r>r�r�)r,r-rhr.r/r/r0�test_bytes_header_parser�
s	z$TestParsers.test_bytes_header_parserc	CsCtdd��-}tjj�j|�|j|j�WdQRXdS)Nz
msg_02.txtr)r!rprj�BytesParserrr��closed)r,rhr/r/r0�%test_bytes_parser_does_not_close_file�
sz1TestParsers.test_bytes_parser_does_not_close_filecCsdtdd��N}tjj}|jtjj|dtjj�j	|�|j
|j�WdQRXdS)Nz
msg_15.txtrr�)r!rprjr,r\rr�r��strictrr�r-)r,rhZbytesParserr/r/r0�2test_bytes_parser_on_exception_does_not_close_file�
sz>TestParsers.test_bytes_parser_on_exception_does_not_close_filec	CsCtdd��-}tjj�j|�|j|j�WdQRXdS)Nz
msg_02.txtr8)r!rprjrrr�r-)r,rhr/r/r0�test_parser_does_not_close_file�
sz+TestParsers.test_parser_does_not_close_filecCsdtdd��N}tjj}|jtjj|dtjj�j	|�|j
|j�WdQRXdS)Nz
msg_15.txtr8r�)r!rprjrr\rr�r�r/rr�r-)r,rhrjr/r/r0�,test_parser_on_exception_does_not_close_file�
s
z8TestParsers.test_parser_on_exception_does_not_close_filecCsQ|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
r6z!the next line has a space on it
 z
message-id�spamzHere's the message body
)r)rpr�r>)r,r-r.r/r/r0�test_whitespace_continuation�
s			z(TestParsers.test_whitespace_continuationcCsQ|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
r6z!the next line has a space on it
 z
message-idr3zHere's the message body
)r)rpr�r>)r,r-r.r/r/r0�(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%rtrz
text/plainz!Simple email with attachment.

rPzapplication/riscos)r)r!rrrr>r5)r,r-rhr.�part1�part2r/r/r0�test_crlf_separation
s	z TestParsers.test_crlf_separationcCsytddd��}|j�}WdQRXtj|�}t�}t|�}|j|dd�|j|j�|�dS)Nz
msg_26.txtr�r%r�z
)	r!rdrpr�rrrfr)rg)r,rhrr.r�r�r/r/r0�test_crlf_flattens	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.txtrPrtrzmessage/rfc822z
text/plainz
message 1
z
message 2
)	r)r)r!rprBr�rr>r5)	r,r-r�rhr.r6Zpart1ar7Zpart2ar/r/r0�-test_multipart_digest_with_extra_mime_headers$s,		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)rpr�r�r�r))r,r�r.r/r/r0�test_three_linesCs
	zTestParsers.test_three_linescCsd|j}d}d}d||f}tj|�}||jd�|�||jd�|�dS)Nrz	more textz'Header: %s
Next-Header: %s

Body

r	zNext-Header)r)rpr��get)r,r-Zvalue1Zvalue2rr.r/r/r0�3test_strip_line_feed_and_carriage_return_in_headersKs	
z?TestParsers.test_strip_line_feed_and_carriage_return_in_headerscCsq|j}d}tj|�}|t|�d�|tdd�|D��dddg�||j�d�dS)	Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyrucss|]}|VqdS)Nr/)rMZfieldr/r/r0rC[sz9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>z!"#QUX;~z>Fromr�r�)r)rpr�rrrr>)r,r-rr.r/r/r0�test_rfc2822_header_syntaxVs	)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)rpr�rr�)r,r-rr.r/r/r0�(test_rfc2822_space_not_allowed_in_header^s	z4TestParsers.test_rfc2822_space_not_allowed_in_headercCsa|j}d}tj|�}|j�}|j�||dddg�||j�d�dS)Nz7A: first header
B: second header
CC: third header

body�A�B�CCr�)r)rpr�r��sortr>)r,r-rr.Zheadersr/r/r0�!test_rfc2822_one_character_headerds	
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
)rpr�r�r>r�)r,rr.r/r/r0�test_CRLFLF_at_end_of_partmsz&TestParsers.test_CRLFLF_at_end_of_part)rrrr*r+r.r0r1r2r4r5r8r9rlr:r;r=r>r?rDrEr/r/r/r0r)�
s$
	r)c@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}
        cCsx|jjdddddd�jd�}tj|�}|j|j�d�|j|jdd	�djd��dS)
Nr2zutf-8r|rA�bodylineupöstalupöstal
r=T)�bodytest_msgrrorprsr)r>)r,rr.r/r/r0�test_known_8bit_CTE�sz)Test8BitBytesHandling.test_known_8bit_CTEcCsx|jjdddddd�jd�}tj|�}|j|j�d�|j|jd	d
�djd��dS)Nr2Znotavalidcharsetr|rArGupöstalzutf-8up��stal
r=Tupöstal
)rHrrorprsr)r>)r,rr.r/r/r0�test_unknown_8bit_CTE�sz+Test8BitBytesHandling.test_unknown_8bit_CTEcCsx|jjdddddd�jd�}tj|�}|j|j�d�|j|jdd	�d
jd��dS)Nr2zutf-8r|zquoted-printablerGup=C3=B6stálu
p=C3=B6stál
r=Tu	pöstál
)rHrrorprsr)r>)r,rr.r/r/r0�test_8bit_in_quopri_body�s
z.Test8BitBytesHandling.test_8bit_in_quopri_bodycCsx|jjdddddd�jd�}tj|�}|j|j�d�|j|jd	d
�djd��dS)Nr2rnr|zquoted-printablerGup=C3=B6stálzutf-8up=C3=B6st��l
r=Tu	pöstál
)rHrrorprsr)r>)r,rr.r/r/r0�.test_invalid_8bit_in_non_8bit_cte_uses_replace�szDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replacecCs||jjdddddd�jd�}tj|�}|j|jdd�d	jd��|j|jd
t	j
�dS)Nr2zutf-8r|r<rGu
cMO2c3RhbAá=r=Tupöstalr)rHrrorprsr)r>r�r�rr�)r,rr.r/r/r0�test_8bit_in_base64_body�sz.Test8BitBytesHandling.test_8bit_in_base64_bodycCsb|jjdddddd�jd�}tj|�}|j|jdd�d	jd��dS)
Nr2zutf-8r|rxrGu
<,.V<W1A; á r=Tu<,.V<W1A; á 
)rHrrorprsr)r>)r,rr.r/r/r0�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|]\}}|�qSr/r/)rM�src�_r/r/r0rO�s	z Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
zutf-8cCsOtj|j�}|jt|jd��d�|jt|d�d�dS)Nr�ub��z)rprs�headertest_msgr)r�r<)r,r.r/r/r0�test_get_8bit_header�sz*Test8BitBytesHandling.test_get_8bit_headercCsNtj|j�}|jt|�tjd�jdd�|jD���dS)Nz�                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            cSs g|]\}}|d�qS)rPr/)rMrXZexpectedr/r/r0rO�s	zATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	rprsrYr)r�rrr�headertest_headers)r,r.r/r/r0�test_print_8bit_headers�s
z-Test8BitBytesHandling.test_print_8bit_headerscCsEtj|j�}|jdd�|j�D�ddddg�dS)NcSsg|]}t|��qSr/)r�)rMr�r/r/r0rOs	zGTest8BitBytesHandling.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)rprsrY�assertListEqualr�)r,r.r/r/r0�test_values_with_8bit_headers�sz3Test8BitBytesHandling.test_values_with_8bit_headerscCsEtj|j�}|jdd�|j�D�d
ddd
g�dS)NcSs.g|]$\}}t|�t|�f�qSr/)r�)rMr�r�r/r/r0rOs	zFTest8BitBytesHandling.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�r_)r�r`)rra)r�rb)rprsrYr]rZ)r,r.r/r/r0�test_items_with_8bit_headers
sz2Test8BitBytesHandling.test_items_with_8bit_headerscCsBtj|j�}|jdd�|jd�D�ddg�dS)NcSsg|]}t|��qSr/)r�)rMr�r/r/r0rOs	zHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r�zfoo@bar.comu	g��st)rprsrYr]r+)r,r.r/r/r0�test_get_all_with_8bit_headerssz4Test8BitBytesHandling.test_get_all_with_8bit_headerscCsgtjtjd�jd��}|j|j�d�|j|j�d�|j|j�d�dS)NuA            Content-Type: text/pl§in; charset=utf-8
            zlatin-1utext/pl�inrupl�in)	rprsrrror)r5r�r�)r,r.r/r/r0�test_get_content_type_with_8bits
z5Test8BitBytesHandling.test_get_content_type_with_8bitcCstjdjd��}|j|jdd�d
ddg�|j|jddd�d�|j|jddd�d�dS)Nu(X-Header: foo=§ne; b§r=two; baz=three
zlatin-1r^zx-headerr{��ne�b�rr�r�r�ZFooub§r)r{rf)rgr�)r�r�)rprsror)r�r6)r,r.r/r/r0�test_get_params_with_8bit%s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)rjrkrl)rprsrrror)r6)r,r.r/r/r0�!test_get_rfc2231_params_with_8bit/s
	z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitcCsNtjtjd�jd��}|jdd�|j|jd�d�dS)Nun            Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nzlatin-1ri�test)rprsrrror�r)r6)r,r.r/r/r0�!test_set_rfc2231_params_with_8bit7s
	z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitcCsatjtjd�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-1rir)	rprsrrror�r)r6r�)r,r.r/r/r0�!test_del_rfc2231_params_with_8bit?s	
z7Test8BitBytesHandling.test_del_rfc2231_params_with_8bitcCsWtjtjd�jd��}|j|j�d�|j|jdd�d�dS)Nu�            Content-Transfer-Encoding: b§se64
            Content-Type: text/plain; charset=latin-1

            payload
            zlatin-1zpayload
r=Tspayload
)rprsrrror)r>)r,r.r/r/r0�%test_get_payload_with_8bit_cte_headerHsz;Test8BitBytesHandling.test_get_payload_with_8bit_cte_headeru0        From: foo@bar.com
        To: báz
        Subject: Maintenant je vous présente mon collègue, le pouf célèbre
        	Jean de Baddie
        Mime-Version: 1.0
        Content-Type: text/plain; charset="utf-8"
        Content-Transfer-Encoding: 8bit

        Да, они летят.
        cCsQtj|j�}t�}tjj|�j|�|j|j�|j�dS)N)	rprs�non_latin_bin_msgrrrrrfr)rg)r,r.rkr/r/r0�test_bytes_generator^s	z*Test8BitBytesHandling.test_bytes_generatorcCsKtjj�}t�}tjj|�j|�|j|j�d�dS)Ns
)	rpr�rrrrrrfr)rg)r,r.rkr/r/r0�&test_bytes_generator_handles_None_bodyds	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==
        cCsQtj|j�}t�}tjj|�j|�|j|j�|j	�dS)N)
rprsrrrrrrrfr)rg� non_latin_bin_msg_as7bit_wrapped)r,r.rkr/r/r0�test_generator_handles_8bitxs	z1Test8BitBytesHandling.test_generator_handles_8bitcCs�tj|j�}t�}t|�j|�|j�}tt��j|�t�}t|�j|�|j	|j�|�dS)N)
rprsrrrrrfrgrrr))r,r.rkZ
orig_valuer/r/r0�;test_str_generator_should_not_mutate_msg_when_handling_8bit~s		zQTest8BitBytesHandling.test_str_generator_should_not_mutate_msg_when_handling_8bitcCs�tj|j�}t�}tjj|�j|dd�|j�jd�}|j	|dj�dd�|j	dj
|dd��|j�dS)Nr�Ts
rsFromrP)rprsrrrrrrrfrgr�r)r�)r,r.rkr�r/r/r0�#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?=rtrXcCs�d}|jt|�t|d��}|j|j�WdQRXt|d��}tjj�j|�}WdQRX|j	t
|�|j�dS)Nztest.msg�wbr)Z
addCleanupr�open�writerrrprjr,rr)r��non_latin_bin_msg_as7bit)r,rcZtestfilerr/r/r0�test_message_from_binary_file�sz3Test8BitBytesHandling.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)rprs�
latin_bin_msgr)r��latin_bin_msg_as7bit)r,rr/r/r0�:test_string_generator_reencodes_to_quopri_when_appropriate�szPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriatecCs^tj|j�}t�}tjj|�j|�|j|j�|jj	d�d�dS)Nzlatin-1r%)
rprsr~rrrrrfr)rgr=)r,rrkr/r/r0�)test_decoded_generator_emits_unicode_body�s
	z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodycCs|tjj�}xAtdt|j�d�D]$}|j|j||d��q+W|j�}|jt	|�|j
�dS)NrrD)rprpr$rHrr~rrr)r�r)r,ZbfprBrr/r/r0�test_bytes_feedparser�s
""z+Test8BitBytesHandling.test_bytes_feedparsercCs|tdd��}|j�}WdQRXtj|�}t�}tjj|�}|j|dd�|j|j	�|�dS)Nz
msg_26.txtrr�z
)
r!rdrprsrrrrrfr)rg)r,rhrr.r�r�r/r/r0r9�s	z'Test8BitBytesHandling.test_crlf_flattencCsitjd�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)rrrorprsrrrrrfr)rg)r,rtr.r�r�r/r/r0�test_8bit_multipart�s%	
z)Test8BitBytesHandling.test_8bit_multipartcCsat�}td�|d<t�}tjj|�}|j|dd�|j|j�d�dS)Nužluťoučký kůňrr�z
s5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr	rrprrrrfr)rg)r,rr�r�r/r/r0�'test_bytes_generator_b_encoding_lineseps			z=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesepcCsat�}td�|d<t�}tjj|�}|j|dd�|j|j�d�dS)Nužluťoučký kůňrr�z
z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	rr	rrprrrrfr)rg)r,rr�r�r/r/r0�!test_generator_b_encoding_lineseps			z7Test8BitBytesHandling.test_generator_b_encoding_linesepN�r�rP�rOr��r�rR�rQr��rrT�rSr��r�rV�rUr�)r�r�r�r�)/rrrrrrHrIrJrKrLrMrNr[r�rorYrZr\r^rcrdrerhrmrorprqrrrsrtrurvrwrxr�r|r}r~rr�r�r�r9r�r�r�rlr/r/r/r0rF�sf				

	
	

	
				
	.rFc@s1eZdZdZdd�Zddd�ZdS)� BaseTestBytesGeneratorIdempotentNc
CsVt|d��}|j�}WdQRX|jj|j|�}tj|�}||fS)Nr)r!rd�normalize_linesep_regex�sub�blineseprprs)r,r�rhr?r.r/r/r0r*#s
z(BaseTestBytesGeneratorIdempotent._msgobjFcCsWt�}tjj|dd�}|j|d|d|j�|j||j��dS)Nr]rr�r�)rrprrrrfr�r)rg)r,r.r?r�rur�r/r/r0rN*s	z,BaseTestBytesGeneratorIdempotent._idempotent)rrrrlr*rNr/r/r/r0r�sr�c@s+eZdZdZdZejd�ZdS)�TestBytesGeneratorIdempotentNLr%s
s\r\nN)rrrr�r��re�compiler�r/r/r/r0r�1sr�c@s+eZdZdZdZejd�ZdS)� TestBytesGeneratorIdempotentCRLFz
s
s	(?<!\r)\nN)rrrr�r�r�r�r�r/r/r/r0r�8sr�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TestBase64cCs�|j}|tjd�ttjddd���x�td�D]�}|dkr\d}nZ|dkrqd}nE|d	kr�d
}n0|dkr�d}n|dkr�d
}nd}|tjd|�|�qAWdS)N�helloshello�eolr&�rrurXrv�r����r�)r)r�
header_lengthr�body_encoderH)r,r-�sizeZbsizer/r/r0�test_len@s 						zTestBase64.test_lencCs9|j}|tjd�d�|tjd�d�dS)Nr&�zaGVsbG8=shello)r)rr=)r,r-r/r/r0�test_decodeMs	zTestBase64.test_decodecCs�|j}|tjd�d�|tjd�d�|tjd�d�|tjdddd	�d
�|tjdddd	dd�d
�dS)Nr�shelloz	aGVsbG8=
shello
z	aGVsbG8K
sxxxx r�r3�(z�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
r�z
z�eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r)rr�)r,r-r/r/r0�test_encodeRs	zTestBase64.test_encodecCs{|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=?=r2z
iso-8859-2z=?iso-8859-2?b?aGVsbG8=?=)r)rr�)r,r-Zher/r/r0�test_header_encodehs		zTestBase64.test_header_encodeN)rrrr�r�r�r�r/r/r/r0r�?s
r�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
dd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd
d&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,d
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)��
TestQuopricsbttttd�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�zrPr@�Zr}�9css|]}|VqdS)Nr/)rMrr/r/r0rC|sz#TestQuopri.setUp.<locals>.<genexpr>s!*+-/cs%g|]}|�jkr|�qSr/)�hlit)rMr)r,r/r0rOs	z$TestQuopri.setUp.<locals>.<listcomp>�r'�~r-�=cs%g|]}|�jkr|�qSr/)�blit)rMr)r,r/r0rO�s	)r7rrH�ordr��hnonr�AssertionErrorr�r4�remove�bnon)r,r/)r,r0rnus"(("zTestQuopri.setUpcCsrx4|jD])}|jtj|�dt|��q
Wx4|jD])}|jtj|�dt|��qAWdS)Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)r�r�rZheader_check�chrr�r�)r,rr/r/r0�test_quopri_header_check�sz#TestQuopri.test_quopri_header_checkcCsrx4|jD])}|jtj|�dt|��q
Wx4|jD])}|jtj|�dt|��qAWdS)Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)r�r�rZ
body_checkr�r�r�)r,rr/r/r0�test_quopri_body_check�sz!TestQuopri.test_quopri_body_checkcCsB|j}|tjd�d�|ttjddd��tjd�d�|tjd�d�|ttjddd��tjd�d�x=|jD]2}|tjt|g��dd	t|��q�WxR|jD]G}|t	d
�kr�q�|tjt|g��ddt|��q�W|tjd
�d�dS)Nshellor�r2ZxxxrDs
h@e@l@l@o@r�rPzexpected length 1 for %rr'ruzexpected length 3 for %r� )
r)rr�rr�r�r�r�r�r�)r,r-rr/r/r0�test_header_quopri_len�s$	z!TestQuopri.test_header_quopri_lencCss|j}x0|jD]%}|tjt|g��d�qWx0|jD]%}|tjt|g��d�qFWdS)NrPru)r)r�rZbody_lengthr�r�)r,r-rr/r/r0�test_body_quopri_len�s
	#zTestQuopri.test_body_quopri_lencCsIxBtd�D]4}t|�}|jtjtj|��|�q
WdS)Nr�)rHr�r)rr�Zquote)r,r�rr/r/r0�test_quote_unquote_idempotent�sz(TestQuopri.test_quote_unquote_idempotentNcCsD|dkrtj|�}ntj||�}|j||�dS)N)rr�r))r,r^Zexpected_encoded_headerr2�encoded_headerr/r/r0�_test_header_encode�szTestQuopri._test_header_encodecCs|jdd�dS)Nr�r&)r�)r,r/r/r0�test_header_encode_null�sz"TestQuopri.test_header_encode_nullcCs|jdd�dS)Nshelloz=?iso-8859-1?q?hello?=)r�)r,r/r/r0�test_header_encode_one_word�sz&TestQuopri.test_header_encode_one_wordcCs|jdd�dS)Nshello
worldz=?iso-8859-1?q?hello=0Aworld?=)r�)r,r/r/r0�test_header_encode_two_lines�s	z'TestQuopri.test_header_encode_two_linescCs|jdd�dS)Nshello�therez=?iso-8859-1?q?hello=C7there?=)r�)r,r/r/r0�test_header_encode_non_ascii�s	z'TestQuopri.test_header_encode_non_asciicCs|jdddd�dS)Nshelloz=?iso-8859-2?q?hello?=r2z
iso-8859-2)r�)r,r/r/r0�test_header_encode_alt_charset�sz)TestQuopri.test_header_encode_alt_charsetcCs#tj|�}|j||�dS)N)r�
header_decoder))r,r�Zexpected_decoded_headerZdecoded_headerr/r/r0�_test_header_decode�szTestQuopri._test_header_decodecCs|jdd�dS)Nr&)r�)r,r/r/r0�test_header_decode_null�sz"TestQuopri.test_header_decode_nullcCs|jdd�dS)Nr�)r�)r,r/r/r0�test_header_decode_one_word�sz&TestQuopri.test_header_decode_one_wordcCs|jdd�dS)Nz
hello=0Aworldzhello
world)r�)r,r/r/r0�test_header_decode_two_lines�sz'TestQuopri.test_header_decode_two_linescCs|jdd�dS)Nz
hello=C7thereuhelloÇthere)r�)r,r/r/r0�test_header_decode_non_ascii�sz'TestQuopri.test_header_decode_non_asciicCs%|jtjdd�dd�dS)Nz=30ir})r)rr�)r,r/r/r0�test_header_decode_re_bug_18380�sz*TestQuopri.test_header_decode_re_bug_18380cCsG|dkrtj|�}ntj|d|�}|j||�dS)Nr�)rr=r))r,ZencodedZexpected_decodedr��decodedr/r/r0�_test_decode�szTestQuopri._test_decodecCs|jdd�dS)Nr&)r�)r,r/r/r0�test_decode_null_word�sz TestQuopri.test_decode_null_wordcCs|jdd�dS)Nz
r%)r�)r,r/r/r0�test_decode_null_line_null_word�sz*TestQuopri.test_decode_null_line_null_wordcCs|jdd�dS)Nr�)r�)r,r/r/r0�test_decode_one_word�szTestQuopri.test_decode_one_wordcCs|jdddd�dS)Nr�r��X)r�)r,r/r/r0�test_decode_one_word_eol�sz#TestQuopri.test_decode_one_word_eolcCs|jdd�dS)Nzhello
zhello
)r�)r,r/r/r0�test_decode_one_lineszTestQuopri.test_decode_one_linecCs|jdd�dS)Nzhello
)r�)r,r/r/r0�test_decode_one_line_lfsz"TestQuopri.test_decode_one_line_lfcCs|jdd�dS)Nzhello
zhello
)r�)r,r/r/r0�test_decode_one_line_crsz"TestQuopri.test_decode_one_line_crcCs|jdddd�dS)Nzhello
�helloXr�r�)r�)r,r/r/r0�test_decode_one_line_nl	sz"TestQuopri.test_decode_one_line_nlcCs|jdddd�dS)Nzhello
r�r�r�)r�)r,r/r/r0�test_decode_one_line_crnlsz$TestQuopri.test_decode_one_line_crnlcCs|jdd�dS)Nzhello
worldzhello
world)r�)r,r/r/r0�test_decode_one_line_one_wordsz(TestQuopri.test_decode_one_line_one_wordcCs|jdddd�dS)Nzhello
worldZhelloXworldr�r�)r�)r,r/r/r0�!test_decode_one_line_one_word_eolsz,TestQuopri.test_decode_one_line_one_word_eolcCs|jdd�dS)Nzhello
world
zhello
world
)r�)r,r/r/r0�test_decode_two_linessz TestQuopri.test_decode_two_linescCs|jdddd�dS)Nzhello
world
ZhelloXworldXr�r�)r�)r,r/r/r0�test_decode_two_lines_eolsz$TestQuopri.test_decode_two_lines_eolcCs|jdddd�dS)NZSpam�)r�)r,r/r/r0�test_decode_one_long_linesz$TestQuopri.test_decode_one_long_linecCs|jdd�dS)Nr'r&)r�)r,r/r/r0�test_decode_one_spacesz TestQuopri.test_decode_one_spacecCs|jdd�dS)Nr'r�r&z     )r�)r,r/r/r0�test_decode_multiple_spaces!sz&TestQuopri.test_decode_multiple_spacescCs|jdd�dS)Nzhello    
zhello
)r�)r,r/r/r0�$test_decode_one_line_trailing_spaces$sz/TestQuopri.test_decode_one_line_trailing_spacescCs|jdd�dS)Nzhello    
world   
zhello
world
)r�)r,r/r/r0�%test_decode_two_lines_trailing_spaces'sz0TestQuopri.test_decode_two_lines_trailing_spacescCs|jdd�dS)Nz=22quoted=20words=22z"quoted words")r�)r,r/r/r0�test_decode_quoted_word*sz"TestQuopri.test_decode_quoted_wordcCs|jdd�dS)Nzab=CD=EFuabÍï)r�)r,r/r/r0�test_decode_uppercase_quoting-sz(TestQuopri.test_decode_uppercase_quotingcCs|jdd�dS)Nzab=cd=efuabÍï)r�)r,r/r/r0�test_decode_lowercase_quoting0sz(TestQuopri.test_decode_lowercase_quotingcCs|jdd�dS)Nzsoft line=
breakzsoft linebreak)r�)r,r/r/r0�test_decode_soft_line_break3sz&TestQuopri.test_decode_soft_line_breakcCs|jdd�dS)NzA=1,B=A ==> A+B==2)r�)r,r/r/r0�test_decode_false_quoting6sz$TestQuopri.test_decode_false_quotingcCs�i}|dkrd}n
||d<|dkr:d}n
||d<tj||�}|j||�|dks~|dkr�x*|j�D]}|jt|�|�q�WdS)Nrr3r%r�z
)rr�r)r2rr)r,r�Zexpected_encoded_bodyr3r��kwargsZencoded_bodyr�r/r/r0�_test_encode9s	
	
zTestQuopri._test_encodecCs|jdd�dS)Nr&)r�)r,r/r/r0�test_encode_nullMszTestQuopri.test_encode_nullcCs|jdd�dS)Nz

)r�)r,r/r/r0�test_encode_null_linesPsz!TestQuopri.test_encode_null_linescCs|jdd�dS)Nzhello
)r�)r,r/r/r0�test_encode_one_lineSszTestQuopri.test_encode_one_linecCs|jdd�dS)Nzhello
zhello
)r�)r,r/r/r0�test_encode_one_line_crlfVsz$TestQuopri.test_encode_one_line_crlfcCs|jdddd�dS)Nzhello
zhello
r�z
)r�)r,r/r/r0�test_encode_one_line_eolYsz#TestQuopri.test_encode_one_line_eolcCs,|jdjd�jd�ddd�dS)Nuhelloυ
zutf-8�latin1z
hello=CF=85
r�z
)r�ror=)r,r/r/r0�(test_encode_one_line_eol_after_non_ascii\sz3TestQuopri.test_encode_one_line_eol_after_non_asciicCs|jdd�dS)Nr'z=20)r�)r,r/r/r0�test_encode_one_spaceasz TestQuopri.test_encode_one_spacecCs|jdd�dS)Nz 
z=20
)r�)r,r/r/r0�test_encode_one_line_one_spacedsz)TestQuopri.test_encode_one_line_one_spacecCs|jdd�dS)Nz 
 
z=20
=20
)r�)r,r/r/r0�test_encode_two_lines_one_spacelsz*TestQuopri.test_encode_two_lines_one_spacecCs|jdd�dS)Nzhello   z
hello  =20)r�)r,r/r/r0�$test_encode_one_word_trailing_spacesosz/TestQuopri.test_encode_one_word_trailing_spacescCs|jdd�dS)Nz	hello   
zhello  =20
)r�)r,r/r/r0�$test_encode_one_line_trailing_spacesrsz/TestQuopri.test_encode_one_line_trailing_spacescCs|jdd�dS)Nzhello  	z
hello  =09)r�)r,r/r/r0�!test_encode_one_word_trailing_tabusz,TestQuopri.test_encode_one_word_trailing_tabcCs|jdd�dS)Nz	hello  	
zhello  =09
)r�)r,r/r/r0�!test_encode_one_line_trailing_tabxsz,TestQuopri.test_encode_one_line_trailing_tabcCs|jdddd�dS)Nz
abcd 
1234zabcd =

1234r3rv)r�)r,r/r/r0�,test_encode_trailing_space_before_maxlinelen{sz7TestQuopri.test_encode_trailing_space_before_maxlinelencCs|jdddd�dS)Nz
abcd 
1234zabcd=
=20
1234r3r�)r�)r,r/r/r0�(test_encode_trailing_space_at_maxlinelen~sz3TestQuopri.test_encode_trailing_space_at_maxlinelencCs|jdddd�dS)Nz
abcd 
1234zabc=
d=20
1234r3rX)r�)r,r/r/r0�,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,r/r/r0�test_encode_whitespace_lines�sz'TestQuopri.test_encode_whitespace_linescCs|jdd�dS)Nza = bza =3D b)r�)r,r/r/r0�test_encode_quoted_equals�sz$TestQuopri.test_encode_quoted_equalscCs(|jddddddd�dS)Nr��d�Kz=
r�)r�)r,r/r/r0�test_encode_one_long_string�sz&TestQuopri.test_encode_one_long_stringcCs0|jddddddddd�dS)Nr�r�r%r�z=
r�)r�)r,r/r/r0�test_encode_one_long_line�sz$TestQuopri.test_encode_one_long_linecCs4|jdddddddddd�dS)Nr���r%rtr�z=
�2)r�)r,r/r/r0�test_encode_one_very_long_line�sz)TestQuopri.test_encode_one_very_long_linecCs|jddddd�dS)	Nr�r�z=3D=
rXz=3Dr3z=====z=3D=
=3D=
=3D=
=3D=
)r�)r,r/r/r0�test_encode_shortest_maxlinelen�sz*TestQuopri.test_encode_shortest_maxlinelencCs#|jt|jdddd�dS)Nr&r3ru)r\r�r�)r,r/r/r0� test_encode_maxlinelen_too_small�sz+TestQuopri.test_encode_maxlinelen_too_smallcCs�|j}|tjd�d�|tjd�d�|tjd�d�|tjdddd�d	�|tjddddd
d�d�|tjd
�d
�dS)Nr&r�zhello
worldzhello
worldzxxxx r�r3r�zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20r�z
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-r/r/r0r��s		zTestQuopri.test_encode)Frrrrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r/r/r/r0r�ts�r�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestCharsetcCs7ddlm}y|jd=Wntk
r2YnXdS)Nr)r2�fake)rpr2ZCHARSETSr�)r,�
CharsetModuler/r/r0�tearDown�s

zTestCharset.tearDowncCsm|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-rr�r/r/r0�test_codec_encodeable�s	z!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)r2r)r)rr�rpr2Zadd_charsetZQP)r,r-rrr/r/r0�test_body_encode�s	zTestCharset.test_body_encodecCs<td�}|jt|�d�|jtjtd�dS)Nzus-asciiuascÿii)rr)r�r\rZCharsetError)r,r2r/r/r0�test_unicode_charset_name�sz%TestCharset.test_unicode_charset_nameN)rrrrrr	r
r/r/r/r0r�src@s0eZdZdd�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�
TestHeadercCsL|j}td�}||j�d�|jd�||j�d�dS)NzHello World!z Goodbye World!zHello World!  Goodbye World!)r)r	ror4)r,r-r0r/r/r0�test_simple�s
	
zTestHeader.test_simplecCsL|j}td�}||j�d�|jd�||j�d�dS)NzHello World!zGoodbye World!zHello World! Goodbye World!)r)r	ror4)r,r-r0r/r/r0�test_simple_surprise�s
	
zTestHeader.test_simple_surprisecCs)d}|jt|�|dfg�dS)Nzno decoding needed)r)r
)r,r0r/r/r0�test_header_needs_no_decoding�sz(TestHeader.test_header_needs_no_decodingcCsRtddd�}x9|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.r3rZ
splitcharsr'z
 )r	ror�rr)r,r0�lr/r/r0�	test_longs		"zTestHeader.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.」と言っています。r3ra=?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?=rurrPrts�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	r4ror
rr�r=r)
r,r-r�r5r6r7r8r9r0�encr�ZustrZnewhr/r/r0�test_multilingual	s0	 
zTestHeader.test_multilingualcCs#t�}|j|j�d�dS)Nr&)r	r)ro)r,r0r/r/r0�test_empty_header_encodeHs	z#TestHeader.test_empty_header_encodecCsF|j}t�}||d�|jdtd��||d�dS)Nr&r{z
iso-8859-1)r)r	r4r)r,r-r0r/r/r0�test_header_ctor_default_argsLs
		
z(TestHeader.test_header_ctor_default_argscCs�|j}d}t|�}||j�d�|t|�|�t|dd�}||j�d�|t|�|�t|dddd�}||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 behaviorr2rz}A very long line that must get split to something other than at the
 76th character boundary to test the non-default behaviorr3i)r)r	ror�)r,r-r/r0r/r/r0�test_explicit_maxlinelenSs	z#TestHeader.test_explicit_maxlinelencCs�|j}tdddd�}dd}|j|�|j�}||d�||ttt|����tdddd�}|jdd�|j�}||d�||ttt|����dS)	Nr2z
iso-8859-1r3r�zxxxx 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	r4ror�rr
)r,r-r0r�r�r/r/r0�test_quopri_splittablefs	

2z!TestHeader.test_quopri_splittablecCs�|j}tdddd�}dd}|j|�|j�}||d�||ttt|����tdddd�}|j|�|j�}||d�||ttt|����dS)	Nr2zkoi8-rr3r�zxxxx 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	r4ror�rr
)r,r-r0r�r�r/r/r0�test_base64_splittable�s	

"
z!TestHeader.test_base64_splittablecCsN|j}d}t|�}||dg�t|�}|||j��dS)Nr�)r�N)r)r
rro)r,r-r�r�r0r/r/r0�test_us_ascii_header�s	zTestHeader.test_us_ascii_headercCs3|j}t�}|jdd�||d�dS)Nr�z
iso-8859-1)r)r	r4)r,r-r0r/r/r0�test_string_charset�s		zTestHeader.test_string_charsetcCsQ|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	ro)r,r-r0r/r/r0�test_utf8_shortest�s
	zTestHeader.test_utf8_shortestcCs�|j}|j}d}|tt|�t�}|t|j|�|jdd�}|tt|dd��|�|j|dd�|t|�|�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzutf-8r.r)r\r)r�r	r4r=r�)r,r�r-r�r0�er/r/r0�test_bad_8bit_header�s			zTestHeader.test_bad_8bit_headercCsod}|jdd�}t|dtjj�}|jt|�d�|jtjj|�|dfg�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigrn�surrogateescaper2u2Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzunknown-8bit)	r=r	rpr2�UNKNOWN8BITr)r�r^r
)r,r�rr0r/r/r0�test_escaped_8bit_headersz#TestHeader.test_escaped_8bit_headercCs]d}t|dtjj�}|jt|�d�|jtjj|�|dfg�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigr2u2Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzunknown-8bit)r	rpr2rr)r�r^r
)r,r�r0r/r/r0�&test_header_handles_binary_unknown8bits
z1TestHeader.test_header_handles_binary_unknown8bitcCs{d}t|dtjj�}tjjtjj|��}|jt|�d�|jtjj|�|dfg�dS)Ns0Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigr2u2Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigzunknown-8bit)	r	rpr2rr^rr
r)r�)r,r�r0Zh2r/r/r0�+test_make_header_handles_binary_unknown8bitsz6TestHeader.test_make_header_handles_binary_unknown8bitcCsEtd�}tjj|�}|jd�|jt|�d�dS)Nrnrn�test2)rnr")r	rpr^r
r4r)r�)r,r0rr/r/r0�0test_modify_returned_list_does_not_change_header"s
z;TestHeader.test_modify_returned_list_does_not_change_headercCsq|j}t�}|jdd�|jd�|j�}||d�tt|��}||j�|�dS)Nr�z
iso-8859-1Zworldz=?iso-8859-1?q?hello?= world)r)r	r4rorr
)r,r-r0r�r/r/r0� test_encoded_adjacent_nonencoded(s		

z+TestHeader.test_encoded_adjacent_nonencodedcCsT|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.)r%N)r&r')r(N)r)r
rro)r,r-r��partsZhdrr/r/r0�test_whitespace_keeper2s	z!TestHeader.test_whitespace_keepercCs&|j}d}|tjt|�dS)NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r\rr]r
)r,r�r�r/r/r0�test_broken_base64_header;s	z$TestHeader.test_broken_base64_headercCs,tddd�}|j|j�d�dS)Nu文r2�	shift_jisz=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	r)ro)r,r0r/r/r0�test_shift_jis_charset@sz!TestHeader.test_shift_jis_charsetcCs)tjd�}|jt|�d�dS)NzEmptyHeader:zEmptyHeader: 

)rpr�r)r�)r,r.r/r/r0�!test_flatten_header_with_no_valueDsz,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.r/r/r0�)test_encode_preserves_leading_ws_on_valueKs	
z4TestHeader.test_encode_preserves_leading_ws_on_valueN)rrrrr
rrrrrrrrrrrrrr r!r#r$r*r+r-r.r/r/r/r/r0r�s0?E6
	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):�TestRFC2231cCsN|j}|jd�}||jd�d	�||jddd�d
�dS)Nz
msg_29.txtri�us-asciirk�%This is even more ***fun*** isn't it!r�F�'"This is even more ***fun*** isn't it!")r1rkr2)r1rkr3)r)r*r6)r,r-r.r/r/r0r�Ws	zTestRFC2231.test_get_paramcCs�|j}t�}|jdddd�||jd�d�|jdddddd�||jd�d
�|jd�}|jdddddd�||jd	d
�d�dS)Nri�%This is even more ***fun*** isn't it!r2�us-asciir&�languagerkz
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
)r5r&r4)r5rkr4)r)rr�r6r*rb)r,r-r.r/r/r0r�_s		

zTestRFC2231.test_set_paramcCs�t�}|jdd�|j|dd�|jdddd�|j|dd�|jdd	dd�|j|dd
�dS)Nrir{zcontent-typeztext/plain; title="foo"r�ZrequoteFztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")rr�r))r,r.r/r/r0�test_set_param_requote�s	z"TestRFC2231.test_set_param_requotecCs�|j}|jd�}|jdddddd�|jdd	dddd�|jdd
d�||jdd
�d�dS)Nz
msg_01.txtr{r�r2zus-asciir6rkriz%This is even more ***fun*** isn't it!r^zContent-Typer]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�rb)r,r-r.r/r/r0r��s	
zTestRFC2231.test_del_paramcCs/|j}|jd�}||j�d�dS)Nz
msg_32.txtzus-ascii)r)r*�get_content_charset)r,r-r.r/r/r0� test_rfc2231_get_content_charset�s	z,TestRFC2231.test_rfc2231_get_content_charsetcCsNtjd�}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)rrrpr�r)rLrb)r,rr.r/r/r0�test_rfc2231_parse_rfc_quoting�s	z*TestRFC2231.test_rfc2231_parse_rfc_quotingcCsNtjd�}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)rrrpr�r)rLrb)r,rr.r/r/r0� test_rfc2231_parse_extra_quoting�s	z,TestRFC2231.test_rfc2231_parse_extra_quotingcCsHd}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)rpr�r6�assertNotIsInstance�tupler))r,rr.�paramr/r/r0�#test_rfc2231_no_language_or_charset�sz/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)rpr�r)rL)r,rr.r/r/r0�/test_rfc2231_no_language_or_charset_in_filename�sz;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)rpr�r)rL)r,rr.r/r/r0�7test_rfc2231_no_language_or_charset_in_filename_encoded�szCTestRFC2231.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)rpr�r)rL)r,rr.r/r/r0�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)rpr�r)rL)r,rr.r/r/r0�test_rfc2231_partly_nonencoded
s
	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)rpr�r)rV)r,rr.r/r/r0�/test_rfc2231_no_language_or_charset_in_boundarysz;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)rpr�r)r8)r,rr.r/r/r0�.test_rfc2231_no_language_or_charset_in_charset#sz: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)rpr�r)rL)r,rr.r/r/r0�%test_rfc2231_bad_encoding_in_filename1sz1TestRFC2231.test_rfc2231_bad_encoding_in_filenamecCs/d}tj|�}|j|j�d�dS)Nz:Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D

)rpr�r)r8)r,rr.r/r/r0�$test_rfc2231_bad_encoding_in_charset=sz0TestRFC2231.test_rfc2231_bad_encoding_in_charsetcCs/d}tj|�}|j|j�d�dS)Nz:Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D

)rpr�r)r8)r,rr.r/r/r0�%test_rfc2231_bad_character_in_charsetGsz1TestRFC2231.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�)rpr�r)rL)r,rr.r/r/r0�&test_rfc2231_bad_character_in_filenameQsz2TestRFC2231.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)rpr�r)rL)r,rr.r/r/r0�test_rfc2231_unknown_encoding]sz)TestRFC2231.test_rfc2231_unknown_encodingcCsa|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)rpr�r6)r,r-rr.r2r6r�r/r/r0�-test_rfc2231_single_tick_in_filename_extendedfs	

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

r�zFrank's Document)rpr�r6r=r>r))r,rr.r?r/r/r0�$test_rfc2231_single_tick_in_filenamets
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)rpr�r)rL)r,rr.r/r/r0�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)rpr�r)rL)r,rr.r/r/r0�0test_rfc2231_missing_tick_with_encoded_non_ascii�s
	z<TestRFC2231.test_rfc2231_missing_tick_with_encoded_non_asciicCsa|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)rpr�r6)r,r-rr.r2r6r�r/r/r0�!test_rfc2231_tick_attack_extended�s	

z-TestRFC2231.test_rfc2231_tick_attack_extendedcCsHd}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)rpr�r6r=r>r))r,rr.r?r/r/r0�test_rfc2231_tick_attack�s
z$TestRFC2231.test_rfc2231_tick_attackcCs8|j}d}tj|�}||jd�d�dS)Nz:Content-Type: application/x-foo; name="Frank's Document"

r�zFrank's Document)r)rpr�r6)r,r-rr.r/r/r0�test_rfc2231_no_extended_values�s	z+TestRFC2231.test_rfc2231_no_extended_valuescCsa|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)rpr�r6)r,r-rr.r2r6r�r/r/r0�,test_rfc2231_encoded_then_unencoded_segments�s	

z8TestRFC2231.test_rfc2231_encoded_then_unencoded_segmentscCsa|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)rpr�r6)r,r-rr.r2r6r�r/r/r0�,test_rfc2231_unencoded_then_encoded_segments�s	

z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsN)rrrr�r�r7r�r9r:r;r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTr/r/r/r0r0Ss8%
!




	


r0c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestSignedc	Cs;t|��"}|j�}tj|�}WdQRX||fS)N)r!rdrpr�)r,r�rh�originalr.r/r/r0�_msg_and_obj�szTestSigned._msg_and_objcCslddl}|jd|j|jB�}|j|�jd�}|j|�jd�}|j||�dS)Nrz^--([^\n]+)\n(.*?)\n--\1$rt)r�r��Sr&�search�groupr))r,rV�resultr�ZrepartZinpartZoutpartr/r/r0�_signed_parts_eq�s
zTestSigned._signed_parts_eqcCs5|jd�\}}|j�}|j||�dS)Nz
msg_45.txt)rWrbr\)r,rVr.r[r/r/r0�test_long_headers_as_string�sz&TestSigned.test_long_headers_as_stringcCs;|jd�\}}|jdd�}|j||�dS)Nz
msg_45.txtr]�<)rWrbr\)r,rVr.r[r/r/r0�(test_long_headers_as_string_maxheaderlen�sz3TestSigned.test_long_headers_as_string_maxheaderlencCsQ|jd�\}}t�}t|�j|�|j�}|j||�dS)Nz
msg_45.txt)rWrrrfrgr\)r,rVr.rhr[r/r/r0�test_long_headers_flatten�s
	z$TestSigned.test_long_headers_flattenN)rrrrWr\r]r_r`r/r/r/r0rU�s
rU�__main__)`r�r�r<r�r�iorr�	itertoolsrZrandomrZsocketrZ	threadingr�ImportErrorZdummy_threadingrpZ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.multipartrrrrrrrZtest.supportrr Ztest.test_emailr!r"r#r$r�r�rGr(ZTestCaserr(rmrwr�r�r�r�r�r�r4rMrdr�rr)rFr�r�r�r�r�rrr0rUr�mainr/r/r/r0�<module>s�
���C��?F((\<�|���.���g1���		5�C:�d��#