
    7\hn                       d dl Z 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Zd dlmZ d dlmZ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.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4 d dlm5Z5 d dlm6Z6 d dlm7Z7 d dlm8Z8 d dlm9Z9 d dlm:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZBmCZC d dl2mDZDmEZE d ZFd!ZGd"ZH G d# d$eC          ZI G d% d&ejJ                  ZK G d' d(eC          ZL G d) d*ejJ                  ZM G d+ d,ejJ                  ZN G d- d.ejJ                  ZO G d/ d0ejJ                  ZP G d1 d2ejJ                  ZQ G d3 d4eC          ZR G d5 d6eC          ZS G d7 d8eC          ZT G d9 d:eC          ZU G d; d<eC          ZV G d= d>eC          ZW G d? d@eC          ZX G dA dBeC          ZY G dC dDeC          ZZ G dE dFeC          Z[ G dG dHeC          Z\ G dI dJ          Z] G dK dLe]eW          Z^ G dM dNe]eW          Z_ G dO dPejJ                  Z` G dQ dRejJ                  Za G dS dTejJ                  Zb G dU dVeC          Zc G dW dXeC          Zd G dY dZeC          Ze G d[ d\eC          Zfegd]k    r ejh                     dS dS )^    N)StringIOBytesIO)chainchoice)Thread)patch)Charset)	GeneratorDecodedGeneratorBytesGenerator)Headerdecode_headermake_header)HeaderRegistry)Message)MIMEApplication)	MIMEAudio)MIMEBase)	MIMEImage)MIMEMessage)MIMEMultipart)MIMENonMultipart)MIMEText)ParserHeaderParser)
base64mime)encoderserrors)	iterators)
quoprimime)utils)support)threading_helper)unlink)openfileTestEmailBase)
FeedParserBytesFeedParser
  c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLdK ZMdL ZNdM ZOdN ZPdO ZQdP ZRdQ ZSdR ZTdS ZUdT ZVdU ZWdV ZXdWS )XTestMessageAPIc                     | j         }|                     d          } ||                    d          g d            ||                    dd          d           d S )Nz
msg_20.txtcc)zccc@zzz.orgzddd@zzz.orgzeee@zzz.orgxxzn/a)assertEqual_msgobjget_allselfeqmsgs      D/opt/python-3.11.14/usr/lib/python3.11/test/test_email/test_email.pytest_get_allzTestMessageAPI.test_get_all;   sf    ll<((
3;;tKKKLLL
3;;tU##U+++++    c                 :   | 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 )N
iso-8859-1mime-versionz1.0
text/plaincontent-typez text/plain; charset="iso-8859-1"charsetcontent-transfer-encodingquoted-printablez2.0zMIME-Versionztext/x-weirdContent-Typezquinted-puntableContent-Transfer-Encodingz"text/x-weird; charset="iso-8859-1")r3   r   get_charsetr
   set_charsetget_content_type	get_paraminput_charsetr7   r8   r9   rB   s       r:   test_getset_charsetz"TestMessageAPI.test_getset_charsetA   s   ii
3??d###,''   
3~&&&
3!!<000
3~ BCCC
3==##\222
3*+-?@@@
3??*L999
3??d###
3~---ii#N,N+='(   
3~&&&
3~ DEEE
3*+-?@@@@@r<   c                     | j         }t                      }|                    d            ||                                j        d            ||d         d           d S )Nus-asciirA   text/plain; charset="us-ascii")r3   r   rH   rG   rK   r6   s      r:   test_set_charset_from_stringz+TestMessageAPI.test_set_charset_from_string[   sb    ii
###
3??*J777
3~ @AAAAAr<   c                     t                      }t          d          }|                    d|           |                     |                                j        d           d S )Nr>   zThis is a string payload)r   r
   set_payloadr3   rG   rK   )r7   r9   rB   s      r:   test_set_payload_with_charsetz,TestMessageAPI.test_set_payload_with_charsetb   sV    ii,''2G<<<**8,GGGGGr<   c                 L   d}t          d          }t                      }|                    ||           |                     |d         d           |                     |                    d          |           |                     |                                d           d S )N   АБВutf-8rC   base64Tdecodez	0JDQkdCS
)r
   r   rS   r3   get_payloadr7   datarB   r9   s       r:   +test_set_payload_with_8bit_data_and_charsetz:TestMessageAPI.test_set_payload_with_8bit_data_and_charseth   s    *'""iig&&&898DDD55t<<<**L99999r<   c                 0   d}t          d          }d |_        t                      }|                    |                    d          |           |                     |d         d           |                     |                    d          |           d S NrV   rW   rC   8bitTrY   )r
   body_encodingr   rS   rZ   r3   r[   r\   s       r:   >test_set_payload_with_non_ascii_and_charset_body_encoding_nonezMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_noneq   s    *'"" $iiG,,g666896BBB55t<<<<<r<   c                 
   d}t          d          }d |_        t                      }|                    ||           |                     |d         d           |                     |                    d          |           d S r`   )r
   rb   r   rS   r3   r[   r\   s       r:   >test_set_payload_with_8bit_data_and_charset_body_encoding_nonezMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonez   s    *'"" $iig&&&896BBB55t<<<<<r<   c                     t                      }|                    g            |                     |                                g            d S Nr   rS   r3   r[   r7   r9   s     r:   test_set_payload_to_listz'TestMessageAPI.test_set_payload_to_list   sC    ii**B/////r<   c                     t                      }d|d<   |                    d           t          t                                }|                     t          d|j        |           d S )Nmultipart/mixedrE   zstring payloadz[Aa]ttach.*non-multipart)r   rS   r   assertRaisesRegex	TypeErrorattach)r7   r9   sub_msgs      r:   "test_attach_when_payload_is_stringz1TestMessageAPI.test_attach_when_payload_is_string   sg    ii/N()))gii((y*D"z7	4 	4 	4 	4 	4r<   c                 `   | j         }|                     d          }|                                } ||g d           |                     d          }|                    d          } ||g d           |                     d          }|                                } ||g d           d S )Nz
msg_08.txt)NrO   r>   
iso-8859-2koi8-rz
msg_09.txtdingbat)ru   rO   r>   ru   rt   z
msg_12.txt)NrO   r>   Nrs   z
iso-8859-3rO   rt   )r3   r4   get_charsets)r7   r8   r9   charsetss       r:   test_get_charsetsz TestMessageAPI.test_get_charsets   s    ll<((##%%
8MMMNNNll<((##I..
8       	! 	! 	! ll<((##%%
8 : : : 	; 	; 	; 	; 	;r<   c                 &   | j         }|                     d          }d |                                D             } ||ddg           |                     d          }|                    d          } ||                                d           d S )N
msg_04.txtc                 6    g | ]}|                                 S  get_filename.0ps     r:   
<listcomp>z4TestMessageAPI.test_get_filename.<locals>.<listcomp>   "    AAA!Q^^%%AAAr<   msg.txt
msg_07.txt   dingusfish.gif)r3   r4   r[   r~   )r7   r8   r9   	filenamessubparts        r:   test_get_filenamez TestMessageAPI.test_get_filename   s    ll<((AAs/@/@AAA	
9y),---ll<((//!$$
7!!#344444r<   c                     | j         }|                     d          }d |                                D             } ||ddg           d S )Nz
msg_44.txtc                 6    g | ]}|                                 S r|   r}   r   s     r:   r   zHTestMessageAPI.test_get_filename_with_name_parameter.<locals>.<listcomp>   r   r<   r   r3   r4   r[   )r7   r8   r9   r   s       r:   %test_get_filename_with_name_parameterz4TestMessageAPI.test_get_filename_with_name_parameter   sU    ll<((AAs/@/@AAA	
9y),-----r<   c                 z    | j         }|                     d          } ||                                d           d S )Nr   BOUNDARY)r3   r4   get_boundaryr6   s      r:   test_get_boundaryz TestMessageAPI.test_get_boundary   s?    ll<((
3z*****r<   c                 N   | j         }|                     d          }|                    d           |                                d         \  }} ||                                d            ||d           |                     d          }|                    d           |                                d         \  }} ||                                d            ||d           |                     d          }|                     t          j        |j        d           d S )	N
msg_01.txtr      rA   z3text/plain; charset="us-ascii"; boundary="BOUNDARY"rz   z$multipart/mixed; boundary="BOUNDARY"
msg_03.txt)r3   r4   set_boundaryitemslowerassertRaisesr    HeaderParseError)r7   r8   r9   headervalues        r:   test_set_boundaryz TestMessageAPI.test_set_boundary   s    ll<(($$$		A
6<<>>>***
5GHHH ll<(($$$		A
6<<>>>***
58999ll<((&1*J	8 	8 	8 	8 	8r<   c                 ,   t          d          }|                     |                                d         d         d           |                                 |                     |                                d         d         d d         d           d S )Nz	form-datar   r   zmultipart/form-data!   z!multipart/form-data; boundary="==)r   r3   r   	as_stringri   s     r:   test_make_boundaryz!TestMessageAPI.test_make_boundary   s    K(( 	Q*,ABBBQ*3B3/;	= 	= 	= 	= 	=r<   c                    t          dd          5 }|                                }d d d            n# 1 swxY w Y   t                      }|                    |          }t	                      }t          |dd          }|                    |d           |                     |                                |           d S )N
msg_46.txtrW   encodingTr   F)	r'   readr   parsestrr   r   flattenr3   getvaluer7   fpmsgdataparserr9   outgens          r:   test_message_rfc822_onlyz'TestMessageAPI.test_message_rfc822_only   s     lW555 	 ggiiG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 oog&&jjT1%%C11111   377c                    t          dd          5 }|                                                    d          }d d d            n# 1 swxY w Y   t          j                                        }|                    |          }t                      }t          j        	                    |          }|
                    |           |                     |                                |           d S )Nr   rW   r   ascii)r'   r   encodeemailr   BytesHeaderParser
parsebytesr   	generatorr   r   r3   r   r   s          r:   test_byte_message_rfc822_onlyz,TestMessageAPI.test_byte_message_rfc822_only   s    lW555 	0ggii&&w//G	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0//11((iio,,S11C11111s   (AA
A
c                 |   | j         }|                     d          } ||                    d          d             ||                    d                              d          d            ||                    d                              d          d            ||                    d                              d          d	            ||                    d
                              d          d            ||                    d                              d          d           d S )Nz
msg_10.txtTrY   r   s    This is a 7bit encoded message.
r   s-   This is a Quoted Printable encoded message!
   s!   This is a Base64 encoded message.   s"   This is a Base64 encoded message.
r   s/   This has no Content-Transfer-Encoding: header.
r   r6   s      r:   test_get_decoded_payloadz'TestMessageAPI.test_get_decoded_payload   sc   ll<((
3??$?''...
3??1)))66/	1 	1 	1 	3??1)))66?	A 	A 	A 	3??1)))66/	1 	1 	1 	3??1)))661	3 	3 	3 	3??1)))66>	@ 	@ 	@ 	@ 	@r<   c                    | j         }t                      }|                    d           dD ]'}||d<    ||                    d          d           (|                    d            ||                    d          d           d S )	Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
z
x-uuencodeuuencodeuuezx-uuerC   TrY      hello worldfoos   foo)r3   r   rS   r[   )r7   r8   r9   ctes       r:   test_get_decoded_uu_payloadz*TestMessageAPI.test_get_decoded_uu_payload  s    iiCDDD= 	= 	=C/2C+,Bsd++^<<<<
3??$?''00000r<   c                 d    t                      }|                     t          |j        d           d S )Nr   )r   r   rn   r[   ri   s     r:   *test_get_payload_n_raises_on_non_multipartz9TestMessageAPI.test_get_payload_n_raises_on_non_multipart  s+    ii)S_a88888r<   c                 X   | j         }|                     d          }t          dd          5 }|                                }d d d            n# 1 swxY w Y   t	                      }t          |          }|                    |            ||                                |           d S )Nr   z
msg_17.txtrW   r   )r3   r4   r'   r   r   r   r   r   )r7   r8   r9   r   textsgs          r:   test_decoded_generatorz%TestMessageAPI.test_decoded_generator  s    ll<((lW555 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	JJQ			#
1::<<s   AAAc                 >   t                      }d|d<   d|d<   |                     d|           |                     d|           |                     d|           |                     d|           |                     d|           |                     d|           d S )	NMeFromYoutofromFROMToTO)r   assertInri   s     r:   test__contains__zTestMessageAPI.test__contains__   s    iiFD	fc"""fc"""fc"""dC   dC   dC     r<   c                    |                      d          }t          dd          5 }|                                }d d d            n# 1 swxY w Y   |                     |t	          |                     |                    d          }|                    d          }|                     |d                             d                     |                     |t          
                    |d	d                               d S )
Nr   rW   r   Tunixfromr+   r   zFrom r   )r4   r'   r   r3   strr   split
assertTrue
startswithNLjoin)r7   r9   r   r   fullreprliness         r:   test_as_stringzTestMessageAPI.test_as_string,  s   ll<((lW555 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s3xx(((==$=//t$$a++G44555rwwuQRRy1122222s   AAAc                 J   |                      d          }|j                            d          }|                    |          }t	                      }t          ||          }|                    |           |                     ||                                           d S Nr   
lineseppolicy)	r4   r   cloner   r   r   r   r3   r   r7   r9   	newpolicyr   r   r   s         r:   test_as_string_policyz$TestMessageAPI.test_as_string_policy6  s    ll<((J$$V$44	==	=22JJa	***			#1::<<00000r<   c                     t          j        d          }|                    d          }t          j        d          }t          j        |          }|                     |                                |           d S )Nu               MIME-Version: 1.0
            Content-type: text/plain; charset="iso-8859-1"

            Test if non-ascii messages with no Content-Transfer-Encoding set
            can be as_string'd:
            Föö bär
            r>   a%              MIME-Version: 1.0
            Content-type: text/plain; charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            Test if non-ascii messages with no Content-Transfer-Encoding set
            can be as_string'd:
            F=F6=F6 b=E4r
            )textwrapdedentr   r   message_from_bytesr3   r   r7   msourceexpectedr9   s        r:   #test_nonascii_as_string_without_ctez2TestMessageAPI.test_nonascii_as_string_without_cte?  sw    O    ,''? $   &v..(33333r<   c                     t          j        d          }|                    d          }|                    dd          }t	          j        |          }|                     |                                |           d S )Nu              MIME-Version: 1.0
            Content-type: text/plain; charset="us-ascii"
            Content-Transfer-Encoding: 8bit

            Test if non-ascii messages with no Content-Transfer-Encoding set
            can be as_string'd:
            Föö bär
            r>   r   replacer   r   r   rZ   r   r   r3   r   r   s        r:   *test_nonascii_as_string_with_ascii_charsetz9TestMessageAPI.test_nonascii_as_string_with_ascii_charsetU  sr    O    ,''==)44&v..(33333r<   c                     t          j        d          }|                    d          }|                    dd          }t	          j        |          }|                     |                                |           d S )Nu               MIME-Version: 1.0

            Test if non-ascii messages with no Content-Type nor
            Content-Transfer-Encoding set can be as_string'd:
            Föö bär
            r>   r   r   r   r   s        r:   4test_nonascii_as_string_without_content_type_and_ctezCTestMessageAPI.test_nonascii_as_string_without_content_type_and_cted  sr    O    ,''==)44&v..(33333r<   c                 *   |                      d          }t          dd          5 }|                                                    d          }d d d            n# 1 swxY w Y   |                     |t          |                     |                    d          }|                    d          }|                     |d         	                    d	                     |                     |d
                    |d
d                               d S )Nr   rW   r   r   Tr      
r   s   From r   )r4   r'   r   r   r3   bytesas_bytesr   r   r   r   )r7   r9   r   r]   r   r   s         r:   test_as_byteszTestMessageAPI.test_as_bytesq  s'   ll<((lW555 	-7799##G,,D	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-uSzz***<<<..u%%a++H55666uzz%)4455555s   (AA"Ac                 J   |                      d          }|j                            d          }|                    |          }t	                      }t          ||          }|                    |           |                     ||                                           d S r   )	r4   r   r   r  r   r   r   r3   r   r   s         r:   test_as_bytes_policyz#TestMessageAPI.test_as_bytes_policy{  s    ll<((J$$V$44	<<y<11II1I...			#1::<<00000r<   c                     t          j        d          }|                     |                    d          d           d S )NzContent-Type: blarg; baz; boo
bazr,   r   message_from_stringr3   rJ   ri   s     r:   test_bad_paramzTestMessageAPI.test_bad_param  s;    '(IJJu--r22222r<   c                 ~    t          j        d          }|                     |                                d            d S Nz
From: foo
r   r	  r3   r~   ri   s     r:   test_missing_filenamez$TestMessageAPI.test_missing_filename  :    '66))++T22222r<   c                 ~    t          j        d          }|                     |                                d           d S )Nz%Content-Disposition: blarg; filename
r,   r  ri   s     r:   test_bogus_filenamez"TestMessageAPI.test_bogus_filename  s?    '02 2))++R00000r<   c                 ~    t          j        d          }|                     |                                d            d S r  r   r	  r3   r   ri   s     r:   test_missing_boundaryz$TestMessageAPI.test_missing_boundary  r  r<   c                    | j         }t          j        d          } ||                    d          g d           t          j        d          } ||                    d          g d            ||                                d            t          j        d          } ||                    d          g d           d S )N&X-Header: foo=one; bar=two; baz=three
x-headerr   ))r   one)bartwor  threez X-Header: foo; bar=one; baz=two
))r   r,   )r  r  )r  r  "X-Header: foo; bar="one"; baz=two
)r3   r   r	  
get_paramsr6   s      r:   test_get_paramszTestMessageAPI.test_get_params  s    '57 7
3>>>,,===	? 	? 	?'/1 1
3>>>,,888	: 	: 	:
3>>T"""'13 3
3>>>,,888	: 	: 	: 	: 	:r<   c                 ~    t                      }d|d<   |                     |                    d          d           d S )Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"rE   boundaryCPIMSSMTPC06p5f3tG)r   r3   rJ   ri   s     r:   test_get_param_liberalz%TestMessageAPI.test_get_param_liberal  s>    ii^Nz224HIIIIIr<   c                    | j         }t          j        d          } ||                    dd          d            ||                    dd          d             ||                    d          d            t          j        d          } ||                    dd          d	            ||                    dd          d
            ||                    dd          d           d S )Nr  r  r  r  r  quuzr  r   r,   r  r  r3   r   r	  rJ   r6   s      r:   test_get_paramzTestMessageAPI.test_get_param  s   '57 7
3==z=22E:::
3==
=33T:::
3==  $''''13 3
3==z=22B777
3==z=22E:::
3==z=22E:::::r<   c                     |                      d          }|                     |                    d                              d          d           d S )Nz
msg_22.txtr   namez
wibble.JPG)r4   r3   r[   rJ   ri   s     r:   'test_get_param_funky_continuation_linesz6TestMessageAPI.test_get_param_funky_continuation_lines  sI    ll<((++55f==|LLLLLr<   c                     t          j        d          }|                     |                    d          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"r  ri   s     r:   #test_get_param_with_semis_in_quotesz2TestMessageAPI.test_get_param_with_semis_in_quotes  ss    'CE Ev..0CDDDvu==.	0 	0 	0 	0 	0r<   c                     t          j        d          }|                     |                    d          d           t          j        d          }|                     |                    d          d           d S )Nz5Content-Type: foo; bar*0="baz\"foobar"; bar*1="\"baz"r  zbaz"foobar"bazr  ri   s     r:   test_get_param_with_quotesz)TestMessageAPI.test_get_param_with_quotes  s|    'EG Gu--/?@@@'KM Mu--/?@@@@@r<   c                     t          j        d          }|                     d|           |                     d|           |                     d|           |                     d|           d S )NzHeader: existsr   r   HEADERheaderx)r   r	  r   assertNotInri   s     r:   test_field_containmentz%TestMessageAPI.test_field_containment  sk    '(899h$$$h$$$h$$$C(((((r<   c                 <   | j         }t                      }|                    dd            ||                    d          d           |                    dd            ||                    d          d            ||                    dd          d            ||                                g d            ||                    d          g d	           |                    dd
d            ||                    dd          d
           d S )NrB   iso-2022-jp
importance
high valueFr-  "high value")r@   r,   )rB   r8  )r9  r:  )r<  )rB   z"iso-2022-jp")r9  r;  ziso-9999-xxzX-Jimmyr  )r3   r   	set_paramrJ   r  r6   s      r:   test_set_paramzTestMessageAPI.test_set_param  sE   iii///
3==##]333lL111
3==&&555
3==u=55~FFF
3>> < < < 	= 	= 	= 	3>>%>(( +G +G +G 	H 	H 	H 	iyAAA
3==9=55}EEEEEr<   c                    | j         }|                     d          } ||                                g d           |                    d          }|                    d            ||                                ddg           |                    d|            ||                                ddd|fg           d S )N
msg_05.txt)multipart/reportr,   )report-typedelivery-statusr"  %D1690A7AC1.996856090/mail.example.comrC  rA  rE  )r3   r4   r  rJ   	del_paramr=  )r7   r8   r9   old_vals       r:   test_del_paramzTestMessageAPI.test_del_param  s    ll<((
3>>C C C	D 	D 	D --..m$$$
3>>$AC	D 	D 	D 	mW---
3>>$AG$&	' 	' 	' 	' 	'r<   c                     t                      }|                    ddd           |                    dd           |                     |d         d           d S )NContent-Disposition
attachmentbud.giffilenamerO  content-dispositionr   
add_headerrG  r3   ri   s     r:   test_del_param_on_other_headerz-TestMessageAPI.test_del_param_on_other_header  s[    ii,lYOOOj"788823\BBBBBr<   c                 N    t                      }|                    dd           d S )NrO  rP  )r   rG  ri   s     r:   $test_del_param_on_nonexistent_headerz3TestMessageAPI.test_del_param_on_nonexistent_header  s&    iij"788888r<   c                     t                      }|                    ddd           |d         }|                    dd           |                     |d         |           d S )NrE   r@   rW   rB   foobarr  rQ  )r7   r9   existing_headers      r:   test_del_nonexistent_paramz)TestMessageAPI.test_del_nonexistent_param  sd    ii~|WEEEn-h~666^,o>>>>>r<   c                 ^   | j         }t                      }|                     t          |j        d           |                    d            ||d         d           |                    dd            ||d         d           |                    d            ||d         d           d S )	Nr   r@   rA   rB   rO   rP   z	text/htmlztext/html; charset="us-ascii")r3   r   r   
ValueErrorset_typer=  r6   s      r:   test_set_typezTestMessageAPI.test_set_type  s    ii*clF;;;\"""
3~---i,,,
3~ @AAA[!!!
3~ ?@@@@@r<   c                     t                      }d|d<   |                    dd           |                     |d         d           d S )Nr@   zX-Content-Typeapplication/octet-streamzx-content-type)r   r]  r3   ri   s     r:   test_set_type_on_other_headerz,TestMessageAPI.test_set_type_on_other_header  sO    ii ,/1ABBB-.0JKKKKKr<   c                 r    t                      }|                     |                                d           d S )Nr@   )r   r3   rI   ri   s     r:   test_get_content_type_missingz,TestMessageAPI.test_get_content_type_missing  s3    ii--//>>>>>r<   c                     t                      }|                    d           |                     |                                d           d S )Nmessage/rfc822)r   set_default_typer3   rI   ri   s     r:   /test_get_content_type_missing_with_default_typez>TestMessageAPI.test_get_content_type_missing_with_default_type#  sI    ii-...--//1ABBBBBr<   c                     |                      d          }|                     |                    d                                          d           d S )N
msg_30.txtr   re  r4   r3   r[   rI   ri   s     r:   +test_get_content_type_from_message_implicitz:TestMessageAPI.test_get_content_type_from_message_implicit(  R    ll<((++<<>>)	+ 	+ 	+ 	+ 	+r<   c                     |                      d          }|                     |                    d                                          d           d S )N
msg_28.txtr   re  rj  ri   s     r:   +test_get_content_type_from_message_explicitz:TestMessageAPI.test_get_content_type_from_message_explicit-  rl  r<   c                     |                      d          }|                     |                                d           d S )Nr   r@   r4   r3   rI   ri   s     r:   6test_get_content_type_from_message_text_plain_implicitzETestMessageAPI.test_get_content_type_from_message_text_plain_implicit2  ;    ll<((--//>>>>>r<   c                     |                      d          }|                     |                                d           d S )Nr   r@   rq  ri   s     r:   6test_get_content_type_from_message_text_plain_explicitzETestMessageAPI.test_get_content_type_from_message_text_plain_explicit6  rs  r<   c                 r    t                      }|                     |                                d           d S )Nr   r   r3   get_content_maintyperi   s     r:   !test_get_content_maintype_missingz0TestMessageAPI.test_get_content_maintype_missing:  s3    ii1133V<<<<<r<   c                     t                      }|                    d           |                     |                                d           d S )Nre  message)r   rf  r3   rx  ri   s     r:   3test_get_content_maintype_missing_with_default_typezBTestMessageAPI.test_get_content_maintype_missing_with_default_type>  sH    ii-...1133Y?????r<   c                     |                      d          }|                     |                    d                                          d           d S )Nri  r   r{  r4   r3   r[   rx  ri   s     r:   /test_get_content_maintype_from_message_implicitz>TestMessageAPI.test_get_content_maintype_from_message_implicitC  G    ll<((++@@BBINNNNNr<   c                     |                      d          }|                     |                    d                                          d           d S )Nrn  r   r{  r~  ri   s     r:   /test_get_content_maintype_from_message_explicitz>TestMessageAPI.test_get_content_maintype_from_message_explicitG  r  r<   c                     |                      d          }|                     |                                d           d S )Nr   r   r4   r3   rx  ri   s     r:   :test_get_content_maintype_from_message_text_plain_implicitzITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitK  ;    ll<((1133V<<<<<r<   c                     |                      d          }|                     |                                d           d S )Nr   r   r  ri   s     r:   :test_get_content_maintype_from_message_text_plain_explicitzITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitO  r  r<   c                 r    t                      }|                     |                                d           d S )Nplainr   r3   get_content_subtyperi   s     r:    test_get_content_subtype_missingz/TestMessageAPI.test_get_content_subtype_missingS  s3    ii0022G<<<<<r<   c                     t                      }|                    d           |                     |                                d           d S )Nre  rfc822)r   rf  r3   r  ri   s     r:   2test_get_content_subtype_missing_with_default_typezATestMessageAPI.test_get_content_subtype_missing_with_default_typeW  sH    ii-...0022H=====r<   c                     |                      d          }|                     |                    d                                          d           d S )Nri  r   r  r4   r3   r[   r  ri   s     r:   .test_get_content_subtype_from_message_implicitz=TestMessageAPI.test_get_content_subtype_from_message_implicit\  G    ll<((++??AA8LLLLLr<   c                     |                      d          }|                     |                    d                                          d           d S )Nrn  r   r  r  ri   s     r:   .test_get_content_subtype_from_message_explicitz=TestMessageAPI.test_get_content_subtype_from_message_explicit`  r  r<   c                     |                      d          }|                     |                                d           d S )Nr   r  r4   r3   r  ri   s     r:   9test_get_content_subtype_from_message_text_plain_implicitzHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitd  ;    ll<((0022G<<<<<r<   c                     |                      d          }|                     |                                d           d S )Nr   r  r  ri   s     r:   9test_get_content_subtype_from_message_text_plain_explicitzHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicith  r  r<   c                 |    t                      }d|d<   |                     |                                d           d S )Nno-slash-in-this-stringrE   r   rw  ri   s     r:   test_get_content_maintype_errorz.TestMessageAPI.test_get_content_maintype_errorl  s=    ii7N1133V<<<<<r<   c                 |    t                      }d|d<   |                     |                                d           d S )Nr  rE   r  r  ri   s     r:   test_get_content_subtype_errorz-TestMessageAPI.test_get_content_subtype_errorq  s=    ii7N0022G<<<<<r<   c                    | j         }t                      }|                    dd           |                    dd           |                    dd            ||                                g d            ||                                g d           |                    dd	            ||                                g d            ||                                g d
           |                    dd           |                    dd            ||                                g d            ||                                g d           |                     t          |j        dd           d S )NFirstOneSecondTwoThirdThree)r  r  r  )r  r  r  Twenty)r  r  r  ElevenOne Hundred)r  r  r  r  )r  r  r  r  FourthMissing)r3   r   rR  keysvaluesreplace_headerr   KeyErrorr6   s      r:   test_replace_headerz"TestMessageAPI.test_replace_headerv  sx   iiw&&&x'''w(((
388::333444
3::<<0001118X...
388::333444
3::<<333444w)))7M222
388::<<<===
3::<<EEEFFF(C$6)LLLLLr<   c                    t                      }|                     |                                           |                    ddd           |                     |                                d           |                    dd           |                     |                                d           |                    dd           |                     |                                d           d S )NrK  rL  z
random.avirN  inlineInlinE)r   assertIsNoneget_content_dispositionrR  r3   r  ri   s     r:   test_get_content_dispositionz+TestMessageAPI.test_get_content_disposition  s    ii#5577888,l , 	 	. 	. 	.4466EEE0(;;;4466AAA0(;;;4466AAAAAr<   c                    d}t                      }d|d<   d|d<   |                    |           |                     |                    d          d           |                     |j        d	         t          j                   d S )
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midirA   rX   rC   TrY   s    . pr   )r   rS   r3   r[   assertIsInstancedefectsr    InvalidBase64CharactersDefectr7   xr9   s      r:   test_broken_base64_payloadz)TestMessageAPI.test_broken_base64_payload  s    &ii,N+3'(557	9 	9 	9 	ck!n$B	D 	D 	D 	D 	Dr<   c                     d}t                      }d|d<   d|d<   |                    |           |                     |                    d          t	          |d                     d S )	Nu   this is a bröken thing to dor@   rA   ra   rC   TrY   zraw-unicode-escape)r   rS   r3   r[   r  r  s      r:   test_broken_unicode_payloadz*TestMessageAPI.test_broken_unicode_payload  sy     .ii*N+1'(55q"677	9 	9 	9 	9 	9r<   c                     d                     d          }t                      }d|d<   d|d<   ||_        |                     |                    d          |           d S )	Nu#   this is a quéstionable thing to dorW   text/plain; charset="utf-8"rA   ra   rC   TrY   )r   r   _payloadr3   r[   r  s      r:   test_questionable_bytes_payloadz.TestMessageAPI.test_questionable_bytes_payload  sf     288AAii;N+1'(55q99999r<   c                     t                      }|                    ddd           |                     d|d                    d S )NrK  rL  rM  rN  zattachment; filename="bud.gif"r   rR  r3   ri   s     r:   test_ascii_add_headerz$TestMessageAPI.test_ascii_add_header  s\    ii,l ) 	 	+ 	+ 	+9%&	( 	( 	( 	( 	(r<   c                     t                      }|                    ddd           |                     d|d                    d S )NrK  rL     Fußballer.pptrN  z/attachment; filename*=utf-8''Fu%C3%9Fballer.pptr  ri   s     r:   test_noascii_add_headerz&TestMessageAPI.test_noascii_add_header  s\    ii,l% 	 	' 	' 	'?%&	( 	( 	( 	( 	(r<   c                     t                      }|                    ddd           |                     d|d                    d S )NrK  rL  )r>   r,   r  rN  z1attachment; filename*=iso-8859-1''Fu%DFballer.pptr  ri   s     r:   #test_nonascii_add_header_via_triplez2TestMessageAPI.test_nonascii_add_header_via_triple  s\    ii,l9 	 	; 	; 	;A%&	( 	( 	( 	( 	(r<   c                     t                      }|                    ddd           |                     d|d                    d S )NrK  rL  zwindows [filename].pptrN  z-attachment; filename="windows [filename].ppt"r  ri   s     r:   #test_ascii_add_header_with_tspecialz2TestMessageAPI.test_ascii_add_header_with_tspecial  s\    ii,l- 	 	/ 	/ 	/;%&	( 	( 	( 	( 	(r<   c                     t                      }|                    ddd           |                     d|d                    d S )NrK  rL  u   Fußballer [filename].pptrN  z@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptr  ri   s     r:   &test_nonascii_add_header_with_tspecialz5TestMessageAPI.test_nonascii_add_header_with_tspecial  s\    ii,l0 	 	2 	2 	2N%&	( 	( 	( 	( 	(r<   c                     dD ]`}t                      }d|z  |d<   d|d<   |                    d           |                     |                    d          d	d
|z             ad S )Nlatin-1r   text/plain; charset=%srA   rD   rC   s   foo=e6=96=87barTrY   	   foo文bar1get_payload returns wrong result with charset %s.rh   r7   rB   r9   s      r:   test_binary_quopri_payloadz)TestMessageAPI.test_binary_quopri_payload  s    + 	O 	OG))C":W"DC/AC+,OO.///t,,%CgMO O O O	O 	Or<   c                     dD ]`}t                      }d|z  |d<   d|d<   |                    d           |                     |                    d          d	d
|z             ad S )Nr  r  rA   rX   rC   s   Zm9v5paHYmFyTrY   r  r  rh   r  s      r:   test_binary_base64_payloadz)TestMessageAPI.test_binary_base64_payload  s    + 	O 	OG))C":W"DC/7C+,OOO,,,t,,%CgMO O O O	O 	Or<   c           
         dD ]}dD ]~}t                      }d|z  |d<   ||d<   |                    d           |                     |                    d          d	t	          d
                              ||                     d S )Nr  r   r  rA   rC   s    begin 666 -
)9F]OYI:'8F%R
 
