B
    18™\X- ã               @   s†  d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlZd dlZd dlmZ d dlmZmZmZ d d	lmZmZ d d
lmZmZmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dlm1Z1 d dlm2Z2 d dlm3Z3 d dlm4Z4 d dlm5Z5 d dlm6Z6 d dl7m8Z8m9Z9 d dl:m;Z;m<Z< d dlm=Z=m>Z> dZ?dZ@dZAG d d!„ d!e<ƒZBG d"d#„ d#ejCƒZDG d$d%„ d%e<ƒZEG d&d'„ d'ejCƒZFG d(d)„ d)ejCƒZGG d*d+„ d+ejCƒZHG d,d-„ d-ejCƒZIG d.d/„ d/ejCƒZJG d0d1„ d1e<ƒZKG d2d3„ d3e<ƒZLG d4d5„ d5e<ƒZMG d6d7„ d7e<ƒZNG d8d9„ d9e<ƒZOG d:d;„ d;e<ƒZPG d<d=„ d=e<ƒZQG d>d?„ d?e<ƒZRG d@dA„ dAe<ƒZSG dBdC„ dCe<ƒZTG dDdE„ dEƒZUG dFdG„ dGeUeOƒZVG dHdI„ dIeUeOƒZWG dJdK„ dKejCƒZXG dLdM„ dMejCƒZYG dNdO„ dOejCƒZZG dPdQ„ dQe<ƒZ[G dRdS„ dSe<ƒZ\G dTdU„ dUe<ƒZ]e^dVkr‚e _¡  dS )Wé    N)ÚStringIOÚBytesIO)Úchain)Úchoice)Úgetfqdn)ÚThread)ÚCharset)ÚHeaderÚdecode_headerÚmake_header)ÚParserÚHeaderParser)Ú	GeneratorÚDecodedGeneratorÚBytesGenerator)ÚMessage)ÚMIMEApplication)Ú	MIMEAudio)ÚMIMEText)Ú	MIMEImage)ÚMIMEBase)ÚMIMEMessage)ÚMIMEMultipart)ÚMIMENonMultipart)Úutils)Úerrors)Úencoders)Ú	iterators)Ú
base64mime)Ú
quoprimime)ÚunlinkÚstart_threads)ÚopenfileÚTestEmailBase)Ú
FeedParserÚBytesFeedParserÚ
Ú ú c               @   s¤  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;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~„ ZAdd€„ ZBdd‚„ ZCdƒd„„ ZDd…d†„ ZEd‡dˆ„ ZFd‰dŠ„ ZGd‹dŒ„ ZHddŽ„ ZIdd„ ZJd‘d’„ ZKd“d”„ ZLd•d–„ ZMd—d˜„ ZNd™dš„ ZOd›dœ„ ZPddž„ ZQdŸd „ ZRd¡d¢„ ZSd£d¤„ ZTd¥d¦„ ZUd§S )¨ÚTestMessageAPIc             C   s<   | j }|  d¡}|| d¡dddgƒ || dd¡dƒ d S )Nz
msg_20.txtÚcczccc@zzz.orgzddd@zzz.orgzeee@zzz.orgÚxxzn/a)ÚassertEqualÚ_msgobjÚget_all)ÚselfÚeqÚmsg© r2   ú^/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_email/test_email.pyÚtest_get_all6   s    
zTestMessageAPI.test_get_allc             C   s   | j }tƒ }|| ¡ d ƒ tdƒ}| |¡ ||d dƒ || ¡ dƒ ||d dƒ || d¡dƒ ||d d	ƒ || ¡ jdƒ | d ¡ || ¡ d ƒ ||d dƒ tƒ }d
|d< d|d< d|d< | |¡ ||d d
ƒ ||d dƒ ||d dƒ d S )Nz
iso-8859-1zmime-versionz1.0z
text/plainzcontent-typez text/plain; charset="iso-8859-1"Úcharsetzcontent-transfer-encodingzquoted-printablez2.0zMIME-Versionztext/x-weirdzContent-Typezquinted-puntablezContent-Transfer-Encodingz"text/x-weird; charset="iso-8859-1")r,   r   Úget_charsetr   Úset_charsetÚget_content_typeÚ	get_paramÚinput_charset)r/   r0   r1   r5   r2   r2   r3   Útest_getset_charset<   s,    


z"TestMessageAPI.test_getset_charsetc             C   s8   | j }tƒ }| d¡ || ¡ jdƒ ||d dƒ d S )Nzus-asciizcontent-typeztext/plain; charset="us-ascii")r,   r   r7   r6   r:   )r/   r0   r1   r2   r2   r3   Útest_set_charset_from_stringV   s
    
z+TestMessageAPI.test_set_charset_from_stringc             C   s0   t ƒ }tdƒ}| d|¡ |  | ¡ jd¡ d S )Nz
iso-8859-1zThis is a string payload)r   r   Úset_payloadr,   r6   r:   )r/   r1   r5   r2   r2   r3   Útest_set_payload_with_charset]   s    z,TestMessageAPI.test_set_payload_with_charsetc             C   sV   d}t dƒ}tƒ }| ||¡ |  |d d¡ |  |jdd|¡ |  | ¡ d¡ d S )Ns   ÐÐ‘Ð’zutf-8zcontent-transfer-encodingÚbase64T)Údecodez	0JDQkdCS
)r   r   r=   r,   Úget_payload)r/   Údatar5   r1   r2   r2   r3   Ú+test_set_payload_with_8bit_data_and_charsetc   s    z:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetc             C   sR   d}t dƒ}d |_tƒ }| | d¡|¡ |  |d d¡ |  |jdd|¡ d S )Ns   ÐÐ‘Ð’zutf-8zcontent-transfer-encodingÚ8bitT)r@   )r   Úbody_encodingr   r=   r@   r,   rA   )r/   rB   r5   r1   r2   r2   r3   Ú>test_set_payload_with_non_ascii_and_charset_body_encoding_nonel   s    zMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_nonec             C   sL   d}t dƒ}d |_tƒ }| ||¡ |  |d d¡ |  |jdd|¡ d S )Ns   ÐÐ‘Ð’zutf-8zcontent-transfer-encodingrD   T)r@   )r   rE   r   r=   r,   rA   )r/   rB   r5   r1   r2   r2   r3   Ú>test_set_payload_with_8bit_data_and_charset_body_encoding_noneu   s    zMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonec             C   s$   t ƒ }| g ¡ |  | ¡ g ¡ d S )N)r   r=   r,   rA   )r/   r1   r2   r2   r3   Útest_set_payload_to_list~   s    
z'TestMessageAPI.test_set_payload_to_listc             C   s8   t ƒ }d|d< | d¡ tt ƒ ƒ}|  td|j|¡ d S )Nzmultipart/mixedzContent-Typezstring payloadz[Aa]ttach.*non-multipart)r   r=   r   ÚassertRaisesRegexÚ	TypeErrorÚattach)r/   r1   Zsub_msgr2   r2   r3   Ú"test_attach_when_payload_is_stringƒ   s    

z1TestMessageAPI.test_attach_when_payload_is_stringc          
   C   s„   | j }|  d¡}| ¡ }||d ddddgƒ |  d¡}| d¡}||dddddgƒ |  d¡}| ¡ }||d ddd dd	ddgƒ d S )
Nz
msg_08.txtzus-asciiz
iso-8859-1z
iso-8859-2zkoi8-rz
msg_09.txtZdingbatz
msg_12.txtz
iso-8859-3)r,   r-   Úget_charsets)r/   r0   r1   Úcharsetsr2   r2   r3   Útest_get_charsets‹   s    



z TestMessageAPI.test_get_charsetsc             C   sV   | j }|  d¡}dd„ | ¡ D ƒ}||ddgƒ |  d¡}| d¡}|| ¡ dƒ d S )Nz
msg_04.txtc             S   s   g | ]}|  ¡ ‘qS r2   )Úget_filename)Ú.0Úpr2   r2   r3   ú
<listcomp>    s    z4TestMessageAPI.test_get_filename.<locals>.<listcomp>zmsg.txtz
msg_07.txté   zdingusfish.gif)r,   r-   rA   rP   )r/   r0   r1   Ú	filenamesÚsubpartr2   r2   r3   Útest_get_filenameœ   s    


z TestMessageAPI.test_get_filenamec             C   s4   | j }|  d¡}dd„ | ¡ D ƒ}||ddgƒ d S )Nz
msg_44.txtc             S   s   g | ]}|  ¡ ‘qS r2   )rP   )rQ   rR   r2   r2   r3   rS   «   s    zHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>zmsg.txt)r,   r-   rA   )r/   r0   r1   rU   r2   r2   r3   Ú%test_get_filename_with_name_parameter§   s    
z4TestMessageAPI.test_get_filename_with_name_parameterc             C   s"   | j }|  d¡}|| ¡ dƒ d S )Nz
msg_07.txtÚBOUNDARY)r,   r-   Úget_boundary)r/   r0   r1   r2   r2   r3   Útest_get_boundary®   s    
z TestMessageAPI.test_get_boundaryc             C   sž   | j }|  d¡}| d¡ | ¡ d \}}|| ¡ dƒ ||dƒ |  d¡}| d¡ | ¡ d \}}|| ¡ dƒ ||dƒ |  d¡}|  tj|jd¡ d S )	Nz
msg_01.txtrY   é   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/   r0   r1   ÚheaderÚvaluer2   r2   r3   Útest_set_boundary´   s    






z TestMessageAPI.test_set_boundaryc             C   sL   t dƒ}|  | ¡ d d d¡ | ¡  |  | ¡ d d d d… d¡ d S )Nz	form-datar   rT   zmultipart/form-dataé!   z!multipart/form-data; boundary="==)r   r,   r^   Ú	as_string)r/   r1   r2   r2   r3   Útest_make_boundaryÊ   s
    z!TestMessageAPI.test_make_boundaryc          	   C   s^   t dƒ}| ¡ }W d Q R X tƒ }| |¡}tƒ }t|ddƒ}| |d¡ |  | ¡ |¡ d S )Nz
msg_46.txtTr   F)	r"   Úreadr   Úparsestrr   r   Úflattenr,   Úgetvalue)r/   ÚfpÚmsgdataÚparserr1   ÚoutÚgenr2   r2   r3   Útest_message_rfc822_onlyÕ   s    

z'TestMessageAPI.test_message_rfc822_onlyc          	   C   sf   t dƒ}| ¡  d¡}W d Q R X tj ¡ }| |¡}tƒ }tj 	|¡}| 
|¡ |  | ¡ |¡ d S )Nz
msg_46.txtÚascii)r"   rh   ÚencodeÚemailrn   ÚBytesHeaderParserÚ
parsebytesr   Ú	generatorr   rj   r,   rk   )r/   rl   rm   rn   r1   ro   rp   r2   r2   r3   Útest_byte_message_rfc822_onlyá   s    



z,TestMessageAPI.test_byte_message_rfc822_onlyc             C   sž   | j }|  d¡}||jddd ƒ || d¡jdddƒ || d¡jdddƒ || d¡jddd	ƒ || d
¡jdddƒ || d¡jdddƒ d S )Nz
msg_10.txtT)r@   r   s    This is a 7bit encoded message.
rT   s-   ¡This is a Quoted Printable encoded message!
é   s!   This is a Base64 encoded message.é   s"   This is a Base64 encoded message.
r\   s/   This has no Content-Transfer-Encoding: header.
)r,   r-   rA   )r/   r0   r1   r2   r2   r3   Útest_get_decoded_payloadì   s    
z'TestMessageAPI.test_get_decoded_payloadc             C   s^   | j }tƒ }| d¡ x&dD ]}||d< ||jdddƒ qW | d¡ ||jdddƒ d S )	Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
)z
x-uuencodeÚuuencodeÚuuezx-uuezcontent-transfer-encodingT)r@   s   hello worldÚfoos   foo)r,   r   r=   rA   )r/   r0   r1   Úcter2   r2   r3   Útest_get_decoded_uu_payload  s    


z*TestMessageAPI.test_get_decoded_uu_payloadc             C   s   t ƒ }|  t|jd¡ d S )NrT   )r   r`   rJ   rA   )r/   r1   r2   r2   r3   Ú*test_get_payload_n_raises_on_non_multipart  s    z9TestMessageAPI.test_get_payload_n_raises_on_non_multipartc          	   C   sV   | j }|  d¡}tdƒ}| ¡ }W d Q R X tƒ }t|ƒ}| |¡ || ¡ |ƒ d S )Nz
msg_07.txtz
msg_17.txt)r,   r-   r"   rh   r   r   rj   rk   )r/   r0   r1   rl   ÚtextÚsÚgr2   r2   r3   Útest_decoded_generator  s    


z%TestMessageAPI.test_decoded_generatorc             C   sb   t ƒ }d|d< d|d< |  d|¡ |  d|¡ |  d|¡ |  d|¡ |  d|¡ |  d|¡ d S )	NZMeÚFromZYouÚtoÚfromZFROMÚToZTO)r   ÚassertIn)r/   r1   r2   r2   r3   Útest__contains__  s    zTestMessageAPI.test__contains__c          	   C   s~   |   d¡}tdƒ}| ¡ }W d Q R X |  |t|ƒ¡ |jdd}| d¡}|  |d  d¡¡ |  |t	 
|dd … ¡¡ d S )Nz
msg_01.txtT)Úunixfromr&   r   zFrom rT   )r-   r"   rh   r,   Ústrrf   ÚsplitÚ
assertTrueÚ
startswithÚNLÚjoin)r/   r1   rl   r‚   ÚfullreprÚlinesr2   r2   r3   Útest_as_string'  s    


zTestMessageAPI.test_as_stringc             C   sT   |   d¡}|jjdd}|j|d}tƒ }t||d}| |¡ |  || ¡ ¡ d S )Nz
msg_01.txtz
)Úlinesep)Úpolicy)	r-   r—   Úclonerf   r   r   rj   r,   rk   )r/   r1   Ú	newpolicyr“   rƒ   r„   r2   r2   r3   Útest_as_string_policy1  s    

z$TestMessageAPI.test_as_string_policyc          	   C   s„   |   d¡}tdƒ}| ¡  d¡}W d Q R X |  |t|ƒ¡ |jdd}| d¡}|  |d  	d¡¡ |  |d 
|dd … ¡¡ d S )	Nz
msg_01.txtrr   T)rŒ   ó   
r   s   From rT   )r-   r"   rh   rs   r,   ÚbytesÚas_bytesrŽ   r   r   r’   )r/   r1   rl   rB   r“   r”   r2   r2   r3   Útest_as_bytes:  s    


zTestMessageAPI.test_as_bytesc             C   sT   |   d¡}|jjdd}|j|d}tƒ }t||d}| |¡ |  || ¡ ¡ d S )Nz
msg_01.txtz
)r–   )r—   )	r-   r—   r˜   r   r   r   rj   r,   rk   )r/   r1   r™   r“   rƒ   r„   r2   r2   r3   Útest_as_bytes_policyD  s    

z#TestMessageAPI.test_as_bytes_policyc             C   s    t  d¡}|  | d¡d¡ d S )NzContent-Type: blarg; baz; boo
Úbazr'   )rt   Úmessage_from_stringr,   r9   )r/   r1   r2   r2   r3   Útest_bad_paramN  s    
zTestMessageAPI.test_bad_paramc             C   s   t  d¡}|  | ¡ d ¡ d S )Nz
From: foo
)rt   r¡   r,   rP   )r/   r1   r2   r2   r3   Útest_missing_filenameR  s    
z$TestMessageAPI.test_missing_filenamec             C   s   t  d¡}|  | ¡ d¡ d S )Nz%Content-Disposition: blarg; filename
r'   )rt   r¡   r,   rP   )r/   r1   r2   r2   r3   Útest_bogus_filenameV  s    z"TestMessageAPI.test_bogus_filenamec             C   s   t  d¡}|  | ¡ d ¡ d S )Nz
From: foo
)rt   r¡   r,   rZ   )r/   r1   r2   r2   r3   Útest_missing_boundary[  s    
z$TestMessageAPI.test_missing_boundaryc             C   s~   | j }t d¡}||jdddddgƒ t d¡}||jdddd	d
gƒ || ¡ d ƒ t d¡}||jdddd	d
gƒ d S )Nz&X-Header: foo=one; bar=two; baz=three
zx-header)rb   )r~   Úone)ÚbarÚtwo)r    Úthreez X-Header: foo; bar=one; baz=two
)r~   r'   )r§   r¦   )r    r¨   z"X-Header: foo; bar="one"; baz=two
)r,   rt   r¡   Ú
get_params)r/   r0   r1   r2   r2   r3   Útest_get_params_  s    zTestMessageAPI.test_get_paramsc             C   s$   t ƒ }d|d< |  | d¡d¡ d S )Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"zContent-TypeÚboundaryZCPIMSSMTPC06p5f3tG)r   r,   r9   )r/   r1   r2   r2   r3   Útest_get_param_liberalp  s    z%TestMessageAPI.test_get_param_liberalc             C   s’   | j }t d¡}||jddddƒ ||jdddd ƒ || d¡d ƒ t d¡}||jdddd	ƒ ||jdddd
ƒ ||jddddƒ d S )Nz&X-Header: foo=one; bar=two; baz=three
r§   zx-header)rb   r¨   Zquuzz"X-Header: foo; bar="one"; baz=two
r~   r'   r¦   r    )r,   rt   r¡   r9   )r/   r0   r1   r2   r2   r3   Útest_get_paramu  s    zTestMessageAPI.test_get_paramc             C   s&   |   d¡}|  | d¡ d¡d¡ d S )Nz
msg_22.txtrT   Únamez
wibble.JPG)r-   r,   rA   r9   )r/   r1   r2   r2   r3   Ú'test_get_param_funky_continuation_lines‡  s    
z6TestMessageAPI.test_get_param_funky_continuation_linesc             C   s6   t  d¡}|  | d¡d¡ |  |jdddd¡ d S )Nz4Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"
r¯   zJim&amp;&amp;JillF)Úunquotez"Jim&amp;&amp;Jill")rt   r¡   r,   r9   )r/   r1   r2   r2   r3   Ú#test_get_param_with_semis_in_quotesŒ  s
    z2TestMessageAPI.test_get_param_with_semis_in_quotesc             C   s<   t  d¡}|  | d¡d¡ t  d¡}|  | d¡d¡ d S )Nz5Content-Type: foo; bar*0="baz\"foobar"; bar*1="\"baz"r§   zbaz"foobar"baz)rt   r¡   r,   r9   )r/   r1   r2   r2   r3   Útest_get_param_with_quotes”  s    z)TestMessageAPI.test_get_param_with_quotesc             C   s>   t  d¡}|  d|¡ |  d|¡ |  d|¡ |  d|¡ d S )NzHeader: existsrb   r	   ZHEADERZheaderx)rt   r¡   rŠ   ÚassertNotIn)r/   r1   r2   r2   r3   Útest_field_containmentœ  s
    
z%TestMessageAPI.test_field_containmentc             C   s¬   | j }tƒ }| dd¡ || d¡dƒ | dd¡ || d¡dƒ ||jddddƒ || ¡ dd	d
gƒ ||jdddddgƒ |jdddd ||jddddƒ d S )Nr5   ziso-2022-jpÚ
importancez
high valueF)r±   z"high value")z
text/plainr'   )r5   ziso-2022-jp)r¶   z
high value)r5   z"iso-2022-jp")r¶   z"high value"ziso-9999-xxzX-Jimmy)rb   )r,   r   Ú	set_paramr9   rª   )r/   r0   r1   r2   r2   r3   Útest_set_param£  s    
zTestMessageAPI.test_set_paramc             C   sr   | j }|  d¡}|| ¡ dddgƒ | d¡}| d¡ || ¡ ddgƒ | d|¡ || ¡ ddd|fgƒ d S )Nz
msg_05.txt)zmultipart/reportr'   )zreport-typezdelivery-status)r¬   z%D1690A7AC1.996856090/mail.example.comzreport-type)r,   r-   rª   r9   Ú	del_paramr·   )r/   r0   r1   Zold_valr2   r2   r3   Útest_del_param´  s    


zTestMessageAPI.test_del_paramc             C   s6   t ƒ }|jdddd | dd¡ |  |d d¡ d S )NzContent-DispositionÚ
attachmentzbud.gif)Úfilenamer¼   zcontent-disposition)r   Ú
add_headerr¹   r,   )r/   r1   r2   r2   r3   Útest_del_param_on_other_headerÅ  s    z-TestMessageAPI.test_del_param_on_other_headerc             C   s   t ƒ }| dd¡ d S )Nr¼   zcontent-disposition)r   r¹   )r/   r1   r2   r2   r3   Ú$test_del_param_on_nonexistent_headerË  s    z3TestMessageAPI.test_del_param_on_nonexistent_headerc             C   s@   t ƒ }|jdddd |d }|jddd |  |d |¡ d S )NzContent-Typez
text/plainzutf-8)r5   Úfoobar)rb   )r   r½   r¹   r,   )r/   r1   Zexisting_headerr2   r2   r3   Útest_del_nonexistent_paramÐ  s
    z)TestMessageAPI.test_del_nonexistent_paramc             C   sj   | j }tƒ }|  t|jd¡ | d¡ ||d dƒ | dd¡ ||d dƒ | d¡ ||d dƒ d S )	Nr‚   z
text/plainzcontent-typer5   zus-asciiztext/plain; charset="us-ascii"z	text/htmlztext/html; charset="us-ascii")r,   r   r`   Ú
ValueErrorÚset_typer·   )r/   r0   r1   r2   r2   r3   Útest_set_type×  s    

