
    daf R                    .   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlZd dlZd dlmZ d dlmZmZmZ d d	lmZmZ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l.m/Z/ d dl0m1Z1m2Z2 d dlm3Z3 d dlm4Z4 d dlm5Z5 d dlm6Z6 d dlm7Z7 d dlm8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@mAZA d dl0mBZB d ZCd!ZDd"ZE G d# d$eA      ZF G d% d&ej                        ZH G d' d(eA      ZI G d) d*ej                        ZJ G d+ d,ej                        ZK G d- d.ej                        ZL G d/ d0ej                        ZM G d1 d2ej                        ZN G d3 d4eA      ZO G d5 d6eA      ZP G d7 d8eA      ZQ G d9 d:eA      ZR G d; d<eA      ZS G d= d>eA      ZT G d? d@eA      ZU G dA dBeA      ZV G dC dDeA      ZW G dE dFeA      ZX G dG dHeA      ZY G dI dJ      ZZ G dK dLeZeT      Z[ G dM dNeZeT      Z\ G dO dPej                        Z] G dQ dRej                        Z^ G dS dTej                        Z_ G dU dVeA      Z` G dW dXeA      Za G dY dZeA      Zb G d[ d\eA      Zcedd]k(  r ej                          yy)^    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
  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 ZXyW)XTestMessageAPIc                     | j                   }| j                  d      } ||j                  d      g d        ||j                  dd      d       y )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      5/root/Python-3.12.4/Lib/test/test_email/test_email.pytest_get_allzTestMessageAPI.test_get_all9   sD    ll<(
3;;tKL
3;;tU#U+    c                    | j                   }t               } ||j                         d        t        d      }|j	                  |        ||d   d        ||j                         d        ||d   d        ||j                  d      d        ||d   d	        ||j                         j                  d       |j	                  d         ||j                         d         ||d   d       t               }d
|d<   d|d<   d|d<   |j	                  |        ||d   d
        ||d   d        ||d   d       y )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")r2   r   get_charsetr
   set_charsetget_content_type	get_paraminput_charsetr6   r7   r8   rA   s       r9   test_getset_charsetz"TestMessageAPI.test_getset_charset?   s6   i
3??d#,' 
3~&
3!<0
3~ BC
3==#\2
3*+-?@
3??**L9
3??d#
3~-i#N,N+='( 
3~&
3~ DE
3*+-?@r;   c                     | j                   }t               }|j                  d        ||j                         j                  d        ||d   d       y )Nus-asciir@   text/plain; charset="us-ascii")r2   r   rG   rF   rJ   r5   s      r9   test_set_charset_from_stringz+TestMessageAPI.test_set_charset_from_stringY   sG    i
#
3??**J7
3~ @Ar;   c                     t               }t        d      }|j                  d|       | j                  |j	                         j
                  d       y )Nr=   zThis is a string payload)r   r
   set_payloadr2   rF   rJ   )r6   r8   rA   s      r9   test_set_payload_with_charsetz,TestMessageAPI.test_set_payload_with_charset`   s?    i,'2G<*88,Gr;   c                    d}t        d      }t               }|j                  ||       | j                  |d   d       | j                  |j	                  d      |       | j                  |j	                         d       y )N   АБВutf-8rB   base64Tdecodez	0JDQkdCS
)r
   r   rR   r2   get_payloadr6   datarA   r8   s       r9   +test_set_payload_with_8bit_data_and_charsetz:TestMessageAPI.test_set_payload_with_8bit_data_and_charsetf   sn    *'"ig&898D5t<*L9r;   c                     d}t        d      }d |_        t               }|j                  |j	                  d      |       | j                  |d   d       | j                  |j                  d      |       y NrU   rV   rB   8bitTrX   )r
   body_encodingr   rR   rY   r2   rZ   r[   s       r9   >test_set_payload_with_non_ascii_and_charset_body_encoding_nonezMTestMessageAPI.test_set_payload_with_non_ascii_and_charset_body_encoding_noneo   sh    *'" $iG,g6896B5t<r;   c                     d}t        d      }d |_        t               }|j                  ||       | j	                  |d   d       | j	                  |j                  d      |       y r_   )r
   ra   r   rR   r2   rZ   r[   s       r9   >test_set_payload_with_8bit_data_and_charset_body_encoding_nonezMTestMessageAPI.test_set_payload_with_8bit_data_and_charset_body_encoding_nonex   s_    *'" $ig&896B5t<r;   c                 z    t               }|j                  g        | j                  |j                         g        y Nr   rR   r2   rZ   r6   r8   s     r9   test_set_payload_to_listz'TestMessageAPI.test_set_payload_to_list   s,    i*B/r;   c                     t               }d|d<   |j                  d       t        t                     }| j                  t        d|j
                  |       y )Nmultipart/mixedrD   zstring payloadz[Aa]ttach.*non-multipart)r   rR   r   assertRaisesRegex	TypeErrorattach)r6   r8   sub_msgs      r9   "test_attach_when_payload_is_stringz1TestMessageAPI.test_attach_when_payload_is_string   sH    i/N()gi(y*D"zz7	4r;   c                 &   | j                   }| j                  d      }|j                         } ||g d       | j                  d      }|j                  d      } ||g d       | j                  d      }|j                         } ||g d       y )Nz
msg_08.txt)NrN   r=   
iso-8859-2koi8-rz
msg_09.txtdingbat)rt   rN   r=   rt   rs   z
msg_12.txt)NrN   r=   Nrr   z
iso-8859-3rN   rs   )r2   r3   get_charsets)r6   r7   r8   charsetss       r9   test_get_charsetsz TestMessageAPI.test_get_charsets   s    ll<(##%
8MNll<(##I.
8   	! ll<(##%
8 : 	;r;   c                 &   | j                   }| j                  d      }|j                         D cg c]  }|j                          }} ||ddg       | j                  d      }|j                  d      } ||j                         d       y c c}w )N
msg_04.txtmsg.txt
msg_07.txt   dingusfish.gifr2   r3   rZ   get_filename)r6   r7   r8   p	filenamessubparts         r9   test_get_filenamez TestMessageAPI.test_get_filename   s    ll<(/2/@A!Q^^%A	A
9y),-ll<(//!$
7!#34 Bs   Bc                     | j                   }| j                  d      }|j                         D cg c]  }|j                          }} ||ddg       y c c}w )Nz
msg_44.txtrz   r~   )r6   r7   r8   r   r   s        r9   %test_get_filename_with_name_parameterz4TestMessageAPI.test_get_filename_with_name_parameter   sQ    ll<(/2/@A!Q^^%A	A
9y),- Bs   Ac                 l    | j                   }| j                  d      } ||j                         d       y )Nr{   BOUNDARY)r2   r3   get_boundaryr5   s      r9   test_get_boundaryz TestMessageAPI.test_get_boundary   s.    ll<(
3z*r;   c                    | j                   }| j                  d      }|j                  d       |j                         d   \  }} ||j	                         d        ||d       | j                  d      }|j                  d       |j                         d   \  }} ||j	                         d        ||d       | j                  d      }| j                  t        j                  |j                  d       y )	N
msg_01.txtr      r@   z3text/plain; charset="us-ascii"; boundary="BOUNDARY"ry   z$multipart/mixed; boundary="BOUNDARY"
msg_03.txt)r2   r3   set_boundaryitemslowerassertRaisesr    HeaderParseError)r6   r7   r8   headervalues        r9   test_set_boundaryz TestMessageAPI.test_set_boundary   s     ll<($		A
6<<>>*
5GH ll<($		A
6<<>>*
589ll<(&11**J	8r;   c                     t        d      }| j                  |j                         d   d   d       |j                          | j                  |j                         d   d   d d d       y )Nz	form-datar   r|   zmultipart/form-data!   z!multipart/form-data; boundary="==)r   r2   r   	as_stringrh   s     r9   test_make_boundaryz!TestMessageAPI.test_make_boundary   s`    K( 	Q*,ABQ*3B/;	=r;   c                 0   t        dd      5 }|j                         }d d d        t               }|j                        }t	               }t        |dd      }|j                  |d       | j                  |j                         |       y # 1 sw Y   nxY w)N
msg_46.txtrV   encodingTr   F)	r'   readr   parsestrr   r   flattenr2   getvaluer6   fpmsgdataparserr8   outgens          r9   test_message_rfc822_onlyz'TestMessageAPI.test_message_rfc822_only   s~     lW5 	 ggiG	 oog&jT1%C1	  	 s   BBc                    t        dd      5 }|j                         j                  d      }d d d        t        j                  j                         }|j                        }t               }t        j                  j                  |      }|j                  |       | j                  |j                         |       y # 1 sw Y   xY w)Nr   rV   r   ascii)r'   r   encodeemailr   BytesHeaderParser
parsebytesr   	generatorr   r   r2   r   r   s          r9   test_byte_message_rfc822_onlyz,TestMessageAPI.test_byte_message_rfc822_only   s    lW5 	0ggi&&w/G	0//1(ioo,,S1C1	0 	0s    C  C	c                     | j                   }| j                  d      } ||j                  d      d         ||j                  d      j                  d      d        ||j                  d      j                  d      d        ||j                  d      j                  d      d	        ||j                  d
      j                  d      d        ||j                  d      j                  d      d       y )Nz
msg_10.txtTrX   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.
)r2   r3   rZ   r5   s      r9   test_get_decoded_payloadz'TestMessageAPI.test_get_decoded_payload   s    ll<(
3??$?'.
3??1)))6/	1 	3??1)))6?	A 	3??1)))6/	1 	3??1)))61	3 	3??1)))6>	@r;   c                     | j                   }t               }|j                  d       dD ]   }||d<    ||j                  d      d       " |j                  d        ||j                  d      d       y )	Nz$begin 666 -
+:&5L;&\@=V]R;&0 
 
end
z
x-uuencodeuuencodeuuezx-uuerB   TrX      hello worldfoos   foo)r2   r   rR   rZ   )r6   r7   r8   ctes       r9   test_get_decoded_uu_payloadz*TestMessageAPI.test_get_decoded_uu_payload  ss    iCD= 	=C/2C+,sd+^<	= 	
3??$?'0r;   c                 Z    t               }| j                  t        |j                  d       y )Nr|   )r   r   rm   rZ   rh   s     r9   *test_get_payload_n_raises_on_non_multipartz9TestMessageAPI.test_get_payload_n_raises_on_non_multipart  s    i)S__a8r;   c                    | j                   }| j                  d      }t        dd      5 }|j                         }d d d        t	               }t        |      }|j                  |        ||j                                y # 1 sw Y   GxY w)Nr{   z
msg_17.txtrV   r   )r2   r3   r'   r   r   r   r   r   )r6   r7   r8   r   textsgs          r9   test_decoded_generatorz%TestMessageAPI.test_decoded_generator  ss    ll<(lW5 	779D	JQ			#
1::<	 	s   BBc                    t               }d|d<   d|d<   | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y )	NMeFromYoutofromFROMToTO)r   assertInrh   s     r9   test__contains__zTestMessageAPI.test__contains__  so    iFD	fc"fc"fc"dC dC dC r;   c                    | j                  d      }t        dd      5 }|j                         }d d d        | j                  t	        |             |j                  d      }|j                  d      }| j                  |d   j                  d             | j                  |t        j                  |d	d               y # 1 sw Y   xY w)
Nr   rV   r   Tunixfromr*   r   zFrom r|   )r3   r'   r   r2   strr   split
assertTrue
startswithNLjoin)r6   r8   r   r   fullreprliness         r9   test_as_stringzTestMessageAPI.test_as_string*  s    ll<(lW5 	779D	s3x(==$=/t$a++G45rwwuQRy12	 	s   CCc                    | j                  d      }|j                  j                  d      }|j                  |      }t	               }t        ||      }|j                  |       | j                  ||j                                y Nr   
lineseppolicy)	r3   r   cloner   r   r   r   r2   r   r6   r8   	newpolicyr   r   r   s         r9   test_as_string_policyz$TestMessageAPI.test_as_string_policy4  sk    ll<(JJ$$V$4	==	=2Ja	*			#1::<0r;   c                     t        j                  d      }|j                  d      }t        j                  d      }t        j                  |      }| j                  |j                         |       y )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_bytesr2   r   r6   msourceexpectedr8   s        r9   #test_nonascii_as_string_without_ctez2TestMessageAPI.test_nonascii_as_string_without_cte=  s`    OO   ,'?? $  &&v.(3r;   c                     t        j                  d      }|j                  d      }|j                  dd      }t	        j
                  |      }| j                  |j                         |       y )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   rY   r   r   r2   r   r   s        r9   *test_nonascii_as_string_with_ascii_charsetz9TestMessageAPI.test_nonascii_as_string_with_ascii_charsetS  s[    OO   ,'==)4&&v.(3r;   c                     t        j                  d      }|j                  d      }|j                  dd      }t	        j
                  |      }| j                  |j                         |       y )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        r9   4test_nonascii_as_string_without_content_type_and_ctezCTestMessageAPI.test_nonascii_as_string_without_content_type_and_cteb  s[    OO   ,'==)4&&v.(3r;   c                    | j                  d      }t        dd      5 }|j                         j                  d      }d d d        | j	                  t        |             |j                  d      }|j                  d      }| j                  |d   j                  d	             | j	                  |dj                  |d
d               y # 1 sw Y   xY w)Nr   rV   r   r   Tr      
r   s   From r|   )r3   r'   r   r   r2   bytesas_bytesr   r   r   r   )r6   r8   r   r\   r   r   s         r9   test_as_byteszTestMessageAPI.test_as_byteso  s    ll<(lW5 	-779##G,D	-uSz*<<<.u%a++H56uzz%)45	- 	-s    CCc                    | j                  d      }|j                  j                  d      }|j                  |      }t	               }t        ||      }|j                  |       | j                  ||j                                y r   )	r3   r   r   r   r   r   r   r2   r   r   s         r9   test_as_bytes_policyz#TestMessageAPI.test_as_bytes_policyy  sk    ll<(JJ$$V$4	<<y<1I1I.			#1::<0r;   c                 p    t        j                  d      }| j                  |j                  d      d       y )NzContent-Type: blarg; baz; boo
bazr+   r   message_from_stringr2   rI   rh   s     r9   test_bad_paramzTestMessageAPI.test_bad_param  s,    ''(IJu-r2r;   c                 n    t        j                  d      }| j                  |j                         d        y Nz
From: foo
r   r   r2   r   rh   s     r9   test_missing_filenamez$TestMessageAPI.test_missing_filename  +    ''6))+T2r;   c                 n    t        j                  d      }| j                  |j                         d       y )Nz%Content-Disposition: blarg; filename
r+   r  rh   s     r9   test_bogus_filenamez"TestMessageAPI.test_bogus_filename  s.    ''02))+R0r;   c                 n    t        j                  d      }| j                  |j                         d        y r  r   r   r2   r   rh   s     r9   test_missing_boundaryz$TestMessageAPI.test_missing_boundary  r  r;   c                 j   | j                   }t        j                  d      } ||j                  d      g d       t        j                  d      } ||j                  d      g d        ||j                         d        t        j                  d      } ||j                  d      g d       y )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
)r2   r   r   
get_paramsr5   s      r9   test_get_paramszTestMessageAPI.test_get_params  s    ''57
3>>>,=	?''/1
3>>>,8	:
3>>T"''13
3>>>,8	:r;   c                 d    t               }d|d<   | j                  |j                  d      d       y )Nz>Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"rD   boundaryCPIMSSMTPC06p5f3tG)r   r2   rI   rh   s     r9   test_get_param_liberalz%TestMessageAPI.test_get_param_liberal  s-    i^Nz24HIr;   c                    | j                   }t        j                  d      } ||j                  dd      d        ||j                  dd      d         ||j                  d      d        t        j                  d      } ||j                  dd      d	        ||j                  dd      d
        ||j                  dd      d       y )Nr  r  r  r  r  quuzr  r   r+   r  r   r2   r   r   rI   r5   s      r9   test_get_paramzTestMessageAPI.test_get_param  s    ''57
