B
    v9aø. ã               @   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.txtZcczccc@zzz.orgzddd@zzz.orgzeee@zzz.orgZxxzn/a)ÚassertEqualÚ_msgobjÚget_all)ÚselfÚeqÚmsg© r0   ú /usr/lib/python3.7/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-   r.   r/   r3   r0   r0   r1   Ú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   r5   r4   r8   )r-   r.   r/   r0   r0   r1   Ú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*   r4   r8   )r-   r/   r3   r0   r0   r1   Ú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-   Údatar3   r/   r0   r0   r1   Ú+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*   r?   )r-   r@   r3   r/   r0   r0   r1   Ú>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-encodingrB   T)r>   )r   rC   r   r;   r*   r?   )r-   r@   r3   r/   r0   r0   r1   Ú>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*   r?   )r-   r/   r0   r0   r1   Ú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   ZassertRaisesRegexÚ	TypeErrorÚattach)r-   r/   Zsub_msgr0   r0   r1   Ú"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-   r.   r/   Úcharsetsr0   r0   r1   Ú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 r0   )Úget_filename)Ú.0Úpr0   r0   r1   ú
<listcomp>    s    z4TestMessageAPI.test_get_filename.<locals>.<listcomp>zmsg.txtz
msg_07.txté   zdingusfish.gif)r*   r+   r?   rM   )r-   r.   r/   Ú	filenamesÚsubpartr0   r0   r1   Ú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 r0   )rM   )rN   rO   r0   r0   r1   rP   «   s    zHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>zmsg.txt)r*   r+   r?   )r-   r.   r/   rR   r0   r0   r1   Ú%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-   r.   r/   r0   r0   r1   Ú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.txtrV   é   zcontent-typez3text/plain; charset="us-ascii"; boundary="BOUNDARY"z
msg_04.txtz$multipart/mixed; boundary="BOUNDARY"z
msg_03.txt)r*   r+   Úset_boundaryÚitemsÚlowerÚassertRaisesr   ÚHeaderParseError)r-   r.   r/   ÚheaderÚvaluer0   r0   r1   Ú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   rQ   zmultipart/form-dataé!   z!multipart/form-data; boundary="==)r   r*   r[   Ú	as_string)r-   r/   r0   r0   r1   Ú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Úparserr/   ÚoutÚgenr0   r0   r1   Ú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"   re   ÚencodeÚemailrk   ÚBytesHeaderParserZ
parsebytesr   Ú	generatorr   rg   r*   rh   )r-   ri   rj   rk   r/   rl   rm   r0   r0   r1   Ú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.
rQ   s-   ¡This is a Quoted Printable encoded message!
é   s!   This is a Base64 encoded message.é   s"   This is a Base64 encoded message.
rY   s/   This has no Content-Transfer-Encoding: header.
)r*   r+   r?   )r-   r.   r/   r0   r0   r1   Ú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;   r?   )r-   r.   r/   Úcter0   r0   r1   Útest_get_decoded_uu_payload  s    


z*TestMessageAPI.test_get_decoded_uu_payloadc             C   s   t ƒ }|  t|jd¡ d S )NrQ   )r   r]   rG   r?   )r-   r/   r0   r0   r1   Ú*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"   re   r   r   rg   rh   )r-   r.   r/   ri   ÚtextÚsÚgr0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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 rQ   )r+   r"   re   r*   Ústrrc   ÚsplitÚ
assertTrueÚ
startswithÚNLÚjoin)r-   r/   ri   r~   ÚfullreprÚlinesr0   r0   r1   Ú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“   Úclonerc   r   r   rg   r*   rh   )r-   r/   Ú	newpolicyr   r   r€   r0   r0   r1   Ú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.txtro   T)rˆ   ó   
r   s   From rQ   )r+   r"   re   rp   r*   ÚbytesÚas_bytesrŠ   r‹   rŒ   rŽ   )r-   r/   ri   r@   r   r   r0   r0   r1   Ú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   rg   r*   rh   )r-   r/   r•   r   r   r€   r0   r0   r1   Ú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'   )rq   Úmessage_from_stringr*   r7   )r-   r/   r0   r0   r1   Útest_bad_paramN  s    
zTestMessageAPI.test_bad_paramc             C   s   t  d¡}|  | ¡ d ¡ d S )Nz
From: foo
)rq   r   r*   rM   )r-   r/   r0   r0   r1   Útest_missing_filenameR  s    
z$TestMessageAPI.test_missing_filenamec             C   s   t  d¡}|  | ¡ d¡ d S )Nz%Content-Disposition: blarg; filename
r'   )rq   r   r*   rM   )r-   r/   r0   r0   r1   Útest_bogus_filenameV  s    z"TestMessageAPI.test_bogus_filenamec             C   s   t  d¡}|  | ¡ d ¡ d S )Nz
From: foo
)rq   r   r*   rW   )r-   r/   r0   r0   r1   Ú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)r_   )rz   Úone)ÚbarÚtwo)rœ   Úthreez X-Header: foo; bar=one; baz=two
)rz   r'   )r£   r¢   )rœ   r¤   z"X-Header: foo; bar="one"; baz=two
)r*   rq   r   Ú
get_params)r-   r.   r/   r0   r0   r1   Ú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*   r7   )r-   r/   r0   r0   r1   Ú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)r_   r¤   Zquuzz"X-Header: foo; bar="one"; baz=two
rz   r'   r¢   rœ   )r*   rq   r   r7   )r-   r.   r/   r0   r0   r1   Útest_get_paramu  s    zTestMessageAPI.test_get_paramc             C   s&   |   d¡}|  | d¡ d¡d¡ d S )Nz
msg_22.txtrQ   Únamez
wibble.JPG)r+   r*   r?   r7   )r-   r/   r0   r0   r1   Ú'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")rq   r   r*   r7   )r-   r/   r0   r0   r1   Ú#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)rq   r   r*   r7   )r-   r/   r0   r0   r1   Ú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: existsr_   r	   ZHEADERZheaderx)rq   r   r†   ZassertNotIn)r-   r/   r0   r0   r1   Ú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 )Nr3   ziso-2022-jpÚ
importancez
high valueF)r­   z"high value")z
text/plainr'   )r3   ziso-2022-jp)r±   z
high value)r3   z"iso-2022-jp")r±   z"high value"ziso-9999-xxzX-Jimmy)r_   )r*   r   Ú	set_paramr7   r¦   )r-   r.   r/   r0   r0   r1   Ú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¦   r7   Ú	del_paramr²   )r-   r.   r/   Zold_valr0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú$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)r3   Úfoobar)r_   )r   r¸   r´   r*   )r-   r/   Zexisting_headerr0   r0   r1   Ú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-typer3   zus-asciiztext/plain; charset="us-ascii"z	text/htmlztext/html; charset="us-ascii")r*   r   r]   Ú
ValueErrorÚset_typer²   )r-   r.   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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*   r6   )r-   r/   r0   r0   r1   Ú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*   r6   )r-   r/   r0   r0   r1   Ú/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*   r?   r6   )r-   r/   r0   r0   r1   Ú+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*   r?   r6   )r-   r/   r0   r0   r1   Ú+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*   r6   )r-   r/   r0   r0   r1   Ú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*   r6   )r-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú!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-   r/   r0   r0   r1   Ú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*   r?   rÈ   )r-   r/   r0   r0   r1   Ú/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*   r?   rÈ   )r-   r/   r0   r0   r1   Ú/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-   r/   r0   r0   r1   Ú: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-   r/   r0   r0   r1   Ú: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-   r/   r0   r0   r1   Ú 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-   r/   r0   r0   r1   Ú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*   r?   rÑ   )r-   r/   r0   r0   r1   Ú.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*   r?   rÑ   )r-   r/   r0   r0   r1   Ú.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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r.   r/   r0   r0   r1   Ú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   ÚassertIsNoneZget_content_dispositionr¸   r*   rá   )r-   r/   r0   r0   r1   Ú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*   r?   ÚassertIsInstanceÚdefectsr   ÚInvalidBase64CharactersDefect)r-   Úxr/   r0   r0   r1   Ú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-typerB   zcontent-transfer-encodingT)r>   zraw-unicode-escape)r   r;   r*   r?   r˜   )r-   rê   r/   r0   r0   r1   Ú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-typerB   zcontent-transfer-encodingT)r>   )rp   r   Z_payloadr*   r?   )r-   rê   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú#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-   r/   r0   r0   r1   Ú#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-   r/   r0   r0   r1   Ú&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-1ro   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*   r?   )r-   r3   r/   r0   r0   r1   Ú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-1ro   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*   r?   )r-   r3   r/   r0   r0   r1   Ú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-1ro   )z
x-uuencoderx   ry   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*   r?   r‰   Úformat)r-   r3   Úencodingr/   r0   r0   r1   Ú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ä   )Zfoo_barzinline; foo-bar)r   r¸   r*   )r-   r/   r0   r0   r1   Ú$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-   r/   r0   r0   r1   Ú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   r^   rc   )r-   r/   r0   r0   r1   Ú(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   r^   rc   )r-   r/   r0   r0   r1   Ú(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-   Úmr0   r0   r1   Ú-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   r0   r0   r1   Ú+test_unicode_body_defaults_to_utf8_encodingì  s    z:TestMessageAPI.test_unicode_body_defaults_to_utf8_encodingN)VÚ__name__Ú
__module__Ú__qualname__r2   r9   r:   r<   rA   rD   rE   rF   rI   rL   rT   rU   rX   ra   rd   rn   rt   rw   r|   r}   r   r‡   r‘   r–   rš   r›   rž   rŸ   r    r¡   r§   r©   rª   r¬   r®   r¯   r°   r³   rµ   r¹   rº   r¼   r¿   rÀ   rÁ   rÃ   rÄ   rÅ   rÆ   rÇ   rÉ   rË   rÌ   rÍ   rÎ   rÏ   rÒ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   rã   ræ   rë   rì   rí   rî   rï   rð   rñ   rò   ró   rô   r÷   rø   rù   rû   rü   r  r  r0   r0   r0   r1   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 r0   )Úlen)rN   rê   r0   r0   r1   rP     s    z;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>éL   )
r"   re   rq   ÚmimeÚimager   r?   rŠ   ÚassertLessEqualÚmax)r-   ri   ÚbindataZmimedZbase64edr   r0   r0   r1   Ú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   r5   )r-   r.   r/   r0   r0   r1   Ú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-   r.   r/   r0   r0   r1   Ú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   rc   rþ   rÿ   )r-   r.   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Ú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-   r/   r0   r0   r1   Útest_qp_encode_non_latin1/  s    z&TestEncoders.test_qp_encode_non_latin1N)	r  r  r  r  r  r  r  r  r  r0   r0   r0   r1   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
)ÚndiffAssertEqualrq   r   r   r   rg   rh   )r-   r.   r/   Úsfpr€   r0   r0   r1   Ú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	   rp   Úreplace)r-   r.   ÚhstrÚhr0   r0   r1   Ú,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   rg   rh   rp   )r-   r.   r€   ÚczÚutf8Úg_headÚcz_headÚ	utf8_headr  r/   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú<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	   rp   )r-   r.   r  r0   r0   r1   Ú-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*   rp   )r-   r  r0   r0   r1   Ú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*   rp   )r-   r  Zresr0   r0   r1   Ú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   rg   rh   )r-   r.   r/   r  r€   r0   r0   r1   Ú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>Nr0   )rN   Úir0   r0   r1   ú	<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   rg   rh   )r-   r.   r/   r  r€   r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú"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	   rp   )r-   r.   r  r0   r0   r1   Ú=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	   rp   )r-   r.   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú/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	   rp   )r-   r.   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú: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	   rp   )r-   r.   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú/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	   rp   )r-   r.   r  r0   r0   r1   Ú@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	   rp   )r-   r.   r  r0   r0   r1   Ú>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>  r2  r3  r4  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   r5  rŽ   r;   r   r   rg   rh   )r-   r.   r/   r  r€   r0   r0   r1   Ú%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>r2  z; abcr3  r4  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   r5  rŽ   r;   r   r   rg   rh   )r-   r.   r/   r  r€   r0   r0   r1   Ú'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,pointsr3  r4  zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r  r   r;   r   r   rg   rh   )r-   r.   r/   r  r€   r0   r0   r1   Ú.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	   rp   )r-   r.   r  r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r  r0   r0   r1   Ú"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	   rp   )r-   r.   r  r  r0   r0   r1   Ú&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#  rp   rc   )r-   r.   r/   r  r0   r0   r1   Ú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-TorH  )rJ  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   rc   r	   )r-   r.   r/   Zheader_stringr0   r0   r1   Ú 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…   rH  )rJ  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   rc   )r-   r.   rƒ   r/   r0   r0   r1   Ú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#  rp   )r-   r.   r   r  r0   r0   r1   Ú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#  rp   )r-   r.   r   r  r0   r0   r1   Ú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	   rp   )r-   r.   ÚfnZgsr  r0   r0   r1   Ú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-2rH  )rJ  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  rc   )r-   r  r/   r0   r0   r1   Ú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-2rH  )rJ  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  rc   )r-   r  r/   r0   r0   r1   Ú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-3rH  )rJ  aØ  Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

)r  r   r	   rc   )r-   r.   r/   Útr0   r0   r1   Ú-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 -0700rH  )rJ  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  rq   r   rc   )r-   r.   r   r/   r0   r0   r1   Ú"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>ZList)r!  rH  )rJ  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	   rc   )r-   r.   r  r/   r0   r0   r1   Ú%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-8r4  )r3   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*   rp   )r-   r  r0   r0   r1   Ú*test_long_rfc2047_header_with_embedded_fwsi  s    z:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws)+r  r  r  ÚmaxDiffr  r   r)  r*  r+  r,  r-  r.  r/  r7  r8  r9  r:  r;  r<  r=  r>  r?  r@  rA  rB  rC  rD  rE  rF  rG  rI  rK  rL  rM  rN  rO  rQ  rR  rS  rU  rV  rW  rX  r0   r0   r0   r1   r  <  sP   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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   r/   r;   )r-   r0   r0   r1   Ú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   rg   r/   r*   rh   )r-   r   r€   r0   r0   r1   Útest_mangled_from‚  s
    