end
TrY   r  )z!get_payload returns wrong result z"with charset {0} and encoding {1}.)r   rS   r3   r[   r   format)r7   rB   r   r9   s       r:   test_binary_uuencode_payloadz+TestMessageAPI.test_binary_uuencode_payload  s    + 	3 	3GF 
3 
3ii&>&HN#3;/0 GHHH  OO4O00) ? @ @w113 3 3 3
3	3 	3r<   c                     t                      }|                    ddd            |                     d|d                    d S )NrK  r  )foo_barzinline; foo-barr  ri   s     r:   $test_add_header_with_name_only_paramz3TestMessageAPI.test_add_header_with_name_only_param   sG    ii,hEEE*C0E,FGGGGGr<   c                     t                      }|                    dd            |                     d|d                    d S )NzX-Statusr,   r  ri   s     r:   test_add_header_with_no_valuez,TestMessageAPI.test_add_header_with_no_value  s?    iiz4(((S_-----r<   c                     t                      }t          d          |d<   |                     t          j        |j                   d S Nzdummy
X-Injected-Header: testDummy)r   r   r   r    r   r   ri   s     r:   (test_embedded_header_via_Header_rejectedz7TestMessageAPI.test_embedded_header_via_Header_rejected  s>    ii>??G&13=AAAAAr<   c                 v    t                      }d|d<   |                     t          j        |j                   d S r  )r   r   r    r   r   ri   s     r:   (test_embedded_header_via_string_rejectedz7TestMessageAPI.test_embedded_header_via_string_rejected  s5    ii7G&13=AAAAAr<   c                     t          d          }d|d<   |                     t          |          t          j        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   r3   r   r   r   r7   r   s     r:   -test_unicode_header_defaults_to_utf8_encodingz<TestMessageAPI.test_unicode_header_defaults_to_utf8_encoding  sU    W )Q 1 ! ! 	 	 	 	 	r<   c                     t          d          }|                     t          |          t          j        d                     d S )Nu   É testabc
z            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: base64

            w4kgdGVzdGFiYwo=
            r  r  s     r:   +test_unicode_body_defaults_to_utf8_encodingz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encoding#  sL    ^$$Q 1 ! ! 	 	 	 	 	r<   N)Y__name__
__module____qualname__r;   rM   rQ   rT   r^   rc   re   rj   rq   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r   r$  r(  r+  r/  r1  r6  r>  rI  rS  rU  rZ  r^  ra  rc  rg  rk  ro  rr  ru  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r<   r:   r/   r/   :   si       , , ,A A A4B B BH H H: : := = == = =0 0 0
4 4 4; ; ;"	5 	5 	5. . .+ + +8 8 8,= = =
2 
2 
2	2 	2 	2@ @ @,	1 	1 	19 9 9  
! 
! 
!3 3 31 1 14 4 4,4 4 44 4 46 6 61 1 13 3 33 3 31 1 1
3 3 3: : :"J J J
; ; ;$M M M
0 0 0A A A) ) )F F F"' ' '"C C C9 9 9
? ? ?	A 	A 	AL L L? ? ?C C C
+ + +
+ + +
? ? ?? ? ?= = =@ @ @
O O OO O O= = == = == = => > >
M M MM M M= = == = == = =
= = =
M M M"	B 	B 	B
D 
D 
D	9 	9 	9: : :( ( (( ( (( ( (( ( (( ( (	O 	O 	O	O 	O 	O3 3 3H H H
. . .B B B
B B B
  	 	 	 	 	r<   r/   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestEncodersc                 r   t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          j        j                            |          }|                                }|                    d          }|                     t          d |D                       d           d S )N
python.gifrbr+   c                 ,    g | ]}t          |          S r|   )lenr   r  s     r:   r   z;TestEncoders.test_EncodersEncode_base64.<locals>.<listcomp>9  s    !:!:!:a3q66!:!:!:r<   L   )
r'   r   r   mimeimager   r[   r   assertLessEqualmax)r7   r   bindatamimedbase64edr   s         r:   test_EncodersEncode_base64z'TestEncoders.test_EncodersEncode_base642  s    lD)) 	 RggiiG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 
 **733$$&&t$$S!:!:5!:!:!:;;R@@@@@   266c                 ~    | j         }t                      }|                    d            ||d         d           d S )NrO   rC   7bit)r3   r   rH   r6   s      r:   test_encode_empty_payloadz&TestEncoders.test_encode_empty_payload;  sC    ii
###
3*+V44444r<   c                     | j         }t          d          } ||d         d           t          d          } ||d         d           t          dd          } ||d         d           d S )	Nhello worldrC   r  u   hello ø worldrX   r>   _charsetrD   )r3   r   r6   s      r:   test_default_ctezTestEncoders.test_default_cteA  s    }%%
3*+V444)**
3*+X666)LAAA
3*+-?@@@@@r<   c                     | j         }t          dd          } ||d         d            ||                                t          j        d                     d S )Nu   文
euc-jpr  rC   r  z            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r3   r   r   r   r   r6   s      r:   test_encode7or8bitzTestEncoders.test_encode7or8bitM  sq     w222
3*+V444
3==??HO -   	 	 	 	 	r<   c                     t          ddd          }|                     t          |          t          j        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  ri   s     r:   test_qp_encode_latin1z"TestEncoders.test_qp_encode_latin1\  sP    |V\::S8? 4 $ $ 	 	 	 	 	r<   c                     t          ddd          }|                     t          |          t          j        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  ri   s     r:   test_qp_encode_non_latin1z&TestEncoders.test_qp_encode_non_latin1f  sP    z6<88S8? 4 $ $ 	 	 	 	 	r<   N)	r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r  0  st        A A A5 5 5
A 
A 
A    	 	 	 	 	r<   r  c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*dS ))TestLongHeadersNc                     | j         }t          j        d          }t                      }t	          |          }|                    |            ||                                d           d S )NzSubject: bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text

test
)ndiffAssertEqualr   r	  r   r   r   r   r7   r8   r9   sfpr   s        r:   test_split_long_continuationz,TestLongHeaders.test_split_long_continuationw  ss    "' )   jjcNN			#
3<<>>  	 	 	 	 	r<   c                     | j         }d}t          |d          } ||                                d           t          |                    dd                    } ||                                d           d S )Nzbug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text	continuation_wsr-   zbug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)r  r   r   r   r7   r8   hstrhs       r:   ,test_another_long_almost_unsplittable_headerz<TestLongHeaders.test_another_long_almost_unsplittable_header  s    " 4...
188::  	 	 	 4<<c**++
188::  	 	 	 	 	r<   c                    | j         }t          d          }t          d          }t          d          }d}d}d}t          ||d          }|                    ||           |                    ||           t	                      }	||	d<   t                      }
t          |
          }|                    |	            ||
                                d	            ||	                    d
          d           d S )Nr>   rs   rW      Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an sdlndischen Wandgemlden vorbei, gegen die rotierenden Klingen befrdert. ;   Finanni metropole se hroutily pod tlakem jejich dvtipu..    正確に言うと翻訳はされていません。一部はドイツ語ですが、あとはでたらめです。実際には「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   r   r   r   )r7   r8   r   czutf8g_headcz_head	utf8_headr"  r9   r  s              r:   test_long_nonstringz#TestLongHeaders.test_long_nonstring  s   "L!!\""w$$0	 61)444	"	D!!!iiIjjcNN			#
3<<>>  	 	 	 	188r8"" %1 	2 	2 	2 	2 	2r<   c                 r    | j         }t          dd          } ||                                d           d S )Niwasnipoop; giraffes="very-long-necked-animals"; spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"X-Foobar-Spoink-Defrobnitr(  jwasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r  r   r   r7   r8   r"  s      r:   test_long_header_encodez'TestLongHeaders.test_long_header_encode  sV    " O:< < < 	188:: > 	? 	? 	? 	? 	?r<   c                 t    | j         }t          ddd          } ||                                d           d S )Nr4  r5  r  r)  r  r6  r7  r8  s      r:   <test_long_header_encode_with_tab_continuation_is_just_a_hintzLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hint  sY    " O:#') ) ) 	188:: > 	? 	? 	? 	? 	?r<   c                 t    | j         }t          ddd          } ||                                d           d S )Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r5  r  r;  zjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r7  r8  s      r:   -test_long_header_encode_with_tab_continuationz=TestLongHeaders.test_long_header_encode_with_tab_continuation  s^    " O:#') ) ) 	188:: ? 	@ 	@ 	@ 	@ 	@r<   c                 v    t          dd          }|                     |                                d           d S )N   文r  =?iso-2022-jp?b?GyRCSjgbKEI=?=r   r3   r   r7   r"  s     r:   0test_header_encode_with_different_output_charsetz@TestLongHeaders.test_header_encode_with_different_output_charset  s6    5(##%EFFFFFr<   c                     t          d                    d          d          }d}|                     |                                |           d S )Ns6   test-ja Ƥ줿᡼ϻʲԤξǧԤäƤޤr  z=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r   rZ   r3   r   )r7   r"  ress      r:   5test_long_header_encode_with_different_output_charsetzETestLongHeaders.test_long_header_encode_with_different_output_charset  sV     $ %+F8$4$4h@ @7 	S)))))r<   c                     | j         }t          d          }d|d<   t                      }t          |          }|                    |            ||                                d           d S )Nr,   r4  r5  zContent-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   r   r   r  s        r:   test_header_splitterz$TestLongHeaders.test_header_splitter  sx    "rllH 	'( jjcNN			#
3<<>>  	 	 	 	 	r<   c                 l   | j         }t                      }d|d<   t                              d t	          d          D                       |d<   |                    d           t                      }t          |          }|                    |            ||	                                d           d S )Ntest@dom.ainr   c              3       K   | ]	}d |z  V  
dS )z<%d@dom.ain>Nr|   )r   is     r:   	<genexpr>z@TestLongHeaders.test_no_semis_header_splitter.<locals>.<genexpr>  s'      &M&Ma~'9&M&M&M&M&M&Mr<   
   
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   rangerS   r   r   r   r   r  s        r:   test_no_semis_header_splitterz-TestLongHeaders.test_no_semis_header_splitter  s    "ii$F!JJ&M&M599&M&M&MMMLjjcNN			#
3<<>>  		 		 		 		 		r<   c                 n    | j         }t          d          } ||                                d           d S )NzSubject: 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_itselfzSubject: 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_itselfr7  r8  s      r:   "test_last_split_chunk_does_not_fitz2TestLongHeaders.test_last_split_chunk_does_not_fit!  S    "    	188:: b 	c 	c 	c 	c 	cr<   c                 n    | 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_itselfr7  r8  s      r:   >test_splittable_leading_char_followed_by_overlong_unsplittablezNTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplittable*  rW  r<   c                 n    | 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_itselfr7  r8  s      r:   Gtest_multiple_splittable_leading_char_followed_by_overlong_unsplittablezWTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplittable3  rW  r<   c                 n    | j         }t          d          } ||                                d           d S )NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;r7  r8  s      r:   1test_trailing_splittable_on_overlong_unsplittablezATestLongHeaders.test_trailing_splittable_on_overlong_unsplittable<  sK    " * + +
188:: * 	+ 	+ 	+ 	+ 	+r<   c                 n    | 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; r7  r8  s      r:   Itest_trailing_splittable_on_overlong_unsplittable_with_leading_splittablezYTestLongHeaders.test_trailing_splittable_on_overlong_unsplittable_with_leading_splittableC  sS    " + , , 	188:: Z 	[ 	[ 	[ 	[ 	[r<   c                 n    | 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 foldedr7  r8  s      r:   5test_long_header_with_multiple_sequential_split_charszETestLongHeaders.test_long_header_with_multiple_sequential_split_charsL  sN    " F G G
188:: ) 	* 	* 	* 	* 	*r<   c                 n    | j         }t          d          } ||                                d           d S )NKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr7  r8  s      r:   :test_splitter_split_on_punctuation_only_if_fws_with_headerzJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headerT  sK    " + , ,
188:: 2 	3 	3 	3 	3 	3r<   c                 n    | j         }t          d          } ||                                d           d S )Nzthis 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;zthis 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;r7  r8  s      r:   Dtest_leading_splittable_in_the_middle_just_before_overlong_last_partzTTestLongHeaders.test_leading_splittable_in_the_middle_just_before_overlong_last_part[  sS    " * + + 	188:: Y 	Z 	Z 	Z 	Z 	Zr<   c                 n    | j         }t          d          } ||                                d           d S )NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself r7  r8  s      r:   /test_overlong_last_part_followed_by_split_pointz?TestLongHeaders.test_overlong_last_part_followed_by_split_pointf  sK    " * + +
188:: = 	> 	> 	> 	> 	>r<   c                 n    | j         }t          d          } ||                                d           d S )Nzthis_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; zthis_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; r7  r8  s      r:   @test_multiline_with_overlong_parts_separated_by_two_split_pointszPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointsm  S    " + , , 	188:: Z 	[ 	[ 	[ 	[ 	[r<   c                 n    | j         }t          d          } ||                                d           d S )Nzthis 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; zthis 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; r7  r8  s      r:   >test_multiline_with_overlong_last_part_followed_by_split_pointzNTestLongHeaders.test_multiline_with_overlong_last_part_followed_by_split_pointx  rk  r<   c                 F   | j         }t                      }d|d<   t                              dgdz            |d<   |                    d           t                      }t          |          }|                    |            ||                                d           d S )NrK  r   z<foo@dom.ain>  rO  rP  rQ  zFrom: 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   rR  r   rS   r   r   r   r   r  s        r:   %test_long_header_with_whitespace_runsz5TestLongHeaders.test_long_header_with_whitespace_runs  s    "ii$F!JJ(9':R'?@@LjjcNN			#
3<<>>  		 		 		 		 		r<   c                 L   | j         }t                      }d|d<   t                              dgdz            dz   |d<   |                    d           t                      }t          |          }|                    |            ||                                d           d S )	NrK  r   z<foo@dom.ain>rO  z; abcrP  rQ  zFrom: 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

Testro  r  s        r:   'test_long_run_with_semi_header_splitterz7TestLongHeaders.test_long_run_with_semi_header_splitter  s    "ii$F!JJ'82'=>>HLjjcNN			#
3<<>>  		 		 		 		 		r<   c                    | j         }t                      }d|d<   d|d<   |                    d           t                      }t	          |          }|                    |            ||                                d           d S )NrK  r   rc  rP  rQ  zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r  r   rS   r   r   r   r   r  s        r:   .test_splitter_split_on_punctuation_only_if_fwsz>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fws  s    "ii$F+LjjcNN			#
3<<>>  		 		 		 		 		r<   c                     | j         }d}t          |          } ||                                d           t          d          } ||                                d           d S )Nz\References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr7  r   s       r:   test_no_split_long_headerz)TestLongHeaders.test_no_split_long_header  ss    "(4LL 	188:: U 	V 	V 	V 8
188::ijjjjjr<   c                 v    | j         }d}t          |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)r7  r   s       r:   "test_splitting_multiple_long_linesz2TestLongHeaders.test_splitting_multiple_long_lines  sR    "
 4...
188:: ) 	* 	* 	* 	* 	*r<   c                 z    | j         }d}t          |ddd          } ||                                d           d S )Nzfrom 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 -0400N   Receivedr  )r+  r)  r  zfrom 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 -0400r7  r   s       r:   &test_splitting_first_line_only_is_longz6TestLongHeaders.test_splitting_first_line_only_is_long  sd    "A
 4BJ#') ) )
188:: A 	B 	B 	B 	B 	Br<   c                 H   | j         }t                      }t          ddd          }|                    d            ||                    d          d           ||d<    ||                    d	          d
            ||                    d	          d           d S )NzBritische Regierung gibtr>   r  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,  r   r   )r7   r8   r9   r"  s       r:   test_long_8bit_headerz%TestLongHeaders.test_long_8bit_header  s    "ii-| )+ + +	DEEE
188r8"" %, 	- 	- 	- I
3==b=)) , 	 	 	
 	3==a=(( + 	 	 	 	 	r<   c                    | j         }t                      }d}||d<    ||                    d          d           t                      }t          |d          |d<    ||                    d          d           d S )Nuh   Britische Regierung gibt grünes Licht für Offshore-Windkraftprojekte <a-very-long-address@example.com>zReply-Tor{  r  zReply-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   r   r   )r7   r8   r9   header_strings       r:    test_long_8bit_header_no_charsetz0TestLongHeaders.test_long_8bit_header_no_charset  s    "ii= (J
3==b=)) , 	 	 	
 ii -79 9 9J
3==b=)) , 	 	 	 	 	r<   c                 ~    | j         }d}t                      }||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   r{  r  zTo: "Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,
 "Someone Test #B" <someone@umich.edu>,
 "Someone Test #C" <someone@eecs.umich.edu>,
 "Someone Test #D" <someone@eecs.umich.edu>

)r  r   r   )r7   r8   r   r9   s       r:   test_long_to_headerz#TestLongHeaders.test_long_to_header  sX    ";
 iiD	
3==b=)) , 	 	 	 	 	r<   c                     | j         }d}t          |          }|                    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,  r   r7   r8   r   r"  s       r:   test_long_line_after_appendz+TestLongHeaders.test_long_line_after_append#  s`    "W1II	$%%%
188r8"" % 	 	 	 	 	r<   c                     | 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  s       r:   test_shorter_line_with_appendz-TestLongHeaders.test_shorter_line_with_append,  s]    "%1II	4555
188::F	H 	H 	H 	H 	Hr<   c                     | j         }d}d}t          |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. r>   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_?=r7  )r7   r8   fngsr"  s        r:   test_long_field_namez$TestLongHeaders.test_long_field_name4  se    "0 2|444
188r8"" %A 	B 	B 	B 	B 	Br<   c                     d}t                      }t          |d          |d<   ||d<   |                     |                    d          d           d S )	Nzfrom 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  
Received-1
Received-2r{  r  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  r   r7   r"  r9   s      r:   test_long_received_headerz)TestLongHeaders.test_long_received_headerC  sl    / ii"1d;;;LLcmmm<< ? 	 	 	 	 	r<   c                     d}t                      }t          |dd          |d<   ||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")r  r  r;  r  r{  r  a#  Received-1: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
Received-2: 
 <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")

r  r  s      r:   test_string_headerinst_eqz)TestLongHeaders.test_string_headerinst_eqU  su    1 ii"1,379 9 9LLcmmm<< ? 	 	 	 	 	r<   c                     | j         }t                      }d}||d<   t          |d          |d<   d|z   |d<    ||                    d          d	           d S )
NziVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1zFace-2r(  r-   zFace-3r{  r  a  Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

r  r   r   r   )r7   r8   r9   ts       r:   -test_long_unbreakable_lines_with_continuationz=TestLongHeaders.test_long_unbreakable_lines_with_continuationh  s~    "iiM Hqh777HaH 	3==b=)) , 	 	 	 	 	r<   c                     | j         }d}t          j        |          } ||                    d          d           d S )NzReceived: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700r{  r  zReceived: 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  r   r	  r   r7   r8   r   r9   s       r:   "test_another_long_multiline_headerz2TestLongHeaders.test_another_long_multiline_header  sV    "/ '**
3==b=)) , 	 	 	 	 	r<   c                     | j         }d}t                      }||d<   t          |d          |d<    ||                    d          d           d S )NzList-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>Listr(  r{  r  a_  List: List-Unsubscribe:
 <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
List: List-Unsubscribe:
 <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>

r  )r7   r8   r"  r9   s       r:   %test_long_lines_with_different_headerz5TestLongHeaders.test_long_lines_with_different_header  sn    "% iiFQF333F
3==b=)) , 	 	 	 	 	r<   c                     t          t          j        d          dd          }|                     |                                dz   t          j        d          dz              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 worksrW   rQ  )rB   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   r3   r   rC  s     r:   *test_long_rfc2047_header_with_embedded_fwsz:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws  s    8? $, - - #%' ' ' 	D(/ ;7 +8 +8 9=	+= 	> 	> 	> 	> 	>r<   )+r  r  r  maxDiffr  r#  r2  r9  r<  r>  rD  rG  rI  rT  rV  rY  r[  r]  r_  ra  rd  rf  rh  rj  rm  rp  rr  rt  rw  ry  r}  r  r  r  r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r  s  s       G  (  "42 42 42l? ? ?? ? ?@ @ @G G G* * *  (	 	 	 c c cc c cc c c+ + +[ [ [* * *3 3 3	Z 	Z 	Z> > >	[ 	[ 	[	[ 	[ 	[	 	 	"	 	 	"	 	 	$
k 
k 
k* * *,B B B   (  *  "  H H HB B B  $  &  0    &> > > > >r<   r  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestFromManglingc                 t    t                      | _        d| j        d<   | j                            d           d S )Nzaaa@bbb.orgr   z(From the desk of A.A.A.:
Blah blah blah
)r   r9   rS   r7   s    r:   setUpzTestFromMangling.setUp  sB    99(  	 	 	 	 	r<   c                     t                      }t          |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   r   r9   r3   r   r7   r   r   s      r:   test_mangled_fromz"TestFromMangling.test_mangled_from  sb    JJad+++			$( ( 	 	 	 	 	r<   c                     t                      }t          |d          }|                    | j                   |                     |                                d           d S )NFr  z;From: aaa@bbb.org