3==z=2E:
3==
=3T:
3== $'''13
3==z=2B7
3==z=2E:
3==z=2E:r;   c                     | j                  d      }| j                  |j                  d      j                  d      d       y )Nz
msg_22.txtr|   namez
wibble.JPG)r3   r2   rZ   rI   rh   s     r9   'test_get_param_funky_continuation_linesz6TestMessageAPI.test_get_param_funky_continuation_lines  s4    ll<(+55f=|Lr;   c                     t        j                  d      }| j                  |j                  d      d       | j                  |j                  dd      d       y )Nz4Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"
r   zJim&amp;&amp;JillFunquotez"Jim&amp;&amp;Jill"r   rh   s     r9   #test_get_param_with_semis_in_quotesz2TestMessageAPI.test_get_param_with_semis_in_quotes  sP    ''CEv.0CDvu=.	0r;   c                     t        j                  d      }| j                  |j                  d      d       t        j                  d      }| j                  |j                  d      d       y )Nz5Content-Type: foo; bar*0="baz\"foobar"; bar*1="\"baz"r  zbaz"foobar"bazr   rh   s     r9   test_get_param_with_quotesz)TestMessageAPI.test_get_param_with_quotes  s^    ''EGu-/?@''KMu-/?@r;   c                     t        j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       y )NzHeader: existsr   r   HEADERheaderx)r   r   r   assertNotInrh   s     r9   test_field_containmentz%TestMessageAPI.test_field_containment  sM    ''(89h$h$h$C(r;   c                    | j                   }t               }|j                  dd        ||j                  d      d       |j                  dd        ||j                  d      d        ||j                  dd      d        ||j	                         g d        ||j	                  d      g d	       |j                  dd
d        ||j                  dd      d
       y )NrA   iso-2022-jp
importance
high valueFr#  "high value")r?   r+   )rA   r.  )r/  r0  )r2  )rA   z"iso-2022-jp")r/  r1  ziso-9999-xxzX-Jimmyr  )r2   r   	set_paramrI   r  r5   s      r9   test_set_paramzTestMessageAPI.test_set_param  s    ii/
3==#]3lL1
3==&5
3==u=5~F
3>> < 	= 	3>>%>( +G 	H 	iyA
3==9=5}Er;   c                 B   | j                   }| j                  d      } ||j                         g d       |j                  d      }|j	                  d        ||j                         ddg       |j                  d|        ||j                         ddd|fg       y )N
msg_05.txt)multipart/reportr+   )report-typedelivery-statusr  %D1690A7AC1.996856090/mail.example.comr9  r7  r;  )r2   r3   r  rI   	del_paramr3  )r6   r7   r8   old_vals       r9   test_del_paramzTestMessageAPI.test_del_param  s    ll<(
3>>C	D --.m$
3>>$AC	D 	mW-
3>>$AG$&	'r;   c                     t               }|j                  ddd       |j                  dd       | j                  |d   d       y )NContent-Disposition
attachmentbud.giffilenamerE  content-dispositionr   
add_headerr=  r2   rh   s     r9   test_del_param_on_other_headerz-TestMessageAPI.test_del_param_on_other_header  sA    i,lYOj"7823\Br;   c                 <    t               }|j                  dd       y )NrE  rF  )r   r=  rh   s     r9   $test_del_param_on_nonexistent_headerz3TestMessageAPI.test_del_param_on_nonexistent_header   s    ij"78r;   c                     t               }|j                  ddd       |d   }|j                  dd       | j                  |d   |       y )NrD   r?   rV   rA   foobarr  rG  )r6   r8   existing_headers      r9   test_del_nonexistent_paramz)TestMessageAPI.test_del_nonexistent_param  sJ    i~|WEn-h~6^,o>r;   c                 "   | j                   }t               }| j                  t        |j                  d       |j	                  d        ||d   d       |j                  dd        ||d   d       |j	                  d        ||d   d       y )	Nr   r?   r@   rA   rN   rO   z	text/htmlztext/html; charset="us-ascii")r2   r   r   
ValueErrorset_typer3  r5   s      r9   test_set_typezTestMessageAPI.test_set_type  s    i*cllF;\"
3~-i,
3~ @A[!
3~ ?@r;   c                 p    t               }d|d<   |j                  dd       | j                  |d   d       y )Nr?   zX-Content-Typeapplication/octet-streamzx-content-type)r   rS  r2   rh   s     r9   test_set_type_on_other_headerz,TestMessageAPI.test_set_type_on_other_header  s;    i ,/1AB-.0JKr;   c                 X    t               }| j                  |j                         d       y )Nr?   )r   r2   rH   rh   s     r9   test_get_content_type_missingz,TestMessageAPI.test_get_content_type_missing  s"    i--/>r;   c                 z    t               }|j                  d       | j                  |j                         d       y )Nmessage/rfc822)r   set_default_typer2   rH   rh   s     r9   /test_get_content_type_missing_with_default_typez>TestMessageAPI.test_get_content_type_missing_with_default_type!  s2    i-.--/1ABr;   c                     | j                  d      }| j                  |j                  d      j                         d       y )N
msg_30.txtr   r[  r3   r2   rZ   rH   rh   s     r9   +test_get_content_type_from_message_implicitz:TestMessageAPI.test_get_content_type_from_message_implicit&  5    ll<(+<<>)	+r;   c                     | j                  d      }| j                  |j                  d      j                         d       y )N
msg_28.txtr   r[  r`  rh   s     r9   +test_get_content_type_from_message_explicitz:TestMessageAPI.test_get_content_type_from_message_explicit+  rb  r;   c                 f    | j                  d      }| j                  |j                         d       y )Nr   r?   r3   r2   rH   rh   s     r9   6test_get_content_type_from_message_text_plain_implicitzETestMessageAPI.test_get_content_type_from_message_text_plain_implicit0  )    ll<(--/>r;   c                 f    | j                  d      }| j                  |j                         d       y )Nr   r?   rg  rh   s     r9   6test_get_content_type_from_message_text_plain_explicitzETestMessageAPI.test_get_content_type_from_message_text_plain_explicit4  ri  r;   c                 X    t               }| j                  |j                         d       y )Nr   r   r2   get_content_maintyperh   s     r9   !test_get_content_maintype_missingz0TestMessageAPI.test_get_content_maintype_missing8  s"    i113V<r;   c                 z    t               }|j                  d       | j                  |j                         d       y )Nr[  message)r   r\  r2   rn  rh   s     r9   3test_get_content_maintype_missing_with_default_typezBTestMessageAPI.test_get_content_maintype_missing_with_default_type<  s1    i-.113Y?r;   c                     | j                  d      }| j                  |j                  d      j                         d       y )Nr_  r   rq  r3   r2   rZ   rn  rh   s     r9   /test_get_content_maintype_from_message_implicitz>TestMessageAPI.test_get_content_maintype_from_message_implicitA  2    ll<(+@@BINr;   c                     | j                  d      }| j                  |j                  d      j                         d       y )Nrd  r   rq  rt  rh   s     r9   /test_get_content_maintype_from_message_explicitz>TestMessageAPI.test_get_content_maintype_from_message_explicitE  rv  r;   c                 f    | j                  d      }| j                  |j                         d       y )Nr   r   r3   r2   rn  rh   s     r9   :test_get_content_maintype_from_message_text_plain_implicitzITestMessageAPI.test_get_content_maintype_from_message_text_plain_implicitI  )    ll<(113V<r;   c                 f    | j                  d      }| j                  |j                         d       y )Nr   r   rz  rh   s     r9   :test_get_content_maintype_from_message_text_plain_explicitzITestMessageAPI.test_get_content_maintype_from_message_text_plain_explicitM  r|  r;   c                 X    t               }| j                  |j                         d       y )Nplainr   r2   get_content_subtyperh   s     r9    test_get_content_subtype_missingz/TestMessageAPI.test_get_content_subtype_missingQ  s"    i002G<r;   c                 z    t               }|j                  d       | j                  |j                         d       y )Nr[  rfc822)r   r\  r2   r  rh   s     r9   2test_get_content_subtype_missing_with_default_typezATestMessageAPI.test_get_content_subtype_missing_with_default_typeU  s1    i-.002H=r;   c                     | j                  d      }| j                  |j                  d      j                         d       y )Nr_  r   r  r3   r2   rZ   r  rh   s     r9   .test_get_content_subtype_from_message_implicitz=TestMessageAPI.test_get_content_subtype_from_message_implicitZ  2    ll<(+??A8Lr;   c                     | j                  d      }| j                  |j                  d      j                         d       y )Nrd  r   r  r  rh   s     r9   .test_get_content_subtype_from_message_explicitz=TestMessageAPI.test_get_content_subtype_from_message_explicit^  r  r;   c                 f    | j                  d      }| j                  |j                         d       y )Nr   r  r3   r2   r  rh   s     r9   9test_get_content_subtype_from_message_text_plain_implicitzHTestMessageAPI.test_get_content_subtype_from_message_text_plain_implicitb  )    ll<(002G<r;   c                 f    | j                  d      }| j                  |j                         d       y )Nr   r  r  rh   s     r9   9test_get_content_subtype_from_message_text_plain_explicitzHTestMessageAPI.test_get_content_subtype_from_message_text_plain_explicitf  r  r;   c                 b    t               }d|d<   | j                  |j                         d       y )Nno-slash-in-this-stringrD   r   rm  rh   s     r9   test_get_content_maintype_errorz.TestMessageAPI.test_get_content_maintype_errorj  s,    i7N113V<r;   c                 b    t               }d|d<   | j                  |j                         d       y )Nr  rD   r  r  rh   s     r9   test_get_content_subtype_errorz-TestMessageAPI.test_get_content_subtype_erroro  s,    i7N002G<r;   c                 x   | j                   }t               }|j                  dd       |j                  dd       |j                  dd        ||j                         g d        ||j	                         g d       |j                  dd	        ||j                         g d        ||j	                         g d
       |j                  dd       |j                  dd        ||j                         g d        ||j	                         g d       | j                  t        |j
                  dd       y )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)r2   r   rH  keysvaluesreplace_headerr   KeyErrorr5   s      r9   test_replace_headerz"TestMessageAPI.test_replace_headert  s    iw&x'w(
388:34
3::<018X.
388:34
3::<34w)7M2
388:<=
3::<EF(C$6$6)Lr;   c                    t               }| j                  |j                                |j                  ddd       | j	                  |j                         d       |j                  dd       | j	                  |j                         d       |j                  dd       | j	                  |j                         d       y )NrA  rB  z
random.avirD  inlineInlinE)r   assertIsNoneget_content_dispositionrH  r2   r  rh   s     r9   test_get_content_dispositionz+TestMessageAPI.test_get_content_disposition  s    i#5578,l , 	 	.446E0(;446A0(;446Ar;   c                     d}t               }d|d<   d|d<   |j                  |       | j                  |j                  d      d       | j	                  |j
                  d	   t        j                         y )
NzAwDp0P7//y6LwKEAcPa/6Q=9zaudio/x-midir@   rW   rB   TrX   s    . pr   )r   rR   r2   rZ   assertIsInstancedefectsr    InvalidBase64CharactersDefectr6   xr8   s      r9   test_broken_base64_payloadz)TestMessageAPI.test_broken_base64_payload  ss    &i,N+3'(57	9 	ckk!n$BB	Dr;   c                     d}t               }d|d<   d|d<   |j                  |       | j                  |j                  d      t	        |d             y )	Nu   this is a bröken thing to dor?   r@   r`   rB   TrX   zraw-unicode-escape)r   rR   r2   rZ   r   r  s      r9   test_broken_unicode_payloadz*TestMessageAPI.test_broken_unicode_payload  sW     .i*N+1'(5q"67	9r;   c                     dj                  d      }t               }d|d<   d|d<   ||_        | j                  |j	                  d      |       y )	Nu#   this is a quéstionable thing to dorV   text/plain; charset="utf-8"r@   r`   rB   TrX   )r   r   _payloadr2   rZ   r  s      r9   test_questionable_bytes_payloadz.TestMessageAPI.test_questionable_bytes_payload  sR     288Ai;N+1'(5q9r;   c                 j    t               }|j                  ddd       | j                  d|d          y )NrA  rB  rC  rD  zattachment; filename="bud.gif"r   rH  r2   rh   s     r9   test_ascii_add_headerz$TestMessageAPI.test_ascii_add_header  s<    i,l ) 	 	+9%&	(r;   c                 j    t               }|j                  ddd       | j                  d|d          y )NrA  rB     Fußballer.pptrD  z/attachment; filename*=utf-8''Fu%C3%9Fballer.pptr  rh   s     r9   test_noascii_add_headerz&TestMessageAPI.test_noascii_add_header  s<    i,l% 	 	'?%&	(r;   c                 j    t               }|j                  ddd       | j                  d|d          y )NrA  rB  )r=   r+   r  rD  z1attachment; filename*=iso-8859-1''Fu%DFballer.pptr  rh   s     r9   #test_nonascii_add_header_via_triplez2TestMessageAPI.test_nonascii_add_header_via_triple  s<    i,l9 	 	;A%&	(r;   c                 j    t               }|j                  ddd       | j                  d|d          y )NrA  rB  zwindows [filename].pptrD  z-attachment; filename="windows [filename].ppt"r  rh   s     r9   #test_ascii_add_header_with_tspecialz2TestMessageAPI.test_ascii_add_header_with_tspecial  s<    i,l- 	 	/;%&	(r;   c                 j    t               }|j                  ddd       | j                  d|d          y )NrA  rB  u   Fußballer [filename].pptrD  z@attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.pptr  rh   s     r9   &test_nonascii_add_header_with_tspecialz5TestMessageAPI.test_nonascii_add_header_with_tspecial  s<    i,l0 	 	2N%&	(r;   c                     dD ]P  }t               }d|z  |d<   d|d<   |j                  d       | j                  |j                  d      d	d
|z         R y )Nlatin-1r   text/plain; charset=%sr@   rC   rB   s   foo=e6=96=87barTrX   	   foo文bar1get_payload returns wrong result with charset %s.rg   r6   rA   r8   s      r9   test_binary_quopri_payloadz)TestMessageAPI.test_binary_quopri_payload  si    + 	OG)C":W"DC/AC+,OO./t,%CgMO	Or;   c                     dD ]P  }t               }d|z  |d<   d|d<   |j                  d       | j                  |j                  d      d	d
|z         R y )Nr  r  r@   rW   rB   s   Zm9v5paHYmFyTrX   r  r  rg   r  s      r9   test_binary_base64_payloadz)TestMessageAPI.test_binary_base64_payload  sh    + 	OG)C":W"DC/7C+,OOO,t,%CgMO	Or;   c           
          dD ]m  }dD ]f  }t               }d|z  |d<   ||d<   |j                  d       | j                  |j                  d      d	t	        d
      j                  ||             h o y )Nr  r   r  r@   rB   s    begin 666 -
)9F]OYI:'8F%R
 
end
TrX   r  )z!get_payload returns wrong result z"with charset {0} and encoding {1}.)r   rR   r2   rZ   r   format)r6   rA   r   r8   s       r9   test_binary_uuencode_payloadz+TestMessageAPI.test_binary_uuencode_payload  s    + 	3GF 
3i&>&HN#3;/0 GH  OO4O0) ? @w13
3	3r;   c                 j    t               }|j                  ddd        | j                  d|d          y )NrA  r  )foo_barzinline; foo-barr  rh   s     r9   $test_add_header_with_name_only_paramz3TestMessageAPI.test_add_header_with_name_only_param  s3    i,hE*C0E,FGr;   c                 f    t               }|j                  dd        | j                  d|d          y )NzX-Statusr+   r  rh   s     r9   test_add_header_with_no_valuez,TestMessageAPI.test_add_header_with_no_value  s+    iz4(S_-r;   c                     t               }t        d      |d<   | j                  t        j                  |j
                         y Nzdummy
X-Injected-Header: testDummy)r   r   r   r    r   r   rh   s     r9   (test_embedded_header_via_Header_rejectedz7TestMessageAPI.test_embedded_header_via_Header_rejected
  s2    i>?G&113==Ar;   c                 v    t               }d|d<   | j                  t        j                  |j                         y r  )r   r   r    r   r   rh   s     r9   (test_embedded_header_via_string_rejectedz7TestMessageAPI.test_embedded_header_via_string_rejected  s,    i7G&113==Ar;   c                     t        d      }d|d<   | j                  t        |      t        j                  d             y )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   r2   r   r   r   r6   r   s     r9   -test_unicode_header_defaults_to_utf8_encodingz<TestMessageAPI.test_unicode_header_defaults_to_utf8_encoding  s9    W )Q 1 ! 	r;   c                 v    t        d      }| j                  t        |      t        j                  d             y )Nu   É testabc
z            Content-Type: text/plain; charset="utf-8"
            MIME-Version: 1.0
            Content-Transfer-Encoding: base64

            w4kgdGVzdGFiYwo=
            r  r  s     r9   +test_unicode_body_defaults_to_utf8_encodingz:TestMessageAPI.test_unicode_body_defaults_to_utf8_encoding!  s0    ^$Q 1 ! 	r;   N)Y__name__
__module____qualname__r:   rL   rP   rS   r]   rb   rd   ri   rp   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r!  r%  r'  r,  r4  r?  rI  rK  rP  rT  rW  rY  r]  ra  re  rh  rk  ro  rr  ru  rx  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r;   r9   r.   r.   8   s   ,A4BH:==0
4;"	5.+8,=
2	2@,	19
!314,4461331
3:"J
;$M
0A)F"'"C9
?	AL?C
+
+
??=@
OO===>
MM===
=
M"	B
D	9:(((((	O	O3H
.B
B
	r;   r.   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestEncodersc           
      h   t        dd      5 }|j                         }d d d        t        j                  j                  j                        }|j                         }|j                  d      }| j                  t        |D cg c]  }t        |       c}      d       y # 1 sw Y   xY wc c}w )N
python.gifrbr*   L   )r'   r   r   mimeimager   rZ   r   assertLessEqualmaxlen)r6   r   bindatamimedbase64edr   r  s          r9   test_EncodersEncode_base64z'TestEncoders.test_EncodersEncode_base640  s    lD) 	 RggiG	 

  **73$$&t$S5!:a3q6!:;R@	  	  ";s   B#B/#B,c                 j    | j                   }t               }|j                  d        ||d   d       y )NrN   rB   7bit)r2   r   rG   r5   s      r9   test_encode_empty_payloadz&TestEncoders.test_encode_empty_payload9  s0    i
#
3*+V4r;   c                     | j                   }t        d      } ||d   d       t        d      } ||d   d       t        dd      } ||d   d       y )	Nhello worldrB   r  u   hello ø worldrW   r=   _charsetrC   )r2   r   r5   s      r9   test_default_ctezTestEncoders.test_default_cte?  s`    }%
3*+V4)*
3*+X6)LA
3*+-?@r;   c                     | j                   }t        dd      } ||d   d        ||j                         t        j                  d             y )Nu   文
euc-jpr  rB   r  z            MIME-Version: 1.0
            Content-Type: text/plain; charset="iso-2022-jp"
            Content-Transfer-Encoding: 7bit

            $BJ8(B
            )r2   r   r   r   r   r5   s      r9   test_encode7or8bitzTestEncoders.test_encode7or8bitK  sK     w2
3*+V4
3==?HOO -  	r;   c                 z    t        ddd      }| j                  t        |      t        j                  d             y )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  rh   s     r9   test_qp_encode_latin1z"TestEncoders.test_qp_encode_latin1Z  s4    |V\:S8?? 4 $ 	r;   c                 z    t        ddd      }| j                  t        |      t        j                  d             y )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  rh   s     r9   test_qp_encode_non_latin1z&TestEncoders.test_qp_encode_non_latin1d  s4    z6<8S8?? 4 $ 	r;   N)	r  r  r  r  r  r  r  r  r  r  r;   r9   r  r  .  s"    A5
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*y))TestLongHeadersNc                     | j                   }t        j                  d      }t               }t	        |      }|j                  |        ||j                         d       y )NzSubject: bug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text

test
)ndiffAssertEqualr   r   r   r   r   r   r6   r7   r8   sfpr   s        r9   test_split_long_continuationz,TestLongHeaders.test_split_long_continuationu  sT    ""'' )  jcN			#
3<<>  	r;   c                     | j                   }d}t        |d      } ||j                         d       t        |j                  dd            } ||j                         d       y )Nzbug demonstration
	12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
	more text	continuation_wsr,   zbug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text)r  r   r   r   r6   r7   hstrhs       r9   ,test_another_long_almost_unsplittable_headerz<TestLongHeaders.test_another_long_almost_unsplittable_header  sc    "" 4.
188:  	 4<<c*+
188:  	r;   c                    | j                   }t        d      }t        d      }t        d      }d}d}d}t        ||d      }|j                  ||       |j                  ||       t	               }	||	d<   t               }
t        |
      }|j                  |	        ||
j                         d	        ||j                  d
      d       y )Nr=   rr   rV      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   )r6   r7   r   czutf8g_headcz_head	utf8_headr  r8   r  s              r9   test_long_nonstringz#TestLongHeaders.test_long_nonstring  s    ""L!\"w$$0	 61)4	"	D!iIjcN			#
3<<>  	 	188r8" %1 	2r;   c                 d    | j                   }t        dd      } ||j                         d       y )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   r6   r7   r  s      r9   test_long_header_encodez'TestLongHeaders.test_long_header_encode  s7    "" O:< 	188: > 	?r;   c                 f    | j                   }t        ddd      } ||j                         d       y )Nr(  r)  r  r  r  r*  r+  r,  s      r9   <test_long_header_encode_with_tab_continuation_is_just_a_hintzLTestLongHeaders.test_long_header_encode_with_tab_continuation_is_just_a_hint  s:    "" O:#') 	188: > 	?r;   c                 f    | j                   }t        ddd      } ||j                         d       y )Nziwasnipoop; giraffes="very-long-necked-animals";	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r)  r  r/  zjwasnipoop; giraffes="very-long-necked-animals";
	spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"r+  r,  s      r9   -test_long_header_encode_with_tab_continuationz=TestLongHeaders.test_long_header_encode_with_tab_continuation  s;    "" O:#') 	188: ? 	@r;   c                 \    t        dd      }| j                  |j                         d       y )N   文r  =?iso-2022-jp?b?GyRCSjgbKEI=?=r   r2   r   r6   r  s     r9   0test_header_encode_with_different_output_charsetz@TestLongHeaders.test_header_encode_with_different_output_charset  s%    5(#%EFr;   c                 ~    t        dj                  d      d      }d}| j                  |j                         |       y )Ns6   test-ja Ƥ줿᡼ϻʲԤξǧԤäƤޤr  z=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKMnE8VCROPjUbKEI=?=
 =?iso-2022-jp?b?GyRCRyckckJUJEMkRiQkJF4kORsoQg==?=)r   rY   r2   r   )r6   r  ress      r9   5test_long_header_encode_with_different_output_charsetzETestLongHeaders.test_long_header_encode_with_different_output_charset  s?     $ %+F8$4h@7 	S)r;   c                     | j                   }t        d      }d|d<   t               }t        |      }|j	                  |        ||j                         d       y )Nr+   r(  r)  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        r9   test_header_splitterz$TestLongHeaders.test_header_splitter  sY    ""rlH 	'( jcN			#
3<<>  	r;   c                 &   | j                   }t               }d|d<   t        j                  d t	        d      D              |d<   |j                  d       t               }t        |      }|j                  |        ||j                         d       y )Ntest@dom.ainr   c              3   &   K   | ]	  }d |z    yw)z<%d@dom.ain>Nr  ).0is     r9   	<genexpr>z@TestLongHeaders.test_no_semis_header_splitter.<locals>.<genexpr>  s     &Ma~'9&Ms   
   
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   rangerR   r   r   r   r   r  s        r9   test_no_semis_header_splitterz-TestLongHeaders.test_no_semis_header_splitter  sv    ""i$F!JJ&M59&MMLjcN			#
3<<>  		r;   c                 `    | j                   }t        d      } ||j                         d       y )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_itselfr+  r,  s      r9   "test_last_split_chunk_does_not_fitz2TestLongHeaders.test_last_split_chunk_does_not_fit  5    ""   	188: b 	cr;   c                 `    | j                   }t        d      } ||j                         d       y )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_itselfr+  r,  s      r9   >test_splittable_leading_char_followed_by_overlong_unsplittablezNTestLongHeaders.test_splittable_leading_char_followed_by_overlong_unsplittable(  rL  r;   c                 `    | j                   }t        d      } ||j                         d       y )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_itselfr+  r,  s      r9   Gtest_multiple_splittable_leading_char_followed_by_overlong_unsplittablezWTestLongHeaders.test_multiple_splittable_leading_char_followed_by_overlong_unsplittable1  rL  r;   c                 `    | j                   }t        d      } ||j                         d       y )NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;r+  r,  s      r9   1test_trailing_splittable_on_overlong_unsplittablezATestLongHeaders.test_trailing_splittable_on_overlong_unsplittable:  s1    "" * +
188: * 	+r;   c                 `    | j                   }t        d      } ||j                         d       y )NzW; this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; zX;
 this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself; r+  r,  s      r9   Itest_trailing_splittable_on_overlong_unsplittable_with_leading_splittablezYTestLongHeaders.test_trailing_splittable_on_overlong_unsplittable_with_leading_splittableA  s5    "" + , 	188: Z 	[r;   c                 `    | j                   }t        d      } ||j                         d       y )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 foldedr+  r,  s      r9   5test_long_header_with_multiple_sequential_split_charszETestLongHeaders.test_long_header_with_multiple_sequential_split_charsJ  s3    "" F G
188: ) 	*r;   c                 `    | j                   }t        d      } ||j                         d       y )NKthisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,pointsr+  r,  s      r9   :test_splitter_split_on_punctuation_only_if_fws_with_headerzJTestLongHeaders.test_splitter_split_on_punctuation_only_if_fws_with_headerR  s1    "" + ,
188: 2 	3r;   c                 `    | j                   }t        d      } ||j                         d       y )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;r+  r,  s      r9   Dtest_leading_splittable_in_the_middle_just_before_overlong_last_partzTTestLongHeaders.test_leading_splittable_in_the_middle_just_before_overlong_last_partY  s5    "" * + 	188: Y 	Zr;   c                 `    | j                   }t        d      } ||j                         d       y )NzTthis_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself r+  r,  s      r9   /test_overlong_last_part_followed_by_split_pointz?TestLongHeaders.test_overlong_last_part_followed_by_split_pointd  s1    "" * +
188: = 	>r;   c                 `    | j                   }t        d      } ||j                         d       y )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; r+  r,  s      r9   @test_multiline_with_overlong_parts_separated_by_two_split_pointszPTestLongHeaders.test_multiline_with_overlong_parts_separated_by_two_split_pointsk  5    "" + , 	188: Z 	[r;   c                 `    | j                   }t        d      } ||j                         d       y )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; r+  r,  s      r9   >test_multiline_with_overlong_last_part_followed_by_split_pointzNTestLongHeaders.test_multiline_with_overlong_last_part_followed_by_split_pointv  r`  r;   c                    | j                   }t               }d|d<   t        j                  dgdz        |d<   |j	                  d       t               }t        |      }|j                  |        ||j                         d       y )Nr?  r   z<foo@dom.ain>  rD  rE  rF  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   rG  r   rR   r   r   r   r   r  s        r9   %test_long_header_with_whitespace_runsz5TestLongHeaders.test_long_header_with_whitespace_runs  su    ""i$F!JJ(9':R'?@LjcN			#
3<<>  		r;   c                    | j                   }t               }d|d<   t        j                  dgdz        dz   |d<   |j	                  d       t               }t        |      }|j                  |        ||j                         d       y )	Nr?  r   z<foo@dom.ain>rD  z; abcrE  rF  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

Testrd  r  s        r9   'test_long_run_with_semi_header_splitterz7TestLongHeaders.test_long_run_with_semi_header_splitter  sy    ""i$F!JJ'82'=>HLjcN			#
3<<>  		r;   c                     | j                   }t               }d|d<   d|d<   |j                  d       t               }t	        |      }|j                  |        ||j                         d       y )Nr?  r   rX  rE  rF  zrFrom: test@dom.ain
References: 
 thisverylongheaderhas;semicolons;and,commas,butthey;arenotlegal;fold,points

Test)r  r   rR   r   r   r   r   r  s        r9   .test_splitter_split_on_punctuation_only_if_fwsz>TestLongHeaders.test_splitter_split_on_punctuation_only_if_fws  se    ""i$F+LjcN			#
3<<>  		r;   c                     | j                   }d}t        |      } ||j                         d       t        d      } ||j                         d       y )Nz\References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz]References:
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr+  r  s       r9   test_no_split_long_headerz)TestLongHeaders.test_no_split_long_header  sQ    ""(4L 	188: U 	V 8
188:ijr;   c                 h    | j                   }d}t        |d      } ||j                         d       y )NaW  from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
r  r  a_  from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)
	from babylon.socal-raves.org (localhost [127.0.0.1]);
 by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
 for <mailman-admin@babylon.socal-raves.org>;
 Sat, 2 Feb 2002 17:00:06 -0800 (PST)r+  r  s       r9   "test_splitting_multiple_long_linesz2TestLongHeaders.test_splitting_multiple_long_lines  s7    ""
 4.
188: ) 	*r;   c                 l    | j                   }d}t        |ddd      } ||j                         d       y )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 -0400r+  r  s       r9   &test_splitting_first_line_only_is_longz6TestLongHeaders.test_splitting_first_line_only_is_long  sA    ""A
 4BJ#')
188: A 	Br;   c                    | j                   }t               }t        ddd      }|j                  d        ||j	                  d      d       ||d<    ||j                  d	      d
        ||j                  d	      d       y )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   )r6   r7   r8   r  s       r9   test_long_8bit_headerz%TestLongHeaders.test_long_8bit_header  s    ""i-| )+	DE
188r8" %, 	- I
3==b=) , 	
 	3==a=( + 	r;   c                     | j                   }t               }d}||d<    ||j                  d      d       t               }t        |d      |d<    ||j                  d      d       y )Nuh   Britische Regierung gibt grünes Licht für Offshore-Windkraftprojekte <a-very-long-address@example.com>zReply-Torp  rt  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   )r6   r7   r8   header_strings       r9    test_long_8bit_header_no_charsetz0TestLongHeaders.test_long_8bit_header_no_charset  sv    ""i= (J
3==b=) , 	
 i -79J
3==b=) , 	r;   c                 p    | j                   }d}t               }||d<    ||j                  d      d       y )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   rp  rt  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   )r6   r7   r   r8   s       r9   test_long_to_headerz#TestLongHeaders.test_long_to_header  s@    "";
 iD	
3==b=) , 	r;   c                     | j                   }d}t        |      }|j                  d        ||j                  d      d       y )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   r6   r7   r   r  s       r9   test_long_line_after_appendz+TestLongHeaders.test_long_line_after_append!  sB    ""W1I	$%
188r8" % 	r;   c                     | j                   }d}t        |      }|j                  d        ||j                         d       y )NzThis is a shorter line.z!Add another sentence. (Surprise?)z9This is a shorter line. Add another sentence. (Surprise?)r}  r~  s       r9   test_shorter_line_with_appendz-TestLongHeaders.test_shorter_line_with_append*  s<    ""%1I	45
188:F	Hr;   c                 r    | j                   }d}d}t        |d|      } ||j                  d      d       y )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_?=r+  )r6   r7   fngsr  s        r9   test_long_field_namez$TestLongHeaders.test_long_field_name2  sE    ""0 2|4
188r8" %A 	Br;   c                     d}t               }t        |d      |d<   ||d<   | j                  |j                  d      d       y )	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-2rp  rt  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   r6   r  r8   s      r9   test_long_received_headerz)TestLongHeaders.test_long_received_headerA  sM    / i"1d;LLcmmm< ? 	r;   c                     d}t               }t        |dd      |d<   ||d<   | j                  |j                  d      d       y )	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  rp  rt  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      r9   test_string_headerinst_eqz)TestLongHeaders.test_string_headerinst_eqS  sR    1 i"1,379LLcmmm< ? 	r;   c                     | j                   }t               }d}||d<   t        |d      |d<   d|z   |d<    ||j                  d      d	       y )
NziVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzpzFace-1zFace-2r  r,   zFace-3rp  rt  a  Face-1: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-2: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
Face-3: 
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp

r  r   r   r   )r6   r7   r8   ts       r9   -test_long_unbreakable_lines_with_continuationz=TestLongHeaders.test_long_unbreakable_lines_with_continuationf  s`    ""iM Hqh7HaH 	3==b=) , 	r;   c                 |    | j                   }d}t        j                  |      } ||j                  d      d       y )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 -0700rp  rt  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   r6   r7   r   r8   s       r9   "test_another_long_multiline_headerz2TestLongHeaders.test_another_long_multiline_header~  s@    ""/ ''*
3==b=) , 	r;   c                     | j                   }d}t               }||d<   t        |d      |d<    ||j                  d      d       y )NzList-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,        <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>Listr  rp  rt  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  )r6   r7   r  r8   s       r9   %test_long_lines_with_different_headerz5TestLongHeaders.test_long_lines_with_different_header  sP    ""% iFQF3F
3==b=) , 	r;   c                     t        t        j                  d      dd      }| j                  |j	                         dz   t        j                  d      dz          y )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 worksrV   rF  )rA   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   r2   r   r7  s     r9   *test_long_rfc2047_header_with_embedded_fwsz:TestLongHeaders.test_long_rfc2047_header_with_embedded_fws  sZ    8?? $, - #%' 	D(// ;7 +8 9=	+= 	>r;   )+r  r  r  maxDiffr  r  r&  r-  r0  r2  r8  r;  r=  rI  rK  rN  rP  rR  rT  rV  rY  r[  r]  r_  rb  re  rg  ri  rl  rn  rr  rv  ry  r{  r  r  r  r  r  r  r  r  r  r  r;   r9   r
  r
  q  s    G("42l??@G*(	 ccc+[*3	Z>	[	[	"	"	$
k*,B (*"HB$&0&>r;   r
  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestFromManglingc                 v    t               | _        d| j                  d<   | j                  j                  d       y )Nzaaa@bbb.orgr   z(From the desk of A.A.A.:
Blah blah blah
)r   r8   rR   r6   s    r9   setUpzTestFromMangling.setUp  s0    9(  	r;   c                     t               }t        |d      }|j                  | j                         | j	                  |j                         d       y )NTmangle_from_z<From: aaa@bbb.org

>From the desk of A.A.A.:
Blah blah blah
r   r   r   r8   r2   r   r6   r   r   s      r9   test_mangled_fromz"TestFromMangling.test_mangled_from  s@    Jad+			$(( ( 	r;   c                     t               }t        |d      }|j                  | j                         | j	                  |j                         d       y )NFr  z;From: aaa@bbb.org

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

        rV   s   From Rölli
Tr  s   >From Rölli
)
r   r   r   r   r   r   r   r   r2   r   )r6   r   r8   br   s        r9    test_mangled_from_with_bad_bytesz1TestFromMangling.test_mangled_from_with_bad_bytes  su     "  VG_ 	 &&v0F'FGI140			#v0G'GHr;   c                 v    t        j                  d      j                  d      }t        j                  |      }y )Nu               From: aperson@example.com
            Content-Type: multipart/mixed; boundary="1"
            Content-Transfer-Encoding: È
        rV   )r   r   r   r   r   )r6   r   r8   s      r9   $test_multipart_with_bad_bytes_in_ctez5TestFromMangling.test_multipart_with_bad_bytes_in_cte  s5     "  VG_	 	
 &&v.r;   N)	r  r  r  r  r  r  r  r  r  r  r;   r9   r  r    s"    		B.I/r;   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestMIMEAudioc                     t        d| d      5 }|j                         | _        d d d        t        | j                        | _        y # 1 sw Y   $xY w)Nzsndhdr.r  )r'   r   
_audiodatar   _aur6   extr   s      r9   _make_audiozTestMIMEAudio._make_audio  sF    uot, 	( ggiDO	(T__-	( 	(   A		Ac                     dddddj                         D ]I  \  }}| j                  |       ||n|}| j                  | j                  j	                         d|        K y )Nzx-aiffzx-wavbasic)aifcaiffwavauzaudio/)r   r  r2   r  rH   r6   r  subtypes      r9   test_guess_minor_typez#TestMIMEAudio.test_guess_minor_type  sm    	

 %'	NLC S!$_c'GTXX668F7):LM	Nr;   c                     | j                  d       | j                  j                         }| j                  t	        j
                  t        |d            | j                         y )Nr  r   )r  r  rZ   r2   rW   decodebytesr   r  r6   payloads     r9   test_encodingzTestMIMEAudio.test_encoding  sK    ((&&(++E'7,CD	*r;   c                     | j                  d       t        | j                  d      }| j                  |j	                         d       y )Nr  fishz
audio/fish)r  r   r  r2   rH   )r6   r  s     r9   test_checkSetMinorz TestMIMEAudio.test_checkSetMinor  s9    t/,,.=r;   c                    | j                  d       | j                  }| j                  j                  ddd        || j                  d   d        || j                  j	                  d      d	d
g        || j                  j                  dd      d       g } || j                  j                  dd      d       | j                  | j                  j                  d|d      |       | j                  | j                  j                  d|      |       | j                  | j                  j                  d|d      |       y )Nr  rA  rB  	sndhdr.aurD  rF  z attachment; filename="sndhdr.au"r  rB  r+   )rE  r  rE  r+   r   failobjr   rN  )r  r2   r  rH  r  rI   assertIsr6   r7   missings      r9   test_add_headerzTestMIMEAudio.test_add_header  s8   1<%0 	 	2
488)*-	/
488&;< 9:	<
488j1FG	
488l3HI2Ndhh((7( ) *+2	4 	dhh((7;WEdhh((w08 ) :;B	Dr;   N)r  r  r  r  r  r  r  r  r  r;   r9   r  r    s    .
	N*>
Dr;   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestMIMEImagec                     t        d| d      5 }|j                         | _        d d d        t        | j                        | _        y # 1 sw Y   $xY w)Nzpython.r  )r'   r   _imgdatar   _imr  s      r9   _make_imagezTestMIMEImage._make_image2  sF    uot, 	&GGIDM	&T]]+	& 	&r  c                     d d d dd d d d ddd d d dj                         D ]I  \  }}| j                  |       ||n|}| j                  | j                  j	                         d|        K y )Njpegrastrgb)bmpexrgifjpgpbmpgmpngppmrassgitiffwebpxbmzimage/)r   r  r2   r  rH   r  s      r9   r  z#TestMIMEImage.test_guess_minor_type7  s    
 %'	NLC S!$_c'GTXX668F7):LM#	Nr;   c                     | j                  d       | j                  j                         }| j                  t	        j
                  t        |d            | j                         y )Nr  r   )r  r  rZ   r2   rW   r  r   r  r  s     r9   r  zTestMIMEImage.test_encodingK  sK    ((&&(++E'7,CD	(r;   c                     | j                  d       t        | j                  d      }| j                  |j	                         d       y )Nr  r  z
image/fish)r  r   r  r2   rH   )r6   ims     r9   r  z TestMIMEImage.test_checkSetMinorQ  s9    t}}f-,,.=r;   c                    | j                  d       | j                  }| j                  j                  ddd        || j                  d   d        || j                  j	                  d      d	d
g        || j                  j                  dd      d       g } || j                  j                  dd      d       | j                  | j                  j                  d|d      |       | j                  | j                  j                  d|      |       | j                  | j                  j                  d|d      |       y )Nr  rA  rB  r}   rD  rF  z%attachment; filename="dingusfish.gif"r  r  )rE  r}   rE  r+   r   r  rN  )r  r2   r  rH  r  rI   r  r  s      r9   r  zTestMIMEImage.test_add_headerV  s:   1<%5 	 	7
488)*2	4
488&;< >?	A
488j1FG	
488l3HI2Ndhh((0E ) GHO	Q 	dhh((7;WEdhh((w08 ) :;B	Dr;   N)r  r  r  r  r  r  r  r  r  r;   r9   r  r  1  s    ,
N((>
Dr;   r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestMIMEApplicationc                 x    | j                   }t        d      } ||j                         d        ||d   d       y )N   rV  rB   rW   )r2   r   rH   r5   s      r9   test_headersz TestMIMEApplication.test_headersm  s<    9:
3!#=>
3*+X6r;   c                     | j                   }d}t        |      } ||j                         j                         d        ||j                  d      |       y )Nr  z+vv8/f7/TrX   )r2   r   rZ   strip)r6   r7   	bytesdatar8   s       r9   	test_bodyzTestMIMEApplication.test_bodys  sK    /	i(
3??""$j1
3??$?'3r;   c                 `   d}t        |t        j                        }| j                  |j	                         dt        |      z         | j                  |j	                  d      |       | j                  |d   d       t               }t        |      }|j                  |       |j                         }t        j                  |      }| j                  |j	                         dt        |      z         | j                  |j	                  d      |       | j                  |d   d       y )Nr  _encoder   �TrX   rE   r`   )r   r   encode_7or8bitr2   rZ   r  r   r   r   r   r   r   r6   r  r8   r   r   wireformmsg2s          r9   $test_binary_body_with_encode_7or8bitz8TestMIMEApplication.test_binary_body_with_encode_7or8bit{  s    /	i(2I2IJ*Hs9~,EF5yA896BI1			#::<''1*Hs9~,EF)))6	B9:FCr;   c                    d}t        |t        j                        }| j                  |j	                         dt        |      z         | j                  |j	                  d      |       t               }t        |      }|j                  |       |j                         }t        j                  |      }| j                  |j	                         dt        |      z         | j                  |j	                  d      |       y )Nr  r  r  TrX   )r   r   encode_noopr2   rZ   r  r   r   r   r   r   r   r  s          r9   !test_binary_body_with_encode_noopz5TestMIMEApplication.test_binary_body_with_encode_noop  s     0	i(2F2FG*Hs9~,EF5yAI1			#::<''1*Hs9~,EF)))6	Br;   c                 \   d}t        |t        j                        }| j                  |j	                  d      |       t               }t        |      }|j                  |       |j                         }t        j                  |      }| j                  |j	                  d      |       y )Ns   r  TrX   )r   r   r   r2   rZ   r   r   r   r   r   r   r  s          r9   0test_binary_body_with_unicode_linend_encode_noopzDTestMIMEApplication.test_binary_body_with_unicode_linend_encode_noop  s    3	i(2F2FG5yAI1			#::<''1)))6	Br;   c                 0   d}t        |t        j                        }| j                  |j	                         d       | j                  |j	                  d      |       | j                  |d   d       t               }t        |      }|j                  |       |j                         }t        j                  |      }| j                  |j	                         d       | j                  |j	                  d      |       | j                  |d   d       y )Ns    r  z=FA=FB=FC=FD=FE=FF=20TrX   rE   rC   )r   r   encode_quoprir2   rZ   r   r   r   r   r   r   r  s          r9   #test_binary_body_with_encode_quopriz7TestMIMEApplication.test_binary_body_with_encode_quopri  s    0	i(2H2HI*,CD5yA89;MNI1			#::<''1*,CD)))6	B9:<NOr;   c                    d}t        |t        j                        }| j                  |j	                         d       | j                  |j	                  d      |       t               }t        |      }|j                  |       |j                         }t        j                  |      }| j                  |j	                         d       | j                  |j	                  d      |       y )Nr  r  z	+vv8/f7/
TrX   )r   r   encode_base64r2   rZ   r   r   r   r   r   r   r  s          r9   #test_binary_body_with_encode_base64z7TestMIMEApplication.test_binary_body_with_encode_base64  s    /	i(2H2HI*L95yAI1			#::<''1*L9)))6	Br;   N)
r  r  r  r  r  r  r  r  r  r	  r  r;   r9   r  r  l  s*    74D"C"
CP Cr;   r  c                   f    e Zd Zd Zd Zd Zd Zd Zd Zd Z	 e
j                  d      d	        Zy
)TestMIMETextc                 $    t        d      | _        y Nhello there)r   _msgr  s    r9   r  zTestMIMEText.setUp  s    ]+	r;   c                 Z   | j                   } || j                  j                         d        || j                  j                  d      d       g }| j	                  | j                  j                  d|      |       | j	                  | j                  j                  d|d      |       y )Nr?   rA   rN   rN  r  )r2   r  rH   rI   r  r  s      r9   
test_typeszTestMIMEText.test_types  s    
499%%'6
499y):6dii))(G<gFdii)))WX)N	r;   c                     | j                  | j                  j                         d       | j                  | j                  j	                                y r  )r2   r  rZ   assertFalseis_multipartr  s    r9   test_payloadzTestMIMEText.test_payload  s:    ..0-@//12r;   c                 V   | j                   }t        dd      } ||j                         j                  d        ||d   d       t	        d      }d |_        t        d|      } ||j                         j                  d        ||d   d        ||j                         d       y )Nr  rN   r  r@   rO   rV   r  )r2   r   rF   rJ   r
   ra   rZ   rK   s       r9   test_charsetzTestMIMEText.test_charset  s    }z:
3??**J7
3~ @A'" $}w7
3??**G4
3~ =>
3??m,r;   c                     | j                   }t        dd      } ||j                         j                  d        ||d   d       y )Nr  rN   r  r@   rO   )r2   r   rF   rJ   r5   s      r9   test_7bit_inputzTestMIMEText.test_7bit_input  s@    }z:
3??**J7
3~ @Ar;   c                     | j                   }t        d      } ||j                         d        ||d   d       | j                  d|j	                                y )Nr  rN   r@   rO   )r2   r   rF   r   r   r5   s      r9   test_7bit_input_no_charsetz'TestMIMEText.test_7bit_input_no_charset  sL    }%
3??j)
3~ @AmS]]_5r;   c                     d}| j                   }t        |d      } ||j                         j                  d        ||d   d        ||j	                  d      |j                  d             y )N   кирилицаrV   r  r@   r  TrX   )r2   r   rF   output_charsetrZ   r   )r6   teststrr7   r8   s       r9   test_utf8_inputzTestMIMEText.test_utf8_input  sc    Dw1
3??++W5
3~ =>
3??$?')@Ar;   zBcan't fix because of backward compat in email5, will fix in email6c                 >    d}| j                  t        t        |       y )Nr  )r   UnicodeEncodeErrorr   )r6   r  s     r9   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;   r9   r  r    sM    ,3-B6B X]]  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y)TestMultipartc                 n   t        dd      5 }|j                         }d d d        t        ddd      }t        d      }|j	                  d	d
d       t        d      }|j                  |       |j                  |       d|d<   d|d<   d|d<   d}t        j                  |      }|d   dk(  rt        j                  }nt        j                  }|dkD  rd}	nd}	d|	|dz  fz  }
t        j                  dt        j                  |            |
z   |d<   || _        || _        || _        y # 1 sw Y   xY w)Nr  r  	multipartmixedr   r  r}   )r   rF  rB  rD  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   rH  r   rn   time	localtimetimezonealtzonestrftimer  r  _txt)r6   r   r\   	containerr  intronow	timetupletzsecssigntzoffsets              r9   r  zTestMultipart.setUp  sE   lD) 	R779D	['JG	$%56."2 	 	4  
 	8	&E	$9	) NN3'	R=A]]F\\FA:DDfrk22 MM#NN3!#+,	& 		C	 	s   D**D4c                    | j                   }| j                  }| j                  }| j                  |j	                                 ||j                         d        |t        |j                               d        |t        |j                  d       |j                  d      }|j                  d      }| j                  || j                         | j                  || j                          ||j                         ||g       | j                  |j	                                | j                  |j	                                y )Nrk   r   r   r|   )r2   r   r  r   r  rH   r  rZ   
IndexErrorr  r6  r  r  )r6   r7   raisesr   m0m1s         r9   test_hierarchyzTestMultipart.test_hierarchy)  s    ""II()
1!23
3q}}#z1==!,]]1]]1b$))$b$((#
1==?RH%*+*+r;   c                 z    d}t               j                  |      }| j                  ||j                                y )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   )r6   r   r8   s      r9   test_empty_multipart_idempotentz-TestMultipart.test_empty_multipart_idempotent;  s3     h%dCMMO4r;   c                     t        dd      }d|d<   d|d<   d|d<   |j                  d	       | j                  |j                         d
       y )Nr)  r*  	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   r6   outers     r9   /test_no_parts_in_a_multipart_with_none_epiloguez=TestMultipart.test_no_parts_in_a_multipart_with_none_epilogueL  sT    g.&i'd)f:&eoo/ 
2 
	r;   c                     t        dd      }d|d<   d|d<   d|d<   d	|_        d	|_        |j                  d
       | j	                  |j                         d       y )Nr)  r*  rG  r  rH  r   rI  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   rJ  s     r9   0test_no_parts_in_a_multipart_with_empty_epiloguez>TestMultipart.test_no_parts_in_a_multipart_with_empty_epilogue^  sb    g.&i'd)f:&eoo/ 2 	r;   c                     | j                   }t        dd      }d|d<   d|d<   d|d<   |j                  d	       t        d
      }|j	                  |        ||j                         d       y )Nr)  r*  rG  r  rH  r   rI  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   rn   r   r6   r7   rK  r8   s       r9   test_one_part_in_a_multipartz*TestMultipart.test_one_part_in_a_multiparts  so    ""g.&i'd)f:&}%S
5??  	r;   c                     | j                   }t        dd      }d|d<   d|d<   d|d<   d	|_        t        d
      }|j	                  |       |j                  d        ||j                         d       y )Nr)  r*  rG  r  rH  r   rI  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   rN  r   rn   r   r   rS  s       r9   1test_seq_parts_in_a_multipart_with_empty_preamblez?TestMultipart.test_seq_parts_in_a_multipart_with_empty_preamble  sv    ""g.&i'd)f}%S:&
5??  	r;   c                     | j                   }t        dd      }d|d<   d|d<   d|d<   d |_        t        d	      }|j	                  |       |j                  d
        ||j                         d       y Nr)  r*  rG  r  rH  r   rI  r   r  r   rR  rV  rS  s       r9   0test_seq_parts_in_a_multipart_with_none_preamblez>TestMultipart.test_seq_parts_in_a_multipart_with_none_preamble  v    ""g.&i'd)f}%S:&
5??  	r;   c                     | j                   }t        dd      }d|d<   d|d<   d|d<   d |_        t        d	      }|j	                  |       |j                  d
        ||j                         d       y rY  r  r   rO  r   rn   r   r   rS  s       r9   0test_seq_parts_in_a_multipart_with_none_epiloguez>TestMultipart.test_seq_parts_in_a_multipart_with_none_epilogue  r[  r;   c                     | j                   }t        dd      }d|d<   d|d<   d|d<   d	|_        t        d
      }|j	                  |       |j                  d        ||j                         d       y )Nr)  r*  rG  r  rH  r   rI  r   r+   r  r   rR  r]  rS  s       r9   1test_seq_parts_in_a_multipart_with_empty_epiloguez?TestMultipart.test_seq_parts_in_a_multipart_with_empty_epilogue  sv    ""g.&i'd)f}%S:&
5??  	r;   c                     | j                   }t        dd      }d|d<   d|d<   d|d<   d	|_        t        d
      }|j	                  |       |j                  d        ||j                         d       y )Nr)  r*  rG  r  rH  r   rI  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]  rS  s       r9   .test_seq_parts_in_a_multipart_with_nl_epiloguez<TestMultipart.test_seq_parts_in_a_multipart_with_nl_epilogue  sv    ""g.&i'd)f}%S:&
5??  	r;   c                    | j                   }| j                  d      } |t        |j                               d       |j                  d      } ||j	                         d        |t        |j                               d       |j                         D ]a  } ||j	                         d        |t        |j                               d       |j                  d      } ||j	                         d       c y )N
msg_36.txtr   r|   zmultipart/alternativezmessage/external-bodyr   r?   )r2   r3   r  rZ   rH   )r6   r7   r8   msg1r   
subsubparts         r9   test_message_external_bodyz(TestMultipart.test_message_external_body  s    ll<(
3s !1%q!
4  "$;<
3t!"A&'') 	<Gw'')+BCs7&&()1- ,,Q/Jz**,l;		<r;   c                 x    | j                  d      }| j                  t        |j                               d       y )Nz
msg_37.txtr   )r3   r2   r  rZ   rh   s     r9   test_double_boundaryz"TestMultipart.test_double_boundary!  s.     ll<(S__./3r;   c                     | j                   }| j                  d      }t               }t        j                  ||        ||j                         d       y )Nz
msg_38.txtzmultipart/mixed
    multipart/mixed
        multipart/alternative
            text/plain
        text/plain
    text/plain
    text/plain
r  r3   r   r!   
_structurer   r6   r7   r8   r  s       r9   )test_nested_inner_contains_outer_boundaryz7TestMultipart.test_nested_inner_contains_outer_boundary(  sI    ""
 ll<(jS#&
3<<>  	r;   c                     | j                   }| j                  d      }t               }t        j                  ||        ||j                         d       y )Nz
msg_39.txtzmultipart/mixed
    multipart/mixed
        multipart/alternative
        application/octet-stream
        application/octet-stream
    text/plain
rk  rm  s       r9   test_nested_with_same_boundaryz,TestMultipart.test_nested_with_same_boundary;  sI    "" ll<(jS#&
3<<>  	r;   c                 f    | j                  d      }| j                  |j                         d       y )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--
)r3   r2   r   rh   s     r9   test_boundary_in_non_multipartz,TestMultipart.test_boundary_in_non_multipartL  s+    ll<( + 	r;   c                     | j                   }t        j                  d      }| j                  |j	                                 ||j                         d        |t        |j                               d       y )NzMIME-Version: 1.0
Content-Type: multipart/mixed; boundary="    XXXX"

--    XXXX
Content-Type: text/plain


--    XXXX
Content-Type: text/plain

--    XXXX--
z    XXXXr   )r2   r   r   r   r  r   r  rZ   r5   s      r9    test_boundary_with_leading_spacez.TestMultipart.test_boundary_with_leading_space[  sb    '' )  	((*+
3z*
3s !1%r;   c                     t               j                  d      }| j                  |j                  d      j                         d       y )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   r2   rZ   r  s     r9   &test_boundary_without_trailing_newlinez4TestMultipart.test_boundary_without_trailing_newlinen  s=    H 
# 
$ 	q)557Dr;   c                     t        dd      }| j                  |j                  t        j                  j                         y )Nr)  r*  )r   r  r   r   compat32r  s     r9   test_mimebase_default_policyz*TestMultipart.test_mimebase_default_policy|  s*    ['*ahh 5 56r;   c                     t        ddt        j                  j                        }| j	                  |j                  t        j                  j                         y )Nr)  r*  r   )r   r   r   defaultr  r  s     r9   test_mimebase_custom_policyz)TestMultipart.test_mimebase_custom_policy  s6    ['%,,2F2FGahh 4 45r;   N)r  r  r  r  rC  rE  rL  rP  rT  rW  rZ  r^  r`  rb  rg  ri  rn  rp  rr  rt  rv  ry  r|  r  r;   r9   r'  r'    sh    "H,$5"$*286666<4&"&&E76r;   r'  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y)TestNonConformantc                     | j                   }| j                  d      } ||j                         d        ||j                         d        ||j	                         d       y )Nz
msg_14.txtr?   r   r  )r2   r3   rH   rn  r  r5   s      r9   test_parse_missing_minor_typez/TestNonConformant.test_parse_missing_minor_type  sT    ll<(
3!<0
3##%v.
3""$g.r;   c                 "   | j                  d      }|j                  d      }| j                  t        |d             | j	                  t        |j                        d       | j                  |j                  d   t        j                         y )N
msg_15.txtr   r  r|   )
r3   rZ   r   hasattrr2   r  r  r  r    StartBoundaryNotFoundDefect)r6   r8   inners      r9   test_same_boundary_inner_outerz0TestNonConformant.test_same_boundary_inner_outer  sm    ll<("y12U]]+Q/emmA.$@@	Br;   c                 l   | j                  d      }| j                  |j                         t               | j	                  t        |j                        d       | j                  |j                  d   t        j                         | j                  |j                  d   t        j                         y )Nz
msg_25.txtr   r   r|   )
r3   r  rZ   r   r2   r  r  r    NoBoundaryInMultipartDefect!MultipartInvariantViolationDefectrh   s     r9   test_multipart_no_boundaryz,TestNonConformant.test_multipart_no_boundary  s    ll<(coo/5S[[)1-ckk!n$@@	Bckk!n$FF	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                  | j                  j                  d            }| j                  t	        |j
                        d       | j                  |j
                  d   t        j                         y )Nz"
Content-Transfer-Encoding: base64r|   r   )	_str_msgmultipart_msgr  r2   r  r  r  r    -InvalidMultipartContentTransferEncodingDefectrh   s     r9   test_multipart_invalid_ctez,TestNonConformant.test_multipart_invalid_cte  sa    mm%%&KLNS[[)1-ckk!n@@	Br;   c                     | j                  | j                  j                  d            }| j                  t	        |j
                        d       y )Nr+   r   r  r  r  r2   r  r  rh   s     r9   test_multipart_no_cte_no_defectz1TestNonConformant.test_multipart_no_cte_no_defect  s:    mmD..55b9:S[[)1-r;   c                     dD ]`  }| j                  | j                  j                  dj                  |                  }| j                  t	        |j
                        d       b y )N)r  r`   BINaryz
Content-Transfer-Encoding: {}r   r  )r6   r   r8   s      r9   "test_multipart_valid_cte_no_defectz4TestNonConformant.test_multipart_valid_cte_no_defect  s^    - 	2C--""))5<<SACDC S-q1		2r;   c                    | j                   }| j                  }t               }d|d<    ||j                         d        ||j	                         d        ||j                         d       |d= d|d<    ||j                         d        ||j	                         d        ||j                         d       t               }t        |      }|j                  |        ||j                         d       y )Nr   rD   r  r?   r@   r   zContent-Type: foo

)
r2   r  r   rn  r  rH   r   r   r   r   )r6   r7   neqr8   r   r   s         r9   test_invalid_content_typez+TestNonConformant.test_invalid_content_type  s    ##i$N
3##%v.
3""$g.
3!<0#N
3##%v.
3""$g.
3!<0JaL			#AJJL12r;   c                 l    | j                   }| j                  d      } ||j                         d       y )N
msg_31.txtzm--BOUNDARY
Content-Type: text/plain

message 1

--BOUNDARY
Content-Type: text/plain

message 2

--BOUNDARY--
)r  r3   rZ   r5   s      r9   test_no_start_boundaryz(TestNonConformant.test_no_start_boundary  s1    ""ll<(
3??  	r;   c                 l    | j                   }| j                  d      } ||j                         d       y )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  r3   r   r5   s      r9   test_no_separating_blank_linez/TestNonConformant.test_no_separating_blank_line  s0    ""ll<(
3==?  	r;   c                 Z   | j                  d      }| j                  t        |d             | j                  t	        |j
                        d       | j                  |j
                  d   t        j                         | j                  |j
                  d   t        j                         y )Nz
msg_41.txtr  r   r   r|   )
r3   r   r  r2   r  r  r  r    r  r  rh   s     r9   test_lying_multipartz&TestNonConformant.test_lying_multipart	  s    ll<(Y/0S[[)1-ckk!n$@@	Bckk!n$FF	Hr;   c                 
   | j                  d      }|j                  d      j                  d      }| j                  t        |j                        d       | j                  |j                  d   t        j                         y )Nz
msg_42.txtr|   r   )r3   rZ   r2   r  r  r  r    r  )r6   rK  bads      r9   test_missing_start_boundaryz-TestNonConformant.test_missing_start_boundary	  sh    \* "..q1S[[)1-ckk!n$@@	Br;   c                 v   | j                   }d}t        j                  |      } ||j                         dg        ||j	                         d        |t        |j                        d       | j                  |j                  t        j                  g        ||j                  d   j                  d       y )Nz Line 1
Subject: test

bodyr  bodyr|   r   z Line 1
)r2   r   r   r  rZ   r  r  assertDefectsEqualr    #FirstHeaderLineIsContinuationDefectliner  s       r9   &test_first_line_is_continuation_headerz8TestNonConformant.test_first_line_is_continuation_header	  s    ,''*
388:	{#
3??f%
3s{{Q"("L"L!M	O
3;;q>,r;   c                     | j                  d      }| j                  |j                         dg       | j                  |j                         d       | j	                  |j
                  t        j                  g       y )Nz&Subject: test
not a header
To: abc

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

b
)r  r2   r  rZ   r  r  r     MissingHeaderBodySeparatorDefectrh   s     r9   "test_missing_header_body_separatorz4TestNonConformant.test_missing_header_body_separator'	  sd    
 mmIJi[1*,JK!'!H!H I	Kr;   N)r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r;   r9   r~  r~    s`    /BH $HOO % M0B.
23*"	HB 	-	Kr;   r~  c                   l    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y)TestRFC2047c                     | j                   }d}t        |      } ||g d       t        |      } |t        |      d       | j	                  |j                  d      d       y )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?=)r2   r   r   r   r  r   r6   r7   r   dhr   s        r9   test_rfc2047_multilinez"TestRFC2047.test_rfc2047_multiline5	  sj    /1
2 5 	6
 R
3v;D	Ffmmrm: =  	!r;   c                     | j                   }d}t        |      } ||ddg       t        t        |            } ||d       y )Nz0=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>)s   Andrr=   )s    Pirard <pirard@dom.ain>Nu   André Pirard <pirard@dom.ain>r2   r   r   r   r  s        r9   test_whitespace_keeper_unicodez*TestRFC2047.test_whitespace_keeper_unicodeF	  sJ    >1
2+35 	6[_%
656r;   c                     | j                   }d}t        |      } ||g d       t        t        |            } ||d       y )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  )r6   r7   r   r  hus        r9    test_whitespace_keeper_unicode_2z,TestRFC2047.test_whitespace_keeper_unicode_2O	  sF    e1
2 K 	LR!
2=>r;   c                 F    d}t        |      }| j                  |g d       y )Nz3Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord))s   SmN   r=   )s   rgN   r=   )s   sbordNr   r2   r6   r   r  s      r9   test_rfc2047_missing_whitespacez+TestRFC2047.test_rfc2047_missing_whitespaceX	  s&    A1 0 	1r;   c                 F    d}t        |      }| j                  |g d       y )Nz7Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord))s   Sm Nr  )s    rg Nr  )s    sbordNr  r  s      r9   test_rfc2047_with_whitespacez(TestRFC2047.test_rfc2047_with_whitespace_	  s&    E1 1 	2r;   c                 j    d}g d}|D ](  \  }}t        ||z        }| j                  ||dfg       * y )Nz=?iso-8859-1?B?%s?=))zdm==   v)zdm=r  )dmr  )zdmk=   vi)dmkr  r=   r  )r6   r   r\   qar  s         r9   test_rfc2047_B_bad_paddingz&TestRFC2047.test_rfc2047_B_bad_paddingf	  sI    !  	6DAqq1u%BR1l"3!45	6r;   c                 @    d}| j                  t        |      dg       y )Nz=?iso-8859-1?Q?andr=e9=zz?=)s   andr=zzr=   r2   r   r6   r   s     r9   test_rfc2047_Q_invalid_digitsz)TestRFC2047.test_rfc2047_Q_invalid_digitsp	  s"    )q)78	:r;   c                 B    d}| j                  t        |      g d       y )Nz(=?ISO-8859-1?Q?a?=))   (N   ar=      )Nr  r  s     r9   test_rfc2047_rfc2047_1z"TestRFC2047.test_rfc2047_rfc2047_1v	  s     "q)>	@r;   c                 B    d}| j                  t        |      g d       y )Nz(=?ISO-8859-1?Q?a?= b))r  r  )s    b)Nr  r  s     r9   test_rfc2047_rfc2047_2z"TestRFC2047.test_rfc2047_rfc2047_2|	       $q)@	Br;   c                 B    d}| j                  t        |      g d       y )Nz'(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)r  )s   abr=   r  r  r  s     r9   test_rfc2047_rfc2047_3z"TestRFC2047.test_rfc2047_rfc2047_3	  s     5q)?	Ar;   c                 B    d}| j                  t        |      g d       y )Nz((=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?=)r  r  r  s     r9   test_rfc2047_rfc2047_4z"TestRFC2047.test_rfc2047_rfc2047_4	  s     6q)?	Ar;   c                 B    d}| j                  t        |      g d       y )Nz,(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r  r  r  s     r9   test_rfc2047_rfc2047_5az#TestRFC2047.test_rfc2047_rfc2047_5a	  s     <q)?	Ar;   c                 B    d}| j                  t        |      g d       y )Nz+(=?ISO-8859-1?Q?a?=
    =?ISO-8859-1?Q?b?=)r  r  r  s     r9   test_rfc2047_rfc2047_5bz#TestRFC2047.test_rfc2047_rfc2047_5b	  s     :q)?	Ar;   c                 B    d}| j                  t        |      g d       y )Nz(=?ISO-8859-1?Q?a_b?=))r  )s   a br=   r  r  r  s     r9   test_rfc2047_rfc2047_6z"TestRFC2047.test_rfc2047_rfc2047_6	  r  r;   c           	         d}| j                  t        |      g d       | j                  t        t        |            j                         |j	                                | j                  t        t        t        |                  d       y )Nz((=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=))r  r  )s    brr   r  z(a b))r2   r   r   r   r   r   r  s     r9   test_rfc2047_rfc2047_7z"TestRFC2047.test_rfc2047_rfc2047_7	  sk    6q)	 	]1%56==?K[q)9:;WEr;   c           	      :   d}| j                  t        |      ddg       | j                  t        t        |            j                         dj	                  |j                                      | j                  t        t        t        |                  d       y )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>)r2   r   r   r   r   
splitlinesr   r  s     r9   test_multiline_headerz!TestRFC2047.test_multiline_header	  s    Iq)/+-	. 	]1%56==?0	2[q)9:;:	<r;   N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r;   r9   r  r  4	  sZ    !"7?126:@BAAAABF<r;   r  c                   l    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y)TestMIMEMessagec                 r    t        dd      5 }|j                         | _        d d d        y # 1 sw Y   y xY w)N
msg_11.txtrV   r   )r'   r   _textr6   r   s     r9   r  zTestMIMEMessage.setUp	  s0    lW5 	#DJ	# 	# 	#s   -6c                 :    | j                  t        t        d       y )Nza plain string)r   rm   r   r  s    r9   test_type_errorzTestMIMEMessage.test_type_error	  s    )[2BCr;   c                 8   | j                   }d}t               }||d<   t        |      } ||j                         d       |j	                         }| j                  |t                |t        |      d       |d   }| j                  ||        ||d   |       y )NzA sub-messager  r[  r|   r   subject)	r2   r   r   rH   rZ   r  listr  r  )r6   r7   r  r   rr  r   s          r9   test_valid_argumentz#TestMIMEMessage.test_valid_argument	  s    !I)N
1!12--/gt,
3w<!*gq!
79w'r;   c                     t               }d|d<   t               }d|d<   t        |      }| j                  t        j                  |j
                  |       y )N	subpart 1r  z	subpart 2)r   r   r   r    MultipartConversionErrorrn   )r6   re  r  r  s       r9   test_bad_multipartz"TestMIMEMessage.test_bad_multipart	  sH    y%Yy%Y&99188TJr;   c                     t               }d|d<   |j                  d       t        |      }d|d<   t               }t	        |      }|j                  |       | j                  |j                         d       y )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   rR   r   r   r   r   r2   r   )r6   r   r  r   r   s        r9   test_generatezTestMIMEMessage.test_generate	  sg    I,)	:;N.)JaL			! ( 	r;   c                 X   | j                   }| j                  d      } ||j                         d       |j                         }| j	                  |t
                |t        |      d       |d   }| j	                  |t                ||d   d        ||j                         d       y )Nr  r[  r|   r   r  r  r  )r2   r3   rH   rZ   r  r  r  r   )r6   r7   r8   r  submsgs        r9   test_parse_message_rfc822z)TestMIMEMessage.test_parse_message_rfc822	  s    ll<(
3!#34//#gt,
3w<fg.
6)34
6!EFr;   c                    | j                   }| j                  d      } ||j                         d       | j                  |j	                                 |t        |j                               d       |j                  d      } ||j                         d        ||j                         d       |j                  d      } ||j                         d        |t        |j                               d	       |j                  d      }| j                  |t                ||d
   d        ||j                  dd      d        ||j                  dd      d        |j                  d      }| j                  |t                ||d   d        ||j                  d      ddg        ||j                  dd      d       |j                  d	      } ||j                         d       |j                         }| j                  |t                |t        |      d       |d   }| j                  |t                ||j                         d        ||d   d       y )N
msg_16.txtr8  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-recipientr[  
message-idz(<002001c144a6$8752e060$56104586@oxy.edu>)r2   r3   rH   r   r  r  rZ   r  r   rI   r  r  )r6   r7   r8   r   dsn1dsn2r  rf  s           r9   test_dsnzTestMIMEMessage.test_dsn	  s"   ll<(
3!#56((*+
3s !1%//!$
7##%|4
7  # 	$ //!$
7##%'@A
3w""$%q) ""1%dG,
4&')MN
4>>%>8"=
4>>%>8$?""1%dG,
4>8$
4??"6?7?@	B
4>>(+<>=rB//!$
7##%'78%%'gt,
3w<QZ
j'2
:&&(,7
:l#5	7r;   c                    | j                   }t        dd      5 }|j                         }d d d        t               }d|d<   d|d<   d|d	<   d
|_        d|_        t        d      }t        d      }|j                  ddd       |j                  |       |j                  |       t               }t        |      }|j                  |        ||j                                y # 1 sw Y   xY w)N
msg_21.txtrV   r   rH  r   rI  r   rF  r  MIME messagezEnd of MIME message
r  r  rD   rk   r   r+  )r  r'   r   r   rN  rO  r   rH  rn   r   r   r   r   )	r6   r7   r   r   r8   re  r  r  r   s	            r9   test_epiloguezTestMIMEMessage.test_epilogue,
  s    ""lW5 	779D	i'F%D	I%.~'8:N

4

4jcN			#
3<<>4 !	 	s   C$$C-c                 0   | j                   }t               }d|d<   d|d<   d|d<   d|_        d|_        t	        d	      }t	        d
      }|j                  ddd       |j                  |       |j                  |        ||j                         d       y )NrH  r   rI  r   rF  r  r  r+   r  r  rD   rk   r   r+  ad  From: aperson@dom.ain
To: bperson@dom.ain
Subject: Test
Content-Type: multipart/mixed; boundary="BOUNDARY"

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

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

Two
--BOUNDARY--
)r  r   rN  rO  r   rH  rn   r   )r6   r7   r8   re  r  s        r9   test_no_nl_preamblez#TestMIMEMessage.test_no_nl_preamble@
  s    ""i'F%D	I%~'8:N

4

4
3==?  	r;   c                    | j                   }t        dd      5 }t        j                  |      }d d d        j	                  d      } ||j                         d        ||j                         d       |j	                  d      } ||j                         d        ||j                         d       |j	                  d      } ||j                         d        ||j                         d       |j	                  d      } ||j                         d        ||j                         d       y # 1 sw Y   xY w)Nr_  rV   r   r   r[  r|   r?   r2   r'   r   message_from_filerZ   get_default_typerH   r6   r7   r   r8   
container1
container2container1acontainer2as           r9   test_default_typez!TestMIMEMessage.test_default_typec
     lW5 	.))"-C	.__Q'

:&&(*:;
:&&(*:;__Q'

:&&(*:;
:&&(*:; ,,Q/
;'')<8
;'')<8 ,,Q/
;'')<8
;'')<8	. 	.   D55D?c                    | j                   }t        dd      5 }t        j                  |      }d d d        j	                  d      } ||j                         d        ||j                         d       |j	                  d      } ||j                         d        ||j                         d       |j	                  d      } ||j                         d        ||j                         d       |j	                  d      } ||j                         d        ||j                         d       y # 1 sw Y   xY w)Nrd  rV   r   r   r[  r|   r?   r  r  s           r9   .test_default_type_with_explicit_container_typez>TestMIMEMessage.test_default_type_with_explicit_container_typet
  r  r  c                    | j                   }| j                  }t        dd      }d|_        t	        d      }t	        d      }t        |      }t        |      }|j                  |       |j                  |        ||j                         d        ||j                         d        ||j                         d        ||j                         d        ||j                  d      d       |d	= |d
= |d	= |d
=  ||j                         d        ||j                         d        ||j                         d        ||j                         d        ||j                  d      d       y )Ndigestr   r+   
message 1

message 2
r[  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--
r@   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--
)
r2   r  r   rO  r   r   rn   rH   r  r   )r6   r7   r  r7  	subpart1a	subpart2asubpart1subpart2s           r9   test_default_type_non_parsedz,TestMIMEMessage.test_default_type_non_parsed
  sf   ##!(J7		]+	]+	y)y)""
8$$&(89
8$$&(89
8$$&(89
8$$&(89I" % 	4 ^$^$^$^$
8$$&(89
8$$&(89
8$$&(89
8$$&(89I" % 	r;   c                    | j                   }t        d      }t        d      }t        ||f      } |t        |j	                               d        ||j	                  d      |        ||j	                  d      |       y )Nr+   )	_subpartsr   r   r|   )r2   r   r   r  rZ   )r6   r7   text1text2r8   s        r9   $test_mime_attachments_in_constructorz4TestMIMEMessage.test_mime_attachments_in_constructor
  si    uen5
3s !1%
3??1u%
3??1u%r;   c                 V    t               }| j                  |j                                y rf   )r   r   r  rh   s     r9   "test_default_multipart_constructorz2TestMIMEMessage.test_default_multipart_constructor
  s    o((*+r;   c                 r    t               }d|d<   d|d<   | j                  |j                  d      ddg       y )Na@b.comr   c@d.comr   )r   r2   r4   rh   s     r9   test_multipart_default_policyz-TestMIMEMessage.test_multipart_default_policy
  s9    oD	D	T*Y	,BCr;   c                     t        t        j                  j                        }d|d<   | j	                  t
              5 }d|d<   d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nr   r1  r   r2  z.There may be at most 1 To headers in a message)	r   r   r   r{  r   rR  r2   r   	exception)r6   r8   cms      r9   test_multipart_custom_policyz,TestMIMEMessage.test_multipart_custom_policy
  sj    5<<#7#78D	z* 	"b!CI	"R\\*I	K	" 	"s   A33A<N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r(  r-  r/  r3  r7  r  r;   r9   r  r  	  s[    #D(K(
G77r!(!F9"9"HT&,DKr;   r  c                       e Zd Zd Zd Zy)TestNonMultipartc                 Z    t        dd      }| j                  |j                                y )Nr   r  )r   r  r  rh   s     r9   "test_nonmultipart_is_not_multipartz3TestNonMultipart.test_nonmultipart_is_not_multipart
  s%    vw/))+,r;   c                     t               }d|d<   t        dd      }| j                  t        j                  |j
                  |       y )Nr  r  r   r  )r   r   r   r    r  rn   )r6   r8   r  s      r9   test_attach_raises_exceptionz-TestNonMultipart.test_attach_raises_exception
  s:    i$IVW-&99188SIr;   N)r  r  r  r;  r=  r  r;   r9   r9  r9  
  s    -Jr;   r9  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y)TestIdempotentr*   c                     t        |d      5 }|j                         }d d d        t        j                        }||fS # 1 sw Y   "xY wNrV   r   r'   r   r   r   r6   rE  r   r\   r8   s        r9   r3   zTestIdempotent._msgobj  sH    h1 	R779D	''-Dy	 	s   A  A	c                     | j                   }t               }t        |d      }|j                  ||        |||j	                                y )Nr   rt  r   )r  r   r   r   r   )r6   r8   r   r   r7   r   r   s          r9   _idempotentzTestIdempotent._idempotent  s@    ""Jaa(			#	)
4r;   c                    | j                   }| j                  d      \  }} ||j                         d        ||j                         d        ||j	                         d        ||j                         d   d        ||j                  d      d        ||j                  d         ||j                  d        | j                  ||       y )	Nr   r?   r   r  r|   )rA   rN   rA   rN   )
r2   r3   rH   rn  r  r  rI   rN  rO  rE  r6   r7   r8   r   s       r9   test_parse_text_messagez&TestIdempotent.test_parse_text_message  s    LL.	T
3!<0
3##%v.
3""$g.
3>>A 78
3==#Z0
3<<
3<<d#r;   c                     | j                   }| j                  d      \  }} ||j                         d        ||j                         d         ||j	                  d      d        | j                  ||       y )Nr   r?   rA   )r2   r3   rH   r  rI   rE  rG  s       r9   test_parse_untyped_messagez)TestIdempotent.test_parse_untyped_message  sf    LL.	T
3!<0
3>>T"
3==#T*d#r;   c                 P    | j                  d      \  }}| j                  ||       y )Nry   r3   rE  r6   r8   r   s      r9   test_simple_multipartz$TestIdempotent.test_simple_multipart"  $    LL.	Td#r;   c                 P    | j                  d      \  }}| j                  ||       y )N
msg_02.txtrL  rM  s      r9   test_MIME_digestzTestIdempotent.test_MIME_digest&  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nz
msg_27.txtrL  rM  s      r9   test_long_headerzTestIdempotent.test_long_header*  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nrd  rL  rM  s      r9   "test_MIME_digest_with_part_headersz1TestIdempotent.test_MIME_digest_with_part_headers.  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )N
msg_06.txtrL  rM  s      r9   test_mixed_with_imagez$TestIdempotent.test_mixed_with_image2  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nr6  rL  rM  s      r9   test_multipart_reportz$TestIdempotent.test_multipart_report6  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nr  rL  rM  s      r9   r  zTestIdempotent.test_dsn:  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nr  rL  rM  s      r9   test_preamble_epiloguez%TestIdempotent.test_preamble_epilogue>  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nz
msg_23.txtrL  rM  s      r9   test_multipart_one_partz&TestIdempotent.test_multipart_one_partB  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nz
msg_24.txtrL  rM  s      r9   test_multipart_no_partsz&TestIdempotent.test_multipart_no_partsF  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nr  rL  rM  s      r9   r  z%TestIdempotent.test_no_start_boundaryJ  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )N
msg_32.txtrL  rM  s      r9   test_rfc2231_charsetz#TestIdempotent.test_rfc2231_charsetN  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nz
msg_33.txtrL  rM  s      r9   test_more_rfc2231_parametersz+TestIdempotent.test_more_rfc2231_parametersR  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nz
msg_34.txtrL  rM  s      r9   %test_text_plain_in_a_multipart_digestz4TestIdempotent.test_text_plain_in_a_multipart_digestV  rO  r;   c                 P    | j                  d      \  }}| j                  ||       y )Nzmsg_12a.txtrL  rM  s      r9   test_nested_multipart_mixedsz+TestIdempotent.test_nested_multipart_mixedsZ  s$    LL/	Td#r;   c                 P    | j                  d      \  }}| j                  ||       y )Nrd  rL  rM  s      r9   %test_message_external_body_idempotentz4TestIdempotent.test_message_external_body_idempotent^  rO  r;   c                 T    | j                  d      \  }}| j                  ||d       y )N
msg_43.txtTr   rL  rM  s      r9   test_message_delivery_statusz+TestIdempotent.test_message_delivery_statusb  s)    LL.	TdT2r;   c                 P    | j                  d      \  }}| j                  ||       y N
msg_45.txtrL  rM  s      r9   test_message_signed_idempotentz-TestIdempotent.test_message_signed_idempotentf  rO  r;   c                 4   | j                   }| j                  d      \  }} ||j                         d       i }|j                         D ]
  \  }}|||<     ||d   d        ||d   d        ||j                  d| j
                  z           ||j                  | j
                          |t        |j                               d       |j                  d	      } ||j                         d
        ||j                         d| j
                  z          |j                  d      } ||j                         d
        ||j                         d| j
                  z          |j                  d      }	 ||	j                         d       | j                  |	t               |	j                         }
| j                  |
t                |t        |
      d       |
d	   }| j                  |t                ||j                         d| j
                  z          y )Nr6  r8  r9  r:  r  r<  z$This is a MIME-encapsulated message.r   r   r?   zYadda yadda yaddar|   r   r[  )r2   r3   rH   r  rN  r   rO  r  rZ   r  r   r  )r6   r7   r8   r   paramspkpvre  r  msg3r  msg4s               r9   test_content_typez TestIdempotent.test_content_typej  s   LL.	T
3!#56nn& 	FBF2J	
6- "34
6*FG
3<<?$,,NO
3<<&
3s !1%q!
4  "L1
42T\\ABq!
4  "L1
42T\\ABq!
4  "$45dG,""$gt,
3w<qzdG,
42T\\ABr;   c                    | j                   }| j                  d      \  }} ||j                         d       |j                         }| j	                  |t
                |t        |      d       |d   }| j	                  |t                ||j                         d       | j	                  |j                         t                ||j                         | j                         y )NrX  r[  r|   r   r?   )
r2   r3   rH   rZ   r  r  r  r   r   r   )r6   r7   r8   r   r  re  s         r9   test_parserzTestIdempotent.test_parser  s    LL.	T
3!#34 //#gt,
3w<qzdG,
4  "L1d..0#6
4t||,r;   NF)r  r  r  r   r3   rE  rH  rJ  rN  rR  rT  rV  rY  r[  r  r^  r`  rb  r  rf  rh  rj  rl  rn  rq  ru  r|  r~  r  r;   r9   r?  r?  
  s    G
$$$$$$$$$$$$$$$$$$3$C>-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) Z+d* Z, e-j\                          e/j`                  d+      d,               Z1d- Z2d. Z3d/ Z4d0 Z5d1 Z6d2 Z7d3 Z8d4 Z9d5 Z:d6 Z;d7 Z<d8 Z=y9):TestMiscellaneousc                 "   t        dd      5 }|j                         }d d d        t        j                        }t	               }t        |d      }|j                  |       | j                  ||j                                y # 1 sw Y   gxY wNr   rV   r   r   rt  	r'   r   r   r   r   r   r   r2   r   r6   r   r   r8   r   r   s         r9   test_message_from_stringz*TestMiscellaneous.test_message_from_string  st    lW5 	779D	''-J aa(			#qzz|,	 	s   BBc                 D   t        dd      5 }|j                         }|j                  d       t        j                  |      }t               }t        |d      }|j                  |       | j                  ||j                                d d d        y # 1 sw Y   y xY wr  )
r'   r   seekr   r  r   r   r   r2   r   r  s         r9   test_message_from_filez(TestMiscellaneous.test_message_from_file  s    lW5 		1779DGGAJ))"-C
A !!,AIIcNT1::<0		1 		1 		1s   A?BBc                    t        dd      5 }|j                         }d d d         G d dt              }t        j                  |      }| j                  ||       t        dd      5 }|j                         }d d d        t        j                  ||      }|j                         D ]  }| j                  ||        y # 1 sw Y   xY w# 1 sw Y   SxY w)Nr   rV   r   c                       e Zd Zy)HTestMiscellaneous.test_message_from_string_with_class.<locals>.MyMessageNr  r  r  r  r;   r9   	MyMessager        r;   r  rQ  )r'   r   r   r   r   r  walk)r6   r   r   r  r8   r   s         r9   #test_message_from_string_with_classz5TestMiscellaneous.test_message_from_string_with_class  s    lW5 	779D		 	 ''i8c9-lW5 	779D	''i8xxz 	6G!!'95	6	 		 	s   C+CCCc                 t    G d dt               }t        dd      5 }t        j                  ||      }d d d        | j	                  |       t        dd      5 }t        j                  ||      }d d d        |j                         D ]  }| j	                  ||        y # 1 sw Y   oxY w# 1 sw Y   =xY w)Nc                       e Zd Zy)FTestMiscellaneous.test_message_from_file_with_class.<locals>.MyMessageNr  r  r;   r9   r  r    r  r;   r  r   rV   r   rQ  )r   r'   r   r  r  r  )r6   r  r   r8   r   s        r9   !test_message_from_file_with_classz3TestMiscellaneous.test_message_from_file_with_class  s    	 	 lW5 	9))"i8C	9c9-lW5 	9))"i8C	9xxz 	6G!!'95	6	9 	9	9 	9s   B"B."B+.B7c                 j     G d dt               }| j                  d|      }| j                  ||       y )Nc                        e Zd Z fdZ xZS )STestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessagec                 "    t         |           y rf   )super__init__)r6   	__class__s    r9   r  z\TestMiscellaneous.test_custom_message_does_not_require_arguments.<locals>.MyMessage.__init__  s     "r;   )r  r  r  r  __classcell__)r  s   @r9   r  r    s    # #r;   r  zSubject: test

test)r   r  r  )r6   r  r8   s      r9   .test_custom_message_does_not_require_argumentsz@TestMiscellaneous.test_custom_message_does_not_require_arguments  s1    	# 	# mm3Y?c9-r;   c                 h    t        d      }| j                  t        |j                        g d       y )Nr   )r   rA   r   r    
feedparserr   r   r!   rq  message_from_binary_filer   r  r   r  r   r"   r#   )
__import__r2   sorted__all__)r6   modules     r9   test__all__zTestMiscellaneous.test__all__  s*    G$/ 2 	r;   c                     t        j                          }| j                  t        j                  t        j                  |            d d t        j
                  |      d d        y )N   )r1  r2   r#   	parsedate
formatdategmtimer6   r9  s     r9   test_formatdatez!TestMiscellaneous.test_formatdate  sK    iik)9)9#)>?CS)"1-	/r;   c                     t        j                          }| j                  t        j                  t        j                  |d            d d t        j
                  |      d d        y )NTr2  r  )r1  r2   r#   r  r  r2  r  s     r9   test_formatdate_localtimez+TestMiscellaneous.test_formatdate_localtime  sN    iikOOE,,SDAB2AFNN3#	%r;   c           	      f   t        j                          }| j                  t        j                  |d      t        j                  dt        j
                  |                   | j                  t        j                  |dd      t        j                  dt        j
                  |                   y )NFr  z%a, %d %b %Y %H:%M:%S -0000T)r2  usegmtz%a, %d %b %Y %H:%M:%S GMT)r1  r2   r#   r  r5  r  r  s     r9   test_formatdate_usegmtz(TestMiscellaneous.test_formatdate_usegmt  s    iikSE2MM7S9IJ	L 	SE$?MM5t{{37GH	Jr;   c                    g d}|D ]e  }| j                  |      5  | j                  t        j                  |             | j                  t        j                  |             d d d        g | j                  t        j                  d              | j                  t        j                  d              y # 1 sw Y   xY w)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)r6   invalid_datesr  s      r9   /test_parsedate_returns_None_for_invalid_stringszATestMiscellaneous.test_parsedate_returns_None_for_invalid_strings  s    

 # 	=EE* =!!%//%"89!!%"4"4U";<= =	=
 	%//$/0%,,T23= =s   A	B88C	c                     | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       y )NzWed, 3 Apr 2002 14:58:26 +0800
  r   r      :      r   r|   r,  p  zWed,3 Apr 2002 14:58:26 +0800zWed 3 Apr 2002 14:58:26 +0800r2   r#   r  r  s    r9   test_parsedate_compactz(TestMiscellaneous.test_parsedate_compact  sf    ++,LMB	D 	++,KLB	D 	++,KLB	Dr;   c                     | j                   } |t        j                  d      d        |t        j                  d      d       y )N5 Feb 2003 13:47:26 -0800
  r         /   r  r   r|   r,  透zFebruary 5, 2003 13:47:26 -0800r  r6   r7   s     r9   test_parsedate_no_dayofweekz-TestMiscellaneous.test_parsedate_no_dayofweek  s?    
59:5	7
5?@5	7r;   c                 N    | j                  t        j                  d      d       y )NzWed, 3 Apr 2002 14:58:26+0800r  r  r  s    r9   .test_parsedate_no_space_before_positive_offsetz@TestMiscellaneous.test_parsedate_no_space_before_positive_offset   s!    ++,KL4	6r;   c                 N    | j                  t        j                  d      d       y )NzWed, 3 Apr 2002 14:58:26-0800)
r  r   r   r  r  r  r   r|   r,  r  r  r  s    r9   .test_parsedate_no_space_before_negative_offsetz@TestMiscellaneous.test_parsedate_no_space_before_negative_offset$  s!    ++,KL5	7r;   c                     | j                   } |t        j                  d      d        |t        j                  d      d       y )Nz5 Feb 2003 13.47.26 -0800r  z5 Feb 2003 13.47 -0800)
r  r   r  r  r  r   r   r|   r,  r  r  r  s     r9   %test_parsedate_accepts_time_with_dotsz7TestMiscellaneous.test_parsedate_accepts_time_with_dots)  s?    
59:5	7
5674	6r;   c                 N    | j                  t        j                  d      d       y )NzFriday, 19-Nov-82 16:14:55 EST)
i           r  7   r   r|   r,  ir  r  s    r9   test_parsedate_rfc_850z(TestMiscellaneous.test_parsedate_rfc_8500  s!    ++,LM7	9r;   c                 N    | j                  t        j                  d      d       y )NzWed, 3 Apr 2002 14:58 +0800
r  r   r   r  r  r   r   r|   r,  r  r  r  s    r9   test_parsedate_no_secondsz+TestMiscellaneous.test_parsedate_no_seconds4  s"    ++,IJA	Cr;   c                     | j                  t        j                  d      d       | j                  t        j                  d      d       y )NzWed, 3 Apr 2002 14.58.26 +0800r  zWed, 3 Apr 2002 14.58 +0800r  r  r  s    r9   !test_parsedate_dot_time_delimiterz3TestMiscellaneous.test_parsedate_dot_time_delimiter8  sB    ++,LMB	D++,IJA	Cr;   c           
         | 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       y )Nr  r  z%Yr  	   )	r2   r#   r  intr1  mktimer2  r5  r  )r6   r7   timetupr  s       r9   +test_parsedate_acceptable_to_time_functionsz=TestMiscellaneous.test_parsedate_acceptable_to_time_functions>  s    //"=>G$%
4>>!Ra '"1+.
3t}}T7+,d3$$%@AGBQK()
4>>!Ra '"1+.
3t}}T72A;/0$7r;   c                     | j                  t        j                  d      d       | j                  t        j                  d      d       y )N)
  r|   r|   r   r   r   r,  r,  r,  r   r   )
r  r|   r|   r   r   r   r,  r,  r,  i  i.)r2   r#   	mktime_tzr  s    r9   test_mktime_tzz TestMiscellaneous.test_mktime_tzI  sE     *9 :;<	> *< =>C	Er;   c                     | j                  t        j                  d      t        j                  d             | j                  t        j                  d      t        j                  d             y)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    r9   test_parsedate_y2kz$TestMiscellaneous.test_parsedate_y2kO  s\     	++,FG++,HI	K++,FG++,HI	Kr;   c                     | j                  t        j                  d      d       | j                  t        j                  t        j                  d            d       y )Nz<>r+   r+   r+   r2   r#   	parseaddr
formataddrr  s    r9   test_parseaddr_emptyz&TestMiscellaneous.test_parseaddr_empty\  s?    .9))%//$*?@"Er;   c                     | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       y )Nza@b@cr  za@b.c@cza@172.17.0.1@cr2   r#   r  r  s    r9   test_parseaddr_multiple_domainsz1TestMiscellaneous.test_parseaddr_multiple_domains`  s^    OOG$	
 	OOI&	
 	OO,-	
r;   c                 N    | j                  t        j                  d      d       y )N)zA Silly Personperson@dom.ainzA Silly Person <person@dom.ain>r2   r#   r  r  s    r9   test_noquote_dumpz#TestMiscellaneous.test_noquote_dumpn  s"    AB-	/r;   c                    | j                  t        j                  d      d       | j                  t        j                  d      d       d}d}| j                  t        j                  t        j                  ||f            ||f       y )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  r2   r#   r  r  r6   r  r  s      r9   test_escape_dumpz"TestMiscellaneous.test_escape_dumps  sz    HI7	9 	OOIJ7	9 $)9)91a&)ABQFKr;   c                     | j                  t        j                  d      d       d}d}| j                  t        j                  t        j                  ||f            ||f       y )N)Arthur \Backslash\ Foobarr  z."Arthur \\Backslash\\ Foobar" <person@dom.ain>r  r  r  r  s      r9   test_escape_backslashesz)TestMiscellaneous.test_escape_backslashes~  sZ    MN=	? ))9)91a&)ABQFKr;   c                     d}d}d}d}| j                  t        j                  ||f      |       | j                  t        j                  ||fd      |       y )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  )r6   r   addrutf8_base64latin1_quopris        r9   test_quotes_unicode_namesz+TestMiscellaneous.test_quotes_unicode_names  sY    %EJ))4,7E))4,E	r;   c                     d}d}d}d G fdd      } |       }d|d}| j                  t        j                  ||f|      |       | j                  t        j                  ||ft        d	            |       y )
Nr   r  r  FOOBARc                       e Zd Z fdZy)KTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMockc                     S rf   r  )r6   stringrN  s     r9   header_encodezYTestMiscellaneous.test_accepts_any_charset_like_object.<locals>.CharsetMock.header_encode  s    r;   N)r  r  r  r  )rN  s   r9   CharsetMockr	    s    r;   r  z <>rV   )r2   r#   r  r
   )r6   r   r  r  r  mockmock_expectedrN  s          @r9   $test_accepts_any_charset_like_objectz6TestMiscellaneous.test_accepts_any_charset_like_object  s~    %E	 	 }%+T2))4,=}M))4,8HI	r;   c                 p    d}d}t               }| j                  t        t        j                  ||f|       y )Nr   r  )objectr   AttributeErrorr#   r  )r6   r   r  bad_charsets       r9   -test_invalid_charset_like_object_raises_errorz?TestMiscellaneous.test_invalid_charset_like_object_raises_error  s4    %h.%*:*:T4L	r;   c                     d}| j                  t        t        j                  d |f       | j                  t        t        j                  d|f       y )Nu   persön@dom.inName)r   UnicodeErrorr#   r  )r6   r  s     r9   !test_unicode_address_raises_errorz3TestMiscellaneous.test_unicode_address_raises_error  s?    #,(8(84,G,(8(864.Ir;   c                     d}d}d\  }}| j                  t        j                  |      ||f       | j                  t        j                  |      ||f       | j                  t        j                  ||f      |       y )NzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>)zJohn X. Doezjxd@example.comr  )r6   r  yr  r  s        r9   test_name_with_dotz$TestMiscellaneous.test_name_with_dot  sn    +-11+aV4+aV4))1a&115r;   c                     | j                   } |t        j                  d      d        |t        j                  d      d        |t        j                  d      d       y )N""example" example"@example.com)r+   r  !"\"example\" example"@example.com)r+   r   #"\\"example\\" example"@example.com)r+   r!  r  r  s     r9   2test_parseaddr_preserves_quoted_pairs_in_addresseszDTestMiscellaneous.test_parseaddr_preserves_quoted_pairs_in_addresses  sT     
5??<=
1	3
5??@A
5	7
5??DE
9	;r;   c                 v   | j                  dt        j                  d             | j                  dt        j                  d             | j                  dt        j                  d             | j                  dt        j                  d             | j                  dt        j                  d	             y )
N)r+   merwok wok@xample.comr$  )r+   merwok  wok@xample.comr%  z merwok  wok  @xample.com)r+   merwok"wok"  wok@xample.comr&  )r+   zmerwok.wok.wok@xample.comzmerwok. wok .  wok@xample.comr  r  s    r9   -test_parseaddr_preserves_spaces_in_local_partz?TestMiscellaneous.test_parseaddr_preserves_spaces_in_local_part  s     	6OO34	67OO45	77OO78	:<OO9:	<:OO;<	>r;   c                     d}d}| j                  t        j                  |      |       | j                  t        j                  |      |       y )N)z#'foo@example.com' (foo@example.com)foo@example.comz7"'foo@example.com' (foo@example.com)" <foo@example.com>r  )r6   r  addrstrs      r9   6test_formataddr_does_not_quote_parens_in_quoted_stringzHTestMiscellaneous.test_formataddr_does_not_quote_parens_in_quoted_string  sE    #C148))$/9r;   c                 R    d}| j                  t        j                  |      d       y )NzFoo
	Bar <foo@example.com>)zFoo Barr)  r  )r6   r  s     r9   test_multiline_from_commentz-TestMiscellaneous.test_multiline_from_comment  s%     	+-KLr;   c                 N    | j                  t        j                  d      d       y )N)zA Silly; Personr  z""A Silly; Person" <person@dom.ain>r  r  s    r9   test_quote_dumpz!TestMiscellaneous.test_quote_dump  s"    BC1	3r;   c                 X   | j                   }| j                  }t               }t               } ||d        ||d        ||d        |d|        |d|        |d|        ||d        ||d        ||d        |d|        |d|        |d|        |||        |||       y )NrN   US-ASCIIzUs-AsCiIusasciiUSASCIIUsAsCiI)r2   assertNotEqualr
   )r6   r7   necset1cset2s        r9   test_charset_richcomparisonsz.TestMiscellaneous.test_charset_richcomparisons  s      		
5*
5*
5*
:u
:u
:u
5)
5)
5)
9e
9e
9e
5%
5%r;   c                 \    | j                   } |t        j                  ddg      ddg       y )Naperson@dom.ain (Al Person)zBud Person <bperson@dom.ain>z	Al PersonrH  )z
Bud PersonrI  r2   r#   getaddressesr  s     r9   test_getaddressesz#TestMiscellaneous.test_getaddresses  s9    
5<=? @,-/	0r;   c                 V    | j                  t        j                  g d      g d       y)zGH-106669 regression test.)z"Bud, Person" <bperson@dom.ain>r;  z#"Mariusz Felisiak" <to@example.com>))zBud, PersonrI  r<  )zMariusz Felisiakzto@example.comNr=  r  s    r9   test_getaddresses_comma_in_namez1TestMiscellaneous.test_getaddresses_comma_in_name
  s(    	
r;   c                     | j                   } |t        j                  dg      dg        |t        j                  dg      g d        |t        j                  ddg      ddg       y )Nzfoo: ;r  z	[]*-- =~$)r  r  )r+   z*--z#"Jason R. Mastaler" <jason@dom.ain>)zJason R. Mastalerzjason@dom.ainr=  r  s     r9   test_getaddresses_nastyz)TestMiscellaneous.test_getaddresses_nasty  sl    
5xj)H:6
5=,	. 	5;<><=	?r;   c                 f    | j                   }t        j                  dg      } ||d   d   d       y)z(Test proper handling of a nested commentz%User ((nested comment)) <foo@bar.com>r   r|   foo@bar.comNr=  )r6   r7   addrss      r9   "test_getaddresses_embedded_commentz4TestMiscellaneous.test_getaddresses_embedded_comment%  s3    ""$K#LM
58A;&r;   c                 r    t        j                  t        d      g      }| j                  |d   d   d       y)z%Test the handling of a Header object.zAl Person <aperson@dom.ain>r   r|   rH  N)r#   r>  r   r2   )r6   rF  s     r9   test_getaddresses_header_objz.TestMiscellaneous.test_getaddresses_header_obj+  s4    ""F+H$I#JKq!&78r;   cpuc                 h    G d dt               }t        d      D cg c]	  } |        }}t        j                  |      5  	 d d d        t	        |D cg c]  }|j
                   c}g       }| j                  t        t        |            t        |             y c c}w # 1 sw Y   `xY wc c}w )Nc                       e Zd Zd Zy)BTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThreadc                     g | _         | j                   j                  }t        j                  }t        j
                  } |       dz   } |       |k  r | |d              |       |k  ry y )Ng      @testdomain-stringdomain)msgidsr   r#   
make_msgidr1  	monotonic)r6   r   rS  clocktfins        r9   runzFTestMiscellaneous.test_make_msgid_collisions.<locals>.MsgidsThread.run5  sY     ++"--
w}gn:-@AB gnr;   N)r  r  r  rW  r  r;   r9   MsgidsThreadrM  4  s    Cr;   rX  r  )	r   rH  r%   start_threadssumrR  r2   r  set)r6   rX  rB  threadsr  all_idss         r9   test_make_msgid_collisionsz,TestMiscellaneous.test_make_msgid_collisions0  s    		C6 		C ,184a<>44++G4 		1Aqxx126S\*CL9	 5	 	1s   BB#B/#B,c                     | j                   }t               }|j                  ddd        ||j                         d       y )NrF  rB  zfoo\wacky"namerD  )r2   r   rH  r   r5   s      r9   test_utils_quote_unquotez*TestMiscellaneous.test_utils_quote_unquoteE  sA    i,l 1 	 	3
301r;   c                 Z    t        d      }| j                  |j                         d       y )Nznot a charsetrW   r
   r2   get_body_encodingr6   rA   s     r9   )test_get_body_encoding_with_bogus_charsetz;TestMiscellaneous.test_get_body_encoding_with_bogus_charsetL  s%    /*224h?r;   c                    | j                   }t               }d|d<    ||d   d       |j                         } |t        |      d        ||d   d       t	        |d         } ||j                         d       |j                  d|	        ||j                         d
        ||j                  d      d        ||d   d       t               }d|d<   |j                         } |t        |      d        ||d   d       t	        |d         } ||j                         t        j                         |j                  d|	        ||j                         d        ||d   d       y )Nztext/plain; charset=UTF-8rD   r@   r|   r   rV   rW   r   rM  aGVsbG8gd29ybGQ=
TrX   rB   ztext/plain; charset="US-ASCII"rN   r  r  )
r2   r   ru   r  r
   rc  rR   rZ   r   r  )r6   r7   r8   rv   rA   s        r9   -test_get_body_encoding_with_uppercase_charsetz?TestMiscellaneous.test_get_body_encoding_with_uppercase_charsetP  sS   i9N
3~ ;<##%
3x=!
8A; (1+&
7$$&18
3??23
3??$?'8
3*+X6i>N##%
3x=!
8A;
#(1+&
7$$&(?(?@w7
3??m,
3*+V4r;   c                     t        d      }t        d      }| j                  |j                         |j                                y )NrN   r1  rb  )r6   lcucs      r9   test_charsets_case_insensitivez0TestMiscellaneous.test_charsets_case_insensitivej  s8    Z Z --/1E1E1GHr;   c                     | j                   }| j                  d      }t               }t        j                  ||        ||j                         d       y )Nrp  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
rk  rm  s       r9   1test_partial_falls_inside_message_delivery_statuszCTestMiscellaneous.test_partial_falls_inside_message_delivery_statuso  sI    ""
 ll<(jS#&
3<<>  	r;   c                 j    | j                  t        j                  j                  d      dd  d       y )NrO  rP  iz@testdomain-string>r2   r   r#   rS  r  s    r9   test_make_msgid_domainz(TestMiscellaneous.test_make_msgid_domain  s0    KK""*=">stD!	#r;   c                 l    | j                  t        j                  j                  dd      dd  d       y )Nztest-idstringrO  )idstringrQ  iz!.test-idstring@testdomain-string>rp  r  s    r9   test_make_msgid_idstringz*TestMiscellaneous.test_make_msgid_idstring  s9    KK""O* # ,,/D2/	1r;   c                     t        d      5 }dx|_        }| j                  t        j                  j                         j                  d|z   dz                d d d        y # 1 sw Y   y xY w)Nzsocket.getfqdnzpythontest.example.com@r  )r	   return_valuer   r   r#   rS  endswith)r6   mock_getfqdnrQ  s      r9   test_make_msgid_default_domainz0TestMiscellaneous.test_make_msgid_default_domain  sb    #$ 	)1IIL%OO&&(11&L3&()	) 	) 	)s   AA!!A*c                 l   t        ddd      5 }|j                         }d d d        j                  dd      }t        j                  |      }t               }t        j                  j                  |      }|j                  |       | j                  |j                         |       y # 1 sw Y   xY w)N
msg_26.txtrV   r*   r   newliner   )r'   r   r   r   r   r   r   r   r   r2   r   r6   fmsgtxt	msgtxt_nlr8   r   r   s          r9   test_Generator_linendz'TestMiscellaneous.test_Generator_linend  s    lWdC 	qVVXF	NN640	''/JOO%%a(			#y1	 	s   B**B3c                    t        ddd      5 }|j                         }d d d        j                  dd      }t        j                  |      }t               }t        j                  j                  |      }|j                  |d       | j                  |j                         j                  d      |       y # 1 sw Y   xY w)Nr|  rV   r*   r}  r   r   r   )r'   r   r   r   r   r   r   r   r   r2   r   rY   r  s          r9   test_BytesGenerator_linendz,TestMiscellaneous.test_BytesGenerator_linend  s    lWdC 	qVVXF	NN640	''	2IOO**1-			#v	&,,W5v>	 	s   B;;Cc                    t        dd      5 }|j                         }d d d        j                  dd      }|j                  dd      }t        j                  |      }t               }t        j                  j                  |      }|j                  |d       | j                  |j                         |       y # 1 sw Y   xY w)	Nr|  r  s   with attachments   fo   
r   r   r   )r'   r   r   r   r   r   r   r   r   r2   r   r  s          r9   )test_BytesGenerator_linend_with_non_asciiz;TestMiscellaneous.test_BytesGenerator_linend_with_non_ascii  s    lD) 	QVVXF	 2I>NN7E2	&&y1IOO**1-			#v	&v.	 	s   B<<Cc                 2   t        dd      5 }|j                         }d d d        t        dd      5 }|j                         }d d d        t        dft        fft        fft
        t               fft        dft        dfg}|D ]  \  }}| j                  |j                  d      5   || }| j                  |j                  t        j                  j                         d d d        | j                  |j                  d      5   ||d	t        j                  j                  i}| j                  |j                  t        j                  j                         d d d         y # 1 sw Y   JxY w# 1 sw Y   2xY w# 1 sw Y   xY w# 1 sw Y   xY w)
Nr  r  r  )r+   )r)  r*  rx  )clsr   r{  r   )r'   r   r   r   r   r   r   r   r   r  r  r  r   r   rx  r{  )r6   r   	audiodatar  classesr  constructorr   s           r9   !test_mime_classes_policy_argumentz3TestMiscellaneous.test_mime_classes_policy_argument  sf   k4( 	"B	I	"lD) 	 RggiG	  e$%
#79,'56u
 !( 	>C#,,zB ?%ahh(=(=>? #,,yA >BU\\-A-ABahh(<(<=> >		>	" 	"	  	 ? ?> >s/   E&E3':F AF&E03E= F		F	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  r  r"  r'  r+  r-  r/  r9  r?  rA  rC  rG  rI  r%   requires_working_threadingr$   requires_resourcer^  r`  re  rh  rl  rn  rq  rt  rz  r  r  r  r  r  r;   r9   r  r    sS   	-
16"6./
%J4,D767
69CC	8EKF
/
	LLJ6;$>$:M3
(0
"?'9
 1002Wu%: & 3:&2@54I
(T#
1)	2	?
/>r;   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestIteratorsc                 ,   | j                   }| j                  }| j                  d      }t        j                  |      }t        |      } |t        |      d        |t        j                  |      |j                                | j                  d      }t        j                  |      }t        |      } |t        |      d       t        dd      5 } |t        j                  |      |j                                d d d        y # 1 sw Y   y xY w)Nr   r  rQ  +   z
msg_19.txtrV   r   )r2   r  r3   r!   body_line_iteratorr  r  EMPTYSTRINGr   rZ   r'   r   )r6   r7   r  r8   itr   r   s          r9   test_body_line_iteratorz%TestIterators.test_body_line_iterator  s    ##ll<())#.R
3u:qKU#S__%67ll<())#.R
3u:rlW5 	4  '3	4 	4 	4s   +D

Dc                    | j                   }| j                  d      }t        j                  |d      }g }d}|D ]&  }|dz  }|j	                  |j                                (  ||d        |t        j                  |      d       y )Nry   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
r2   r3   r!   typed_subpart_iteratorr   rZ   r  r   r6   r7   r8   r  r   subpartsr   s          r9   test_typed_subpart_iteratorz)TestIterators.test_typed_subpart_iterator  s    ll<(--c6: 	0GMHLL,,./	0 	8Q
;E" % 	r;   c                    | j                   }| j                  d      }t        j                  |dd      }g }d}|D ]&  }|dz  }|j	                  |j                                (  ||d        |t        j                  |      d       y )Nr   r   r  r   r|   z%
Hi,

Do you like this message?

-Me
r  r  s          r9   (test_typed_subpart_iterator_default_typez6TestIterators.test_typed_subpart_iterator_default_type  s    ll<(--c67C 	0GMHLL,,./	0 	8Q
;E" % 	r;   c           
         g d}ddl m}m}  |       }g }d}|D ]`  \  }}|j                  |       ||z  }d}	t	        |j
                  |      D ]  }
|j                  |
       |	dz  }	 | j                  ||	       b | j                  t        |      |       | j                  dj                  |D cg c]  \  }}|	 c}}      dj                  |             yc c}}w )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+   N)
email.feedparserr  r  pushiterreadliner   r2   r  r   )r6   imtr  r  bsfomntilnn1ols              r9   test_pushCR_LFzTestIterators.test_pushCR_LF  s    
	 	C 	$EBHHRL!GBB3<<6 		"a Q#	$ 	R"%#!6Q"!67E!6s   3Cc                 x   ddl m}m} d}d}ddj                  fdt	        |      D              dz   }|j                  d	      } |       }g }t	        dt        |      |      D ]@  }	||	|	|z    }
|j                  |
       |j                  t        |j                  |             B | j                  ||       y )
Nr   r  i'  r  zabcd 	
r+   c              3   4   K   | ]  }t                y wrf   r   )rA  rB  charss     r9   rC  z1TestIterators.test_push_random.<locals>.<genexpr>?  s     4aF5M4s   r*   T)r  r  r  r   rH  r  r  r  extendr  r  r2   )r6   r  r  r  	chunksizer   targetr  r   rB  chunkr  s              @r9   test_push_randomzTestIterators.test_push_random8  s    B	GG45844t;d#q#a&), 	;Aa)$EHHUOLLcllL9:	; 	'r;   N)r  r  r  r  r  r  r  r  r  r;   r9   r  r    s    4""&F<(r;   r  c                   $    e Zd Zd Zd Zd Zd Zy)TestFeedParsersc                 f    t               }|D ]  }|j                  |        |j                         S rf   )r)   feedclose)r6   chunksr  r  s       r9   parsezTestFeedParsers.parseM  s3    \
 	#EOOE"	#!!r;   c                 z    | j                  d      }| j                  |d   d       | j                  |d   d       y )NzFirst: val
: bad
Second: valr  valr  )r  r2   rh   s     r9   test_empty_header_name_handledz.TestFeedParsers.test_empty_header_name_handledS  s9    jj9:Wu-X.r;   c                    | j                  dg      }| j                  |j                         g d       | j                  dg      }| j                  |j                         g d       | j                  ddg      }| j                  |j                         ddg       | j                  dd	g      }| j                  |j                         dd
g       | j                  ddg      }| j                  |j                         dd
g       | j                  dg      }| j                  |j                         dg       | j                  g d      }| j                  |j                         ddg       y )Nza:
b:c:
d:
)r  r  cdz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  r2   r  r   r  s     r9   test_newlineszTestFeedParsers.test_newlinesY  s3   JJ,-.#78JJ*+,#78JJ()C;/JJ'(C:.JJ)*C:. JJ,-.%<$=>JJ12Y$@Ar;   c                    d\  }}| j                  dgd|z  g|z  z         }| j                  |j                         dg       | j                  |j                         d|z  |z         | j                  dgd|z  g|z  z         }| j                  |j                         dg       | j                  |j                         d|z  |z         | j                  dgd|z  dz   g|z  z         }| j                  |j                         dg       | j                  |j                         d|z  dz   |z         | j                  ddgd|z  g|z  z         }| j                  |j                         d	d
d|z  |z  fg       y )N)i  i N  za:b

r  )r  r  za:b   r  zb: r  r  )r  r2   r   rZ   )r6   MNr   s       r9   test_long_lineszTestFeedParsers.test_long_linesk  s\   1JJ	{c!eWq[01ZL1#a%'2JJ	{c!eWq[01ZL1#a%'2JJ	{c!eFl^a%778ZL13q5<*:;JJ#a%145Yc!eAg$?@r;   N)r  r  r  r  r  r  r  r  r;   r9   r  r  K  s    "/B$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y)TestParsersc                 v   | j                   }t        dd      5 }t               j                  |      }d d d         |d   d        ||d   d        ||j	                         d       | j                  |j                                | j                  |j                         t               y # 1 sw Y   |xY w)	NrQ  rV   r   r   ppp-request@zzz.orgr   ppp@zzz.orgrk   )
r2   r'   r   r  rH   r  r  r  rZ   r   r6   r7   r   r8   s       r9   test_header_parserzTestParsers.test_header_parser}  s    lW5 	+.&&r*C	+
3v;-.
3t9m$
3!#45))+,coo/5	+ 	+s   B//B8c                    | j                   }t        dd      5 }t        j                  j	                         j                  |      }d d d         |d   d        ||d   d        ||j                         d       | j                  |j                                | j                  |j                         t               | j                  |j                  d	      t               y # 1 sw Y   xY w)
NrQ  r  r   r  r   r  rk   TrX   )r2   r'   r   r   r   r  rH   r  r  r  rZ   r   r   r  s       r9   test_bytes_header_parserz$TestParsers.test_bytes_header_parser  s    lD) 	=R,,00288<C	=
3v;-.
3t9m$
3!#45))+,coo/5cooTo:EB	= 	=s   .C((C1c                 6   t        dd      5 }|j                         }d d d        t        j                  j	                  t        j
                  j                        }|j                  d      }| j                  |j                  g        y # 1 sw Y   qxY w)Nz
msg_47.txtrV   r   r   T)headersonly)
r'   r   r   r   r   r   r{  r   r2   r  )r6   r   r   r   
parsed_msgs        r9   %test_header_parser_multipart_is_validz1TestParsers.test_header_parser_multipart_is_valid  sy    lW5 	 ggiG	  $$ELL,@,@$A__W$_?
++R0	  	 s   BBc                     t        dd      5 }t        j                  j                         j	                  |       | j                  |j                         d d d        y # 1 sw Y   y xY w)NrQ  r  )r'   r   r   BytesParserr  r  closedr  s     r9   %test_bytes_parser_does_not_close_filez1TestParsers.test_bytes_parser_does_not_close_file  sP    lD) 	(RLL$$&,,R0RYY'	( 	( 	(s   A	AA(c                 X   t        dd      5 }t        j                  j                  }| j	                  t        j
                  j                   |t        j                  j                        j                  |       | j                  |j                         d d d        y # 1 sw Y   y xY w)Nr  r  r   )r'   r   r   r  r   r    r  r   strictr  r  r  )r6   r   bytesParsers      r9   2test_bytes_parser_on_exception_does_not_close_filez>TestParsers.test_bytes_parser_on_exception_does_not_close_file  s{    lD) 	(R,,22KellFF)1D1DEKK " RYY'	( 	( 	(s   B
B  B)c                     t        dd      5 }t        j                  j                         j	                  |       | j                  |j                         d d d        y # 1 sw Y   y xY w)NrQ  rV   r   )r'   r   r   r   r  r  r  r  s     r9   test_parser_does_not_close_filez+TestParsers.test_parser_does_not_close_file  sP    lW5 	(LL!''+RYY'	( 	( 	(s   A	A  A)c                 Z   t        dd      5 }t        j                  j                  }| j	                  t        j
                  j                   |t        j                  j                        j                  |       | j                  |j                         d d d        y # 1 sw Y   y xY w)Nr  rV   r   r   )r'   r   r   r   r   r    r  r   r  r  r  r  )r6   r   r   s      r9   ,test_parser_on_exception_does_not_close_filez8TestParsers.test_parser_on_exception_does_not_close_file  sy    lW5 	(\\((FellFF$ELL,?,?@FFLRYY'		( 	( 	(s   B
B!!B*c                     | j                   }t        j                  d      } ||d   d        ||d   d        ||j                         d       y )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
r2   r   r   rZ   r5   s      r9   test_whitespace_continuationz(TestParsers.test_whitespace_continuation  V     '' 	) 	 	3y>?@
3|f%
3??9:r;   c                     | j                   }t        j                  d      } ||d   d        ||d   d        ||j                         d       y )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  r5   s      r9   (test_whitespace_continuation_last_headerz4TestParsers.test_whitespace_continuation_last_header  r  r;   c                    | j                   }t        ddd      5 }t               j                  |      }d d d         |t	        j                               d       |j                  d      } ||j                         d        ||j                         d       |j                  d	      } ||j                         d
       y # 1 sw Y   xY w)Nr|  rV   r*   r}  r   r   r?   z!Simple email with attachment.

r|   zapplication/riscos)r2   r'   r   r  r  rZ   rH   )r6   r7   r   r8   part1part2s         r9   test_crlf_separationz TestParsers.test_crlf_separation  s    lWdC 	%r(..$C	%
3s !1%"
5!!#\2
5 GH"
5!!#%9:	% 	%s   CCc                 $   t        ddd      5 }|j                         }d d d        t        j                        }t	               }t        |      }|j                  |d       | j                  |j                         |       y # 1 sw Y   gxY w)Nr|  rV   r*   r}  r   r   r  r  s         r9   test_crlf_flattenzTestParsers.test_crlf_flatten  sv    lWdC 	r779D	''-JaL			#v	&t,	 	s   BBNc                    | j                   }| j                  }t        dd      5 }t        j                  |      }d d d         |j                         d        |t        |j                               d       |j                  d      } ||j                         d        ||j                         d        |t        |j                               d       |j                  d      } ||j                         d        ||j                         d        ||j                         d	       |j                  d      } ||j                         d        ||j                         d        |t        |j                               d       |j                  d      } ||j                         d        ||j                         d        ||j                         d
       y # 1 sw Y   xY w)Nrd  rV   r   r|   r   r   r[  r?   r"  r#  )	r2   r  r'   r   r  r  r  rZ   rH   )	r6   r7   r  r   r8   r  part1ar  part2as	            r9   -test_multipart_digest_with_extra_mime_headersz9TestParsers.test_multipart_digest_with_extra_mime_headers  s   ##lW5 	.))"-C	. 	3q!
3s !1%"
5!!#%56
5#
3u  "#Q'""1%
6 !$
6""$l3F -0"
5!!#%56
5#
3u  "#Q'""1%
6 !$
6""$l3F -05	. 	.s   G&&G0c                     g d}t        j                  t        j                  |            }| j	                  |d   d       y )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   r2   )r6   r   r8   s      r9   test_three_lineszTestParsers.test_three_lines  s8    : ''7V&GHr;   c                     | j                   }d}d}d|d|d}t        j                  |      } ||j                  d      |        ||j                  d      |       y )Nr   z	more textzHeader: z
Next-Header: z

Body

r   zNext-Header)r2   r   r   get)r6   r7   value1value2r   r8   s         r9   3test_strip_line_feed_and_carriage_return_in_headersz?TestParsers.test_strip_line_feed_and_carriage_return_in_headers  sY    F''*
3778f%
377=!6*r;   c                     | j                   }d}t        j                  |      } |t        |      d        |t	        d |D              g d        ||j                         d       y )Nz(>From: foo
From: bar
!"#QUX;~: zoo

bodyr   c              3       K   | ]  }|  y wrf   r  )rA  fields     r9   rC  z9TestParsers.test_rfc2822_header_syntax.<locals>.<genexpr>)  s     )E%)   )z!"#QUX;~z>Fromr   r  )r2   r   r   r  r  rZ   r  s       r9   test_rfc2822_header_syntaxz&TestParsers.test_rfc2822_header_syntax$  sV    :''*
3s8Q
6)S))+HI
3??f%r;   c                     | j                   }d}t        j                  |      } |t        |j	                               d       y )Nz<>From foo@example.com 11:25:53
From: bar
!"#QUX;~: zoo

bodyr   )r2   r   r   r  r  r  s       r9   (test_rfc2822_space_not_allowed_in_headerz4TestParsers.test_rfc2822_space_not_allowed_in_header,  s6    N''*
3sxxz?Ar;   c                     | j                   }d}t        j                  |      }|j                         }|j	                           ||g d        ||j                         d       y )Nz7A: first header
B: second header
CC: third header

body)ABCCr  )r2   r   r   r  sortrZ   )r6   r7   r   r8   headerss        r9   !test_rfc2822_one_character_headerz-TestParsers.test_rfc2822_one_character_header2  sR    I''*((*
7$%
3??f%r;   c                     d}t        j                  |      }| j                  |j                  d      j                         j	                  d             y )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   rZ   rx  r6   r   r8   s      r9   test_CRLFLF_at_end_of_partz&TestParsers.test_CRLFLF_at_end_of_part;  sG    
 	
 ''**668AA&IJr;   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r;   r9   r  r  {  sf    	6
C1(
((
(;$;$	;- G1>I	+&&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	Zd
j                  eD  cg c]  \  }}|	 c}}}       dz   j                  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      j                  d      Zd Zd Z ej                  d      Zd Z d Z!d Z"ejG                  d
      Z$dge$d d! d
j                  e$      Z$d" Z% ej                  d#      j                  d$      Z& ej                  d%      Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d-Z/y-c c}}} w ).Test8BitBytesHandlingz        From: foo@bar.com
        To: baz
        Mime-Version: 1.0
        Content-Type: text/plain; charset={charset}
        Content-Transfer-Encoding: {cte}

        {bodyline}
        c                 *   | j                   j                  ddd      j                  d      }t        j                  |      }| j                  |j                         d       | j                  |j                  d      dj                  d             y )NrV   r`      pöstalrA   r   bodyline   pöstal
TrX   bodytest_msgr  r   r   r   r2   rZ   r  s      r9   test_known_8bit_CTEz)Test8BitBytesHandling.test_known_8bit_CTEb  s    $$W)/.7 % 99? 	
 &&q)*K85$++G4	6r;   c                 *   | j                   j                  ddd      j                  d      }t        j                  |      }| j                  |j                         d       | j                  |j                  d      d	j                  d             y )
Nnotavalidcharsetr`   r  r  rV   u   p��stal
TrX   r  r  r  s      r9   test_unknown_8bit_CTEz+Test8BitBytesHandling.test_unknown_8bit_CTEk  s    $$-?)/.7 % 99? 	
 &&q)*,AB5$++G4	6r;   c                 *   | j                   j                  ddd      j                  d      }t        j                  |      }| j                  |j                         d       | j                  |j                  d      dj                  d             y )	NrV   rC      p=C3=B6stálr  u   p=C3=B6stál
TrX   	   pöstál
r  r  s      r9   test_8bit_in_quopri_bodyz.Test8BitBytesHandling.test_8bit_in_quopri_bodyt  s     $$W);.< % >>DfWo 	
 &&q)*,<=5%,,W5	7r;   c                 *   | j                   j                  ddd      j                  d      }t        j                  |      }| j                  |j                         d       | j                  |j                  d      d	j                  d             y )
Nr   rC   r$  r  rV   u   p=C3=B6st��l
TrX   r%  r  r  s      r9   .test_invalid_8bit_in_non_8bit_cte_uses_replacezDTest8BitBytesHandling.test_invalid_8bit_in_non_8bit_cte_uses_replace  s     $$W);.< % >>DfWo 	
 &&q)*,FG5$++G4	6r;   c                 D   | j                   j                  ddd      j                  d      }t        j                  |      }| j                  |j                  d      dj                  d             | j                  |j                  d   t        j                         y )	NrV   rW   u   cMO2c3RhbAá=r  TrX   r  r   )r  r  r   r   r   r2   rZ   r  r  r    r  r  s      r9   test_8bit_in_base64_bodyz.Test8BitBytesHandling.test_8bit_in_base64_body  s     $$W)1.= % ??Evg 	
 &&q)5"))'2	4ckk!n$BB	Dr;   c                     | j                   j                  ddd      j                  d      }t        j                  |      }| j                  |j                  d      dj                  d             y )NrV   r   u   <,.V<W1A; á r  TrX   u   <,.V<W1A; á 
r  r  s      r9   test_8bit_in_uuencode_bodyz0Test8BitBytesHandling.test_8bit_in_uuencode_body  sn     $$W)3.= % ??Evg 	
 &&q)5*11':	<r;   c                    t        j                  d      j                  d      }t        j                  |      }| j                  |j                         d       | j                  |j                  d      dj                  d             y )Nu           From: foo@bar.com
        To: baz
        Mime-Version: 1.0
        Content-Type: text/plain; charset*=ansi-x3.4-1968''utf-8
        Content-Transfer-Encoding: 8bit

        pöstal
        rV   r  TrX   )r   r   r   r   r   r2   rZ   r  s      r9   test_rfc2231_charset_8bit_CTEz3Test8BitBytesHandling.test_rfc2231_charset_8bit_CTE  su    OO   VG_ 	
 &&q)*K85$++G4	6r;   ))zFrom: foo@bar.comr   rE  )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*   z
Yes, they are flying.
rV   c                     t        j                  | j                        }| j                  t	        |j                  d            d       | j                  t	        |d         d       y )Nr      b��z)r   r   headertest_msgr2   r   r  rh   s     r9   test_get_8bit_headerz*Test8BitBytesHandling.test_get_8bit_header  sO    &&t':':;SWWT]+-=>SY)9:r;   c                    t        j                  | j                        }| j                  t	        |       t        j                  d      j                  | j                  D cg c]
  \  }}|d    c}}        y c c}}w )Nz                            From: {}
                            To: {}
                            Subject: {}
                            From: {}

                            Yes, they are flying.
                            r|   )	r   r   r2  r2   r   r   r   r  headertest_headers)r6   r8   _r   s       r9   test_print_8bit_headersz-Test8BitBytesHandling.test_print_8bit_headers  sw    &&t':':;S( *  ! "((,(?(?*A-1h(1+ *AB		C*As   #A<c                     t        j                  | j                        }| j                  |j	                         D cg c]  }t        |       c}g d       y c c}w )N)rE  r1  ]   Maintenant je vous pr��sente mon coll��gue, le pouf c��l��bre
	Jean de Baddie	   g��st)r   r   r2  assertListEqualr  r   r6   r8   r  s      r9   test_values_with_8bit_headersz3Test8BitBytesHandling.test_values_with_8bit_headers  sE    &&t':':;cjjl;c!f;2	3;s   Ac           
          t        j                  | j                        }| j                  |j	                         D cg c]  \  }}t        |      t        |      f c}}g d       y c c}}w )N)r/  )r   r1  )r  r9  )r   r:  )r   r   r2  r;  r   r   )r6   r8   r  r  s       r9   test_items_with_8bit_headersz2Test8BitBytesHandling.test_items_with_8bit_headers  sR    &&t':':;SYY[I6Aqs1vs1v.I<	=Is    A*
c                     t        j                  | j                        }| j                  |j	                  d      D cg c]  }t        |       c}ddg       y c c}w )Nr   rE  r:  )r   r   r2  r;  r4   r   r<  s      r9   test_get_all_with_8bit_headersz4Test8BitBytesHandling.test_get_all_with_8bit_headers  sN    &&t':':;ckk&.ABc!fB,02	3Bs   Ac                 2   t        j                  t        j                  d      j	                  d            }| j                  |j                         d       | j                  |j                         d       | j                  |j                         d       y )NuA               Content-Type: text/pl§in; charset=utf-8
            r  u   text/pl�inr   u   pl�in)	r   r   r   r   r   r2   rH   rn  r  rh   s     r9   test_get_content_type_with_8bitz5Test8BitBytesHandling.test_get_content_type_with_8bit  sz    &&x 8 (	"$ 	--/1BC113V<002LAr;   c                     t        j                  dj                  d            }| j                  |j	                  d      g d       | j                  |j                  dd      d       | j                  |j                  dd      d        y )	Nu(   X-Header: foo=§ne; b§r=two; baz=three
r  r  r  ))r      �ne)u   b�rr  r  FoorE  u   b§r)r   r   r   r2   r  rI   rh   s     r9   test_get_params_with_8bitz/Test8BitBytesHandling.test_get_params_with_8bit  sz    &&;BB9MOz:G	IuZ@*Mx
CTJr;   c                     t        j                  t        j                  d      j	                  d            }| j                  |j                  d      d       y )Nn               Content-Type: text/plain; charset=us-ascii;
             title*=us-ascii'en'This%20is%20not%20f§nr  title)rN   enu   This is not f�n)r   r   r   r   r   r2   rI   rh   s     r9   !test_get_rfc2231_params_with_8bitz7Test8BitBytesHandling.test_get_rfc2231_params_with_8bit  sL    &&x 8< ( vi " 	w/6	8r;   c                     t        j                  t        j                  d      j	                  d            }|j                  dd       | j                  |j                  d      d       y )NrI  r  rJ  test)r   r   r   r   r   r3  r2   rI   rh   s     r9   !test_set_rfc2231_params_with_8bitz7Test8BitBytesHandling.test_set_rfc2231_params_with_8bit  sW    &&x 8< ( vi " 	gv&w/8r;   c                    t        j                  t        j                  d      j	                  d            }|j                  d       | j                  |j                  d      d        | j                  |j                         d       y )NrI  r  rJ  r   )	r   r   r   r   r   r=  r2   rI   rn  rh   s     r9   !test_del_rfc2231_params_with_8bitz7Test8BitBytesHandling.test_del_rfc2231_params_with_8bit  sn    &&x 8< ( vi " 	gw/6113V<r;   c                     t        j                  t        j                  d      j	                  d            }| j                  |j                         d       | j                  |j                  d      d       y )Nu               Content-Transfer-Encoding: b§se64
            Content-Type: text/plain; charset=latin-1

            payload
            r  zpayload
TrX   s   payload
)r   r   r   r   r   r2   rZ   rh   s     r9   %test_get_payload_with_8bit_cte_headerz;Test8BitBytesHandling.test_get_payload_with_8bit_cte_header%  sb    &&x 8 (
 	"$ 	*K85|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                  |      j                  |       | j                  |j                         | j                         y rf   )	r   r   non_latin_bin_msgr   r   r   r   r2   r   r6   r8   r   s      r9   test_bytes_generatorz*Test8BitBytesHandling.test_bytes_generator;  sX    &&t'='=>i&&s+33C8)?)?@r;   c                     t         j                  j                         }t               }t         j                  j                  |      j                  |       | j                  |j                         d       y )Nr   )	r   rq  r   r   r   r   r   r2   r   rV  s      r9   &test_bytes_generator_handles_None_bodyz<Test8BitBytesHandling.test_bytes_generator_handles_None_bodyA  sN    mm##%i&&s+33C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                  |      j                  |       | j                  |j                         | j                         y rf   )
r   r   rU  r   r   r   r   r2   r    non_latin_bin_msg_as7bit_wrappedrV  s      r9   test_generator_handles_8bitz1Test8BitBytesHandling.test_generator_handles_8bitU  sX    &&t'='=>j!!#&..s3)N)NOr;   c                 v   t        j                  | j                        }t               }t	        |      j                  |       |j                         }t        t                     j                  |       t               }t	        |      j                  |       | j                  |j                         |       y rf   )
r   r   rU  r   r   r   r   r   r   r2   )r6   r8   r   
orig_values       r9   ;test_str_generator_should_not_mutate_msg_when_handling_8bitzQTest8BitBytesHandling.test_str_generator_should_not_mutate_msg_when_handling_8bit[  s    &&t'='=>is##C(\\^
(*%%c*is##C(4r;   c                    t        j                  | j                        }t               }t         j                  j                  |      j                  |d       |j                         j                  d      }| j                  |d   j                         d   d       | j                  dj                  |dd        | j                         y )NTr   r   r   s   Fromr|   )r   r   rU  r   r   r   r   r   r   r2   r   )r6   r8   r   r   s       r9   #test_bytes_generator_with_unix_fromz9Test8BitBytesHandling.test_bytes_generator_with_unix_frome  s     &&t'='=>i&&s+33C$3G$$U+q)!,g6E!"I.0F0F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}| j                  t        |       t        |d      5 }|j                  | j                         d d d        t        |d      5 }t
        j                  j                         j                  |      }d d d        | j                  t              | j                         y # 1 sw Y   qxY w# 1 sw Y   ;xY w)Nztest.msgwbr  )
addCleanupr&   openwriterU  r   r   r  r  r2   r   non_latin_bin_msg_as7bit)r6   r  testfiler   s       r9   test_message_from_binary_filez3Test8BitBytesHandling.test_message_from_binary_filev  s    #"d^ 	3xNN4112	3"d^ 	;x((*00:A	;Q!>!>?		3 	3	; 	;s   B1.B=1B:=C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                        }| j                  t	        |      | j
                         y rf   )r   r   latin_bin_msgr2   r   latin_bin_msg_as7bitr  s     r9   :test_string_generator_reencodes_to_quopri_when_appropriatezPTest8BitBytesHandling.test_string_generator_reencodes_to_quopri_when_appropriate  s2    $$T%7%78Q!:!:;r;   c                 *   t        j                  | j                        }t               }t         j                  j                  |      j                  |       | j                  |j                         | j                  j                  d      dz          y )Nr  r*   )
r   r   rk  r   r   r   r   r2   r   rY   )r6   r   r   s      r9   )test_decoded_generator_emits_unicode_bodyz?Test8BitBytesHandling.test_decoded_generator_emits_unicode_body  sm    $$T%7%78j((-55a8 	%%i05	7r;   c                 6   t         j                  j                         }t        dt	        | j
                        d      D ]#  }|j                  | j
                  ||dz           % |j                         }| j                  t        |      | j                         y )Nr   rD  )r   r  BytesFeedParserrH  r  rk  r  r  r2   r   rl  )r6   bfprB  r   s       r9   test_bytes_feedparserz+Test8BitBytesHandling.test_bytes_feedparser  s{    ..0q#d00126 	1AHHT''!B$/0	1IIKQ!:!:;r;   c                 H   t        dd      5 }|j                         }d d d        t        j                        }t	               }t        j
                  j                  |      }|j                  |d       | j                  |j                         |       y # 1 sw Y   {xY w)Nr|  r  r   r   )
r'   r   r   r   r   r   r   r   r2   r   r  s         r9   r  z'Test8BitBytesHandling.test_crlf_flatten  s    lD) 	R779D	&&t,IOO**1-			#v	&t,	 	s   BB!c                 *   t        j                  d      j                  d      }t        j                  |      }t               }t        j                  j                  |      }|j                  |       | j                  |j                         |       y )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--

            rV   )r   r   r   r   r   r   r   r   r   r2   r   )r6   r   r8   r   r   s        r9   test_8bit_multipartz)Test8BitBytesHandling.test_8bit_multipart  st     %" %J K 	L &&v.IOO**1-			#v.r;   c                     t               }t        d      |d<   t               }t        j                  j                  |      }|j                  |d       | j                  |j                         d       y )N   žluťoučký kůňr  r   r   s5   Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	r   r   r   r   r   r   r   r2   r   r6   r   r   r   s       r9   'test_bytes_generator_b_encoding_linesepz=Test8BitBytesHandling.test_bytes_generator_b_encoding_linesep  s^    I34)IOO**1-			!V	$JJLH	Jr;   c                     t               }t        d      |d<   t               }t        j                  j                  |      }|j                  |d       | j                  |j                         d       y )Nrx  r  r   r   z5Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=

)	r   r   r   r   r   r   r   r2   r   ry  s       r9   !test_generator_b_encoding_linesepz7Test8BitBytesHandling.test_generator_b_encoding_linesep  s^    I34)JOO%%a(			!V	$JJLG	Ir;   N)0r  r  r  r   r   r  r  r"  r&  r(  r*  r,  r.  r5  r   r   r2  r3  r7  r=  r?  rA  rC  rG  rL  rO  rQ  rS  rU  rW  rY  r[  r\  r_  ra  r   rg  ri  rk  rl  rm  ro  rs  r  rv  rz  r|  r  )rA  srcr6  s   000r9   r  r  O  s    #8?? $ L667$6 D<6 	
 ii5G H H#q HI#$%+VG_ ;
C	3
=3BK89=E ( 
) 
 VG_ A0 (7x 8 ($P5	H  @EEdK	8%9Qq!  $yy)AB@ $HOO 	% 	 VI  +8?? 	, 	<7<-,/\
J
I Ge	 !Is   D?r  c                       e Zd ZdZd ZddZy) BaseTestBytesGeneratorIdempotentNc                     t        |d      5 }|j                         }d d d        | j                  j                  | j                        }t        j                  |      }||fS # 1 sw Y   HxY w)Nr  )r'   r   normalize_linesep_regexsubblinesepr   r   rC  s        r9   r3   z(BaseTestBytesGeneratorIdempotent._msgobj   sd    h% 	779D	++//tD&&t,Dy		 	s   A%%A.c                     t               }t        j                  j                  |d      }|j	                  ||| j
                         | j                  ||j                                y )Nr   rt  )r   r   )r   r   r   r   r   r   r2   r   )r6   r8   r\   r   r  r   s         r9   rE  z,BaseTestBytesGeneratorIdempotent._idempotent  sN    IOO**11*=			#$,,	?qzz|,r;   r  )r  r  r  r  r3   rE  r  r;   r9   r  r    s    G-r;   r  c                   8    e Zd ZdZdZ ej                  d      Zy)TestBytesGeneratorIdempotentNLr*   r   s   \r\nNr  r  r  r   r  recompiler  r  r;   r9   r  r    s    GH(bjj2r;   r  c                   8    e Zd ZdZdZ ej                  d      Zy) TestBytesGeneratorIdempotentCRLFr   r  s	   (?<!\r)\nNr  r  r;   r9   r  r    s    GH(bjj7r;   r  c                   $    e Zd Zd Zd Zd Zd Zy)
TestBase64c           	      B   | j                   } |t        j                  d      t        t        j                  dd                   t        d      D ]K  }|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        |       M y )Nhello   hellor+   eol   r   r   r   r     r     r     r  )r2   r   header_lengthr  body_encoderH  )r6   r7   sizebsizes       r9   test_lenzTestBase64.test_len  s    
:##G,z%%hB78	:"I 	<DQUQUQURURU%'Uz''d
3U;	<r;   c                     | j                   } |t        j                  d      d        |t        j                  d      d       y )Nr+   r;   zaGVsbG8=r  )r2   r   rY   r  s     r9   test_decodezTestBase64.test_decode*  s7    
:R #&
:Z((3r;   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       y )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==
)r2   r   r  r  s     r9   test_encodezTestBase64.test_encode/  s    
:!!#&+
:!!(+\:
:!!*-|<
:!!-B? B 	 	:!!-BFK	r;   c                     | j                   }t        j                  } | |d      d        | |d      d        | |d      d        | |dd      d	        | |d      d       y )
Nr  z=?iso-8859-1?b?aGVsbG8=?=hello
worldz!=?iso-8859-1?b?aGVsbG8NCndvcmxk?=hello
worldz!=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=rr   rM  z=?iso-8859-2?b?aGVsbG8=?=)r2   r   r  )r6   r7   hes      r9   test_header_encodezTestBase64.test_header_encodeE  sj    %%
2g;34
2!DE
2nBC
2g|,.IJ
2nBCr;   N)r  r  r  r  r  r  r  r  r;   r9   r  r    s    <4
,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 ZEy)G
TestQuopric                 z   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                    | _        t        d
      D cg c]  }|| j                  vs| c}| _        t        | j                        t        | j
                        z   d
k(  sJ t        t        t        d      t        d      dz               | _        | j                  j                  t        d             | j                  j                  t        d             t        d
      D cg c]  }|| j                  vs| c}| _
        t        | j                        t        | j                        z   d
k(  sJ y c c}w c c}w )Nr  zr|   r  Zr  9c              3       K   | ]  }|  y wrf   r  )rA  r  s     r9   rC  z#TestQuopri.setUp.<locals>.<genexpr>X  s     !1Q!r  s   !*+-/   r,   ~r  =)r  r   rH  ordhlithnonr  blitr   removebnonr6   r  s     r9   r  zTestQuopri.setUpQ  sF    #c(CHqL)#c(CHqL)#c(CHqL)!!	# $	 !&c
A1atyy.@QA	499~DII.#555 s3xSA67			T#		S" !&c
A1atyy.@QA	499~DII.#555 B Bs   F3"F3"F86F8c                    | j                   D ]3  }| j                  t        j                  |      dt	        |      z         5 | j
                  D ]3  }| j                  t        j                  |      dt	        |      z         5 y )Nz'Should not be header quopri encoded: %sz#Should be header quopri encoded: %s)r  r  r"   header_checkchrr  r   r  s     r9   test_quopri_header_checkz#TestQuopri.test_quopri_header_checkg  s|     	LAZ44Q7ACFJL	L  	LAOOJ33A6ACFJL	Lr;   c                    | j                   D ]3  }| j                  t        j                  |      dt	        |      z         5 | j
                  D ]3  }| j                  t        j                  |      dt	        |      z         5 y )Nz%Should not be body quopri encoded: %sz!Should be body quopri encoded: %s)r  r  r"   
body_checkr  r  r   r  s     r9   test_quopri_body_checkz!TestQuopri.test_quopri_body_checko  s|     	JAZ2215?#a&HJ	J  	JAOOJ11!4?#a&H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 ]5  } |t        j                  t        |g            dd	t        |      z         7 | j                  D ]D  }|t        d
      k(  r |t        j                  t        |g            ddt        |      z         F  |t        j                  d      d       y )Nr  r  xxxrM  rD  s
   h@e@l@l@o@r  r|   zexpected length 1 for %rr,   r   zexpected length 3 for %r    )
r2   r"   r  r  r  r  r   r  r  r  r6   r7   r  s      r9   test_header_quopri_lenz!TestQuopri.test_header_quopri_lenw  s>   
:##H-q1
3z''%@A##H-	 	:##M2B7
3z''uEF##M2	  	4Az''qc
3Q)CF24	4  	4ACH}z''qc
3Q)CF24		4 	:##D)1-r;   c                     | j                   }| j                  D ](  } |t        j                  t	        |g            d       * | j
                  D ](  } |t        j                  t	        |g            d       * y )Nr|   r   )r2   r  r"   body_lengthr   r  r  s      r9   test_body_quopri_lenzTestQuopri.test_body_quopri_len  si     	6Az%%eQCj115	6 	6Az%%eQCj115	6r;   c                     t        d      D ]E  }t        |      }| j                  t        j                  t        j
                  |            |       G y )Nr  )rH  r  r2   r"   r$  quote)r6   r  r  s      r9   test_quote_unquote_idempotentz(TestQuopri.test_quote_unquote_idempotent  sF    s 	IAAAZ//
0@0@0CDaH	Ir;   Nc                     |t        j                  |      }nt        j                  ||      }| j                  ||       y rf   )r"   r  r2   )r6   r   expected_encoded_headerrA   encoded_headers        r9   _test_header_encodezTestQuopri._test_header_encode  s:    ?'55f=N'55fgFN)@Ar;   c                 (    | j                  dd       y )Nr;   r+   r  r  s    r9   test_header_encode_nullz"TestQuopri.test_header_encode_null  s      b)r;   c                 (    | j                  dd       y )Nr  z=?iso-8859-1?q?hello?=r  r  s    r9   test_header_encode_one_wordz&TestQuopri.test_header_encode_one_word  s      +CDr;   c                 (    | j                  dd       y )Ns   hello
worldz=?iso-8859-1?q?hello=0Aworld?=r  r  s    r9   test_header_encode_two_linesz'TestQuopri.test_header_encode_two_lines  s       @	Br;   c                 (    | j                  dd       y )Ns   hellotherez=?iso-8859-1?q?hello=C7there?=r  r  s    r9   test_header_encode_non_asciiz'TestQuopri.test_header_encode_non_ascii  s      !2 @	Br;   c                 ,    | j                  ddd       y )Nr  z=?iso-8859-2?q?hello?=rr   rM  r  r  s    r9   test_header_encode_alt_charsetz)TestQuopri.test_header_encode_alt_charset  s      +C$ 	! 	&r;   c                 R    t        j                  |      }| j                  ||       y rf   )r"   header_decoder2   )r6   r  expected_decoded_headerdecoded_headers       r9   _test_header_decodezTestQuopri._test_header_decode  s#    #11.A)@Ar;   c                 (    | j                  dd       y Nr+   r  r  s    r9   test_header_decode_nullz"TestQuopri.test_header_decode_null  s      R(r;   c                 (    | j                  dd       y Nr  r  r  s    r9   test_header_decode_one_wordz&TestQuopri.test_header_decode_one_word  s      '2r;   c                 (    | j                  dd       y )Nzhello=0Aworldr  r  r  s    r9   test_header_decode_two_linesz'TestQuopri.test_header_decode_two_lines  s      .Ar;   c                 (    | j                  dd       y )Nzhello=C7thereu   helloÇtherer  r  s    r9   test_header_decode_non_asciiz'TestQuopri.test_header_decode_non_ascii  s      2BCr;   c                 N    | j                  t        j                  d      d       y )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)r2   r"   r  r  s    r9   test_header_decode_re_bug_18380z*TestQuopri.test_header_decode_re_bug_18380  s    11+>	Jr;   c                     |t        j                  |      }nt        j                  ||      }| j                  ||       y )Nr  )r"   rY   r2   )r6   encodedexpected_decodedr  decodeds        r9   _test_decodezTestQuopri._test_decode  s:    ; ''0G ''S9G"23r;   c                 (    | j                  dd       y r  r  r  s    r9   test_decode_null_wordz TestQuopri.test_decode_null_word      "b!r;   c                 (    | j                  dd       y )Nr   r*   r  r  s    r9   test_decode_null_line_null_wordz*TestQuopri.test_decode_null_line_null_word  s    &$'r;   c                 (    | j                  dd       y r  r  r  s    r9   test_decode_one_wordzTestQuopri.test_decode_one_word  s    '7+r;   c                 ,    | j                  ddd       y )Nr  Xr  r  r  s    r9   test_decode_one_word_eolz#TestQuopri.test_decode_one_word_eol  s    '74r;   c                 (    | j                  dd       y Nhello
hello
r  r  s    r9   test_decode_one_linezTestQuopri.test_decode_one_line      +y1r;   c                 (    | j                  dd       y Nr  r  r  s    r9   test_decode_one_line_lfz"TestQuopri.test_decode_one_line_lf      )Y/r;   c                 (    | j                  dd       y )Nzhellor  r  r  s    r9   test_decode_one_line_crz"TestQuopri.test_decode_one_line_cr  r  r;   c                 ,    | j                  ddd       y )Nr  helloXr  r  r  r  s    r9   test_decode_one_line_nlz"TestQuopri.test_decode_one_line_nl  s    )X37r;   c                 ,    | j                  ddd       y )Nr  r	  r  r  r  r  s    r9   test_decode_one_line_crnlz$TestQuopri.test_decode_one_line_crnl  s    +xS9r;   c                 (    | j                  dd       y )Nr  r  r  r  s    r9   test_decode_one_line_one_wordz(TestQuopri.test_decode_one_line_one_word  s    *N;r;   c                 ,    | j                  ddd       y )Nr  helloXworldr  r  r  r  s    r9   !test_decode_one_line_one_word_eolz,TestQuopri.test_decode_one_line_one_word_eol  s    *MsCr;   c                 (    | j                  dd       y )Nhello
world
hello
world
r  r  s    r9   test_decode_two_linesz TestQuopri.test_decode_two_lines  s    .0@Ar;   c                 ,    | j                  ddd       y )Nr  helloXworldXr  r  r  r  s    r9   test_decode_two_lines_eolz$TestQuopri.test_decode_two_lines_eol  s    .CHr;   c                 (    | j                  dd       y )N  SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamr  r  s    r9   test_decode_one_long_linez$TestQuopri.test_decode_one_long_line  s    ,5r;   c                 (    | j                  dd       y )Nr,   r+   r  r  s    r9   test_decode_one_spacez TestQuopri.test_decode_one_space  s    #r"r;   c                 (    | j                  dd       y )Nz     r+   r  r  s    r9   test_decode_multiple_spacesz&TestQuopri.test_decode_multiple_spaces  s    '2&r;   c                 (    | j                  dd       y )Nzhello    
r  r  r  s    r9   $test_decode_one_line_trailing_spacesz/TestQuopri.test_decode_one_line_trailing_spaces   s    /95r;   c                 (    | j                  dd       y )Nzhello    
world   
r  r  r  s    r9   %test_decode_two_lines_trailing_spacesz0TestQuopri.test_decode_two_lines_trailing_spaces  s    57GHr;   c                 (    | j                  dd       y )Nz=22quoted=20words=22z"quoted words"r  r  s    r9   test_decode_quoted_wordz"TestQuopri.test_decode_quoted_word  s    02BCr;   c                 (    | j                  dd       y )Nzab=CD=EF   abÍïr  r  s    r9   test_decode_uppercase_quotingz(TestQuopri.test_decode_uppercase_quoting	      *l3r;   c                 (    | j                  dd       y )Nzab=cd=efr'  r  r  s    r9   test_decode_lowercase_quotingz(TestQuopri.test_decode_lowercase_quoting  r)  r;   c                 (    | j                  dd       y )Nzsoft line=
breakzsoft linebreakr  r  s    r9   test_decode_soft_line_breakz&TestQuopri.test_decode_soft_line_break  s    /1ABr;   c                 (    | j                  dd       y )NzA=1,B=A ==> A+B==2r  r  s    r9   test_decode_false_quotingz$TestQuopri.test_decode_false_quoting  s    .0DEr;   c                     i }|d}n||d<   |d}n||d<   t        j                  |fi |}| j                  ||       |dk(  s|dk(  r1|j                         D ]  }| j	                  t        |      |        y y )Nr  r  r*   r  r   )r"   r  r2   r  r  r  )r6   r  expected_encoded_bodyr  r  kwargsencoded_bodyr  s           r9   _test_encodezTestQuopri._test_encode  s    J#-F< ;CF5M!--d=f='<=$;#- %//1 <$$SY
;< (r;   c                 (    | j                  dd       y r  r4  r  s    r9   test_encode_nullzTestQuopri.test_encode_null)  r  r;   c                 (    | j                  dd       y )Nz

r6  r  s    r9   test_encode_null_linesz!TestQuopri.test_encode_null_lines,  s    &&)r;   c                 (    | j                  dd       y r  r6  r  s    r9   test_encode_one_linezTestQuopri.test_encode_one_line/  r  r;   c                 (    | j                  dd       y r  r6  r  s    r9   test_encode_one_line_crlfz$TestQuopri.test_encode_one_line_crlf2  r  r;   c                 ,    | j                  ddd       y )Nr  r  r   r  r6  r  s    r9   test_encode_one_line_eolz#TestQuopri.test_encode_one_line_eol5  s    )[f=r;   c                 h    | j                  dj                  d      j                  d      dd       y )Nu   helloυ
rV   latin1zhello=CF=85
r   r  )r4  r   rY   r  s    r9   (test_encode_one_line_eol_after_non_asciiz3TestQuopri.test_encode_one_line_eol_after_non_ascii8  s2    /009@@J+ 	 	9r;   c                 (    | j                  dd       y )Nr,   z=20r6  r  s    r9   test_encode_one_spacez TestQuopri.test_encode_one_space=  s    #u%r;   c                 (    | j                  dd       y )Nz 
z=20
r6  r  s    r9   test_encode_one_line_one_spacez)TestQuopri.test_encode_one_line_one_space@  s    %)r;   c                 (    | j                  dd       y )Nz 
 
z=20
=20
r6  r  s    r9   test_encode_two_lines_one_spacez*TestQuopri.test_encode_two_lines_one_spaceH  s    (L1r;   c                 (    | j                  dd       y )Nzhello   z
hello  =20r6  r  s    r9   $test_encode_one_word_trailing_spacesz/TestQuopri.test_encode_one_word_trailing_spacesK  r)  r;   c                 (    | j                  dd       y )Nz	hello   
zhello  =20
r6  r  s    r9   $test_encode_one_line_trailing_spacesz/TestQuopri.test_encode_one_line_trailing_spacesN  s    ,7r;   c                 (    | j                  dd       y )Nzhello  	z
hello  =09r6  r  s    r9   !test_encode_one_word_trailing_tabz,TestQuopri.test_encode_one_word_trailing_tabQ  s    +|4r;   c                 (    | j                  dd       y )Nz	hello  	
zhello  =09
r6  r  s    r9   !test_encode_one_line_trailing_tabz,TestQuopri.test_encode_one_line_trailing_tabT  s    -8r;   c                 ,    | j                  ddd       y )N
abcd 
1234zabcd =

1234r  r  r6  r  s    r9   ,test_encode_trailing_space_before_maxlinelenz7TestQuopri.test_encode_trailing_space_before_maxlinelenW  s    -)9aHr;   c                 ,    | j                  ddd       y )NrR  zabcd=
=20
1234r  r  r6  r  s    r9   (test_encode_trailing_space_at_maxlinelenz3TestQuopri.test_encode_trailing_space_at_maxlinelenZ      -);Jr;   c                 ,    | j                  ddd       y )NrR  zabc=
d=20
1234r   r  r6  r  s    r9   ,test_encode_trailing_space_beyond_maxlinelenz7TestQuopri.test_encode_trailing_space_beyond_maxlinelen]  rV  r;   c                 (    | j                  dd       y )Nz
 
 
 
 
 
z=20
=20
=20
=20
=20
r6  r  s    r9   test_encode_whitespace_linesz'TestQuopri.test_encode_whitespace_lines`  s    )[1r;   c                 (    | j                  dd       y )Nza = bza =3D br6  r  s    r9   test_encode_quoted_equalsz$TestQuopri.test_encode_quoted_equalsc  s    '9-r;   c                 (    | j                  dd       y )Ndxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxr6  r  s    r9   test_encode_one_long_stringz&TestQuopri.test_encode_one_long_stringf  s    )%@Ar;   c                 (    | j                  dd       y )Nzexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxx
r6  r  s    r9   test_encode_one_long_linez$TestQuopri.test_encode_one_long_linei  s    *,NOr;   c                 (    | j                  dd       y )Nzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r6  r  s    r9   test_encode_one_very_long_linez)TestQuopri.test_encode_one_very_long_linel  s    *8	:r;   c                 ,    | j                  ddd       y )Nz=====z=3D=
=3D=
=3D=
=3D=
=3Dr   r  r6  r  s    r9   test_encode_shortest_maxlinelenz*TestQuopri.test_encode_shortest_maxlinelenp  s    '#7AFr;   c                 L    | j                  t        | j                  ddd       y )Nr+   r   r  )r   rR  r4  r  s    r9    test_encode_maxlinelen_too_smallz+TestQuopri.test_encode_maxlinelen_too_smalls  s!    *d&7&7RANr;   c                 v   | 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       y )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)r2   r"   r  r  s     r9   r  zTestQuopri.test_encodev  s    
:!!"%r*
:!!'*G4
:!!"23^D
:!!,2> A 	
 	:!!,26J	
 	:!! # 	r;   rf   )NN)Fr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  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  r7  r9  r;  r=  r?  rB  rD  rF  rH  rJ  rL  rN  rP  rS  rU  rX  rZ  r\  r_  ra  rc  re  rg  r  r  r;   r9   r  r  P  sj   6,LJ.26I
B*EBB&B)3BDK4"(,52008:<DBI6#'6ID44CF<("*02>9
&*24859IKK2.BP:GOr;   r  c                   $    e Zd Zd Zd Zd Zd Zy)TestCharsetc                 J    ddl m} 	 |j                  d= y # t        $ r Y y w xY w)Nr   rM  fake)r   rA   CHARSETSr  )r6   CharsetModules     r9   tearDownzTestCharset.tearDown  s*    2	&&v. 		s    	""c                     | j                   }t        d      } ||j                  d      d       d}| j                  t        |j                  |       t        d      } ||j                  |      d       y )NrN   Hello World!u   ¤¢¤¤¤¦¤¨¤ªrV   z(=?utf-8?b?wqTCosKkwqTCpMKmwqTCqMKkwqo=?=)r2   r
   r  r   r  )r6   r7   r  r   s       r9   test_codec_encodeablez!TestCharset.test_codec_encodeable  sc    J
1??>*N;6,;G
1??1IJr;   c                    | j                   }t        d      } |d|j                  d             t        d      } |d|j                  d             t        d      } |d|j                  d             t        d	      }d
dlm} |j                  d|j                  d d       t        d      } |d|j                  d             y )Nr=   zhello w=F6rldu   hello wörldrV   rg  r   rN   r  r  r   rM  rm  )r2   r
   r  r   rA   add_charsetQP)r6   r7   r  ro  s       r9   test_body_encodezTestCharset.test_body_encode  s    L!
?AMM*:;<G
~!>?J
=!--67H 	3!!&-*:*:D'JFO
=!--67r;   c                     t        d      }| j                  t        |      d       | j                  t        j
                  t         d       y )NrN   u   ascÿii)r
   r2   r   r   r    CharsetErrorrd  s     r9   test_unicode_charset_namez%TestCharset.test_unicode_charset_name  s8    *%Wz2&--wDr;   N)r  r  r  rp  rs  rw  rz  r  r;   r9   rk  rk    s    	K8>E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y)
TestHeaderc                     | j                   }t        d      } ||j                         d       |j                  d        ||j                         d       y )Nrr  z Goodbye World!zHello World!  Goodbye World!r  r   r   r   r,  s      r9   test_simplezTestHeader.test_simple  sE    "">"
188:~&	"#
188:56r;   c                     | j                   }t        d      } ||j                         d       |j                  d        ||j                         d       y )Nrr  zGoodbye World!zHello World! Goodbye World!r~  r,  s      r9   test_simple_surprisezTestHeader.test_simple_surprise  sE    "">"
188:~&	!"
188:45r;   c                 D    d}| j                  t        |      |d fg       y )Nzno decoding neededr  r7  s     r9   test_header_needs_no_decodingz(TestHeader.test_header_needs_no_decoding  s"     q)QI;7r;   c                     t        dd      }|j                  d      j                  d      D ]  }| j                  t	        |      d        y )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  )r6   r  ls      r9   	test_longzTestHeader.test_long  sN      L "S)//6 	-A  Q,	-r;   c                 ,   | j                   }t        d      }t        d      }t        d      }d}d}d}t        ||      }|j                  ||       |j                  ||       |j	                  d      }	 ||	d	       t        |	      }
 |t        |
      d
        ||
d   |df        ||
d   |df        ||
d   |j	                  d      df       t        |      } ||dj                  d             t        t        |	            } |||       y )Nr=   rr   rV   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   rY   r   )r6   r7   r   r!  r"  r#  r$  r%  r  encr  ustrnewhs                r9   test_multilingualzTestHeader.test_multilingual  s&   ""L!\"wB$0	 61	"	D!hh"h%
3 ) 	*  $
3w<
71:-.
71:./
71:	((17;<1v
4D  fWo#	& =-.
4r;   c                 X    t               }| j                  |j                         d       y r  r6  r7  s     r9   test_empty_header_encodez#TestHeader.test_empty_header_encode$  s    HR(r;   c                     | j                   }t               } ||d       |j                  dt        d              ||d       y )Nr+   r   r=   )r  r   r   r
   r,  s      r9   test_header_ctor_default_argsz(TestHeader.test_header_ctor_default_args(  s9    ""H
1b		-.
1er;   c                 b   | j                   }d}t        |      } ||j                         d        |t        |      |       t        |d      } ||j                         d        |t        |      |       t        |dd      } ||j                         |        |t        |      |       y )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       r9   test_explicit_maxlinelenz#TestHeader.test_explicit_maxlinelen/  s    "" 4L
188: 8 	9 	3q644Y/
188: = 	> 	3q644Di@
188:t
3q64r;   c           
         | j                   }t        dd      }d}|j                  |       |j                         } ||d        ||t	        t        t        |                         t        dd      }|j                  d       |j                         } ||d        ||t	        t        t        |                         y )Nr=   r  rA   r  ri  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   r6   r7   r  r  r   s        r9   test_quopri_splittablez!TestHeader.test_quopri_splittableB  s    ""<B7	HHJ
1 2 2	f 	1c+mA./01<B7	HHJ
1 ! 	" 	1c+mA./01r;   c           
         | j                   }t        dd      }d}|j                  |       |j                         } ||d        ||t	        t        t        |                         t        dd      }|j                  |       |j                         } ||d        ||t	        t        t        |                         y )Nrs   r  r  ri  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        r9   test_base64_splittablez!TestHeader.test_base64_splittable  s    ""83	HHJ
1 " "	F 	1c+mA./0183	HHJ
1 " 	# 	1c+mA./01r;   c                     | j                   }d}t        |      } ||dg       t        |      } |||j                                y )Nr  )r  Nr2   r   r   r   )r6   r7   r   r  r  s        r9   test_us_ascii_headerzTestHeader.test_us_ascii_header  sB    !
1 N
1ahhjr;   c                 f    | j                   }t               }|j                  dd        ||d       y )Nr  r=   )r2   r   r   r,  s      r9   test_string_charsetzTestHeader.test_string_charset  s+    H	,'
1gr;   c                     | j                   }t        dd      } ||j                         d       t        dd      } ||j                         d       y )Nr  rV   z=?utf-8?q?p=C3=B6stal?=u   菊地時夫z=?utf-8?b?6I+K5Zyw5pmC5aSr?=r2   r   r   r,  s      r9   test_utf8_shortestzTestHeader.test_utf8_shortest  sH    ;(
188:01-w7
188:56r;   c                 H   | j                   }| j                  }d} |t        t        |       t               } |t        |j                  |       |j                  dd      } |t        t        |d            |       |j	                  |d        |t        |      |       y )N0   Ynwp4dUEbay Auction Semiar- No Charge  Earn BigrV   r   r   )r   r2   r  r   r   rY   r   )r6   r@  r7   r  r  es         r9   test_bad_8bit_headerzTestHeader.test_bad_8bit_header  s    ""B|VQ'H|QXXq)HHWi(
3va	*+Q/	9%
3q61r;   c                    d}|j                  dd      }t        |t        j                  j                        }| j                  t        |      d       | j                  t        j                  j                  |      |dfg       y )Nr  r   surrogateescaperM  2   Ynwp4dUEbay Auction Semiar- No Charge � Earn Bigunknown-8bit)	rY   r   r   rA   UNKNOWN8BITr2   r   r   r   )r6   r  r  r  s       r9   test_escaped_8bit_headerz#TestHeader.test_escaped_8bit_header  sm    BHHW/01emm778QO	Q33A6!^9L8MNr;   c                     d}t        |t        j                  j                        }| j	                  t        |      d       | j	                  t        j                  j                  |      |dfg       y Nr  rM  r  r  )r   r   rA   r  r2   r   r   r   )r6   r  r  s      r9   &test_header_handles_binary_unknown8bitz1TestHeader.test_header_handles_binary_unknown8bit  s\    B1emm778QO	Q33A6!^9L8MNr;   c                 d   d}t        |t        j                  j                        }t        j                  j                  t        j                  j                  |            }| j                  t        |      d       | j                  t        j                  j                  |      |dfg       y r  )	r   r   rA   r  r   r   r   r2   r   )r6   r  r  h2s       r9   +test_make_header_handles_binary_unknown8bitz6TestHeader.test_make_header_handles_binary_unknown8bit  s    B1emm778\\%%ell&@&@&CDRO	Q33B71n:M9NOr;   c                     t        d      }t        j                  j                  |      }|j	                  d       | j                  t        |      d       y )NrN  )r   test2)r   r   r   r   r   r2   r   )r6   r  r  s      r9   0test_modify_returned_list_does_not_change_headerz;TestHeader.test_modify_returned_list_does_not_change_header  s@    6N++A.()Q(r;   c                     | j                   }t               }|j                  dd       |j                  d       |j                         } ||d       t	        t        |            } ||j                         |       y )Nr  r=   worldz=?iso-8859-1?q?hello?= world)r2   r   r   r   r   r   )r6   r7   r  r   s       r9    test_encoded_adjacent_nonencodedz+TestHeader.test_encoded_adjacent_nonencoded  sc    H	,'	HHJ
1,-a()
188:qr;   c                     | j                   }d}t        |      } ||g d       t        |      } ||j                         d       y )NzGSubject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.))s	   Subject: N)s     rs   )s    zz.Nz6Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.r  )r6   r7   r   partshdrs        r9   test_whitespace_keeperz!TestHeader.test_whitespace_keeper  sK    Ua 
5  Y  	Z% 
3::<C	Er;   c                 X    | j                   }d} |t        j                  t        |       y )NzXSubject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=)r   r    r   r   )r6   r@  r   s      r9   test_broken_base64_headerz$TestHeader.test_broken_base64_header  s$    ""fv&&q9r;   c                 ^    t        dd      }| j                  |j                         d       y )Nr4  	shift_jisrM  r5  r6  r7  s     r9   test_shift_jis_charsetz!TestHeader.test_shift_jis_charset  s%    5+.%EFr;   c                 d    t        j                  d      }| j                  t        |      d       y )NzEmptyHeader:zEmptyHeader: 

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

)r   r2   r   rh   s     r9   )test_encode_preserves_leading_ws_on_valuez4TestHeader.test_encode_preserves_leading_ws_on_value'  s(    i6LS#MNr;   c                 V    | j                  t        d      j                         d       y )Nr,   r  r  s    r9   test_whitespace_headerz!TestHeader.test_whitespace_header,  s    ++-s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;   r9   r|  r|    s    768-=~)&C2J42l7
OOP)E:
G8O
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 y) TestRFC2231c                     | j                   }| j                  d      } ||j                  d      d        ||j                  dd      d       y )Nz
msg_29.txtrJ  rN   rK  %This is even more ***fun*** isn't it!Fr#  )rN   rK  z'"This is even more ***fun*** isn't it!")r2   r3   rI   r5   s      r9   r  zTestRFC2231.test_get_param6  sM    ll<(
3==!G	I
3==%=0I	Kr;   c                 `   | j                   }t               }|j                  ddd        ||j                  d      d       |j                  dddd        ||j                  d      d       | j	                  d	      }|j                  dddd        ||j                  d
      d       y )NrJ  r  rN   rM  )rN   r+   r  rK  rA   languager  r   rp  rt  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   r3  rI   r3   r   r5   s      r9   r4  zTestRFC2231.test_set_param>  s    ""igG( 	 	*
3==!E	GgG(4 	 	9
3==!G	Ill<(gG(4 	 	9
3==b=) , 	r;   c                 
   t               }|j                  dd       | j                  |d   d       |j                  ddd       | j                  |d   d       |j                  dd	d       | j                  |d   d
       y )NrJ  r   r@   ztext/plain; title="foo"r  F)requoteztext/plain; title=barz	(bar)bellztext/plain; title="(bar)bell")r   r3  r2   rh   s     r9   test_set_param_requotez"TestRFC2231.test_set_param_requotec  s}    igu%^,.GHgue4^,.EFg{E:^,.MNr;   c                     | j                   }| j                  d      }|j                  dddd       |j                  dddd       |j                  dd	
        ||j	                  d      d       y )Nr   r   r  rN   rK  r  rJ  r  rD   r  rp  rt  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  r3   r3  r=  r   r5   s      r9   r?  zTestRFC2231.test_del_paramm  st    ""ll<(eUJFgG 	 	/eN3
3==b=) , 	r;   c                 l    | j                   }| j                  d      } ||j                         d       y )Nre  rN   )r2   r3   get_content_charsetr5   s      r9    test_rfc2231_get_content_charsetz,TestRFC2231.test_rfc2231_get_content_charset  s.    ll<(
3""$j1r;   c                     t        j                  d      }t        j                  |      }| j	                  |j                         d       | j	                  ||j                                y )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   r2   r   r   r  s      r9   test_rfc2231_parse_rfc_quotingz*TestRFC2231.test_rfc2231_parse_rfc_quoting  Z    OO   ''*))+D	FCMMO,r;   c                     t        j                  d      }t        j                  |      }| j	                  |j                         d       | j	                  ||j                                y )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  r  s      r9    test_rfc2231_parse_extra_quotingz,TestRFC2231.test_rfc2231_parse_extra_quoting  r  r;   c                     d}t        j                  |      }|j                  d      }| j                  |t               | j                  |d       y )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   rI   assertNotIsInstancetupler2   r6   r   r8   params       r9   #test_rfc2231_no_language_or_charsetz/TestRFC2231.test_rfc2231_no_language_or_charset  sN     ''*f%  .[	]r;   c                 r    d}t        j                  |      }| j                  |j                         d       y 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  r  s      r9   /test_rfc2231_no_language_or_charset_in_filenamez;TestRFC2231.test_rfc2231_no_language_or_charset_in_filename  8     ''*))+D	Fr;   c                 r    d}t        j                  |      }| j                  |j                         d       y r  r  r  s      r9   7test_rfc2231_no_language_or_charset_in_filename_encodedzCTestRFC2231.test_rfc2231_no_language_or_charset_in_filename_encoded  r  r;   c                 r    d}t        j                  |      }| j                  |j                         d       y )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  r  s      r9   test_rfc2231_partly_encodedz'TestRFC2231.test_rfc2231_partly_encoded  s9     ''*?	Ar;   c                 r    d}t        j                  |      }| j                  |j                         d       y )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  r  s      r9   test_rfc2231_partly_nonencodedz*TestRFC2231.test_rfc2231_partly_nonencoded  s9     ''*M	Or;   c                 r    d}t        j                  |      }| j                  |j                         d       y )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	  r  s      r9   /test_rfc2231_no_language_or_charset_in_boundaryz;TestRFC2231.test_rfc2231_no_language_or_charset_in_boundary  r  r;   c                 r    d}t        j                  |      }| j                  |j                         d       y )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   r2   r  r  s      r9   .test_rfc2231_no_language_or_charset_in_charsetz:TestRFC2231.test_rfc2231_no_language_or_charset_in_charset  s8     ''*002D	Fr;   c                 r    d}t        j                  |      }| j                  |j                         d       y )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  r  s      r9   %test_rfc2231_bad_encoding_in_filenamez1TestRFC2231.test_rfc2231_bad_encoding_in_filename  r  r;   c                 r    d}t        j                  |      }| j                  |j                         d        y )Nz:Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D

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

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


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

r  r  r  s      r9   &test_rfc2231_bad_character_in_encodingz2TestRFC2231.test_rfc2231_bad_character_in_encodingE  r  r;   c                     | j                   }d}t        j                  |      }|j                  d      \  }}} ||d         ||d         ||d       y )NzJContent-Type: application/x-foo;
	name*0*="Frank's"; name*1*=" Document"

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

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

r   rN   en-usr  r  r  s          r9   !test_rfc2231_tick_attack_extendedz-TestRFC2231.test_rfc2231_tick_attack_extended{  sZ    
 ''*"}}V41
7J
8W
1 !r;   c                     d}t        j                  |      }|j                  d      }| j                  |t               | j                  |d       y )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       r9   test_rfc2231_tick_attackz$TestRFC2231.test_rfc2231_tick_attack  sJ    
 ''*f%  . ABr;   c                 z    | j                   }d}t        j                  |      } ||j                  d      d       y )Nz:Content-Type: application/x-foo; name="Frank's Document"

r   r  r  r  s       r9   test_rfc2231_no_extended_valuesz+TestRFC2231.test_rfc2231_no_extended_values  s:     ''*
3== "45r;   c                     | j                   }d}t        j                  |      }|j                  d      \  }}} ||d        ||d        ||d       y )NziContent-Type: application/x-foo;
	name*0*="us-ascii'en-us'My";
	name*1=" Document";
	name*2*=" For You"

r   rN   r  My Document For Your  r  s          r9   ,test_rfc2231_encoded_then_unencoded_segmentsz8TestRFC2231.test_rfc2231_encoded_then_unencoded_segments  Z     ''*"}}V41
7J
8W
1#$r;   c                     | j                   }d}t        j                  |      }|j                  d      \  }}} ||d        ||d        ||d       y )NziContent-Type: application/x-foo;
	name*0="us-ascii'en-us'My";
	name*1*=" Document";
	name*2*=" For You"

r   rN   r  r  r  r  s          r9   ,test_rfc2231_unencoded_then_encoded_segmentsz8TestRFC2231.test_rfc2231_unencoded_then_encoded_segments  r  r;   c                     ddg}|D ]2  }| j                  |      5  t        j                  |      }d d d        4 y # 1 sw Y   ?xY w)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   )r6   messagesr   r8   s       r9   +test_should_not_hang_on_invalid_ew_messagesz7TestRFC2231.test_should_not_hang_on_invalid_ew_messages  s\    "  	3A" 3//23 3	33 3s	   =A	N)!r  r  r  r  r4  r  r?  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r	  r  r  r  r  r  r  r  r  r  r;   r9   r  r  2  s    K#JOB2-- ]
F
FAO
FF
F::
L;;"4$"	C6%"%3r;   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)
TestSignedc                     t        |d      5 }|j                         }t        j                  |      }d d d        ||fS # 1 sw Y   fS xY wrA  rB  )r6   rE  r   originalr8   s        r9   _msg_and_objzTestSigned._msg_and_obj  sQ    h1 	6RwwyH++H5C	6 }	6 }s   &A  Ac                    dd l } |j                  d|j                  |j                  z        }|j	                  |      j                  d      }|j	                  |      j                  d      }| j                  ||       y )Nr   z^--([^\n]+)\n(.*?)\n--\1$r   )r  r  Sr  searchgroupr2   )r6   r!  resultr  repartinpartoutparts          r9   _signed_parts_eqzTestSigned._signed_parts_eq  sf    8"$$+Fx(..q1--'--a0&)r;   c                 p    | j                  d      \  }}|j                         }| j                  ||       y rs  r"  r   r+  r6   r!  r8   r'  s       r9   test_long_headers_as_stringz&TestSigned.test_long_headers_as_string  s1    )),7#h/r;   c                 t    | j                  d      \  }}|j                  d      }| j                  ||       y )Nrt  <   rt  r-  r.  s       r9   (test_long_headers_as_string_maxheaderlenz3TestSigned.test_long_headers_as_string_maxheaderlen  s6    )),7#B/h/r;   c                     | j                  d      \  }}t               }t        |      j                  |       |j	                         }| j                  ||       y rs  )r"  r   r   r   r   r+  )r6   r!  r8   r   r'  s        r9   test_long_headers_flattenz$TestSigned.test_long_headers_flatten  sJ    )),7#Z"c"h/r;   N)r  r  r  r"  r+  r/  r2  r4  r  r;   r9   r  r    s    *0
0
0r;   r  c                       e Zd Zd Zy)TestHeaderRegistryc                     t               } |dd      }| j                  |j                  d   t        j                         y )NrA  zattachment; 0*00="foo"r   )r   r  r  r    InvalidHeaderDefect)r6   regr  s      r9   test_HeaderRegistryz&TestHeaderRegistry.test_HeaderRegistry  s6    %'?@aiilF,F,FGr;   N)r  r  r  r:  r  r;   r9   r6  r6    s    Hr;   r6  __main__)fr  r1  rW   r$  r   ior   r   	itertoolsr   randomr   	threadingr   unittest.mockr	   r   email.policy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#   rN  r$   test.supportr%   test.support.os_helperr&   test.test_emailr'   r(   r)   r   r  rG  r.   TestCaser  r
  r  r  r  r  r  r'  r~  r  r  r9  r?  r  r  r  r  r  r  r  r  r  r  rk  r|  r  r  r6  r  mainr  r;   r9   <module>rU     s  
 
             ! G G ; ; / ! 2 & $ & * . 4 $ -        ) ) 3 $	r] rl?8$$ ?Fx>m x>zK/x(( K/^/DH%% /Dh7DH%% 7DvXC(++ XCx7A8$$ 7Ax~6M ~6BkK kK^}<- }<BsKm sKn		J} 	J"Z-] Z-~D	> D	>Pd(M d(N-Am -A`QK- QKhjM jZ- -$3%E$238'G'581D"" 1Dh}"" }D
5E(## 5Eta4 a4La3- a3N0 0BH H zHMMO r;   