z"TestFromMangling.test_mangled_fromc             C   s2   t ƒ }t|dd}| | j¡ |  | ¡ d¡ d S )NF)r\  z;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
)r   r   rg   r/   r*   rh   )r-   r   r€   r0   r0   r1   Ú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)r\  a)              From: foo@bar.com
            Mime-Version: 1.0
            Content-Type: multipart/mixed; boundary=XXX

            From somewhere unknown

            --XXX
            Content-Type: text/plain

            foo

            --XXX--

            From somewhere unknowable
            c             S   s   g | ]}|  d ¡rd‘qS )z>From rQ   )rŒ   )rN   rê   r0   r0   r1   rP   ¬  s    zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>r&   ru   )r   r   rq   r   rþ   rÿ   rg   r*   r  rh   rŠ   )r-   r   r€   r/   r0   r0   r1   Ú'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)r\  s   >From RÃ¶lli
)
rþ   rÿ   rp   rq   Úmessage_from_bytesr   r   rg   r*   rh   )r-   Úsourcer/   Úbr€   r0   r0   r1   Ú test_mangled_from_with_bad_bytes¯  s    
z1TestFromMangling.test_mangled_from_with_bad_bytesc             C   s   t  d¡ d¡}t |¡}d S )Nu               From: aperson@example.com
            Content-Type: multipart/mixed; boundary="1"
            Content-Transfer-Encoding: Ãˆ
        zutf-8)rþ   rÿ   rp   rq   r`  )r-   ra  r/   r0   r0   r1   Ú%test_mutltipart_with_bad_bytes_in_cte½  s    z6TestFromMangling.test_mutltipart_with_bad_bytes_in_cteN)	r  r  r  r[  r]  r^  r_  rc  rd  r0   r0   r0   r1   rZ  y  s   rZ  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"   re   Ú
_audiodatar   Ú_au)r-   ri   r0   r0   r1   r[  É  s    zTestMIMEAudio.setUpc             C   s   |   | j ¡ d¡ d S )Nzaudio/basic)r*   rg  r6   )r-   r0   r0   r1   Útest_guess_minor_typeÎ  s    z#TestMIMEAudio.test_guess_minor_typec             C   s(   | j  ¡ }|  t t|dƒ¡| j¡ d S )Nro   )rg  r?   r*   r=   Údecodebytesr˜   rf  )r-   Úpayloadr0   r0   r1   Útest_encodingÑ  s    
zTestMIMEAudio.test_encodingc             C   s    t | jdƒ}|  | ¡ d¡ d S )NÚfishz
audio/fish)r   rf  r*   r6   )r-   Zaur0   r0   r1   Ú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")r_   )r¶   r'   )r·   zaudiotest.aur·   r'   rz   )Úfailobjr_   r»   )r*   rg  r¸   r¦   r7   ÚassertIs)r-   r.   Úmissingr0   r0   r1   Útest_add_headerÚ  s     


zTestMIMEAudio.test_add_headerN)r  r  r  r[  rh  rk  rm  rq  r0   r0   r0   r1   re  È  s
   re  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"   re   Ú_imgdatar   Ú_im)r-   ri   r0   r0   r1   r[  ñ  s    zTestMIMEImage.setUpc             C   s   |   | j ¡ d¡ d S )Nz	image/gif)r*   rt  r6   )r-   r0   r0   r1   rh  ö  s    z#TestMIMEImage.test_guess_minor_typec             C   s(   | j  ¡ }|  t t|dƒ¡| j¡ d S )Nro   )rt  r?   r*   r=   ri  r˜   rs  )r-   rj  r0   r0   r1   rk  ù  s    
zTestMIMEImage.test_encodingc             C   s    t | jdƒ}|  | ¡ d¡ d S )Nrl  z
image/fish)r   rs  r*   r6   )r-   Zimr0   r0   r1   rm  þ  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")r_   )r¶   r'   )r·   zdingusfish.gifr·   r'   rz   )rn  r_   r»   )r*   rt  r¸   r¦   r7   ro  )r-   r.   rp  r0   r0   r1   rq    s     


zTestMIMEImage.test_add_headerN)r  r  r  r[  rh  rk  rm  rq  r0   r0   r0   r1   rr  ð  s
   rr  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   r6   )r-   r.   r/   r0   r0   r1   Ú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   r?   Ústrip)r-   r.   Ú	bytesdatar/   r0   r0   r1   Ú	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-EncodingrB   )r   r   Úencode_7or8bitr*   r?   r  r   r   rg   rh   rq   r`  )r-   rx  r/   r   r€   ÚwireformÚmsg2r0   r0   r1   Ú$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   úûüýþÿ)rz  u   ï¿½T)r>   )r   r   Úencode_noopr*   r?   r  r   r   rg   rh   rq   r`  )r-   rx  r/   r   r€   r|  r}  r0   r0   r1   Ú!test_binary_body_with_encode_noop8  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   úûüýþÿ)rz  T)r>   )r   r   r  r*   r?   r   r   rg   rh   rq   r`  )r-   rx  r/   r   r€   r|  r}  r0   r0   r1   Ú0test_binary_body_with_unicode_linend_encode_noopI  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   úûüýþÿ )rz  z=FA=FB=FC=FD=FE=FF=20T)r>   zContent-Transfer-Encodingzquoted-printable)r   r   Zencode_quoprir*   r?   r   r   rg   rh   rq   r`  )r-   rx  r/   r   r€   r|  r}  r0   r0   r1   Ú#test_binary_body_with_encode_quopriU  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   úûüýþÿ)rz  z	+vv8/f7/
T)r>   )r   r   Zencode_base64r*   r?   r   r   rg   rh   rq   r`  )r-   rx  r/   r   r€   r|  r}  r0   r0   r1   Ú#test_binary_body_with_encode_base64e  s    