zTestMessageAPI.test_set_typec             C   s.   t ƒ }d|d< | dd¡ |  |d d¡ d S )Nz
text/plainzX-Content-Typezapplication/octet-streamzx-content-type)r   rÃ   r,   )r/   r1   r2   r2   r3   Útest_set_type_on_other_headerâ  s    z,TestMessageAPI.test_set_type_on_other_headerc             C   s   t ƒ }|  | ¡ d¡ d S )Nz
text/plain)r   r,   r8   )r/   r1   r2   r2   r3   Útest_get_content_type_missingè  s    z,TestMessageAPI.test_get_content_type_missingc             C   s$   t ƒ }| d¡ |  | ¡ d¡ d S )Nzmessage/rfc822)r   Úset_default_typer,   r8   )r/   r1   r2   r2   r3   Ú/test_get_content_type_missing_with_default_typeì  s    
z>TestMessageAPI.test_get_content_type_missing_with_default_typec             C   s$   |   d¡}|  | d¡ ¡ d¡ d S )Nz
msg_30.txtr   zmessage/rfc822)r-   r,   rA   r8   )r/   r1   r2   r2   r3   Ú+test_get_content_type_from_message_implicitñ  s    
z:TestMessageAPI.test_get_content_type_from_message_implicitc             C   s$   |   d¡}|  | d¡ ¡ d¡ d S )Nz
msg_28.txtr   zmessage/rfc822)r-   r,   rA   r8   )r/   r1   r2   r2   r3   Ú+test_get_content_type_from_message_explicitö  s    
z:TestMessageAPI.test_get_content_type_from_message_explicitc             C   s   |   d¡}|  | ¡ d¡ d S )Nz
msg_03.txtz
text/plain)r-   r,   r8   )r/   r1   r2   r2   r3   Ú6test_get_content_type_from_message_text_plain_implicitû  s    
zETestMessageAPI.test_get_content_type_from_message_text_plain_implicitc             C   s   |   d¡}|  | ¡ d¡ d S )Nz
msg_01.txtz
text/plain)r-   r,   r8   )r/   r1   r2   r2   r3   Ú6test_get_content_type_from_message_text_plain_explicitÿ  s    
zETestMessageAPI.test_get_content_type_from_message_text_plain_explicitc             C   s   t ƒ }|  | ¡ d¡ d S )Nr‚   )r   r,   Úget_content_maintype)r/   r1   r2   r2   r3   Ú!test_get_content_maintype_missing  s    z0TestMessageAPI.test_get_content_maintype_missingc             C   s$   t ƒ }| d¡ |  | ¡ d¡ d S )Nzmessage/rfc822Úmessage)r   rÇ   r,   rÍ   )r/   r1   r2   r2   r3   Ú3test_get_content_maintype_missing_with_default_type  s    
zBTestMessageAPI.test_get_content_maintype_missing_with_default_typec             C   s$   |   d¡}|  | d¡ ¡ d¡ d S )Nz
msg_30.txtr   rÏ   )r-   r,   rA   rÍ   )r/   r1   r2   r2   r3   Ú/test_get_content_maintype_from_message_implicit  s    
z>TestMessageAPI.test_get_content_maintype_from_message_implicitc             C   s$   |   d¡}|  | d¡ ¡ d¡ d S )Nz
msg_28.txtr   rÏ   )r-   r,   rA   rÍ   )r/   r1   r2   r2   r3   Ú/test_get_content_maintype_from_message_explicit  s    
z>TestMessageAPI.test_get_content_maintype_from_message_explicitc             C   s   |   d¡}|  | ¡ d¡ d S )Nz
msg_03.txtr‚   )r-   r,   rÍ   )r/   r1   r2   r2   r3   Ú:test_get_content_maintype_from_message_text_plain_implicit  s    
zITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitc             C   s   |   d¡}|  | ¡ d¡ d S )Nz
msg_01.txtr‚   )r-   r,   rÍ   )r/   r1   r2   r2   r3   Ú:test_get_content_maintype_from_message_text_plain_explicit  s    
zITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitc             C   s   t ƒ }|  | ¡ d¡ d S )NÚplain)r   r,   Úget_content_subtype)r/   r1   r2   r2   r3   Ú test_get_content_subtype_missing  s    z/TestMessageAPI.test_get_content_subtype_missingc             C   s$   t ƒ }| d¡ |  | ¡ d¡ d S )Nzmessage/rfc822Úrfc822)r   rÇ   r,   rÖ   )r/   r1   r2   r2   r3   Ú2test_get_content_subtype_missing_with_default_type   s    
zATestMessageAPI.test_get_content_subtype_missing_with_default_typec             C   s$   |   d¡}|  | d¡ ¡ d¡ d S )Nz
msg_30.txtr   rØ   )r-   r,   rA   rÖ   )r/   r1   r2   r2   r3   Ú.test_get_content_subtype_from_message_implicit%  s    
z=TestMessageAPI.test_get_content_subtype_from_message_implicitc             C   s$   |   d¡}|  | d¡ ¡ d¡ d S )Nz
msg_28.txtr   rØ   )r-   r,   rA   rÖ   )r/   r1   r2   r2   r3   Ú.test_get_content_subtype_from_message_explicit)  s    
z=TestMessageAPI.test_get_content_subtype_from_message_explicitc             C   s   |   d¡}|  | ¡ d¡ d S )Nz
msg_03.txtrÕ   )r-   r,   rÖ   )r/   r1   r2   r2   r3   Ú9test_get_content_subtype_from_message_text_plain_implicit-  s    
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitc             C   s   |   d¡}|  | ¡ d¡ d S )Nz
msg_01.txtrÕ   )r-   r,   rÖ   )r/   r1   r2   r2   r3   Ú9test_get_content_subtype_from_message_text_plain_explicit1  s    
zHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitc             C   s"   t ƒ }d|d< |  | ¡ d¡ d S )Nzno-slash-in-this-stringzContent-Typer‚   )r   r,   rÍ   )r/   r1   r2   r2   r3   Útest_get_content_maintype_error5  s    z.TestMessageAPI.test_get_content_maintype_errorc             C   s"   t ƒ }d|d< |  | ¡ d¡ d S )Nzno-slash-in-this-stringzContent-TyperÕ   )r   r,   rÖ   )r/   r1   r2   r2   r3   Útest_get_content_subtype_error:  s    z-TestMessageAPI.test_get_content_subtype_errorc             C   sæ   | j }tƒ }| dd¡ | dd¡ | dd¡ || ¡ dddgƒ || ¡ dddgƒ | dd¡ || ¡ dddgƒ || ¡ dddgƒ | dd¡ | dd	¡ || ¡ ddddgƒ || ¡ d	dddgƒ |  t|jd
d¡ d S )NÚFirstÚOneÚSecondÚTwoZThirdZThreeZTwentyZElevenzOne HundredZFourthZMissing)r,   r   r½   ÚkeysÚvaluesÚreplace_headerr`   ÚKeyError)r/   r0   r1   r2   r2   r3   Útest_replace_header?  s    z"TestMessageAPI.test_replace_headerc             C   sp   t ƒ }|  | ¡ ¡ |jdddd |  | ¡ d¡ | dd¡ |  | ¡ d¡ | dd¡ |  | ¡ d¡ d S )NzContent-Dispositionr»   z
random.avi)r¼   ÚinlineZInlinE)r   ÚassertIsNoneÚget_content_dispositionr½   r,   ræ   )r/   r1   r2   r2   r3   Útest_get_content_dispositionP  s    z+TestMessageAPI.test_get_content_dispositionc             C   sP   d}t ƒ }d|d< d|d< | |¡ |  |jddd¡ |  |jd	 tj¡ d S )
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midizcontent-typer?   zcontent-transfer-encodingT)r@   s    éÐþÿÿ.‹À¡ pö¿ér   )r   r=   r,   rA   ÚassertIsInstanceÚdefectsr   ÚInvalidBase64CharactersDefect)r/   Úxr1   r2   r2   r3   Útest_broken_base64_payload\  s    
z)TestMessageAPI.test_broken_base64_payloadc             C   sB   d}t ƒ }d|d< d|d< | |¡ |  |jddt|dƒ¡ d S )	Nu   this is a brÃ¶ken thing to doz
text/plainzcontent-typerD   zcontent-transfer-encodingT)r@   zraw-unicode-escape)r   r=   r,   rA   rœ   )r/   rð   r1   r2   r2   r3   Útest_broken_unicode_payloadh  s    
z*TestMessageAPI.test_broken_unicode_payloadc             C   s>   d  d¡}tƒ }d|d< d|d< ||_|  |jdd|¡ d S )	Nu#   this is a quÃ©stionable thing to dozutf-8ztext/plain; charset="utf-8"zcontent-typerD   zcontent-transfer-encodingT)r@   )rs   r   Ú_payloadr,   rA   )r/   rð   r1   r2   r2   r3   Útest_questionable_bytes_payloads  s    
z.TestMessageAPI.test_questionable_bytes_payloadc             C   s*   t ƒ }|jdddd |  d|d ¡ d S )NzContent-Dispositionr»   zbud.gif)r¼   zattachment; filename="bud.gif")r   r½   r,   )r/   r1   r2   r2   r3   Útest_ascii_add_header~  s
    z$TestMessageAPI.test_ascii_add_headerc             C   s*   t ƒ }|jdddd |  d|d ¡ d S )NzContent-Dispositionr»   u   FuÃŸballer.ppt)r¼   z/attachment; filename*=utf-8''Fu%C3%9Fballer.ppt)r   r½   r,   )r/   r1   r2   r2   r3   Útest_noascii_add_header…  s    z&TestMessageAPI.test_noascii_add_headerc             C   s*   t ƒ }|jdddd |  d|d ¡ d S )NzContent-Dispositionr»   )z
iso-8859-1r'   u   FuÃŸballer.ppt)r¼   z1attachment; filename*=iso-8859-1''Fu%DFballer.ppt)r   r½   r,   )r/   r1   r2   r2   r3   Ú#test_nonascii_add_header_via_triple  s    z2TestMessageAPI.test_nonascii_add_header_via_triplec             C   s*   t ƒ }|jdddd |  d|d ¡ d S )NzContent-Dispositionr»   zwindows [filename].ppt)r¼   z-attachment; filename="windows [filename].ppt")r   r½   r,   )r/   r1   r2   r2   r3   Ú#test_ascii_add_header_with_tspecial•  s    z2TestMessageAPI.test_ascii_add_header_with_tspecialc             C   s*   t ƒ }|jdddd |  d|d ¡ d S )NzContent-Dispositionr»   u   FuÃŸballer [filename].ppt)r¼   z@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt)r   r½   r,   )r/   r1   r2   r2   r3   Ú&test_nonascii_add_header_with_tspecial  s    z5TestMessageAPI.test_nonascii_add_header_with_tspecialc             C   sP   xJdD ]B}t ƒ }d| |d< d|d< | d¡ |  |jddd	d
| ¡ qW d S )N)zlatin-1rr   ztext/plain; charset=%szcontent-typezquoted-printablezcontent-transfer-encodings   foo=e6=96=87barT)r@   s	   fooæ–‡barz1get_payload returns wrong result with charset %s.)r   r=   r,   rA   )r/   r5   r1   r2   r2   r3   Útest_binary_quopri_payload¥  s    


z)TestMessageAPI.test_binary_quopri_payloadc             C   sP   xJdD ]B}t ƒ }d| |d< d|d< | d¡ |  |jddd	d
| ¡ qW d S )N)zlatin-1rr   ztext/plain; charset=%szcontent-typer?   zcontent-transfer-encodings   Zm9v5paHYmFyT)r@   s	   fooæ–‡barz1get_payload returns wrong result with charset %s.)r   r=   r,   rA   )r/   r5   r1   r2   r2   r3   Útest_binary_base64_payload°  s    


z)TestMessageAPI.test_binary_base64_payloadc          
   C   sf   x`dD ]X}xRdD ]J}t ƒ }d| |d< ||d< | d¡ |  |jddd	td
ƒ ||¡¡ qW qW d S )N)zlatin-1rr   )z
x-uuencoder|   r}   zx-uueztext/plain; charset=%szcontent-typezcontent-transfer-encodings    begin 666 -
)9F]OYI:'8F%R
 
end
T)r@   s	   fooæ–‡bar)z!get_payload returns wrong result z"with charset {0} and encoding {1}.)r   r=   r,   rA   r   Úformat)r/   r5   Úencodingr1   r2   r2   r3   Útest_binary_uuencode_payload»  s    



z+TestMessageAPI.test_binary_uuencode_payloadc             C   s*   t ƒ }|jddd d |  d|d ¡ d S )NzContent-Dispositionré   )Úfoo_barzinline; foo-bar)r   r½   r,   )r/   r1   r2   r2   r3   Ú$test_add_header_with_name_only_paramÉ  s    z3TestMessageAPI.test_add_header_with_name_only_paramc             C   s&   t ƒ }| dd ¡ |  d|d ¡ d S )NzX-Statusr'   )r   r½   r,   )r/   r1   r2   r2   r3   Útest_add_header_with_no_valueÎ  s    z,TestMessageAPI.test_add_header_with_no_valuec             C   s&   t ƒ }tdƒ|d< |  tj|j¡ d S )Nzdummy
X-Injected-Header: testÚDummy)r   r	   r`   r   ra   rf   )r/   r1   r2   r2   r3   Ú(test_embedded_header_via_Header_rejectedÕ  s    z7TestMessageAPI.test_embedded_header_via_Header_rejectedc             C   s"   t ƒ }d|d< |  tj|j¡ d S )Nzdummy
X-Injected-Header: testr  )r   r`   r   ra   rf   )r/   r1   r2   r2   r3   Ú(test_embedded_header_via_string_rejectedÚ  s    z7TestMessageAPI.test_embedded_header_via_string_rejectedc             C   s*   t dƒ}d|d< |  t|ƒt d¡¡ d S )Nzabc
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
            )r   r,   r   ÚtextwrapÚdedent)r/   Úmr2   r2   r3   Ú-test_unicode_header_defaults_to_utf8_encodingß  s    z<TestMessageAPI.test_unicode_header_defaults_to_utf8_encodingc             C   s"   t dƒ}|  t|ƒt d¡¡ d S )Nu   Ã‰ testabc
z¬            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: base64

            w4kgdGVzdGFiYwo=
            )r   r,   r   r  r  )r/   r  r2   r2   r3   Ú+test_unicode_body_defaults_to_utf8_encodingì  s    z:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)VÚ__name__Ú
__module__Ú__qualname__r4   r;   r<   r>   rC   rF   rG   rH   rL   rO   rW   rX   r[   rd   rg   rq   rx   r{   r€   r   r…   r‹   r•   rš   rž   rŸ   r¢   r£   r¤   r¥   r«   r­   r®   r°   r²   r³   rµ   r¸   rº   r¾   r¿   rÁ   rÄ   rÅ   rÆ   rÈ   rÉ   rÊ   rË   rÌ   rÎ   rÐ   rÑ   rÒ   rÓ   rÔ   r×   rÙ   rÚ   rÛ   rÜ   rÝ   rÞ   rß   rè   rì   rñ   rò   rô   rõ   rö   r÷   rø   rù   rú   rû   rþ   r   r  r  r  r	  r
  r2   r2   r2   r3   r)   5   s¦   			

	

r)   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestEncodersc          	   C   s\   t ddƒ}| ¡ }W d Q R X tjj |¡}| ¡ }| d¡}|  t	dd„ |D ƒƒd¡ d S )NzPyBanner048.gifÚrbr&   c             S   s   g | ]}t |ƒ‘qS r2   )Úlen)rQ   rð   r2   r2   r3   rS     s    z;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>éL   )
r"   rh   rt   ÚmimeÚimager   rA   rŽ   ÚassertLessEqualÚmax)r/   rl   ÚbindataZmimedZbase64edr”   r2   r2   r3   Útest_EncodersEncode_base64û  s    
z'TestEncoders.test_EncodersEncode_base64c             C   s(   | j }tƒ }| d¡ ||d dƒ d S )Nzus-asciizcontent-transfer-encodingÚ7bit)r,   r   r7   )r/   r0   r1   r2   r2   r3   Útest_encode_empty_payload  s    
z&TestEncoders.test_encode_empty_payloadc             C   sP   | j }tdƒ}||d dƒ tdƒ}||d dƒ tddd}||d dƒ d S )	Nzhello worldzcontent-transfer-encodingr  u   hello Ã¸ worldr?   z
iso-8859-1)Ú_charsetzquoted-printable)r,   r   )r/   r0   r1   r2   r2   r3   Útest_default_cte
  s    zTestEncoders.test_default_ctec             C   s8   | j }tddd}||d dƒ || ¡ t d¡ƒ d S )Nu   æ–‡
zeuc-jp)r  zcontent-transfer-encodingr  z¨            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r,   r   rf   r  r  )r/   r0   r1   r2   r2   r3   Útest_encode7or8bit  s
    zTestEncoders.test_encode7or8bitc             C   s&   t dddƒ}|  t|ƒt d¡¡ d S )Nu   Ã¡Ã¶
r‚   z
ISO-8859-1z°            MIME-Version: 1.0
            Content-Type: text/text; charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            =E1=F6
            )r   r,   r   r  r  )r/   r1   r2   r2   r3   Útest_qp_encode_latin1%  s    z"TestEncoders.test_qp_encode_latin1c             C   s&   t dddƒ}|  t|ƒt d¡¡ d S )Nu   Å¼
r‚   z
ISO-8859-2z­            MIME-Version: 1.0
            Content-Type: text/text; charset="iso-8859-2"
            Content-Transfer-Encoding: quoted-printable

            =BF
            )r   r,   r   r  r  )r/   r1   r2   r2   r3   Útest_qp_encode_non_latin1/  s    z&TestEncoders.test_qp_encode_non_latin1N)	r  r  r  r  r  r  r  r  r  r2   r2   r2   r3   r  ù  s   	
r  c               @   sH  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd: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*dS )PÚTestLongHeadersNc             C   s:   | j }t d¡}tƒ }t|ƒ}| |¡ || ¡ dƒ d S )NzºSubject: bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text

test
)ÚndiffAssertEqualrt   r¡   r   r   rj   rk   )r/   r0   r1   Úsfpr„   r2   r2   r3   Útest_split_long_continuation@  s    
z,TestLongHeaders.test_split_long_continuationc             C   sF   | j }d}t|dd}|| ¡ dƒ t| dd¡ƒ}|| ¡ dƒ d S )Nzªbug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more textú	)Úcontinuation_wsr(   zªbug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)r   r	   rs   Úreplace)r/   r0   ÚhstrÚhr2   r2   r3   Ú,test_another_long_almost_unsplittable_headerT  s    z<TestLongHeaders.test_another_long_almost_unsplittable_headerc             C   sš   | j }tdƒ}tdƒ}tdƒ}d}d}d}t||dd}| ||¡ | ||¡ tƒ }	||	d< tƒ }
t|
ƒ}| |	¡ ||
 ¡ d	ƒ ||j	d
ddƒ d S )Nz
iso-8859-1z
iso-8859-2zutf-8s©   Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an südlündischen Wandgemälden vorbei, gegen die rotierenden Klingen befördert. s;   Finanèni metropole se hroutily pod tlakem jejich dùvtipu.. uø   æ­£ç¢ºã«è¨€ã†ã¨ç¿»è¨³ã¯ã•ã‚Œã¦ã„ã¾ã›ã‚“ã€‚ä¸€éƒ¨ã¯ãƒ‰ã‚¤ãƒ„èªžã§ã™ãŒã€ã‚ã¨ã¯ã§ãŸã‚‰ã‚ã§ã™ã€‚å®Ÿéš›ã«ã¯ã€ŒWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.ã€ã¨è¨€ã£ã¦ã„ã¾ã™ã€‚r  )Úheader_namea!  Subject: =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderb?=
 =?iso-8859-1?q?and_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen?=
 =?iso-8859-1?q?_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef?=
 =?iso-8859-1?q?=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hrouti?=
 =?iso-8859-2?q?ly_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
 =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC5LiA?=
 =?utf-8?b?6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn44Gf44KJ?=
 =?utf-8?b?44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFzIE51bnN0dWNr?=
 =?utf-8?b?IGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWloZXJodW5kIGRhcyBPZGVyIGRp?=
 =?utf-8?b?ZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI3jgajoqIDjgaPjgabjgYTjgb7jgZk=?=
 =?utf-8?b?44CC?=

r  )Ú
maxlinelena	  =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerde?=
 =?iso-8859-1?q?rband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndis?=
 =?iso-8859-1?q?chen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klinge?=
 =?iso-8859-1?q?n_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se?=
 =?iso-8859-2?q?_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
 =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb?=
 =?utf-8?b?44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go?=
 =?utf-8?b?44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBp?=
 =?utf-8?b?c3QgZGFzIE51bnN0dWNrIGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWlo?=
 =?utf-8?b?ZXJodW5kIGRhcyBPZGVyIGRpZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI0=?=
 =?utf-8?b?44Go6KiA44Gj44Gm44GE44G+44GZ44CC?=)
r   r   r	   Úappendr   r   r   rj   rk   rs   )r/   r0   r„   ÚczÚutf8Úg_headÚcz_headÚ	utf8_headr'  r1   r!  r2   r2   r3   Útest_long_nonstringe  s&    
z#TestLongHeaders.test_long_nonstringc             C   s$   | j }tddd}|| ¡ dƒ d S )Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnit)r)  zjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r   r	   rs   )r/   r0   r'  r2   r2   r3   Útest_long_header_encode›  s
    z'TestLongHeaders.test_long_header_encodec             C   s&   | j }tdddd}|| ¡ dƒ d S )Nziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitr#  )r)  r$  zjwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r   r	   rs   )r/   r0   r'  r2   r2   r3   Ú<test_long_header_encode_with_tab_continuation_is_just_a_hint¤  s    zLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hintc             C   s&   | j }tdddd}|| ¡ dƒ d S )Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-Foobar-Spoink-Defrobnitr#  )r)  r$  zjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey")r   r	   rs   )r/   r0   r'  r2   r2   r3   Ú-test_long_header_encode_with_tab_continuation®  s    z=TestLongHeaders.test_long_header_encode_with_tab_continuationc             C   s   t ddƒ}|  | ¡ d¡ d S )Nu   æ–‡zeuc-jpz=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	   r,   rs   )r/   r'  r2   r2   r3   Ú0test_header_encode_with_different_output_charset¸  s    
z@TestLongHeaders.test_header_encode_with_different_output_charsetc             C   s(   t d d¡dƒ}d}|  | ¡ |¡ d S )Ns6   test-ja ¤ØÅê¹Æ¤µ¤ì¤¿¥á¡¼¥ë¤Ï»Ê²ñ¼Ô¤Î¾µÇ§¤òÂÔ¤Ã¤Æ¤¤¤Þ¤¹zeuc-jpz‚=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r	   r@   r,   rs   )r/   r'  Úresr2   r2   r3   Ú5test_long_header_encode_with_different_output_charset¼  s    
zETestLongHeaders.test_long_header_encode_with_different_output_charsetc             C   s@   | j }tdƒ}d|d< tƒ }t|ƒ}| |¡ || ¡ dƒ d S )Nr'   ziwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"zX-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   r   r   r   rj   rk   )r/   r0   r1   r!  r„   r2   r2   r3   Útest_header_splitterÆ  s    
z$TestLongHeaders.test_header_splitterc             C   sd   | j }tƒ }d|d< t dd„ tdƒD ƒ¡|d< | d¡ tƒ }t|ƒ}| |¡ || 	¡ dƒ d S )	Nztest@dom.ainr†   c             s   s   | ]}d | V  qdS )z<%d@dom.ain>Nr2   )rQ   Úir2   r2   r3   ú	<genexpr>Þ  s    z@TestLongHeaders.test_no_semis_header_splitter.<locals>.<genexpr>é
   Ú
ReferencesÚTestzFrom: 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=   r   r   rj   rk   )r/   r0   r1   r!  r„   r2   r2   r3   Útest_no_semis_header_splitterÚ  s    

z-TestLongHeaders.test_no_semis_header_splitterc             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   Ú"test_last_split_chunk_does_not_fitê  s    z2TestLongHeaders.test_last_split_chunk_does_not_fitc             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   Ú=test_splittable_leading_char_followed_by_overlong_unsplitableó  s    zMTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplitablec             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   ÚFtest_multiple_splittable_leading_char_followed_by_overlong_unsplitableü  s    zVTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplitablec             C   s    | j }tdƒ}|| ¡ dƒ d S )NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;)r   r	   rs   )r/   r0   r'  r2   r2   r3   Ú/test_trailing_splitable_on_overlong_unsplitable  s    z?TestLongHeaders.test_trailing_splitable_on_overlong_unsplitablec             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   ÚFtest_trailing_splitable_on_overlong_unsplitable_with_leading_splitable  s    zVTestLongHeaders.test_trailing_splitable_on_overlong_unsplitable_with_leading_splitablec             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   Ú5test_long_header_with_multiple_sequential_split_chars  s    zETestLongHeaders.test_long_header_with_multiple_sequential_split_charsc             C   s    | j }tdƒ}|| ¡ dƒ d S )NzKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points)r   r	   rs   )r/   r0   r'  r2   r2   r3   Ú:test_splitter_split_on_punctuation_only_if_fws_with_header  s    zJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headerc             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   ÚDtest_leading_splittable_in_the_middle_just_before_overlong_last_part$  s    zTTestLongHeaders.test_leading_splittable_in_the_middle_just_before_overlong_last_partc             C   s    | j }tdƒ}|| ¡ dƒ d S )NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself )r   r	   rs   )r/   r0   r'  r2   r2   r3   Ú/test_overlong_last_part_followed_by_split_point/  s    z?TestLongHeaders.test_overlong_last_part_followed_by_split_pointc             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   Ú@test_multiline_with_overlong_parts_separated_by_two_split_points6  s    zPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointsc             C   s    | j }tdƒ}|| ¡ dƒ d S )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	   rs   )r/   r0   r'  r2   r2   r3   Ú>test_multiline_with_overlong_last_part_followed_by_split_pointA  s    zNTestLongHeaders.test_multiline_with_overlong_last_part_followed_by_split_pointc             C   s\   | j }tƒ }d|d< t dgd ¡|d< | d¡ tƒ }t|ƒ}| |¡ || ¡ dƒ d S )Nztest@dom.ainr†   z<foo@dom.ain>  r;  r<  r=  zÆFrom: test@dom.ain
References: <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>
   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>   <foo@dom.ain>
   <foo@dom.ain>   <foo@dom.ain>  

Test)	r   r   r>  r’   r=   r   r   rj   rk   )r/   r0   r1   r!  r„   r2   r2   r3   Ú%test_long_header_with_whitespace_runsL  s    

