
    dafd                       d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d d	lmZ  e       Z G d
 de	      Z G d de	      Z G d de      Ze
 G d de             Ze
 G d de             Ze
 G d de             Ze
 G d de             Ze
 G d de             Ze
 G d de             Ze
 G d de             Z G d de	      Z G d  d!e      Z e!d"k(  r ejD                          yy)#    N)errorspolicy)Message)TestEmailBaseparameterize)headerregistry)AddressGroup)decode_header)	ALWAYS_EQc                   ^    e Zd Zd Zd Z G d d      Zd Z G d d      Zd Zd	 Z	d
 Z
d Zy)TestHeaderRegistryc                     t        j                         } |dd      }| j                  |t         j                         | j                  |t         j                         y Nfoobartestr	   HeaderRegistryassertIsInstance
BaseHeaderUnstructuredHeaderselffactoryhs      >/root/Python-3.12.4/Lib/test/test_email/test_headerregistry.py test_arbitrary_name_unstructuredz3TestHeaderRegistry.test_arbitrary_name_unstructured   sH     //1Hf%a!:!:;a!B!BC    c                     t        j                         }| j                  d|j                          |dd      }| j	                  |t         j
                         | j	                  |t         j                         y )NSubjectr   )r	   r   assertNotInregistryr   r   UniqueUnstructuredHeaderr   s      r   test_name_case_ignoredz)TestHeaderRegistry.test_name_case_ignored   s^     //1G$4$45Iv&a!:!:;a!H!HIr   c                       e Zd Zd Zy)TestHeaderRegistry.FooBasec                      y N )r   argskws      r   __init__z#TestHeaderRegistry.FooBase.__init__"   s    r   N)__name__
__module____qualname__r-   r*   r   r   FooBaser'   !   s    	r   r1   c                     t        j                  | j                        } |dd      }| j                  || j                         | j                  |t         j                         y )N)
base_classr   r   )r	   r   r1   r   r   r   s      r    test_override_default_base_classz3TestHeaderRegistry.test_override_default_base_class%   sL     //4<<HHf%a.a!B!BCr   c                   8    e Zd Zej                  j
                  Zy)TestHeaderRegistry.FooDefaultN)r.   r/   r0   r	   r   parser*   r   r   
FooDefaultr6   +   s    1177r   r8   c                     t        j                  | j                        } |dd      }| j                  |t         j                         | j                  || j                         y )Ndefault_classr   r   )r	   r   r8   r   r   r   s      r   test_override_default_classz.TestHeaderRegistry.test_override_default_class.   sL     //dooNHf%a!:!:;a1r   c                     t        j                  | j                        } |dd      }| j                  |t         j                         | j                  |t         j
                         y )Nr:   subjectr   )r	   r   r8   r   r   r$   r   s      r   2test_override_default_class_only_overrides_defaultzETestHeaderRegistry.test_override_default_class_only_overrides_default4   sN     //dooNIv&a!:!:;a!H!HIr   c                     t        j                  d      } |dd      }| j                  |t         j                         | j                  |t         j                         y )NF)use_default_mapr>   r   r   r   s      r   test_dont_use_default_mapz,TestHeaderRegistry.test_dont_use_default_map:   sJ     //FIv&a!:!:;a!B!BCr   c                    t        j                         } |dd      }|j                  dt         j                          |dd      }| j	                  |t         j
                         | j	                  |t         j                         | j	                  |t         j
                         | j	                  |t         j                         y r   )r	   r   map_to_typer$   r   r   r   )r   r   h1h2s       r   test_map_to_typez#TestHeaderRegistry.test_map_to_type@   s     //1Xv&Hn&M&MNXv&b.";";<b."C"CDb.";";<b."I"IJr   N)r.   r/   r0   r   r%   r1   r4   r8   r<   r?   rB   rG   r*   r   r   r   r      s?    DJ D8 82JDKr   r   c                   4    e Zd Z ej                         Zd Zy)TestHeaderBasec                 &    | j                  ||      S r)   )r   )r   namevalues      r   make_headerzTestHeaderBase.make_headerO   s    ||D%((r   N)r.   r/   r0   r	   r   r   rM   r*   r   r   rI   rI   K   s    +n++-G)r   rI   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestBaseHeaderFeaturesc                     | j                  dd      }| j                  |t               | j                  |d       | j                  t        |      d       y Nr>   this is a test)rM   r   strassertEqualr   r   s     r   test_strzTestBaseHeaderFeatures.test_strU   sK    Y(89a%,-Q!12r   c                 R    | j                  dd      }| j                  |dd d       y )Nr>   rR         is)rM   rT   rU   s     r   test_substrz"TestBaseHeaderFeatures.test_substr[   s+    Y(891Q&r   c                 `    | j                  dd      }| j                  |j                  d       y rQ   )rM   rT   rK   rU   s     r   test_has_namez$TestBaseHeaderFeatures.test_has_name_   s)    Y(89+r   c                     | j                  dd      }| j                  t              5  t        ||d       d d d        y # 1 sw Y   y xY w)Nr>   rR   foo)rM   assertRaisesAttributeErrorsetattr)r   attrr   s      r   _test_attr_roz$TestBaseHeaderFeatures._test_attr_roc   sD    Y(89~. 	$AtU#	$ 	$ 	$s	   ?Ac                 &    | j                  d       y )NrK   rd   r   s    r   test_name_read_onlyz*TestBaseHeaderFeatures.test_name_read_onlyh   s    6"r   c                 &    | j                  d       y )Ndefectsrf   rg   s    r   test_defects_read_onlyz-TestBaseHeaderFeatures.test_defects_read_onlyk   s    9%r   c                 `   | j                  dd      }| j                  t        |j                        d       | j	                  |j                  t
               | j                  dd      }| j                  t        |j                        d       | j	                  |j                  t
               y )Nr>   rR   r   date    )rM   rT   lenrj   r   tuplerU   s     r   test_defects_is_tuplez,TestBaseHeaderFeatures.test_defects_is_tuplen   s    Y(89QYY+aii/VR(QYY+aii/r   N)
r.   r/   r0   rV   r[   r]   rd   rh   rk   rr   r*   r   r   rO   rO   S   s%    3',$
#&0r   rO   c                   0    e Zd Zd Zddg dfddg dfddd	Zy
)TestUnstructuredHeaderc                 H   t        |      }|dkD  r|d   ng }d|rdndz   }||dkD  r|d   n|z   dz   }| j                  d|      }| j                  ||       | j                  |j                  |       | j                  |j                  t        j                        |       y )	Nr   zSubject: rn   ro   
r!   r   )rp   rM   rT   assertDefectsEqualrj   foldr   default)	r   sourcedecodedr+   lrj   headerfoldedr   s	            r   string_as_valuez&TestUnstructuredHeader.string_as_value   s     IqS$q'bfs"5ac47v6=Y/G$		73v~~6?r   z=?utf-8?q?this_is_a_test?=rR   z!=?gb2312?b?1eLKx9bQzsSy4srUo6E=?=u   这是中文测试！z(=?utf-8?b?6L+Z5piv5Lit5paH5rWL6K+V77yB?=)z=?utf-8?q?=C3=89ric?=   Éric)z$The =?utf-8?q?=C3=89ric=2C?= Himself   The Éric, Himself)rfc2047_simple_quoprirfc2047_gb2312_base64rfc2047_simple_nonascii_quopri rfc2047_quopri_with_regular_textN)r.   r/   r0   r   string_paramsr*   r   r   rt   rt      s?    @  )	" 086	"8+-"%Mr   rt   c            	           e Zd ZdZ ej
                  d      Z ej                  e      Z ej                  dddddd	e
      Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zy)TestDateHeaderzSun, 23 Sep 2001 20:10:55 -0700i)hoursi  	         
   7   )tzinfoc                 `   | j                  d| j                        }| j                  || j                         | j                  |j                  | j                         | j                  |j                  j                         | j
                         | j                  |j                  d       y Nrm   r*   )rM   
datestringrT   datetimedt	utcoffsetrj   rU   s     r   test_parse_datezTestDateHeader.test_parse_date   sy    VT__5DOO,TWW---/@B'r   c                     | j                  d| j                        }| j                  || j                         | j                  |j                  | j                         | j                  |j
                  d       y r   )rM   r   rT   r   r   rj   rU   s     r   test_set_from_datetimez%TestDateHeader.test_set_from_datetime   sX    VTWW-DOO,TWW-B'r   c                     | j                  d| j                        }| j                  |t        j                         | j                  |j                  d       | j                  |j                  d       y )Nrm   ro   r*   )rM   r   r   r	   UniqueDateHeaderrT   	max_countrj   rU   s     r   test_date_header_propertiesz*TestDateHeader.test_date_header_properties   sV    VT__5a!@!@Aa(B'r   c                     | j                  d| j                        }| j                  |t        j                         | j                  |j                  d        | j                  |j                  d       y )Nzresent-dater*   )rM   r   r   r	   
DateHeaderrT   r   rj   rU   s     r   "test_resent_date_header_propertiesz1TestDateHeader.test_resent_date_header_properties   sV    ]DOO<a!:!:;d+B'r   c                     | j                  dd      }| j                  t        |j                        d       | j	                  |j                  d   t
        j                         y )Nrm   rn   ro   r   )rM   rT   rp   rj   r   r   HeaderMissingRequiredValuerU   s     r   test_no_value_is_defectz&TestDateHeader.test_no_value_is_defect   sJ    VR(QYY+aiilF,M,MNr   c                 *   d}| j                  d|      }| j                  ||       | j                  |j                         | j                  t	        |j
                        d       | j                  |j
                  d   t        j                         y )NzNot a date headerrm   ro   r   	rM   rT   assertIsNoner   rp   rj   r   r   InvalidDateDefectr   sr   s      r   test_invalid_date_formatz'TestDateHeader.test_invalid_date_format   sq    VQ'A!**%QYY+aiilF,D,DEr   c                 *   d}| j                  d|      }| j                  ||       | j                  |j                         | j                  t	        |j
                        d       | j                  |j
                  d   t        j                         y )NzTue, 06 Jun 2017 27:39:33 +0600rm   ro   r   r   r   s      r   test_invalid_date_valuez&TestDateHeader.test_invalid_date_value   sq    -VQ'A!**%QYY+aiilF,D,DEr   c                     | j                  d| j                        }| j                  t              5  d|_        d d d        y # 1 sw Y   y xY w)Nrm   r_   )rM   r   r`   ra   r   rU   s     r   test_datetime_read_onlyz&TestDateHeader.test_datetime_read_only   sB    VT__5~. 	AJ	 	 	s   AAc                     t        t        j                        }| j                  |d<   | j	                  |d   | j
                         | j	                  |d   j                  | j                         y )Nr   Date)r   r   rz   r   rT   r   r   )r   ms     r   "test_set_date_header_from_datetimez1TestDateHeader.test_set_date_header_from_datetime   sS    6>>*GG&	6DOO46++TWW5r   N)r.   r/   r0   r   r   	timedeltar   timezonetzr   r   r   r   r   r   r   r   r   r   r*   r   r   r   r      s{     3J""",I			9	%B			4BB2	>B((((O
FF
6r   r   c                   L   e Zd Zd Zi dddddddig d	fd
ddddddig d	fdd	dddddifdddddi ej
                  gfdddddi ej
                  gfdddddi ej
                  gfdddddi ej
                  gfdddddddddddddddifd d!ddddd"ifd#d$ddddd%ifd&d'dddddig d(fd)d*dddd+dig d,fd-d.dddd+d/ifi d0d1dddd+d2ifd3d4dddd5d5d6ej
                  gd7z  fd8d9d:d;d<d=d>ig d?fd@dAdBdCdDdEdFdGdHg dIdJfdKdLdBdCdDdEdFdGdMdNg dLdOfdPdQdBdCdDdRdSifdTdUdBdCdDdRdVifdWdXdBdCdDdRdYig dXfdZd[j                  d\      j                  dd]      d^d_d`dadbdcej                  gd7z  dddefdfdgdBdCdDdRdhig difdjdkdBdCdDd`dlig dmfdndoj                  d\      j                  dd]      dddddpdqej                  gdrdsfdtdudddddig d	fdvdwddddRdxig dyfdzd{ddddRd|iej
                  gd}z  d~fddddddddqej
                  gd}z  ddfddddddRdiej
                  gd}z  dfdddddRdig dfdddddRdiej
                  gdfdddddRdiej
                  gd}z  dfdddddRdiej
                  gd}z  dfdddddRdiej
                  gddfdddddRdig dfddddddiej                  gddfddddddiej                  gddfddddddig ddfdddddRdiej
                  gdfdddddRdiej
                  gd7z  dfdddddRdiej
                  gd}z  dfdddddRdig ddfdZ	y)TestContentTypeHeaderc                    t        |      }|dkD  r|d   ni }|dkD  r|d   ng }|dkD  r|d   t        ur|d   n|}	|rdnd}