z7TestMIMEApplication.test_binary_body_with_encode_base64N)
r  r  r  rv  ry  r~  r€  r  r‚  rƒ  r0   r0   r0   r1   ru    s   ru  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-   r0   r0   r1   r[  u  s    zTestMIMEText.setUpc             C   s`   | j }|| j ¡ dƒ || j d¡dƒ g }|  | j d|¡|¡ |  | jjd|dd|¡ d S )Nz
text/plainr3   zus-asciir»   )r_   )r*   r…  r6   r7   ro  )r-   r.   rp  r0   r0   r1   Ú
test_typesx  s    zTestMIMEText.test_typesc             C   s&   |   | j ¡ d¡ |  | j ¡ ¡ d S )Nzhello there)r*   r…  r?   ÚassertFalseÚis_multipart)r-   r0   r0   r1   Útest_payload  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   r4   r8   r   rC   r?   )r-   r.   r/   r3   r0   r0   r1   Ú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   r4   r8   )r-   r.   r/   r0   r0   r1   Ú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   r4   r†   rc   )r-   r.   r/   r0   r0   r1   Ú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   r4   Úoutput_charsetr?   rp   )r-   Úteststrr.   r/   r0   r0   r1   Ú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Ž  r0   r0   r1   Útest_utf8_input_no_charset§  s    z'TestMIMEText.test_utf8_input_no_charsetN)r  r  r  r[  r†  r‰  rŠ  r‹  rŒ  r  ÚunittestÚskipr‘  r0   r0   r0   r1   r„  t  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ÚmixedrV   )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:%SZDate)r"   re   r   r   r¸   r   rH   ÚtimeÚ	localtimeZtimezoneZaltzoneÚstrftimer…  rt  Ú_txt)r-   ri   r@   Ú	containerr  ZintroÚnowZ	timetupleZtzsecsÚsignZtzoffsetr0   r0   r1   r[  ±  s8    


zTestMultipart.setUpc             C   s°   | j }| j}| j}|  | ¡ ¡ || ¡ dƒ |t| ¡ ƒdƒ |t|jdƒ | d¡}| d¡}|  	|| j
¡ |  	|| j¡ || ¡ ||gƒ |  | ¡ ¡ |  | ¡ ¡ d S )Nzmultipart/mixedru   r   rQ   )r*   r]   r…  r‹   rˆ  r6   r  r?   Ú
IndexErrorro  rž  rt  r‡  )r-   r.   Úraisesr   Zm0Zm1r0   r0   r1   Ú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   rf   r  rc   )r-   r~   r/   r0   r0   r1   Ú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‚   rV   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   rZ   r  rc   )r-   Úouterr0   r0   r1   Ú/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'   rV   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ÚepiloguerZ   r  rc   )r-   r¦  r0   r0   r1   Ú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‚   rV   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   rZ   r   rH   rc   )r-   r.   r¦  r/   r0   r0   r1   Ú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 worldrV   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   rH   rZ   rc   )r-   r.   r¦  r/   r0   r0   r1   Ú1test_seq_parts_in_a_multipart_with_empty_preamble8  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 worldrV   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   rH   rZ   rc   )r-   r.   r¦  r/   r0   r0   r1   Ú0test_seq_parts_in_a_multipart_with_none_preambleT  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 worldrV   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   rH   rZ   rc   )r-   r.   r¦  r/   r0   r0   r1   Ú0test_seq_parts_in_a_multipart_with_none_epilogueo  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 worldrV   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   rH   rZ   rc   )r-   r.   r¦  r/   r0   r0   r1   Ú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 worldrV   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   rH   rZ   rc   )r-   r.   r¦  r/   r0   r0   r1   Ú.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.txtru   rQ   zmultipart/alternativezmessage/external-bodyr   z
text/plain)r*   r+   r  r?   r6   )r-   r.   r/   Úmsg1rS   Ú
subsubpartr0   r0   r1   Útest_message_external_bodyÀ  s    


z(TestMultipart.test_message_external_bodyc             C   s"   |   d¡}|  t| ¡ ƒd¡ d S )Nz
msg_37.txtrv   )r+   r*   r  r?   )r-   r/   r0   r0   r1   Ú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   Ú
_structurerh   )r-   r.   r/   r  r0   r0   r1   Ú)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µ  rh   )r-   r.   r/   r  r0   r0   r1   Ú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*   rc   )r-   r/   r0   r0   r1   Ú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    XXXXru   )r*   rq   r   r‹   rˆ  rW   r  r?   )r-   r.   r/   r0   r0   r1   Ú 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   rf   r*   r?   )r-   r   r0   r0   r1   Ú&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   ro  r“   rq   Úcompat32)r-   r   r0   r0   r1   Ú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   rq   r“   Údefaultro  )r-   r   r0   r0   r1   Útest_mimebase_custom_policy,  s    z)TestMultipart.test_mimebase_custom_policyN)r  r  r  r[  r¤  r¥  r§  rª  r«  r¬  r­  r®  r¯  r°  r³  r´  r¶  r·  r¸  r¹  rº  r¼  r¾  r0   r0   r0   r1   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+   r6   rÈ   rÑ   )r-   r.   r/   r0   r0   r1   Útest_parse_missing_minor_type3  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è   rQ   )
r+   r?   r‹   Úhasattrr*   r  rè   rç   r   ÚStartBoundaryNotFoundDefect)r-   r/   Úinnerr0   r0   r1   Útest_same_boundary_inner_outer;  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.txtru   r   rQ   )
r+   rç   r?   r‰   r*   r  rè   r   ÚNoBoundaryInMultipartDefectÚ!MultipartInvariantViolationDefect)r-   r/   r0   r0   r1   Útest_multipart_no_boundaryE  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: base64rQ   r   )	Ú_str_msgÚmultipart_msgrõ   r*   r  rè   rç   r   Z-InvalidMultipartContentTransferEncodingDefect)r-   r/   r0   r0   r1   Útest_multipart_invalid_ctef  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-   r/   r0   r0   r1   Útest_multipart_no_cte_no_defectn  s    z1TestNonConformant.test_multipart_no_cte_no_defectc             C   s<   x6dD ].}|   | j d |¡¡¡}|  t|jƒd¡ qW d S )N)r  rB   ZBINaryz
Content-Transfer-Encoding: {}r   )rÈ  rÉ  rõ   r*   r  rè   )r-   r{   r/   r0   r0   r1   Ú"test_multipart_valid_cte_no_defects  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-typerz   zContent-Type: foo

)
r*   r  r   rÈ   rÑ   r6   r   r   rg   rh   )r-   r.   Úneqr/   r   r€   r0   r0   r1   Útest_invalid_content_type{  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+   r?   )r-   r.   r/   r0   r0   r1   Ú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+   rc   )r-   r.   r/   r0   r0   r1   Ú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è   ru   r   rQ   )
r+   r‹   rÁ  r*   r  rè   rç   r   rÅ  rÆ  )r-   r/   r0   r0   r1   Ú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.txtrQ   r   )r+   r?   r*   r  rè   rç   r   rÂ  )r-   r¦  Zbadr0   r0   r1   Ú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ý   ÚbodyrQ   r   z Line 1
)r*   rq   r   rß   r?   r  rè   ÚassertDefectsEqualr   Z#FirstHeaderLineIsContinuationDefectÚline)r-   r.   r   r/   r0   r0   r1   Ú&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ß   r?   rÔ  rè   r   Z MissingHeaderBodySeparatorDefect)r-   r/   r0   r0   r1   Ú"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×  r0   r0   r0   r1   r¿  1  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  rp   )r-   r.   r   Údhr_   r0   r0   r1   Ú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-   r.   r   rÙ  r_   r0   r0   r1   Ú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-   r.   r   rÙ  Úhur0   r0   r1   Ú 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Ù  r0   r0   r1   Ú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Ù  r0   r0   r1   Ú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   r@   ÚqÚarÙ  r0   r0   r1   Ú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   r0   r0   r1   Ú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   r0   r0   r1   Ú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   r0   r0   r1   Ú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   r0   r0   r1   Ú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   r0   r0   r1   Útest_rfc2047_rfc2047_44	  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   r0   r0   r1   Útest_rfc2047_rfc2047_5a:	  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   r0   r0   r1   Útest_rfc2047_rfc2047_5b@	  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   r0   r0   r1   Útest_rfc2047_rfc2047_6F	  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   rp   r\   r‰   )r-   r   r0   r0   r1   Útest_rfc2047_rfc2047_7L	  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   rp   rŽ   Ú
splitlinesr‰   )r-   r   r0   r0   r1   Útest_multiline_headerU	  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ó  r0   r0   r0   r1   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"   re   Z_text)r-   ri   r0   r0   r1   r[  b	  s    
zTestMIMEMessage.setUpc             C   s   |   ttd¡ d S )Nza plain string)r]   rG   r   )r-   r0   r0   r1   Útest_type_errorf	  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/rfc822rQ   r   Úsubject)	r*   r   r   r6   r?   rç   Úlistr  ro  )r-   r.   rö  r   Úrrj  rS   r0   r0   r1   Útest_valid_argumenti	  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   ZMultipartConversionErrorrH   )r-   r±  r}  rø  r0   r0   r1   Útest_bad_multipartw	  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   rg   r*   rh   )r-   r   rø  r   r€   r0   r0   r1   Útest_generate	  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/rfc822rQ   r   rö  zAn enclosed messagez!Here is the body of the message.
)r*   r+   r6   r?   rç   r÷  r  r   )r-   r.   r/   rj  Zsubmsgr0   r0   r1   Ú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/reportrv   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

rQ   zmessage/delivery-statusru   zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.eduZdnszreporting-mta)r_   r'   ZnsdÚactionZ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+   r6   r‹   rˆ  r  r?   rç   r   r7   r¦   r÷  )r-   r.   r/   rS   Zdsn1Zdsn2rj  r²  r0   r0   r1   Ú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…   r4  rý   zMIME messagezEnd of MIME message
rÜ   rÞ   zContent-Typezmultipart/mixedrV   )r¨   )r  r"   re   r   r¨  r©  r   r¸   rH   r   r   rg   rh   )	r-   r.   ri   r~   r/   r±  r}  r  r€   r0   r0   r1   Ú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…   r4  rý   zMIME messager'   rÜ   rÞ   zContent-Typezmultipart/mixedrV   )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¸   rH   rc   )r-   r.   r/   r±  r}  r0   r0   r1   Ú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/rfc822rQ   z
text/plain)r*   r"   rq   Úmessage_from_filer?   Úget_default_typer6   )r-   r.   ri   r/   Ú
container1Ú
container2Úcontainer1aÚcontainer2ar0   r0   r1   Ú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/rfc822rQ   z
text/plain)r*   r"   rq   r  r?   r  r6   )r-   r.   ri   r/   r  r  r  r  r0   r0   r1   Ú.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 )NZdigestrV   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   rH   r6   r  rc   )r-   r.   rÍ  rŸ  Z	subpart1aZ	subpart2aZsubpart1Zsubpart2r0   r0   r1   Útest_default_type_non_parsed1
  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'   )Z	_subpartsru   r   rQ   )r*   r   r   r  r?   )r-   r.   Ztext1Ztext2r/   r0   r0   r1   Ú$test_mime_attachments_in_constructor{
  s    z4TestMIMEMessage.test_mime_attachments_in_constructorc             C   s   t ƒ }|  | ¡ ¡ d S )N)r   r‹   rˆ  )r-   r/   r0   r0   r1   Ú"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-   r/   r0   r0   r1   Ú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   rq   r“   r½  r]   r½   r*   r‰   Z	exception)r-   r/   Úcmr0   r0   r1   Útest_multipart_custom_policyŽ
  s    z,TestMIMEMessage.test_multipart_custom_policyN)r  r  r  r[  rõ  rù  rú  rû  rü  rþ  rÿ  r   r  r  r	  r
  r  r  r  r0   r0   r0   r1   rô  a	  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"   re   rq   r   )r-   r·   ri   r@   r/   r0   r0   r1   r+   Ÿ
  s    

zTestIdempotent._msgobjFc             C   s8   | j }tƒ }t|dd}|j||d ||| ¡ ƒ d S )Nr   )rJ  )rˆ   )r  r   r   rg   rh   )r-   r/   r~   rˆ   r.   r   r€   r0   r0   r1   Ú_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Ð   rQ   )r3   zus-asciir3   zus-ascii)
r*   r+   r6   rÈ   rÑ   r¦   r7   r¨  r©  r  )r-   r.   r/   r~   r0   r0   r1   Ú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/plainr3   )r*   r+   r6   r¦   r7   r  )r-   r.   r/   r~   r0   r0   r1   Útest_parse_untyped_message¸
  s    z)TestIdempotent.test_parse_untyped_messagec             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_04.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_simple_multipartÀ
  s    z$TestIdempotent.test_simple_multipartc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_02.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_MIME_digestÄ
  s    zTestIdempotent.test_MIME_digestc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_27.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_long_headerÈ
  s    zTestIdempotent.test_long_headerc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_28.txt)r+   r  )r-   r/   r~   r0   r0   r1   Ú"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-   r/   r~   r0   r0   r1   Útest_mixed_with_imageÐ
  s    z$TestIdempotent.test_mixed_with_imagec             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_05.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_multipart_reportÔ
  s    z$TestIdempotent.test_multipart_reportc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_16.txt)r+   r  )r-   r/   r~   r0   r0   r1   rþ  Ø
  s    zTestIdempotent.test_dsnc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_21.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_preamble_epilogueÜ
  s    z%TestIdempotent.test_preamble_epiloguec             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_23.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_multipart_one_partà
  s    z&TestIdempotent.test_multipart_one_partc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_24.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_multipart_no_partsä
  s    z&TestIdempotent.test_multipart_no_partsc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_31.txt)r+   r  )r-   r/   r~   r0   r0   r1   rÏ  è
  s    z%TestIdempotent.test_no_start_boundaryc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_32.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_rfc2231_charsetì
  s    z#TestIdempotent.test_rfc2231_charsetc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_33.txt)r+   r  )r-   r/   r~   r0   r0   r1   Útest_more_rfc2231_parametersð
  s    z+TestIdempotent.test_more_rfc2231_parametersc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_34.txt)r+   r  )r-   r/   r~   r0   r0   r1   Ú%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-   r/   r~   r0   r0   r1   Útest_nested_multipart_mixedsø
  s    z+TestIdempotent.test_nested_multipart_mixedsc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_36.txt)r+   r  )r-   r/   r~   r0   r0   r1   Ú%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-   r/   r~   r0   r0   r1   Útest_message_delivery_status   s    z+TestIdempotent.test_message_delivery_statusc             C   s   |   d¡\}}|  ||¡ d S )Nz
msg_45.txt)r+   r  )r-   r/   r~   r0   r0   r1   Ú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.rv   r   z
text/plainzYadda yadda yaddarQ   ru   zmessage/rfc822)r*   r+   r6   r¦   r¨  r’   r©  r  r?   rç   r   r÷  )r-   r.   r/   r~   ÚparamsZpkZpvr±  r}  Zmsg3rj  Zmsg4r0   r0   r1   Ú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/rfc822rQ   r   z
text/plain)
r*   r+   r6   r?   rç   r÷  r  r   r‰   r’   )r-   r.   r/   r~   rj  r±  r0   r0   r1   Útest_parser'  s    zTestIdempotent.test_parserN)F)r  r  r  r’   r+   r  r  r  r  r  r  r  r  r  rþ  r  r  r  rÏ  r  r  r  r  r   r!  r"  r$  r%  r0   r0   r0   r1   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   )rJ  )	r"   re   rq   r   r   r   rg   r*   rh   )r-   ri   r~   r/   r   r€   r0   r0   r1   Útest_message_from_string;  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   )rJ  )
r"   re   Úseekrq   r  r   r   rg   r*   rh   )r-   ri   r~   r/   r   r€   r0   r0   r1   Útest_message_from_fileF  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  r0   r0   r0   r1   Ú	MyMessageW  s   r*  z
msg_02.txt)r"   re   r   rq   r   rç   Úwalk)r-   ri   r~   r*  r/   rS   r0   r0   r1   Ú#test_message_from_string_with_classR  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  r0   r0   r0   r1   r*  e  s   r*  z
msg_01.txtz
msg_02.txt)r   r"   rq   r  rç   r+  )r-   r*  ri   r/   rS   r0   r0   r1   Ú!test_message_from_file_with_classc  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__r0   r1   r/  s  s    z\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__)r  r  r  r/  Ú__classcell__r0   r0   )r0  r1   r*  r  s   r*  zSubject: test

test)r   rÈ  rç   )r-   r*  r/   r0   r0   r1   Ú.test_custom_message_does_not_require_argumentsq  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 )Nrq   r   r3   r   r   Ú
feedparserrs   r_   r   rÊ   Zmessage_from_binary_filer`  r  r   r
  rk   r   r   )Ú