From the desk of A.A.A.:
Blah blah blah
r  r  s      r:   test_dont_mangle_fromz&TestFromMangling.test_dont_mangle_from  sb    JJae,,,			$( ( 	 	 	 	 	r<   c                 ^   t                      }t          |d          }t          j        t	          j        d                    }|                    |           |                     t          d |	                                
                    d          D                       d           d S )NTr  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                 <    g | ]}|                     d           dS )z>From r   )r   r  s     r:   r   zLTestFromMangling.test_mangle_from_in_preamble_and_epilog.<locals>.<listcomp>  s8     = = =A%&\\(%;%;=a = = =r<   r+   r   )r   r   r   r	  r   r   r   r3   r  r   r   )r7   r   r   r9   s       r:   'test_mangle_from_in_preamble_and_epilogz8TestFromMangling.test_mangle_from_in_preamble_and_epilog  s    JJad+++' 9 ) )    	
		# = =););D)A)A = = = > >?@	B 	B 	B 	B 	Br<   c                 @   t          j        d                              d          }t          j        |dz             }t                      }t          |d          }|                    |           |                     |	                                |dz              d S )Nz            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: 8bit
            From: aaa@bbb.org

        rW   s   From Rölli
Tr  s   >From Rölli
)
r   r   r   r   r   r   r   r   r3   r   )r7   r   r9   br   s        r:    test_mangled_from_with_bad_bytesz1TestFromMangling.test_mangled_from_with_bad_bytes  s     "   VG__ 	 &v0F'FGGII14000			#v0G'GHHHHHr<   c                 |    t          j        d                              d          }t          j        |          }d S )Nu               From: aperson@example.com
            Content-Type: multipart/mixed; boundary="1"
            Content-Transfer-Encoding: È
        rW   )r   r   r   r   r   )r7   r   r9   s      r:   $test_multipart_with_bad_bytes_in_ctez5TestFromMangling.test_multipart_with_bad_bytes_in_cte  s>     "   VG__	 	
 &v..r<   N)	r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r    st          	 	 		 	 	B B B.I I I/ / / / /r<   r  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestMIMEAudioc                     t          d| d          5 }|                                | _        d d d            n# 1 swxY w Y   t          | j                  | _        d S )Nzsndhdr.r  )r'   r   
_audiodatar   _aur7   extr   s      r:   _make_audiozTestMIMEAudio._make_audio   s    ooot,, 	( ggiiDO	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(T_--   :>>c                     ddddd                                 D ]P\  }}|                     |           ||n|}|                     | j                                        d|            Qd S )Nzx-aiffzx-wavbasic)aifcaiffwavauzaudio/)r   r  r3   r  rI   r7   r  subtypes      r:   test_guess_minor_typez#TestMIMEAudio.test_guess_minor_type  s    	
 

 %''	N 	NLC S!!!$_cc'GTX6688:L7:L:LMMMM	N 	Nr<   c                     |                      d           | j                                        }|                     t	          j        t          |d                    | j                   d S )Nr  r   )r  r  r[   r3   rX   decodebytesr  r  r7   payloads     r:   test_encodingzTestMIMEAudio.test_encoding  sg    (&&((+E'7,C,CDD	* 	* 	* 	* 	*r<   c                     |                      d           t          | j        d          }|                     |                                d           d S )Nr  fishz
audio/fish)r  r   r  r3   rI   )r7   r  s     r:   test_checkSetMinorz TestMIMEAudio.test_checkSetMinor  sO    t//,,..=====r<   c                    |                      d           | j        }| j                            ddd            || j        d         d            || j                            d          d	d
g            || j                            dd          d           g } || j                            dd          d           |                     | j                            d|d          |           |                     | j                            d|          |           |                     | j                            d|d          |           d S )Nr  rK  rL  	sndhdr.aurN  rP  z attachment; filename="sndhdr.au"r  rL  r,   )rO  r  rO  r,   r   failobjr   rX  )r  r3   r  rR  r  rJ   assertIsr7   r8   missings      r:   test_add_headerzTestMIMEAudio.test_add_header  s   1<%0 	 	2 	2 	2
48)*-	/ 	/ 	/
48&;<< 9:	< 	< 	<
48j1FGG	 	 	
48l3HII2NNNdh((7( ) * *+2	4 	4 	4 	dh((7;;WEEEdh((w08 ) : :;B	D 	D 	D 	D 	Dr<   N)r  r  r  r  r  r  r  r  r|   r<   r:   r  r    sg        . . .
	N 	N 	N* * *> > >
D D D D Dr<   r  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestMIMEImagec                     t          d| d          5 }|                                | _        d d d            n# 1 swxY w Y   t          | j                  | _        d S )Nzpython.r  )r'   r   _imgdatar   _imr  s      r:   _make_imagezTestMIMEImage._make_image4  s    ooot,, 	&GGIIDM	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&T]++r  c                     d d d dd d d d ddd d d d                                 D ]P\  }}|                     |           ||n|}|                     | j                                        d|            Qd S )Njpegrastrgb)bmpexrgifjpgpbmpgmpngppmrassgitiffwebpxbmzimage/)r   r  r3   r  rI   r  s      r:   r  z#TestMIMEImage.test_guess_minor_type9  s    
 
 %''	N 	NLC S!!!$_cc'GTX6688:L7:L:LMMMM#	N 	Nr<   c                     |                      d           | j                                        }|                     t	          j        t          |d                    | j                   d S )Nr  r   )r  r  r[   r3   rX   r  r  r  r  s     r:   r  zTestMIMEImage.test_encodingM  sg    (&&((+E'7,C,CDD	( 	( 	( 	( 	(r<   c                     |                      d           t          | j        d          }|                     |                                d           d S )Nr  r  z
image/fish)r  r   r  r3   rI   )r7   ims     r:   r  z TestMIMEImage.test_checkSetMinorS  sO    t}f--,,..=====r<   c                    |                      d           | j        }| j                            ddd            || j        d         d            || j                            d          d	d
g            || j                            dd          d           g } || j                            dd          d           |                     | j                            d|d          |           |                     | j                            d|          |           |                     | j                            d|d          |           d S )Nr  rK  rL  r   rN  rP  z%attachment; filename="dingusfish.gif"r  r  )rO  r   rO  r,   r   r  rX  )r  r3   r  rR  r  rJ   r  r  s      r:   r  zTestMIMEImage.test_add_headerX  s   1<%5 	 	7 	7 	7
48)*2	4 	4 	4
48&;<< >?	A 	A 	A
48j1FGG	 	 	
48l3HII2NNNdh((0E ) G GHO	Q 	Q 	Q 	dh((7;;WEEEdh((w08 ) : :;B	D 	D 	D 	D 	Dr<   N)r  r  r  r  r  r  r  r  r|   r<   r:   r  r  3  sg        , , ,
N N N(( ( (> > >
D D D D Dr<   r  c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	TestMIMEApplicationc                     | j         }t          d          } ||                                d            ||d         d           d S )N   r`  rC   rX   )r3   r   rI   r6   s      r:   test_headersz TestMIMEApplication.test_headerso  sU    9::
3!!#=>>>
3*+X66666r<   c                     | j         }d}t          |          } ||                                                                d            ||                    d          |           d S )Nr  z+vv8/f7/TrY   )r3   r   r[   strip)r7   r8   	bytesdatar9   s       r:   	test_bodyzTestMIMEApplication.test_bodyu  sj    /	i((
3??""$$j111
3??$?''33333r<   c                    d}t          |t          j                  }|                     |                                dt          |          z             |                     |                    d          |           |                     |d         d           t                      }t          |          }|                    |           |	                                }t          j        |          }|                     |                                dt          |          z             |                     |                    d          |           |                     |d         d           d S )Nr  _encoder   �TrY   rF   ra   )r   r   encode_7or8bitr3   r[   r  r   r   r   r   r   r   r7   r   r9   r   r   wireformmsg2s          r:   $test_binary_body_with_encode_7or8bitz8TestMIMEApplication.test_binary_body_with_encode_7or8bit}  s=   /	i(2IJJJ**Hs9~~,EFFF55yAAA896BBBII1			#::<<'11**Hs9~~,EFFF)))66	BBB9:FCCCCCr<   c                 |   d}t          |t          j                  }|                     |                                dt          |          z             |                     |                    d          |           t                      }t          |          }|                    |           |	                                }t          j        |          }|                     |                                dt          |          z             |                     |                    d          |           d S )Nr  r  r  TrY   )r   r   encode_noopr3   r[   r  r   r   r   r   r   r   r  s          r:   !test_binary_body_with_encode_noopz5TestMIMEApplication.test_binary_body_with_encode_noop  s    0	i(2FGGG**Hs9~~,EFFF55yAAAII1			#::<<'11**Hs9~~,EFFF)))66	BBBBBr<   c                    d}t          |t          j                  }|                     |                    d          |           t                      }t          |          }|                    |           |                                }t          j
        |          }|                     |                    d          |           d S )Ns   r  TrY   )r   r   r  r3   r[   r   r   r   r   r   r   r  s          r:   0test_binary_body_with_unicode_linend_encode_noopzDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noop  s    3	i(2FGGG55yAAAII1			#::<<'11)))66	BBBBBr<   c                    d}t          |t          j                  }|                     |                                d           |                     |                    d          |           |                     |d         d           t                      }t          |          }|                    |           |                                }t          j
        |          }|                     |                                d           |                     |                    d          |           |                     |d         d           d S )Ns    r  z=FA=FB=FC=FD=FE=FF=20TrY   rF   rD   )r   r   encode_quoprir3   r[   r   r   r   r   r   r   r  s          r:   #test_binary_body_with_encode_quopriz7TestMIMEApplication.test_binary_body_with_encode_quopri  s+   0	i(2HIII**,CDDD55yAAA89;MNNNII1			#::<<'11**,CDDD)))66	BBB9:<NOOOOOr<   c                 <   d}t          |t          j                  }|                     |                                d           |                     |                    d          |           t                      }t          |          }|                    |           |                                }t          j
        |          }|                     |                                d           |                     |                    d          |           d S )Nr  r  z	+vv8/f7/
TrY   )r   r   encode_base64r3   r[   r   r   r   r   r   r   r  s          r:   #test_binary_body_with_encode_base64z7TestMIMEApplication.test_binary_body_with_encode_base64  s    /	i(2HIII**L99955yAAAII1			#::<<'11**L999)))66	BBBBBr<   N)
r  r  r  r  r  r
  r  r  r  r  r|   r<   r:   r  r  n  s        7 7 74 4 4D D D"C C C"
C 
C 
CP P P C C C C Cr<   r  c                   j    e Zd Zd Zd Zd Zd Zd Zd Zd Z	 e
j        d          d	             Zd
S )TestMIMETextc                 .    t          d          | _        d S Nhello there)r   _msgr  s    r:   r  zTestMIMEText.setUp  s    ]++			r<   c                 f   | j         } || j                                        d            || j                            d          d           g }|                     | j                            d|          |           |                     | j                            d|d          |           d S )Nr@   rB   rO   rX  r  )r3   r  rI   rJ   r  r  s      r:   
test_typeszTestMIMEText.test_types  s    
49%%''666
49y)):666di))(G<<gFFFdi)))WX)NN	 	 	 	 	r<   c                     |                      | j                                        d           |                     | j                                                   d S r  )r3   r  r[   assertFalseis_multipartr  s    r:   test_payloadzTestMIMEText.test_payload  sN    ..00-@@@//1122222r<   c                    | j         }t          dd          } ||                                j        d            ||d         d           t	          d          }d |_        t          d|          } ||                                j        d            ||d         d            ||                                d           d S )Nr  rO   r  rA   rP   rW   r  )r3   r   rG   rK   r
   rb   r[   rL   s       r:   test_charsetzTestMIMEText.test_charset  s    }z:::
3??*J777
3~ @AAA'"" $}w777
3??*G444
3~ =>>>
3??m,,,,,r<   c                     | j         }t          dd          } ||                                j        d            ||d         d           d S )Nr  rO   r  rA   rP   )r3   r   rG   rK   r6   s      r:   test_7bit_inputzTestMIMEText.test_7bit_input  sY    }z:::
3??*J777
3~ @AAAAAr<   c                     | j         }t          d          } ||                                d            ||d         d           |                     d|                                           d S )Nr  rO   rA   rP   )r3   r   rG   r   r   r6   s      r:   test_7bit_input_no_charsetz'TestMIMEText.test_7bit_input_no_charset  sm    }%%
3??j)))
3~ @AAAmS]]__55555r<   c                 
   d}| j         }t          |d          } ||                                j        d            ||d         d            ||                    d          |                    d                     d S )N   кирилицаrW   r  rA   r  TrY   )r3   r   rG   output_charsetr[   r   )r7   teststrr8   r9   s       r:   test_utf8_inputzTestMIMEText.test_utf8_input  s    Dw111
3??+W555
3~ =>>>
3??$?'')@)@AAAAAr<   zBcan't fix because of backward compat in email5, will fix in email6c                 L    d}|                      t          t          |           d S )Nr)  )r   UnicodeEncodeErrorr   )r7   r+  s     r:   test_utf8_input_no_charsetz'TestMIMEText.test_utf8_input_no_charset  s)     E,h@@@@@r<   N)r  r  r  r  r  r!  r#  r%  r'  r,  unittestskipr/  r|   r<   r:   r  r    s        , , ,  3 3 3- - -B B B6 6 6B B B X]   A A A A Ar<   r  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestMultipartc                    t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          ddd          }t          |d          }|                    d	d
d           t          d          }|                    |           |                    |           d|d<   d|d<   d|d<   d}t          j        |          }|d         dk    rt          j	        }nt          j
        }|dk    rd}	nd}	d|	|dz  fz  }
t          j        dt          j        |                    |
z   |d<   || _        || _        || _        d S )Nr  r  	multipartmixedr   r"  r   )r*  rP  rL  rN  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  g4FcpAr   -+z %s%04d$   z%a, %d %b %Y %H:%M:%SDate)r'   r   r   r   rR  r   ro   time	localtimetimezonealtzonestrftimer  r  _txt)r7   r   r]   	containerr  intronow	timetupletzsecssigntzoffsets              r:   r  zTestMultipart.setUp  s   lD)) 	R7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	['JGGG	$%5666."2 	 	4 	4 	4   
 	8	&E	$9	) N3''	R=A]FF\FA::DDDfrk22 M#N3! !#+,	& 				r  c                    | j         }| j        }| j        }|                     |                                            ||                                d            |t          |                                          d            |t          |j        d           |                    d          }|                    d          }| 	                    || j
                   | 	                    || j                    ||                                ||g           |                     |                                           |                     |                                           d S )Nrl   r   r   r   )r3   r   r  r   r   rI   r  r[   
IndexErrorr  rB  r  r  )r7   r8   raisesr   m0m1s         r:   test_hierarchyzTestMultipart.test_hierarchy+  s:   "I(()))
1!2333
3q}}###z1=!,,,]]1]]1b$)$$$b$(###
1==??RH%%%**+++**+++++r<   c                     d}t                                          |          }|                     ||                                           d S )NzContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY


--BOUNDARY--
)r   r   r  r   )r7   r   r9   s      r:   test_empty_multipart_idempotentz-TestMultipart.test_empty_multipart_idempotent=  sF     hh%%dCMMOO44444r<   c                     t          dd          }d|d<   d|d<   d|d<   |                    d	           |                     |                                d
           d S )Nr5  r6  	A subjectr  aperson@dom.ainr   bperson@dom.ainr   r   zContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain

--BOUNDARY

--BOUNDARY--
)r   r   r  r   r7   outers     r:   /test_no_parts_in_a_multipart_with_none_epiloguez=TestMultipart.test_no_parts_in_a_multipart_with_none_epilogueN  st    g..&i'd)f:&&&eoo// 
2 
	 
	 
	 
	 
	r<   c                     t          dd          }d|d<   d|d<   d|d<   d	|_        d	|_        |                    d
           |                     |                                d           d S )Nr5  r6  rS  r  rT  r   rU  r   r,   r   zContent-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY

--BOUNDARY--
)r   preambleepiloguer   r  r   rV  s     r:   0test_no_parts_in_a_multipart_with_empty_epiloguez>TestMultipart.test_no_parts_in_a_multipart_with_empty_epilogue`  s    g..&i'd)f:&&&eoo// 2 	 	 	 	 	r<   c                     | j         }t          dd          }d|d<   d|d<   d|d<   |                    d	           t          d
          }|                    |            ||                                d           d S )Nr5  r6  rS  r  rT  r   rU  r   r   r
    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   ro   r   r7   r8   rW  r9   s       r:   test_one_part_in_a_multipartz*TestMultipart.test_one_part_in_a_multipartu  s    "g..&i'd)f:&&&}%%S
5??  	 	 	 	 	r<   c                    | j         }t          dd          }d|d<   d|d<   d|d<   d	|_        t          d
          }|                    |           |                    d            ||                                d           d S )Nr5  r6  rS  r  rT  r   rU  r   r,   r
  r   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   rZ  r   ro   r   r   r_  s       r:   1test_seq_parts_in_a_multipart_with_empty_preamblez?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamble  s    "g..&i'd)f}%%S:&&&
5??  	 	 	 	 	r<   c                    | j         }t          dd          }d|d<   d|d<   d|d<   d |_        t          d	          }|                    |           |                    d
            ||                                d           d S Nr5  r6  rS  r  rT  r   rU  r   r
  r   r^  rb  r_  s       r:   0test_seq_parts_in_a_multipart_with_none_preamblez>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamble      "g..&i'd)f}%%S:&&&
5??  	 	 	 	 	r<   c                    | j         }t          dd          }d|d<   d|d<   d|d<   d |_        t          d	          }|                    |           |                    d
            ||                                d           d S re  r  r   r[  r   ro   r   r   r_  s       r:   0test_seq_parts_in_a_multipart_with_none_epiloguez>TestMultipart.test_seq_parts_in_a_multipart_with_none_epilogue  rg  r<   c                    | j         }t          dd          }d|d<   d|d<   d|d<   d	|_        t          d
          }|                    |           |                    d            ||                                d           d S )Nr5  r6  rS  r  rT  r   rU  r   r,   r
  r   r^  ri  r_  s       r:   1test_seq_parts_in_a_multipart_with_empty_epiloguez?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epilogue  s    "g..&i'd)f}%%S:&&&
5??  	 	 	 	 	r<   c                    | j         }t          dd          }d|d<   d|d<   d|d<   d	|_        t          d
          }|                    |           |                    d            ||                                d           d S )Nr5  r6  rS  r  rT  r   rU  r   r+   r
  r   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--

ri  r_  s       r:   .test_seq_parts_in_a_multipart_with_nl_epiloguez<TestMultipart.test_seq_parts_in_a_multipart_with_nl_epilogue  s    "g..&i'd)f}%%S:&&&
5??  	 	 	 	 	r<   c                 v   | j         }|                     d          } |t          |                                          d           |                    d          } ||                                d            |t          |                                          d           |                                D ]~} ||                                d            |t          |                                          d           |                    d          } ||                                d           d S )N
msg_36.txtr   r   zmultipart/alternativezmessage/external-bodyr   r@   )r3   r4   r  r[   rI   )r7   r8   r9   msg1r   
subsubparts         r:   test_message_external_bodyz(TestMultipart.test_message_external_body  s3   ll<((
3s  !!1%%%q!!
4  ""$;<<<
3t!!""A&&&'')) 	< 	<GBw''))+BCCCBs7&&(())1--- ,,Q//JBz**,,l;;;;		< 	<r<   c                     |                      d          }|                     t          |                                          d           d S )Nz
msg_37.txtr   )r4   r3   r  r[   ri   s     r:   test_double_boundaryz"TestMultipart.test_double_boundary#  sC     ll<((S__..//33333r<   c                     | j         }|                     d          }t                      }t          j        ||            ||                                d           d S )Nz
msg_38.txtzmultipart/mixed
    multipart/mixed
        multipart/alternative
            text/plain
        text/plain
    text/plain
    text/plain
r  r4   r   r!   
_structurer   r7   r8   r9   r  s       r:   )test_nested_inner_contains_outer_boundaryz7TestMultipart.test_nested_inner_contains_outer_boundary*  sf    "
 ll<((jjS#&&&
3<<>>  	 	 	 	 	r<   c                     | j         }|                     d          }t                      }t          j        ||            ||                                d           d S )Nz
msg_39.txtzmultipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
rw  ry  s       r:   test_nested_with_same_boundaryz,TestMultipart.test_nested_with_same_boundary=  sf    " ll<((jjS#&&&
3<<>>  	 	 	 	 	r<   c                     |                      d          }|                     |                                d           d S )Nz
msg_40.txtzMIME-Version: 1.0
Content-Type: text/html; boundary="--961284236552522269"

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

<html></html>

----961284236552522269--
)r4   r3   r   ri   s     r:   test_boundary_in_non_multipartz,TestMultipart.test_boundary_in_non_multipartN  sD    ll<(( + 	 	 	 	 	r<   c                    | j         }t          j        d          }|                     |                                            ||                                d            |t          |                                          d           d S )NzMIME-Version: 1.0
Content-Type: multipart/mixed; boundary="    XXXX"

--    XXXX
Content-Type: text/plain


--    XXXX
Content-Type: text/plain

--    XXXX--
z    XXXXr   )r3   r   r	  r   r   r   r  r[   r6   s      r:    test_boundary_with_leading_spacez.TestMultipart.test_boundary_with_leading_space]  s    ' )   	((**+++
3z***
3s  !!1%%%%%r<   c                     t                                          d          }|                     |                    d                                          d           d S )NzContent-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   r   r3   r[   r  s     r:   &test_boundary_without_trailing_newlinez4TestMultipart.test_boundary_without_trailing_newlinep  sV    HH 
# 
$ 
$ 	q))5577DDDDDr<   c                 z    t          dd          }|                     |j        t          j        j                   d S )Nr5  r6  )r   r  r   r   compat32r  s     r:   test_mimebase_default_policyz*TestMultipart.test_mimebase_default_policy~  s2    ['**ah 566666r<   c                     t          ddt          j        j                  }|                     |j        t          j        j                   d S )Nr5  r6  r   )r   r   r   defaultr  r  s     r:   test_mimebase_custom_policyz)TestMultipart.test_mimebase_custom_policy  s<    ['%,2FGGGah 455555r<   N)r  r  r  r  rO  rQ  rX  r\  r`  rc  rf  rj  rl  rn  rs  ru  rz  r|  r~  r  r  r  r  r|   r<   r:   r3  r3    sD       " " "H, , ,$5 5 5"  $  *  2  8  6  6  6  6< < <4 4 4  &  "  & & &&E E E7 7 76 6 6 6 6r<   r3  c                   |    e Zd Zd Zd Zd Z ej        d          Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd ZdS )TestNonConformantc                     | j         }|                     d          } ||                                d            ||                                d            ||                                d           d S )Nz
msg_14.txtr@   r   r  )r3   r4   rI   rx  r  r6   s      r:   test_parse_missing_minor_typez/TestNonConformant.test_parse_missing_minor_type  s{    ll<((
3!!<000
3##%%v...
3""$$g.....r<   c                 F   |                      d          }|                    d          }|                     t          |d                     |                     t          |j                  d           |                     |j        d         t          j	                   d S )N
msg_15.txtr   r  r   )
r4   r[   r   hasattrr3   r  r  r  r    StartBoundaryNotFoundDefect)r7   r9   inners      r:   test_same_boundary_inner_outerz0TestNonConformant.test_same_boundary_inner_outer  s    ll<((""y11222U]++Q///emA.$@	B 	B 	B 	B 	Br<   c                    |                      d          }|                     |                                t                     |                     t          |j                  d           |                     |j        d         t          j                   |                     |j        d         t          j	                   d S )Nz
msg_25.txtr   r   r   )
r4   r  r[   r   r3   r  r  r    NoBoundaryInMultipartDefect!MultipartInvariantViolationDefectri   s     r:   test_multipart_no_boundaryz,TestNonConformant.test_multipart_no_boundary  s    ll<((coo//555S[))1---ck!n$@	B 	B 	Bck!n$F	H 	H 	H 	H 	Hr<   a^          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                    |                      | j                            d                    }|                     t	          |j                  d           |                     |j        d         t          j                   d S )Nz"
Content-Transfer-Encoding: base64r   r   )	_str_msgmultipart_msgr  r3   r  r  r  r    -InvalidMultipartContentTransferEncodingDefectri   s     r:   test_multipart_invalid_ctez,TestNonConformant.test_multipart_invalid_cte  s    mm%%&KLLN NS[))1---ck!n@	B 	B 	B 	B 	Br<   c                     |                      | j                            d                    }|                     t	          |j                  d           d S )Nr,   r   r  r  r  r3   r  r  ri   s     r:   test_multipart_no_cte_no_defectz1TestNonConformant.test_multipart_no_cte_no_defect  sJ    mmD.55b99::S[))1-----r<   c                     dD ]j}|                      | j                            d                    |                              }|                     t	          |j                  d           kd S )N)r  ra   BINaryz
Content-Transfer-Encoding: {}r   r  )r7   r   r9   s      r:   "test_multipart_valid_cte_no_defectz4TestNonConformant.test_multipart_valid_cte_no_defect  s~    - 	2 	2C--"))5<<SAAC CD DC S--q1111		2 	2r<   c                 `   | j         }| j        }t                      }d|d<    ||                                d            ||                                d            ||                                d           |d= d|d<    ||                                d            ||                                d            ||                                d           t                      }t          |          }|                    |            ||	                                d           d S )Nr   rE   r  r@   rA   r   zContent-Type: foo

)
r3   r  r   rx  r  rI   r   r   r   r   )r7   r8   neqr9   r   r   s         r:   test_invalid_content_typez+TestNonConformant.test_invalid_content_type  s/   #ii$N
3##%%v...
3""$$g...
3!!<000#N
3##%%v...
3""$$g...
3!!<000JJaLL			#AJJLL122222r<   c                 z    | j         }|                     d          } ||                                d           d S )N
msg_31.txtzm--BOUNDARY
Content-Type: text/plain

message 1

--BOUNDARY
Content-Type: text/plain

message 2

--BOUNDARY--
)r  r4   r[   r6   s      r:   test_no_start_boundaryz(TestNonConformant.test_no_start_boundary  sJ    "ll<((
3??  	 	 	 	 	r<   c                 z    | j         }|                     d          } ||                                d           d S )Nz
msg_35.txtzFrom: aperson@dom.ain
To: bperson@dom.ain
Subject: here's something interesting

counter to RFC 2822, there's no separating newline here
)r  r4   r   r6   s      r:   test_no_separating_blank_linez/TestNonConformant.test_no_separating_blank_line  sH    "ll<((
3==??  	 	 	 	 	r<   c                 r   |                      d          }|                     t          |d                     |                     t	          |j                  d           |                     |j        d         t          j                   |                     |j        d         t          j	                   d S )Nz
msg_41.txtr  r   r   r   )
r4   r   r  r3   r  r  r  r    r  r  ri   s     r:   test_lying_multipartz&TestNonConformant.test_lying_multipart	  s    ll<((Y//000S[))1---ck!n$@	B 	B 	Bck!n$F	H 	H 	H 	H 	Hr<   c                 &   |                      d          }|                    d                              d          }|                     t          |j                  d           |                     |j        d         t          j                   d S )Nz
msg_42.txtr   r   )r4   r[   r3   r  r  r  r    r  )r7   rW  bads      r:   test_missing_start_boundaryz-TestNonConformant.test_missing_start_boundary	  s    \** ""..q11S[))1---ck!n$@	B 	B 	B 	B 	Br<   c                 z   | j         }d}t          j        |          } ||                                dg            ||                                d            |t          |j                  d           |                     |j        t          j	        g            ||j        d         j
        d           d S )Nz Line 1