|dkD  r|d   n|
|	z   dz   }| j                  d|      }| j                  |j                  |       | j                  |j
                  |       | j                  |j                  |       | j                  |j                  |       | j                  t              5  d	|j                  d
<   d d d        | j                  |j                  |       | j                  ||	       | j                  |j                  t        j                        |       y # 1 sw Y   hxY w)Nr   ro      zContent-Type: rn      rw   zContent-Typexyzabcr   )rp   DITTOrM   rT   content_typemaintypesubtypeparamsr`   	TypeErrorrx   rj   ry   r   rz   )r   r{   r   r   r   r+   r}   parmdictrj   r|   r~   r   r   s                r   content_type_as_valuez+TestContentTypeHeader.content_type_as_value   sE    Ic47rc47rcd1gU&:47*0&baCaVg%5%<^V46X.G,8,y) 	$#AHHUO	$		73G$v~~6?		$ 	$s   *E!!E*
RFC_2045_1z)text/plain; charset=us-ascii (Plain text)
text/plaintextplaincharsetzus-asciiztext/plain; charset="us-ascii"
RFC_2045_2ztext/plain; charset=us-ascii
RFC_2045_3no_subtype_in_content_typeztext/no_slash_in_content_typer_   junk_text_in_content_typez<crazy "stuff"> too_many_slashes_in_content_typezimage/jpeg/foounknown_content_type)	bad/namesr   badnamesmixed_case_content_type)z
ImAge/JPeg
image/jpegimagejpegspaces_in_content_type)z  text  /  plain  r   r   r   cfws_in_content_type)z"(foo) text (bar)/(baz)plain(stuff)r   r   r   charset_paramztext/plain; charset="utf-8"zutf-8capitalized_charsetztext/plain; charset="US-ASCII"zUS-ASCIIunknown_charsetztext/plain; charset="fOo"fOo*capitalized_charset_param_name_and_commentz*text/plain; (interjection) Charset="utf-8"ztext/plain; Charset="utf-8"unquoted_param_valueztext/plain; title=footitleztext/plain; title="foo"param_value_with_tspecialsz!text/plain; title="(bar)foo blue"z(bar)foo blue"param_with_extra_quoted_whitespacez0text/plain; title="  a     loong  way 	 home   "z  a     loong  way 	 home   
bad_paramszblarg; baz; boorn   )bazboor   spaces_around_param_equalsz0Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"zmultipart/mixed	multipartmixedboundaryCPIMSSMTPC06p5f3tGz.Multipart/mixed; boundary="CPIMSSMTPC06p5f3tG"spaces_around_semiszPimage/jpeg; name="wibble.JPG" ; x-mac-type="4A504547" ; x-mac-creator="474B4F4E"r   r   r   z
wibble.JPG4A504547474B4F4E)rK   
x-mac-typex-mac-creatorzNimage/jpeg; name="wibble.JPG"; x-mac-type="4A504547"; x-mac-creator="474B4F4E"z^Content-Type: image/jpeg; name="wibble.JPG"; x-mac-type="4A504547";
 x-mac-creator="474B4F4E"