z5TestLongHeaders.test_long_header_with_whitespace_runsc             C   s`   | j }tƒ }d|d< t dgd ¡d |d< | d¡ tƒ }t|ƒ}| |¡ || ¡ dƒ d S )	Nztest@dom.ainr†   z<foo@dom.ain>r;  z; abcr<  r=  z·From: test@dom.ain
References: <foo@dom.ain> <foo@dom.ain> <foo@dom.ain> <foo@dom.ain>
 <foo@dom.ain> <foo@dom.ain> <foo@dom.ain> <foo@dom.ain> <foo@dom.ain>
 <foo@dom.ain>; abc

Test)	r   r   r>  r’   r=   r   r   rj   rk   )r/   r0   r1   r!  r„   r2   r2   r3   Ú'test_long_run_with_semi_header_splitter]  s    

z7TestLongHeaders.test_long_run_with_semi_header_splitterc             C   sP   | j }tƒ }d|d< d|d< | d¡ tƒ }t|ƒ}| |¡ || ¡ dƒ d S )Nztest@dom.ainr†   zKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr<  r=  zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r   r   r=   r   r   rj   rk   )r/   r0   r1   r!  r„   r2   r2   r3   Ú.test_splitter_split_on_punctuation_only_if_fwsn  s    

z>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fwsc             C   s:   | j }d}t|ƒ}|| ¡ dƒ tdƒ}|| ¡ dƒ d S )Nz\References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r   r	   rs   )r/   r0   r&  r'  r2   r2   r3   Útest_no_split_long_header€  s    z)TestLongHeaders.test_no_split_long_headerc             C   s(   | j }d}t|dd}|| ¡ dƒ d S )NaW  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$  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	   rs   )r/   r0   r&  r'  r2   r2   r3   Ú"test_splitting_multiple_long_linesŒ  s
    z2TestLongHeaders.test_splitting_multiple_long_linesc             C   s,   | j }d}t|dddd}|| ¡ dƒ d S )NzÞfrom modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93] helo=cthulhu.gerg.ca)
	by kronos.mems-exchange.org with esmtp (Exim 4.05)
	id 17k4h5-00034i-00
	for test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400éN   ZReceivedr#  )r*  r)  r$  zßfrom modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93]
 helo=cthulhu.gerg.ca)
	by kronos.mems-exchange.org with esmtp (Exim 4.05)
	id 17k4h5-00034i-00
	for test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400)r   r	   rs   )r/   r0   r&  r'  r2   r2   r3   Ú&test_splitting_first_line_only_is_long¢  s    z6TestLongHeaders.test_splitting_first_line_only_is_longc             C   sf   | j }tƒ }tdddd}| d¡ ||jdddƒ ||d< ||jdd	d
ƒ ||jdd	dƒ d S )NzBritische Regierung gibtz
iso-8859-1r  )r)  u-   grÃ¼nes Licht fÃ¼r Offshore-Windkraftprojekter  )r*  zl=?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offs?=
 =?iso-8859-1?q?hore-Windkraftprojekte?=)ÚmaxheaderlenzwSubject: =?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offs?=
 =?iso-8859-1?q?hore-Windkraftprojekte?=

r   zdSubject: =?iso-8859-1?q?Britische_Regierung_gibt_gr=FCnes_Licht_f=FCr_Offshore-Windkraftprojekte?=

)r   r   r	   r+  rs   rf   )r/   r0   r1   r'  r2   r2   r3   Útest_long_8bit_header²  s    
z%TestLongHeaders.test_long_8bit_headerc             C   sV   | j }tƒ }d}||d< ||jdddƒ tƒ }t|dd|d< ||jdddƒ d S )Nuh   Britische Regierung gibt grÃ¼nes Licht fÃ¼r Offshore-Windkraftprojekte <a-very-long-address@example.com>zReply-TorQ  )rS  zžReply-To: =?utf-8?q?Britische_Regierung_gibt_gr=C3=BCnes_Licht_f=C3=BCr_Offs?=
 =?utf-8?q?hore-Windkraftprojekte_=3Ca-very-long-address=40example=2Ecom=3E?=

)r)  )r   r   rf   r	   )r/   r0   r1   Zheader_stringr2   r2   r3   Ú test_long_8bit_header_no_charsetÆ  s    z0TestLongHeaders.test_long_8bit_header_no_charsetc             C   s.   | j }d}tƒ }||d< ||jdddƒ d S )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‰   rQ  )rS  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   r   rf   )r/   r0   r‡   r1   r2   r2   r3   Útest_long_to_headerÛ  s    z#TestLongHeaders.test_long_to_headerc             C   s2   | j }d}t|ƒ}| d¡ ||jdddƒ d S )NzIThis is an example of string which has almost the limit of header length.zAdd another line.r  )r*  z\This is an example of string which has almost the limit of header length.
 Add another line.)r   r	   r+  rs   )r/   r0   rƒ   r'  r2   r2   r3   Útest_long_line_after_appendì  s    
z+TestLongHeaders.test_long_line_after_appendc             C   s.   | j }d}t|ƒ}| d¡ || ¡ dƒ d S )NzThis is a shorter line.z!Add another sentence. (Surprise?)z9This is a shorter line. Add another sentence. (Surprise?))r   r	   r+  rs   )r/   r0   rƒ   r'  r2   r2   r3   Útest_shorter_line_with_appendõ  s    
z-TestLongHeaders.test_shorter_line_with_appendc             C   s2   | j }d}d}t|d|d}||jdddƒ d S )Nz!X-Very-Very-Very-Long-Header-Nameu­   Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an sÃ¼dlÃ¼ndischen WandgemÃ¤lden vorbei, gegen die rotierenden Klingen befÃ¶rdert. z
iso-8859-1)r)  r  )r*  a  =?iso-8859-1?q?Die_Mieter_treten_hier_e?=
 =?iso-8859-1?q?in_werden_mit_einem_Foerderband_komfortabel_den_Korridor_e?=
 =?iso-8859-1?q?ntlang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei=2C_ge?=
 =?iso-8859-1?q?gen_die_rotierenden_Klingen_bef=F6rdert=2E_?=)r   r	   rs   )r/   r0   ÚfnZgsr'  r2   r2   r3   Útest_long_field_nameý  s    z$TestLongHeaders.test_long_field_namec             C   s:   d}t ƒ }t|dd|d< ||d< |  |jddd¡ d S )	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-2rQ  )rS  a1  Received-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

)r   r	   r   rf   )r/   r'  r1   r2   r2   r3   Útest_long_received_header  s    z)TestLongHeaders.test_long_received_headerc             C   s<   d}t ƒ }t|ddd|d< ||d< |  |jddd¡ d S )	Nz<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")z
Received-1r#  )r)  r$  z
Received-2rQ  )rS  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")

)r   r	   r   rf   )r/   r'  r1   r2   r2   r3   Útest_string_headerinst_eq  s    z)TestLongHeaders.test_string_headerinst_eqc             C   sJ   | j }tƒ }d}||d< t|dd|d< d| |d< ||jddd	ƒ d S )
Nz’iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1zFace-2)r)  r(   zFace-3rQ  )rS  aØ  Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

)r   r   r	   rf   )r/   r0   r1   Útr2   r2   r3   Ú-test_long_unbreakable_lines_with_continuation1  s    z=TestLongHeaders.test_long_unbreakable_lines_with_continuationc             C   s*   | j }d}t |¡}||jdddƒ d S )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 -0700rQ  )rS  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   rt   r¡   rf   )r/   r0   r  r1   r2   r2   r3   Ú"test_another_long_multiline_headerI  s
    
z2TestLongHeaders.test_another_long_multiline_headerc             C   s>   | j }d}tƒ }||d< t|dd|d< ||jdddƒ d S )Nz¦List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>ÚList)r)  rQ  )rS  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   r   r	   rf   )r/   r0   r'  r1   r2   r2   r3   Ú%test_long_lines_with_different_headerV  s    z5TestLongHeaders.test_long_lines_with_different_headerc             C   s6   t t d¡ddd}|  | ¡ d t d¡d ¡ d S )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 workszutf-8r=  )r5   r)  r&   zü            =?utf-8?q?We=27re_going_to_pretend_this_header_is_in_a_non-ascii_chara?=
             =?utf-8?q?cter_set?=
             =?utf-8?q?_to_see_if_line_wrapping_with_encoded_words_and_embedded?=
             =?utf-8?q?_folding_white_space_works?=)r	   r  r  r,   rs   )r/   r'  r2   r2   r3   Ú*test_long_rfc2047_header_with_embedded_fwsi  s    z:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+r  r  r  ÚmaxDiffr"  r(  r1  r2  r3  r4  r5  r7  r8  r@  rA  rB  rC  rD  rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  rO  rP  rR  rT  rU  rV  rW  rX  rZ  r[  r\  r^  r_  ra  rb  r2   r2   r2   r3   r  <  sP   6	


					r  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestFromManglingc             C   s"   t ƒ | _d| jd< | j d¡ d S )Nzaaa@bbb.orgr†   z(From the desk of A.A.A.:
Blah blah blah
)r   r1   r=   )r/   r2   r2   r3   ÚsetUpz  s    
zTestFromMangling.setUpc             C   s2   t ƒ }t|dd}| | j¡ |  | ¡ d¡ d S )NT)Úmangle_from_z<From: aaa@bbb.org

>From the desk of A.A.A.:
Blah blah blah
)r   r   rj   r1   r,   rk   )r/   rƒ   r„   r2   r2   r3   Útest_mangled_from‚  s
    
z"TestFromMangling.test_mangled_fromc             C   s2   t ƒ }t|dd}| | j¡ |  | ¡ d¡ d S )NF)rf  z;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
)r   r   rj   r1   r,   rk   )r/   rƒ   r„   r2   r2   r3   Útest_dont_mangle_from  s
    
z&TestFromMangling.test_dont_mangle_fromc             C   sT   t ƒ }t|dd}t t d¡¡}| |¡ |  tdd„ | 	¡  
d¡D ƒƒd¡ d S )NT)rf  a)              From: foo@bar.com
            Mime-Version: 1.0
            Content-Type: multipart/mixed; boundary=XXX

            From somewhere unknown

            --XXX
            Content-Type: text/plain

            foo

            --XXX--

            From somewhere unknowable
            c             S   s   g | ]}|  d ¡rd‘qS )z>From rT   )r   )rQ   rð   r2   r2   r3   rS   ¬  s    zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r&   ry   )r   r   rt   r¡   r  r  rj   r,   r  rk   rŽ   )r/   rƒ   r„   r1   r2   r2   r3   Ú'test_mangle_from_in_preamble_and_epilog˜  s    
z8TestFromMangling.test_mangle_from_in_preamble_and_epilogc             C   sR   t  d¡ d¡}t |d ¡}tƒ }t|dd}| |¡ |  | 	¡ |d ¡ d S )Nz§            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: 8bit
            From: aaa@bbb.org

        zutf-8s   From RÃ¶lli
T)rf  s   >From RÃ¶lli
)
r  r  rs   rt   Úmessage_from_bytesr   r   rj   r,   rk   )r/   Úsourcer1   Úbr„   r2   r2   r3   Ú test_mangled_from_with_bad_bytes¯  s    
z1TestFromMangling.test_mangled_from_with_bad_bytesN)r  r  r  re  rg  rh  ri  rm  r2   r2   r2   r3   rd  y  s
   rd  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestMIMEAudioc          	   C   s0   t ddƒ}| ¡ | _W d Q R X t| jƒ| _d S )Nzaudiotest.aur  )r"   rh   Ú
_audiodatar   Ú_au)r/   rl   r2   r2   r3   re  À  s    zTestMIMEAudio.setUpc             C   s   |   | j ¡ d¡ d S )Nzaudio/basic)r,   rp  r8   )r/   r2   r2   r3   Útest_guess_minor_typeÅ  s    z#TestMIMEAudio.test_guess_minor_typec             C   s(   | j  ¡ }|  t t|dƒ¡| j¡ d S )Nrr   )rp  rA   r,   r?   Údecodebytesrœ   ro  )r/   Úpayloadr2   r2   r3   Útest_encodingÈ  s    
zTestMIMEAudio.test_encodingc             C   s    t | jdƒ}|  | ¡ d¡ d S )NÚfishz
audio/fish)r   ro  r,   r8   )r/   Úaur2   r2   r3   Útest_checkSetMinorÍ  s    z TestMIMEAudio.test_checkSetMinorc             C   s¾   | j }| jjdddd || jd dƒ || jjdddd	gƒ || jjd
dddƒ g }|| jjddddƒ |  | jjd|dd|¡ |  | j d|¡|¡ |  | jjd|dd|¡ d S )NzContent-Dispositionr»   zaudiotest.au)r¼   zcontent-dispositionz#attachment; filename="audiotest.au")rb   )r»   r'   )r¼   zaudiotest.aur¼   r'   r~   )Úfailobjrb   rÀ   )r,   rp  r½   rª   r9   ÚassertIs)r/   r0   Úmissingr2   r2   r3   Útest_add_headerÑ  s     


zTestMIMEAudio.test_add_headerN)r  r  r  re  rq  rt  rw  r{  r2   r2   r2   r3   rn  ¿  s
   rn  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestMIMEImagec          	   C   s0   t ddƒ}| ¡ | _W d Q R X t| jƒ| _d S )NzPyBanner048.gifr  )r"   rh   Ú_imgdatar   Ú_im)r/   rl   r2   r2   r3   re  è  s    zTestMIMEImage.setUpc             C   s   |   | j ¡ d¡ d S )Nz	image/gif)r,   r~  r8   )r/   r2   r2   r3   rq  í  s    z#TestMIMEImage.test_guess_minor_typec             C   s(   | j  ¡ }|  t t|dƒ¡| j¡ d S )Nrr   )r~  rA   r,   r?   rr  rœ   r}  )r/   rs  r2   r2   r3   rt  ð  s    
zTestMIMEImage.test_encodingc             C   s    t | jdƒ}|  | ¡ d¡ d S )Nru  z
image/fish)r   r}  r,   r8   )r/   Zimr2   r2   r3   rw  õ  s    z TestMIMEImage.test_checkSetMinorc             C   s¾   | j }| jjdddd || jd dƒ || jjdddd	gƒ || jjd
dddƒ g }|| jjddddƒ |  | jjd|dd|¡ |  | j d|¡|¡ |  | jjd|dd|¡ d S )NzContent-Dispositionr»   zdingusfish.gif)r¼   zcontent-dispositionz%attachment; filename="dingusfish.gif")rb   )r»   r'   )r¼   zdingusfish.gifr¼   r'   r~   )rx  rb   rÀ   )r,   r~  r½   rª   r9   ry  )r/   r0   rz  r2   r2   r3   r{  ù  s     


zTestMIMEImage.test_add_headerN)r  r  r  re  rq  rt  rw  r{  r2   r2   r2   r3   r|  ç  s
   r|  c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚTestMIMEApplicationc             C   s.   | j }tdƒ}|| ¡ dƒ ||d dƒ d S )Ns   úûüýþÿzapplication/octet-streamzcontent-transfer-encodingr?   )r,   r   r8   )r/   r0   r1   r2   r2   r3   Útest_headers  s    z TestMIMEApplication.test_headersc             C   s:   | j }d}t|ƒ}|| ¡  ¡ dƒ ||jdd|ƒ d S )Ns   úûüýþÿz+vv8/f7/T)r@   )r,   r   rA   Ústrip)r/   r0   Ú	bytesdatar1   r2   r2   r3   Ú	test_body  s
    zTestMIMEApplication.test_bodyc             C   s¸   d}t |tjd}|  | ¡ dt|ƒ ¡ |  |jdd|¡ |  |d d¡ tƒ }t|ƒ}| |¡ | 	¡ }t
 |¡}|  | ¡ dt|ƒ ¡ |  |jdd|¡ |  |d d¡ d S )Ns   úûüýþÿ)Ú_encoderu   ï¿½T)r@   zContent-Transfer-EncodingrD   )r   r   Úencode_7or8bitr,   rA   r  r   r   rj   rk   rt   rj  )r/   r‚  r1   rƒ   r„   ÚwireformÚmsg2r2   r2   r3   Ú$test_binary_body_with_encode_7or8bit  s    

z8TestMIMEApplication.test_binary_body_with_encode_7or8bitc             C   s˜   d}t |tjd}|  | ¡ dt|ƒ ¡ |  |jdd|¡ tƒ }t|ƒ}| |¡ | 	¡ }t
 |¡}|  | ¡ dt|ƒ ¡ |  |jdd|¡ d S )Ns   úûüýþÿ)r„  u   ï¿½T)r@   )r   r   Úencode_noopr,   rA   r  r   r   rj   rk   rt   rj  )r/   r‚  r1   rƒ   r„   r†  r‡  r2   r2   r3   Ú!test_binary_body_with_encode_noop/  s    

z5TestMIMEApplication.test_binary_body_with_encode_noopc             C   sh   d}t |tjd}|  |jdd|¡ tƒ }t|ƒ}| |¡ | ¡ }t	 
|¡}|  |jdd|¡ d S )Ns   úûüýþÿ)r„  T)r@   )r   r   r‰  r,   rA   r   r   rj   rk   rt   rj  )r/   r‚  r1   rƒ   r„   r†  r‡  r2   r2   r3   Ú0test_binary_body_with_unicode_linend_encode_noop@  s    

zDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noopc             C   s¨   d}t |tjd}|  | ¡ d¡ |  |jdd|¡ |  |d d¡ tƒ }t|ƒ}| |¡ | ¡ }t	 
|¡}|  | ¡ d¡ |  |jdd|¡ |  |d d¡ d S )Ns   úûüýþÿ )r„  z=FA=FB=FC=FD=FE=FF=20T)r@   zContent-Transfer-Encodingzquoted-printable)r   r   Úencode_quoprir,   rA   r   r   rj   rk   rt   rj  )r/   r‚  r1   rƒ   r„   r†  r‡  r2   r2   r3   Ú#test_binary_body_with_encode_quopriL  s    

z7TestMIMEApplication.test_binary_body_with_encode_quopric             C   sˆ   d}t |tjd}|  | ¡ d¡ |  |jdd|¡ tƒ }t|ƒ}| |¡ | ¡ }t	 
|¡}|  | ¡ d¡ |  |jdd|¡ d S )Ns   úûüýþÿ)r„  z	+vv8/f7/
T)r@   )r   r   Úencode_base64r,   rA   r   r   rj   rk   rt   rj  )r/   r‚  r1   rƒ   r„   r†  r‡  r2   r2   r3   Ú#test_binary_body_with_encode_base64\  s    

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
r  r  r  r€  rƒ  rˆ  rŠ  r‹  r  r  r2   r2   r2   r3   r    s   r  c               @   sV   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	e
 d¡dd„ ƒZdS )ÚTestMIMETextc             C   s   t dƒ| _d S )Nzhello there)r   Ú_msg)r/   r2   r2   r3   re  l  s    zTestMIMEText.setUpc             C   s`   | j }|| j ¡ dƒ || j d¡dƒ g }|  | j d|¡|¡ |  | jjd|dd|¡ d S )Nz
text/plainr5   zus-asciirÀ   )rb   )r,   r‘  r8   r9   ry  )r/   r0   rz  r2   r2   r3   Ú
test_typeso  s    zTestMIMEText.test_typesc             C   s&   |   | j ¡ d¡ |  | j ¡ ¡ d S )Nzhello there)r,   r‘  rA   ÚassertFalseÚis_multipart)r/   r2   r2   r3   Útest_payloadx  s    zTestMIMEText.test_payloadc             C   sz   | j }tddd}|| ¡ jdƒ ||d dƒ tdƒ}d |_td|d}|| ¡ jdƒ ||d dƒ || ¡ dƒ d S )Nzhello therezus-ascii)r  zcontent-typeztext/plain; charset="us-ascii"zutf-8ztext/plain; charset="utf-8")r,   r   r6   r:   r   rE   rA   )r/   r0   r1   r5   r2   r2   r3   Útest_charset|  s    zTestMIMEText.test_charsetc             C   s4   | j }tddd}|| ¡ jdƒ ||d dƒ d S )Nzhello therezus-ascii)r  zcontent-typeztext/plain; charset="us-ascii")r,   r   r6   r:   )r/   r0   r1   r2   r2   r3   Útest_7bit_input‰  s    zTestMIMEText.test_7bit_inputc             C   s>   | j }tdƒ}|| ¡ dƒ ||d dƒ |  d| ¡ ¡ d S )Nzhello therezus-asciizcontent-typeztext/plain; charset="us-ascii")r,   r   r6   rŠ   rf   )r/   r0   r1   r2   r2   r3   Útest_7bit_input_no_charset  s
    z'TestMIMEText.test_7bit_input_no_charsetc             C   sP   d}| j }t|dd}|| ¡ jdƒ ||d dƒ ||jdd| d¡ƒ d S )Nu   ÐºÐ¸Ñ€Ð¸Ð»Ð¸Ñ†Ð°zutf-8)r  zcontent-typeztext/plain; charset="utf-8"T)r@   )r,   r   r6   Úoutput_charsetrA   rs   )r/   Úteststrr0   r1   r2   r2   r3   Útest_utf8_input–  s    zTestMIMEText.test_utf8_inputzBcan't fix because of backward compat in email5, will fix in email6c             C   s   d}|   tt|¡ d S )Nu   ÐºÐ¸Ñ€Ð¸Ð»Ð¸Ñ†Ð°)r`   ÚUnicodeEncodeErrorr   )r/   rš  r2   r2   r3   Útest_utf8_input_no_charsetž  s    z'TestMIMEText.test_utf8_input_no_charsetN)r  r  r  re  r’  r•  r–  r—  r˜  r›  ÚunittestÚskipr  r2   r2   r2   r3   r  k  s   	r  c               @   s¬   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)S )*ÚTestMultipartc          	   C   sö   t ddƒ}| ¡ }W d Q R X tdddd}t|dd}|jd	d
dd tdƒ}| |¡ | |¡ d|d< d|d< d|d< d}t |¡}|d dkržtj	}ntj
}|dkr²d}	nd}	d|	|d f }
t dt |¡¡|
 |d< || _|| _|| _d S )NzPyBanner048.gifr  Ú	multipartÚmixedrY   )r¬   zdingusfish.gif)r¯   zcontent-dispositionr»   )r¼   z$Hi there,

This is the dingus fish.
zBarry <barry@digicool.com>r†   z)Dingus Lovers <cravindogs@cravindogs.com>r‰   zHere is your dingus fishr  gÊ4FÓcpÍAéÿÿÿÿr   ú-ú+z %s%04dé$   z%a, %d %b %Y %H:%M:%SÚDate)r"   rh   r   r   r½   r   rK   ÚtimeÚ	localtimeÚtimezoneÚaltzoneÚstrftimer‘  r~  Ú_txt)r/   rl   rB   Ú	containerr  ÚintroÚnowÚ	timetupleZtzsecsÚsignÚtzoffsetr2   r2   r3   re  ¨  s8    


zTestMultipart.setUpc             C   s°   | j }| j}| j}|  | ¡ ¡ || ¡ dƒ |t| ¡ ƒdƒ |t|jdƒ | d¡}| d¡}|  	|| j
¡ |  	|| j¡ || ¡ ||gƒ |  | ¡ ¡ |  | ¡ ¡ d S )Nzmultipart/mixedry   r   rT   )r,   r`   r‘  r   r”  r8   r  rA   Ú
IndexErrorry  r­  r~  r“  )r/   r0   Úraisesr  Zm0Úm1r2   r2   r3   Útest_hierarchyÌ  s    

zTestMultipart.test_hierarchyc             C   s$   d}t ƒ  |¡}|  || ¡ ¡ d S )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   ri   r   rf   )r/   r‚   r1   r2   r2   r3   Útest_empty_multipart_idempotentÞ  s    z-TestMultipart.test_empty_multipart_idempotentc             C   s@   t ddƒ}d|d< d|d< d|d< | d	¡ |  | ¡ d
¡ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   rY   zœContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY

--BOUNDARY--
)r   r]   r   rf   )r/   Úouterr2   r2   r3   Ú/test_no_parts_in_a_multipart_with_none_epilogueï  s    



z=TestMultipart.test_no_parts_in_a_multipart_with_none_epiloguec             C   sL   t ddƒ}d|d< d|d< d|d< d	|_d	|_| d
¡ |  | ¡ d¡ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   r'   rY   zContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY

--BOUNDARY--
)r   ÚpreambleÚepiloguer]   r   rf   )r/   r¹  r2   r2   r3   Ú0test_no_parts_in_a_multipart_with_empty_epilogue  s    


z>TestMultipart.test_no_parts_in_a_multipart_with_empty_epiloguec             C   sV   | j }tddƒ}d|d< d|d< d|d< | d	¡ td
ƒ}| |¡ || ¡ dƒ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   rY   zhello worlda  Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

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

hello world
--BOUNDARY--
)r   r   r]   r   rK   rf   )r/   r0   r¹  r1   r2   r2   r3   Útest_one_part_in_a_multipart  s    


z*TestMultipart.test_one_part_in_a_multipartc             C   s\   | j }tddƒ}d|d< d|d< d|d< d	|_td
ƒ}| |¡ | d¡ || ¡ dƒ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   r'   zhello worldrY   a  Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


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

hello world
--BOUNDARY--
)r   r   r»  r   rK   r]   rf   )r/   r0   r¹  r1   r2   r2   r3   Ú1test_seq_parts_in_a_multipart_with_empty_preamble/  s    


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamblec             C   s\   | j }tddƒ}d|d< d|d< d|d< d |_td	ƒ}| |¡ | d
¡ || ¡ dƒ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   zhello worldrY   a  Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

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

hello world
--BOUNDARY--
)r   r   r»  r   rK   r]   rf   )r/   r0   r¹  r1   r2   r2   r3   Ú0test_seq_parts_in_a_multipart_with_none_preambleK  s    


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamblec             C   s\   | j }tddƒ}d|d< d|d< d|d< d |_td	ƒ}| |¡ | d
¡ || ¡ dƒ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   zhello worldrY   a  Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

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

hello world
--BOUNDARY--
)r   r   r¼  r   rK   r]   rf   )r/   r0   r¹  r1   r2   r2   r3   Ú0test_seq_parts_in_a_multipart_with_none_epiloguef  s    


z>TestMultipart.test_seq_parts_in_a_multipart_with_none_epiloguec             C   s\   | j }tddƒ}d|d< d|d< d|d< d	|_td
ƒ}| |¡ | d¡ || ¡ dƒ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   r'   zhello worldrY   a  Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

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

hello world
--BOUNDARY--
)r   r   r¼  r   rK   r]   rf   )r/   r0   r¹  r1   r2   r2   r3   Ú1test_seq_parts_in_a_multipart_with_empty_epilogue  s    


z?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epiloguec             C   s\   | j }tddƒ}d|d< d|d< d|d< d	|_td
ƒ}| |¡ | d¡ || ¡ dƒ d S )Nr¡  r¢  z	A subjectr  zaperson@dom.ainr‰   zbperson@dom.ainr†   r&   zhello worldrY   a  Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

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

hello world
--BOUNDARY--

)r   r   r¼  r   rK   r]   rf   )r/   r0   r¹  r1   r2   r2   r3   Ú.test_seq_parts_in_a_multipart_with_nl_epilogueœ  s    


z<TestMultipart.test_seq_parts_in_a_multipart_with_nl_epiloguec             C   sš   | j }|  d¡}|t| ¡ ƒdƒ | d¡}|| ¡ dƒ |t| ¡ ƒdƒ xH| ¡ D ]<}|| ¡ dƒ |t| ¡ ƒdƒ | d¡}|| ¡ dƒ qVW d S )Nz
msg_36.txtry   rT   zmultipart/alternativezmessage/external-bodyr   z
text/plain)r,   r-   r  rA   r8   )r/   r0   r1   Úmsg1rV   Ú
subsubpartr2   r2   r3   Útest_message_external_body·  s    


z(TestMultipart.test_message_external_bodyc             C   s"   |   d¡}|  t| ¡ ƒd¡ d S )Nz
msg_37.txtrz   )r-   r,   r  rA   )r/   r1   r2   r2   r3   Útest_double_boundaryÄ  s    
z"TestMultipart.test_double_boundaryc             C   s4   | j }|  d¡}tƒ }t ||¡ || ¡ dƒ d S )Nz
msg_38.txtzŠmultipart/mixed
    multipart/mixed
        multipart/alternative
            text/plain
        text/plain
    text/plain
    text/plain
)r   r-   r   r   Ú
_structurerk   )r/   r0   r1   r!  r2   r2   r3   Ú)test_nested_inner_contains_outer_boundaryË  s    
z7TestMultipart.test_nested_inner_contains_outer_boundaryc             C   s4   | j }|  d¡}tƒ }t ||¡ || ¡ dƒ d S )Nz
msg_39.txtz“multipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
)r   r-   r   r   rÈ  rk   )r/   r0   r1   r!  r2   r2   r3   Útest_nested_with_same_boundaryÞ  s    
z,TestMultipart.test_nested_with_same_boundaryc             C   s   |   d¡}|  | ¡ d¡ d S )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,   rf   )r/   r1   r2   r2   r3   Útest_boundary_in_non_multipartï  s    

z,TestMultipart.test_boundary_in_non_multipartc             C   sB   | j }t d¡}|  | ¡ ¡ || ¡ dƒ |t| ¡ ƒdƒ d S )NzžMIME-Version: 1.0
Content-Type: multipart/mixed; boundary="    XXXX"

--    XXXX
Content-Type: text/plain


--    XXXX
Content-Type: text/plain