__import__r*   ÚsortedÚ__all__)r-   Úmoduler0   r0   r1   Útest__all__x  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   r0   r0   r1   Útest_formatdate‚  s    z!TestMiscellaneous.test_formatdatec             C   s>   t   ¡ }|  t tj|dd¡d d… t  |¡d d… ¡ d S )NT)rœ  r9  )r›  r*   r   r:  r;  rœ  )r-   r   r0   r0   r1   Ú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œ  Zusegmtz%a, %d %b %Y %H:%M:%S GMT)r›  r*   r   r;  r  r<  )r-   r   r0   r0   r1   Ú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   r:  Úparsedate_tz)r-   r0   r0   r1   Ú/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   r:  )r-   r0   r0   r1   Ú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Ó  ru   é   é   é/   é   r   rQ   r—  i€ÿÿ)r*   r   rA  )r-   r.   r0   r0   r1   Ú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Ó  ru   é   rE  rF  rG  r   rQ   r—  i€ÿÿ)r*   r   rA  )r-   r.   r0   r0   r1   Ú#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Ò  rY   rv   é   é:   rG  r   rQ   r—  i€p  )r*   r   rA  )r-   r0   r0   r1   Ú.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Ò  rY   rv   rK  rL  rG  r   rQ   r—  i€ÿÿ)r*   r   rA  )r-   r0   r0   r1   Ú.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Ó  ru   rI  rE  rF  rG  r   rQ   r—  i€ÿÿz5 Feb 2003 13.47 -0800)
iÓ  ru   rI  rE  rF  r   r   rQ   r—  i€ÿÿ)r*   r   rA  )r-   r.   r0   r0   r1   Ú%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 -0800r9  z%YiÓ  é	   )	r*   r   r:  Úintr›  Zmktimerœ  r  rA  )r-   r.   ZtimetuprT  r0   r0   r1   Ú+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²  rQ   rQ   r   r   r   r—  r—  r—  r   r   )
i²  rQ   rQ   r   r   r   r—  r—  r—  iÒ  i.ûÿÿ)r*   r   Z	mktime_tz)r-   r0   r0   r1   Ú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   rA  )r-   r0   r0   r1   Ú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-   r0   r0   r1   Ú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   rV  )r-   r0   r0   r1   Ú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   rV  rU  )r-   rä  rb  r0   r0   r1   Ú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   rV  rU  )r-   rä  rb  r0   r0   r1   Ú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   rV  )r-   r«   ÚaddrÚutf8_base64Zlatin1_quoprir0   r0   r1   Ú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 )Nr0   )r-   Ústring)r»   r0   r1   Úheader_encode  s    zYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encodeN)r  r  r  r_  r0   )r»   r0   r1   ÚCharsetMock  s   r`  z%s <%s>zutf-8)r*   r   rV  r   )r-   r«   r[  r\  r`  ZmockZmock_expectedr0   )r»   r1   Ú$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   rV  )r-   r«   r[  Zbad_charsetr0   r0   r1   Ú-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   rV  )r-   r[  r0   r0   r1   Ú!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   rU  rV  )r-   rê   Úyrä  rb  r0   r0   r1   Ú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   rU  )r-   r.   r0   r0   r1   Ú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   rU  )r-   r0   r0   r1   Ú-test_parseaddr_preserves_spaces_in_local_part?  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   rU  rV  )r-   r[  Zaddrstrr0   r0   r1   Ú6test_formataddr_does_not_quote_parens_in_quoted_stringQ  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   rU  )r-   rê   r0   r0   r1   Útest_multiline_from_commentZ  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   rV  )r-   r0   r0   r1   Útest_quote_dump`  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usasciiZUSASCIIZUsAsCiI)r*   ZassertNotEqualr   )r-   r.   ÚneZcset1Zcset2r0   r0   r1   Útest_charset_richcomparisonse  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-   r.   r0   r0   r1   Útest_getaddressesy  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   rq  )r-   r.   r0   r0   r1   Útest_getaddresses_nasty€  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   rQ   zfoo@bar.comN)r*   r   rq  )r-   r.   Zaddrsr0   r0   r1   Ú"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›  Z	monotonic)r-   r#  rw  ZclockZtfinr0   r0   r1   Úrun“  s    
zFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.runN)r  r  r  rx  r0   r0   r0   r1   ÚMsgidsThread’  s   ry  c                s   g | ]
}ˆ ƒ ‘qS r0   r0   )rN   r0  )ry  r0   r1   rP     s    z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>rI  c             S   s   g | ]
}|j ‘qS r0   )rv  )rN   rT  r0   r0   r1   rP      s    )r   r6  r!   Úsumr*   r  Úset)r-   ZthreadsZall_idsr0   )ry  r1   Ú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¸   rM   )r-   r.   r/   r0   r0   r1   Ú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-   r3   r0   r0   r1   Ú)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-typerQ   r   zutf-8r=   s   hello world)r3   zaGVsbG8gd29ybGQ=
T)r>   zcontent-transfer-encodingztext/plain; charset="US-ASCII"zus-asciizhello worldr  )
r*   r   rJ   r  r   r~  r;   r?   r   r{  )r-   r.   r/   rK   r3   r0   r0   r1   Ú-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-   ZlcZucr0   r0   r1   Ú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µ  rh   )r-   r.   r/   r  r0   r0   r1   Ú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)ru  iíÿÿÿz@testdomain-string>)r*   rq   r   rw  )r-   r0   r0   r1   Ú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)Zidstringru  ißÿÿÿz!.test-idstring@testdomain-string>)r*   rq   r   rw  )r-   r0   r0   r1   Útest_make_msgid_idstringü  s    z*TestMiscellaneous.test_make_msgid_idstringc             C   s$   |   tj ¡  dtƒ  d ¡¡ d S )Nú@ú>)r‹   rq   r   rw  Úendswithr   )r-   r0   r0   r1   Ú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"   re   r  rq   r   r   rs   r   rg   r*   rh   )r-   ÚfÚmsgtxtÚ	msgtxt_nlr/   r   r€   r0   r0   r1   Ú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’   ro   )r"   re   r  rq   r   r   rs   r   rg   r*   rh   r>   )r-   rŠ  r‹  rŒ  r/   r   r€   r0   r0   r1   Ú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"   re   r  rq   r`  r   rs   r   rg   r*   rh   )r-   rŠ  r‹  rŒ  r/   r   r€   r0   r0   r1   Ú)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"   re   r   r   r   r   r   r   r   ZsubTestr  ro  r“   rq   r»  r½  )r-   ri   Z	audiodatar  Úclassesr  Úconstructorr   r0   r0   r1   Ú!test_mime_classes_policy_argument)  s"    