Subject: test

bodyr  bodyr   r   z Line 1
)r3   r   r	  r  r[   r  r  assertDefectsEqualr    #FirstHeaderLineIsContinuationDefectliner  s       r:   &test_first_line_is_continuation_headerz8TestNonConformant.test_first_line_is_continuation_header	  s    ,'**
388::	{###
3??f%%%
3s{Q"("L!M	O 	O 	O
3;q>,,,,,r<   c                    |                      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  r3   r  r[   r  r  r     MissingHeaderBodySeparatorDefectri   s     r:   "test_missing_header_body_separatorz4TestNonConformant.test_missing_header_body_separator)	  s    
 mmIJJi[111**,JKKK!'!H I	K 	K 	K 	K 	Kr<   N)r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r    s       / / /B B BH H H $HO %  M0B B B. . .
2 2 23 3 3*  "	 	 	H H HB B B 	- 	- 	-	K 	K 	K 	K 	Kr<   r  c                   n    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )TestRFC2047c                     | j         }d}t          |          } ||g d           t          |          } |t          |          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
   rksmrgszmac-iceland)s    baz foo bar Nr  u+   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?=)r3   r   r   r   r  r   r7   r8   r   dhr   s        r:   test_rfc2047_multilinez"TestRFC2047.test_rfc2047_multiline7	  s    /1
2 5 5 5 	6 	6 	6
 R
3v;;D	F 	F 	Ffmmrm:: =  	! 	! 	! 	! 	!r<   c                     | j         }d}t          |          } ||ddg           t          t          |                    } ||d           d S )Nz0=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>)s   Andrr>   )s    Pirard <pirard@dom.ain>Nu   André Pirard <pirard@dom.ain>r3   r   r   r   r  s        r:   test_whitespace_keeper_unicodez*TestRFC2047.test_whitespace_keeper_unicodeH	  si    >1
2+35 	6 	6 	6[__%%
6566666r<   c                     | j         }d}t          |          } ||g d           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 foxr>   )s    jumped over the N)s   lazy dogr>   z,The quick brown fox jumped over the lazy dogr  )r7   r8   r   r  hus        r:    test_whitespace_keeper_unicode_2z,TestRFC2047.test_whitespace_keeper_unicode_2Q	  ss    e1
2 K K K 	L 	L 	LR!!
2=>>>>>r<   c                 X    d}t          |          }|                     |g d           d S )Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord))s   SmN   r>   )s   rgN   r>   )s   sbordNr   r3   r7   r   r  s      r:   test_rfc2047_missing_whitespacez+TestRFC2047.test_rfc2047_missing_whitespaceZ	  sG    A1 0 0 0 	1 	1 	1 	1 	1r<   c                 X    d}t          |          }|                     |g d           d S )Nz7Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord))s   Sm Nr  )s    rg Nr  )s    sbordNr  r  s      r:   test_rfc2047_with_whitespacez(TestRFC2047.test_rfc2047_with_whitespacea	  sG    E1 1 1 1 	2 	2 	2 	2 	2r<   c                 x    d}g d}|D ]0\  }}t          ||z            }|                     ||dfg           1d S )Nz=?iso-8859-1?B?%s?=))zdm==   v)zdm=r  )dmr  )zdmk=   vi)dmkr  r>   r  )r7   r   r]   qar  s         r:   test_rfc2047_B_bad_paddingz&TestRFC2047.test_rfc2047_B_bad_paddingh	  si    !    	6 	6DAqq1u%%BR1l"3!45555	6 	6r<   c                 R    d}|                      t          |          dg           d S )Nz=?iso-8859-1?Q?andr=e9=zz?=)s   andr=zzr>   r3   r   r7   r   s     r:   test_rfc2047_Q_invalid_digitsz)TestRFC2047.test_rfc2047_Q_invalid_digitsr	  s9    )q))78	: 	: 	: 	: 	:r<   c                 T    d}|                      t          |          g d           d S )Nz(=?ISO-8859-1?Q?a?=))   (N   ar>      )Nr  r  s     r:   test_rfc2047_rfc2047_1z"TestRFC2047.test_rfc2047_rfc2047_1x	  sA    "q))>>>	@ 	@ 	@ 	@ 	@r<   c                 T    d}|                      t          |          g d           d S )Nz(=?ISO-8859-1?Q?a?= b))r  r  )s    b)Nr  r  s     r:   test_rfc2047_rfc2047_2z"TestRFC2047.test_rfc2047_rfc2047_2~	  A    $q))@@@	B 	B 	B 	B 	Br<   c                 T    d}|                      t          |          g d           d S )Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)r  )s   abr>   r  r  r  s     r:   test_rfc2047_rfc2047_3z"TestRFC2047.test_rfc2047_rfc2047_3	  sA    5q))???	A 	A 	A 	A 	Ar<   c                 T    d}|                      t          |          g d           d S )Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r  r  r  s     r:   test_rfc2047_rfc2047_4z"TestRFC2047.test_rfc2047_rfc2047_4	  sA    6q))???	A 	A 	A 	A 	Ar<   c                 T    d}|                      t          |          g d           d S )Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r  r  r  s     r:   test_rfc2047_rfc2047_5az#TestRFC2047.test_rfc2047_rfc2047_5a	  sA    <q))???	A 	A 	A 	A 	Ar<   c                 T    d}|                      t          |          g d           d S )Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r  r  r  s     r:   test_rfc2047_rfc2047_5bz#TestRFC2047.test_rfc2047_rfc2047_5b	  sA    :q))???	A 	A 	A 	A 	Ar<   c                 T    d}|                      t          |          g d           d S )Nz(=?ISO-8859-1?Q?a_b?=))r  )s   a br>   r  r  r  s     r:   test_rfc2047_rfc2047_6z"TestRFC2047.test_rfc2047_rfc2047_6	  r  r<   c           	      v   d}|                      t          |          g d           |                      t          t          |                                                    |                                           |                      t          t          t          |                              d           d S )Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))r  r  )s    brs   r  z(a b))r3   r   r   r   r   r   r  s     r:   test_rfc2047_rfc2047_7z"TestRFC2047.test_rfc2047_rfc2047_7	  s    6q))  	 	 	 	]1%5%566==??KKK[q)9)9::;;WEEEEEr<   c           	         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
   "Mller T"zwindows-1252)s   <T.Mueller@xxx.com>Nr,   u   "Müller T" <T.Mueller@xxx.com>)r3   r   r   r   r   