--    XXXX--
z    XXXXry   )r,   rt   r¡   r   r”  rZ   r  rA   )r/   r0   r1   r2   r2   r3   Ú test_boundary_with_leading_spaceþ  s    z.TestMultipart.test_boundary_with_leading_spacec             C   s&   t ƒ  d¡}|  | d¡ ¡ d¡ d S )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==--r   zYXNkZg==)r   ri   r,   rA   )r/   r  r2   r2   r3   Ú&test_boundary_without_trailing_newline  s    
z4TestMultipart.test_boundary_without_trailing_newlinec             C   s    t ddƒ}|  |jtjj¡ d S )Nr¡  r¢  )r   ry  r—   rt   Úcompat32)r/   r  r2   r2   r3   Útest_mimebase_default_policy  s    
z*TestMultipart.test_mimebase_default_policyc             C   s(   t ddtjjd}|  |jtjj¡ d S )Nr¡  r¢  )r—   )r   rt   r—   Údefaultry  )r/   r  r2   r2   r3   Útest_mimebase_custom_policy#  s    z)TestMultipart.test_mimebase_custom_policyN)r  r  r  re  r·  r¸  rº  r½  r¾  r¿  rÀ  rÁ  rÂ  rÃ  rÆ  rÇ  rÉ  rÊ  rË  rÌ  rÍ  rÏ  rÑ  r2   r2   r2   r3   r   §  s(   $r   c               @   s~   e Zd Zdd„ Zdd„ Zdd„ Ze d¡Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestNonConformantc             C   s>   | j }|  d¡}|| ¡ dƒ || ¡ dƒ || ¡ dƒ d S )Nz
msg_14.txtz
text/plainr‚   rÕ   )r,   r-   r8   rÍ   rÖ   )r/   r0   r1   r2   r2   r3   Útest_parse_missing_minor_type*  s
    
z/TestNonConformant.test_parse_missing_minor_typec             C   sN   |   d¡}| d¡}|  t|dƒ¡ |  t|jƒd¡ |  |jd tj	¡ d S )Nz
msg_15.txtr   rî   rT   )
r-   rA   r   Úhasattrr,   r  rî   rí   r   ÚStartBoundaryNotFoundDefect)r/   r1   Úinnerr2   r2   r3   Útest_same_boundary_inner_outer2  s    

z0TestNonConformant.test_same_boundary_inner_outerc             C   sX   |   d¡}|  | ¡ t¡ |  t|jƒd¡ |  |jd tj¡ |  |jd tj	¡ d S )Nz
msg_25.txtry   r   rT   )
r-   rí   rA   r   r,   r  rî   r   ÚNoBoundaryInMultipartDefectÚ!MultipartInvariantViolationDefect)r/   r1   r2   r2   r3   Útest_multipart_no_boundary<  s    
z,TestNonConformant.test_multipart_no_boundarya^          Date: Wed, 14 Nov 2007 12:56:23 GMT
        From: foo@bar.invalid
        To: foo@bar.invalid
        Subject: Content-Transfer-Encoding: base64 and multipart
        MIME-Version: 1.0
        Content-Type: multipart/mixed;
            boundary="===============3344438784458119861=="{}

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

        Test message

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

        YWJj

        --===============3344438784458119861==--
        c             C   s<   |   | j d¡¡}|  t|jƒd¡ |  |jd tj¡ d S )Nz"
Content-Transfer-Encoding: base64rT   r   )	Ú_str_msgÚmultipart_msgrü   r,   r  rî   rí   r   Ú-InvalidMultipartContentTransferEncodingDefect)r/   r1   r2   r2   r3   Útest_multipart_invalid_cte]  s
    z,TestNonConformant.test_multipart_invalid_ctec             C   s(   |   | j d¡¡}|  t|jƒd¡ d S )Nr'   r   )rÛ  rÜ  rü   r,   r  rî   )r/   r1   r2   r2   r3   Útest_multipart_no_cte_no_defecte  s    z1TestNonConformant.test_multipart_no_cte_no_defectc             C   s<   x6dD ].}|   | j d |¡¡¡}|  t|jƒd¡ qW d S )N)r  rD   ZBINaryz
Content-Transfer-Encoding: {}r   )rÛ  rÜ  rü   r,   r  rî   )r/   r   r1   r2   r2   r3   Ú"test_multipart_valid_cte_no_defectj  s
    
z4TestNonConformant.test_multipart_valid_cte_no_defectc             C   s¦   | j }| j}tƒ }d|d< || ¡ dƒ || ¡ dƒ || ¡ dƒ |d= d|d< || ¡ dƒ || ¡ dƒ || ¡ dƒ tƒ }t|ƒ}| |¡ || 	¡ dƒ d S )Nr‚   zContent-TyperÕ   z
text/plainzcontent-typer~   zContent-Type: foo

)
r,   r   r   rÍ   rÖ   r8   r   r   rj   rk   )r/   r0   Úneqr1   rƒ   r„   r2   r2   r3   Útest_invalid_content_typer  s     
z+TestNonConformant.test_invalid_content_typec             C   s"   | j }|  d¡}|| ¡ dƒ d S )Nz
msg_31.txtzm--BOUNDARY
Content-Type: text/plain

message 1

--BOUNDARY
Content-Type: text/plain

message 2

--BOUNDARY--
)r   r-   rA   )r/   r0   r1   r2   r2   r3   Útest_no_start_boundary‡  s    
z(TestNonConformant.test_no_start_boundaryc             C   s"   | j }|  d¡}|| ¡ dƒ d S )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-   rf   )r/   r0   r1   r2   r2   r3   Útest_no_separating_blank_line˜  s    
z/TestNonConformant.test_no_separating_blank_linec             C   sX   |   d¡}|  t|dƒ¡ |  t|jƒd¡ |  |jd tj¡ |  |jd tj	¡ d S )Nz
msg_41.txtrî   ry   r   rT   )
r-   r   rÔ  r,   r  rî   rí   r   rØ  rÙ  )r/   r1   r2   r2   r3   Útest_lying_multipart¤  s    
z&TestNonConformant.test_lying_multipartc             C   sD   |   d¡}| d¡ d¡}|  t|jƒd¡ |  |jd tj¡ d S )Nz
msg_42.txtrT   r   )r-   rA   r,   r  rî   rí   r   rÕ  )r/   r¹  Úbadr2   r2   r3   Útest_missing_start_boundary®  s
    
	z-TestNonConformant.test_missing_start_boundaryc             C   sj   | j }d}t |¡}|| ¡ dgƒ || ¡ dƒ |t|jƒdƒ |  |jtj	g¡ ||jd j
dƒ d S )Nz Line 1
Subject: test

bodyr  ÚbodyrT   r   z Line 1
)r,   rt   r¡   rä   rA   r  rî   ÚassertDefectsEqualr   Ú#FirstHeaderLineIsContinuationDefectÚline)r/   r0   r  r1   r2   r2   r3   Ú&test_first_line_is_continuation_header¾  s    

z8TestNonConformant.test_first_line_is_continuation_headerc             C   sB   |   d¡}|  | ¡ dg¡ |  | ¡ d¡ |  |jtjg¡ d S )Nz&Subject: test
not a header
To: abc

b
r  znot a header
To: abc

b
)rÛ  r,   rä   rA   ré  rî   r   Ú MissingHeaderBodySeparatorDefect)r/   r1   r2   r2   r3   Ú"test_missing_header_body_separatorÊ  s
    
z4TestNonConformant.test_missing_header_body_separatorN)r  r  r  rÓ  r×  rÚ  r  r  rÜ  rÞ  rß  rà  râ  rã  rä  rå  rç  rì  rî  r2   r2   r2   r3   rÒ  (  s   
	
rÒ  c               @   sŒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"ÚTestRFC2047c             C   sR   | j }d}t|ƒ}||ddddgƒ t|ƒ}|t|ƒdƒ |  |jddd¡ d S )	NzVRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=)s   Re: N)s
   rŠksmšrgŒszmac-iceland)s    baz foo bar Nu+   Re: rÃ¤ksmÃ¶rgÃ¥s baz foo bar rÃ¤ksmÃ¶rgÃ¥sr  )r*  ziRe: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?=
 =?mac-iceland?q?=9Arg=8Cs?=)r,   r
   r   r   r   rs   )r/   r0   rƒ   Údhrb   r2   r2   r3   Útest_rfc2047_multilineØ  s    z"TestRFC2047.test_rfc2047_multilinec             C   s:   | j }d}t|ƒ}||ddgƒ tt|ƒƒ}||dƒ d S )Nz0=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>)s   Andréz
iso-8859-1)s    Pirard <pirard@dom.ain>Nu   AndrÃ© Pirard <pirard@dom.ain>)r,   r
   r   r   )r/   r0   rƒ   rð  rb   r2   r2   r3   Útest_whitespace_keeper_unicodeé  s    z*TestRFC2047.test_whitespace_keeper_unicodec             C   s>   | j }d}t|ƒ}||ddddgƒ tt|ƒƒ}||dƒ d S )NzWThe =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?=)s   The N)s   quick brown foxz
iso-8859-1)s    jumped over the N)s   lazy dogz
iso-8859-1z,The quick brown fox jumped over the lazy dog)r,   r
   r   r   )r/   r0   rƒ   rð  Úhur2   r2   r3   Ú test_whitespace_keeper_unicode_2ò  s    
z,TestRFC2047.test_whitespace_keeper_unicode_2c             C   s&   d}t |ƒ}|  |dddddg¡ d S )Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord)s   SmN)ó   öz
iso-8859-1)s   rgN)ó   åz
iso-8859-1)s   sbordN)r
   r,   )r/   rƒ   rð  r2   r2   r3   Útest_rfc2047_missing_whitespaceû  s
    
z+TestRFC2047.test_rfc2047_missing_whitespacec             C   s&   d}t |ƒ}|  |dddddg¡ d S )Nz7Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord)s   Sm N)rõ  z
iso-8859-1)s    rg N)rö  z
iso-8859-1)s    sbordN)r
   r,   )r/   rƒ   rð  r2   r2   r3   Útest_rfc2047_with_whitespace	  s
    
z(TestRFC2047.test_rfc2047_with_whitespacec             C   sF   d}dddddg}x.|D ]&\}}t || ƒ}|  ||dfg¡ qW d S )Nz=?iso-8859-1?B?%s?=)zdm==ó   v)zdm=rù  )Zdmrù  )zdmk=s   vi)Zdmks   viz
iso-8859-1)r
   r,   )r/   rƒ   rB   ÚqÚarð  r2   r2   r3   Útest_rfc2047_B_bad_padding		  s    z&TestRFC2047.test_rfc2047_B_bad_paddingc             C   s   d}|   t|ƒdg¡ d S )Nz=?iso-8859-1?Q?andr=e9=zz?=)s   andré=zzz
iso-8859-1)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_Q_invalid_digits	  s    
z)TestRFC2047.test_rfc2047_Q_invalid_digitsc             C   s   d}|   t|ƒdddg¡ d S )Nz(=?ISO-8859-1?Q?a?=))ó   (N)ó   az
iso-8859-1)ó   )N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_1	  s    
z"TestRFC2047.test_rfc2047_rfc2047_1c             C   s   d}|   t|ƒdddg¡ d S )Nz(=?ISO-8859-1?Q?a?= b))rþ  N)rÿ  z
iso-8859-1)s    b)N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_2	  s    
z"TestRFC2047.test_rfc2047_rfc2047_2c             C   s   d}|   t|ƒdddg¡ d S )Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=))rþ  N)s   abz
iso-8859-1)r   N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_3%	  s    
z"TestRFC2047.test_rfc2047_rfc2047_3c             C   s   d}|   t|ƒdddg¡ d S )Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=))rþ  N)s   abz
iso-8859-1)r   N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_4+	  s    
z"TestRFC2047.test_rfc2047_rfc2047_4c             C   s   d}|   t|ƒdddg¡ d S )Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=))rþ  N)s   abz
iso-8859-1)r   N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_5a1	  s    
z#TestRFC2047.test_rfc2047_rfc2047_5ac             C   s   d}|   t|ƒdddg¡ d S )Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=))rþ  N)s   abz
iso-8859-1)r   N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_5b7	  s    
z#TestRFC2047.test_rfc2047_rfc2047_5bc             C   s   d}|   t|ƒdddg¡ d S )Nz(=?ISO-8859-1?Q?a_b?=))rþ  N)s   a bz
iso-8859-1)r   N)r,   r
   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_6=	  s    
z"TestRFC2047.test_rfc2047_rfc2047_6c             C   sT   d}|   t|ƒddddg¡ |   tt|ƒƒ ¡ | ¡ ¡ |   ttt|ƒƒƒd¡ d S )Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))rþ  N)rÿ  z
iso-8859-1)s    bz
iso-8859-2)r   Nz(a b))r,   r
   r   rs   r_   r   )r/   rƒ   r2   r2   r3   Útest_rfc2047_rfc2047_7C	  s    
z"TestRFC2047.test_rfc2047_rfc2047_7c             C   sV   d}|   t|ƒddg¡ |   tt|ƒƒ ¡ d | ¡ ¡¡ |   ttt|ƒƒƒd¡ d S )Nz9=?windows-1252?q?=22M=FCller_T=22?=
 <T.Mueller@xxx.com>)s
   "Müller T"zwindows-1252)s   <T.Mueller@xxx.com>Nr'   u   "MÃ¼ller T" <T.Mueller@xxx.com>)r,   r
   r   rs   r’   Ú
splitlinesr   )r/   rƒ   r2   r2   r3   Útest_multiline_headerL	  s    
z!TestRFC2047.test_multiline_headerN)r  r  r  rñ  rò  rô  r÷  rø  rü  rý  r  r  r  r  r  r  r  r  r
  r2   r2   r2   r3   rï  ×  s    		
	rï  c               @   sŒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"ÚTestMIMEMessagec          	   C   s"   t dƒ}| ¡ | _W d Q R X d S )Nz
msg_11.txt)r"   rh   Ú_text)r/   rl   r2   r2   r3   re  Y	  s    
zTestMIMEMessage.setUpc             C   s   |   ttd¡ d S )Nza plain string)r`   rJ   r   )r/   r2   r2   r3   Útest_type_error]	  s    zTestMIMEMessage.test_type_errorc             C   sv   | j }d}tƒ }||d< t|ƒ}|| ¡ dƒ | ¡ }|  |t¡ |t|ƒdƒ |d }|  ||¡ ||d |ƒ d S )NzA sub-messager  zmessage/rfc822rT   r   Úsubject)	r,   r   r   r8   rA   rí   Úlistr  ry  )r/   r0   r  r  Úrrs  rV   r2   r2   r3   Útest_valid_argument`	  s    z#TestMIMEMessage.test_valid_argumentc             C   s:   t ƒ }d|d< t ƒ }d|d< t|ƒ}|  tj|j|¡ d S )Nz	subpart 1r  z	subpart 2)r   r   r`   r   ÚMultipartConversionErrorrK   )r/   rÄ  r‡  r  r2   r2   r3   Útest_bad_multipartn	  s    z"TestMIMEMessage.test_bad_multipartc             C   sT   t ƒ }d|d< | d¡ t|ƒ}d|d< tƒ }t|ƒ}| |¡ |  | ¡ d¡ d S )NzAn enclosed messager  z!Here is the body of the message.
zThe 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.
)r   r=   r   r   r   rj   r,   rk   )r/   r  r  rƒ   r„   r2   r2   r3   Útest_generatev	  s    


zTestMIMEMessage.test_generatec             C   st   | j }|  d¡}|| ¡ dƒ | ¡ }|  |t¡ |t|ƒdƒ |d }|  |t¡ ||d dƒ || ¡ dƒ d S )Nz
msg_11.txtzmessage/rfc822rT   r   r  zAn enclosed messagez!Here is the body of the message.
)r,   r-   r8   rA   rí   r  r  r   )r/   r0   r1   rs  Zsubmsgr2   r2   r3   Útest_parse_message_rfc822Š	  s    
z)TestMIMEMessage.test_parse_message_rfc822c             C   s–  | j }|  d¡}|| ¡ dƒ |  | ¡ ¡ |t| ¡ ƒdƒ | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ |t| ¡ ƒd	ƒ | d¡}|  |t¡ ||d
 dƒ ||j	ddddƒ ||j	dddd ƒ | d¡}|  |t¡ ||d dƒ ||j
ddddgƒ ||j	ddddƒ | d	¡}|| ¡ dƒ | ¡ }|  |t¡ |t|ƒdƒ |d }|  |t¡ || ¡ dƒ ||d dƒ d S )Nz
msg_16.txtzmultipart/reportrz   r   z
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

rT   zmessage/delivery-statusry   zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnszreporting-mta)rb   r'   ZnsdÚactionÚfailedzoriginal-recipient)rØ   r'   )zjangel1@cougar.noc.ucla.edur'   rØ   zfinal-recipientzmessage/rfc822z
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r,   r-   r8   r   r”  r  rA   rí   r   r9   rª   r  )r/   r0   r1   rV   Zdsn1Zdsn2rs  rÅ  r2   r2   r3   Útest_dsn–	  sB    






zTestMIMEMessage.test_dsnc       	   	   C   sª   | j }tdƒ}| ¡ }W d Q R X tƒ }d|d< d|d< d|d< d|_d	|_td
ƒ}tdƒ}|jdddd | |¡ | |¡ t	ƒ }t
|ƒ}| |¡ || ¡ |ƒ d S )Nz
msg_21.txtzaperson@dom.ainr†   zbperson@dom.ainr‰   r=  r  zMIME messagezEnd of MIME message
rá   rã   zContent-Typezmultipart/mixedrY   )r¬   )r   r"   rh   r   r»  r¼  r   r½   rK   r   r   rj   rk   )	r/   r0   rl   r‚   r1   rÄ  r‡  r!  r„   r2   r2   r3   Útest_epilogueÏ	  s$    



zTestMIMEMessage.test_epiloguec             C   sv   | j }tƒ }d|d< d|d< d|d< d|_d|_td	ƒ}td
ƒ}|jdddd | |¡ | |¡ || ¡ dƒ d S )Nzaperson@dom.ainr†   zbperson@dom.ainr‰   r=  r  zMIME messager'   rá   rã   zContent-Typezmultipart/mixedrY   )r¬   ad  From: 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   r   r»  r¼  r   r½   rK   rf   )r/   r0   r1   rÄ  r‡  r2   r2   r3   Útest_no_nl_preambleã	  s    

z#TestMIMEMessage.test_no_nl_preamblec          	   C   sÀ   | j }tdƒ}t |¡}W d Q R X | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ d S )Nz
msg_30.txtr   zmessage/rfc822rT   z
text/plain)r,   r"   rt   Úmessage_from_filerA   Úget_default_typer8   )r/   r0   rl   r1   Ú
container1Ú
container2Úcontainer1aÚcontainer2ar2   r2   r3   Útest_default_type
  s    




z!TestMIMEMessage.test_default_typec          	   C   sÀ   | j }tdƒ}t |¡}W d Q R X | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ d S )Nz
msg_28.txtr   zmessage/rfc822rT   z
text/plain)r,   r"   rt   r  rA   r  r8   )r/   r0   rl   r1   r  r  r  r   r2   r2   r3   Ú.test_default_type_with_explicit_container_type
  s    




z>TestMIMEMessage.test_default_type_with_explicit_container_typec             C   sü   | j }| j}tddƒ}d|_tdƒ}tdƒ}t|ƒ}t|ƒ}| |¡ | |¡ || ¡ dƒ || ¡ dƒ || ¡ dƒ || ¡ dƒ || 	d¡dƒ |d	= |d
= |d	= |d
= || ¡ dƒ || ¡ dƒ || ¡ dƒ || ¡ dƒ || 	d¡dƒ d S )NÚdigestrY   r'   z
message 1
z
message 2
zmessage/rfc822r   a   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-versionaB  Content-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   r   r¼  r   r   rK   r8   r  rf   )r/   r0   rá  r®  Z	subpart1aZ	subpart2aZsubpart1Zsubpart2r2   r2   r3   Útest_default_type_non_parsed(
  s4    




z,TestMIMEMessage.test_default_type_non_parsedc             C   sZ   | j }tdƒ}tdƒ}t||fd}|t| ¡ ƒdƒ || d¡|ƒ || d¡|ƒ d S )Nr'   )Ú	_subpartsry   r   rT   )r,   r   r   r  rA   )r/   r0   Ztext1Ztext2r1   r2   r2   r3   Ú$test_mime_attachments_in_constructorr
  s    z4TestMIMEMessage.test_mime_attachments_in_constructorc             C   s   t ƒ }|  | ¡ ¡ d S )N)r   r   r”  )r/   r1   r2   r2   r3   Ú"test_default_multipart_constructor{
  s    z2TestMIMEMessage.test_default_multipart_constructorc             C   s0   t ƒ }d|d< d|d< |  | d¡ddg¡ d S )Nza@b.comr‰   zc@d.comr‡   )r   r,   r.   )r/   r1   r2   r2   r3   Útest_multipart_default_policy
  s    z-TestMIMEMessage.test_multipart_default_policyc          	   C   sJ   t tjjd}d|d< |  t¡}d|d< W d Q R X |  t|jƒd¡ d S )N)r—   za@b.comr‰   zc@d.comz.There may be at most 1 To headers in a message)	r   rt   r—   rÐ  r`   rÂ   r,   r   Ú	exception)r/   r1   Úcmr2   r2   r3   Útest_multipart_custom_policy…
  s    z,TestMIMEMessage.test_multipart_custom_policyN)r  r  r  re  r  r  r  r  r  r  r  r  r!  r"  r$  r&  r'  r(  r+  r2   r2   r2   r3   r  X	  s    9#J	r  c               @   sÒ   e Zd ZdZdd„ Zd4dd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3S )5ÚTestIdempotentr&   c          	   C   s.   t |ƒ}| ¡ }W d Q R X t |¡}||fS )N)r"   rh   rt   r¡   )r/   r¼   rl   rB   r1   r2   r2   r3   r-   –
  s    

zTestIdempotent._msgobjFc             C   s8   | j }tƒ }t|dd}|j||d ||| ¡ ƒ d S )Nr   )rS  )rŒ   )r   r   r   rj   rk   )r/   r1   r‚   rŒ   r0   rƒ   r„   r2   r2   r3   Ú_idempotentœ
  s
    zTestIdempotent._idempotentc             C   sˆ   | j }|  d¡\}}|| ¡ dƒ || ¡ dƒ || ¡ dƒ || ¡ d dƒ || d¡dƒ ||jd ƒ ||jd ƒ |  	||¡ d S )	Nz
msg_01.txtz
text/plainr‚   rÕ   rT   )r5   zus-asciir5   zus-ascii)
r,   r-   r8   rÍ   rÖ   rª   r9   r»  r¼  r-  )r/   r0   r1   r‚   r2   r2   r3   Útest_parse_text_message£
  s    z&TestIdempotent.test_parse_text_messagec             C   sP   | j }|  d¡\}}|| ¡ dƒ || ¡ d ƒ || d¡d ƒ |  ||¡ d S )Nz
msg_03.txtz
text/plainr5   )r,   r-   r8   rª   r9   r-  )r/   r0   r1   r‚   r2   r2   r3   Útest_parse_untyped_message¯
  s    z)TestIdempotent.test_parse_untyped_messagec             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_04.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_simple_multipart·
  s    z$TestIdempotent.test_simple_multipartc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_02.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_MIME_digest»
  s    zTestIdempotent.test_MIME_digestc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_27.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_long_header¿
  s    zTestIdempotent.test_long_headerc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_28.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Ú"test_MIME_digest_with_part_headersÃ
  s    z1TestIdempotent.test_MIME_digest_with_part_headersc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_06.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_mixed_with_imageÇ
  s    z$TestIdempotent.test_mixed_with_imagec             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_05.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_multipart_reportË
  s    z$TestIdempotent.test_multipart_reportc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_16.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   r  Ï
  s    zTestIdempotent.test_dsnc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_21.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_preamble_epilogueÓ
  s    z%TestIdempotent.test_preamble_epiloguec             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_23.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_multipart_one_part×
  s    z&TestIdempotent.test_multipart_one_partc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_24.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_multipart_no_partsÛ
  s    z&TestIdempotent.test_multipart_no_partsc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_31.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   rã  ß
  s    z%TestIdempotent.test_no_start_boundaryc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_32.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_rfc2231_charsetã
  s    z#TestIdempotent.test_rfc2231_charsetc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_33.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_more_rfc2231_parametersç
  s    z+TestIdempotent.test_more_rfc2231_parametersc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_34.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Ú%test_text_plain_in_a_multipart_digestë
  s    z4TestIdempotent.test_text_plain_in_a_multipart_digestc             C   s   |   d¡\}}|  ||¡ d S )Nzmsg_12a.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_nested_multipart_mixedsï
  s    z+TestIdempotent.test_nested_multipart_mixedsc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_36.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Ú%test_message_external_body_idempotentó
  s    z4TestIdempotent.test_message_external_body_idempotentc             C   s"   |   d¡\}}| j||dd d S )Nz
msg_43.txtT)rŒ   )r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_message_delivery_status÷
  s    z+TestIdempotent.test_message_delivery_statusc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_45.txt)r-   r-  )r/   r1   r‚   r2   r2   r3   Útest_message_signed_idempotentû
  s    z-TestIdempotent.test_message_signed_idempotentc             C   s\  | j }|  d¡\}}|| ¡ dƒ i }x| ¡ D ]\}}|||< q0W ||d dƒ ||d dƒ ||jd| j ƒ ||j| jƒ |t| ¡ ƒdƒ | d	¡}|| ¡ d
ƒ || ¡ d| j ƒ | d¡}|| ¡ d
ƒ || ¡ d| j ƒ | d¡}	||	 ¡ dƒ |  	|	t
¡ |	 ¡ }
|  	|
t¡ |t|
ƒdƒ |
d	 }|  	|t
¡ || ¡ d| j ƒ d S )Nz
msg_05.txtzmultipart/reportzreport-typezdelivery-statusr¬   z%D1690A7AC1.996856090/mail.example.comz$This is a MIME-encapsulated message.rz   r   z
text/plainzYadda yadda yaddarT   ry   zmessage/rfc822)r,   r-   r8   rª   r»  r–   r¼  r  rA   rí   r   r  )r/   r0   r1   r‚   ÚparamsÚpkÚpvrÄ  r‡  Zmsg3rs  Zmsg4r2   r2   r3   Útest_content_typeÿ
  s4    


z TestIdempotent.test_content_typec             C   sŠ   | j }|  d¡\}}|| ¡ dƒ | ¡ }|  |t¡ |t|ƒdƒ |d }|  |t¡ || ¡ dƒ |  | ¡ t¡ || ¡ | j	ƒ d S )Nz
msg_06.txtzmessage/rfc822rT   r   z
text/plain)
r,   r-   r8   rA   rí   r  r  r   r   r–   )r/   r0   r1   r‚   rs  rÄ  r2   r2   r3   Útest_parser  s    zTestIdempotent.test_parserN)F)r  r  r  r–   r-   r-  r.  r/  r0  r1  r2  r3  r4  r5  r  r6  r7  r8  rã  r9  r:  r;  r<  r=  r>  r?  rC  rD  r2   r2   r2   r3   r,  ’
  s2   
r,  c               @   sœ  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;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ÚTestMiscellaneousc          	   C   sV   t dƒ}| ¡ }W d Q R X t |¡}tƒ }t|dd}| |¡ |  || ¡ ¡ d S )Nz
msg_01.txtr   )rS  )	r"   rh   rt   r¡   r   r   rj   r,   rk   )r/   rl   r‚   r1   rƒ   r„   r2   r2   r3   Útest_message_from_string2  s    


z*TestMiscellaneous.test_message_from_stringc          	   C   s`   t dƒN}| ¡ }| d¡ t |¡}tƒ }t|dd}| |¡ |  || 	¡ ¡ W d Q R X d S )Nz
msg_01.txtr   )rS  )
r"   rh   Úseekrt   r  r   r   rj   r,   rk   )r/   rl   r‚   r1   rƒ   r„   r2   r2   r3   Útest_message_from_file=  s    