z3TestMiscellaneous.test_mime_classes_policy_argumentN)5r  r  r  r'  r)  r,  r-  r2  r8  r=  r>  r?  rB  rC  rH  rJ  rM  rN  rO  rR  rS  rT  rW  rX  rY  rZ  r]  ra  rd  rg  ri  rj  rk  rl  rm  rn  rp  rr  rs  rt  r|  r}  r  r€  r  r‚  rƒ  r„  rˆ  r  rŽ  r  r“  r0   r0   r0   r1   r&  :  sd   


			
*r&  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.txtr9  z
msg_02.txté+   z
msg_19.txt)r*   r  r+   r   Zbody_line_iteratorr÷  r  ÚEMPTYSTRINGrŽ   r?   r"   re   )r-   r.   rÍ  r/   Úitr   ri   r0   r0   r1   Útest_body_line_iteratorA  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   rQ   ru   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#  r?   r–  rŽ   )r-   r.   r/   r—  r   ÚsubpartsrS   r0   r0   r1   Útest_typed_subpart_iteratorR  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   rQ   z%
Hi,

Do you like this message?

-Me
)r*   r+   r   r™  r#  r?   r–  rŽ   )r-   r.   r/   r—  r   rš  rS   r0   r0   r1   Ú(test_typed_subpart_iterator_default_typec  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 
ru   )rb  r   )zc
rQ   )r'   r   )zd
rQ   )zer   )z
frQ   )z
rQ   r   )ÚBufferedSubFileÚNeedMoreDatarQ   r'   c             S   s   g | ]\}}|‘qS r0   r0   )rN   ÚilÚnr0   r0   r1   rP   ’  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olr0   r0   r1   Útest_pushCR_LFv  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'  rI  zabcd 	
r'   c             3   s   | ]}t ˆ ƒV  qd S )N)r   )rN   r0  )Úcharsr0   r1   r1  ›  s    z1TestIterators.test_push_random.<locals>.<genexpr>r&   T)r¡  r  rž  rŽ   r6  rò  r  r¢  Úextendr£  r¤  r*   )r-   r  rž  r   Z	chunksizer   Útargetr¥  r   r0  Úchunkr0   )r¨  r1   Útest_push_random”  s     

zTestIterators.test_push_randomN)r  r  r  r˜  r›  rœ  r§  r¬  r0   r0   r0   r1   r”  @  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-   Úchunksr3  r«  r0   r0   r1   Úparse©  s    
zTestFeedParsers.parsec             C   s.   |   d¡}|  |d d¡ |  |d d¡ d S )NzFirst: val
: bad
Second: valrÛ   ÚvalrÝ   )r±  r*   )r-   r/   r0   r0   r1   Ú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ä  rb  ÚcÚdza:
b:c:
d:za:bzc:
Zbcza:zb:
z
b:
u   a:Â…b:â€¨c:
)rä  u	   Â…b:â€¨c:u   b:Â…)rä  r'   )rb  u   Â…c:)r±  r*   rß   r[   )r-   r   r0   r0   r1   Ú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ä  rb  za:bõ   Â…za:zb: )rä  r'   rb  )r±  r*   r[   r?   )r-   ÚMÚNr   r0   r0   r1   Útest_long_linesÇ  s    zTestFeedParsers.test_long_linesN)r  r  r  r±  r³  r¶  rº  r0   r0   r0   r1   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±  r6   r‡  rˆ  rç   r?   r‰   )r-   r.   ri   r/   r0   r0   r1   Ú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"   rq   rk   rr   r±  r6   r‡  rˆ  rç   r?   r‰   r˜   )r-   r.   ri   r/   r0   r0   r1   Ú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"   rq   rk   ÚBytesParserr±  r‡  Úclosed)r-   ri   r0   r0   r1   Ú%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"   rq   rk   r¾  r]   r   rÂ  r“   Ústrictr±  r‡  r¿  )r-   ri   ZbytesParserr0   r0   r1   Ú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"   rq   rk   r   r±  r‡  r¿  )r-   ri   r0   r0   r1   Ú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"   rq   rk   r   r]   r   rÂ  r“   rÁ  r±  r‡  r¿  )r-   ri   rk   r0   r0   r1   Ú,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*   rq   r   r?   )r-   r.   r/   r0   r0   r1   Ú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*   rq   r   r?   )r-   r.   r/   r0   r0   r1   Ú(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‰  ru   r   z
text/plainz!Simple email with attachment.

rQ   zapplication/riscos)r*   r"   r   r±  r  r?   r6   )r-   r.   ri   r/   Úpart1Úpart2r0   r0   r1   Ú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"   re   rq   r   r   r   rg   r*   rh   )r-   ri   r~   r/   r   r€   r0   r0   r1   Útest_crlf_flatten8  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.txtrQ   ru   r   zmessage/rfc822z
text/plainz
message 1
z
message 2
)	r*   r  r"   rq   r  rˆ  r  r?   r6   )	r-   r.   rÍ  ri   r/   rÈ  Zpart1arÉ  Zpart2ar0   r0   r1   Ú-test_multipart_digest_with_extra_mime_headersD  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 +1000ZdatezTue, 20 Aug 2002 16:43:45 +1000)rq   r   r   rŽ   r*   )r-   r   r/   r0   r0   r1   Útest_three_linesc  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*   rq   r   Úget)r-   r.   Zvalue1Zvalue2r   r/   r0   r0   r1   Ú3test_strip_line_feed_and_carriage_return_in_headersk  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