lots_of_mime_paramszmimage/jpeg; name="wibble.JPG"; x-mac-type="4A504547"; x-mac-creator="474B4F4E"; x-extrastuff="make it longer"zmake it longer)rK   r   r   zx-extrastuffz}Content-Type: image/jpeg; name="wibble.JPG"; x-mac-type="4A504547";
 x-mac-creator="474B4F4E"; x-extrastuff="make it longer"
semis_inside_quotesz$image/jpeg; name="Jim&amp;&amp;Jill"rK   zJim&amp;&amp;Jillsingle_quotes_inside_quotesz!image/jpeg; name="Jim 'Bob' Jill"zJim 'Bob' Jilldouble_quotes_inside_quotesz#image/jpeg; name="Jim \"Bob\" Jill"zJim "Bob" Jillnon_ascii_in_paramsu   foo§/bar; b§r=two; baz=thr§ezlatin-1surrogateescapeu
   foo�/baru   foo�bartwou   thr�e)u   b�rr   u&   foo�/bar; b�r="two"; baz="thr�e"uV   Content-Type: =?unknown-8bit?q?foo=A7?=/bar; br="two";
 baz*=unknown-8bit''thr%A7e
rfc2231_segmented_normal_valuesz(image/jpeg; name*0="abc"; name*1=".html"zabc.htmlzimage/jpeg; name="abc.html"quotes_inside_rfc2231_valuez.image/jpeg; bar*0="baz\"foobar"; bar*1="\"baz"zbaz"foobar"bazz"image/jpeg; bar="baz\"foobar\"baz"non_ascii_rfc2231_valueuG   text/plain; charset=us-ascii; title*=us-ascii'en'This%20is%20not%20f§nu   This is not f�n)r   r   u9   text/plain; charset="us-ascii"; title="This is not f�n"z\Content-Type: text/plain; charset="us-ascii";
 title*=unknown-8bit''This%20is%20not%20f%A7n
rfc2231_encoded_charsetz-text/plain; charset*=ansi-x3.4-1968''us-ascii rfc2231_encoded_no_double_quotesz\text/plain;	name*0*=''This%20is%20;	name*1*=%2A%2A%2Afun%2A%2A%2A%20;	name*2="is it not.pdf"zThis is ***fun*** is it not.pdfz2text/plain; name="This is ***fun*** is it not.pdf""rfc2231_encoded_with_double_quoteszvtext/plain;	name*0*="us-ascii''This%20is%20even%20more%20";	name*1*="%2A%2A%2Afun%2A%2A%2A%20";	name*2="is it not.pdf"z)This is even more ***fun*** is it not.pdfr   z<text/plain; name="This is even more ***fun*** is it not.pdf")rfc2231_single_quote_inside_double_quotesztext/plain; charset=us-ascii;	title*0*="us-ascii'en'This%20is%20really%20";	title*1*="%2A%2A%2Afun%2A%2A%2A%20";	title*2="isn't it!"z"This is really ***fun*** isn't it!zJtext/plain; charset="us-ascii"; title="This is really ***fun*** isn't it!"zZContent-Type: text/plain; charset="us-ascii";
 title="This is really ***fun*** isn't it!"
3rfc2231_single_quote_in_value_with_charset_and_langzHapplication/x-foo;	name*0*="us-ascii'en-us'Frank's"; name*1*=" Document"zapplication/x-fooapplicationzx-foozFrank's Documentz*application/x-foo; name="Frank's Document"zFapplication/x-foo;	name*0="us-ascii'en-us'Frank's"; name*1=" Document"zus-ascii'en-us'Frank's Documentz9application/x-foo; name="us-ascii'en-us'Frank's Document"z/text/plain; NAME*0*=english_is_the_default.htmlzenglish_is_the_default.htmlz.text/plain; NAME="english_is_the_default.html"zjtext/plain;	name*0*="''This%20is%20even%20more%20";	name*1*="%2A%2A%2Afun%2A%2A%2A%20";	name*2="is it.pdf"z%This is even more ***fun*** is it.pdfz8text/plain; name="This is even more ***fun*** is it.pdf"zitext/plain;	name*0*="''This%20is%20even%20more%20";	name*1="%2A%2A%2Afun%2A%2A%2A%20";	name*2="is it.pdf"z3This is even more %2A%2A%2Afun%2A%2A%2A%20is it.pdfzFtext/plain; name="This is even more %2A%2A%2Afun%2A%2A%2A%20is it.pdf"zVContent-Type: text/plain;
 name="This is even more %2A%2A%2Afun%2A%2A%2A%20is it.pdf"