z(TestMiscellaneous.test_message_from_filec          	   C   sŽ   t dƒ}| ¡ }W d Q R X G dd„ dtƒ}t ||¡}|  ||¡ t dƒ}| ¡ }W d Q R X t ||¡}x| ¡ D ]}|  ||¡ qvW d S )Nz
msg_01.txtc               @   s   e Zd ZdS )zHTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageN)r  r  r  r2   r2   r2   r3   Ú	MyMessageN  s   rI  z
msg_02.txt)r"   rh   r   rt   r¡   rí   Úwalk)r/   rl   r‚   rI  r1   rV   r2   r2   r3   Ú#test_message_from_string_with_classI  s    

z5TestMiscellaneous.test_message_from_string_with_classc          	   C   s~   G dd„ dt ƒ}tdƒ}t ||¡}W d Q R X |  ||¡ tdƒ}t ||¡}W d Q R X x| ¡ D ]}|  ||¡ qfW d S )Nc               @   s   e Zd ZdS )zFTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageN)r  r  r  r2   r2   r2   r3   rI  \  s   rI  z
msg_01.txtz
msg_02.txt)r   r"   rt   r  rí   rJ  )r/   rI  rl   r1   rV   r2   r2   r3   Ú!test_message_from_file_with_classZ  s    

z3TestMiscellaneous.test_message_from_file_with_classc             C   s,   G dd„ dt ƒ}|  d|¡}|  ||¡ d S )Nc                   s   e Zd Z‡ fdd„Z‡  ZS )zSTestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessagec                s   t ƒ  ¡  d S )N)ÚsuperÚ__init__)r/   )Ú	__class__r2   r3   rN  j  s    z\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)r  r  r  rN  Ú__classcell__r2   r2   )rO  r3   rI  i  s   rI  zSubject: test

test)r   rÛ  rí   )r/   rI  r1   r2   r2   r3   Ú.test_custom_message_does_not_require_argumentsh  s    z@TestMiscellaneous.test_custom_message_does_not_require_argumentsc             C   s@   t dƒ}|  t|jƒdddddddd	d
ddddddddg¡ d S )Nrt   r   r5   r   r   Ú
feedparserrw   rb   r   rÏ   Úmessage_from_binary_filerj  r  r¡   r  rn   r   r   )Ú
__import__r,   ÚsortedÚ__all__)r/   Úmoduler2   r2   r3   Útest__all__o  s    
zTestMiscellaneous.test__all__c             C   s:   t   ¡ }|  t t |¡¡d d… t  |¡d d… ¡ d S )Né   )r¨  r,   r   Ú	parsedateÚ
formatdateÚgmtime)r/   r°  r2   r2   r3   Útest_formatdatey  s    z!TestMiscellaneous.test_formatdatec             C   s>   t   ¡ }|  t tj|dd¡d d… t  |¡d d… ¡ d S )NT)r©  rY  )r¨  r,   r   rZ  r[  r©  )r/   r°  r2   r2   r3   Útest_formatdate_localtime~  s    z+TestMiscellaneous.test_formatdate_localtimec          	   C   sV   t   ¡ }|  tj|ddt  dt  |¡¡¡ |  tj|dddt  dt  |¡¡¡ d S )NF)r©  z%a, %d %b %Y %H:%M:%S -0000T)r©  Úusegmtz%a, %d %b %Y %H:%M:%S GMT)r¨  r,   r   r[  r¬  r\  )r/   r°  r2   r2   r3   Útest_formatdate_usegmt„  s    z(TestMiscellaneous.test_formatdate_usegmtc             C   s„   |   t d¡¡ |   t d¡¡ |   t d¡¡ |   t d¡¡ |   t d¡¡ |   t d¡¡ |   t d ¡¡ |   t d ¡¡ d S )Nr'   Ú0zA Complete Waste of Time)rê   r   rZ  Úparsedate_tz)r/   r2   r2   r3   Ú/test_parsedate_returns_None_for_invalid_stringsŽ  s    zATestMiscellaneous.test_parsedate_returns_None_for_invalid_stringsc             C   s   |   t d¡t d¡¡ d S )NzWed,3 Apr 2002 14:58:26 +0800zWed, 3 Apr 2002 14:58:26 +0800)r,   r   rZ  )r/   r2   r2   r3   Útest_parsedate_compact™  s    z(TestMiscellaneous.test_parsedate_compactc             C   s   | j }|t d¡dƒ d S )Nz25 Feb 2003 13:47:26 -0800)
iÓ  ry   é   é   é/   é   r   rT   r£  i€ÿÿ)r,   r   rb  )r/   r0   r2   r2   r3   Útest_parsedate_no_dayofweekž  s    
z-TestMiscellaneous.test_parsedate_no_dayofweekc             C   s   | j }|t d¡dƒ d S )Nz5 Feb 2003 13:47:26 -0800)
iÓ  ry   é   rf  rg  rh  r   rT   r£  i€ÿÿ)r,   r   rb  )r/   r0   r2   r2   r3   Ú#test_parsedate_compact_no_dayofweek£  s    
z5TestMiscellaneous.test_parsedate_compact_no_dayofweekc             C   s   |   t d¡d¡ d S )NzWed, 3 Apr 2002 14:58:26+0800)
iÒ  r\   rz   é   é:   rh  r   rT   r£  i€p  )r,   r   rb  )r/   r2   r2   r3   Ú.test_parsedate_no_space_before_positive_offset¨  s    z@TestMiscellaneous.test_parsedate_no_space_before_positive_offsetc             C   s   |   t d¡d¡ d S )NzWed, 3 Apr 2002 14:58:26-0800)
iÒ  r\   rz   rl  rm  rh  r   rT   r£  i€ÿÿ)r,   r   rb  )r/   r2   r2   r3   Ú.test_parsedate_no_space_before_negative_offset¬  s    z@TestMiscellaneous.test_parsedate_no_space_before_negative_offsetc             C   s*   | j }|t d¡dƒ |t d¡dƒ d S )Nz5 Feb 2003 13.47.26 -0800)
iÓ  ry   rj  rf  rg  rh  r   rT   r£  i€ÿÿz5 Feb 2003 13.47 -0800)
iÓ  ry   rj  rf  rg  r   r   rT   r£  i€ÿÿ)r,   r   rb  )r/   r0   r2   r2   r3   Ú%test_parsedate_accepts_time_with_dots²  s
    

z7TestMiscellaneous.test_parsedate_accepts_time_with_dotsc             C   s¶   | j }t d¡}tt |¡ƒ}|t |¡d d… |d d… ƒ |tt d|¡ƒdƒ t d¡}tt |d d… ¡ƒ}|t |¡d d… |d d… ƒ |tt d|d d… ¡ƒdƒ d S )Nz5 Feb 2003 13:47:26 -0800rY  z%YiÓ  é	   )	r,   r   rZ  Úintr¨  Úmktimer©  r¬  rb  )r/   r0   Ztimetupr]  r2   r2   r3   Ú+test_parsedate_acceptable_to_time_functions¹  s    
 
 z=TestMiscellaneous.test_parsedate_acceptable_to_time_functionsc             C   s(   |   t d¡d¡ |   t d¡d¡ d S )N)
i²  rT   rT   r   r   r   r£  r£  r£  r   r   )
i²  rT   rT   r   r   r   r£  r£  r£  iÒ  i.ûÿÿ)r,   r   Ú	mktime_tz)r/   r2   r2   r3   Útest_mktime_tzÄ  s    z TestMiscellaneous.test_mktime_tzc             C   s4   |   t d¡t d¡¡ |   t d¡t d¡¡ dS )a   Test 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.

        z25 Feb 03 13:47:26 -0800z25 Feb 2003 13:47:26 -0800z25 Feb 71 13:47:26 -0800z25 Feb 1971 13:47:26 -0800N)r,   r   rb  )r/   r2   r2   r3   Útest_parsedate_y2kÊ  s    z$TestMiscellaneous.test_parsedate_y2kc             C   s.   |   t d¡d¡ |   t t d¡¡d¡ d S )Nz<>)r'   r'   r'   )r,   r   Ú	parseaddrÚ
formataddr)r/   r2   r2   r3   Útest_parseaddr_empty×  s    z&TestMiscellaneous.test_parseaddr_emptyc             C   s   |   t d¡d¡ d S )N)zA Silly Personzperson@dom.ainzA Silly Person <person@dom.ain>)r,   r   ry  )r/   r2   r2   r3   Útest_noquote_dumpÛ  s    z#TestMiscellaneous.test_noquote_dumpc             C   sP   |   t d¡d¡ |   t d¡d¡ d}d}|   t t ||f¡¡||f¡ d S )N)zA (Very) Silly Personzperson@dom.ainz("A (Very) Silly Person" <person@dom.ain>z*"A \(Very\) Silly Person" <person@dom.ain>zA \(Special\) Personzperson@dom.ain)r,   r   ry  rx  )r/   rû  rl  r2   r2   r3   Útest_escape_dumpà  s    z"TestMiscellaneous.test_escape_dumpc             C   s>   |   t d¡d¡ d}d}|   t t ||f¡¡||f¡ d S )N)zArthur \Backslash\ Foobarzperson@dom.ainz."Arthur \\Backslash\\ Foobar" <person@dom.ain>zArthur \Backslash\ Foobarzperson@dom.ain)r,   r   ry  rx  )r/   rû  rl  r2   r2   r3   Útest_escape_backslashesë  s    z)TestMiscellaneous.test_escape_backslashesc             C   sB   d}d}d}d}|   t ||f¡|¡ |   t ||fd¡|¡ d S )Nu   HÃ¤ns WÃ¼rstzperson@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,   r   ry  )r/   r¯   ÚaddrÚutf8_base64Zlatin1_quoprir2   r2   r3   Útest_quotes_unicode_namesó  s    z+TestMiscellaneous.test_quotes_unicode_namesc                sl   d}d}d}d‰ G ‡ fdd„dƒ}|ƒ }dˆ |f }|   t ||f|¡|¡ |   t ||ftdƒ¡|¡ d S )	Nu   HÃ¤ns WÃ¼rstzperson@dom.ainz-=?utf-8?b?SMOkbnMgV8O8cnN0?= <person@dom.ain>ZFOOBARc                   s   e Zd Z‡ fdd„ZdS )zKTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockc                s   ˆ S )Nr2   )r/   Ústring)rÀ   r2   r3   Úheader_encode  s    zYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)r  r  r  r‚  r2   )rÀ   r2   r3   ÚCharsetMock  s   rƒ  z%s <%s>zutf-8)r,   r   ry  r   )r/   r¯   r~  r  rƒ  ÚmockZmock_expectedr2   )rÀ   r3   Ú$test_accepts_any_charset_like_objectý  s    z6TestMiscellaneous.test_accepts_any_charset_like_objectc             C   s(   d}d}t ƒ }|  ttj||f|¡ d S )Nu   HÃ¤ns WÃ¼rstzperson@dom.ain)Úobjectr`   ÚAttributeErrorr   ry  )r/   r¯   r~  Zbad_charsetr2   r2   r3   Ú-test_invalid_charset_like_object_raises_error  s
    z?TestMiscellaneous.test_invalid_charset_like_object_raises_errorc             C   s0   d}|   ttjd |f¡ |   ttjd|f¡ d S )Nu   persÃ¶n@dom.inÚName)r`   ÚUnicodeErrorr   ry  )r/   r~  r2   r2   r3   Ú!test_unicode_address_raises_error  s    z3TestMiscellaneous.test_unicode_address_raises_errorc             C   sV   d}d}d\}}|   t |¡||f¡ |   t |¡||f¡ |   t ||f¡|¡ d S )NzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>)zJohn X. Doezjxd@example.com)r,   r   rx  ry  )r/   rð   Úyrû  rl  r2   r2   r3   Útest_name_with_dot  s    z$TestMiscellaneous.test_name_with_dotc             C   s:   | j }|t d¡dƒ |t d¡dƒ |t d¡dƒ d S )Nz""example" example"@example.com)r'   z""example" example"@example.comz!"\"example\" example"@example.com)r'   z!"\"example\" example"@example.comz#"\\"example\\" example"@example.com)r'   z#"\\"example\\" example"@example.com)r,   r   rx  )r/   r0   r2   r2   r3   Ú2test_parseaddr_preserves_quoted_pairs_in_addresses$  s    



zDTestMiscellaneous.test_parseaddr_preserves_quoted_pairs_in_addressesc             C   s^   |   dt d¡¡ |   dt d¡¡ |   dt d¡¡ |   dt d¡¡ |   dt d	¡¡ d S )
N)r'   zmerwok wok@xample.comzmerwok wok@xample.com)r'   zmerwok  wok@xample.comzmerwok  wok@xample.comz merwok  wok  @xample.com)r'   zmerwok"wok"  wok@xample.comzmerwok"wok"  wok@xample.com)r'   zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.com)r,   r   rx  )r/   r2   r2   r3   Ú-test_parseaddr_preserves_spaces_in_local_part6  s    z?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_partc             C   s0   d}d}|   t |¡|¡ |   t |¡|¡ d S )N)z#'foo@example.com' (foo@example.com)zfoo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>)r,   r   rx  ry  )r/   r~  Zaddrstrr2   r2   r3   Ú6test_formataddr_does_not_quote_parens_in_quoted_stringH  s    zHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_stringc             C   s   d}|   t |¡d¡ d S )NzFoo
	Bar <foo@example.com>)zFoo Barzfoo@example.com)r,   r   rx  )r/   rð   r2   r2   r3   Útest_multiline_from_commentQ  s    z-TestMiscellaneous.test_multiline_from_commentc             C   s   |   t d¡d¡ d S )N)zA Silly; Personzperson@dom.ainz""A Silly; Person" <person@dom.ain>)r,   r   ry  )r/   r2   r2   r3   Útest_quote_dumpW  s    z!TestMiscellaneous.test_quote_dumpc             C   s¨   | j }| j}tƒ }tƒ }||dƒ ||dƒ ||dƒ |d|ƒ |d|ƒ |d|ƒ ||dƒ ||dƒ ||dƒ |d|ƒ |d|ƒ |d|ƒ |||ƒ |||ƒ d S )Nzus-asciizUS-ASCIIzUs-AsCiIZusasciiÚUSASCIIZUsAsCiI)r,   ÚassertNotEqualr   )r/   r0   ÚneZcset1Zcset2r2   r2   r3   Útest_charset_richcomparisons\  s$    












z.TestMiscellaneous.test_charset_richcomparisonsc             C   s"   | j }|t ddg¡ddgƒ d S )Nzaperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>)z	Al Personzaperson@dom.ain)z
Bud Personzbperson@dom.ain)r,   r   Úgetaddresses)r/   r0   r2   r2   r3   Útest_getaddressesp  s
    z#TestMiscellaneous.test_getaddressesc             C   sN   | j }|t dg¡dgƒ |t dg¡dddgƒ |t ddg¡ddgƒ d S )Nzfoo: ;)r'   r'   z	[]*-- =~$)r'   z*--z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerzjason@dom.ain)r,   r   r—  )r/   r0   r2   r2   r3   Útest_getaddresses_nastyw  s    z)TestMiscellaneous.test_getaddresses_nastyc             C   s(   | j }t dg¡}||d d dƒ dS )z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>r   rT   zfoo@bar.comN)r,   r   r—  )r/   r0   Úaddrsr2   r2   r3   Ú"test_getaddresses_embedded_comment  s    z4TestMiscellaneous.test_getaddresses_embedded_commentc          	      sj   G dd„ dt ƒ‰ ‡ fdd„tdƒD ƒ}t|ƒ W d Q R X tdd„ |D ƒg ƒ}|  tt|ƒƒt|ƒ¡ d S )Nc               @   s   e Zd Zdd„ ZdS )zBTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadc             S   sF   g | _ | j j}tj}tj}|ƒ d }x|ƒ |k r@||ddƒ q&W d S )Ng      @ztestdomain-string)Údomain)Úmsgidsr+  r   Ú
make_msgidr¨  Ú	monotonic)r/   r+  rž  ÚclockZtfinr2   r2   r3   ÚrunŠ  s    
zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)r  r  r  r¡  r2   r2   r2   r3   ÚMsgidsThread‰  s   r¢  c                s   g | ]
}ˆ ƒ ‘qS r2   r2   )rQ   r9  )r¢  r2   r3   rS   ”  s    z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>rj  c             S   s   g | ]
}|j ‘qS r2   )r  )rQ   r]  r2   r2   r3   rS   —  s    )r   r?  r!   Úsumr,   r  Úset)r/   ÚthreadsZall_idsr2   )r¢  r3   Útest_make_msgid_collisions‡  s    

z,TestMiscellaneous.test_make_msgid_collisionsc             C   s.   | j }tƒ }|jdddd || ¡ dƒ d S )Nzcontent-dispositionr»   zfoo\wacky"name)r¼   )r,   r   r½   rP   )r/   r0   r1   r2   r2   r3   Útest_utils_quote_unquoteš  s
    z*TestMiscellaneous.test_utils_quote_unquotec             C   s   t dƒ}|  | ¡ d¡ d S )Nznot a charsetr?   )r   r,   Úget_body_encoding)r/   r5   r2   r2   r3   Ú)test_get_body_encoding_with_bogus_charset¡  s    z;TestMiscellaneous.test_get_body_encoding_with_bogus_charsetc             C   s  | j }tƒ }d|d< ||d dƒ | ¡ }|t|ƒdƒ ||d dƒ t|d ƒ}|| ¡ dƒ |jd|d	 || ¡ d
ƒ ||jdddƒ ||d dƒ tƒ }d|d< | ¡ }|t|ƒdƒ ||d dƒ t|d ƒ}|| ¡ tj	ƒ |jd|d	 || ¡ dƒ ||d dƒ d S )Nztext/plain; charset=UTF-8zContent-Typezcontent-typerT   r   zutf-8r?   s   hello world)r5   zaGVsbG8gd29ybGQ=
T)r@   zcontent-transfer-encodingztext/plain; charset="US-ASCII"zus-asciizhello worldr  )
r,   r   rM   r  r   r¨  r=   rA   r   r…  )r/   r0   r1   rN   r5   r2   r2   r3   Ú-test_get_body_encoding_with_uppercase_charset¥  s.    z?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetc             C   s(   t dƒ}t dƒ}|  | ¡ | ¡ ¡ d S )Nzus-asciizUS-ASCII)r   r,   r¨  )r/   ÚlcZucr2   r2   r3   Útest_charsets_case_insensitive¿  s    z0TestMiscellaneous.test_charsets_case_insensitivec             C   s4   | j }|  d¡}tƒ }t ||¡ || ¡ dƒ d S )Nz
msg_43.txtaB  multipart/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-   r   r   rÈ  rk   )r/   r0   r1   r!  r2   r2   r3   Ú1test_partial_falls_inside_message_delivery_statusÄ  s    
zCTestMiscellaneous.test_partial_falls_inside_message_delivery_statusc             C   s"   |   tjjdddd … d¡ d S )Nztestdomain-string)rœ  iíÿÿÿz@testdomain-string>)r,   rt   r   rž  )r/   r2   r2   r3   Útest_make_msgid_domainî  s    z(TestMiscellaneous.test_make_msgid_domainc             C   s$   |   tjjddddd … d¡ d S )Nztest-idstringztestdomain-string)Úidstringrœ  ißÿÿÿz!.test-idstring@testdomain-string>)r,   rt   r   rž  )r/   r2   r2   r3   Útest_make_msgid_idstringó  s    z*TestMiscellaneous.test_make_msgid_idstringc             C   s$   |   tj ¡  dtƒ  d ¡¡ d S )Nú@ú>)r   rt   r   rž  Úendswithr   )r/   r2   r2   r3   Útest_make_msgid_default_domainù  s    
z0TestMiscellaneous.test_make_msgid_default_domainc          	   C   sf   t ddd}| ¡ }W d Q R X | dd¡}t |¡}tƒ }tj |¡}| |¡ |  	| 
¡ |¡ d S )Nz
msg_26.txtr&   )Únewlinez
)r"   rh   r%  rt   r¡   r   rw   r   rj   r,   rk   )r/   ÚfÚmsgtxtÚ	msgtxt_nlr1   rƒ   r„   r2   r2   r3   Útest_Generator_linendþ  s    

z'TestMiscellaneous.test_Generator_linendc          	   C   sp   t ddd}| ¡ }W d Q R X | dd¡}t |¡}tƒ }tj |¡}|j|dd |  	| 
¡  d¡|¡ d S )Nz
msg_26.txtr&   )rµ  z
)r–   rr   )r"   rh   r%  rt   r¡   r   rw   r   rj   r,   rk   r@   )r/   r¶  r·  r¸  r1   rƒ   r„   r2   r2   r3   Útest_BytesGenerator_linend	  s    
z,TestMiscellaneous.test_BytesGenerator_linendc          	   C   st   t ddƒ}| ¡ }W d Q R X | dd¡}| dd¡}t |¡}tƒ }tj |¡}|j|dd |  	| 
¡ |¡ d S )	Nz
msg_26.txtr  s   with attachments   foös   
r›   z
)r–   )r"   rh   r%  rt   rj  r   rw   r   rj   r,   rk   )r/   r¶  r·  r¸  r1   rƒ   r„   r2   r2   r3   Ú)test_BytesGenerator_linend_with_non_ascii  s    
z;TestMiscellaneous.test_BytesGenerator_linend_with_non_asciic          
   C   sø   t ddƒ}| ¡ }W d Q R X t ddƒ}| ¡ }W d Q R X tdft|fft|ffttƒ fftdftdfg}x†|D ]~\}}| j	|j
dd  ||Ž }|  |jtjj¡ W d Q R X | j	|j
dd* ||d	tjjiŽ}|  |jtjj¡ W d Q R X qrW d S )
Nzaudiotest.aur  zPyBanner048.gif)r'   )r¡  r¢  rÎ  )Úclsr—   rÐ  r—   )r"   rh   r   r   r   r   r   r   r   ÚsubTestr  ry  r—   rt   rÎ  rÐ  )r/   rl   Z	audiodatar  Úclassesr¼  Úconstructorr  r2   r2   r3   Ú!test_mime_classes_policy_argument   s"    

z3TestMiscellaneous.test_mime_classes_policy_argumentN)5r  r  r  rF  rH  rK  rL  rQ  rX  r]  r^  r`  rc  rd  ri  rk  rn  ro  rp  rt  rv  rw  rz  r{  r|  r}  r€  r…  rˆ  r‹  r  rŽ  r  r  r‘  r’  r–  r˜  r™  r›  r¦  r§  r©  rª  r¬  r­  r®  r°  r´  r¹  rº  r»  rÀ  r2   r2   r2   r3   rE  1  sd   


			
*rE  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestIteratorsc          	   C   s    | j }| j}|  d¡}t |¡}t|ƒ}|t|ƒdƒ |t |¡| 	¡ ƒ |  d¡}t |¡}t|ƒ}|t|ƒdƒ t
dƒ}|t |¡| ¡ ƒ W d Q R X d S )Nz
msg_01.txtrY  z
msg_02.txté+   z
msg_19.txt)r,   r   r-   r   Úbody_line_iteratorr  r  ÚEMPTYSTRINGr’   rA   r"   rh   )r/   r0   rá  r1   Úitr”   rl   r2   r2   r3   Útest_body_line_iterator8  s    