bodyrv   c             s   s   | ]
}|V  qd S )Nr0   )rN   Zfieldr0   r0   r1   r1  {  s    z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>z!"#QUX;~z>Fromr‚   rÓ  )r*   rq   r   r  r5  r?   )r-   r.   r   r/   r0   r0   r1   Útest_rfc2822_header_syntaxv  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*   rq   r   r  rß   )r-   r.   r   r/   r0   r0   r1   Ú(test_rfc2822_space_not_allowed_in_header~  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ÚBZCCrÓ  )r*   rq   r   rß   Úsortr?   )r-   r.   r   r/   Zheadersr0   r0   r1   Ú!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
)rq   r   r‹   r?   r‡  )r-   r   r/   r0   r0   r1   Ú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Ë  rY  rÌ  rÍ  rÏ  rÐ  rÑ  rÕ  rÖ  r0   r0   r0   r1   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-8rB   u   pÃ¶stal)r3   r{   Úbodylineu   pÃ¶stal
T)r>   )Úbodytest_msgrõ   rp   rq   r`  r*   r?   )r-   r   r/   r0   r0   r1   Ú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notavalidcharsetrB   u   pÃ¶stal)r3   r{   rØ  zutf-8u   pï¿½ï¿½stal
T)r>   u   pÃ¶stal
)rÙ  rõ   rp   rq   r`  r*   r?   )r-   r   r/   r0   r0   r1   Ú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)r3   r{   rØ  u   p=C3=B6stÃ¡l
T)r>   u	   pÃ¶stÃ¡l
)rÙ  rõ   rp   rq   r`  r*   r?   )r-   r   r/   r0   r0   r1   Ú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 )
Nro   zquoted-printableu   p=C3=B6stÃ¡l)r3   r{   rØ  zutf-8u   p=C3=B6stï¿½ï¿½l
T)r>   u	   pÃ¶stÃ¡l
)rÙ  rõ   rp   rq   r`  r*   r?   )r-   r   r/   r0   r0   r1   Ú.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Ã¡=)r3   r{   rØ  T)r>   u   pÃ¶stalr   )rÙ  rõ   rp   rq   r`  r*   r?   rç   rè   r   ré   )r-   r   r/   r0   r0   r1   Ú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-8rx   u   <,.V<W1A; Ã¡ )r3   r{   rØ  T)r>   u   <,.V<W1A; Ã¡ 
)rÙ  rõ   rp   rq   r`  r*   r?   )r-   r   r/   r0   r0   r1   Ú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 r0   r0   )rN   ÚsrcÚ_r0   r0   r1   rP   
  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)rq   r`  Úheadertest_msgr*   r‰   rÎ  )r-   r/   r0   r0   r1   Ú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 )rQ   r0   )rN   rá  Zexpectedr0   r0   r1   rP     s    zATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>)	rq   r`  râ  r*   r‰   rþ   rÿ   rõ   Úheadertest_headers)r-   r/   r0   r0   r1   Ú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 r0   )r‰   )rN   rê   r0   r0   r1   rP   !  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)rq   r`  râ  ÚassertListEqualrà   )r-   r/   r0   r0   r1   Ú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 r0   )r‰   )rN   rê   rh  r0   r0   r1   rP   ,  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)rq   r`  râ  ræ  r[   )r-   r/   r0   r0   r1   Ú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 r0   )r‰   )rN   rê   r0   r0   r1   rP   8  s    zHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>r„   zfoo@bar.comu	   gï¿½ï¿½st)rq   r`  râ  ræ  r,   )r-   r/   r0   r0   r1   Útest_get_all_with_8bit_headers6  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)	rq   r`  rþ   rÿ   rp   r*   r6   rÈ   rÑ   )r-   r/   r0   r0   r1   Útest_get_content_type_with_8bit<  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)r_   )rz   u   ï¿½ne)u   bï¿½rr¤   )rœ   r¥   ZFoou   ï¿½neu   bÂ§r)rq   r`  rp   r*   r¦   r7   )r-   r/   r0   r0   r1   Útest_get_params_with_8bitE  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)rq   r`  rþ   rÿ   rp   r*   r7   )r-   r/   r0   r0   r1   Ú!test_get_rfc2231_params_with_8bitO  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)rq   r`  rþ   rÿ   rp   r²   r*   r7   )r-   r/   r0   r0   r1   Ú!test_set_rfc2231_params_with_8bitW  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~   )	rq   r`  rþ   rÿ   rp   r´   r*   r7   rÈ   )r-   r/   r0   r0   r1   Ú!test_del_rfc2231_params_with_8bit_  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
)rq   r`  rþ   rÿ   rp   r*   r?   )r-   r/   r0   r0   r1   Ú%test_get_payload_with_8bit_cte_headerh  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)	rq   r`  Únon_latin_bin_msgr   rs   r   rg   r*   rh   )r-   r/   rl   r0   r0   r1   Útest_bytes_generator~  s    z*Test8BitBytesHandling.test_bytes_generatorc             C   s6   t j ¡ }tƒ }t j |¡ |¡ |  | ¡ d¡ d S )Nr—   )	rq   rÊ   r   r   rs   r   rg   r*   rh   )r-   r/   rl   r0   r0   r1   Ú&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)
rq   r`  ró  r   rs   r   rg   r*   rh   Ú non_latin_bin_msg_as7bit_wrapped)r-   r/   rl   r0   r0   r1   Útest_generator_handles_8bit˜  s    z1Test8BitBytesHandling.test_generator_handles_8bitc             C   s`   t  | j¡}tƒ }t|ƒ |¡ | ¡ }ttƒ ƒ |¡ tƒ }t|ƒ |¡ |  	| ¡ |¡ d S )N)
rq   r`  ró  r   r   rg   rh   r   r   r*   )r-   r/   rl   Z
orig_valuer0   r0   r1   Ú;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   FromrQ   )rq   r`  ró  r   rs   r   rg   rh   rŠ   r*   rŽ   )r-   r/   rl   r   r0   r0   r1   Ú#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?=ru   rY   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  )Z
addCleanupr    ÚopenÚwriteró  rq   rk   r¾  r±  r*   r‰   Únon_latin_bin_msg_as7bit)r-   rP  Ztestfiler   r0   r0   r1   Ú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)rq   r`  Úlatin_bin_msgr*   r‰   Úlatin_bin_msg_as7bit)r-   r   r0   r0   r1   Ú: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&   )
rq   r`  rÿ  r   rs   r   rg   r*   rh   r>   )r-   r   rl   r0   r0   r1   Ú)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   r2  )rq   r3  r%   r6  r  rÿ  r®  r¯  r*   r‰   r   )r-   Zbfpr0  r   r0   r0   r1   Ú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"   re   rq   r`  r   rs   r   rg   r*   rh   )r-   ri   r~   r/   r   r€   r0   r0   r1   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ÿ   rp   rq   r`  r   rs   r   rg   r*   rh   )r-   ra  r/   r   r€   r0   r0   r1   Ú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   rq   rs   r   rg   r*   rh   )r-   r   r   r€   r0   r0   r1   Ú'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   rq   rs   r   rg   r*   rh   )r-   r   r   r€   r0   r0   r1   Ú!test_generator_b_encoding_linesep0  s    z7Test8BitBytesHandling.test_generator_b_encoding_linesepN)/r  r  r  rþ   rÿ   rÙ  rÚ  rÛ  rÜ  rÝ  rÞ  rß  rä  rŽ   rp   râ  rã  rå  rç  rè  ré  rê  rë  rî  rð  rñ  rò  ró  rô  rõ  rö  r÷  rø  rù  rŠ   rý  rþ  rÿ  r   r  r  r  rË  r  r  r  rY  r0   r0   r0   r1   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"   re   Únormalize_linesep_regexÚsubÚblineseprq   r`  )r-   r·   ri   r@   r/   r0   r0   r1   r+   C  s
    
z(BaseTestBytesGeneratorIdempotent._msgobjFc             C   s<   t ƒ }tjj|dd}|j||| jd |  || ¡ ¡ d S )Nr   )rJ  )rˆ   r’   )r   rq   rs   r   rg   r’   r*   rh   )r-   r/   r@   rˆ   rb  r€   r0   r0   r1   r  J  s    z,BaseTestBytesGeneratorIdempotent._idempotent)F)r  r  r  rY  r+   r  r0   r0   r0   r1   r  ?  s   r  c               @   s   e Zd ZdZdZe d¡ZdS )ÚTestBytesGeneratorIdempotentNLr&   r—   s   \r\nN)r  r  r  r’   r
  ÚreÚcompiler  r0   r0   r0   r1   r  Q  s   r  c               @   s   e Zd ZdZdZe d¡ZdS )Ú TestBytesGeneratorIdempotentCRLFz
s   
s	   (?<!\r)\nN)r  r  r  r’   r
  r  r  r  r0   r0   r0   r1   r  X  s   r  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   rv   rY   r9  é   rP  é   é   é   rê   )r*   r   Úheader_lengthr  Úbody_encoder6  )r-   r.   ÚsizeZbsizer0   r0   r1   Útest_len`  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-   r.   r0   r0   r1   Útest_decodem  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 )Nr  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"  r  zeHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r*   r   r  )r-   r.   r0   r0   r1   Útest_encoder  s    zTestBase64.test_encodec             C   sZ   | j }tj}||dƒdƒ ||dƒdƒ ||dƒdƒ ||dddd	ƒ ||dƒdƒ d S )
Nr  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)r3   z=?iso-8859-2?b?aGVsbG8=?=)r*   r   r_  )r-   r.   Úher0   r0   r1   Útest_header_encodeˆ  s    zTestBase64.test_header_encodeN)r  r  r  r  r  r  r   r0   r0   r0   r1   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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 ttdƒtdƒd ƒƒˆ _ˆ j tdƒ¡ ˆ j tdƒ¡ ‡ fdd„tdƒD ƒˆ _	d S )Nrä  ÚzrQ   rÒ  ÚZr@  Ú9c             s   s   | ]
}|V  qd S )Nr0   )rN   r´  r0   r0   r1   r1  œ  s    z#TestQuopri.setUp.<locals>.<genexpr>s   !*+-/c                s   g | ]}|ˆ j kr|‘qS r0   )Úhlit)rN   r´  )r-   r0   r1   rP   Ÿ  s    z$TestQuopri.setUp.<locals>.<listcomp>é   r(   ú~r  ú=c                s   g | ]}|ˆ j kr|‘qS r0   )Úblit)rN   r´  )r-   r0   r1   rP   ¨  s    )
r÷  r   r6  Úordr%  Úhnonr)  r#  ÚremoveÚbnon)r-   r0   )r-   r1   r[  •  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   Zheader_checkÚchrr+  r‹   )r-   r´  r0   r0   r1   Ú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)r)  r‡  r   Z
body_checkr.  r-  r‹   )r-   r´  r0   r0   r1   Ú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   hellorI  Zxxx)r3   r2  s
   h@e@l@l@o@r  rQ   zexpected length 1 for %rr(   rv   zexpected length 3 for %ró    )
r*   r   r  r  r_  r%  r˜   r.  r+  r*  )r-   r.   r´  r0   r0   r1   Ú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 )NrQ   rv   )r*   r)  r   Zbody_lengthr˜   r-  )r-   r.   r´  r0   r0   r1   Útest_body_quopri_lenÔ  s
    zTestQuopri.test_body_quopri_lenc             C   s6   x0t dƒD ]$}t|ƒ}|  t t |¡¡|¡ q