splitlinesr   r  s     r:   test_multiline_headerz!TestRFC2047.test_multiline_header	  s    Iq))/+-	. 	. 	. 	]1%5%566==??00	2 	2 	2[q)9)9::;;:	< 	< 	< 	< 	<r<   N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r  6	  s       ! ! !"7 7 7? ? ?1 1 12 2 26 6 6: : :@ @ @B B BA A AA A AA A AA A AB B BF F F< < < < <r<   r  c                   n    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )TestMIMEMessagec                     t          dd          5 }|                                | _        d d d            d S # 1 swxY w Y   d S )N
msg_11.txtrW   r   )r'   r   _textr7   r   s     r:   r  zTestMIMEMessage.setUp	  s    lW555 	#DJ	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   9= =c                 H    |                      t          t          d           d S )Nza plain string)r   rn   r   r  s    r:   test_type_errorzTestMIMEMessage.test_type_error	  s!    )[2BCCCCCr<   c                    | j         }d}t                      }||d<   t          |          } ||                                d           |                                }|                     |t                      |t          |          d           |d         }|                     ||            ||d         |           d S )NzA sub-messager  re  r   r   subject)	r3   r   r   rI   r[   r  listr  r  )r7   r8   r  r   rr  r   s          r:   test_valid_argumentz#TestMIMEMessage.test_valid_argument	  s    !II)NN
1!1222--//gt,,,
3w<<!*gq!!!
79w'''''r<   c                     t                      }d|d<   t                      }d|d<   t          |          }|                     t          j        |j        |           d S )N	subpart 1r  z	subpart 2)r   r   r   r    MultipartConversionErrorro   )r7   rq  r	  r  s       r:   test_bad_multipartz"TestMIMEMessage.test_bad_multipart	  sV    yy%Yyy%Y&918TJJJJJr<   c                 2   t                      }d|d<   |                    d           t          |          }d|d<   t                      }t	          |          }|                    |           |                     |                                d           d S )NAn enclosed messager  !Here is the body of the message.
zThe enclosing messagezContent-Type: message/rfc822
MIME-Version: 1.0
Subject: The enclosing message

Subject: An enclosed message

Here is the body of the message.
)r   rS   r   r   r   r   r3   r   )r7   r   r  r   r   s        r:   test_generatezTestMIMEMessage.test_generate	  s    II,)	:;;;NN.)JJaLL			! ( 	 	 	 	 	r<   c                    | j         }|                     d          } ||                                d           |                                }|                     |t
                      |t          |          d           |d         }|                     |t                      ||d         d            ||                                d           d S )Nr  re  r   r   r  r  r	  )r3   r4   rI   r[   r  r   r  r   )r7   r8   r9   r  submsgs        r:   test_parse_message_rfc822z)TestMIMEMessage.test_parse_message_rfc822	  s    ll<((
3!!#3444//##gt,,,
3w<<fg...
6)3444
6!EFFFFFr<   c                 *   | j         }|                     d          } ||                                d           |                     |                                            |t          |                                          d           |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            |t          |                                          d	           |                    d          }|                     |t                      ||d
         d            ||	                    dd          d            ||	                    dd          d            |                    d          }|                     |t                      ||d         d            ||
                    d          ddg            ||	                    dd          d           |                    d	          } ||                                d           |                                }|                     |t                      |t          |          d           |d         }|                     |t                      ||                                d            ||d         d           d S )N
msg_16.txtrB  r   r   r@   a  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

r   zmessage/delivery-statusr   zoriginal-envelope-idz"0GK500B4HD0888@cougar.noc.ucla.edudnszreporting-mtar  r,   nsdactionfailedzoriginal-recipient)r  r,   )zjangel1@cougar.noc.ucla.edur,   r  zfinal-recipientre  
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r3   r4   rI   r   r   r  r[   r  r   rJ   r  r   )r7   r8   r9   r   dsn1dsn2r  rr  s           r:   test_dsnzTestMIMEMessage.test_dsn	  s   ll<((
3!!#5666((**+++
3s  !!1%%%//!$$
7##%%|444
7   # 	 	 	$ //!$$
7##%%'@AAA
3w""$$%%q))) ""1%%dG,,,
4&')MNNN
4>>%>88"===
4>>%>88$???""1%%dG,,,
4>8$$$
4??"6?77?@	B 	B 	B
4>>(+<>==rBBB//!$$
7##%%'7888%%''gt,,,
3w<<QZ
j'222
:&&((,777
:l#5	7 	7 	7 	7 	7r<   c                 D   | j         }t          dd          5 }|                                }d d d            n# 1 swxY w Y   t                      }d|d<   d|d<   d|d	<   d
|_        d|_        t          d          }t          d          }|                    ddd           |                    |           |                    |           t                      }t          |          }|                    |            ||                                |           d S )N
msg_21.txtrW   r   rT  r   rU  r   rQ  r  MIME messagezEnd of MIME message
r  r  rE   rl   r   r7  )r  r'   r   r   rZ  r[  r   rR  ro   r   r   r   r   )	r7   r8   r   r   r9   rq  r	  r  r   s	            r:   test_epiloguezTestMIMEMessage.test_epilogue.
  sD   "lW555 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	ii'F%D	I%.~'8:NNN

4

4jjcNN			#
3<<>>4        :>>c                 f   | j         }t                      }d|d<   d|d<   d|d<   d|_        d|_        t	          d	          }t	          d
          }|                    ddd           |                    |           |                    |            ||                                d           d S )NrT  r   rU  r   rQ  r  r  r,   r  r  rE   rl   r   r7  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   rZ  r[  r   rR  ro   r   )r7   r8   r9   rq  r	  s        r:   test_no_nl_preamblez#TestMIMEMessage.test_no_nl_preambleB
  s    "ii'F%D	I%~'8:NNN

4

4
3==??  	 	 	 	 	r<   c                    | j         }t          dd          5 }t          j        |          }d d d            n# 1 swxY w Y   |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            ||                                d           d S )Nri  rW   r   r   re  r   r@   r3   r'   r   message_from_filer[   get_default_typerI   r7   r8   r   r9   
container1
container2container1acontainer2as           r:   test_default_typez!TestMIMEMessage.test_default_typee
     lW555 	.)"--C	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.__Q''

:&&((*:;;;
:&&((*:;;;__Q''

:&&((*:;;;
:&&((*:;;; ,,Q//
;''))<888
;''))<888 ,,Q//
;''))<888
;''))<88888r  c                    | j         }t          dd          5 }t          j        |          }d d d            n# 1 swxY w Y   |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            ||                                d           |                    d          } ||                                d            ||                                d           d S )Nrn  rW   r   r   re  r   r@   r   r#  s           r:   .test_default_type_with_explicit_container_typez>TestMIMEMessage.test_default_type_with_explicit_container_typev
  r)  r  c                    | j         }| j        }t          dd          }d|_        t	          d          }t	          d          }t          |          }t          |          }|                    |           |                    |            ||                                d            ||                                d            ||                                d            ||                                d            ||	                    d          d           |d	= |d
= |d	= |d
=  ||                                d            ||                                d            ||                                d            ||                                d            ||	                    d          d           d S )Ndigestr   r,   
message 1

message 2
re  r   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--
rA   r?   aB  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--
)
r3   r  r   r[  r   r   ro   rI   r"  r   )r7   r8   r  rC  	subpart1a	subpart2asubpart1subpart2s           r:   test_default_type_non_parsedz,TestMIMEMessage.test_default_type_non_parsed
  s   #!(J77		]++	]++	y))y))""""""
8$$&&(8999
8$$&&(8999
8$$&&(8999
8$$&&(8999I"" % 	 	 	4 ^$^$^$^$
8$$&&(8999
8$$&&(8999
8$$&&(8999
8$$&&(8999I"" % 	 	 	 	 	r<   c                 F   | j         }t          d          }t          d          }t          ||f          } |t          |                                          d            ||                    d          |            ||                    d          |           d S )Nr,   )	_subpartsr   r   r   )r3   r   r   r  r[   )r7   r8   text1text2r9   s        r:   $test_mime_attachments_in_constructorz4TestMIMEMessage.test_mime_attachments_in_constructor
  s    uen555
3s  !!1%%%
3??1u%%%
3??1u%%%%%r<   c                 p    t                      }|                     |                                           d S rg   )r   r   r   ri   s     r:   "test_default_multipart_constructorz2TestMIMEMessage.test_default_multipart_constructor
  s/    oo((**+++++r<   c                     t                      }d|d<   d|d<   |                     |                    d          ddg           d S )Na@b.comr   c@d.comr   )r   r3   r5   ri   s     r:   test_multipart_default_policyz-TestMIMEMessage.test_multipart_default_policy
  sJ    ooD	D	T**Y	,BCCCCCr<   c                    t          t          j        j                  }d|d<   |                     t
                    5 }d|d<   d d d            n# 1 swxY w Y   |                     t          |j                  d           d S )Nr   r=  r   r>  z.There may be at most 1 To headers in a message)	r   r   r   r  r   r\  r3   r   	exception)r7   r9   cms      r:   test_multipart_custom_policyz,TestMIMEMessage.test_multipart_custom_policy
  s    5<#7888D	z** 	"b!CI	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"R\**I	K 	K 	K 	K 	Ks   AAAN)r  r  r  r  r  r  r  r
  r  r  r  r  r(  r+  r4  r9  r;  r?  rC  r|   r<   r:   r  r  	  s       # # #D D D( ( (K K K  (
G 
G 
G77 77 77r! ! !(! ! !F9 9 9"9 9 9"H H HT& & &, , ,D D DK K K K Kr<   r  c                       e Zd Zd Zd ZdS )TestNonMultipartc                 t    t          dd          }|                     |                                           d S )Nr   r  )r   r  r   ri   s     r:   "test_nonmultipart_is_not_multipartz3TestNonMultipart.test_nonmultipart_is_not_multipart
  s7    vw//))++,,,,,r<   c                     t                      }d|d<   t          dd          }|                     t          j        |j        |           d S )Nr  r  r   r  )r   r   r   r    r  ro   )r7   r9   r  s      r:   test_attach_raises_exceptionz-TestNonMultipart.test_attach_raises_exception
  sF    ii$IVW--&918SIIIIIr<   N)r  r  r  rG  rI  r|   r<   r:   rE  rE  
  s7        - - -J J J J Jr<   rE  c                       e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestIdempotentr+   c                     t          |d          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          }||fS NrW   r   r'   r   r   r	  r7   rO  r   r]   r9   s        r:   r4   zTestIdempotent._msgobj  s    h111 	R7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'--Dyr   Fc                     | j         }t                      }t          |d          }|                    ||            |||                                           d S )Nr   r  r   )r  r   r   r   r   )r7   r9   r   r   r8   r   r   s          r:   _idempotentzTestIdempotent._idempotent	  s[    "JJaa(((			#	)))
4r<   c                    | j         }|                     d          \  }} ||                                d            ||                                d            ||                                d            ||                                d         d            ||                    d          d            ||j        d             ||j        d            | 	                    ||           d S )	Nr   r@   r   r  r   )rB   rO   rB   rO   )
r3   r4   rI   rx  r  r  rJ   rZ  r[  rQ  r7   r8   r9   r   s       r:   test_parse_text_messagez&TestIdempotent.test_parse_text_message  s    LL..	T
3!!<000
3##%%v...
3""$$g...
3>>A 7888
3==##Z000
3<
3<d#####r<   c                 &   | j         }|                     d          \  }} ||                                d            ||                                d             ||                    d          d            |                     ||           d S )Nr   r@   rB   )r3   r4   rI   r  rJ   rQ  rS  s       r:   test_parse_untyped_messagez)TestIdempotent.test_parse_untyped_message  s    LL..	T
3!!<000
3>>T"""
3==##T***d#####r<   c                 b    |                      d          \  }}|                     ||           d S )Nrz   r4   rQ  r7   r9   r   s      r:   test_simple_multipartz$TestIdempotent.test_simple_multipart$  3    LL..	Td#####r<   c                 b    |                      d          \  }}|                     ||           d S )N
msg_02.txtrX  rY  s      r:   test_MIME_digestzTestIdempotent.test_MIME_digest(  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nz
msg_27.txtrX  rY  s      r:   test_long_headerzTestIdempotent.test_long_header,  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nrn  rX  rY  s      r:   "test_MIME_digest_with_part_headersz1TestIdempotent.test_MIME_digest_with_part_headers0  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )N
msg_06.txtrX  rY  s      r:   test_mixed_with_imagez$TestIdempotent.test_mixed_with_image4  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nr@  rX  rY  s      r:   test_multipart_reportz$TestIdempotent.test_multipart_report8  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nr  rX  rY  s      r:   r  zTestIdempotent.test_dsn<  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nr  rX  rY  s      r:   test_preamble_epiloguez%TestIdempotent.test_preamble_epilogue@  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nz
msg_23.txtrX  rY  s      r:   test_multipart_one_partz&TestIdempotent.test_multipart_one_partD  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nz
msg_24.txtrX  rY  s      r:   test_multipart_no_partsz&TestIdempotent.test_multipart_no_partsH  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nr  rX  rY  s      r:   r  z%TestIdempotent.test_no_start_boundaryL  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )N
msg_32.txtrX  rY  s      r:   test_rfc2231_charsetz#TestIdempotent.test_rfc2231_charsetP  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nz
msg_33.txtrX  rY  s      r:   test_more_rfc2231_parametersz+TestIdempotent.test_more_rfc2231_parametersT  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nz
msg_34.txtrX  rY  s      r:   %test_text_plain_in_a_multipart_digestz4TestIdempotent.test_text_plain_in_a_multipart_digestX  r[  r<   c                 b    |                      d          \  }}|                     ||           d S )Nzmsg_12a.txtrX  rY  s      r:   test_nested_multipart_mixedsz+TestIdempotent.test_nested_multipart_mixeds\  s3    LL//	Td#####r<   c                 b    |                      d          \  }}|                     ||           d S )Nrp  rX  rY  s      r:   %test_message_external_body_idempotentz4TestIdempotent.test_message_external_body_idempotent`  r[  r<   c                 f    |                      d          \  }}|                     ||d           d S )N
msg_43.txtTr   rX  rY  s      r:   test_message_delivery_statusz+TestIdempotent.test_message_delivery_statusd  s8    LL..	TdT22222r<   c                 b    |                      d          \  }}|                     ||           d S N
msg_45.txtrX  rY  s      r:   test_message_signed_idempotentz-TestIdempotent.test_message_signed_idempotenth  r[  r<   c                    | j         }|                     d          \  }} ||                                d           i }|                                D ]
\  }}|||<    ||d         d            ||d         d            ||j        d| j        z               ||j        | j                    |t          |                                          d           |                    d	          } ||                                d
            ||                                d| j        z              |                    d          } ||                                d
            ||                                d| j        z              |                    d          }	 ||	                                d           | 	                    |	t                     |	                                }
| 	                    |
t                      |t          |
          d           |
d	         }| 	                    |t                      ||                                d| j        z              d S )Nr@  rB  rC  rD  r"  rF  z$This is a MIME-encapsulated message.r   r   r@   zYadda yadda yaddar   r   re  )r3   r4   rI   r  rZ  r   r[  r  r[   r  r   r   )r7   r8   r9   r   paramspkpvrq  r	  msg3r  msg4s               r:   test_content_typez TestIdempotent.test_content_typel  sk   LL..	T
3!!#5666nn&& 	 	FBF2JJ
6- "3444
6*FGGG
3<?$,NOOO
3<&&&
3s  !!1%%%q!!
4  ""L111
42T\ABBBq!!
4  ""L111
42T\ABBBq!!
4  ""$4555dG,,,""$$gt,,,
3w<<qzdG,,,
42T\ABBBBBr<   c                 2   | j         }|                     d          \  }} ||                                d           |                                }|                     |t
                      |t          |          d           |d         }|                     |t                      ||                                d           |                     |                                t                      ||                                | j	                   d S )Nrd  re  r   r   r@   )
r3   r4   rI   r[   r  r   r  r   r   r   )r7   r8   r9   r   r  rq  s         r:   test_parserzTestIdempotent.test_parser  s   LL..	T
3!!#3444 //##gt,,,
3w<<qzdG,,,
4  ""L111d..00#666
4t|,,,,,r<   NF)r  r  r  r   r4   rQ  rT  rV  rZ  r^  r`  rb  re  rg  r  rj  rl  rn  r  rr  rt  rv  rx  rz  r}  r  r  r  r|   r<   r:   rK  rK  
  s       G     
$ 
$ 
$$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $$ $ $3 3 3$ $ $C C C>- - - - -r<   rK  c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z- e.j/                     e0j1        d,          d-                         Z2d. Z3d/ Z4d0 Z5d1 Z6d2 Z7d3 Z8d4 Z9d5 Z:d6 Z;d7 Z<d8 Z=d9 Z>d: Z?d; Z@d< ZAd=S )>TestMiscellaneousc                 `   t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          }t	                      }t          |d          }|                    |           |                     ||                                           d S Nr   rW   r   r   r  	r'   r   r   r	  r   r   r   r3   r   r7   r   r   r9   r   r   s         r:   test_message_from_stringz*TestMiscellaneous.test_message_from_string  s    lW555 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'--JJ aa(((			#qzz||,,,,,r   c                    t          dd          5 }|                                }|                    d           t          j        |          }t                      }t          |d          }|                    |           |                     ||	                                           d d d            d S # 1 swxY w Y   d S r  )
r'   r   seekr   r!  r   r   r   r3   r   r  s         r:   test_message_from_filez(TestMiscellaneous.test_message_from_file  s    lW555 		17799DGGAJJJ)"--C

A !!,,,AIIcNNNT1::<<000		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1 		1s   BB99B= B=c                    t          dd          5 }|                                }d d d            n# 1 swxY w Y    G d dt                    }t          j        ||          }|                     ||           t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          j        ||          }|                                D ]}|                     ||           d S )Nr   rW   r   c                       e Zd ZdS )HTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageNr  r  r  r|   r<   r:   	MyMessager            Dr<   r  r]  )r'   r   r   r   r	  r  walk)r7   r   r   r  r9   r   s         r:   #test_message_from_string_with_classz5TestMiscellaneous.test_message_from_string_with_class  s   lW555 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 'i88c9---lW555 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'i88xxzz 	6 	6G!!'95555	6 	6s   377B..B25B2c                     G d dt                     }t          dd          5 }t          j        ||          }d d d            n# 1 swxY w Y   |                     ||           t          dd          5 }t          j        ||          }d d d            n# 1 swxY w Y   |                                D ]}|                     ||           d S )Nc                       e Zd ZdS )FTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageNr  r|   r<   r:   r  r    r  r<   r  r   rW   r   r]  )r   r'   r   r!  r  r  )r7   r  r   r9   r   s        r:   !test_message_from_file_with_classz3TestMiscellaneous.test_message_from_file_with_class  sl   	 	 	 	 	 	 	 	 lW555 	9)"i88C	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9c9---lW555 	9)"i88C	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9xxzz 	6 	6G!!'95555	6 	6s#   AAA9BB"Bc                      G d dt                     }|                     d|          }|                     ||           d S )Nc                        e Zd Z fdZ xZS )STestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessagec                 H    t                                                       d S rg   )super__init__)r7   	__class__s    r:   r  z\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__  s      """""r<   )r  r  r  r  __classcell__)r  s   @r:   r  r    s8        # # # # # # # # #r<   r  zSubject: test

test)r   r  r  )r7   r  r9   s      r:   .test_custom_message_does_not_require_argumentsz@TestMiscellaneous.test_custom_message_does_not_require_arguments  s^    	# 	# 	# 	# 	# 	# 	# 	# mm3Y??c9-----r<   c                 x    t          d          }|                     t          |j                  g d           d S )Nr   )r   rB   r   r    
feedparserr   r   r!   r{  message_from_binary_filer   r!  r	  r  r   r"   r#   )
__import__r3   sorted__all__)r7   modules     r:   test__all__zTestMiscellaneous.test__all__  sL    G$$// 2 2 2 	 	 	 	 	r<   c                     t          j                     }|                     t          j        t          j        |                    d d         t          j        |          d d                    d S )N   )r=  r3   r#   	parsedate
formatdategmtimer7   rE  s     r:   test_formatdatez!TestMiscellaneous.test_formatdate  se    ikk)9#)>)>??CS))"1"-	/ 	/ 	/ 	/ 	/r<   c                     t          j                     }|                     t          j        t          j        |d                    d d         t          j        |          d d                    d S )NTr>  r  )r=  r3   r#   r  r  r>  r  s     r:   test_formatdate_localtimez+TestMiscellaneous.test_formatdate_localtime  sk    ikkOE,SDAAABB2A2FN3#	% 	% 	% 	% 	%r<   c           	      j   t          j                     }|                     t          j        |d          t          j        dt          j        |                               |                     t          j        |dd          t          j        dt          j        |                               d S )NFr  z%a, %d %b %Y %H:%M:%S -0000T)r>  usegmtz%a, %d %b %Y %H:%M:%S GMT)r=  r3   r#   r  rA  r  r  s     r:   test_formatdate_usegmtz(TestMiscellaneous.test_formatdate_usegmt  s    ikkSE222M7S9I9IJJ	L 	L 	L 	SE$???M5t{37G7GHH	J 	J 	J 	J 	Jr<   c                    g d}|D ]~}|                      |          5  |                     t          j        |                     |                     t          j        |                     d d d            n# 1 swxY w Y   |                     t          j        d                      |                     t          j        d                      d S )N)	r,   r-   0zA Complete Waste of Timez Wed, 3 Apr 2002 12.34.56.78+0800z17 June , 2022zFriday, -Nov-82 16:14:55 ESTzFriday, Nov--82 16:14:55 ESTzFriday, 19-Nov- 16:14:55 EST)dtstr)subTestr  r#   r  parsedate_tz)r7   invalid_datesr  s      r:   /test_parsedate_returns_None_for_invalid_stringszATestMiscellaneous.test_parsedate_returns_None_for_invalid_strings  s   

 

 

 # 	= 	=EE** = =!!%/%"8"8999!!%"4U";";<<<= = = = = = = = = = = = = = = 	%/$//000%,T2233333s   AA::A>	A>	c                     |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d          d           d S )NzWed, 3 Apr 2002 14:58:26 +0800
  r   r      :      r   r   r8  p  zWed,3 Apr 2002 14:58:26 +0800zWed 3 Apr 2002 14:58:26 +0800r3   r#   r  r  s    r:   test_parsedate_compactz(TestMiscellaneous.test_parsedate_compact  s    +,LMMB	D 	D 	D 	+,KLLB	D 	D 	D 	+,KLLB	D 	D 	D 	D 	Dr<   c                     | j         } |t          j        d          d            |t          j        d          d           d S )N5 Feb 2003 13:47:26 -0800
  r         /   r  r   r   r8  透zFebruary 5, 2003 13:47:26 -0800r  r7   r8   s     r:   test_parsedate_no_dayofweekz-TestMiscellaneous.test_parsedate_no_dayofweek  s^    
59::5	7 	7 	7
5?@@5	7 	7 	7 	7 	7r<   c                 V    |                      t          j        d          d           d S )NzWed, 3 Apr 2002 14:58:26+0800r  r  r  s    r:   .test_parsedate_no_space_before_positive_offsetz@TestMiscellaneous.test_parsedate_no_space_before_positive_offset"  s5    +,KLL4	6 	6 	6 	6 	6r<   c                 V    |                      t          j        d          d           d S )NzWed, 3 Apr 2002 14:58:26-0800)
r  r   r   r  r  r  r   r   r8  r  r  r  s    r:   .test_parsedate_no_space_before_negative_offsetz@TestMiscellaneous.test_parsedate_no_space_before_negative_offset&  s5    +,KLL5	7 	7 	7 	7 	7r<   c                     | j         } |t          j        d          d            |t          j        d          d           d S )Nz5 Feb 2003 13.47.26 -0800r  z5 Feb 2003 13.47 -0800)
r  r   r  r  r  r   r   r   r8  r  r  r  s     r:   %test_parsedate_accepts_time_with_dotsz7TestMiscellaneous.test_parsedate_accepts_time_with_dots+  s^    
59::5	7 	7 	7
56774	6 	6 	6 	6 	6r<   c                 V    |                      t          j        d          d           d S )NzFriday, 19-Nov-82 16:14:55 EST)
i           r  7   r   r   r8  ir  r  s    r:   test_parsedate_rfc_850z(TestMiscellaneous.test_parsedate_rfc_8502  s5    +,LMM7	9 	9 	9 	9 	9r<   c                 V    |                      t          j        d          d           d S )NzWed, 3 Apr 2002 14:58 +0800
r  r   r   r  r  r   r   r   r8  r  r  r  s    r:   test_parsedate_no_secondsz+TestMiscellaneous.test_parsedate_no_seconds6  s:    +,IJJA	C 	C 	C 	C 	Cr<   c                     |                      t          j        d          d           |                      t          j        d          d           d S )NzWed, 3 Apr 2002 14.58.26 +0800r  zWed, 3 Apr 2002 14.58 +0800r  r  r  s    r:   !test_parsedate_dot_time_delimiterz3TestMiscellaneous.test_parsedate_dot_time_delimiter:  sf    +,LMMB	D 	D 	D+,IJJA	C 	C 	C 	C 	Cr<   c           
      p   | j         }t          j        d          }t          t	          j        |                    } |t	          j        |          d d         |d d                     |t          t	          j        d|                    d           t          j        d          }t          t	          j        |d d                             } |t	          j        |          d d         |d d                     |t          t	          j        d|d d                             d           d S )Nr  r  z%Yr  	   )	r3   r#   r  intr=  mktimer>  rA  r  )r7   r8   timetupr  s       r:   +test_parsedate_acceptable_to_time_functionsz=TestMiscellaneous.test_parsedate_acceptable_to_time_functions@  s   /"=>>G$$%%
4>!RaR '"1"+...
3t}T7++,,d333$%@AAGBQBK(())
4>!RaR '"1"+...
3t}T72A2;//00$77777r<   c                     |                      t          j        d          d           |                      t          j        d          d           d S )N)
  r   r   r   r   r   r8  r8  r8  r   r   )
r  r   r   r   r   r   r8  r8  r8  i  i.)r3   r#   	mktime_tzr  s    r:   test_mktime_tzz TestMiscellaneous.test_mktime_tzK  sm     *9 : :;<	> 	> 	> *< = =>C	E 	E 	E 	E 	Er<   c                     |                      t          j        d          t          j        d                     |                      t          j        d          t          j        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 -0800Nr  r  s    r:   test_parsedate_y2kz$TestMiscellaneous.test_parsedate_y2kQ  s     	+,FGG+,HII	K 	K 	K+,FGG+,HII	K 	K 	K 	K 	Kr<   c                     |                      t          j        d          d           |                      t          j        t          j        d                    d           d S )Nz<>r,   r,   r,   r3   r#   	parseaddr
formataddrr  s    r:   test_parseaddr_emptyz&TestMiscellaneous.test_parseaddr_empty^  sS    ..999)%/$*?*?@@"EEEEEr<   c                     |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d          d           d S )Nza@b@cr  za@b.c@cza@172.17.0.1@cr3   r#   r  r  s    r:   test_parseaddr_multiple_domainsz1TestMiscellaneous.test_parseaddr_multiple_domainsb  s    OG$$	
 	
 	
 	OI&&	
 	
 	
 	O,--	
 	
 	
 	
 	
r<   c                 V    |                      t          j        d          d           d S )N)zA Silly Personperson@dom.ainzA Silly Person <person@dom.ain>r3   r#   r  r  s    r:   test_noquote_dumpz#TestMiscellaneous.test_noquote_dumpp  s6    ABB-	/ 	/ 	/ 	/ 	/r<   c                 *   |                      t          j        d          d           |                      t          j        d          d           d}d}|                      t          j        t          j        ||f                    ||f           d S )N)zA (Very) Silly Personr  z("A (Very) Silly Person" <person@dom.ain>z*"A \(Very\) Silly Person" <person@dom.ain>zA \(Special\) Personr  r3   r#   r  r  r7   r  r  s      r:   test_escape_dumpz"TestMiscellaneous.test_escape_dumpu  s    HII7	9 	9 	9 	OIJJ7	9 	9 	9 $)91a&)A)ABBQFKKKKKr<   c                     |                      t          j        d          d           d}d}|                      t          j        t          j        ||f                    ||f           d S )N)Arthur \Backslash\ Foobarr  z."Arthur \\Backslash\\ Foobar" <person@dom.ain>r	  r  r  r  s      r:   test_escape_backslashesz)TestMiscellaneous.test_escape_backslashes  sq    MNN=	? 	? 	? ))91a&)A)ABBQFKKKKKr<   c                     d}d}d}d}|                      t          j        ||f          |           |                      t          j        ||fd          |           d S )N   Häns Würstr  -=?utf-8?b?SMOkbnMgV8O8cnN0?= <person@dom.ain>z0=?iso-8859-1?q?H=E4ns_W=FCrst?= <person@dom.ain>r>   r  )r7   r*  addrutf8_base64latin1_quopris        r:   test_quotes_unicode_namesz+TestMiscellaneous.test_quotes_unicode_names  ss    %EJ)4,77EEE)4,EE	 	 	 	 	r<   c                     d}d}d}d G fdd          } |            }d|d}|                      t          j        ||f|          |           |                      t          j        ||ft          d	                    |           d S )
Nr  r  r  FOOBARc                       e Zd Z fdZdS )KTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockc                     S rg   r|   )r7   stringrX  s     r:   header_encodezYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encode  s    r<   N)r  r  r  r  )rX  s   r:   CharsetMockr    s.              r<   r  z <>rW   )r3   r#   r  r
   )r7   r*  r  r  r  mockmock_expectedrX  s          @r:   $test_accepts_any_charset_like_objectz6TestMiscellaneous.test_accepts_any_charset_like_object  s    %E	 	 	 	 	 	 	 	 	 	 {}}%+VVTTT2)4,==}MMM)4,8H8HII	 	 	 	 	r<   c                 |    d}d}t                      }|                     t          t          j        ||f|           d S )Nr  r  )objectr   AttributeErrorr#   r  )r7   r*  r  bad_charsets       r:   -test_invalid_charset_like_object_raises_errorz?TestMiscellaneous.test_invalid_charset_like_object_raises_error  sG    %hh.%*:T4L	 	 	 	 	r<   c                     d}|                      t          t          j        d |f           |                      t          t          j        d|f           d S )Nu   persön@dom.inName)r   UnicodeErrorr#   r  r7   r  s     r:   !test_unicode_address_raises_errorz3TestMiscellaneous.test_unicode_address_raises_error  sK    #,(84,GGG,(864.IIIIIr<   c                    d}d}d\  }}|                      t          j        |          ||f           |                      t          j        |          ||f           |                      t          j        ||f          |           d S )NzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>)zJohn X. Doezjxd@example.comr  )r7   r  yr  r  s        r:   test_name_with_dotz$TestMiscellaneous.test_name_with_dot  s    +-11++aV444++aV444)1a&11155555r<   c                     | j         } |t          j        d          d            |t          j        d          d            |t          j        d          d           d S )N""example" example"@example.com)r,   r,  !"\"example\" example"@example.com)r,   r-  #"\\"example\\" example"@example.com)r,   r.  r  r  s     r:   2test_parseaddr_preserves_quoted_pairs_in_addresseszDTestMiscellaneous.test_parseaddr_preserves_quoted_pairs_in_addresses  s     
5?<==
1	3 	3 	3
5?@AA
5	7 	7 	7
5?DEE
9	; 	; 	; 	; 	;r<   c                    |                      dt          j        d                     |                      dt          j        d                     |                      dt          j        d                     |                      dt          j        d                     |                      dt          j        d	                     d S )
N)r,   merwok wok@xample.comr1  )r,   merwok  wok@xample.comr2  z merwok  wok  @xample.com)r,   merwok"wok"  wok@xample.comr3  )r,   zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.comr  r  s    r:   -test_parseaddr_preserves_spaces_in_local_partz?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_part  s     	6O344	6 	6 	67O455	7 	7 	77O788	: 	: 	:<O9::	< 	< 	<:O;<<	> 	> 	> 	> 	>r<   c                     d}d}|                      t          j        |          |           |                      t          j        |          |           d S )N)z#'foo@example.com' (foo@example.com)foo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>r  )r7   r  addrstrs      r:   6test_formataddr_does_not_quote_parens_in_quoted_stringzHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_string  sX    #C114888)$//99999r<   c                 Z    d}|                      t          j        |          d           d S )NzFoo
	Bar <foo@example.com>)zFoo Barr6  r  )r7   r  s     r:   test_multiline_from_commentz-TestMiscellaneous.test_multiline_from_comment  s2     	++-KLLLLLr<   c                 V    |                      t          j        d          d           d S )N)zA Silly; Personr  z""A Silly; Person" <person@dom.ain>r  r  s    r:   test_quote_dumpz!TestMiscellaneous.test_quote_dump  s6    BCC1	3 	3 	3 	3 	3r<   c                    | j         }| j        }t                      }t                      } ||d            ||d            ||d            |d|            |d|            |d|            ||d            ||d            ||d            |d|            |d|            |d|            |||            |||           d S )NrO   US-ASCIIzUs-AsCiIusasciiUSASCIIUsAsCiI)r3   assertNotEqualr
   )r7   r8   necset1cset2s        r:   test_charset_richcomparisonsz.TestMiscellaneous.test_charset_richcomparisons  s&    				
5*
5*
5*
:u
:u
:u
5)
5)
5)
9e
9e
9e
5%
5%r<   c                 X    | j         } |t          j        ddg          ddg           d S )Naperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>z	Al PersonrT  )z
Bud PersonrU  r3   r#   getaddressesr  s     r:   test_getaddressesz#TestMiscellaneous.test_getaddresses  sO    
5<=? @ @,-/	0 	0 	0 	0 	0r<   c                 ^    |                      t          j        g d          g d           dS )zGH-106669 regression test.)z"Bud, Person" <bperson@dom.ain>rH  z#"Mariusz Felisiak" <to@example.com>))zBud, PersonrU  rI  )zMariusz Felisiakto@example.comNrJ  r  s    r:   test_getaddresses_comma_in_namez1TestMiscellaneous.test_getaddresses_comma_in_name  sR         	
 	
 	
 	
 	
r<   c                 
   d}d}d}dd| d|fgfdd|f|d|fgfdd|f|d|f|gfdd|f|d|fgfd	d| d
| dfgfdd|f|d|fgfd||d|fgfdd|f|d|fgfdd|fd|fgfdd|dz   fd|fgfdd|fdd| dfgffD ]\  }}| | d| d}|                      |          5  |                     t          j        |g          |g           |                     t          j        |gd          |           |                     t          j        |g          |           |                     t          j        |gd          d|f           ddd           n# 1 swxY w Y   | d| d}|                     t          j        |g          d|fd|fg           |                     t          j        |gd          d|fd|fg           |                     t          j        |g          |           |                     t          j        |gd          d|f           d}d}|                     t          j        |g          |g           |                     t          j        |gd          |g           |                     t          j        |g          |           |                     t          j        |gd          d|f           d}d}|                     t          j        |g          |g           |                     t          j        |gd          |g           |                     t          j        |g          |           |                     t          j        |gd          d|f           d}|                     t          j        |g          |g           |                     t          j        |gd          g d           |                     t          j        |g          |           |                     t          j        |gd          d|f           d}|                     t          j        |g          ddg           |                     t          j        |gd          ddg           |                     t          j        |g          |           |                     t          j        |gd          d|f           |                     t
          j        j        d            dS )!z>Test for parsing errors from CVE-2023-27043 and CVE-2019-16056alice@example.orgbob@example.comr  (<r  )r,   [z[<z>]]@;:.")addressFstrictNz,<z,"Alice, alice@example.org" <bob@example.com>)zAlice, alice@example.orgrR  zalice@example.org (Alice))AlicerQ  zalice@example.org )Alice())r,   rQ  r  )r,   r`  <"Jane Doe" <jane@example.net>, "John Doe" <john@example.net>)zJane Doezjane@example.net)zJohn Doezjohn@example.netT)r  r3   r#   rK  r  r   supports_strict_parsing)r7   alicebobemptyinvalid_separatorexpected_non_strictr]  expected_stricts           r:   test_parsing_errorsz%TestMiscellaneous.test_parsing_errors  sf   # JJJJ&'(B;Cy12B;Cy%89B;Cy12B5++C+++,-.B;Cy125%"c+,B;Cy12B;S	*+B$r3i01B;ZZZZ 0127
 	0 	022 : 1::C:::Gg.. 	0 	0  !3WI!>!>"'* * *  !3WIe!L!L!L!46 6 6   '!;!;!&( ( (  '5!I!I!I"$g0 0 0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 $$c$$$+WI66u+Cy1	3 	3 	3+WIeDDDu+Cy1	3 	3 	3'33	  	  	 '5AAAg	( 	( 	( AI+WI668IJJJ+WIeDDDFWXXX'33_EEE'5AAAg	( 	( 	( .8+WI668IJJJ+WIeDDDFWXXX'33_EEE'5AAAg	( 	( 	( .+WI66@@@+WIeDDDMMM	O 	O 	O'33U;;;'5AAAg	( 	( 	( Q+WI66::<	= 	= 	= 	+WIeDDD::<	= 	= 	= 	'33U;;;'5AAAg	( 	( 	( 	<dCCCCCs   !B,EE	 E	c                 2   dgdgfdgdgfddgddgfdgdgfd	gdgfd
gg dfdgdgfdgdgfdgdgfdgddgff
D ]\  }}|                      |          5  |                     t          j        |          |           |                     t          j        |d          |           d d d            n# 1 swxY w Y   dg}|                     t          j        |          dg           |                     t          j        |d          g d           d S )Nu&   "Sürname, Firstname" <to@example.com>)u   Sürname, FirstnamerN  zfoo: ;r  z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerzjason@dom.ainz=Pete(A nice \) chap) <pete(his account)@silly.test(his host)>)z)Pete (A nice ) chap his account his host)zpete@silly.testz<(Empty list)(start)Undisclosed recipients  :(nobody(I know))z=Mary <@machine.tld:mary@example.net>, , jdoe@test   . example))Maryzmary@example.netr  )r,   zjdoe@test.examplez*John Doe <jdoe@machine(comment).  example>)zJohn Doe (comment)zjdoe@machine.examplez3"Mary Smith: Personal Account" <smith@home.example>)zMary Smith: Personal Accountzsmith@home.examplezUndisclosed recipients:;z7<boss@nil.test>, "Giant; \"Big\" Box" <bob@example.net>)r,   zboss@nil.test)zGiant; "Big" Boxzbob@example.net)	addressesFr^  z	[]*-- =~$)r  r  )r,   z*--)r  r3   r#   rK  )r7   rl  r   s      r:   test_getaddresses_nastyz)TestMiscellaneous.test_getaddresses_nastyu  s   6778: ZZ =>>?A OONOQ MMZ NNPPPR ;;<=? DDDEG ))Z II#%LMO9$
 #	+ #	+Ix> 	22 + +  !3I!>!>!)+ + +  !3Ie!L!L!L!)+ + ++ + + + + + + + + + + + + + + !M	+I66"	% 	% 	%+IeDDD:::	< 	< 	< 	< 	<s   AB33B7	:B7	c                 n    | j         }t          j        dg          } ||d         d         d           dS )z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>r   r   foo@bar.comNrJ  )r7   r8   addrss      r:   "test_getaddresses_embedded_commentz4TestMiscellaneous.test_getaddresses_embedded_comment  s>    "$K#LMM
58A;&&&&&r<   c                     t          j        t          d          g          }|                     |d         d         d           dS )z%Test the handling of a Header object.zAl Person <aperson@dom.ain>r   r   rT  N)r#   rK  r   r3   )r7   rp  s     r:   test_getaddresses_header_objz.TestMiscellaneous.test_getaddresses_header_obj  sC    "F+H$I$I#JKKq!&788888r<   cpuc                 l    G d dt                     fdt          d          D             }t          j        |          5  	 d d d            n# 1 swxY w Y   t	          d |D             g           }|                     t          t          |                    t          |                     d S )Nc                       e Zd Zd ZdS )BTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadc                     g | _         | j         j        }t          j        }t          j        } |            dz   } |            |k     r% | |d                      |            |k     #d S d S )Ng      @testdomain-stringdomain)msgidsr,  r#   
make_msgidr=  	monotonic)r7   r,  r}  clocktfins        r:   runzFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.run  sw     +"-
uww}eggnnF::-@AAABBB eggnnnnnnr<   N)r  r  r  r  r|   r<   r:   MsgidsThreadrw    s(        C C C C Cr<   r  c                 $    g | ]}             S r|   r|   )r   rM  r  s     r:   r   z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>  s    444a<<>>444r<   r  c                     g | ]	}|j         
S r|   )r|  )r   r  s     r:   r   z@TestMiscellaneous.test_make_msgid_collisions.<locals>.<listcomp>  s    111Aqx111r<   )r   rS  r%   start_threadssumr3   r  set)r7   threadsall_idsr  s      @r:   test_make_msgid_collisionsz,TestMiscellaneous.test_make_msgid_collisions  s   		C 		C 		C 		C 		C6 		C 		C 		C 5444588444+G44 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	11111266S\\**CLL99999s   AAAc                     | j         }t                      }|                    ddd            ||                                d           d S )NrP  rL  zfoo\wacky"namerN  )r3   r   rR  r~   r6   s      r:   test_utils_quote_unquotez*TestMiscellaneous.test_utils_quote_unquote  s[    ii,l 1 	 	3 	3 	3
3011111r<   c                 t    t          d          }|                     |                                d           d S )Nznot a charsetrX   r
   r3   get_body_encodingr7   rB   s     r:   )test_get_body_encoding_with_bogus_charsetz;TestMiscellaneous.test_get_body_encoding_with_bogus_charset  s7    /**2244h?????r<   c                    | j         }t                      }d|d<    ||d         d           |                                } |t          |          d            ||d         d           t	          |d                   } ||                                d           |                    d|	            ||                                d
            ||                    d          d            ||d         d           t                      }d|d<   |                                } |t          |          d            ||d         d           t	          |d                   } ||                                t          j	                   |                    d|	            ||                                d            ||d         d           d S )Nztext/plain; charset=UTF-8rE   rA   r   r   rW   rX   r   rW  aGVsbG8gd29ybGQ=
TrY   rC   ztext/plain; charset="US-ASCII"rO   r
  r  )
r3   r   rv   r  r
   r  rS   r[   r   r  )r7   r8   r9   rw   rB   s        r:   -test_get_body_encoding_with_uppercase_charsetz?TestMiscellaneous.test_get_body_encoding_with_uppercase_charset  s   ii9N
3~ ;<<<##%%
3x==!
8A;   (1+&&
7$$&&111888
3??2333
3??$?''888
3*+X666ii>N##%%
3x==!
8A;
###(1+&&
7$$&&(?@@@w777
3??m,,,
3*+V44444r<   c                     t          d          }t          d          }|                     |                                |                                           d S )NrO   r>  r  )r7   lcucs      r:   test_charsets_case_insensitivez0TestMiscellaneous.test_charsets_case_insensitive  sP    Z  Z  --//1E1E1G1GHHHHHr<   c                     | j         }|                     d          }t                      }t          j        ||            ||                                d           d S )Nr|  aB  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
rw  ry  s       r:   1test_partial_falls_inside_message_delivery_statuszCTestMiscellaneous.test_partial_falls_inside_message_delivery_status  sf    "
 ll<((jjS#&&&
3<<>>  	 	 	 	 	r<   c                 ~    |                      t          j                            d          dd          d           d S )Nry  rz  iz@testdomain-string>r3   r   r#   r}  r  s    r:   test_make_msgid_domainz(TestMiscellaneous.test_make_msgid_domain  sG    K""*=">>sttD!	# 	# 	# 	# 	#r<   c                     |                      t          j                            dd          dd          d           d S )Nztest-idstringry  )idstringr{  iz!.test-idstring@testdomain-string>r  r  s    r:   test_make_msgid_idstringz*TestMiscellaneous.test_make_msgid_idstring  sR    K""O* # , ,,/DD2/	1 	1 	1 	1 	1r<   c                     t          d          5 }dx|_        }|                     t          j                                                            d|z   dz                        d d d            d S # 1 swxY w Y   d S )Nzsocket.getfqdnzpythontest.example.comrX  r  )r	   return_valuer   r   r#   r}  endswith)r7   mock_getfqdnr{  s      r:   test_make_msgid_default_domainz0TestMiscellaneous.test_make_msgid_default_domain   s    #$$ 	)1IIL%OO&&((11&L3&( () ) )	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   AA11A58A5c                    t          ddd          5 }|                                }d d d            n# 1 swxY w Y   |                    dd          }t          j        |          }t                      }t          j                            |          }|                    |           | 	                    |
                                |           d S )N
msg_26.txtrW   r+   r   newliner   )r'   r   r   r   r	  r   r   r   r   r3   r   r7   fmsgtxt	msgtxt_nlr9   r   r   s          r:   test_Generator_linendz'TestMiscellaneous.test_Generator_linend'  s    lWdCCC 	qVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	NN6400	'//JJO%%a((			#y11111   488c                    t          ddd          5 }|                                }d d d            n# 1 swxY w Y   |                    dd          }t          j        |          }t                      }t          j                            |          }|                    |d           | 	                    |
                                                    d          |           d S )Nr  rW   r+   r  r   r   r   )r'   r   r   r   r	  r   r   r   r   r3   r   rZ   r  s          r:   test_BytesGenerator_linendz,TestMiscellaneous.test_BytesGenerator_linend2  s    lWdCCC 	qVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	NN6400	'	22IIO**1--			#v	&&&,,W55v>>>>>r  c                    t          dd          5 }|                                }d d d            n# 1 swxY w Y   |                    dd          }|                    dd          }t          j        |          }t                      }t          j                            |          }|                    |d           | 	                    |
                                |           d S )	Nr  r  s   with attachments   fo   
r   r   r   )r'   r   r   r   r   r   r   r   r   r3   r   r  s          r:   )test_BytesGenerator_linend_with_non_asciiz;TestMiscellaneous.test_BytesGenerator_linend_with_non_ascii=  s    lD)) 	QVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 2I>>NN7E22	&y11IIO**1--			#v	&&&v.....r  c                 8   t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          dft          |fft          |fft
          t                      fft          dft          dfg}|D ]\  }}| 	                    |j
        d          5   || }|                     |j        t          j        j                   d d d            n# 1 swxY w Y   | 	                    |j
        d          5   ||d	t          j        j        i}|                     |j        t          j        j                   d d d            n# 1 swxY w Y   d S )
Nr  r  r  )r,   )r5  r6  r  )clsr   r  r   )r'   r   r   r   r   r   r   r   r   r  r  r  r   r   r  r  )r7   r   	audiodatar  classesr  constructorr   s           r:   !test_mime_classes_policy_argumentz3TestMiscellaneous.test_mime_classes_policy_argumentI  s|   k4(( 	"B		I	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"lD)) 	 RggiiG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  e$%
#799,'56u
 !( 	> 	>C#,zBB ? ?C%ah(=>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #,yAA > >CBU\-ABBah(<===> > > > > > > > > > > > > > >		> 	>sC   266A..A25A20DD	 D	 AFF	F	c                     |                      t          t          j        d                    g d           |                      t          t          j        d                    ddg           d S )Nza\\b\"c\\"d)r   r  )r   \\)r   r  )r  z\")r  c)   r  )r  r\  )rO  dza\r  )r   \)r3   r   r#   _iter_escaped_charsr  s    r:   test_iter_escaped_charsz)TestMiscellaneous.test_iter_escaped_chars^  s    e7GGHH% % %	& 	& 	& 	e7>>??"I.	0 	0 	0 	0 	0r<   c                 ,     fd} |dd            |dd            |dd            |dd	            |d
d            |dd            |dd            |dd           dD ]*}                      t          j        |          |           +d S )Nc                 X                         t          j        |           |           d S rg   r3   r#   _strip_quoted_realnames)r  r   r7   s     r:   checkz<TestMiscellaneous.test_strip_quoted_realnames.<locals>.checkl  s*    U:4@@(KKKKKr<   ra  z( <jane@example.net>,  <john@example.net>z""Jane \"Doe\"." <jane@example.net>z <jane@example.net>zbefore"name"afterbeforeafterzbefore"name"beforezb"name"r  z"name"afterafterz"name"ar  z"name"r,   )z8Jane Doe <jane@example.net>, John Doe <john@example.net>zlone " quoter  )r7   r  r  s   `  r:   test_strip_quoted_realnamesz-TestMiscellaneous.test_strip_quoted_realnamesk  s   	L 	L 	L 	L 	L 	L8	: 	: 	:3#	% 	% 	% 	"M222ox(((j#ng&&&j#i
 	H 	HD U:4@@$GGGG		H 	Hr<   c                    d}|                      t          j        | d                     |                     t          j        | d                     |                     t          j        | d                     |                     t          j        | d                     |                      t          j        d|                      d S )Nzalice@example.netz (Alice)z )Alice(z	 (Alice))z	 ((Alice)z")Alice((" )r   r#   _check_parenthesisr  r&  s     r:   test_check_parenthesisz(TestMiscellaneous.test_check_parenthesis  s    "0D1B1B1BCCDDD1T2C2C2CDDEEE1T2D2D2DEEFFF1T2D2D2DEEFFF 	01Et1E1EFFGGGGGr<   N)Br  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r"  r'  r*  r/  r4  r8  r:  r<  rF  rL  rO  ri  rm  rq  rs  r%   requires_working_threadingr$   requires_resourcer  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r    s       	- 	- 	-
1 
1 
16 6 6"6 6 6. . .  / / /
% % %J J J4 4 4,D D D7 7 76 6 67 7 7
6 6 69 9 9C C CC C C	8 	8 	8E E EK K KF F F
 
 
/ / /
	L 	L 	LL L L      J J J6 6 6; ; ;$> > >$: : :M M M3 3 3
  (0 0 0
 
 
"VD VD VDp*< *< *<X' ' '9 9 9
 1022Wu%%: : &% 32:&2 2 2@ @ @5 5 54I I I
( ( (T# # #
1 1 1) ) )	2 	2 	2	? 	? 	?
/ 
/ 
/> > >*0 0 0H H H2H H H H Hr<   r  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestIteratorsc                    | j         }| j        }|                     d          }t          j        |          }t          |          } |t          |          d            |t                              |          |	                                           |                     d          }t          j        |          }t          |          } |t          |          d           t          dd          5 } |t                              |          |                                           d d d            d S # 1 swxY w Y   d S )Nr   r  r]  +   z
msg_19.txtrW   r   )r3   r  r4   r!   body_line_iteratorr   r  EMPTYSTRINGr   r[   r'   r   )r7   r8   r  r9   itr   r   s          r:   test_body_line_iteratorz%TestIterators.test_body_line_iterator  s`   #ll<(()#..R
3u::qKU##S__%6%6777ll<(()#..R
3u::rlW555 	4C  ''333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   87D<<E E c                 2   | j         }|                     d          }t          j        |d          }g }d}|D ].}|dz  }|                    |                                           / ||d            |t                              |          d           d S )Nrz   r   r   r   r   z`a simple kind of mirror
to reflect upon our own
a simple kind of mirror
to reflect upon our own
r3   r4   r!   typed_subpart_iteratorr,  r[   r  r   r7   r8   r9   r  r   subpartsr   s          r:   test_typed_subpart_iteratorz)TestIterators.test_typed_subpart_iterator  s    ll<((-c6:: 	0 	0GMHLL,,..////
8Q
;E"" % 	 	 	 	 	r<   c                 4   | j         }|                     d          }t          j        |dd          }g }d}|D ].}|dz  }|                    |                                           / ||d            |t                              |          d           d S )Nr   r   r  r   r   z%
Hi,

Do you like this message?

-Me
r  r  s          r:   (test_typed_subpart_iterator_default_typez6TestIterators.test_typed_subpart_iterator_default_type  s    ll<((-c67CC 	0 	0GMHLL,,..////
8Q
;E"" % 	 	 	 	 	r<   c                    g d}ddl m}m}  |            }g }d}|D ]i\  }}|                    |           ||z  }d}	t	          |j        |          D ]}
|                    |
           |	dz  }	|                     ||	           j|                     t          |          |           |                     d	                    d |D                       d	                    |                     dS )zFeedParser 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 
r   )r  r   )zc
r   )r,   r   )zd
r   )zer   )z
fr   )r   r   r   BufferedSubFileNeedMoreDatar   r,   c                     g | ]\  }}|S r|   r|   )r   ilns      r:   r   z0TestIterators.test_pushCR_LF.<locals>.<listcomp>  s    !6!6!6Q"!6!6!6r<   N)
email.feedparserr  r  pushiterreadliner,  r3   r  r   )r7   imtr  r  bsfomntr  r  n1ols              r:   test_pushCR_LFzTestIterators.test_pushCR_LF  s    
	 	 	 	CBBBBBBBo 	$ 	$EBHHRLLL!GBB3<66  		"aQ####R"%%%!6!6#!6!6!677EEEEEr<   c                    ddl m}m} d}d}dd                    fdt	          |          D                       dz   }|                    d	          } |            }g }t	          dt          |          |          D ]L}	||	|	|z            }
|                    |
           |                    t          |j
        |                     M|                     ||           d S )
Nr   r  i'  r  zabcd 	
r,   c              3   6   K   | ]}t                    V  d S rg   r   )r   rM  charss     r:   rN  z1TestIterators.test_push_random.<locals>.<genexpr>  s)      44aF5MM444444r<   r+   T)r  r  r  r   rS  r  r  r  extendr  r  r3   )r7   r  r  r  	chunksizer   targetr  r   rM  chunkr  s              @r:   test_push_randomzTestIterators.test_push_random  s    BBBBBBBB	GG444458844444t;d##oq#a&&),, 	; 	;Aa)m$EHHUOOOLLclL99::::'''''r<   N)r  r  r  r  r  r  r  r  r|   r<   r:   r  r    sb        4 4 4"  "  &F F F<( ( ( ( (r<   r  c                   &    e Zd Zd Zd Zd Zd ZdS )TestFeedParsersc                 z    t                      }|D ]}|                    |           |                                S rg   )r)   feedclose)r7   chunksr  r  s       r:   parsezTestFeedParsers.parse  sA    \\
 	# 	#EOOE""""!!!r<   c                     |                      d          }|                     |d         d           |                     |d         d           d S )NzFirst: val