z%TestIterators.test_body_line_iteratorc             C   sf   | j }|  d¡}t |d¡}g }d}x"|D ]}|d7 }| | ¡ ¡ q*W ||dƒ |t |¡dƒ d S )Nz
msg_04.txtr‚   r   rT   ry   z`a simple kind of mirror
to reflect upon our own
a simple kind of mirror
to reflect upon our own
)r,   r-   r   Útyped_subpart_iteratorr+  rA   rÄ  r’   )r/   r0   r1   rÅ  r”   ÚsubpartsrV   r2   r2   r3   Útest_typed_subpart_iteratorI  s    



z)TestIterators.test_typed_subpart_iteratorc             C   sh   | j }|  d¡}t |dd¡}g }d}x"|D ]}|d7 }| | ¡ ¡ q,W ||dƒ |t |¡dƒ d S )Nz
msg_03.txtr‚   rÕ   r   rT   z%
Hi,

Do you like this message?

-Me
)r,   r-   r   rÇ  r+  rA   rÄ  r’   )r/   r0   r1   rÅ  r”   rÈ  rV   r2   r2   r3   Ú(test_typed_subpart_iterator_default_typeZ  s    



z6TestIterators.test_typed_subpart_iterator_default_typec             C   sÄ   ddddddddg}d	d
l m}m} |ƒ }g }d	}xZ|D ]R\}}| |¡ ||7 }d	}	x&t|j|ƒD ]}
| |
¡ |	d7 }	qdW |  ||	¡ q8W |  t|ƒ|¡ |  d 	dd„ |D ƒ¡d 	|¡¡ dS )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.
        )za 
ry   )rl  r   )zc
rT   )r'   r   )zd
rT   )zer   )z
frT   )z
rT   r   )ÚBufferedSubFileÚNeedMoreDatarT   r'   c             S   s   g | ]\}}|‘qS r2   r2   )rQ   ÚilÚnr2   r2   r3   rS   ‰  s    z0TestIterators.test_pushCR_LF.<locals>.<listcomp>N)
Úemail.feedparserrË  rÌ  ÚpushÚiterÚreadliner+  r,   r  r’   )r/   ZimtrË  rÌ  ÚbsfZomÚntrÍ  rÎ  Zn1Zolr2   r2   r3   Útest_pushCR_LFm  s,    

zTestIterators.test_pushCR_LFc                s¦   ddl m}m} d}d}d‰ d ‡ fdd„t|ƒD ƒ¡d	 }| d
¡}|ƒ }g }xDtdt|ƒ|ƒD ]0}	||	|	| … }
| |
¡ | t	|j
|ƒ¡ qbW |  ||¡ d S )Nr   )rË  rÌ  i'  rj  zabcd 	
r'   c             3   s   | ]}t ˆ ƒV  qd S )N)r   )rQ   r9  )Úcharsr2   r3   r:  ’  s    z1TestIterators.test_push_random.<locals>.<genexpr>r&   T)rÏ  rË  rÌ  r’   r?  r	  r  rÐ  ÚextendrÑ  rÒ  r,   )r/   rË  rÌ  rÎ  Ú	chunksizerƒ   ÚtargetrÓ  r”   r9  Úchunkr2   )rÖ  r3   Útest_push_random‹  s     

zTestIterators.test_push_randomN)r  r  r  rÆ  rÉ  rÊ  rÕ  rÛ  r2   r2   r2   r3   rÁ  7  s
   rÁ  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestFeedParsersc             C   s&   t ƒ }x|D ]}| |¡ qW | ¡ S )N)r$   ÚfeedÚclose)r/   ÚchunksrR  rÚ  r2   r2   r3   Úparse   s    
zTestFeedParsers.parsec             C   s.   |   d¡}|  |d d¡ |  |d d¡ d S )NzFirst: val
: bad
Second: valrà   Úvalrâ   )rà  r,   )r/   r1   r2   r2   r3   Útest_empty_header_name_handled¦  s    
z.TestFeedParsers.test_empty_header_name_handledc             C   sô   |   dg¡}|  | ¡ ddddg¡ |   dg¡}|  | ¡ ddddg¡ |   ddg¡}|  | ¡ dd	g¡ |   d
dg¡}|  | ¡ ddg¡ |   d
dg¡}|  | ¡ ddg¡ |   dg¡}|  | ¡ dg¡ |   d
ddg¡}|  | ¡ ddg¡ d S )Nza:
b:c:
d:
rû  rl  ÚcÚdza:
b:c:
d:za:bzc:
Úbcza:zb:
z
b:
u   a:Â…b:â€¨c:
)rû  u	   Â…b:â€¨c:u   b:Â…)rû  r'   )rl  u   Â…c:)rà  r,   rä   r^   )r/   r  r2   r2   r3   Útest_newlines¬  s    zTestFeedParsers.test_newlinesc             C   s  d\}}|   dgd| g|  ¡}|  | ¡ dg¡ |  | ¡ d| | ¡ |   dgd| g|  ¡}|  | ¡ dg¡ |  | ¡ d| | ¡ |   dgd| d g|  ¡}|  | ¡ dg¡ |  | ¡ d| d | ¡ |   ddgd| g|  ¡}|  | ¡ d	d
d| | fg¡ d S )N)iè  i N  za:b

rð   )rû  rl  za:bõ   Â…za:zb: )rû  r'   rl  )rà  r,   r^   rA   )r/   ÚMÚNr  r2   r2   r3   Útest_long_lines¾  s    zTestFeedParsers.test_long_linesN)r  r  r  rà  râ  ræ  rê  r2   r2   r2   r3   rÜ  ž  s   rÜ  c               @   s˜   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ ZdS )$ÚTestParsersc          	   C   sr   | j }tdƒ}tƒ  |¡}W d Q R X ||d dƒ ||d dƒ || ¡ dƒ |  | ¡ ¡ |  | ¡ t	¡ d S )Nz
msg_02.txtrˆ   zppp-request@zzz.orgr‡   zppp@zzz.orgzmultipart/mixed)
r,   r"   r   rà  r8   r“  r”  rí   rA   r   )r/   r0   rl   r1   r2   r2   r3   Útest_header_parserÐ  s    
zTestParsers.test_header_parserc          	   C   sŒ   | j }tddƒ}tj ¡  |¡}W d Q R X ||d dƒ ||d dƒ || ¡ dƒ |  | ¡ ¡ |  	| 
¡ t¡ |  	|j
dd	t¡ d S )
Nz
msg_02.txtr  rˆ   zppp-request@zzz.orgr‡   zppp@zzz.orgzmultipart/mixedT)r@   )r,   r"   rt   rn   ru   rà  r8   r“  r”  rí   rA   r   rœ   )r/   r0   rl   r1   r2   r2   r3   Útest_bytes_header_parserÛ  s    z$TestParsers.test_bytes_header_parserc          	   C   s6   t ddƒ"}tj ¡  |¡ |  |j¡ W d Q R X d S )Nz
msg_02.txtr  )r"   rt   rn   ÚBytesParserrà  r“  Úclosed)r/   rl   r2   r2   r3   Ú%test_bytes_parser_does_not_close_fileç  s    z1TestParsers.test_bytes_parser_does_not_close_filec          	   C   sL   t ddƒ8}tjj}|  tjj|tjjdj	|¡ |  
|j¡ W d Q R X d S )Nz
msg_15.txtr  )r—   )r"   rt   rn   rî  r`   r   rÕ  r—   Ústrictrà  r“  rï  )r/   rl   ZbytesParserr2   r2   r3   Ú2test_bytes_parser_on_exception_does_not_close_fileì  s    
z>TestParsers.test_bytes_parser_on_exception_does_not_close_filec          	   C   s6   t ddƒ"}tj ¡  |¡ |  |j¡ W d Q R X d S )Nz
msg_02.txtr  )r"   rt   rn   r   rà  r“  rï  )r/   rl   r2   r2   r3   Útest_parser_does_not_close_fileô  s    z+TestParsers.test_parser_does_not_close_filec          	   C   sL   t ddƒ8}tjj}|  tjj|tjjdj	|¡ |  
|j¡ W d Q R X d S )Nz
msg_15.txtr  )r—   )r"   rt   rn   r   r`   r   rÕ  r—   rñ  rà  r“  rï  )r/   rl   rn   r2   r2   r3   Ú,test_parser_on_exception_does_not_close_fileù  s
    
z8TestParsers.test_parser_on_exception_does_not_close_filec             C   s>   | j }t d¡}||d dƒ ||d dƒ || ¡ dƒ d S )Nz¤From: aperson@dom.ain
To: bperson@dom.ain
Subject: the next line has a space on it
 
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam

Here's the message body
r  z!the next line has a space on it
 z
message-idÚspamzHere's the message body
)r,   rt   r¡   rA   )r/   r0   r1   r2   r2   r3   Útest_whitespace_continuation   s    	z(TestParsers.test_whitespace_continuationc             C   s>   | j }t d¡}||d dƒ ||d dƒ || ¡ dƒ d S )Nz¤From: aperson@dom.ain
To: bperson@dom.ain
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam
Subject: the next line has a space on it
 

Here's the message body
r  z!the next line has a space on it
 z
message-idrõ  zHere's the message body
)r,   rt   r¡   rA   )r/   r0   r1   r2   r2   r3   Ú(test_whitespace_continuation_last_header  s    	z4TestParsers.test_whitespace_continuation_last_headerc          	   C   s~   | j }tddd}tƒ  |¡}W d Q R X |t| ¡ ƒdƒ | d¡}|| ¡ dƒ || ¡ dƒ | d¡}|| ¡ d	ƒ d S )
Nz
msg_26.txtr&   )rµ  ry   r   z
text/plainz!Simple email with attachment.

rT   zapplication/riscos)r,   r"   r   rà  r  rA   r8   )r/   r0   rl   r1   Úpart1Úpart2r2   r2   r3   Útest_crlf_separation$  s    

z TestParsers.test_crlf_separationc          	   C   sZ   t ddd}| ¡ }W d Q R X t |¡}tƒ }t|ƒ}|j|dd |  | ¡ |¡ d S )Nz
msg_26.txtr&   )rµ  z
)r–   )	r"   rh   rt   r¡   r   r   rj   r,   rk   )r/   rl   r‚   r1   rƒ   r„   r2   r2   r3   Útest_crlf_flatten/  s    
zTestParsers.test_crlf_flattenNc       	   	   C   s&  | j }| j}tdƒ}t |¡}W d Q R X || ¡ dƒ |t| ¡ ƒdƒ | d¡}|| ¡ dƒ || ¡ dƒ |t| ¡ ƒdƒ | d¡}|| ¡ dƒ || ¡ dƒ || ¡ dƒ | d¡}|| ¡ dƒ || ¡ dƒ |t| ¡ ƒdƒ | d¡}|| ¡ dƒ || ¡ dƒ || ¡ dƒ d S )	Nz
msg_28.txtrT   ry   r   zmessage/rfc822z
text/plainz
message 1
z
message 2
)	r,   r   r"   rt   r  r”  r  rA   r8   )	r/   r0   rá  rl   r1   rø  Zpart1arù  Zpart2ar2   r2   r3   Ú-test_multipart_digest_with_extra_mime_headers;  s,    




z9TestParsers.test_multipart_digest_with_extra_mime_headersc             C   s.   dddg}t  t |¡¡}|  |d d¡ d S )Nz$From: Andrew Person <aperson@dom.ainzSubject: Testz%Date: Tue, 20 Aug 2002 16:43:45 +1000ÚdatezTue, 20 Aug 2002 16:43:45 +1000)rt   r¡   r‘   r’   r,   )r/   r”   r1   r2   r2   r3   Útest_three_linesZ  s
    zTestParsers.test_three_linesc             C   sH   | j }d}d}d||f }t |¡}|| d¡|ƒ || d¡|ƒ d S )Nr‚   z	more textz'Header: %s
Next-Header: %s

Body

r	   zNext-Header)r,   rt   r¡   Úget)r/   r0   Úvalue1Úvalue2r  r1   r2   r2   r3   Ú3test_strip_line_feed_and_carriage_return_in_headersb  s    

z?TestParsers.test_strip_line_feed_and_carriage_return_in_headersc             C   sR   | j }d}t |¡}|t|ƒdƒ |tdd„ |D ƒƒdddgƒ || ¡ dƒ d S )	Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyrz   c             s   s   | ]
}|V  qd S )Nr2   )rQ   Úfieldr2   r2   r3   r:  r  s    z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>z!"#QUX;~z>Fromr†   rè  )r,   rt   r¡   r  rU  rA   )r/   r0   r  r1   r2   r2   r3   Útest_rfc2822_header_syntaxm  s    
z&TestParsers.test_rfc2822_header_syntaxc             C   s*   | j }d}t |¡}|t| ¡ ƒdƒ d S )Nz<>From foo@example.com 11:25:53
From: bar
!"#QUX;~: zoo

bodyr   )r,   rt   r¡   r  rä   )r/   r0   r  r1   r2   r2   r3   Ú(test_rfc2822_space_not_allowed_in_headeru  s    
z4TestParsers.test_rfc2822_space_not_allowed_in_headerc             C   sF   | j }d}t |¡}| ¡ }| ¡  ||dddgƒ || ¡ dƒ d S )Nz7A: first header
B: second header
CC: third header

bodyÚAÚBÚCCrè  )r,   rt   r¡   rä   ÚsortrA   )r/   r0   r  r1   Úheadersr2   r2   r3   Ú!test_rfc2822_one_character_header{  s    
z-TestParsers.test_rfc2822_one_character_headerc             C   s,   d}t  |¡}|  | d¡ ¡  d¡¡ d S )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--
r   z
)rt   r¡   r   rA   r³  )r/   r  r1   r2   r2   r3   Útest_CRLFLF_at_end_of_part„  s    
z&TestParsers.test_CRLFLF_at_end_of_part)r  r  r  rì  rí  rð  rò  ró  rô  rö  r÷  rú  rû  rc  rü  rþ  r  r  r  r  r  r2   r2   r2   r3   rë  Î  s$   
	rë  c               @   s‚  e Zd Ze d¡Zdd„ Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ ZdZd dd„ eD ƒ¡d  d¡Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Ze d*¡ d¡Zd+d,„ Zd-d.„ Ze d/¡Zd0d1„ Zd2d3„ Z d4d5„ Z!e "d¡Z#d6ge#d7d8…< d e#¡Z#d9d:„ Z$e d;¡ d<¡Z%e d=¡Z&d>d?„ Z'd@dA„ Z(dBdC„ Z)dDdE„ Z*dFdG„ Z+dHdI„ Z,dJdK„ Z-dLZ.dLS )MÚTest8BitBytesHandlingz½        From: foo@bar.com
        To: baz
        Mime-Version: 1.0
        Content-Type: text/plain; charset={charset}
        Content-Transfer-Encoding: {cte}

        {bodyline}
        c             C   sP   | j jdddd d¡}t |¡}|  | ¡ d¡ |  |jddd d¡¡ d S )Nzutf-8rD   u   pÃ¶stal)r5   r   Úbodylineu   pÃ¶stal
T)r@   )Úbodytest_msgrü   rs   rt   rj  r,   rA   )r/   r  r1   r2   r2   r3   Útest_known_8bit_CTE«  s    
z)Test8BitBytesHandling.test_known_8bit_CTEc             C   sP   | j jdddd d¡}t |¡}|  | ¡ d¡ |  |jddd	 d¡¡ d S )
NZnotavalidcharsetrD   u   pÃ¶stal)r5   r   r  zutf-8u   pï¿½ï¿½stal
T)r@   u   pÃ¶stal
)r  rü   rs   rt   rj  r,   rA   )r/   r  r1   r2   r2   r3   Útest_unknown_8bit_CTE´  s    
z+Test8BitBytesHandling.test_unknown_8bit_CTEc             C   sP   | j jdddd d¡}t |¡}|  | ¡ d¡ |  |jddd d¡¡ d S )	Nzutf-8zquoted-printableu   p=C3=B6stÃ¡l)r5   r   r  u   p=C3=B6stÃ¡l
T)r@   u	   pÃ¶stÃ¡l
)r  rü   rs   rt   rj  r,   rA   )r/   r  r1   r2   r2   r3   Útest_8bit_in_quopri_body½  s    

z.Test8BitBytesHandling.test_8bit_in_quopri_bodyc             C   sP   | j jdddd d¡}t |¡}|  | ¡ d¡ |  |jddd	 d¡¡ d S )
Nrr   zquoted-printableu   p=C3=B6stÃ¡l)r5   r   r  zutf-8u   p=C3=B6stï¿½ï¿½l
T)r@   u	   pÃ¶stÃ¡l
)r  rü   rs   rt   rj  r,   rA   )r/   r  r1   r2   r2   r3   Ú.test_invalid_8bit_in_non_8bit_cte_uses_replaceÏ  s    
zDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replacec             C   sT   | j jdddd d¡}t |¡}|  |jddd d¡¡ |  |jd t	j
¡ d S )	Nzutf-8r?   u   cMO2c3RhbAÃ¡=)r5   r   r  T)r@   u   pÃ¶stalr   )r  rü   rs   rt   rj  r,   rA   rí   rî   r   rï   )r/   r  r1   r2   r2   r3   Útest_8bit_in_base64_bodyß  s    
z.Test8BitBytesHandling.test_8bit_in_base64_bodyc             C   s@   | j jdddd d¡}t |¡}|  |jddd d¡¡ d S )Nzutf-8r|   u   <,.V<W1A; Ã¡ )r5   r   r  T)r@   u   <,.V<W1A; Ã¡ 
)r  rü   rs   rt   rj  r,   rA   )r/   r  r1   r2   r2   r3   Útest_8bit_in_uuencode_bodyì  s    
z0Test8BitBytesHandling.test_8bit_in_uuencode_body))zFrom: foo@bar.com)r†   zfoo@bar.com)u   To: bÃ¡z)r‰   z=?unknown-8bit?q?b=C3=A1z?=)uV   Subject: Maintenant je vous prÃ©sente mon collÃ¨gue, le pouf cÃ©lÃ¨bre
	Jean de Baddie)r  z†=?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=
 =?unknown-8bit?q?_Jean_de_Baddie?=)u   From: gÃ¶st)r†   z=?unknown-8bit?b?Z8O2c3Q=?=r&   c             C   s   g | ]\}}|‘qS r2   r2   )rQ   ÚsrcÚ_r2   r2   r3   rS     s    z Test8BitBytesHandling.<listcomp>z
Yes, they are flying.
zutf-8c             C   s:   t  | j¡}|  t| d¡ƒd¡ |  t|d ƒd¡ d S )Nr‡   u   bï¿½ï¿½z)rt   rj  Úheadertest_msgr,   r   rÿ  )r/   r1   r2   r2   r3   Útest_get_8bit_header  s    z*Test8BitBytesHandling.test_get_8bit_headerc             C   s8   t  | j¡}|  t|ƒt d¡jdd„ | jD ƒŽ ¡ d S )Nzä                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            c             S   s   g | ]\}}|d  ‘qS )rT   r2   )rQ   r  Úexpectedr2   r2   r3   rS     s    zATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	rt   rj  r  r,   r   r  r  rü   Úheadertest_headers)r/   r1   r2   r2   r3   Útest_print_8bit_headers	  s
    
z-Test8BitBytesHandling.test_print_8bit_headersc             C   s2   t  | j¡}|  dd„ | ¡ D ƒddddg¡ d S )Nc             S   s   g | ]}t |ƒ‘qS r2   )r   )rQ   rð   r2   r2   r3   rS     s    zGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>zfoo@bar.comu   bï¿½ï¿½zu]   Maintenant je vous prï¿½ï¿½sente mon collï¿½ï¿½gue, le pouf cï¿½ï¿½lï¿½ï¿½bre
	Jean de Baddieu	   gï¿½ï¿½st)rt   rj  r  ÚassertListEqualrå   )r/   r1   r2   r2   r3   Útest_values_with_8bit_headers  s    z3Test8BitBytesHandling.test_values_with_8bit_headersc             C   s2   t  | j¡}|  dd„ | ¡ D ƒddddg¡ d S )Nc             S   s    g | ]\}}t |ƒt |ƒf‘qS r2   )r   )rQ   rð   rŒ  r2   r2   r3   rS   #  s    zFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>)r†   zfoo@bar.com)r‰   u   bï¿½ï¿½z)r  u]   Maintenant je vous prï¿½ï¿½sente mon collï¿½ï¿½gue, le pouf cï¿½ï¿½lï¿½ï¿½bre
	Jean de Baddie)r†   u	   gï¿½ï¿½st)rt   rj  r  r  r^   )r/   r1   r2   r2   r3   Útest_items_with_8bit_headers!  s    z2Test8BitBytesHandling.test_items_with_8bit_headersc             C   s0   t  | j¡}|  dd„ | d¡D ƒddg¡ d S )Nc             S   s   g | ]}t |ƒ‘qS r2   )r   )rQ   rð   r2   r2   r3   rS   /  s    zHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>rˆ   zfoo@bar.comu	   gï¿½ï¿½st)rt   rj  r  r  r.   )r/   r1   r2   r2   r3   Útest_get_all_with_8bit_headers-  s    z4Test8BitBytesHandling.test_get_all_with_8bit_headersc             C   sJ   t  t d¡ d¡¡}|  | ¡ d¡ |  | ¡ d¡ |  | ¡ d¡ d S )NuA               Content-Type: text/plÂ§in; charset=utf-8
            zlatin-1u   text/plï¿½inr‚   u   plï¿½in)	rt   rj  r  r  rs   r,   r8   rÍ   rÖ   )r/   r1   r2   r2   r3   Útest_get_content_type_with_8bit3  s
    z5Test8BitBytesHandling.test_get_content_type_with_8bitc             C   sZ   t  d d¡¡}|  |jdddddg¡ |  |jdddd	¡ |  |jd
ddd ¡ d S )Nu(   X-Header: foo=Â§ne; bÂ§r=two; baz=three
zlatin-1zx-header)rb   )r~   u   ï¿½ne)u   bï¿½rr¨   )r    r©   ÚFoou   ï¿½neu   bÂ§r)rt   rj  rs   r,   rª   r9   )r/   r1   r2   r2   r3   Útest_get_params_with_8bit<  s    z/Test8BitBytesHandling.test_get_params_with_8bitc             C   s,   t  t d¡ d¡¡}|  | d¡d¡ d S )Nun               Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20fÂ§nzlatin-1Útitle)zus-asciiÚenu   This is not fï¿½n)rt   rj  r  r  rs   r,   r9   )r/   r1   r2   r2   r3   Ú!test_get_rfc2231_params_with_8bitF  s
    z7Test8BitBytesHandling.test_get_rfc2231_params_with_8bitc             C   s8   t  t d¡ d¡¡}| dd¡ |  | d¡d¡ d S )Nun               Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20fÂ§nzlatin-1r$  Útest)rt   rj  r  r  rs   r·   r,   r9   )r/   r1   r2   r2   r3   Ú!test_set_rfc2231_params_with_8bitN  s
    z7Test8BitBytesHandling.test_set_rfc2231_params_with_8bitc             C   sF   t  t d¡ d¡¡}| d¡ |  | d¡d ¡ |  | ¡ d¡ d S )Nun               Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20fÂ§nzlatin-1r$  r‚   )	rt   rj  r  r  rs   r¹   r,   r9   rÍ   )r/   r1   r2   r2   r3   Ú!test_del_rfc2231_params_with_8bitV  s    
z7Test8BitBytesHandling.test_del_rfc2231_params_with_8bitc             C   s>   t  t d¡ d¡¡}|  | ¡ d¡ |  |jddd¡ d S )Nu†               Content-Transfer-Encoding: bÂ§se64
            Content-Type: text/plain; charset=latin-1

            payload
            zlatin-1zpayload
T)r@   s   payload
)rt   rj  r  r  rs   r,   rA   )r/   r1   r2   r2   r3   Ú%test_get_payload_with_8bit_cte_header_  s    z;Test8BitBytesHandling.test_get_payload_with_8bit_cte_headeru0          From: foo@bar.com
        To: bÃ¡z
        Subject: Maintenant je vous prÃ©sente mon collÃ¨gue, le pouf cÃ©lÃ¨bre
        	Jean de Baddie
        Mime-Version: 1.0
        Content-Type: text/plain; charset="utf-8"
        Content-Transfer-Encoding: 8bit

        Ð”Ð°, Ð¾Ð½Ð¸ Ð»ÐµÑ‚ÑÑ‚.
        c             C   s:   t  | j¡}tƒ }t j |¡ |¡ |  | ¡ | j¡ d S )N)	rt   rj  Únon_latin_bin_msgr   rw   r   rj   r,   rk   )r/   r1   ro   r2   r2   r3   Útest_bytes_generatoru  s    z*Test8BitBytesHandling.test_bytes_generatorc             C   s6   t j ¡ }tƒ }t j |¡ |¡ |  | ¡ d¡ d S )Nr›   )	rt   rÏ   r   r   rw   r   rj   r,   rk   )r/   r1   ro   r2   r2   r3   Ú&test_bytes_generator_handles_None_body{  s    
z<Test8BitBytesHandling.test_bytes_generator_handles_None_bodya«          From: foo@bar.com
        To: =?unknown-8bit?q?b=C3=A1z?=
        Subject: =?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue?=
         =?unknown-8bit?q?=2C_le_pouf_c=C3=A9l=C3=A8bre?=
         =?unknown-8bit?q?_Jean_de_Baddie?=
        Mime-Version: 1.0
        Content-Type: text/plain; charset="utf-8"
        Content-Transfer-Encoding: base64

        0JTQsCwg0L7QvdC4INC70LXRgtGP0YIuCg==
        c             C   s:   t  | j¡}tƒ }t j |¡ |¡ |  | ¡ | j	¡ d S )N)