W d S )Nr&  )r6  r.  r*   r   r­   Zquote)r-   rê   r´  r0   r0   r1   Ú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-   r_   Zexpected_encoded_headerr3   Úencoded_headerr0   r0   r1   Ú_test_header_encodeà  s    zTestQuopri._test_header_encodec             C   s   |   dd¡ d S )Nr  r'   )r6  )r-   r0   r0   r1   Útest_header_encode_nullç  s    z"TestQuopri.test_header_encode_nullc             C   s   |   dd¡ d S )Ns   helloz=?iso-8859-1?q?hello?=)r6  )r-   r0   r0   r1   Ú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?=)r6  )r-   r0   r0   r1   Ú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?=)r6  )r-   r0   r0   r1   Ú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)r3   )r6  )r-   r0   r0   r1   Útest_header_encode_alt_charsetõ  s    z)TestQuopri.test_header_encode_alt_charsetc             C   s   t  |¡}|  ||¡ d S )N)r   Úheader_decoder*   )r-   r5  Zexpected_decoded_headerZdecoded_headerr0   r0   r1   Ú_test_header_decodeù  s    
zTestQuopri._test_header_decodec             C   s   |   dd¡ d S )Nr'   )r=  )r-   r0   r0   r1   Útest_header_decode_nullý  s    z"TestQuopri.test_header_decode_nullc             C   s   |   dd¡ d S )Nr  )r=  )r-   r0   r0   r1   Ú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-   r0   r0   r1   Ú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-   r0   r0   r1   Ú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-   r0   r0   r1   Ú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)r  )r   r>   r*   )r-   ZencodedZexpected_decodedr  Údecodedr0   r0   r1   Ú_test_decode  s    zTestQuopri._test_decodec             C   s   |   dd¡ d S )Nr'   )rD  )r-   r0   r0   r1   Útest_decode_null_word  s    z TestQuopri.test_decode_null_wordc             C   s   |   dd¡ d S )Nz
r&   )rD  )r-   r0   r0   r1   Útest_decode_null_line_null_word  s    z*TestQuopri.test_decode_null_line_null_wordc             C   s   |   dd¡ d S )Nr  )rD  )r-   r0   r0   r1   Útest_decode_one_word  s    zTestQuopri.test_decode_one_wordc             C   s   | j dddd d S )Nr  ÚX)r  )rD  )r-   r0   r0   r1   Útest_decode_one_word_eol  s    z#TestQuopri.test_decode_one_word_eolc             C   s   |   dd¡ d S )Nzhello
zhello
)rD  )r-   r0   r0   r1   Útest_decode_one_line   s    zTestQuopri.test_decode_one_linec             C   s   |   dd¡ d S )Nzhello
)rD  )r-   r0   r0   r1   Útest_decode_one_line_lf#  s    z"TestQuopri.test_decode_one_line_lfc             C   s   |   dd¡ d S )Nzhellozhello
)rD  )r-   r0   r0   r1   Útest_decode_one_line_cr&  s    z"TestQuopri.test_decode_one_line_crc             C   s   | j dddd d S )Nzhello
ÚhelloXrH  )r  )rD  )r-   r0   r0   r1   Útest_decode_one_line_nl)  s    z"TestQuopri.test_decode_one_line_nlc             C   s   | j dddd d S )Nzhello
rM  rH  )r  )rD  )r-   r0   r0   r1   Útest_decode_one_line_crnl,  s    z$TestQuopri.test_decode_one_line_crnlc             C   s   |   dd¡ d S )Nzhello
worldzhello
world)rD  )r-   r0   r0   r1   Ú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helloXworldrH  )r  )rD  )r-   r0   r0   r1   Ú!test_decode_one_line_one_word_eol2  s    z,TestQuopri.test_decode_one_line_one_word_eolc             C   s   |   dd¡ d S )Nzhello
world
zhello
world
)rD  )r-   r0   r0   r1   Útest_decode_two_lines5  s    z TestQuopri.test_decode_two_linesc             C   s   | j dddd d S )Nzhello
world
ZhelloXworldXrH  )r  )rD  )r-   r0   r0   r1   Útest_decode_two_lines_eol8  s    z$TestQuopri.test_decode_two_lines_eolc             C   s   |   dd¡ d S )NAè  SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam)rD  )r-   r0   r0   r1   Útest_decode_one_long_line;  s    z$TestQuopri.test_decode_one_long_linec             C   s   |   dd¡ d S )Nr(   r'   )rD  )r-   r0   r0   r1   Útest_decode_one_space>  s    z TestQuopri.test_decode_one_spacec             C   s   |   dd¡ d S )Nz     r'   )rD  )r-   r0   r0   r1   Útest_decode_multiple_spacesA  s    z&TestQuopri.test_decode_multiple_spacesc             C   s   |   dd¡ d S )Nzhello    
zhello
)rD  )r-   r0   r0   r1   Ú$test_decode_one_line_trailing_spacesD  s    z/TestQuopri.test_decode_one_line_trailing_spacesc             C   s   |   dd¡ d S )Nzhello    
world   
zhello
world
)rD  )r-   r0   r0   r1   Ú%test_decode_two_lines_trailing_spacesG  s    z0TestQuopri.test_decode_two_lines_trailing_spacesc             C   s   |   dd¡ d S )Nz=22quoted=20words=22z"quoted words")rD  )r-   r0   r0   r1   Útest_decode_quoted_wordJ  s    z"TestQuopri.test_decode_quoted_wordc             C   s   |   dd¡ d S )Nzab=CD=EFu   abÃÃ¯)rD  )r-   r0   r0   r1   Útest_decode_uppercase_quotingM  s    z(TestQuopri.test_decode_uppercase_quotingc             C   s   |   dd¡ d S )Nzab=cd=efu   abÃÃ¯)rD  )r-   r0   r0   r1   Útest_decode_lowercase_quotingP  s    z(TestQuopri.test_decode_lowercase_quotingc             C   s   |   dd¡ d S )Nzsoft line=
breakzsoft linebreak)rD  )r-   r0   r0   r1   Útest_decode_soft_line_breakS  s    z&TestQuopri.test_decode_soft_line_breakc             C   s   |   dd¡ d S )NzA=1,B=A ==> A+B==2)rD  )r-   r0   r0   r1   Útest_decode_false_quotingV  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&   r  z
)r   r  r*   rò  r  r  )r-   rÓ  Zexpected_encoded_bodyr"  r  ÚkwargsZencoded_bodyrÕ  r0   r0   r1   Ú_test_encodeY  s    zTestQuopri._test_encodec             C   s   |   dd¡ d S )Nr'   )r_  )r-   r0   r0   r1   Útest_encode_nullm  s    zTestQuopri.test_encode_nullc             C   s   |   dd¡ d S )Nz

)r_  )r-   r0   r0   r1   Útest_encode_null_linesp  s    z!TestQuopri.test_encode_null_linesc             C   s   |   dd¡ d S )Nzhello
)r_  )r-   r0   r0   r1   Útest_encode_one_lines  s    zTestQuopri.test_encode_one_linec             C   s   |   dd¡ d S )Nzhello
zhello
)r_  )r-   r0   r0   r1   Útest_encode_one_line_crlfv  s    z$TestQuopri.test_encode_one_line_crlfc             C   s   | j dddd d S )Nzhello
zhello
z
)r  )r_  )r-   r0   r0   r1   Útest_encode_one_line_eoly  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
)r  )r_  rp   r>   )r-   r0   r0   r1   Ú(test_encode_one_line_eol_after_non_ascii|  s    z3TestQuopri.test_encode_one_line_eol_after_non_asciic             C   s   |   dd¡ d S )Nr(   z=20)r_  )r-   r0   r0   r1   Útest_encode_one_space  s    z TestQuopri.test_encode_one_spacec             C   s   |   dd¡ d S )Nz 
z=20
)r_  )r-   r0   r0   r1   Ú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-   r0   r0   r1   Ú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-   r0   r0   r1   Ú$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-   r0   r0   r1   Ú$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-   r0   r0   r1   Ú!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-   r0   r0   r1   Ú!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 =

1234r9  )r"  )r_  )r-   r0   r0   r1   Ú,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
1234rI  )r"  )r_  )r-   r0   r0   r1   Ú(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
1234rY   )r"  )r_  )r-   r0   r0   r1   Ú,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-   r0   r0   r1   Ú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-   r0   r0   r1   Útest_encode_quoted_equals§  s    z$TestQuopri.test_encode_quoted_equalsc             C   s   |   dd¡ d S )NZdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx)r_  )r-   r0   r0   r1   Útest_encode_one_long_stringª  s    z&TestQuopri.test_encode_one_long_stringc             C   s   |   dd¡ d S )Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
)r_  )r-   r0   r0   r1   Ú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-   r0   r0   r1   Ú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=
=3DrY   )r"  )r_  )r-   r0   r0   r1   Útest_encode_shortest_maxlinelen´  s    z*TestQuopri.test_encode_shortest_maxlinelenc             C   s   | j t| jdddd d S )Nr'   rv   )r"  )r]   r½   r_  )r-   r0   r0   r1   Ú 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'   r  zhello
worldzhello
worldzdxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx r  )r"  zjxxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
x xxxx xxxx xxxx xxxx=20z
)r"  r  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   r  )r-   r.   r0   r0   r1   r  º  s    zTestQuopri.test_encode)N)N)NN)Fr  r  r  r[  r/  r0  r2  r3  r4  r6  r7  r8  r9  r:  r;  r=  r>  r?  r@  rA  rB  rD  rE  rF  rG  rI  rJ  rK  rL  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  r]  r_  r`  ra  rb  rc  rd  rf  rg  rh  ri  rj  rk  rl  rm  rn  ro  rp  rq  rr  rs  rt  ru  rv  rw  r  r0   r0   r0   r1   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   )r3   Úfake)rq   r3   ZCHARSETSrâ   )r-   ÚCharsetModuler0   r0   r1   Ú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]   rf  )r-   r.   r´  r   r0   r0   r1   Ú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   )r3   ry  )r*   r   r  rq   r3   Zadd_charsetZQP)r-   r.   r´  rz  r0   r0   r1   Ú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   ZCharsetError)r-   r3   r0   r0   r1   Útest_unicode_charset_name  s    z%TestCharset.test_unicode_charset_nameN)r  r  r  r{  r|  r}  r~  r0   r0   r0   r1   rx  Ö  s   rx  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d3S )4Ú
TestHeaderc             C   s8   | j }tdƒ}|| ¡ dƒ | d¡ || ¡ dƒ d S )NzHello World!z Goodbye World!zHello World!  Goodbye World!)r  r	   rp   r#  )r-   r.   r  r0   r0   r1   Ú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	   rp   r#  )r-   r.   r  r0   r0   r1   Ú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  r0   r0   r1   Ú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(   )Z
splitcharsz
 )r	   rp   rŠ   r  r  )r-   r  Úlr0   r0   r1   Ú	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?=rv   r   rQ   ru   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#  rp   r
   r  r‰   r>   r   )r-   r.   r€   r$  r%  r&  r'  r(  r  ÚencrC  ZustrZnewhr0   r0   r1   Útest_multilingual)  s0    