: bad
Second: valr  valr  )r  r3   ri   s     r:   test_empty_header_name_handledz.TestFeedParsers.test_empty_header_name_handled  sN    jj9::Wu---X.....r<   c                    |                      dg          }|                     |                                g d           |                      dg          }|                     |                                g d           |                      ddg          }|                     |                                ddg           |                      dd	g          }|                     |                                dd
g           |                      ddg          }|                     |                                dd
g           |                      dg          }|                     |                                dg           |                      g d          }|                     |                                ddg           d S )Nza:
b:c:
d:
)r  r  r  r  za:
b:c:
d:za:bc:
r  bca:zb:
r  z
b:
u   a:b: c:
)r  u	   b: c:)r	  u   b:r  r  r,   )r  u   c:)r  r3   r  r   r  s     r:   test_newlineszTestFeedParsers.test_newlines  s   JJ,-..#7#7#7888JJ*+,,#7#7#7888JJ())C;///JJ'((C:...JJ)**C:... JJ,-..%<$=>>>JJ11122Y$@AAAAAr<   c                    d\  }}|                      dgd|z  g|z  z             }|                     |                                dg           |                     |                                d|z  |z             |                      dgd|z  g|z  z             }|                     |                                dg           |                     |                                d|z  |z             |                      dgd|z  dz   g|z  z             }|                     |                                dg           |                     |                                d|z  dz   |z             |                      ddgd|z  g|z  z             }|                     |                                d	d
d|z  |z  fg           d S )N)i  i N  za:b

r  )r  r  za:b   r	  zb: r
  r  )r  r3   r   r[   )r7   MNr   s       r:   test_long_lineszTestFeedParsers.test_long_lines  s   1JJ	{c!eWq[011ZL111#a%'222JJ	{c!eWq[011ZL111#a%'222JJ	{c!eFl^a%7788ZL1113q5<*:;;;JJ#a%1455Yc!eAg$?@@@@@r<   N)r  r  r  r  r  r  r  r|   r<   r:   r  r    sX        " " "/ / /B B B$A A A A Ar<   r  c                   ~    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZdZd Zd Zd Zd Zd Zd Zd ZdS )TestParsersc                    | j         }t          dd          5 }t                                          |          }d d d            n# 1 swxY w Y    ||d         d            ||d         d            ||                                d           |                     |                                           |                     |                                t                     d S )	Nr]  rW   r   r   ppp-request@zzz.orgr   ppp@zzz.orgrl   )
r3   r'   r   r  rI   r  r   r  r[   r   r7   r8   r   r9   s       r:   test_header_parserzTestParsers.test_header_parser)  s   lW555 	+..&&r**C	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
3v;-...
3t9m$$$
3!!#4555))++,,,coo//55555s   "AAAc                 P   | j         }t          dd          5 }t          j                                                            |          }d d d            n# 1 swxY w Y    ||d         d            ||d         d            ||                                d           |                     |                                           | 	                    |
                                t                     | 	                    |
                    d	          t                     d S )
Nr]  r  r   r  r   r  rl   TrY   )r3   r'   r   r   r   r  rI   r  r   r  r[   r   r  r  s       r:   test_bytes_header_parserz$TestParsers.test_bytes_header_parser4  sC   lD)) 	=R,002288<<C	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=
3v;-...
3t9m$$$
3!!#4555))++,,,coo//555cooTo::EBBBBBs   2AAAc                 B   t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          j                            t          j        j                  }|                    |d          }|                     |j	        g            d S )Nz
msg_47.txtrW   r   r   T)headersonly)
r'   r   r   r   r   r   r  r   r3   r  )r7   r   r   r   
parsed_msgs        r:   %test_header_parser_multipart_is_validz1TestParsers.test_header_parser_multipart_is_valid@  s    lW555 	 ggiiG	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  $$EL,@$AA__W$_??
+R00000r   c                     t          dd          5 }t          j                                                            |           |                     |j                   d d d            d S # 1 swxY w Y   d S )Nr]  r  )r'   r   r   BytesParserr  r  closedr  s     r:   %test_bytes_parser_does_not_close_filez1TestParsers.test_bytes_parser_does_not_close_fileJ  s    lD)) 	(RL$$&&,,R000RY'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   AA**A.1A.c                 6   t          dd          5 }t          j        j        }|                     t          j        j         |t          j        j                  j	        |           | 
                    |j                   d d d            d S # 1 swxY w Y   d S )Nr  r  r   )r'   r   r   r  r   r    r  r   r_  r  r  r   )r7   r   bytesParsers      r:   2test_bytes_parser_on_exception_does_not_close_filez>TestParsers.test_bytes_parser_on_exception_does_not_close_fileO  s    lD)) 	(R,2KelF)k1DEEEK " " " RY'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   A0BBBc                     t          dd          5 }t          j                                                            |           |                     |j                   d d d            d S # 1 swxY w Y   d S )Nr]  rW   r   )r'   r   r   r   r  r  r   r  s     r:   test_parser_does_not_close_filez+TestParsers.test_parser_does_not_close_fileW  s    lW555 	(L!!''+++RY'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   AA++A/2A/c                 8   t          dd          5 }t          j        j        }|                     t          j        j         |t          j        j                  j	        |           | 
                    |j                   d d d            d S # 1 swxY w Y   d S )Nr  rW   r   r   )r'   r   r   r   r   r    r  r   r_  r  r  r   )r7   r   r   s      r:   ,test_parser_on_exception_does_not_close_filez8TestParsers.test_parser_on_exception_does_not_close_file\  s    lW555 	(\(FelF$fEL,?@@@FL L LRY'''		( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   A0BBBc                     | j         }t          j        d          } ||d         d            ||d         d            ||                                d           d S )NzFrom: 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  !the next line has a space on it
 r  spamHere's the message body
r3   r   r	  r[   r6   s      r:   test_whitespace_continuationz(TestParsers.test_whitespace_continuationc  v     ' 	) 	 	 	3y>?@@@
3|f%%%
3??9:::::r<   c                     | j         }t          j        d          } ||d         d            ||d         d            ||                                d           d S )NzFrom: 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  r*  r  r+  r,  r-  r6   s      r:   (test_whitespace_continuation_last_headerz4TestParsers.test_whitespace_continuation_last_headeru  r/  r<   c                    | j         }t          ddd          5 }t                                          |          }d d d            n# 1 swxY w Y    |t	          |                                          d           |                    d          } ||                                d            ||                                d           |                    d	          } ||                                d
           d S )Nr  rW   r+   r  r   r   r@   z!Simple email with attachment.

r   zapplication/riscos)r3   r'   r   r  r  r[   rI   )r7   r8   r   r9   part1part2s         r:   test_crlf_separationz TestParsers.test_crlf_separation  s.   lWdCCC 	%r((..$$C	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%
3s  !!1%%%""
5!!##\222
5 GHHH""
5!!##%9:::::s   "AAAc                 b   t          ddd          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          }t	                      }t          |          }|                    |d           |                     |                                |           d S )Nr  rW   r+   r  r   r   r  r  s         r:   test_crlf_flattenzTestParsers.test_crlf_flatten  s    lWdCCC 	r7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'--JJaLL			#v	&&&t,,,,,r  Nc                    | j         }| j        }t          dd          5 }t          j        |          }d d d            n# 1 swxY w Y    ||                                d            |t          |                                          d           |                    d          } ||                                d            ||                                d            |t          |                                          d           |                    d          } ||                                d            ||                                d            ||                                d	           |                    d          } ||                                d            ||                                d            |t          |                                          d           |                    d          } ||                                d            ||                                d            ||                                d
           d S )Nrn  rW   r   r   r   r   re  r@   r.  r/  )	r3   r  r'   r   r!  r   r  r[   rI   )	r7   r8   r  r   r9   r3  part1ar4  part2as	            r:   -test_multipart_digest_with_extra_mime_headersz9TestParsers.test_multipart_digest_with_extra_mime_headers  s   #lW555 	.)"--C	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	3q!!!
3s  !!1%%%""
5!!##%5666
5###
3u  ""##Q'''""1%%
6  !$$$
6""$$l333F  -000""
5!!##%5666
5###
3u  ""##Q'''""1%%
6  !$$$
6""$$l333F  -00000s   AAAc                     g d}t          j        t                              |                    }|                     |d         d           d S )N)z$From: Andrew Person <aperson@dom.ainzSubject: Testz%Date: Tue, 20 Aug 2002 16:43:45 +1000datezTue, 20 Aug 2002 16:43:45 +1000)r   r	  r   r   r3   )r7   r   r9   s      r:   test_three_lineszTestParsers.test_three_lines  sP    : : : '77V&GHHHHHr<   c                     | j         }d}d}d|d|d}t          j        |          } ||                    d          |            ||                    d          |           d S )Nr   z	more textzHeader: z
Next-Header: z

Body

r   zNext-Header)r3   r   r	  get)r7   r8   value1value2r   r9   s         r:   3test_strip_line_feed_and_carriage_return_in_headersz?TestParsers.test_strip_line_feed_and_carriage_return_in_headers  s|    FFFFF'**
3778f%%%
377=!!6*****r<   c                     | j         }d}t          j        |          } |t          |          d            |t	          d |D                       g d            ||                                d           d S )Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyr   c              3      K   | ]}|V  d S rg   r|   )r   fields     r:   rN  z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>  s"      ))E%))))))r<   )z!"#QUX;~z>Fromr   r  )r3   r   r	  r  r  r[   r  s       r:   test_rfc2822_header_syntaxz&TestParsers.test_rfc2822_header_syntax  s    :'**
3s88Q
6))S)))))+H+H+HIII
3??f%%%%%r<   c                     | j         }d}t          j        |          } |t          |                                          d           d S )Nz<>From foo@example.com 11:25:53
From: bar
!"#QUX;~: zoo

bodyr   )r3   r   r	  r  r  r  s       r:   (test_rfc2822_space_not_allowed_in_headerz4TestParsers.test_rfc2822_space_not_allowed_in_header  sE    N'**
3sxxzz??Ar<   c                     | j         }d}t          j        |          }|                                }|                                  ||g d            ||                                d           d S )Nz7A: first header
B: second header
CC: third header

body)ABCCr  )r3   r   r	  r  sortr[   )r7   r8   r   r9   headerss        r:   !test_rfc2822_one_character_headerz-TestParsers.test_rfc2822_one_character_header  st    I'**((**
7$$$%%%
3??f%%%%%r<   c                     d}t          j        |          }|                     |                    d                                                              d                     d S )NzFrom: 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   r   )r   r	  r   r[   r  r7   r   r9   s      r:   test_CRLFLF_at_end_of_partz&TestParsers.test_CRLFLF_at_end_of_part  s\    
 	
 '****6688AA&IIJJJJJr<   )r  r  r  r  r  r  r!  r$  r&  r(  r.  r1  r5  r7  r  r;  r>  rC  rG  rI  rP  rS  r|   r<   r:   r  r  '  s4       	6 	6 	6
C 
C 
C1 1 1( ( (
( ( (( ( (
( ( (; ; ;$; ; ;$	; 	; 	;- - - G1 1 1>I I I	+ 	+ 	+& & &  & & &K K K K Kr<   r  c                      e Zd Z ej        d          Zd Zd Zd Zd Z	d Z
d ZdZd	                    d
 eD                       dz                       d          Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej        d                              d          Zd Zd Z ej        d          Zd Zd Z d Z!e"                    d	          Z#dge#d d!<   d	                    e#          Z#d" Z$ ej        d#                              d$          Z% ej        d%          Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d-Z.d-S ).Test8BitBytesHandlingz        From: foo@bar.com
        To: baz
        Mime-Version: 1.0
        Content-Type: text/plain; charset={charset}
        Content-Transfer-Encoding: {cte}

        {bodyline}
        c                 X   | j                             ddd                              d          }t          j        |          }|                     |                                d           |                     |                    d          d                    d                     d S )NrW   ra      pöstalrB   r   bodyline   pöstal
TrY   bodytest_msgr  r   r   r   r3   r[   rR  s      r:   test_known_8bit_CTEz)Test8BitBytesHandling.test_known_8bit_CTE  s    $$W)/.7 % 9 99? 	
 &q))**K88855$++G44	6 	6 	6 	6 	6r<   c                 X   | j                             ddd                              d          }t          j        |          }|                     |                                d           |                     |                    d          d	                    d                     d S )
Nnotavalidcharsetra   rW  rX  rW   u   p��stal
TrY   rZ  r[  rR  s      r:   test_unknown_8bit_CTEz+Test8BitBytesHandling.test_unknown_8bit_CTE  s    $$-?)/.7 % 9 99? 	
 &q))**,ABBB55$++G44	6 	6 	6 	6 	6r<   c                 X   | j                             ddd                              d          }t          j        |          }|                     |                                d           |                     |                    d          d                    d                     d S )	NrW   rD      p=C3=B6stálrX  u   p=C3=B6stál
TrY   	   pöstál
r[  rR  s      r:   test_8bit_in_quopri_bodyz.Test8BitBytesHandling.test_8bit_in_quopri_body   s     $$W);.< % > >>DfWoo 	
 &q))**,<===55%,,W55	7 	7 	7 	7 	7r<   c                 X   | j                             ddd                              d          }t          j        |          }|                     |                                d           |                     |                    d          d	                    d                     d S )
Nr   rD   rb  rX  rW   u   p=C3=B6st��l
TrY   rc  r[  rR  s      r:   .test_invalid_8bit_in_non_8bit_cte_uses_replacezDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replace2  s     $$W);.< % > >>DfWoo 	
 &q))**,FGGG55$++G44	6 	6 	6 	6 	6r<   c                 ^   | j                             ddd                              d          }t          j        |          }|                     |                    d          d                    d                     |                     |j        d         t          j
                   d S )	NrW   rX   u   cMO2c3RhbAá=rX  TrY   rW  r   )r\  r  r   r   r   r3   r[   r  r  r    r  rR  s      r:   test_8bit_in_base64_bodyz.Test8BitBytesHandling.test_8bit_in_base64_bodyB  s     $$W)1.= % ? ??Evg 	
 &q))55"))'22	4 	4 	4ck!n$B	D 	D 	D 	D 	Dr<   c                    | j                             ddd                              d          }t          j        |          }|                     |                    d          d                    d                     d S )NrW   r   u   <,.V<W1A; á rX  TrY   u   <,.V<W1A; á 
r[  rR  s      r:   test_8bit_in_uuencode_bodyz0Test8BitBytesHandling.test_8bit_in_uuencode_bodyO  s     $$W)3.= % ? ??Evg 	
 &q))55*11'::	< 	< 	< 	< 	<r<   ))zFrom: foo@bar.comr   ro  )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                     g | ]\  }}|S r|   r|   )r   src_s      r:   r   z Test8BitBytesHandling.<listcomp>d  s     H H H#q H H Hr<   z
Yes, they are flying.
rW   c                     t          j        | j                  }|                     t	          |                    d                    d           |                     t	          |d                   d           d S )Nr      b��z)r   r   headertest_msgr3   r   r@  ri   s     r:   test_get_8bit_headerz*Test8BitBytesHandling.test_get_8bit_headerg  se    &t':;;SWWT]]++-=>>>SY)9:::::r<   c                     t          j        | j                  }|                     t	          |           t          j        d          j        d | j        D                         d S )Nz                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            c                 $    g | ]\  }}|d          S )r   r|   )r   rn  r   s      r:   r   zATest8BitBytesHandling.test_print_8bit_headers.<locals>.<listcomp>v  s2     *A *A *A-1h(1+ *A *A *Ar<   )	r   r   rq  r3   r   r   r   r  headertest_headersri   s     r:   test_print_8bit_headersz-Test8BitBytesHandling.test_print_8bit_headersl  s    &t':;;S( *  ! ! "( *A *A(,(?*A *A *AB		C 		C 		C 		C 		Cr<   c                     t          j        | j                  }|                     d |                                D             g d           d S )Nc                 ,    g | ]}t          |          S r|   r   r  s     r:   r   zGTest8BitBytesHandling.test_values_with_8bit_headers.<locals>.<listcomp>{  s    ;;;c!ff;;;r<   )ro  rp  ]   Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie	   g��st)r   r   rq  assertListEqualr  ri   s     r:   test_values_with_8bit_headersz3Test8BitBytesHandling.test_values_with_8bit_headersy  s_    &t':;;;;cjjll;;;2 2 2	3 	3 	3 	3 	3r<   c                     t          j        | j                  }|                     d |                                D             g d           d S )Nc                 P    g | ]#\  }}t          |          t          |          f$S r|   ry  )r   r  r)  s      r:   r   zFTest8BitBytesHandling.test_items_with_8bit_headers.<locals>.<listcomp>  s-    III6Aqs1vvs1vv.IIIr<   )rk  )r   rp  )r  rz  )r   r{  )r   r   rq  r|  r   ri   s     r:   test_items_with_8bit_headersz2Test8BitBytesHandling.test_items_with_8bit_headers  s_    &t':;;IISYY[[III< < <	= 	= 	= 	= 	=r<   c                     t          j        | j                  }|                     d |                    d          D             ddg           d S )Nc                 ,    g | ]}t          |          S r|   ry  r  s     r:   r   zHTest8BitBytesHandling.test_get_all_with_8bit_headers.<locals>.<listcomp>  s    BBBc!ffBBBr<   r   ro  r{  )r   r   rq  r|  r5   ri   s     r:   test_get_all_with_8bit_headersz4Test8BitBytesHandling.test_get_all_with_8bit_headers  s_    &t':;;BBckk&.A.ABBB,02	3 	3 	3 	3 	3r<   c                 h   t          j        t          j        d                              d                    }|                     |                                d           |                     |                                d           |                     |                                d           d S )NuA               Content-Type: text/pl§in; charset=utf-8
            r  u   text/pl�inr   u   pl�in)	r   r   r   r   r   r3   rI   rx  r  ri   s     r:   test_get_content_type_with_8bitz5Test8BitBytesHandling.test_get_content_type_with_8bit  s    &x 8 ( (	""$ $ 	--//1BCCC1133V<<<0022LAAAAAr<   c                 X   t          j        d                    d                    }|                     |                    d          g d           |                     |                    dd          d           |                     |                    dd          d            d S )	Nu(   X-Header: foo=§ne; b§r=two; baz=three
r  r  r  ))r      �ne)u   b�rr  r  Foor  u   b§r)r   r   r   r3   r  rJ   ri   s     r:   test_get_params_with_8bitz/Test8BitBytesHandling.test_get_params_with_8bit  s    &;BB9MMO Oz::GGG	I 	I 	IuZ@@*MMMx
CCTJJJJJr<   c                     t          j        t          j        d                              d                    }|                     |                    d          d           d S )Nn               Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nr  title)rO   enu   This is not f�n)r   r   r   r   r   r3   rJ   ri   s     r:   !test_get_rfc2231_params_with_8bitz7Test8BitBytesHandling.test_get_rfc2231_params_with_8bit  sk    &x 8< ( ( vi  " " 	w//6	8 	8 	8 	8 	8r<   c                     t          j        t          j        d                              d                    }|                    dd           |                     |                    d          d           d S )Nr  r  r  test)r   r   r   r   r   r=  r3   rJ   ri   s     r:   !test_set_rfc2231_params_with_8bitz7Test8BitBytesHandling.test_set_rfc2231_params_with_8bit  st    &x 8< ( ( vi  " " 	gv&&&w//88888r<   c                 D   t          j        t          j        d                              d                    }|                    d           |                     |                    d          d            |                     |                                d           d S )Nr  r  r  r   )	r   r   r   r   r   rG  r3   rJ   rx  ri   s     r:   !test_del_rfc2231_params_with_8bitz7Test8BitBytesHandling.test_del_rfc2231_params_with_8bit  s    &x 8< ( ( vi  " " 	gw//6661133V<<<<<r<   c                    t          j        t          j        d                              d                    }|                     |                                d           |                     |                    d          d           d S )Nu               Content-Transfer-Encoding: b§se64
            Content-Type: text/plain; charset=latin-1

            payload
            r  zpayload
TrY   s   payload
)r   r   r   r   r   r3   r[   ri   s     r:   %test_get_payload_with_8bit_cte_headerz;Test8BitBytesHandling.test_get_payload_with_8bit_cte_header  s    &x 8 ( (
 	""$ $ 	**K88855|DDDDDr<   u0          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                    t          j        | j                  }t                      }t           j                            |                              |           |                     |                                | j                   d S rg   )	r   r   non_latin_bin_msgr   r   r   r   r3   r   r7   r9   r   s      r:   test_bytes_generatorz*Test8BitBytesHandling.test_bytes_generator  si    &t'=>>ii&&s++33C888)?@@@@@r<   c                    t           j                                        }t                      }t           j                            |                              |           |                     |                                d           d S )Nr   )	r   r{  r   r   r   r   r   r3   r   r  s      r:   &test_bytes_generator_handles_None_bodyz<Test8BitBytesHandling.test_bytes_generator_handles_None_body  sf    m##%%ii&&s++33C888/////r<   a          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                    t          j        | j                  }t                      }t           j                            |                              |           |                     |                                | j	                   d S rg   )
r   r   r  r   r   r   r   r3   r    non_latin_bin_msg_as7bit_wrappedr  s      r:   test_generator_handles_8bitz1Test8BitBytesHandling.test_generator_handles_8bit  si    &t'=>>jj!!#&&..s333)NOOOOOr<   c                    t          j        | j                  }t                      }t	          |                              |           |                                }t          t                                                    |           t                      }t	          |                              |           | 	                    |                                |           d S rg   )
r   r   r  r   r   r   r   r   r   r3   )r7   r9   r   
orig_values       r:   ;test_str_generator_should_not_mutate_msg_when_handling_8bitzQTest8BitBytesHandling.test_str_generator_should_not_mutate_msg_when_handling_8bit  s    &t'=>>iis##C(((\\^^
(**%%c***iis##C(((44444r<   c                    t          j        | j                  }t                      }t           j                            |                              |d           |                                                    d          }| 	                    |d                                         d         d           | 	                    d
                    |dd                    | j                   d S )NTr   r   r   s   Fromr   )r   r   r  r   r   r   r   r   r   r3   r   )r7   r9   r   r   s       r:   #test_bytes_generator_with_unix_fromz9Test8BitBytesHandling.test_bytes_generator_with_unix_from  s     &t'=>>ii&&s++33C$3GGG$$U++q))!,g666E!""I..0FGGGGGr<   zkSubject: =?unknown-8bit?q?Maintenant_je_vous_pr=C3=A9sente_mon_coll=C3=A8gue=2C_le_pouf_c=C3=A9l=C3=A8bre?=r   r   c                    d}|                      t          |           t          |d          5 }|                    | j                   d d d            n# 1 swxY w Y   t          |d          5 }t
          j                                                            |          }d d d            n# 1 swxY w Y   | 	                    t          |          | j                   d S )Nztest.msgwbr  )