z1text/plain; name*0*=bogus'xx'ascii_is_the_defaultascii_is_the_defaultz'text/plain; name="ascii_is_the_default"z*text/plain; charset*=ascii''utf-8%F1%F2%F3u   utf-8���u$   text/plain; charset="utf-8���"z@Content-Type: text/plain; charset*=unknown-8bit''utf-8%F1%F2%F3
z*text/plain; charset*=ascii''utf-8%E2%80%9Du   utf-8”u   text/plain; charset="utf-8”"z@Content-Type: text/plain; charset*=unknown-8bit''utf-8%E2%80%9D
u-   text/plain; charset*=utf-8”''utf-8%E2%80%9Dz9Content-Type: text/plain; charset*=utf-8''utf-8%E2%80%9D
zUapplication/x-foo;	name*0*="us-ascii'en-us'My";	name*1=" Document";	name*2=" For You"zMy Document For Youz-application/x-foo; name="My Document For You"zTapplication/x-foo;	name*0=us-ascii'en-us'My;	name*1*=" Document";	name*2*=" For You"zVapplication/x-foo;	name*0="us-ascii'en-us'My";	name*1*=" Document";	name*2*=" For You"z"us-ascii'en-us'My Document For Youz<application/x-foo; name="us-ascii'en-us'My Document For You"zrapplication/x-foo;	name="with spaceswith spaceswith spaceswith spaceswith spaceswith spaceswith spaceswith spaces"zXwith spaceswith spaceswith spaceswith spaceswith spaceswith spaceswith spaceswith spaceszrapplication/x-foo; name="with spaceswith spaceswith spaceswith spaceswith spaceswith spaceswith spaceswith spaces"zContent-Type: application/x-foo;
 name*0*=us-ascii''with%20spaceswith%20spaceswith%20spaceswith%20spaceswith;
 name*1*=%20spaceswith%20spaceswith%20spaceswith%20spaces
))rfc2231_single_quote_in_non_encoded_valuerfc2231_no_language_or_charsetrfc2231_encoded_no_charsetrfc2231_partly_encodedrfc2231_partly_encoded_2(rfc2231_unknown_charset_treated_as_ascii0rfc2231_bad_character_in_charset_parameter_value8rfc2231_utf8_in_supposedly_ascii_charset_parameter_value6rfc2231_nonascii_in_charset_of_charset_parameter_value'rfc2231_encoded_then_unencoded_segments'rfc2231_unencoded_then_encoded_segments.rfc2231_quoted_unencoded_then_encoded_segments+rfc2231_folded_segments_correctly_formattedN)
r.   r/   r0   r   r   InvalidHeaderDefectencodedecodeUndecodableBytesDefectcontent_type_paramsr*   r   r   r   r      sw   @.[ 	7
#,.	[ 	*
#,.[, 	,
#%-[@ 	%''('*A[P 	#''(%*Q[` 	$''(&*a[p 	+''(-*q[L 	 !M[\ 	" $][h 	! #i[t 	 !u[H 	) "I[V 	,
# %W[d 	' e[r 	58 )7+s[R 	#e%!S[f 	%/o&'(g[t 	-?56/8u[B 	r"''(*,C[R 	%>-.<'S[f 	+!%(* ++ g[H 	J!%(-/ JJ I[p 	2() +q[~ 	&1%&(([L 	&2%&2(4M[^ 	%vi0
8I2K|4**+A-4,! _[J 	*6Z ),+K[\ 	&=$%1(3][n 	"#VI.vvj5F0H"-CD++,H>$o[L	 	"=
#,$.M	[`	 	++ 67@-a	[|	 	-+ @A''(*J/}	[V
 	4( "-QR''(*=A6W
[v
 	>N'(''(*9	@w
[NL67J	6 >23''(<+>' <=''(*F'' <=''(*F#' JK''(K%$ @+,557 912**+;7
= 9
#**+,7E <
#,0
C&  *+''(;4"'  *+''(*;40'  9:''(*L;$3_%?J8Y[r   r   c                   Z    e Zd Zd Zdddej
                  gddfddej                  gfdZy)	TestContentTransferEncodingc                    t        |      }|dkD  r|d   ng }|dkD  r|d   t        ur|d   n|}|rdnd}|dkD  r|d   n||z   dz   }| j                  d|      }	| j                  |	j                  |       | j                  |	j                  |       | j                  |	|       | j                  |	j                  t        j                        |       y )	Nr   ro   zContent-Transfer-Encoding: rn   r   rw   zContent-Transfer-Encodingr   )
rp   r   rM   rT   cterx   rj   ry   r   rz   )
r   r{   r  r+   r}   rj   r|   r~   r   r   s
             r   cte_as_valuez(TestContentTransferEncoding.cte_as_value'  s     Ic47rcd1gU&:477=32aCaVf_t%;8&A$		73G$v~~6?r   )base64r  rn   7bitzContent-Transfer-Encoding:
z7bit and a bunch more)
RFC_2183_1no_valuejunk_after_cteN)r.   r/   r0   r  r   r   r  
cte_paramsr*   r   r   r  r  $  sL    @"
 ../* $''(*Jr   r  c                       e Zd Zd Zddddddg dd	fd
di ej
                  gd
dfddi ej                  gfddddiej                  gfddddiej                  gdz  ddfddddiej                  gddfdZy)TestContentDispositionc                    t        |      }|dkD  r|d   ni }|dkD  r|d   ng }|dkD  r|d   t        ur|d   n|}|rdnd}|dkD  r|d   n||z   dz   }	| j                  d|      }
| j                  |
j                  |       | j                  |
j
                  |       | j                  |
j                  |       | j                  |
|       | j                  |
j                  t        j                  	      |	       y )
Nr   ro   r   zContent-Disposition: rn   r   rw   zContent-Dispositionr   )rp   r   rM   rT   content_dispositionr   rx   rj   ry   r   rz   )r   r{   r"  r+   r}   r   rj   r|   r~   r   r   s              r   content_disp_as_valuez,TestContentDisposition.content_disp_as_valueO  s     Ic47rc47rcd1gU&:4717-RaCaVf_t%;2F;..0CD8,		73G$v~~6?r   )inliner$  zWattachment; filename=genome.jpeg;  modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
attachmentzgenome.jpegzWed, 12 Feb 1997 16:29:51 -0500)filenamezmodification-datezWattachment; filename="genome.jpeg"; modification-date="Wed, 12 Feb 1997 16:29:51 -0500"znContent-Disposition: attachment; filename="genome.jpeg";
 modification-date="Wed, 12 Feb 1997 16:29:51 -0500"
rn   NzContent-Disposition:
zab./kzab.zab./k; filename="foo"r&  r_   zaattachment; filename="=?UTF-8?Q?Schulbesuchsbest=C3=A4ttigung=2E?=               =?UTF-8?Q?pdf?="u   Schulbesuchsbestättigung.pdfr   u4   attachment; filename="Schulbesuchsbestättigung.pdf"zUContent-Disposition: attachment;
 filename*=utf-8''Schulbesuchsbest%C3%A4ttigung.pdf
z<attachment; filename="File =?utf-8?q?Name?= With Spaces.pdf"zFile Name With Spaces.pdfz0attachment; filename="File Name With Spaces.pdf"zFContent-Disposition: attachment; filename="File Name With Spaces.pdf"
)r  
RFC_2183_2r  invalid_valueinvalid_value_with_params+invalid_parameter_value_with_fws_between_ew'parameter_value_with_fws_between_tokens)r.   r/   r0   r#  r   r   r  content_disp_paramsr*   r   r   r   r   L  s    @*
F&"CEGF ../$& ''(	* $''(	&*.89''(*CG	8 K45''(>V4i<r   r   c                      e Zd Zd Zdddddg fdddddg fdddddg fdddddg fdddddg fd	d	d	d
dg fdddddg fdddddg fdddddej
                  gfdddddej
                  gfdddddej
                  gfdddddej
                  gfdddddej
                  gfdddddej
                  gfdddddej                  gfdZy)TestMIMEVersionHeaderc                    | j                  d|      }| j                  ||       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       |rd|z   }| j                  |j                  t        j                        d|z   dz          y )NzMIME-Versionrv   r   zMIME-Version:rw   )
rM   rT   versionmajorminorrx   rj   ry   r   rz   )r   r{   r|   r0  r1  r2  rj   r   s           r   version_string_as_MIME_Versionz4TestMIMEVersionHeader.version_string_as_MIME_Version  s     ^V4G$G,%(%(		736\Fv~~6(61D8	:r   z1.0ro   r   z1.0 (produced by MetaSend Vx.x)z(produced by MetaSend Vx.x) 1.0z1.(produced by MetaSend Vx.x)0z1.1z2.1r   z1 .0z  1.0  z	1.0 <abc>z	<abc> 1.0Nz1.<abc>0z1..0z2.xr_   rn   )r   r   r   
RFC_2045_41_12_1
whitespace#leading_trailing_whitespace_ignorednon_comment_garbage_afternon_comment_garbage_beforenon_comment_garbage_insidetwo_periods2_xr_   missing)r.   r/   r0   r3  r   r  r   version_string_paramsr*   r   r   r.  r.    s   :.  .- .- -,    0 ''(&* ''('* ''('* ''(* ''(* ''(* ../1}F
r   r.  c            
          e Zd Zi ddej                  gddddddfddg ddddddfd	d
g d
dddddfddg ddddddfddg ddddddfddg ddddddfddej
                  gddddd dfd!d"ej                  gd#z  d$dd$d%d dfd&d'g d'dd'd(d dfd)d*ej                  gd+z  d,dd,d-d dfd.d/ej                  gd0z  d1dd1d2d dfd3d4ej
                  gd5dd5d6d dfd7d8g d9d:d;d<d dfd=d>g d?d@d;d<d dfdAdBej                  ej                  gd9d:d;d<d dfdCdDej
                  gdEdFddd dfdGdHej                  ej
                  gdIdJddd dfZdK ZdL ZdM Z	dN Z
dO ZdP ZdQ ZdR ZdS ZdT ZdU ZdV ZdW Zy)XTestAddressHeaderempty<>rn   Naddress_onlyzzippy@pinhead.comzippyzpinhead.comname_and_addressz%Zaphrod Beblebrux <zippy@pinhead.com>zZaphrod Beblebruxquoted_local_partz)Zaphrod Beblebrux <"foo bar"@pinhead.com>z"foo bar"@pinhead.comfoo barquoted_parens_in_namez'"A \(Special\) Person" <person@dom.ain>z%"A (Special) Person" <person@dom.ain>zA (Special) Personzperson@dom.ainpersonzdom.ainquoted_backslashes_in_namez."Arthur \\Backslash\\ Foobar" <person@dom.ain>zArthur \Backslash\ Foobarname_with_dotzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>zJohn X. Doezjxd@example.comjxdexample.comquoted_strings_in_local_partz""example" example"@example.comr   z"example example"@example.comzexample example$escaped_quoted_strings_in_local_partz!"\"example\" example"@example.comz"example" exampleescaped_escapes_in_local_partz#"\\"example\\" example"@example.comrX   z#"\\example\\\\ example"@example.comz\example\\ example'spaces_in_unquoted_local_part_collapsedzmerwok  wok  @example.comr   z"merwok wok"@example.comz
merwok wok(spaces_around_dots_in_local_part_removedzmerwok. wok .  wok@example.comzmerwok.wok.wok@example.comzmerwok.wok.wokrfc2047_atom_is_decodedz'=?utf-8?q?=C3=89ric?= <foo@example.com>u   Éric <foo@example.com>r   foo@example.comr_   !rfc2047_atom_in_phrase_is_decodedz6The =?utf-8?q?=C3=89ric=2C?= Himself <foo@example.com>u&   "The Éric, Himself" <foo@example.com>r   (rfc2047_atom_in_quoted_string_is_decodedz)"=?utf-8?q?=C3=89ric?=" <foo@example.com>"name_ending_with_dot_without_spacezJohn X.<jxd@example.com>z"John X." <jxd@example.com>zJohn X.name_starting_with_dotz. Doe <jxd@example.com>z". Doe" <jxd@example.com>z. Doec	                    | j                  d|      }	| j                  |	|       | j                  |	j                  |       |	j                  }
| j                  t        |
      |       | j                  t        |	j                        d       | j                  |
gt        |	j                  d   j                               | j                  |
gt        |	j                               | j                  |
j                  |       | j                  |
j                  |       | j                  |
j                  |       | j                  |
j                  |       y )Nsenderro   r   )rM   rT   rx   rj   addressrS   rp   groupslist	addressesdisplay_name	addr_specusernamedomain)r   r{   rj   r|   r`  ra  rb  rc  commentr   as              r   example_as_addressz$TestAddressHeader.example_as_address  s    Xv.G$		73IIQ)QXX*!d188A;#8#89:!d1;;/06i0X.6*r   c	                    dj                  |      }|rdj                  |      nd}	| j                  d|      }
| j                  |
|	       | j                  |
j                  |       | j                  |
j
                  d   j                  |
j                         | j                  t        |
j
                        d       | j                  t        |
j                        d       |
j                  d   }| j                  t        |      |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       y )Nzfoo: {};foo:;tor   ro   )formatrM   rT   rx   rj   r]  r_  rp   rS   r`  ra  rb  rc  )r   r{   rj   r|   r`  ra  rb  rc  rd  gdecodedr   re  s               r   example_as_groupz"TestAddressHeader.example_as_group  s    ""6*18:$$W-gT6*H%		73!..<QXX*Q[[)1-KKNQ)6i0X.6*r   c                    d}| j                  d|      }| j                  ||       | j                  t        |j                        d       | j                  t        |j                        d       t        d      D ];  }| j                  |j                  |   j                  d   |j                  |          = | j                  t        |j                  d         d       | j                  t        |j                  d         d       | j                  t        |j                  d         d	       | j                  |j                  d   j                  d
       y )NzTFred <dinsdale@python.org>, foo@example.com, "Harry W. Hastings" <hasty@example.com>ri  r   r   zFred <dinsdale@python.org>ro   rU  r   z'"Harry W. Hastings" <hasty@example.com>zHarry W. Hastings)rM   rT   rp   r]  r_  rangerS   r`  )r   rL   r   is       r   test_simple_address_listz*TestAddressHeader.test_simple_address_list  s   >T5)E"QXX*Q[[)1-q 	GAQXXa[2215q{{1~F	GQ[[^,.JKQ[[^,.?@Q[[^,5	7Q44	!r   c                    t        | j                  j                               }ddj                  |d d D cg c]  }|d   	 c}      z   dz   dz   dj                  |dd D cg c]  }|d   	 c}      z   dz   dj                  |dd  D cg c]  }|d   	 c}      z   }ddj                  |d d D cg c]  }|d	   	 c}      z   dz   dz   dj                  |dd D cg c]  }|d	   	 c}      z   d
z   dj                  |dd  D cg c]  }|d	   	 c}      z   }| j	                  d|      }| j                  |j                  d      |j                  d             | j                  ||       | j                  t        |j                        dt        |      z   dz
         | j                  |j                  d   j                  d       | j                  |j                  d   j                  d       | j                  |j                  d   j                  d       | j                  t        |j                        t        |             t        d      D ]k  }| j                  |j                  |d	z      j                         | j                  t        |j                  |d	z      j                  d         ||   d	          m t        ddt        |      z   dz
        D ]h  }| j                  |j                  |   j                         | j                  t        |j                  |   j                  d         ||dz
     d	          j t        t        |            D ]_  }| j                  t        |j                  |         ||   d	          | j                  |j                  |   j                  ||   d          a y c c}w c c}w c c}w c c}w c c}w c c}w )Nz dummy list:;, another: (empty);,z,    r   z"A \"list\"":    z;,zdummy list:;, another:;, r   z;, ri  ,rY   z
dummy listro   anotherzA "list")r^  example_paramsvaluesjoinrM   rT   splitrp   r]  r`  r_  rn  r   rS   ra  )r   examplesxr{   expectedr   ro  s          r   test_complex_address_listz+TestAddressHeader.test_complex_address_list%  s   ++22454(2A,7QAaD789;?@"# IIXa];qt;<= @DD (12,7QAaD78	9 0(2A,7QAaD789;?@"# IIXa];qt;<= @EE (12,7QAaD78	9 T6*x~~c':;H%QXXCM(9A(=>!11<@!119=!11:>Q[[)3x=9q 	NAahhqsm889S!A#!8!8!;<hqk!nM	N q!c(m+a/0 	NAahhqk667S!!6!6q!9:HQqSM!<LM	N s8}% 	GASQ0(1+a.AQ[[^55x{1~F	G9 8;7
 8;7s#   O
#O

O
4O
 O
	O
c                     | j                  dd      }| j                  t              5  d|_        d d d        y # 1 sw Y   y xY wNr[  zabc@xyz.comr_   )rM   r`   ra   r\  rU   s     r   test_address_read_onlyz(TestAddressHeader.test_address_read_onlyH  s>    X}5~. 	AI	 	 		   9Ac                     | j                  dd      }| j                  t              5  d|_        d d d        y # 1 sw Y   y xY wr  )rM   r`   ra   r_  rU   s     r   test_addresses_read_onlyz*TestAddressHeader.test_addresses_read_onlyM  s>    X}5~. 	 AK	  	  	 r  c                     | j                  dd      }| j                  t              5  d|_        d d d        y # 1 sw Y   y xY wr  )rM   r`   ra   r]  rU   s     r   test_groups_read_onlyz'TestAddressHeader.test_groups_read_onlyR  s>    X}5~. 	AH	 	 	r  c                     d}| j                  d|      }| j                  |j                  t               | j                  |j                  d   t               y Nzme <who@example.com>ri  r   )rM   r   r_  rq   r
   r   r{   r   s      r   test_addresses_typesz&TestAddressHeader.test_addresses_typesW  sE    'T6*akk51akk!ng6r   c                     d}| j                  d|      }| j                  |j                  t               | j                  |j                  d   t               y r  )rM   r   r]  rq   r   r  s      r   test_groups_typesz#TestAddressHeader.test_groups_types]  sE    'T6*ahh.ahhqk51r   c                 b    | j                  dt        ddd            }| j                  |d       y )Nri  mer_   rN  zme <foo@example.com>rM   r
   rT   rU   s     r   test_set_from_Addressz'TestAddressHeader.test_set_from_Addressc  s.    T74#FG23r   c           	      |    | j                  dt        ddd      t        ddd      g      }| j                  |d       y )Nri  r  r_   rN  your   z+me <foo@example.com>, you <bar@example.com>r  rU   s     r   test_set_from_Address_listz,TestAddressHeader.test_set_from_Address_listg  sC    TGD%$G$+E5-$H$J KIJr   c                 B   | j                  dt        ddd      t        dt        ddd      t        d	d
d      g      t        ddd      g      }| j                  |d       | j                  |j	                  t
        j                  j                  d            d       y )Nri  r  r_   rN  bingfizzb.comziffc.comr  r   zPme <foo@example.com>, bing: fiz <z@b.com>, zif <f@c.com>;, you <bar@example.com>(   max_line_lengthr   zWto: me <foo@example.com>,
 bing: fiz <z@b.com>, zif <f@c.com>;,
 you <bar@example.com>
)rM   r
   r   rT   ry   r   rz   clonerU   s     r   $test_set_from_Address_and_Group_listz6TestAddressHeader.test_set_from_Address_and_Group_listl  s    TGD%$G$)&75#w3O3:5#w3O3Q %R$+E5-$H$J K 	 D 	Ev~~';';B';'OP3	4r   c                     | j                  dt        dt        ddd      t        ddd      g      g      }| j                  |d	       y )
Nri  r  r  r  r  r  r  r  z#bing: fiz <z@b.com>, zif <f@c.com>;)rM   r   r
   rT   rU   s     r   test_set_from_Group_listz*TestAddressHeader.test_set_from_Group_listx  sS    TE&75#w3O3:5#w3O3Q %R $S TABr   )r.   r/   r0   r   r  ObsoleteHeaderDefectrv  rf  rl  rp  r}  r  r  r  r  r  r  r  r  r  r*   r   r   rA  rA  =  s   m
(()m
 	   m
, 	44  /m
@ 	88 $Cm
T 	 74!Wm
h 	%>>)km
| 	,))*.m
P 	'.(()!+,,Sm
d 	/111!gm
x 	(3(()!+33"{m
L 	2((()!+''Om
` 	3-))*))cm
t 	"6%wm
H 	,E4 Km
\ 	38''&&(%_m
r 	-'))**um
F 	!&((&*E*EF(Im
Nf+"+"! !GF
 

724K

4Cr   rA  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$y#)$TestAddressAndGroupc                 r    | j                  t              5  t        ||d       d d d        y # 1 sw Y   y xY w)Nr_   )r`   ra   rb   )r   objrc   s      r   rd   z!TestAddressAndGroup._test_attr_ro  s1    ~. 	&Cu%	& 	& 	&   -6c                 >    | j                  t        ddd      d       y )Nr_   r   r   r`  rd   r
   rg   s    r   test_address_display_name_roz0TestAddressAndGroup.test_address_display_name_ro  s    75%7Hr   c                 >    | j                  t        ddd      d       y )Nr_   r   r   rb  r  rg   s    r   test_address_username_roz,TestAddressAndGroup.test_address_username_ro  s    75%7Dr   c                 >    | j                  t        ddd      d       y )Nr_   r   r   rc  r  rg   s    r   test_address_domain_roz*TestAddressAndGroup.test_address_domain_ro  s    75%7Br   c                 :    | j                  t        d      d       y )Nr_   r`  rd   r   rg   s    r   test_group_display_name_roz.TestAddressAndGroup.test_group_display_name_ro  s    5<8r   c                 :    | j                  t        d      d       y )Nr_   r_  r  rg   s    r   test_group_addresses_roz+TestAddressAndGroup.test_group_addresses_ro  s    5<5r   c                 4   t        ddd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nr_   r   r   bar@bazfoo <bar@baz>r
   rT   r`  rb  rc  ra  rS   r   re  s     r   !test_address_from_username_domainz5TestAddressAndGroup.test_address_from_username_domain  st    E5%(/U+5)i0Q1r   c                 4   t        dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nr_   r  ra  r   r   r  r  r  s     r   test_address_from_addr_specz/TestAddressAndGroup.test_address_from_addr_spec  sr    EY//U+5)i0Q1r   c                 2   t        d      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nr  r  rn   r   r   r  r  s     r   !test_address_with_no_display_namez5TestAddressAndGroup.test_address_with_no_display_name  sp    i(,U+5)i0Q+r   c                 .   t               }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nrn   rC  r  r  s     r   test_null_addressz%TestAddressAndGroup.test_null_address  sm    I,R(2&d+Q&r   c                 2   t        d      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nbuzzrc  rn   z@buzzr  r  s     r   test_domain_onlyz$TestAddressAndGroup.test_domain_only  sp    6",R(6*g.Q)r   c                 2   t        d      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nr  rb  rn   r  r  s     r   test_username_onlyz&TestAddressAndGroup.test_username_only  sp    V$,V,2&f-Q(r   c                 0   t        d      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nr  rn   rC  zbuzz <>r  r  s     r   test_display_name_onlyz*TestAddressAndGroup.test_display_name_only  so    FO0R(2&d+Q+r   c                 4   t        ddd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )NzSara J.zbad namerN  z"bad name"@example.comz""Sara J." <"bad name"@example.com>r  r  s     r   test_quotingz TestAddressAndGroup.test_quoting  sx     Iz=93Z0=1&>?Q!EFr   c                 4   t        ddd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  t        |      d       y )Nr   woku   exàmple.comu   wok@exàmple.comu   Éric <wok@exàmple.com>r  r  s     r   	test_il8nzTestAddressAndGroup.test_il8n  sv    GUN31U+>2&89Q!;<r   c                    t        d      t        d      t        d      t        d      t        d      t        d      t        d	
      t        d
      t        d
      t        d      t        d      t        d      f}|D ]G  }| j                  |      5  | j                  t        d      5  t	        di | d d d        d d d        I y # 1 sw Y   xY w# 1 sw Y   `xY w)Nzfoo)r`  zfoo
zfoo
zexample.comr  zexample.com
zexample.com
zwokr  zwok
zwok
zwok@example.comr  zwok@example.com
zwok@example.com
)kwargszinvalid argumentsr*   )dictsubTestassertRaisesRegex
ValueErrorr
   )r   casesr  s      r   $test_crlf_in_constructor_args_raisesz8TestAddressAndGroup.test_crlf_in_constructor_args_raises  s    g&g&i((()*'"'")$././01
  	"FV, "d.D.DZQd.e "!&!" " "	"" " " "s$   C 5CC CC  C)	c                 r    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nr_   u   wők@example.comr  r`   r  r
   rg   s    r   +test_non_ascii_username_in_addr_spec_raisesz?TestAddressAndGroup.test_non_ascii_username_in_addr_spec_raises  s0    z* 	9E%78	9 	9 	9r  c                 t    | j                  t              5  t        ddd       d d d        y # 1 sw Y   y xY w)Nr_   r  r  )rb  ra  r`   r   r
   rg   s    r   *test_address_addr_spec_and_username_raisesz>TestAddressAndGroup.test_address_addr_spec_and_username_raises  s5    y) 	AEFi@	A 	A 	A   .7c                 t    | j                  t              5  t        ddd       d d d        y # 1 sw Y   y xY w)Nr_   r  r  )rc  ra  r  rg   s    r   (test_address_addr_spec_and_domain_raisesz<TestAddressAndGroup.test_address_addr_spec_and_domain_raises  s1    y) 	?E&I>	? 	? 	?r  c                 v    | j                  t              5  t        dddd       d d d        y # 1 sw Y   y xY w)Nr_   bongr  r  )rb  rc  ra  r  rg   s    r   5test_address_addr_spec_and_username_and_domain_raiseszITestAddressAndGroup.test_address_addr_spec_and_username_and_domain_raises  s7    y) 	PEF6YO	P 	P 	Ps   /8c                 r    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nr_   zbad name@example.comr  r  rg   s    r   'test_space_in_addr_spec_username_raisesz;TestAddressAndGroup.test_space_in_addr_spec_username_raises  s0    z* 	=E%;<	= 	= 	=r  c                 r    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nr_   zname@ex[]ample.comr  r  rg   s    r   test_bad_addr_sepc_raisesz-TestAddressAndGroup.test_bad_addr_sepc_raises  s0    z* 	;E%9:	; 	; 	;r  c                     t        d      }| j                  |j                  d       | j                  |j                  t	                      | j                  t        |      d       y )Nr_   rh  r   rT   r`  r_  rq   rS   r   gs     r   test_empty_groupz$TestAddressAndGroup.test_empty_group  sI    %L/eg.Q)r   c                     t        dg       }| j                  |j                  d       | j                  |j                  t	                      | j                  t        |      d       y )Nr_   r_  rh  r  r  s     r   test_empty_group_listz)TestAddressAndGroup.test_empty_group_list  sL    %2&/eg.Q)r   c                     t               }| j                  |j                         | j                  |j                  t                      | j                  t        |      d       y )NzNone:;)r   r   r`  rT   r_  rq   rS   r  s     r   test_null_groupz#TestAddressAndGroup.test_null_group  sE    G!..)eg.Q*r   c                    t        ddd      t        ddd      g}t        d|      }| j                  |j                  d       | j                  |j                  t        |             | j                  t        |      d       y )Nbcre  r_   zfoo: b <b@c>, a <b@c>;)r
   r   rT   r`  r_  rq   rS   r   addrsr  s      r   test_group_with_addressesz-TestAddressAndGroup.test_group_with_addresses!  sk    c3'c#)>?%/eEl3Q!9:r   c                    t        ddd      t        ddd      g}t        |      }| j                  |j                         | j	                  |j
                  t        |             | j	                  t        |      d       y )Nr  r  re  r  zNone: b <b@c>, a <b@c>;r
   r   r   r`  rT   r_  rq   rS   r  s      r   )test_group_with_addresses_no_display_namez=TestAddressAndGroup.test_group_with_addresses_no_display_name(  sg    c3'c#)>?E"!..)eEl3Q!:;r   c                     t        ddd      g}t        |      }| j                  |j                         | j	                  |j
                  t        |             | j	                  t        |      d       y )Nr  r  r  zb <b@c>r  r  s      r   +test_group_with_one_address_no_display_namez?TestAddressAndGroup.test_group_with_one_address_no_display_name/  s[    c3'(E"!..)eEl3Q+r   c                     t        d      }| j                  |j                  d       | j                  |j                  t	                      | j                  t        |      d       y )Nzfoo.barz"foo.bar":;r  r  s     r   test_display_name_quotingz-TestAddressAndGroup.test_display_name_quoting6  sJ    )3eg.Q/r   c                     t        d      }| j                  |j                  d       | j                  |j                  t	                      | j                  t        |      d       y )NrH  	foo bar:;r  r  s     r   #test_display_name_blanks_not_quotedz7TestAddressAndGroup.test_display_name_blanks_not_quoted<  sJ    )3eg.Q-r   c                     t        ddd      }t        t        j                        }||d<   | j	                  |d   d       | j	                  |d   j
                  |f       y )Nr_   r   rN  r   Tori  zfoo <bar@example.com>)r
   r   r   rz   rT   r_  )r   re  r   s      r   $test_set_message_header_from_addressz8TestAddressAndGroup.test_set_message_header_from_addressB  sX    E5-06>>*$4"9:4**QD1r   c                     t        d      }t        t        j                        }||d<   | j	                  |d   d       | j	                  |d   j
                  |j
                         y )NrH  r   r  ri  r  )r   r   r   rz   rT   r_  )r   r  r   s      r   "test_set_message_header_from_groupz6TestAddressAndGroup.test_set_message_header_from_groupI  sU    )6>>*$4+.4**AKK8r   c                 n   t        ddd      }| j                  t        ddd      |       | j                  t        ddd      |       | j                  t        ddd      |       | j                  t        ddd      |       | j                  |t	               k(         | j                  |t        k(         y )Nr_   r   rN  r   )r
   rT   assertNotEqualassertFalseobject
assertTruer   r  s     r   test_address_comparisonz+TestAddressAndGroup.test_address_comparisonP  s    E5-0}=qAGE5-@!DGE5-@!DGE5%8!<fh'Y'r   c                 L   t        ddd      }t        d|g      }| j                  t        d|f      |       | j                  t        d|g      |       | j                  t        dg       |       | j	                  |t               k(         | j                  |t        k(         y )Nr_   r   rN  rH  r   )r
   r   rT   r  r  r	  r
  r   )r   re  r  s      r   test_group_comparisonz)TestAddressAndGroup.test_group_comparisonY  s    E5-0)aS!y1$/3E%!-q1E)R0!4fh'Y'r   N)%r.   r/   r0   rd   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r*   r   r   r  r  ~  s    &IEC9622,'*),G="&9A?P=;**+;<,0.29((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y)TestFoldingc                     dD ]U  \  }}| j                  dt        |d            }| j                  |j                  t        j
                        d|z         W y)z1Test the folding and encoding of address headers.)	)zFoo Bar, Francez"Foo Bar, France")zFoo Bar (France)z"Foo Bar (France)")u   Foo Bar, Españaz"Foo =?utf-8?q?Bar=2C_Espa=C3=B1a?=)u   Foo Bar (España)z Foo Bar =?utf-8?b?KEVzcGHDsWEp?=)u   Foo, Bar Españaz"=?utf-8?q?Foo=2C_Bar_Espa=C3=B1a?=)u   Foo, Bar [España]z(=?utf-8?q?Foo=2C_Bar_=5BEspa=C3=B1a=5D?=)u   Foo Bär, Francez"Foo =?utf-8?q?B=C3=A4r=2C?= France)u   Foo Bär <France>z%Foo =?utf-8?q?B=C3=A4r_=3CFrance=3E?=)ur   Lôrem ipsum dôlôr sit amet, cônsectetuer adipiscing. Suspendisse pôtenti. Aliquam nibh. Suspendisse pôtenti.z=?utf-8?q?L=C3=B4rem_ipsum_d=C3=B4l=C3=B4r_sit_amet=2C_c=C3=B4nsectetuer?=
 =?utf-8?q?_adipiscing=2E_Suspendisse_p=C3=B4tenti=2E_Aliquam_nibh=2E?=
 Suspendisse =?utf-8?q?p=C3=B4tenti=2E?=r  za@b.comr  r   zTo: %s <a@b.com>
N)rM   r
   rT   ry   r   rz   )r   rK   resultr   s       r   test_address_display_namesz&TestFolding.test_address_display_namese  s\     	CLD&$   wty'IJAQVV6>>V:$86$AC'	Cr   c                     | j                  dd      }| j                  |j                  t        j                        d       y )Nr>   rR   r   zsubject: this is a test
rM   rT   ry   r   rz   rU   s     r   test_short_unstructuredz#TestFolding.test_short_unstructured}  s7    Y(89v~~64	6r   c                     | j                  dd      }| j                  |j                  t        j                        d       y )Nr!   zhThis is a long header line that will need to be folded into two lines and will demonstrate basic foldingr   zsSubject: This is a long header line that will need to be folded into two lines
 and will demonstrate basic folding
r  rU   s     r   test_long_unstructuredz"TestFolding.test_long_unstructured  sA    Y )1 2 	v~~6@	Ar   c                     | j                  dd      }| j                  |j                  t        j                  j                  d            t        j                  d             y )Nr!   z1this is a short header that will be folded anywayr   r  r   z                Subject: this is a
                 short header that
                 will be folded
                 anyway
                rM   rT   ry   r   rz   r  textwrapdedentrU   s     r   'test_unstructured_short_max_line_lengthz3TestFolding.test_unstructured_short_max_line_length  sX    Y )) *FF&....r.BFCOO  	r   c                     | j                  dd      }| j                  |j                  t        j                        d       y )Nr!   r   r   zSubject: test
r  rU   s     r   "test_fold_unstructured_single_wordz.TestFolding.test_fold_unstructured_single_word  s4    Y/v~~68IJr   c                     | j                  dd      }| j                  |j                  t        j                        d       y )Nr!   ztest test testr   zSubject: test test test
r  rU   s     r   test_fold_unstructured_shortz(TestFolding.test_fold_unstructured_short  s7    Y(89v~~63	5r   c                     | j                  dd      }| j                  |j                  t        j                  j                  d            d       y )Nr!   5thisisaverylonglineconsistingofasinglewordthatwontfitr   r  r   zSubject: 
 =?utf-8?q?thisisa?=
 =?utf-8?q?verylon?=
 =?utf-8?q?glineco?=
 =?utf-8?q?nsistin?=
 =?utf-8?q?gofasin?=
 =?utf-8?q?gleword?=
 =?utf-8?q?thatwon?=
 =?utf-8?q?tfit?=
rM   rT   ry   r   rz   r  rU   s     r   )test_fold_unstructured_with_overlong_wordz5TestFolding.test_fold_unstructured_with_overlong_word  sL    Y )$ %FF&....r.BFC"	r   c                     | j                  dd      }| j                  |j                  t        j                  j                  d            d       y )Nr!   zXthisisaverylonglineconsistingofasinglewordthatwontfit plusanotherverylongwordthatwontfitr   r  r   a  Subject: 
 =?utf-8?q?thisisa?=
 =?utf-8?q?verylon?=
 =?utf-8?q?glineco?=
 =?utf-8?q?nsistin?=
 =?utf-8?q?gofasin?=
 =?utf-8?q?gleword?=
 =?utf-8?q?thatwon?=
 =?utf-8?q?tfit_pl?=
 =?utf-8?q?usanoth?=
 =?utf-8?q?erveryl?=
 =?utf-8?q?ongword?=
 =?utf-8?q?thatwon?=
 =?utf-8?q?tfit?=
r#  rU   s     r   .test_fold_unstructured_with_two_overlong_wordsz:TestFolding.test_fold_unstructured_with_two_overlong_words  sN    Y )G HFF&....r.BFC"	r   c                     | j                  dd      }| j                  |j                  t        j                  j                  d            d       y )Nr!    thislongwordislessthanmaxlinelen#   r  r   z+Subject:
 thislongwordislessthanmaxlinelen
r#  rU   s     r   .test_fold_unstructured_with_slightly_long_wordz:TestFolding.test_fold_unstructured_with_slightly_long_word  sF    Y(JKFF&....r.BFC;	=r   c                     | j                  dd      }| j                  |j                  t        j                  j                  d            t        j                  d             y )Nr!   zThis header is intended to demonstrate, in a fairly succinct way, that we now do not give a , special treatment in unstructured headers.<   r  r   z                Subject: This header is intended to demonstrate, in a fairly
                 succinct way, that we now do not give a , special treatment
                 in unstructured headers.
                 r  rU   s     r   "test_fold_unstructured_with_commasz.TestFolding.test_fold_unstructured_with_commas  s\    Y )F G 	FF&....r.BFCOO  	r   c                     | j                  dd      }| j                  |j                  t        j                        t        j                  d             y )Nr  z"Theodore H. Perfect" <yes@man.com>, "My address is very long because my name is long" <foo@bar.com>, "Only A. Friend" <no@yes.com>r   z            To: "Theodore H. Perfect" <yes@man.com>,
             "My address is very long because my name is long" <foo@bar.com>,
             "Only A. Friend" <no@yes.com>
             )rM   rT   ry   r   rz   r  r  rU   s     r   test_fold_address_listz"TestFolding.test_fold_address_list  sK    T $, - 	v~~6 I 9 	r   c                     | j                  dd      }| j                  |j                  t        j                        d       y )Nr   zSat, 2 Feb 2002 17:00:06 -0800r   z&Date: Sat, 02 Feb 2002 17:00:06 -0800
r  rU   s     r   test_fold_date_headerz!TestFolding.test_fold_date_header  s8    V%EFv~~6A	Cr   c                     | j                  dd      }| j                  |j                  t        j                        d       y )NzX-Report-Abusez]<https://www.mailitapp.com/report_abuse.php?mid=xxx-xxx-xxxxxxxxxxxxxxxxxxxxxxxx==-xxx-xx-xx>r   zX-Report-Abuse: =?utf-8?q?=3Chttps=3A//www=2Emailitapp=2Ecom/report=5Fabuse?=
 =?utf-8?q?=2Ephp=3Fmid=3Dxxx-xxx-xxxxxxxxxxxxxxxxxxxxxxxx=3D=3D-xxx-xx-xx?=
 =?utf-8?q?=3E?=
r  rU   s     r   &test_fold_overlong_words_using_RFC2047z2TestFolding.test_fold_overlong_words_using_RFC2047  sC    BC 	FF&..F)!	"r   c                    | j                  dd      }| j                  |j                  t        j                  j                  d            d       | j                  dd      }| j                  |j                  t        j                  j                  d            d       | j                  dd	      }| j                  |j                  t        j                  j                  d
            d       | j                  dd      }| j                  |j                  t        j                  j                  d            d       y )Nz
Message-IDz+<somemessageidlongerthan@maxlinelength.com>r   r  r   z8Message-ID: <somemessageidlongerthan@maxlinelength.com>
z1<somemessageidlongerthan@[127.0.0.0.0.0.0.0.0.1]>z>Message-ID: <somemessageidlongerthan@[127.0.0.0.0.0.0.0.0.1]>
u   <ईमेल@wők.com>   u$   Message-ID: <ईमेल@wők.com>
u"   <ईमेलfromMessage@wők.com>u0   Message-ID:
 <ईमेलfromMessage@wők.com>
r#  rU   s     r   $test_message_id_header_is_not_foldedz0TestFolding.test_message_id_header_is_not_folded  s&   9; 	FF&....r.BFCG	I
 ?A 	FF&....r.BFCM	O
 \+DEFF&....r.BFC3	5 \+OPFF&....r.BFC@	Br   N)r.   r/   r0   r  r  r  r  r  r   r$  r&  r*  r-  r/  r1  r3  r6  r*   r   r   r  r  c  sM    C06
A
K5
 .=C
"Br   r  __main__)#r   r  unittestemailr   r   email.messager   test.test_emailr   r   r	   email.headerregistryr
   r   email.headerr   test.supportr   r	  r   r   rI   rO   rt   r   r   r  r   r.  rA  r  r  r.   mainr*   r   r   <module>r@     sd        ! 7   / & " 	7K 7Kt)] )"0^ "0\ %^ % %P >6^ >6 >6B tN t tn $. $ $N O^ O Od Z
N Z
 Z
z }C }C }C@
b(- b(JnB. nB` zHMMO r   