zTestHeader.test_multilingualc             C   s   t ƒ }|  | ¡ d¡ d S )Nr'   )r	   r*   rp   )r-   r  r0   r0   r1   Útest_empty_header_encodeh  s    z#TestHeader.test_empty_header_encodec             C   s4   | j }tƒ }||dƒ | dtdƒ¡ ||dƒ d S )Nr'   rz   z
iso-8859-1)r  r	   r#  r   )r-   r.   r  r0   r0   r1   Útest_header_ctor_default_argsl  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	   rp   r‰   )r-   r.   r  r  r0   r0   r1   Útest_explicit_maxlinelens  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-1r  )r3   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?_?=r  zÁ=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xxx?=
 =?iso-8859-1?q?x_xxxx_xxxx_xxxx_xxxx_?=
 =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
 =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
 =?iso-8859-1?q?_xxxx_xxxx_?=)r  r	   r#  rp   r‰   r   r
   )r-   r.   r  rê   r   r0   r0   r1   Ú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-rr  )r3   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==?=r  zà=?koi8-r?b?eHh4eCB4eHh4IHh4eHggeHh4?=
 =?koi8-r?b?eCB4eHh4IHh4eHggeHh4eCB4?=
 =?koi8-r?b?eHh4IHh4eHggeHh4eCB4eHh4?=
 =?koi8-r?b?IHh4eHggeHh4eCB4eHh4IHh4?=
 =?koi8-r?b?eHggeHh4eCB4eHh4IHh4eHgg?=
 =?koi8-r?b?eHh4eCB4eHh4IA==?=)r  r	   r#  rp   r‰   r   r
   )r-   r.   r  rê   r   r0   r0   r1   Útest_base64_splittableË  s    
"
z!TestHeader.test_base64_splittablec             C   s8   | j }d}t|ƒ}||dgƒ t|ƒ}||| ¡ ƒ d S )Nr  )r  N)r*   r
   r   rp   )r-   r.   r   rê   r  r0   r0   r1   Útest_us_ascii_header  s    zTestHeader.test_us_ascii_headerc             C   s&   | j }tƒ }| dd¡ ||dƒ d S )Nr  z
iso-8859-1)r*   r	   r#  )r-   r.   r  r0   r0   r1   Ú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	   rp   )r-   r.   r  r0   r0   r1   Ú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*   rf  r	   r#  r>   r‰   )r-   r£  r.   rê   r  Úer0   r0   r1   Ú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 Bigro   Úsurrogateescape)r3   u2   Ynwp4dUEbay Auction Semiar- No Charge ï¿½ Earn Bigzunknown-8bit)	r>   r	   rq   r3   ÚUNKNOWN8BITr*   r‰   r_   r
   )r-   rê   r  r  r0   r0   r1   Ú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)r3   u2   Ynwp4dUEbay Auction Semiar- No Charge ï¿½ Earn Bigzunknown-8bit)r	   rq   r3   r’  r*   r‰   r_   r
   )r-   rê   r  r0   r0   r1   Ú&test_header_handles_binary_unknown8bit3  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)r3   u2   Ynwp4dUEbay Auction Semiar- No Charge ï¿½ Earn Bigzunknown-8bit)	r	   rq   r3   r’  r_   r   r
   r*   r‰   )r-   rê   r  Zh2r0   r0   r1   Ú+test_make_header_handles_binary_unknown8bit:  s    
z6TestHeader.test_make_header_handles_binary_unknown8bitc             C   s2   t dƒ}tj |¡}| d¡ |  t|ƒd¡ d S )Nrï  )ro   Ztest2)r	   rq   r_   r
   r#  r*   r‰   )r-   r  r°  r0   r0   r1   Ú0test_modify_returned_list_does_not_change_headerB  s    
z;TestHeader.test_modify_returned_list_does_not_change_headerc             C   sR   | j }tƒ }| dd¡ | d¡ | ¡ }||dƒ tt|ƒƒ}|| ¡ |ƒ d S )Nr  z
iso-8859-1Zworldz=?iso-8859-1?q?hello?= world)r*   r	   r#  rp   r   r
   )r-   r.   r  r   r0   r0   r1   Ú test_encoded_adjacent_nonencodedH  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   rp   )r-   r.   r   ÚpartsZhdrr0   r0   r1   Útest_whitespace_keeperR  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   r^   r
   )r-   r£  r   r0   r0   r1   Útest_broken_base64_header[  s    z$TestHeader.test_broken_base64_headerc             C   s    t ddd}|  | ¡ d¡ d S )Nu   æ–‡Ú	shift_jis)r3   z=?iso-2022-jp?b?GyRCSjgbKEI=?=)r	   r*   rp   )r-   r  r0   r0   r1   Útest_shift_jis_charset`  s    z!TestHeader.test_shift_jis_charsetc             C   s   t  d¡}|  t|ƒd¡ d S )NzEmptyHeader:zEmptyHeader: 

)rq   r   r*   r‰   )r-   r/   r0   r0   r1   Ú!test_flatten_header_with_no_valued  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-   r/   r0   r0   r1   Ú)test_encode_preserves_leading_ws_on_valuek  s    z4TestHeader.test_encode_preserves_leading_ws_on_valuec             C   s   |   tdƒ ¡ d¡ d S )Nr(   )r*   r	   rp   )r-   r0   r0   r1   Útest_whitespace_headerp  s    z!TestHeader.test_whitespace_headerN)r  r  r  r€  r  r‚  r„  r†  r‡  rˆ  r‰  rŠ  r‹  rŒ  r  rŽ  r  r“  r”  r•  r–  r—  r™  rš  rœ  r  rž  rŸ  r0   r0   r0   r1   r    s2   ?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+   r7   )r-   r.   r/   r0   r0   r1   rª   z  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)r3   )zus-asciir'   z%This is even more ***fun*** isn't it!rí  )r3   Úlanguage)zus-asciirí  z%This is even more ***fun*** isn't it!z
msg_01.txtrH  )rJ  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²   r7   r+   rc   )r-   r.   r/   r0   r0   r1   r³   ‚  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ì  rz   zcontent-typeztext/plain; title="foo"r£   F)Zrequoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")r   r²   r*   )r-   r/   r0   r0   r1   Ú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.txtrz   r£   zus-asciirí  )r3   r¡  rì  z%This is even more ***fun*** isn't it!zContent-Type)r_   rH  )rJ  a$  Return-Path: <bbb@zzz.org>
Delivered-To: bbb@zzz.org
Received: by mail.zzz.org (Postfix, from userid 889)
	id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
From: bbb@ddd.com (John X. Doe)
To: bbb@zzz.org
Subject: This is a test message
Date: Fri, 4 May 2001 14:05:44 -0400
Content-Type: text/plain; charset="us-ascii";
 title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21


Hi,

Do you like this message?

-Me
)r  r+   r²   r´   rc   )r-   r.   r/   r0   r0   r1   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-   r.   r/   r0   r0   r1   Ú 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ÿ   rq   r   r*   rM   rc   )r-   r   r/   r0   r0   r1   Ú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ÿ   rq   r   r*   rM   rc   )r-   r   r/   r0   r0   r1   Ú 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)rq   r   r7   ÚassertNotIsInstanceÚtupler*   )r-   r   r/   Úparamr0   r0   r1   Ú#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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú/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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú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)rq   r   r*   rW   )r-   r   r/   r0   r0   r1   Ú/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)rq   r   r*   r£  )r-   r   r/   r0   r0   r1   Ú.test_rfc2231_no_language_or_charset_in_charsetF  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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú%test_rfc2231_bad_encoding_in_filenameT  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

)rq   r   r*   r£  )r-   r   r/   r0   r0   r1   Ú$test_rfc2231_bad_encoding_in_charset`  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

)rq   r   r*   r£  )r-   r   r/   r0   r0   r1   Ú%test_rfc2231_bad_character_in_charsetj  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ï¿½)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú&test_rfc2231_bad_character_in_filenamet  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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Útest_rfc2231_unknown_encoding€  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*   rq   r   r7   )r-   r.   r   r/   r3   r¡  r   r0   r0   r1   Ú-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)rq   r   r7   r¨  r©  r*   )r-   r   r/   rª  r0   r0   r1   Ú$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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú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)rq   r   r*   rM   )r-   r   r/   r0   r0   r1   Ú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*   rq   r   r7   )r-   r.   r   r/   r3   r¡  r   r0   r0   r1   Ú!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)rq   r   r7   r¨  r©  r*   )r-   r   r/   rª  r0   r0   r1   Ú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*   rq   r   r7   )r-   r.   r   r/   r0   r0   r1   Ú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*   rq   r   r7   )r-   r.   r   r/   r3   r¡  r   r0   r0   r1   Ú,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*   rq   r   r7   )r-   r.   r   r/   r3   r¡  r   r0   r0   r1   Ú,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¿  r0   r0   r0   r1   r   v  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"   re   rq   r   )r-   r·   ri   Úoriginalr/   r0   r0   r1   Ú_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$ru   )r  r  ÚSr¸  ÚsearchÚgroupr*   )r-   rÁ  Úresultr  ZrepartZinpartZoutpartr0   r0   r1   Ú_signed_parts_eq  s
    zTestSigned._signed_parts_eqc             C   s&   |   d¡\}}| ¡ }|  ||¡ d S )Nz
msg_45.txt)rÂ  rc   rÇ  )r-   rÁ  r/   rÆ  r0   r0   r1   Ú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é<   )rJ  )rÂ  rc   rÇ  )r-   rÁ  r/   rÆ  r0   r0   r1   Ú(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   rg   rh   rÇ  )r-   rÁ  r/   ri   rÆ  r0   r0   r1   Útest_long_headers_flatten  s
    z$TestSigned.test_long_headers_flattenN)r  r  r  rÂ  rÇ  rÈ  rÊ  rË  r0   r0   r0   r1   rÀ  ÿ  s
   rÀ  Ú__main__)`r  r›  r=   r’  rþ   Úior   r   Ú	itertoolsr   Zrandomr   Zsocketr   Z	threadingr   rq   Zemail.policyZemail.charsetr   Zemail.headerr	   r
   r   Zemail.parserr   r   Zemail.generatorr   r   r   Zemail.messager   Zemail.mime.applicationr   Zemail.mime.audior   Zemail.mime.textr   Zemail.mime.imager   Zemail.mime.baser   Zemail.mime.messager   Zemail.mime.multipartr   Zemail.mime.nonmultipartr   r   r   r   r   r   r   Ztest.supportr    r!   Ztest.test_emailr"   r#   r$   r%   r   r–  r5  r)   ZTestCaser  r  rZ  re  rr  ru  r„  r”  r¿  rØ  rô  r  r&  r”  r­  r»  r×  r  r  r  r  r!  rx  r  r   rÀ  r  Úmainr0   r0   r0   r1   Ú<module>   sÆ        IC    AO((\<    0   <      
g0 K   !5  D:  h   #