addCleanupr&   openwriter  r   r   r  r  r3   r   non_latin_bin_msg_as7bit)r7   r  testfiler   s       r:   test_message_from_binary_filez3Test8BitBytesHandling.test_message_from_binary_file  s6   ###"d^^ 	3xNN41222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3"d^^ 	;x((**00::A	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;Q!>?????s#   AAA02B..B25B2u          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?
        r  a           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                     t          j        | j                  }|                     t	          |          | j                   d S rg   )r   r   latin_bin_msgr3   r   latin_bin_msg_as7bitr  s     r:   :test_string_generator_reencodes_to_quopri_when_appropriatezPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriate2  s:    $T%788Q!:;;;;;r<   c                 >   t          j        | j                  }t                      }t           j                            |                              |           |                     |                                | j        	                    d          dz              d S )Nr  r+   )
r   r   r  r   r   r   r   r3   r   rZ   )r7   r   r   s      r:   )test_decoded_generator_emits_unicode_bodyz?Test8BitBytesHandling.test_decoded_generator_emits_unicode_body6  s    $T%788jj((--55a888 	%%i005	7 	7 	7 	7 	7r<   c                 P   t           j                                        }t          dt	          | j                  d          D ]'}|                    | j        ||dz                       (|                                }|                     t          |          | j
                   d S )Nr   rO  )r   r  r*   rS  r  r  r  r   r3   r   r  )r7   bfprM  r   s       r:   test_bytes_feedparserz+Test8BitBytesHandling.test_bytes_feedparser@  s    ..00q#d011266 	1 	1AHHT'!B$/0000IIKKQ!:;;;;;r<   c                 ~   t          dd          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          }t	                      }t          j                            |          }|                    |d           |                     |	                                |           d S )Nr  r  r   r   )
r'   r   r   r   r   r   r   r   r3   r   r  s         r:   r7  z'Test8BitBytesHandling.test_crlf_flattenG  s    lD)) 	R7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	&t,,IIO**1--			#v	&&&t,,,,,r  c                 P   t          j        d                              d          }t          j        |          }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--

            rW   )r   r   r   r   r   r   r   r   r   r3   r   )r7   r   r9   r   r   s        r:   test_8bit_multipartz)Test8BitBytesHandling.test_8bit_multipartP  s     %" % %J K 	L &v..IIO**1--			#v.....r<   c                    t                      }t          d          |d<   t                      }t          j                            |          }|                    |d           |                     |                                d           d S )N   žluťoučký kůňr  r   r   s5   Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	r   r   r   r   r   r   r   r3   r   r7   r   r   r   s       r:   'test_bytes_generator_b_encoding_linesepz=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesep~  s    II344)IIO**1--			!V	$$$JJLLH	J 	J 	J 	J 	Jr<   c                    t                      }t          d          |d<   t                      }t          j                            |          }|                    |d           |                     |                                d           d S )Nr  r  r   r   z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	r   r   r   r   r   r   r   r3   r   r  s       r:   !test_generator_b_encoding_linesepz7Test8BitBytesHandling.test_generator_b_encoding_linesep  s    II344)JJO%%a((			!V	$$$JJLLG	I 	I 	I 	I 	Ir<   N)/r  r  r  r   r   r\  r]  r`  rd  rf  rh  rj  ru  r   r   rq  rr  rv  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r7  r  r  r  r  r|   r<   r:   rU  rU    s"        #8? $  L6 6 66 6 67 7 7$6 6 6 D D D< < <	
 ii H H5G H H HII#$%+VG__ ; ; ;
C C C	3 	3 	3
= 
= 
=3 3 3B B BK K K8 8 89 9 9= = =E E E ( 
) 
 
 VG__ A A A0 0 0 (7x 8 ( ($P P P5 5 5	H 	H 	H  @EEdKK	8%9QqS!  $yy)ABB@ @ @ $HO 	% 	 	 VI  +8? 	, 	 	< < <7 7 7< < <- - -,/ ,/ ,/\
J 
J 
J
I 
I 
I GGGr<   rU  c                        e Zd ZdZd ZddZdS ) BaseTestBytesGeneratorIdempotentNc                     t          |d          5 }|                                }d d d            n# 1 swxY w Y   | j                            | j        |          }t          j        |          }||fS )Nr  )r'   r   normalize_linesep_regexsubblinesepr   r   rO  s        r:   r4   z(BaseTestBytesGeneratorIdempotent._msgobj  s    h%% 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	+//tDD&t,,Dyr  Fc                     t                      }t          j                            |d          }|                    ||| j                   |                     ||                                           d S )Nr   r  )r   r   )r   r   r   r   r   r   r3   r   )r7   r9   r]   r   r  r   s         r:   rQ  z,BaseTestBytesGeneratorIdempotent._idempotent  sc    IIO**11*==			#$,	???qzz||,,,,,r<   r  )r  r  r  r  r4   rQ  r|   r<   r:   r  r    s<        G  - - - - - -r<   r  c                   6    e Zd ZdZdZ ej        d          ZdS )TestBytesGeneratorIdempotentNLr+   r   s   \r\nNr  r  r  r   r  recompiler  r|   r<   r:   r  r    s,        GH(bj22r<   r  c                   6    e Zd ZdZdZ ej        d          ZdS ) TestBytesGeneratorIdempotentCRLFr   r  s	   (?<!\r)\nNr  r|   r<   r:   r  r    s,        GH(bj77r<   r  c                   &    e Zd Zd Zd Zd Zd ZdS )
TestBase64c           	      V   | j         } |t          j        d          t          t          j        dd                               t          d          D ]R}|dk    rd}n&|dk    rd}n|d	k    rd
}n|dk    rd}n|dk    rd}nd} |t          j        d|z            |           Sd S )Nhello   hellor,   eol   r   r   r   r  r  r     r     r  )r3   r   header_lengthr  body_encoderS  )r7   r8   sizebsizes       r:   test_lenzTestBase64.test_len  s    
:#G,,z%hB77788	: 	: 	:"II 	< 	<DQUUQUUQUURUURUU%'UBz'd
33U;;;;	< 	<r<   c                     | j         } |t          j        d          d            |t          j        d          d           d S )Nr,   r<   zaGVsbG8=r  )r3   r   rZ   r  s     r:   test_decodezTestBase64.test_decode  sJ    
:R  #&&&
:Z(((33333r<   c                 J   | j         } |t          j        d          d            |t          j        d          d            |t          j        d          d            |t          j        dd	          d
            |t          j        ddd          d           d S )Nr<   r,   r  z	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*  zeHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
r   r+  r  zeHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
eHh4eCB4eHh4IA==
)r3   r   r  r  s     r:   test_encodezTestBase64.test_encode  s    
:!#&&+++
:!(++\:::
:!*--|<<<
:!-B??? B 	 	 	 	:!-BFKKK	 	 	 	 	r<   c                    | j         }t          j        } | |d          d            | |d          d            | |d          d            | |dd          d	            | |d          d           d S )
Nr  z=?iso-8859-1?b?aGVsbG8=?=hello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=hello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=rs   rW  z=?iso-8859-2?b?aGVsbG8=?=)r3   r   r  )r7   r8   hes      r:   test_header_encodezTestBase64.test_header_encode  s    %
22g;;3444
22!DEEE
22nBCCC
22g|,,,.IJJJ
22nBCCCCCr<   N)r  r  r  r  r  r  r  r|   r<   r:   r  r    sU        < < <4 4 4
  ,D D D D Dr<   r  c                      e Zd Zd Zd Zd Zd Zd Zd ZdEdZ	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdEdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,dFd,Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z;d; Z<d< Z=d= Z>d> Z?d? Z@d@ ZAdA ZBdB ZCdC ZDdD ZEdS )G
TestQuopric                     t          t          t          t          d          t          d          dz             t          t          d          t          d          dz             t          t          d          t          d          dz             d d	D                                  _         fd
t          d          D              _        t           j                  t           j                  z   dk    sJ t          t          t          d          t          d          dz                        _         j                            t          d                      j        	                    t          d                      fdt          d          D              _
        t           j                  t           j
                  z   dk    sJ d S )Nr  zr   rK  Zr  9c              3      K   | ]}|V  d S rg   r|   )r   r  s     r:   rN  z#TestQuopri.setUp.<locals>.<genexpr>  s"      !!1Q!!!!!!r<   s   !*+-/c                 &    g | ]}|j         v|S r|   )hlitr   r  r7   s     r:   r   z$TestQuopri.setUp.<locals>.<listcomp>  %    AAA1aty.@.@Q.@.@.@r<      r-   ~r  =c                 &    g | ]}|j         v|S r|   )blitr  s     r:   r   z$TestQuopri.setUp.<locals>.<listcomp>  r  r<   )r   r   rS  ordr  hnonr  r  r,  removebnonr  s   `r:   r  zTestQuopri.setUp  s    #c((CHHqL))#c((CHHqL))#c((CHHqL))!!!!!	# # $ $	 BAAAc

AAA	49~~DI.#5555 s3xxSA6677		T###	S""" BAAAc

AAA	49~~DI.#555555r<   c                    | j         D ]:}|                     t          j        |          dt	          |          z             ;| j        D ]:}|                     t          j        |          dt	          |          z             ;d S )Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)r  r  r"   header_checkchrr  r   r7   r  s     r:   test_quopri_header_checkz#TestQuopri.test_quopri_header_check  s     	L 	LAZ4Q77ACFFJL L L L 	L 	LAOOJ3A66ACFFJL L L L	L 	Lr<   c                    | j         D ]:}|                     t          j        |          dt	          |          z             ;| j        D ]:}|                     t          j        |          dt	          |          z             ;d S )Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)r  r  r"   
body_checkr  r  r   r  s     r:   test_quopri_body_checkz!TestQuopri.test_quopri_body_check  s     	J 	JAZ2155?#a&&HJ J J J 	J 	JAOOJ1!44?#a&&HJ J J J	J 	Jr<   c           	         | j         } |t          j        d          d            |t          t          j        dd                    t          j        d          dz               |t          j        d          d            |t          t          j        dd                    t          j        d          dz              | j        D ]?} |t          j        t          |g                    dd	t          |          z             @| j        D ]S}|t          d
          k    r |t          j        t          |g                    ddt          |          z             T |t          j        d          d           d S )Nr  r  xxxrW  rO  s
   h@e@l@l@o@r  r   zexpected length 1 for %rr-   r   zexpected length 3 for %r    )
r3   r"   r  r  r  r  r  r  r  r  r7   r8   r  s      r:   test_header_quopri_lenz!TestQuopri.test_header_quopri_len  s   
:#H--q111
3z'%@@@AA#H--	 	 	 	:#M22B777
3z'uEEEFF#M22	 	 	  	4 	4ABz'qc

33Q)CFF24 4 4 4 	4 	4ACHH}}Bz'qc

33Q)CFF24 4 4 4
:#D))1-----r<   c                     | j         }| j        D ].} |t          j        t	          |g                    d           /| j        D ].} |t          j        t	          |g                    d           /d S )Nr   r   )r3   r  r"   body_lengthr  r  r  s      r:   test_body_quopri_lenzTestQuopri.test_body_quopri_len-  s     	6 	6ABz%eQCjj1115555 	6 	6ABz%eQCjj1115555	6 	6r<   c                     t          d          D ]K}t          |          }|                     t          j        t          j        |                    |           Ld S )Nr  )rS  r  r3   r"   r.  quote)r7   r  r  s      r:   test_quote_unquote_idempotentz(TestQuopri.test_quote_unquote_idempotent4  s_    s 	I 	IAAAZ/
0@0C0CDDaHHHH	I 	Ir<   Nc                     |t          j        |          }nt          j        ||          }|                     ||           d S rg   )r"   r  r3   )r7   r   expected_encoded_headerrB   encoded_headers        r:   _test_header_encodezTestQuopri._test_header_encode9  sH    ?'5f==NN'5fgFFN)@AAAAAr<   c                 2    |                      dd           d S )Nr<   r,   r  r  s    r:   test_header_encode_nullz"TestQuopri.test_header_encode_null@  s      b)))))r<   c                 2    |                      dd           d S )Nr  z=?iso-8859-1?q?hello?=r  r  s    r:   test_header_encode_one_wordz&TestQuopri.test_header_encode_one_wordC  s      +CDDDDDr<   c                 2    |                      dd           d S )Ns   hello
worldz=?iso-8859-1?q?hello=0Aworld?=r  r  s    r:   test_header_encode_two_linesz'TestQuopri.test_header_encode_two_linesF  s.       @	B 	B 	B 	B 	Br<   c                 2    |                      dd           d S )Ns   hellotherez=?iso-8859-1?q?hello=C7there?=r  r  s    r:   test_header_encode_non_asciiz'TestQuopri.test_header_encode_non_asciiJ  s/      !2 @	B 	B 	B 	B 	Br<   c                 6    |                      ddd           d S )Nr  z=?iso-8859-2?q?hello?=rs   rW  r  r  s    r:   test_header_encode_alt_charsetz)TestQuopri.test_header_encode_alt_charsetN  s1      +C$ 	! 	& 	& 	& 	& 	&r<   c                 Z    t          j        |          }|                     ||           d S rg   )r"   header_decoder3   )r7   r  expected_decoded_headerdecoded_headers       r:   _test_header_decodezTestQuopri._test_header_decodeR  s/    #1.AA)@AAAAAr<   c                 2    |                      dd           d S Nr,   r   r  s    r:   test_header_decode_nullz"TestQuopri.test_header_decode_nullV  s      R(((((r<   c                 2    |                      dd           d S Nr  r#  r  s    r:   test_header_decode_one_wordz&TestQuopri.test_header_decode_one_wordY  s      '22222r<   c                 2    |                      dd           d S )Nzhello=0Aworldr  r#  r  s    r:   test_header_decode_two_linesz'TestQuopri.test_header_decode_two_lines\  s      .AAAAAr<   c                 2    |                      dd           d S )Nzhello=C7thereu   helloÇtherer#  r  s    r:   test_header_decode_non_asciiz'TestQuopri.test_header_decode_non_ascii_  s      2BCCCCCr<   c                 V    |                      t          j        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=30  00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)r3   r"   r  r  s    r:   test_header_decode_re_bug_18380z*TestQuopri.test_header_decode_re_bug_18380b  s)    1+>>	JJJJJr<   c                     |t          j        |          }nt          j        ||          }|                     ||           d S )Nr  )r"   rZ   r3   )r7   encodedexpected_decodedr  decodeds        r:   _test_decodezTestQuopri._test_decodef  sK    ; '00GG 'S999G"233333r<   c                 2    |                      dd           d S r"  r3  r  s    r:   test_decode_null_wordz TestQuopri.test_decode_null_wordm      "b!!!!!r<   c                 2    |                      dd           d S )Nr   r+   r5  r  s    r:   test_decode_null_line_null_wordz*TestQuopri.test_decode_null_line_null_wordp  s    &$'''''r<   c                 2    |                      dd           d S r&  r5  r  s    r:   test_decode_one_wordzTestQuopri.test_decode_one_words  s    '7+++++r<   c                 6    |                      ddd           d S )Nr  Xr  r5  r  s    r:   test_decode_one_word_eolz#TestQuopri.test_decode_one_word_eolv  s#    '744444r<   c                 2    |                      dd           d S Nhello
hello
r5  r  s    r:   test_decode_one_linezTestQuopri.test_decode_one_liney      +y11111r<   c                 2    |                      dd           d S NrB  r5  r  s    r:   test_decode_one_line_lfz"TestQuopri.test_decode_one_line_lf|      )Y/////r<   c                 2    |                      dd           d S )NzhellorB  r5  r  s    r:   test_decode_one_line_crz"TestQuopri.test_decode_one_line_cr  rH  r<   c                 6    |                      ddd           d S )NrB  helloXr=  r  r5  r  s    r:   test_decode_one_line_nlz"TestQuopri.test_decode_one_line_nl  s#    )X377777r<   c                 6    |                      ddd           d S )NrA  rL  r=  r  r5  r  s    r:   test_decode_one_line_crnlz$TestQuopri.test_decode_one_line_crnl  s#    +xS99999r<   c                 2    |                      dd           d S )Nr  r  r5  r  s    r:   test_decode_one_line_one_wordz(TestQuopri.test_decode_one_line_one_word  s    *N;;;;;r<   c                 6    |                      ddd           d S )Nr  helloXworldr=  r  r5  r  s    r:   !test_decode_one_line_one_word_eolz,TestQuopri.test_decode_one_line_one_word_eol  s$    *MsCCCCCr<   c                 2    |                      dd           d S )Nhello
world
hello
world
r5  r  s    r:   test_decode_two_linesz TestQuopri.test_decode_two_lines  s     .0@AAAAAr<   c                 6    |                      ddd           d S )NrV  helloXworldXr=  r  r5  r  s    r:   test_decode_two_lines_eolz$TestQuopri.test_decode_two_lines_eol  s$    .CHHHHHr<   c                 2    |                      dd           d S )N  SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamr5  r  s    r:   test_decode_one_long_linez$TestQuopri.test_decode_one_long_line  s    ,55555r<   c                 2    |                      dd           d S )Nr-   r,   r5  r  s    r:   test_decode_one_spacez TestQuopri.test_decode_one_space  s    #r"""""r<   c                 2    |                      dd           d S )Nz     r,   r5  r  s    r:   test_decode_multiple_spacesz&TestQuopri.test_decode_multiple_spaces  s    '2&&&&&r<   c                 2    |                      dd           d S )Nzhello    
rB  r5  r  s    r:   $test_decode_one_line_trailing_spacesz/TestQuopri.test_decode_one_line_trailing_spaces  s    /955555r<   c                 2    |                      dd           d S )Nzhello    
world   
rW  r5  r  s    r:   %test_decode_two_lines_trailing_spacesz0TestQuopri.test_decode_two_lines_trailing_spaces  s     57GHHHHHr<   c                 2    |                      dd           d S )Nz=22quoted=20words=22z"quoted words"r5  r  s    r:   test_decode_quoted_wordz"TestQuopri.test_decode_quoted_word  s     02BCCCCCr<   c                 2    |                      dd           d S )Nzab=CD=EF   abÍïr5  r  s    r:   test_decode_uppercase_quotingz(TestQuopri.test_decode_uppercase_quoting      *l33333r<   c                 2    |                      dd           d S )Nzab=cd=efrj  r5  r  s    r:   test_decode_lowercase_quotingz(TestQuopri.test_decode_lowercase_quoting  rl  r<   c                 2    |                      dd           d S )Nzsoft line=
breakzsoft linebreakr5  r  s    r:   test_decode_soft_line_breakz&TestQuopri.test_decode_soft_line_break  s     /1ABBBBBr<   c                 2    |                      dd           d S )NzA=1,B=A ==> A+B==2r5  r  s    r:   test_decode_false_quotingz$TestQuopri.test_decode_false_quoting  s     .0DEEEEEr<   c                    i }|d}n||d<   |d}n||d<   t          j        |fi |}|                     ||           |dk    s|dk    r:|                                D ]'}|                     t          |          |           &d S d S )Nr  r+  r+   r  r   )r"   r  r3   r  r  r  )r7   r  expected_encoded_bodyr+  r  kwargsencoded_bodyr  s           r:   _test_encodezTestQuopri._test_encode  s    JJ#-F< ;CCF5M!-d==f=='<===$;;#-- %//11 < <$$SYY
;;;;	 (-< <r<   c                 2    |                      dd           d S r"  rw  r  s    r:   test_encode_nullzTestQuopri.test_encode_null  r7  r<   c                 2    |                      dd           d S )Nz

ry  r  s    r:   test_encode_null_linesz!TestQuopri.test_encode_null_lines  s    &&)))))r<   c                 2    |                      dd           d S rF  ry  r  s    r:   test_encode_one_linezTestQuopri.test_encode_one_line  rH  r<   c                 2    |                      dd           d S r@  ry  r  s    r:   test_encode_one_line_crlfz$TestQuopri.test_encode_one_line_crlf  rD  r<   c                 6    |                      ddd           d S )NrB  rA  r   r  ry  r  s    r:   test_encode_one_line_eolz#TestQuopri.test_encode_one_line_eol  s#    )[f=====r<   c                     |                      d                    d                              d          dd           d S )Nu   helloυ
rW   latin1zhello=CF=85
r   r  )rw  r   rZ   r  s    r:   (test_encode_one_line_eol_after_non_asciiz3TestQuopri.test_encode_one_line_eol_after_non_ascii  sL    /0099@@JJ+ 	 	9 	9 	9 	9 	9r<   c                 2    |                      dd           d S )Nr-   z=20ry  r  s    r:   test_encode_one_spacez TestQuopri.test_encode_one_space  s    #u%%%%%r<   c                 2    |                      dd           d S )Nz 
z=20
ry  r  s    r:   test_encode_one_line_one_spacez)TestQuopri.test_encode_one_line_one_space  s    %)))))r<   c                 2    |                      dd           d S )Nz 
 
z=20
=20
ry  r  s    r:   test_encode_two_lines_one_spacez*TestQuopri.test_encode_two_lines_one_space  s    (L11111r<   c                 2    |                      dd           d S )Nzhello   z
hello  =20ry  r  s    r:   $test_encode_one_word_trailing_spacesz/TestQuopri.test_encode_one_word_trailing_spaces  rl  r<   c                 2    |                      dd           d S )Nz	hello   
zhello  =20
ry  r  s    r:   $test_encode_one_line_trailing_spacesz/TestQuopri.test_encode_one_line_trailing_spaces  s    ,77777r<   c                 2    |                      dd           d S )Nzhello  	z
hello  =09ry  r  s    r:   !test_encode_one_word_trailing_tabz,TestQuopri.test_encode_one_word_trailing_tab  s    +|44444r<   c                 2    |                      dd           d S )Nz	hello  	
zhello  =09
ry  r  s    r:   !test_encode_one_line_trailing_tabz,TestQuopri.test_encode_one_line_trailing_tab  s    -88888r<   c                 6    |                      ddd           d S )N
abcd 
1234zabcd =

1234r  r*  ry  r  s    r:   ,test_encode_trailing_space_before_maxlinelenz7TestQuopri.test_encode_trailing_space_before_maxlinelen  s$    -)9aHHHHHr<   c                 6    |                      ddd           d S )Nr  zabcd=
=20
1234r  r*  ry  r  s    r:   (test_encode_trailing_space_at_maxlinelenz3TestQuopri.test_encode_trailing_space_at_maxlinelen  $    -);JJJJJr<   c                 6    |                      ddd           d S )Nr  zabc=
d=20
1234r   r*  ry  r  s    r:   ,test_encode_trailing_space_beyond_maxlinelenz7TestQuopri.test_encode_trailing_space_beyond_maxlinelen  r  r<   c                 2    |                      dd           d S )Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
ry  r  s    r:   test_encode_whitespace_linesz'TestQuopri.test_encode_whitespace_lines  s    )[11111r<   c                 2    |                      dd           d S )Nza = bza =3D bry  r  s    r:   test_encode_quoted_equalsz$TestQuopri.test_encode_quoted_equals   s    '9-----r<   c                 2    |                      dd           d S )Ndxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxry  r  s    r:   test_encode_one_long_stringz&TestQuopri.test_encode_one_long_string  s    )%@AAAAAr<   c                 2    |                      dd           d S )Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
ry  r  s    r:   test_encode_one_long_linez$TestQuopri.test_encode_one_long_line  s     *,NOOOOOr<   c                 2    |                      dd           d S )Nzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ry  r  s    r:   test_encode_one_very_long_linez)TestQuopri.test_encode_one_very_long_line	  s*    *8	: 	: 	: 	: 	:r<   c                 6    |                      ddd           d S )Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr   r*  ry  r  s    r:   test_encode_shortest_maxlinelenz*TestQuopri.test_encode_shortest_maxlinelen  s$    '#7AFFFFFr<   c                 N    |                      t          | j        ddd           d S )Nr,   r   r*  )r   r\  rw  r  s    r:    test_encode_maxlinelen_too_smallz+TestQuopri.test_encode_maxlinelen_too_small  s*    *d&7RANNNNNr<   c                    | j         } |t          j        d          d            |t          j        d          d            |t          j        d          d            |t          j        dd          d            |t          j        ddd	
          d            |t          j        d          d           d S )Nr,   r  r  r  dxxxx 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=20r   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)r3   r"   r  r  s     r:   r  zTestQuopri.test_encode  s    
:!"%%r***
:!'**G444
:!"233^DDD
:!,2>>> A 	 	 	
 	:!,26JJJ	 	 	
 	:! #  	 	 	 	 	r<   rg   )NN)Fr  r  r  r  r  r  r  r	  r  r  r  r  r  r  r  r   r$  r'  r)  r+  r.  r3  r6  r9  r;  r>  rC  rG  rJ  rM  rO  rQ  rT  rX  r[  r^  r`  rb  rd  rf  rh  rk  rn  rp  rr  rw  rz  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r<   r:   r  r    s\       6 6 6,L L LJ J J. . .26 6 6I I I
B B B B* * *E E EB B BB B B& & &B B B) ) )3 3 3B B BD D DK K K4 4 4 4" " "( ( (, , ,5 5 52 2 20 0 00 0 08 8 8: : :< < <D D DB B BI I I6 6 6# # #' ' '6 6 6I I ID D D4 4 44 4 4C C CF F F< < < <(" " "* * *0 0 02 2 2> > >9 9 9
& & &* * *2 2 24 4 48 8 85 5 59 9 9I I IK K KK K K2 2 2. . .B B BP P P: : :G G GO O O    r<   r  c                   &    e Zd Zd Zd Zd Zd ZdS )TestCharsetc                 F    ddl m} 	 |j        d= d S # t          $ r Y d S w xY w)Nr   rW  fake)r   rB   CHARSETSr  )r7   CharsetModules     r:   tearDownzTestCharset.tearDown0  sL    222222	&v... 	 	 	DD	s    
  c                    | j         }t          d          } ||                    d          d           d}|                     t          |j        |           t          d          } ||                    |          d           d S )NrO   Hello World!u   ¤¢¤¤¤¦¤¨¤ªrW   z(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r3   r
   r  r   r%  )r7   r8   r  r   s       r:   test_codec_encodeablez!TestCharset.test_codec_encodeable7  s    J