rt   rj  r+  r   rw   r   rj   r,   rk   Ú non_latin_bin_msg_as7bit_wrapped)r/   r1   ro   r2   r2   r3   Útest_generator_handles_8bit  s    z1Test8BitBytesHandling.test_generator_handles_8bitc             C   s`   t  | j¡}tƒ }t|ƒ |¡ | ¡ }ttƒ ƒ |¡ tƒ }t|ƒ |¡ |  	| ¡ |¡ d S )N)
rt   rj  r+  r   r   rj   rk   r   r   r,   )r/   r1   ro   Z
orig_valuer2   r2   r3   Ú;test_str_generator_should_not_mutate_msg_when_handling_8bit•  s    zQTest8BitBytesHandling.test_str_generator_should_not_mutate_msg_when_handling_8bitc             C   sn   t  | j¡}tƒ }t j |¡j|dd | ¡  d¡}|  	|d  ¡ d d¡ |  	d 
|dd … ¡| j¡ d S )NT)rŒ   r›   r   s   FromrT   )rt   rj  r+  r   rw   r   rj   rk   rŽ   r,   r’   )r/   r1   ro   r”   r2   r2   r3   Ú#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?=ry   r\   c          	   C   sn   d}|   t|¡ t|dƒ}| | j¡ W d Q R X t|dƒ}tj ¡  |¡}W d Q R X |  	t
|ƒ| j¡ d S )Nztest.msgÚwbr  )Ú
addCleanupr    ÚopenÚwriter+  rt   rn   rî  rà  r,   r   Únon_latin_bin_msg_as7bit)r/   rY  Útestfiler  r2   r2   r3   Útest_message_from_binary_file°  s    z3Test8BitBytesHandling.test_message_from_binary_fileu          From: foo@bar.com
        To: Dinsdale
        Subject: Nudge nudge, wink, wink
        Mime-Version: 1.0
        Content-Type: text/plain; charset="latin-1"
        Content-Transfer-Encoding: 8bit

        oh lÃ  lÃ , know what I mean, know what I mean?
        zlatin-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?
        c             C   s"   t  | j¡}|  t|ƒ| j¡ d S )N)rt   rj  Úlatin_bin_msgr,   r   Úlatin_bin_msg_as7bit)r/   r  r2   r2   r3   Ú:test_string_generator_reencodes_to_quopri_when_appropriateÏ  s    zPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriatec             C   sD   t  | j¡}tƒ }t j |¡ |¡ |  | ¡ | j 	d¡d ¡ d S )Nzlatin-1r&   )
rt   rj  r9  r   rw   r   rj   r,   rk   r@   )r/   r  ro   r2   r2   r3   Ú)test_decoded_generator_emits_unicode_bodyÓ  s
    
z?Test8BitBytesHandling.test_decoded_generator_emits_unicode_bodyc             C   s\   t j ¡ }x2tdt| jƒdƒD ]}| | j||d … ¡ qW | ¡ }|  t	|ƒ| j
¡ d S )Nr   r;  )rt   rR  r%   r?  r  r9  rÝ  rÞ  r,   r   r:  )r/   Zbfpr9  r  r2   r2   r3   Útest_bytes_feedparserÝ  s
    
z+Test8BitBytesHandling.test_bytes_feedparserc          	   C   s\   t ddƒ}| ¡ }W d Q R X t |¡}tƒ }tj |¡}|j|dd |  | 	¡ |¡ d S )Nz
msg_26.txtr  z
)r–   )
r"   rh   rt   rj  r   rw   r   rj   r,   rk   )r/   rl   r‚   r1   rƒ   r„   r2   r2   r3   rû  ä  s    
z'Test8BitBytesHandling.test_crlf_flattenc             C   sJ   t  d¡ d¡}t |¡}tƒ }tj |¡}| |¡ |  	| 
¡ |¡ d S )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--

            zutf-8)r  r  rs   rt   rj  r   rw   r   rj   r,   rk   )r/   rk  r1   rƒ   r„   r2   r2   r3   Útest_8bit_multipartí  s    %

z)Test8BitBytesHandling.test_8bit_multipartc             C   sF   t ƒ }tdƒ|d< tƒ }tj |¡}|j|dd |  | ¡ d¡ d S )Nu   Å¾luÅ¥ouÄkÃ½ kÅ¯Åˆr  z
)r–   s5   Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	r   r	   r   rt   rw   r   rj   r,   rk   )r/   r  rƒ   r„   r2   r2   r3   Ú'test_bytes_generator_b_encoding_linesep  s    z=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesepc             C   sF   t ƒ }tdƒ|d< tƒ }tj |¡}|j|dd |  | ¡ d¡ d S )Nu   Å¾luÅ¥ouÄkÃ½ kÅ¯Åˆr  z
)r–   z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	r   r	   r   rt   rw   r   rj   r,   rk   )r/   r  rƒ   r„   r2   r2   r3   Ú!test_generator_b_encoding_linesep'  s    z7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/r  r  r  r  r  r  r  r  r  r  r  r  r  r’   rs   r  r  r  r  r  r   r!  r#  r&  r(  r)  r*  r+  r,  r-  r.  r/  r0  r1  rŽ   r6  r8  r9  r:  r;  r<  r=  rû  r>  r?  r@  rc  r2   r2   r2   r3   r  ˜  s^   					
	




			
	.r  c               @   s"   e Zd ZdZdd„ Zddd„ZdS )Ú BaseTestBytesGeneratorIdempotentNc          	   C   s@   t |dƒ}| ¡ }W d Q R X | j | j|¡}t |¡}||fS )Nr  )r"   rh   Únormalize_linesep_regexÚsubÚblineseprt   rj  )r/   r¼   rl   rB   r1   r2   r2   r3   r-   :  s
    
z(BaseTestBytesGeneratorIdempotent._msgobjFc             C   s<   t ƒ }tjj|dd}|j||| jd |  || ¡ ¡ d S )Nr   )rS  )rŒ   r–   )r   rt   rw   r   rj   r–   r,   rk   )r/   r1   rB   rŒ   rl  r„   r2   r2   r3   r-  A  s    z,BaseTestBytesGeneratorIdempotent._idempotent)F)r  r  r  rc  r-   r-  r2   r2   r2   r3   rA  6  s   rA  c               @   s   e Zd ZdZdZe d¡ZdS )ÚTestBytesGeneratorIdempotentNLr&   r›   s   \r\nN)r  r  r  r–   rD  ÚreÚcompilerB  r2   r2   r2   r3   rE  H  s   rE  c               @   s   e Zd ZdZdZe d¡ZdS )Ú TestBytesGeneratorIdempotentCRLFz
s   
s	   (?<!\r)\nN)r  r  r  r–   rD  rF  rG  rB  r2   r2   r2   r3   rH  O  s   rH  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
TestBase64c             C   s˜   | j }|t d¡ttjdddƒƒ xntdƒD ]b}|dkr@d}n<|dkrNd}n.|d	kr\d
}n |dkrjd}n|dkrxd}nd}|t d| ¡|ƒ q.W d S )NÚhellos   hellor'   )Úeolé   r   rz   r\   rY  é   rq  é   é   é   rð   )r,   r   Úheader_lengthr  Úbody_encoder?  )r/   r0   ÚsizeZbsizer2   r2   r3   Útest_lenW  s     
     zTestBase64.test_lenc             C   s*   | j }|t d¡dƒ |t d¡dƒ d S )Nr'   ó    zaGVsbG8=s   hello)r,   r   r@   )r/   r0   r2   r2   r3   Útest_decoded  s    zTestBase64.test_decodec             C   sd   | j }|t d¡dƒ |t d¡dƒ |t d¡dƒ |tjdddd	ƒ |tjddd
ddƒ d S )NrU  s   helloz	aGVsbG8=
s   hello
z	aGVsbG8K
sd   xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx é(   )r*  zŒeHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
z
)r*  rK  zeHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r,   r   rR  )r/   r0   r2   r2   r3   Útest_encodei  s    zTestBase64.test_encodec             C   sZ   | j }tj}||dƒdƒ ||dƒdƒ ||dƒdƒ ||dddd	ƒ ||dƒdƒ d S )
NrJ  z=?iso-8859-1?b?aGVsbG8=?=zhello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=zhello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=z
iso-8859-2)r5   z=?iso-8859-2?b?aGVsbG8=?=)r,   r   r‚  )r/   r0   Úher2   r2   r3   Útest_header_encode  s    zTestBase64.test_header_encodeN)r  r  r  rT  rV  rX  rZ  r2   r2   r2   r3   rI  V  s   rI  c               @   s*  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdˆdd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd‰d&d'„Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd: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)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dŠdVdW„Z-dXdY„ Z.dZd[„ Z/d\d]„ Z0d^d_„ Z1d`da„ Z2dbdc„ Z3ddde„ Z4dfdg„ Z5dhdi„ Z6djdk„ Z7dldm„ Z8dndo„ Z9dpdq„ Z:drds„ Z;dtdu„ Z<dvdw„ Z=dxdy„ Z>dzd{„ Z?d|d}„ Z@d~d„ ZAd€d„ ZBd‚dƒ„ ZCd„d…„ ZDd†d‡„ ZEdS )‹Ú
TestQuopric                sü   t tttdƒtdƒd ƒttdƒtdƒd ƒttdƒtdƒd ƒdd	„ d
D ƒƒƒˆ _‡ fdd„tdƒD ƒˆ _tˆ jƒtˆ jƒ dksˆt‚t ttdƒtdƒd ƒƒˆ _ˆ j 	tdƒ¡ ˆ j 
tdƒ¡ ‡ fdd„tdƒD ƒˆ _tˆ jƒtˆ jƒ dksøt‚d S )Nrû  ÚzrT   r  ÚZra  Ú9c             s   s   | ]
}|V  qd S )Nr2   )rQ   rã  r2   r2   r3   r:  “  s    z#TestQuopri.setUp.<locals>.<genexpr>s   !*+-/c                s   g | ]}|ˆ j kr|‘qS r2   )Úhlit)rQ   rã  )r/   r2   r3   rS   –  s    z$TestQuopri.setUp.<locals>.<listcomp>é   r(   ú~r#  ú=c                s   g | ]}|ˆ j kr|‘qS r2   )Úblit)rQ   rã  )r/   r2   r3   rS   Ÿ  s    )r  r   r?  Úordr_  Úhnonr  ÚAssertionErrorrc  r+  ÚremoveÚbnon)r/   r2   )r/   r3   re  Œ  s    zTestQuopri.setUpc             C   sX   x(| j D ]}|  t |¡dt|ƒ ¡ qW x(| jD ]}|  t |¡dt|ƒ ¡ q2W d S )Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)r_  r“  r   Úheader_checkÚchrre  r   )r/   rã  r2   r2   r3   Útest_quopri_header_check¢  s    z#TestQuopri.test_quopri_header_checkc             C   sX   x(| j D ]}|  t |¡dt|ƒ ¡ qW x(| jD ]}|  t |¡dt|ƒ ¡ q2W d S )Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)rc  r“  r   Ú
body_checkrj  rh  r   )r/   rã  r2   r2   r3   Útest_quopri_body_checkª  s    z!TestQuopri.test_quopri_body_checkc             C   sì   | j }|t d¡dƒ |ttjdddƒt d¡d ƒ |t d¡dƒ |ttjdddƒt d¡d ƒ x.| jD ]$}|t t|gƒ¡dd	t|ƒ ƒ qrW x<| jD ]2}|t	d
ƒkr´q¢|t t|gƒ¡ddt|ƒ ƒ q¢W |t d¡dƒ d S )Ns   hellorj  Úxxx)r5   r;  s
   h@e@l@l@o@rP  rT   zexpected length 1 for %rr(   rz   zexpected length 3 for %ró    )
r,   r   rQ  r  r‚  r_  rœ   rj  re  rd  )r/   r0   rã  r2   r2   r3   Útest_header_quopri_len²  s$    z!TestQuopri.test_header_quopri_lenc             C   sV   | j }x$| jD ]}|t t|gƒ¡dƒ qW x$| jD ]}|t t|gƒ¡dƒ q4W d S )NrT   rz   )r,   rc  r   Úbody_lengthrœ   rh  )r/   r0   rã  r2   r2   r3   Útest_body_quopri_lenË  s
    zTestQuopri.test_body_quopri_lenc             C   s6   x0t dƒD ]$}t|ƒ}|  t t |¡¡|¡ q
W d S )Nr`  )r?  rj  r,   r   r±   Úquote)r/   rð   rã  r2   r2   r3   Útest_quote_unquote_idempotentÒ  s    z(TestQuopri.test_quote_unquote_idempotentNc             C   s0   |d krt  |¡}nt  ||¡}|  ||¡ d S )N)r   r‚  r,   )r/   rb   Zexpected_encoded_headerr5   Úencoded_headerr2   r2   r3   Ú_test_header_encode×  s    zTestQuopri._test_header_encodec             C   s   |   dd¡ d S )NrU  r'   )rv  )r/   r2   r2   r3   Útest_header_encode_nullÞ  s    z"TestQuopri.test_header_encode_nullc             C   s   |   dd¡ d S )Ns   helloz=?iso-8859-1?q?hello?=)rv  )r/   r2   r2   r3   Útest_header_encode_one_wordá  s    z&TestQuopri.test_header_encode_one_wordc             C   s   |   dd¡ d S )Ns   hello
worldz=?iso-8859-1?q?hello=0Aworld?=)rv  )r/   r2   r2   r3   Útest_header_encode_two_linesä  s    z'TestQuopri.test_header_encode_two_linesc             C   s   |   dd¡ d S )Ns   helloÇtherez=?iso-8859-1?q?hello=C7there?=)rv  )r/   r2   r2   r3   Útest_header_encode_non_asciiè  s    z'TestQuopri.test_header_encode_non_asciic             C   s   | j dddd d S )Ns   helloz=?iso-8859-2?q?hello?=z
iso-8859-2)r5   )rv  )r/   r2   r2   r3   Útest_header_encode_alt_charsetì  s    z)TestQuopri.test_header_encode_alt_charsetc             C   s   t  |¡}|  ||¡ d S )N)r   Úheader_decoder,   )r/   ru  Zexpected_decoded_headerZdecoded_headerr2   r2   r3   Ú_test_header_decodeð  s    
zTestQuopri._test_header_decodec             C   s   |   dd¡ d S )Nr'   )r}  )r/   r2   r2   r3   Útest_header_decode_nullô  s    z"TestQuopri.test_header_decode_nullc             C   s   |   dd¡ d S )NrJ  )r}  )r/   r2   r2   r3   Útest_header_decode_one_word÷  s    z&TestQuopri.test_header_decode_one_wordc             C   s   |   dd¡ d S )Nzhello=0Aworldzhello
world)r}  )r/   r2   r2   r3   Útest_header_decode_two_linesú  s    z'TestQuopri.test_header_decode_two_linesc             C   s   |   dd¡ d S )Nzhello=C7thereu   helloÃ‡there)r}  )r/   r2   r2   r3   Útest_header_decode_non_asciiý  s    z'TestQuopri.test_header_decode_non_asciic             C   s   |   t d¡d¡ d S )Na  =30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30=30A  00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)r,   r   r|  )r/   r2   r2   r3   Útest_header_decode_re_bug_18380   s    z*TestQuopri.test_header_decode_re_bug_18380c             C   s2   |d krt  |¡}nt j||d}|  ||¡ d S )N)rK  )r   r@   r,   )r/   ÚencodedZexpected_decodedrK  Údecodedr2   r2   r3   Ú_test_decode  s    zTestQuopri._test_decodec             C   s   |   dd¡ d S )Nr'   )r…  )r/   r2   r2   r3   Útest_decode_null_word  s    z TestQuopri.test_decode_null_wordc             C   s   |   dd¡ d S )Nz
r&   )r…  )r/   r2   r2   r3   Útest_decode_null_line_null_word  s    z*TestQuopri.test_decode_null_line_null_wordc             C   s   |   dd¡ d S )NrJ  )r…  )r/   r2   r2   r3   Útest_decode_one_word  s    zTestQuopri.test_decode_one_wordc             C   s   | j dddd d S )NrJ  ÚX)rK  )r…  )r/   r2   r2   r3   Útest_decode_one_word_eol  s    z#TestQuopri.test_decode_one_word_eolc             C   s   |   dd¡ d S )Nzhello
zhello
)r…  )r/   r2   r2   r3   Útest_decode_one_line  s    zTestQuopri.test_decode_one_linec             C   s   |   dd¡ d S )Nzhello
)r…  )r/   r2   r2   r3   Útest_decode_one_line_lf  s    z"TestQuopri.test_decode_one_line_lfc             C   s   |   dd¡ d S )Nzhellozhello
)r…  )r/   r2   r2   r3   Útest_decode_one_line_cr  s    z"TestQuopri.test_decode_one_line_crc             C   s   | j dddd d S )Nzhello
ÚhelloXr‰  )rK  )r…  )r/   r2   r2   r3   Útest_decode_one_line_nl   s    z"TestQuopri.test_decode_one_line_nlc             C   s   | j dddd d S )Nzhello
rŽ  r‰  )rK  )r…  )r/   r2   r2   r3   Útest_decode_one_line_crnl#  s    z$TestQuopri.test_decode_one_line_crnlc             C   s   |   dd¡ d S )Nzhello
worldzhello
world)r…  )r/   r2   r2   r3   Útest_decode_one_line_one_word&  s    z(TestQuopri.test_decode_one_line_one_wordc             C   s   | j dddd d S )Nzhello
worldZhelloXworldr‰  )rK  )r…  )r/   r2   r2   r3   Ú!test_decode_one_line_one_word_eol)  s    z,TestQuopri.test_decode_one_line_one_word_eolc             C   s   |   dd¡ d S )Nzhello
world
zhello
world
)r…  )r/   r2   r2   r3   Útest_decode_two_lines,  s    z TestQuopri.test_decode_two_linesc             C   s   | j dddd d S )Nzhello
world
ZhelloXworldXr‰  )rK  )r…  )r/   r2   r2   r3   Útest_decode_two_lines_eol/  s    z$TestQuopri.test_decode_two_lines_eolc             C   s   |   dd¡ d S )NAè  SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam)r…  )r/   r2   r2   r3   Útest_decode_one_long_line2  s    z$TestQuopri.test_decode_one_long_linec             C   s   |   dd¡ d S )Nr(   r'   )r…  )r/   r2   r2   r3   Útest_decode_one_space5  s    z TestQuopri.test_decode_one_spacec             C   s   |   dd¡ d S )Nz     r'   )r…  )r/   r2   r2   r3   Útest_decode_multiple_spaces8  s    z&TestQuopri.test_decode_multiple_spacesc             C   s   |   dd¡ d S )Nzhello    
zhello
)r…  )r/   r2   r2   r3   Ú$test_decode_one_line_trailing_spaces;  s    z/TestQuopri.test_decode_one_line_trailing_spacesc             C   s   |   dd¡ d S )Nzhello    
world   
zhello
world
)r…  )r/   r2   r2   r3   Ú%test_decode_two_lines_trailing_spaces>  s    z0TestQuopri.test_decode_two_lines_trailing_spacesc             C   s   |   dd¡ d S )Nz=22quoted=20words=22z"quoted words")r…  )r/   r2   r2   r3   Útest_decode_quoted_wordA  s    z"TestQuopri.test_decode_quoted_wordc             C   s   |   dd¡ d S )Nzab=CD=EFu   abÃÃ¯)r…  )r/   r2   r2   r3   Útest_decode_uppercase_quotingD  s    z(TestQuopri.test_decode_uppercase_quotingc             C   s   |   dd¡ d S )Nzab=cd=efu   abÃÃ¯)r…  )r/   r2   r2   r3   Útest_decode_lowercase_quotingG  s    z(TestQuopri.test_decode_lowercase_quotingc             C   s   |   dd¡ d S )Nzsoft line=
breakzsoft linebreak)r…  )r/   r2   r2   r3   Útest_decode_soft_line_breakJ  s    z&TestQuopri.test_decode_soft_line_breakc             C   s   |   dd¡ d S )NzA=1,B=A ==> A+B==2)r…  )r/   r2   r2   r3   Útest_decode_false_quotingM  s    z$TestQuopri.test_decode_false_quotingc             C   s€   i }|d krd}n||d< |d kr(d}n||d< t j|f|Ž}|  ||¡ |dksZ|dkr|x | ¡ D ]}|  t|ƒ|¡ qdW d S )Nr  r*  r&   rK  z
)r   rR  r,   r	  r  r  )r/   rè  Zexpected_encoded_bodyr*  rK  ÚkwargsÚencoded_bodyrë  r2   r2   r3   Ú_test_encodeP  s    zTestQuopri._test_encodec             C   s   |   dd¡ d S )Nr'   )r¡  )r/   r2   r2   r3   Útest_encode_nulld  s    zTestQuopri.test_encode_nullc             C   s   |   dd¡ d S )Nz

)r¡  )r/   r2   r2   r3   Útest_encode_null_linesg  s    z!TestQuopri.test_encode_null_linesc             C   s   |   dd¡ d S )Nzhello
)r¡  )r/   r2   r2   r3   Útest_encode_one_linej  s    zTestQuopri.test_encode_one_linec             C   s   |   dd¡ d S )Nzhello
zhello
)r¡  )r/   r2   r2   r3   Útest_encode_one_line_crlfm  s    z$TestQuopri.test_encode_one_line_crlfc             C   s   | j dddd d S )Nzhello
zhello
z
)rK  )r¡  )r/   r2   r2   r3   Útest_encode_one_line_eolp  s    z#TestQuopri.test_encode_one_line_eolc             C   s    | j d d¡ d¡ddd d S )Nu   helloÏ…
zutf-8Úlatin1zhello=CF=85
z
)rK  )r¡  rs   r@   )r/   r2   r2   r3   Ú(test_encode_one_line_eol_after_non_asciis  s    z3TestQuopri.test_encode_one_line_eol_after_non_asciic             C   s   |   dd¡ d S )Nr(   z=20)r¡  )r/   r2   r2   r3   Útest_encode_one_spacex  s    z TestQuopri.test_encode_one_spacec             C   s   |   dd¡ d S )Nz 
z=20
)r¡  )r/   r2   r2   r3   Útest_encode_one_line_one_space{  s    z)TestQuopri.test_encode_one_line_one_spacec             C   s   |   dd¡ d S )Nz 
 
z=20
=20
)r¡  )r/   r2   r2   r3   Útest_encode_two_lines_one_spaceƒ  s    z*TestQuopri.test_encode_two_lines_one_spacec             C   s   |   dd¡ d S )Nzhello   z
hello  =20)r¡  )r/   r2   r2   r3   Ú$test_encode_one_word_trailing_spaces†  s    z/TestQuopri.test_encode_one_word_trailing_spacesc             C   s   |   dd¡ d S )Nz	hello   
zhello  =20
)r¡  )r/   r2   r2   r3   Ú$test_encode_one_line_trailing_spaces‰  s    z/TestQuopri.test_encode_one_line_trailing_spacesc             C   s   |   dd¡ d S )Nzhello  	z
hello  =09)r¡  )r/   r2   r2   r3   Ú!test_encode_one_word_trailing_tabŒ  s    z,TestQuopri.test_encode_one_word_trailing_tabc             C   s   |   dd¡ d S )Nz	hello  	
zhello  =09
)r¡  )r/   r2   r2   r3   Ú!test_encode_one_line_trailing_tab  s    z,TestQuopri.test_encode_one_line_trailing_tabc             C   s   | j dddd d S )Nz
abcd 
1234zabcd =

1234rY  )r*  )r¡  )r/   r2   r2   r3   Ú,test_encode_trailing_space_before_maxlinelen’  s    z7TestQuopri.test_encode_trailing_space_before_maxlinelenc             C   s   | j dddd d S )Nz
abcd 
1234zabcd=
=20
1234rj  )r*  )r¡  )r/   r2   r2   r3   Ú(test_encode_trailing_space_at_maxlinelen•  s    z3TestQuopri.test_encode_trailing_space_at_maxlinelenc             C   s   | j dddd d S )Nz
abcd 
1234zabc=
d=20
1234r\   )r*  )r¡  )r/   r2   r2   r3   Ú,test_encode_trailing_space_beyond_maxlinelen˜  s    z7TestQuopri.test_encode_trailing_space_beyond_maxlinelenc             C   s   |   dd¡ d S )Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
)r¡  )r/   r2   r2   r3   Útest_encode_whitespace_lines›  s    z'TestQuopri.test_encode_whitespace_linesc             C   s   |   dd¡ d S )Nza = bza =3D b)r¡  )r/   r2   r2   r3   Útest_encode_quoted_equalsž  s    z$TestQuopri.test_encode_quoted_equalsc             C   s   |   dd¡ d S )NZdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx)r¡  )r/   r2   r2   r3   Útest_encode_one_long_string¡  s    z&TestQuopri.test_encode_one_long_stringc             C   s   |   dd¡ d S )Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
)r¡  )r/   r2   r2   r3   Útest_encode_one_long_line¤  s    z$TestQuopri.test_encode_one_long_linec             C   s   |   dd¡ d S )NzÉxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zÍxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
)r¡  )r/   r2   r2   r3   Útest_encode_one_very_long_line§  s    z)TestQuopri.test_encode_one_very_long_linec             C   s   | j dddd d S )Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr\   )r*  )r¡  )r/   r2   r2   r3   Útest_encode_shortest_maxlinelen«  s    z*TestQuopri.test_encode_shortest_maxlinelenc             C   s   | j t| jdddd d S )Nr'   rz   )r*  )r`   rÂ   r¡  )r/   r2   r2   r3   Ú test_encode_maxlinelen_too_small®  s    z+TestQuopri.test_encode_maxlinelen_too_smallc             C   st   | j }|t d¡dƒ |t d¡dƒ |t d¡dƒ |tjddddƒ |tjddd	d
dƒ |t d¡dƒ d S )Nr'   rJ  zhello
worldzhello
worldzdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx rW  )r*  zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20z
)r*  rK  zlxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20zone line

two line)r,   r   rR  )r/   r0   r2   r2   r3   rX  ±  s    zTestQuopri.test_encode)N)N)NN)Fr  r  r  re  rk  rm  rp  rr  rt  rv  rw  rx  ry  rz  r{  r}  r~  r  r€  r  r‚  r…  r†  r‡  rˆ  rŠ  r‹  rŒ  r  r  r  r‘  r’  r“  r”  r•  r–  r—  r˜  r™  rš  r›  rœ  r  rž  r¡  r¢  r£  r¤  r¥  r¦  r¨  r©  rª  r«  r¬  r­  r®  r¯  r°  r±  r²  r³  r´  rµ  r¶  r·  r¸  r¹  rX  r2   r2   r2   r3   r[  ‹  s†   


r[  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestCharsetc             C   s2   ddl m} y|jd= W n tk
r,   Y nX d S )Nr   )r5   Úfake)rt   r5   ÚCHARSETSrç   )r/   ÚCharsetModuler2   r2   r3   ÚtearDownÎ  s
    zTestCharset.tearDownc             C   sN   | j }tdƒ}|| d¡dƒ d}|  t|j|¡ tdƒ}|| |¡dƒ d S )Nzus-asciizHello World!u   Â¤Â¢Â¤Â¤Â¤Â¦Â¤Â¨Â¤Âªzutf-8z(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r,   r   r‚  r`   rŠ  )r/   r0   rã  rƒ   r2   r2   r3   Útest_codec_encodeableÕ  s    z!TestCharset.test_codec_encodeablec             C   s   | j }tdƒ}|d| d¡ƒ tdƒ}|d| d¡ƒ tdƒ}|d| d¡ƒ td	ƒ}d
dlm} | d|jd d¡ tdƒ}|d| d¡ƒ d S )Nz
iso-8859-1zhello w=F6rldu   hello wÃ¶rldzutf-8zaGVsbG8gd29ybGQ=
s   hello worldzus-asciizhello worldzeuc-jpr   )r5   r»  )r,   r   rR  rt   r5   Úadd_charsetÚQP)r/   r0   rã  r½  r2   r2   r3   Útest_body_encodeà  s    zTestCharset.test_body_encodec             C   s,   t dƒ}|  t|ƒd¡ |  tjt d¡ d S )Nzus-asciiu   ascÃ¿ii)r   r,   r   r`   r   ÚCharsetError)r/   r5   r2   r2   r3   Útest_unicode_charset_nameÿ  s    z%TestCharset.test_unicode_charset_nameN)r  r  r  r¾  r¿  rÂ  rÄ  r2   r2   r2   r3   rº  Í  s   rº  c               @   sÌ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1S )2Ú
TestHeaderc             C   s8   | j }tdƒ}|| ¡ dƒ | d¡ || ¡ dƒ d S )NzHello World!z Goodbye World!zHello World!  Goodbye World!)r   r	   rs   r+  )r/   r0   r'  r2   r2   r3   Útest_simple  s
    