1??>**N;;;6,;;;G
1??1IJJJJJr<   c                    | 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 )Nr>   zhello w=F6rldu   hello wörldrW   r  r   rO   r
  r  r   rW  r  )r3   r
   r  r   rB   add_charsetQP)r7   r8   r  r  s       r:   test_body_encodezTestCharset.test_body_encodeB  s    L!!
?AMM*:;;<<<G
~!>!>???J
=!--66777H 	322222!!&-*:D'JJJFOO
=!--6677777r<   c                     t          d          }|                     t          |          d           |                     t          j        t           d           d S )NrO   u   ascÿii)r
   r3   r   r   r    CharsetErrorr  s     r:   test_unicode_charset_namez%TestCharset.test_unicode_charset_namea  sL    *%%Wz222&-wDDDDDr<   N)r  r  r  r  r  r  r  r|   r<   r:   r  r  /  sX          	K 	K 	K8 8 8>E E E E Er<   r  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )
TestHeaderc                     | j         }t          d          } ||                                d           |                    d            ||                                d           d S )Nr  z Goodbye World!zHello World!  Goodbye World!r  r   r   r,  r8  s      r:   test_simplezTestHeader.test_simplej  se    ">""
188::~&&&	"###
188::566666r<   c                     | j         }t          d          } ||                                d           |                    d            ||                                d           d S )Nr  zGoodbye World!zHello World! Goodbye World!r  r8  s      r:   test_simple_surprisezTestHeader.test_simple_surpriseq  se    ">""
188::~&&&	!"""
188::455555r<   c                 V    d}|                      t          |          |d fg           d S )Nzno decoding neededr  rC  s     r:   test_header_needs_no_decodingz(TestHeader.test_header_needs_no_decodingx  s1     q))QI;77777r<   c                     t          dd          }|                    d                              d          D ]%}|                     t	          |          d           &d S )Na  I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.r  r*  r-   )
splitcharsz
 )r   r   r   r  r  )r7   r"  ls      r:   	test_longzTestHeader.test_long|  ss      L " " "S))//66 	- 	-A  Q,,,,	- 	-r<   c                    | j         }t          d          }t          d          }t          d          }d}d}d}t          ||          }|                    ||           |                    ||           |                    d          }	 ||	d	           t          |	          }
 |t          |
          d
            ||
d         |df            ||
d         |df            ||
d         |                    d          df           t          |          } ||d                    d                     t          t          |	                    } |||           d S )Nr>   rs   rW   r%  r&  r'  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?=r   r   r   r   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,  r   r   r  r   rZ   r   )r7   r8   r   r-  r.  r/  r0  r1  r"  encr2  ustrnewhs                r:   test_multilingualzTestHeader.test_multilingual  s   "L!!\""wB$0	 61	"	D!!!hh"h%%
3 ) 	* 	* 	*  $$
3w<<
71:-...
71:.///
71:	((117;<<<1vv
4D  fWoo#	 	 	& =--..
4r<   c                 r    t                      }|                     |                                d           d S r"  rB  rC  s     r:   test_empty_header_encodez#TestHeader.test_empty_header_encode  s/    HHR(((((r<   c                     | j         }t                      } ||d           |                    dt          d                      ||d           d S )Nr,   r   r>   )r  r   r,  r
   r8  s      r:   test_header_ctor_default_argsz(TestHeader.test_header_ctor_default_args  sQ    "HH
1b				--...
1er<   c                    | j         }d}t          |          } ||                                d            |t          |          |           t          |d          } ||                                d            |t          |          |           t          |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   r   r   r   s       r:   test_explicit_maxlinelenz#TestHeader.test_explicit_maxlinelen  s    " 4LL
188:: 8 	9 	9 	9 	3q6644Y///
188:: = 	> 	> 	> 	3q6644Di@@@
188::t
3q664r<   c           
         | j         }t          dd          }d}|                    |           |                                } ||d            ||t	          t          t          |                                         t          dd          }|                    d           |                                } ||d            ||t	          t          t          |                                         d S )Nr>   r  rB   r+  r  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,  r   r   r   r   r7   r8   r"  r  r   s        r:   test_quopri_splittablez!TestHeader.test_quopri_splittable  s   "<B777	HHJJ
1 2 2	 2	 2	f 	1c+mA..//00111<B777	HHJJ
1 ! 	" 	" 	" 	1c+mA..//0011111r<   c           
         | j         }t          dd          }d}|                    |           |                                } ||d            ||t	          t          t          |                                         t          dd          }|                    |           |                                } ||d            ||t	          t          t          |                                         d S )Nrt   r  r  r  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  s        r:   test_base64_splittablez!TestHeader.test_base64_splittable$  s    "8333	HHJJ
1 " "	 "	 "	F 	1c+mA..//001118333	HHJJ
1 " 	# 	# 	# 	1c+mA..//0011111r<   c                     | j         }d}t          |          } ||dg           t          |          } |||                                           d S )Nr  )r  Nr3   r   r   r   )r7   r8   r   r  r"  s        r:   test_us_ascii_headerzTestHeader.test_us_ascii_headerZ  s\    !
1   NN
1ahhjjr<   c                 t    | j         }t                      }|                    dd            ||d           d S )Nr  r>   )r3   r   r,  r8  s      r:   test_string_charsetzTestHeader.test_string_charsetb  s:    HH	,'''
1gr<   c                     | j         }t          dd          } ||                                d           t          dd          } ||                                d           d S )NrW  rW   z=?utf-8?q?p=C3=B6stal?=u   菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=r3   r   r   r8  s      r:   test_utf8_shortestzTestHeader.test_utf8_shortestq  se    ;((
188::0111-w77
188::566666r<   c                 z   | j         }| j        }d} |t          t          |           t                      } |t          |j        |           |                    dd          } |t          t          |d                    |           |                    |d            |t          |          |           d S )N0   Ynwp4dUEbay Auction Semiar- No Charge  Earn BigrW   r   r   )r   r3   r%  r   r,  rZ   r   )r7   rL  r8   r  r"  es         r:   test_bad_8bit_headerzTestHeader.test_bad_8bit_headerx  s    "B|VQ'''HH|QXq)))HHWi((
3va	***++Q///	9%%%
3q661r<   c                 (   d}|                     dd          }t          |t          j        j                  }|                     t          |          d           |                     t          j                            |          |dfg           d S )Nr  r   surrogateescaperW  2   Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigunknown-8bit)	rZ   r   r   rB   UNKNOWN8BITr3   r   r   r   )r7   r  r  r"  s       r:   test_escaped_8bit_headerz#TestHeader.test_escaped_8bit_header  s    BHHW/001em7888QO	Q 	Q 	Q33A66!^9L8MNNNNNr<   c                     d}t          |t          j        j                  }|                     t          |          d           |                     t          j                            |          |dfg           d S Nr  rW  r  r  )r   r   rB   r  r3   r   r   r   )r7   r  r"  s      r:   &test_header_handles_binary_unknown8bitz1TestHeader.test_header_handles_binary_unknown8bit  sx    B1em7888QO	Q 	Q 	Q33A66!^9L8MNNNNNr<   c                 t   d}t          |t          j        j                  }t          j                            t          j                            |                    }|                     t          |          d           |                     t          j                            |          |dfg           d S r  )	r   r   rB   r  r   r   r   r3   r   )r7   r  r"  h2s       r:   +test_make_header_handles_binary_unknown8bitz6TestHeader.test_make_header_handles_binary_unknown8bit  s    B1em7888\%%el&@&@&C&CDDRO	Q 	Q 	Q33B771n:M9NOOOOOr<   c                     t          d          }t          j                            |          }|                    d           |                     t          |          d           d S )Nr  )r   test2)r   r   r   r   r,  r3   r   )r7   r"  r  s      r:   0test_modify_returned_list_does_not_change_headerz;TestHeader.test_modify_returned_list_does_not_change_header  sW    6NN++A..()))Q(((((r<   c                 :   | j         }t                      }|                    dd           |                    d           |                                } ||d           t	          t          |                    } ||                                |           d S )Nr  r>   worldz=?iso-8859-1?q?hello?= world)r3   r   r,  r   r   r   )r7   r8   r"  r   s       r:    test_encoded_adjacent_nonencodedz+TestHeader.test_encoded_adjacent_nonencoded  s    HH	,'''	HHJJ
1,---a(())
188::qr<   c                     | j         }d}t          |          } ||g d           t          |          } ||                                d           d S )NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.))s	   Subject: N)s     rt   )s    zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.r  )r7   r8   r   partshdrs        r:   test_whitespace_keeperz!TestHeader.test_whitespace_keeper  s    Ua  
5  Y  Y  Y  	Z  	Z  	Z%  
3::<<C	E 	E 	E 	E 	Er<   c                 P    | j         }d} |t          j        t          |           d S )NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r   r    r   r   )r7   rL  r   s      r:   test_broken_base64_headerz$TestHeader.test_broken_base64_header  s,    "fv&q99999r<   c                 x    t          dd          }|                     |                                d           d S )Nr@  	shift_jisrW  rA  rB  rC  s     r:   test_shift_jis_charsetz!TestHeader.test_shift_jis_charset  s9    5+...%EFFFFFr<   c                 t    t          j        d          }|                     t          |          d           d S )NzEmptyHeader:zEmptyHeader: 

)r   r	  r3   r   ri   s     r:   !test_flatten_header_with_no_valuez,TestHeader.test_flatten_header_with_no_value  s7     '77S#677777r<   c                 r    t                      }d|d<   |                     t          |          d           d S )Nz   value with leading ws
SomeHeaderz&SomeHeader:    value with leading ws

)r   r3   r   ri   s     r:   )test_encode_preserves_leading_ws_on_valuez4TestHeader.test_encode_preserves_leading_ws_on_value  s8    ii6LS#MNNNNNr<   c                 p    |                      t          d                                          d           d S )Nr-   r  r  s    r:   test_whitespace_headerz!TestHeader.test_whitespace_header  s0    ++--s33333r<   N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r
  r|   r<   r:   r  r  i  s       7 7 76 6 68 8 8- - -= = =~) ) )    &C2 C2 C2J42 42 42l    7 7 7
 
 
O O OO O OP P P) ) )  E E E: : :
G G G8 8 8O O O
4 4 4 4 4r<   r  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z dS ) TestRFC2231c                     | j         }|                     d          } ||                    d          d            ||                    dd          d           d S )Nz
msg_29.txtr  rO   r  %This is even more ***fun*** isn't it!Fr-  )rO   r  z'"This is even more ***fun*** isn't it!")r3   r4   rJ   r6   s      r:   r(  zTestRFC2231.test_get_param  s{    ll<((
3==!!G	I 	I 	I
3==%=00I	K 	K 	K 	K 	Kr<   c                    | j         }t                      }|                    ddd            ||                    d          d           |                    dddd            ||                    d          d           |                     d	          }|                    dddd            ||                    d
          d           d S )Nr  r  rO   rW  )rO   r,   r  r  rB   languager  r   r{  r  a"  Return-Path: <bbb@zzz.org>
Delivered-To: bbb@zzz.org
Received: by mail.zzz.org (Postfix, from userid 889)
	id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
From: bbb@ddd.com (John X. Doe)
To: bbb@zzz.org
Subject: This is a test message
Date: Fri, 4 May 2001 14:05:44 -0400
Content-Type: text/plain; charset=us-ascii;
 title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21


Hi,

Do you like this message?

-Me
)r  r   r=  rJ   r4   r   r6   s      r:   r>  zTestRFC2231.test_set_param  s   "iigG( 	 	* 	* 	*
3==!!E	G 	G 	GgG(4 	 	9 	9 	9
3==!!G	I 	I 	Ill<((gG(4 	 	9 	9 	9
3==b=)) , 	 	 	 	 	r<   c                 V   t                      }|                    dd           |                     |d         d           |                    ddd           |                     |d         d           |                    dd	d           |                     |d         d
           d S )Nr  r   rA   ztext/plain; title="foo"r  F)requoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")r   r=  r3   ri   s     r:   test_set_param_requotez"TestRFC2231.test_set_param_requote   s    iigu%%%^,.GHHHgue444^,.EFFFg{E:::^,.MNNNNNr<   c                    | j         }|                     d          }|                    dddd           |                    dddd           |                    dd	
            ||                    d          d           d S )Nr   r   r  rO   r  r  r  r  rE   r  r{  r  a$  Return-Path: <bbb@zzz.org>
Delivered-To: bbb@zzz.org
Received: by mail.zzz.org (Postfix, from userid 889)
	id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
From: bbb@ddd.com (John X. Doe)
To: bbb@zzz.org
Subject: This is a test message
Date: Fri, 4 May 2001 14:05:44 -0400
Content-Type: text/plain; charset="us-ascii";
 title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21


Hi,

Do you like this message?

-Me
)r  r4   r=  rG  r   r6   s      r:   rI  zTestRFC2231.test_del_param
  s    "ll<((eUJFFFgG 	 	/ 	/ 	/eN333
3==b=)) , 	 	 	 	 	r<   c                 z    | j         }|                     d          } ||                                d           d S )Nrq  rO   )r3   r4   get_content_charsetr6   s      r:    test_rfc2231_get_content_charsetz,TestRFC2231.test_rfc2231_get_content_charset+  s?    ll<((
3""$$j11111r<   c                     t          j        d          }t          j        |          }|                     |                                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"

            )This is even more ***fun*** is it not.pdfr   r   r   r	  r3   r~   r   rR  s      r:   test_rfc2231_parse_rfc_quotingz*TestRFC2231.test_rfc2231_parse_rfc_quoting1  z    O    '**))++D	F 	F 	FCMMOO,,,,,r<   c                     t          j        d          }t          j        |          }|                     |                                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"

            r  r  rR  s      r:    test_rfc2231_parse_extra_quotingz,TestRFC2231.test_rfc2231_parse_extra_quoting?  r  r<   c                     d}t          j        |          }|                    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r   r	  rJ   assertNotIsInstancetupler3   r7   r   r9   params       r:   #test_rfc2231_no_language_or_charsetz/TestRFC2231.test_rfc2231_no_language_or_charsetO  so     '**f%%  ...[	] 	] 	] 	] 	]r<   c                     d}t          j        |          }|                     |                                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"

r  r  rR  s      r:   /test_rfc2231_no_language_or_charset_in_filenamez;TestRFC2231.test_rfc2231_no_language_or_charset_in_filename^  S     '**))++D	F 	F 	F 	F 	Fr<   c                     d}t          j        |          }|                     |                                d           d S r*  r  rR  s      r:   7test_rfc2231_no_language_or_charset_in_filename_encodedzCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encodedk  r,  r<   c                     d}t          j        |          }|                     |                                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.pdfr  rR  s      r:   test_rfc2231_partly_encodedz'TestRFC2231.test_rfc2231_partly_encodedy  sT     '**?	A 	A 	A 	A 	Ar<   c                     d}t          j        |          }|                     |                                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%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdfr  rR  s      r:   test_rfc2231_partly_nonencodedz*TestRFC2231.test_rfc2231_partly_nonencoded  sT     '**M	O 	O 	O 	O 	Or<   c                     d}t          j        |          }|                     |                                d           d S )NzContent-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"

r  r  rR  s      r:   /test_rfc2231_no_language_or_charset_in_boundaryz;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundary  r,  r<   c                     d}t          j        |          }|                     |                                d           d S )NzContent-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r   r	  r3   r  rR  s      r:   .test_rfc2231_no_language_or_charset_in_charsetz:TestRFC2231.test_rfc2231_no_language_or_charset_in_charset  sS     '**0022D	F 	F 	F 	F 	Fr<   c                     d}t          j        |          }|                     |                                d           d S )NzContent-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"

r  r  rR  s      r:   %test_rfc2231_bad_encoding_in_filenamez1TestRFC2231.test_rfc2231_bad_encoding_in_filename  r,  r<   c                     d}t          j        |          }|                     |                                d            d S )Nz:Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D

r6  rR  s      r:   $test_rfc2231_bad_encoding_in_charsetz0TestRFC2231.test_rfc2231_bad_encoding_in_charset  E     '** 	0022D99999r<   c                     d}t          j        |          }|                     |                                d            d S )Nz:Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D

r6  rR  s      r:   %test_rfc2231_bad_character_in_charsetz1TestRFC2231.test_rfc2231_bad_character_in_charset  r<  r<   c                     d}t          j        |          }|                     |                                d           d S )NzContent-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�r  rR  s      r:   &test_rfc2231_bad_character_in_filenamez2TestRFC2231.test_rfc2231_bad_character_in_filename  sS     '**))++J	L 	L 	L 	L 	Lr<   c                     d}t          j        |          }|                     |                                d           d S )Nz^Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt


myfile.txtr  rR  s      r:   test_rfc2231_unknown_encodingz)TestRFC2231.test_rfc2231_unknown_encoding  C    
 '**))++\:::::r<   c                     d}t          j        |          }|                     |                                d           d S )Nuc   Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename*=utf-8''myfile.txt

rB  r  rR  s      r:   &test_rfc2231_bad_character_in_encodingz2TestRFC2231.test_rfc2231_bad_character_in_encoding  rD  r<   c                     | j         }d}t          j        |          }|                    d          \  }}} ||d             ||d             ||d           d S )NzJContent-Type: application/x-foo;
	name*0*="Frank's"; name*1*=" Document"

r*  Frank's Documentr'  r7   r8   r   r9   rB   r  r   s          r:   -test_rfc2231_single_tick_in_filename_extendedz9TestRFC2231.test_rfc2231_single_tick_in_filename_extended  sx    
 '**"}}V441
7D
8T
1 !!!!!r<   c                     d}t          j        |          }|                    d          }|                     |t                     |                     |d           d S )NzGContent-Type: application/x-foo; name*0="Frank's"; name*1=" Document"

r*  rH  r#  r&  s       r:   $test_rfc2231_single_tick_in_filenamez0TestRFC2231.test_rfc2231_single_tick_in_filename  s_     '**f%%  ... 233333r<   c                     d}t          j        |          }|                     |                                d           d S )NzAContent-Disposition: inline;
	filename*0*="'This%20is%20broken";
z'This is brokenr  rR  s      r:   test_rfc2231_missing_tickz%TestRFC2231.test_rfc2231_missing_tick  sO     '**	 	 	 	 	r<   c                     d}t          j        |          }|                     |                                d           d S )NzAContent-Disposition: inline;
	filename*0*="'This%20is%E2broken";
u   'This is�brokenr  rR  s      r:   0test_rfc2231_missing_tick_with_encoded_non_asciiz<TestRFC2231.test_rfc2231_missing_tick_with_encoded_non_ascii  sO     '**"	$ 	$ 	$ 	$ 	$r<   c                     | j         }d}t          j        |          }|                    d          \  }}} ||d            ||d            ||d           d S )NzYContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'Frank's"; name*1*=" Document"

r*  rO   en-usrH  r'  rI  s          r:   !test_rfc2231_tick_attack_extendedz-TestRFC2231.test_rfc2231_tick_attack_extended  sx    
 '**"}}V441
7J
8W
1 !!!!!r<   c                     d}t          j        |          }|                    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 Documentr#  r&  s       r:   test_rfc2231_tick_attackz$TestRFC2231.test_rfc2231_tick_attack&  s_    
 '**f%%  ... ABBBBBr<   c                 ~    | j         }d}t          j        |          } ||                    d          d           d S )Nz:Content-Type: application/x-foo; name="Frank's Document"

r*  rH  r'  r  s       r:   test_rfc2231_no_extended_valuesz+TestRFC2231.test_rfc2231_no_extended_values2  sH     '**
3==  "455555r<   c                     | j         }d}t          j        |          }|                    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*  rO   rR  My Document For Your'  rI  s          r:   ,test_rfc2231_encoded_then_unencoded_segmentsz8TestRFC2231.test_rfc2231_encoded_then_unencoded_segments<  x     '**"}}V441
7J
8W
1#$$$$$r<   c                     | j         }d}t          j        |          }|                    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*  rO   rR  rY  r'  rI  s          r:   ,test_rfc2231_unencoded_then_encoded_segmentsz8TestRFC2231.test_rfc2231_unencoded_then_encoded_segmentsM  r[  r<   c                     ddg}|D ]D}|                      |          5  t          j        |          }d d d            n# 1 swxY w Y   Ed S )NzFrom: user@host.com
To: user@host.com
Bad-Header:
 =?us-ascii?Q?LCSwrV11+IB0rSbSker+M9vWR7wEDSuGqmHD89Gt=ea0nJFSaiz4vX3XMJPT4vrE?=
 =?us-ascii?Q?xGUZeOnp0o22pLBB7CYLH74Js=wOlK6Tfru2U47qR?=
 =?us-ascii?Q?72OfyEY2p2=2FrA9xNFyvH+fBTCmazxwzF8nGkK6D?=

Hello!
u  From: ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ <xxx@xxx>
To: "xxx" <xxx@xxx>
Subject:   ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½
MIME-Version: 1.0
Content-Type: text/plain; charset="windows-1251";
Content-Transfer-Encoding: 8bit

ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½
)r   )r  r   r	  )r7   messagesr   r9   s       r:   +test_should_not_hang_on_invalid_ew_messagesz7TestRFC2231.test_should_not_hang_on_invalid_ew_messages\  s    "  	3 	3A"" 3 3/223 3 3 3 3 3 3 3 3 3 3 3 3 3 3	3 	3s   A  A	A	N)!r  r  r  r(  r>  r  rI  r  r  r   r(  r+  r.  r0  r2  r4  r7  r9  r;  r>  r@  rC  rF  rJ  rL  rN  rP  rS  rU  rW  rZ  r]  r`  r|   r<   r:   r  r    s       K K K# # #JO O O  B2 2 2- - -- - - ] ] ]
F 
F 
F
F 
F 
FA A AO O O
F 
F 
FF F F
F 
F 
F: : :: : :
L 
L 
L; ; ;; ; ;" " "4 4 4  $ $ $" " "	C 	C 	C6 6 6% % %"% % %3 3 3 3 3r<   r  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )
TestSignedc                     t          |d          5 }|                                }t          j        |          }d d d            n# 1 swxY w Y   ||fS rM  rN  )r7   rO  r   originalr9   s        r:   _msg_and_objzTestSigned._msg_and_objx  s    h111 	6RwwyyH+H55C	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 }s   )AAAc                    dd l } |j        d|j        |j        z            }|                    |                              d          }|                    |                              d          }|                     ||           d S )Nr   z^--([^\n]+)\n(.*?)\n--\1$r   )r  r  Sr  searchgroupr3   )r7   rd  resultr  repartinpartoutparts          r:   _signed_parts_eqzTestSigned._signed_parts_eq~  s    			8"$+FFx((..q11--''--a00&)))))r<   c                     |                      d          \  }}|                                }|                     ||           d S r  re  r   rn  r7   rd  r9   rj  s       r:   test_long_headers_as_stringz&TestSigned.test_long_headers_as_string  sB    )),77#h/////r<   c                     |                      d          \  }}|                    d          }|                     ||           d S )Nr  <   r  rp  rq  s       r:   (test_long_headers_as_string_maxheaderlenz3TestSigned.test_long_headers_as_string_maxheaderlen  sH    )),77#B//h/////r<   c                     |                      d          \  }}t                      }t          |                              |           |                                }|                     ||           d S r  )re  r   r   r   r   rn  )r7   rd  r9   r   rj  s        r:   test_long_headers_flattenz$TestSigned.test_long_headers_flatten  se    )),77#ZZ"c"""h/////r<   N)r  r  r  re  rn  rr  ru  rw  r|   r<   r:   rb  rb  v  s_          * * *0 0 0
0 0 0
0 0 0 0 0r<   rb  c                       e Zd Zd ZdS )TestHeaderRegistryc                     t                      } |dd          }|                     |j        d         t          j                   d S )NrK  zattachment; 0*00="foo"r   )r   r  r  r    InvalidHeaderDefect)r7   regr  s      r:   test_HeaderRegistryz&TestHeaderRegistry.test_HeaderRegistry  sE    C%'?@@ailF,FGGGGGr<   N)r  r  r  r}  r|   r<   r:   ry  ry    s(        H H H H Hr<   ry  __main__)ir  r=  rX   r0  r   warningsior   r   	itertoolsr   randomr   	threadingr   unittest.mockr	   r   email.policyemail.utilsemail.charsetr
   email.generatorr   r   r   email.headerr   r   r   email.headerregistryr   email.messager   email.mime.applicationr   email.mime.audior   email.mime.baser   email.mime.imager   email.mime.messager   email.mime.multipartr   email.mime.nonmultipartr   email.mime.textr   email.parserr   r   r   r   r    r!   r"   r#   r  r$   test.supportr%   test.support.os_helperr&   test.test_emailr'   r(   r)   r*   r   r  rR  r/   TestCaser  r  r  r  r  r  r  r3  r  r  r  rE  rK  r  r  r  r  rU  r  r  r  r  r  r  r  r  rb  ry  r  mainr|   r<   r:   <module>r     s  
 
			                                                       ! ! ! ! ! ! G G G G G G G G G G ; ; ; ; ; ; ; ; ; ; / / / / / / ! ! ! ! ! ! 2 2 2 2 2 2 & & & & & & $ $ $ $ $ $ & & & & & & * * * * * * . . . . . . 4 4 4 4 4 4 $ $ $ $ $ $ - - - - - - - -                                           ) ) ) ) ) ) ) ) ) ) ) ) 3 3 3 3 3 3 3 3 5 4 4 4 4 4 4 4	r r r r r] r r rl? ? ? ? ?8$ ? ? ?Fx> x> x> x> x>m x> x> x>zK/ K/ K/ K/ K/x( K/ K/ K/^/D /D /D /D /DH% /D /D /Dh7D 7D 7D 7D 7DH% 7D 7D 7DvXC XC XC XC XC(+ XC XC XCx7A 7A 7A 7A 7A8$ 7A 7A 7Ax~6 ~6 ~6 ~6 ~6M ~6 ~6 ~6BkK kK kK kK kK kK kK kK^}< }< }< }< }<- }< }< }<BsK sK sK sK sKm sK sK sKn		J 	J 	J 	J 	J} 	J 	J 	J"Z- Z- Z- Z- Z-] Z- Z- Z-~nH nH nH nH nH nH nH nHdd( d( d( d( d(M d( d( d(N-A -A -A -A -Am -A -A -A`QK QK QK QK QK- QK QK QKh[ [ [ [ [M [ [ [|- - - - - - - -$3 3 3 3 3%E$23 3 38 8 8 8 8'G'58 8 81D 1D 1D 1D 1D" 1D 1D 1Dh} } } } }" } } }D
5E 5E 5E 5E 5E(# 5E 5E 5Eta4 a4 a4 a4 a4 a4 a4 a4La3 a3 a3 a3 a3- a3 a3 a3N0 0 0 0 0 0 0 0BH H H H H H H H zHMOOOOO r<   