zTestHeader.test_simplec             C   s8   | j }tdƒ}|| ¡ dƒ | d¡ || ¡ dƒ d S )NzHello World!zGoodbye World!zHello World! Goodbye World!)r   r	   rs   r+  )r/   r0   r'  r2   r2   r3   Útest_simple_surprise  s
    
zTestHeader.test_simple_surprisec             C   s   d}|   t|ƒ|d fg¡ d S )Nzno decoding needed)r,   r
   )r/   r'  r2   r2   r3   Útest_header_needs_no_decoding  s    z(TestHeader.test_header_needs_no_decodingc             C   s<   t ddd}x*|jdd d¡D ]}|  t|ƒd¡ q W d S )Na¶  I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.r  )r*  r(   )Ú
splitcharsz
 )r	   rs   rŽ   r  r  )r/   r'  Úlr2   r2   r3   Ú	test_long  s    zTestHeader.test_longc             C   sæ   | j }tdƒ}tdƒ}tdƒ}d}d}d}t||ƒ}| ||¡ | ||¡ |jdd}	||	d	ƒ t|	ƒ}
|t|
ƒd
ƒ ||
d |dfƒ ||
d |dfƒ ||
d | d¡dfƒ t|ƒ}||d d¡ƒ t	t|	ƒƒ}|||ƒ d S )Nz
iso-8859-1z
iso-8859-2zutf-8s©   Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an südlündischen Wandgemälden vorbei, gegen die rotierenden Klingen befördert. s;   Finanèni metropole se hroutily pod tlakem jejich dùvtipu.. uø   æ­£ç¢ºã«è¨€ã†ã¨ç¿»è¨³ã¯ã•ã‚Œã¦ã„ã¾ã›ã‚“ã€‚ä¸€éƒ¨ã¯ãƒ‰ã‚¤ãƒ„èªžã§ã™ãŒã€ã‚ã¨ã¯ã§ãŸã‚‰ã‚ã§ã™ã€‚å®Ÿéš›ã«ã¯ã€ŒWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.ã€ã¨è¨€ã£ã¦ã„ã¾ã™ã€‚r  )r*  a  =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderband_kom?=
 =?iso-8859-1?q?fortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen_Wand?=
 =?iso-8859-1?q?gem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef=F6r?=
 =?iso-8859-1?q?dert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutily?=
 =?iso-8859-2?q?_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
 =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC?=
 =?utf-8?b?5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn?=
 =?utf-8?b?44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFz?=
 =?utf-8?b?IE51bnN0dWNrIGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWloZXJodW5k?=
 =?utf-8?b?IGRhcyBPZGVyIGRpZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI3jgajoqIA=?=
 =?utf-8?b?44Gj44Gm44GE44G+44GZ44CC?=rz   r   rT   ry   sâ  Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an sÃ¼dlÃ¼ndischen WandgemÃ¤lden vorbei, gegen die rotierenden Klingen befÃ¶rdert. FinanÄni metropole se hroutily pod tlakem jejich dÅ¯vtipu.. æ­£ç¢ºã«è¨€ã†ã¨ç¿»è¨³ã¯ã•ã‚Œã¦ã„ã¾ã›ã‚“ã€‚ä¸€éƒ¨ã¯ãƒ‰ã‚¤ãƒ„èªžã§ã™ãŒã€ã‚ã¨ã¯ã§ãŸã‚‰ã‚ã§ã™ã€‚å®Ÿéš›ã«ã¯ã€ŒWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.ã€ã¨è¨€ã£ã¦ã„ã¾ã™ã€‚)
r   r   r	   r+  rs   r
   r  r   r@   r   )r/   r0   r„   r,  r-  r.  r/  r0  r'  Úencr„  ZustrZnewhr2   r2   r3   Útest_multilingual   s0    
zTestHeader.test_multilingualc             C   s   t ƒ }|  | ¡ d¡ d S )Nr'   )r	   r,   rs   )r/   r'  r2   r2   r3   Útest_empty_header_encode_  s    z#TestHeader.test_empty_header_encodec             C   s4   | j }tƒ }||dƒ | dtdƒ¡ ||dƒ d S )Nr'   r~   z
iso-8859-1)r   r	   r+  r   )r/   r0   r'  r2   r2   r3   Útest_header_ctor_default_argsc  s
    
z(TestHeader.test_header_ctor_default_argsc             C   s„   | j }d}t|ƒ}|| ¡ dƒ |t|ƒ|ƒ t|dd}|| ¡ dƒ |t|ƒ|ƒ t|ddd}|| ¡ |ƒ |t|ƒ|ƒ d S )Nz|A very long line that must get split to something other than at the 76th character boundary to test the non-default behaviorz}A very long line that must get split to something other than at the 76th
 character boundary to test the non-default behaviorr  )r)  z}A very long line that must get split to something other than at the
 76th character boundary to test the non-default behaviori   )r*  r)  )r   r	   rs   r   )r/   r0   r&  r'  r2   r2   r3   Útest_explicit_maxlinelenj  s    z#TestHeader.test_explicit_maxlinelenc             C   sŠ   | j }tddd}d}| |¡ | ¡ }||dƒ ||ttt|ƒƒƒƒ tddd}| d¡ | ¡ }||dƒ ||ttt|ƒƒƒƒ d S )Nz
iso-8859-1rP  )r5   r*  zdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx a  =?iso-8859-1?q?xxx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_x?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?x_?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?xx?=
 =?iso-8859-1?q?_?=rW  zÁ=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xxx?=
 =?iso-8859-1?q?x_xxxx_xxxx_xxxx_xxxx_?=
 =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
 =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
 =?iso-8859-1?q?_xxxx_xxxx_?=)r   r	   r+  rs   r   r   r
   )r/   r0   r'  rð   rƒ   r2   r2   r3   Útest_quopri_splittable}  s    
2
z!TestHeader.test_quopri_splittablec             C   sŠ   | j }tddd}d}| |¡ | ¡ }||dƒ ||ttt|ƒƒƒƒ tddd}| |¡ | ¡ }||dƒ ||ttt|ƒƒƒƒ d S )Nzkoi8-rrP  )r5   r*  zdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx a„  =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IHh4?=
 =?koi8-r?b?eHgg?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?eCB4?=
 =?koi8-r?b?eHh4?=
 =?koi8-r?b?IA==?=rW  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	   r+  rs   r   r   r
   )r/   r0   r'  rð   rƒ   r2   r2   r3   Útest_base64_splittableÂ  s    
"
z!TestHeader.test_base64_splittablec             C   s8   | j }d}t|ƒ}||dgƒ t|ƒ}||| ¡ ƒ d S )NrJ  )rJ  N)r,   r
   r   rs   )r/   r0   rƒ   rð   r'  r2   r2   r3   Útest_us_ascii_headerø  s    zTestHeader.test_us_ascii_headerc             C   s&   | j }tƒ }| dd¡ ||dƒ d S )NrJ  z
iso-8859-1)r,   r	   r+  )r/   r0   r'  r2   r2   r3   Útest_string_charset   s    zTestHeader.test_string_charsetc             C   s:   | j }tddƒ}|| ¡ dƒ tddƒ}|| ¡ dƒ d S )Nu   pÃ¶stalzutf-8z=?utf-8?q?p=C3=B6stal?=u   èŠåœ°æ™‚å¤«z=?utf-8?b?6I+K5Zyw5pmC5aSr?=)r,   r	   rs   )r/   r0   r'  r2   r2   r3   Útest_utf8_shortest  s
    

zTestHeader.test_utf8_shortestc             C   sr   | j }| j}d}|tt|ƒ tƒ }|t|j|ƒ | dd¡}|tt|ddƒ|ƒ |j|dd |t|ƒ|ƒ d S )Ns0   Ynwp4dUEbay Auction Semiar- No Charge – Earn Bigzutf-8r%  )r   )r`   r,   rŠ  r	   r+  r@   r   )r/   rµ  r0   rð   r'  Úer2   r2   r3   Útest_bad_8bit_header  s    zTestHeader.test_bad_8bit_headerc             C   sN   d}|  dd¡}t|tjjd}|  t|ƒd¡ |  tj |¡|dfg¡ d S )Ns0   Ynwp4dUEbay Auction Semiar- No Charge – Earn Bigrr   Úsurrogateescape)r5   u2   Ynwp4dUEbay Auction Semiar- No Charge ï¿½ Earn Bigzunknown-8bit)	r@   r	   rt   r5   ÚUNKNOWN8BITr,   r   rb   r
   )r/   rð   rÖ  r'  r2   r2   r3   Útest_escaped_8bit_header"  s    
z#TestHeader.test_escaped_8bit_headerc             C   sB   d}t |tjjd}|  t|ƒd¡ |  tj |¡|dfg¡ d S )Ns0   Ynwp4dUEbay Auction Semiar- No Charge – Earn Big)r5   u2   Ynwp4dUEbay Auction Semiar- No Charge ï¿½ Earn Bigzunknown-8bit)r	   rt   r5   rÙ  r,   r   rb   r
   )r/   rð   r'  r2   r2   r3   Ú&test_header_handles_binary_unknown8bit*  s
    
z1TestHeader.test_header_handles_binary_unknown8bitc             C   sV   d}t |tjjd}tj tj |¡¡}|  t|ƒd¡ |  tj |¡|dfg¡ d S )Ns0   Ynwp4dUEbay Auction Semiar- No Charge – Earn Big)r5   u2   Ynwp4dUEbay Auction Semiar- No Charge ï¿½ Earn Bigzunknown-8bit)	r	   rt   r5   rÙ  rb   r   r
   r,   r   )r/   rð   r'  Zh2r2   r2   r3   Ú+test_make_header_handles_binary_unknown8bit1  s    
z6TestHeader.test_make_header_handles_binary_unknown8bitc             C   s2   t dƒ}tj |¡}| d¡ |  t|ƒd¡ d S )Nr'  )rr   Útest2)r	   rt   rb   r
   r+  r,   r   )r/   r'  rß  r2   r2   r3   Ú0test_modify_returned_list_does_not_change_header9  s    
z;TestHeader.test_modify_returned_list_does_not_change_headerc             C   sR   | j }tƒ }| dd¡ | d¡ | ¡ }||dƒ tt|ƒƒ}|| ¡ |ƒ d S )NrJ  z
iso-8859-1Úworldz=?iso-8859-1?q?hello?= world)r,   r	   r+  rs   r   r
   )r/   r0   r'  rƒ   r2   r2   r3   Ú test_encoded_adjacent_nonencoded?  s    

z+TestHeader.test_encoded_adjacent_nonencodedc             C   s<   | j }d}t|ƒ}||dddgƒ t|ƒ}|| ¡ dƒ d S )NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.)s	   Subject: N)s   ðÒÏ×ÅÒËÁ ÎÁ ÆÉÎÁÌØÎÙÊzkoi8-r)s    zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.)r,   r
   r   rs   )r/   r0   rƒ   ÚpartsÚhdrr2   r2   r3   Útest_whitespace_keeperI  s    z!TestHeader.test_whitespace_keeperc             C   s   | j }d}|tjt|ƒ d S )NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r`   r   ra   r
   )r/   rµ  rƒ   r2   r2   r3   Útest_broken_base64_headerR  s    z$TestHeader.test_broken_base64_headerc             C   s    t ddd}|  | ¡ d¡ d S )Nu   æ–‡Ú	shift_jis)r5   z=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	   r,   rs   )r/   r'  r2   r2   r3   Útest_shift_jis_charsetW  s    z!TestHeader.test_shift_jis_charsetc             C   s   t  d¡}|  t|ƒd¡ d S )NzEmptyHeader:zEmptyHeader: 

)rt   r¡   r,   r   )r/   r1   r2   r2   r3   Ú!test_flatten_header_with_no_value[  s    
z,TestHeader.test_flatten_header_with_no_valuec             C   s"   t ƒ }d|d< |  t|ƒd¡ d S )Nz   value with leading wsZ
SomeHeaderz&SomeHeader:    value with leading ws

)r   r,   r   )r/   r1   r2   r2   r3   Ú)test_encode_preserves_leading_ws_on_valueb  s    z4TestHeader.test_encode_preserves_leading_ws_on_valueN)r  r  r  rÆ  rÇ  rÈ  rË  rÍ  rÎ  rÏ  rÐ  rÑ  rÒ  rÓ  rÔ  rÕ  r×  rÚ  rÛ  rÜ  rÞ  rà  rã  rä  ræ  rç  rè  r2   r2   r2   r3   rÅ    s0   ?E6
	rÅ  c               @   sì   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9S ):ÚTestRFC2231c             C   s8   | j }|  d¡}|| d¡dƒ ||jddddƒ d S )Nz
msg_29.txtr$  )zus-asciir%  z%This is even more ***fun*** isn't it!F)r±   )zus-asciir%  z'"This is even more ***fun*** isn't it!")r,   r-   r9   )r/   r0   r1   r2   r2   r3   r®   n  s    

zTestRFC2231.test_get_paramc             C   s€   | j }tƒ }|jdddd || d¡dƒ |jddddd || d¡dƒ |  d	¡}|jddddd ||jd
ddƒ d S )Nr$  z%This is even more ***fun*** isn't it!zus-ascii)r5   )zus-asciir'   z%This is even more ***fun*** isn't it!r%  )r5   Úlanguage)zus-asciir%  z%This is even more ***fun*** isn't it!z
msg_01.txtrQ  )rS  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·   r9   r-   rf   )r/   r0   r1   r2   r2   r3   r¸   v  s    




zTestRFC2231.test_set_paramc             C   sf   t ƒ }| dd¡ |  |d d¡ |jdddd |  |d d¡ |jdd	dd |  |d d
¡ d S )Nr$  r~   zcontent-typeztext/plain; title="foo"r§   F)Úrequoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")r   r·   r,   )r/   r1   r2   r2   r3   Útest_set_param_requote›  s    z"TestRFC2231.test_set_param_requotec             C   sX   | j }|  d¡}|jddddd |jddddd |jdd	d
 ||jdddƒ d S )Nz
msg_01.txtr~   r§   zus-asciir%  )r5   rê  r$  z%This is even more ***fun*** isn't it!zContent-Type)rb   rQ  )rS  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¹   rf   )r/   r0   r1   r2   r2   r3   rº   ¥  s    

zTestRFC2231.test_del_paramc             C   s"   | j }|  d¡}|| ¡ dƒ d S )Nz
msg_32.txtzus-ascii)r,   r-   Úget_content_charset)r/   r0   r1   r2   r2   r3   Ú test_rfc2231_get_content_charsetÆ  s    
z,TestRFC2231.test_rfc2231_get_content_charsetc             C   s8   t  d¡}t |¡}|  | ¡ d¡ |  || ¡ ¡ d S )NzÈ            Content-Disposition: inline;
            	filename*0*=''This%20is%20even%20more%20;
            	filename*1*=%2A%2A%2Afun%2A%2A%2A%20;
            	filename*2="is it not.pdf"

            z)This is even more ***fun*** is it not.pdf)r  r  rt   r¡   r,   rP   rf   )r/   r  r1   r2   r2   r3   Útest_rfc2231_parse_rfc_quotingÌ  s    

z*TestRFC2231.test_rfc2231_parse_rfc_quotingc             C   s8   t  d¡}t |¡}|  | ¡ d¡ |  || ¡ ¡ d S )NzÌ            Content-Disposition: inline;
            	filename*0*="''This%20is%20even%20more%20";
            	filename*1*="%2A%2A%2Afun%2A%2A%2A%20";
            	filename*2="is it not.pdf"

            z)This is even more ***fun*** is it not.pdf)r  r  rt   r¡   r,   rP   rf   )r/   r  r1   r2   r2   r3   Ú test_rfc2231_parse_extra_quotingÚ  s    

z,TestRFC2231.test_rfc2231_parse_extra_quotingc             C   s4   d}t  |¡}| d¡}|  |t¡ |  |d¡ d S )Na  Content-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)rt   r¡   r9   ÚassertNotIsInstanceÚtupler,   )r/   r  r1   Úparamr2   r2   r3   Ú#test_rfc2231_no_language_or_charsetê  s    

z/TestRFC2231.test_rfc2231_no_language_or_charsetc             C   s"   d}t  |¡}|  | ¡ d¡ d S )NzContent-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)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Ú/test_rfc2231_no_language_or_charset_in_filenameù  s    

z;TestRFC2231.test_rfc2231_no_language_or_charset_in_filenamec             C   s"   d}t  |¡}|  | ¡ d¡ d S )NzContent-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)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Ú7test_rfc2231_no_language_or_charset_in_filename_encoded  s    

zCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedc             C   s"   d}t  |¡}|  | ¡ d¡ d S )NzContent-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)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Útest_rfc2231_partly_encoded  s
    
z'TestRFC2231.test_rfc2231_partly_encodedc             C   s"   d}t  |¡}|  | ¡ d¡ d S )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)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Útest_rfc2231_partly_nonencoded!  s
    
z*TestRFC2231.test_rfc2231_partly_nonencodedc             C   s"   d}t  |¡}|  | ¡ d¡ d S )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)rt   r¡   r,   rZ   )r/   r  r1   r2   r2   r3   Ú/test_rfc2231_no_language_or_charset_in_boundary.  s    

z;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundaryc             C   s"   d}t  |¡}|  | ¡ d¡ d S )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)rt   r¡   r,   rí  )r/   r  r1   r2   r2   r3   Ú.test_rfc2231_no_language_or_charset_in_charset:  s    

z:TestRFC2231.test_rfc2231_no_language_or_charset_in_charsetc             C   s"   d}t  |¡}|  | ¡ d¡ d S )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)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Ú%test_rfc2231_bad_encoding_in_filenameH  s    

z1TestRFC2231.test_rfc2231_bad_encoding_in_filenamec             C   s"   d}t  |¡}|  | ¡ d ¡ d S )Nz:Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D

)rt   r¡   r,   rí  )r/   r  r1   r2   r2   r3   Ú$test_rfc2231_bad_encoding_in_charsetT  s    
z0TestRFC2231.test_rfc2231_bad_encoding_in_charsetc             C   s"   d}t  |¡}|  | ¡ d ¡ d S )Nz:Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D

)rt   r¡   r,   rí  )r/   r  r1   r2   r2   r3   Ú%test_rfc2231_bad_character_in_charset^  s    
z1TestRFC2231.test_rfc2231_bad_character_in_charsetc             C   s"   d}t  |¡}|  | ¡ d¡ d S )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ï¿½)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Ú&test_rfc2231_bad_character_in_filenameh  s    

z2TestRFC2231.test_rfc2231_bad_character_in_filenamec             C   s"   d}t  |¡}|  | ¡ d¡ d S )Nz^Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt

z
myfile.txt)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Útest_rfc2231_unknown_encodingt  s    
z)TestRFC2231.test_rfc2231_unknown_encodingc             C   sF   | j }d}t |¡}| d¡\}}}||d ƒ ||d ƒ ||dƒ d S )NzJContent-Type: application/x-foo;
	name*0*="Frank's"; name*1*=" Document"

r¯   zFrank's Document)r,   rt   r¡   r9   )r/   r0   r  r1   r5   rê  rƒ   r2   r2   r3   Ú-test_rfc2231_single_tick_in_filename_extended}  s    


z9TestRFC2231.test_rfc2231_single_tick_in_filename_extendedc             C   s4   d}t  |¡}| d¡}|  |t¡ |  |d¡ d S )NzGContent-Type: application/x-foo; name*0="Frank's"; name*1=" Document"

r¯   zFrank's Document)rt   r¡   r9   rò  ró  r,   )r/   r  r1   rô  r2   r2   r3   Ú$test_rfc2231_single_tick_in_filename‹  s
    

z0TestRFC2231.test_rfc2231_single_tick_in_filenamec             C   s"   d}t  |¡}|  | ¡ d¡ d S )NzAContent-Disposition: inline;
	filename*0*="'This%20is%20broken";
z'This is broken)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Útest_rfc2231_missing_tick•  s
    
z%TestRFC2231.test_rfc2231_missing_tickc             C   s"   d}t  |¡}|  | ¡ d¡ d S )NzAContent-Disposition: inline;
	filename*0*="'This%20is%E2broken";
u   'This isï¿½broken)rt   r¡   r,   rP   )r/   r  r1   r2   r2   r3   Ú0test_rfc2231_missing_tick_with_encoded_non_asciiŸ  s
    
z<TestRFC2231.test_rfc2231_missing_tick_with_encoded_non_asciic             C   sF   | j }d}t |¡}| d¡\}}}||dƒ ||dƒ ||dƒ d S )NzYContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'Frank's"; name*1*=" Document"

r¯   zus-asciizen-uszFrank's Document)r,   rt   r¡   r9   )r/   r0   r  r1   r5   rê  rƒ   r2   r2   r3   Ú!test_rfc2231_tick_attack_extendedª  s    


z-TestRFC2231.test_rfc2231_tick_attack_extendedc             C   s4   d}t  |¡}| d¡}|  |t¡ |  |d¡ d S )NzWContent-Type: application/x-foo;
	name*0="us-ascii'en-us'Frank's"; name*1=" Document"

r¯   zus-ascii'en-us'Frank's Document)rt   r¡   r9   rò  ró  r,   )r/   r  r1   rô  r2   r2   r3   Útest_rfc2231_tick_attack¸  s
    

z$TestRFC2231.test_rfc2231_tick_attackc             C   s(   | j }d}t |¡}|| d¡dƒ d S )Nz:Content-Type: application/x-foo; name="Frank's Document"

r¯   zFrank's Document)r,   rt   r¡   r9   )r/   r0   r  r1   r2   r2   r3   Útest_rfc2231_no_extended_valuesÄ  s    
z+TestRFC2231.test_rfc2231_no_extended_valuesc             C   sF   | j }d}t |¡}| d¡\}}}||dƒ ||dƒ ||dƒ d S )NziContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'My";
	name*1=" Document";
	name*2*=" For You"

r¯   zus-asciizen-uszMy Document For You)r,   rt   r¡   r9   )r/   r0   r  r1   r5   rê  rƒ   r2   r2   r3   Ú,test_rfc2231_encoded_then_unencoded_segmentsÎ  s    


z8TestRFC2231.test_rfc2231_encoded_then_unencoded_segmentsc             C   sF   | j }d}t |¡}| d¡\}}}||dƒ ||dƒ ||dƒ d S )NziContent-Type: application/x-foo;
	name*0="us-ascii'en-us'My";
	name*1*=" Document";
	name*2*=" For You"

r¯   zus-asciizen-uszMy Document For You)r,   rt   r¡   r9   )r/   r0   r  r1   r5   rê  rƒ   r2   r2   r3   Ú,test_rfc2231_unencoded_then_encoded_segmentsß  s    


z8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsN)r  r  r  r®   r¸   rì  rº   rî  rï  rð  rõ  rö  r÷  rø  rù  rú  rû  rü  rý  rþ  rÿ  r   r  r  r  r  r  r  r  r  r	  r2   r2   r2   r3   ré  j  s8   %
!

	


ré  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú
TestSignedc          	   C   s.   t |ƒ}| ¡ }t |¡}W d Q R X ||fS )N)r"   rh   rt   r¡   )r/   r¼   rl   Úoriginalr1   r2   r2   r3   Ú_msg_and_objõ  s    
zTestSigned._msg_and_objc             C   sL   dd l }| d|j|jB ¡}| |¡ d¡}| |¡ d¡}|  ||¡ d S )Nr   z^--([^\n]+)\n(.*?)\n--\1$ry   )rF  rG  ÚSrè  ÚsearchÚgroupr,   )r/   r  ÚresultrF  ZrepartZinpartZoutpartr2   r2   r3   Ú_signed_parts_eqû  s
    zTestSigned._signed_parts_eqc             C   s&   |   d¡\}}| ¡ }|  ||¡ d S )Nz
msg_45.txt)r  rf   r  )r/   r  r1   r  r2   r2   r3   Útest_long_headers_as_string  s    z&TestSigned.test_long_headers_as_stringc             C   s*   |   d¡\}}|jdd}|  ||¡ d S )Nz
msg_45.txté<   )rS  )r  rf   r  )r/   r  r1   r  r2   r2   r3   Ú(test_long_headers_as_string_maxheaderlen  s    z3TestSigned.test_long_headers_as_string_maxheaderlenc             C   s:   |   d¡\}}tƒ }t|ƒ |¡ | ¡ }|  ||¡ d S )Nz
msg_45.txt)r  r   r   rj   rk   r  )r/   r  r1   rl   r  r2   r2   r3   Útest_long_headers_flatten  s
    z$TestSigned.test_long_headers_flattenN)r  r  r  r  r  r  r  r  r2   r2   r2   r3   r
  ó  s
   r
  Ú__main__)`rF  r¨  r?   rž  r  Úior   r   Ú	itertoolsr   Úrandomr   Úsocketr   Ú	threadingr   rt   Úemail.policyZemail.charsetr   Úemail.headerr	   r
   r   Úemail.parserr   r   Úemail.generatorr   r   r   Úemail.messager   Úemail.mime.applicationr   Úemail.mime.audior   Úemail.mime.textr   Úemail.mime.imager   Úemail.mime.baser   Úemail.mime.messager   Úemail.mime.multipartr   Úemail.mime.nonmultipartr   r   r   r   r   r   r   Ztest.supportr    r!   Ztest.test_emailr"   r#   r$   r%   r‘   rÄ  r>  r)   ÚTestCaser  r  rd  rn  r|  r  r  r   rÒ  rï  r  r,  rE  rÁ  rÜ  rë  r  rA  rE  rH  rI  r[  rº  rÅ  ré  r
  r  Úmainr2   r2   r2   r3   Ú<module>   sÆ        IC    AF((\<    0   <      
g0 K   !5  D:  e   #
