
    <e                     |   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  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j                      dS dS )"    N)errorspolicy)Message)TestEmailBaseparameterize)headerregistry)AddressGroup)	ALWAYS_EQc                   l    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dS )TestHeaderRegistryc                     t          j                    } |dd          }|                     |t           j                   |                     |t           j                   d S Nfoobartestr	   HeaderRegistryassertIsInstance
BaseHeaderUnstructuredHeaderselffactoryhs      :/usr/lib/python3.11/test/test_email/test_headerregistry.py test_arbitrary_name_unstructuredz3TestHeaderRegistry.test_arbitrary_name_unstructured   sY     /11GHf%%a!:;;;a!BCCCCC    c                     t          j                    }|                     d|j                    |dd          }|                     |t           j                   |                     |t           j                   d S )NSubjectr   )r	   r   assertNotInregistryr   r   UniqueUnstructuredHeaderr   s      r   test_name_case_ignoredz)TestHeaderRegistry.test_name_case_ignored   sr     /11G$4555GIv&&a!:;;;a!HIIIIIr   c                       e Zd Zd ZdS )TestHeaderRegistry.FooBasec                     d S N )r   argskws      r   __init__z#TestHeaderRegistry.FooBase.__init__!   s    Dr   N)__name__
__module____qualname__r,   r)   r   r   FooBaser&       s#        	 	 	 	 	r   r0   c                     t          j        | j                  } |dd          }|                     || j                   |                     |t           j                   d S )N)
base_classr   r   )r	   r   r0   r   r   r   s      r    test_override_default_base_classz3TestHeaderRegistry.test_override_default_base_class$   s_     /4<HHHGHf%%a...a!BCCCCCr   c                   &    e Zd Zej        j        ZdS )TestHeaderRegistry.FooDefaultN)r-   r.   r/   r	   r   parser)   r   r   
FooDefaultr5   *   s        17r   r7   c                     t          j        | j                  } |dd          }|                     |t           j                   |                     || j                   d S )Ndefault_classr   r   )r	   r   r7   r   r   r   s      r   test_override_default_classz.TestHeaderRegistry.test_override_default_class-   s_     /doNNNGHf%%a!:;;;a11111r   c                     t          j        | j                  } |dd          }|                     |t           j                   |                     |t           j                   d S )Nr9   subjectr   )r	   r   r7   r   r   r#   r   s      r   2test_override_default_class_only_overrides_defaultzETestHeaderRegistry.test_override_default_class_only_overrides_default3   s`     /doNNNGIv&&a!:;;;a!HIIIIIr   c                     t          j        d          } |dd          }|                     |t           j                   |                     |t           j                   d S )NF)use_default_mapr=   r   r   r   s      r   test_dont_use_default_mapz,TestHeaderRegistry.test_dont_use_default_map9   s^     /FFFGIv&&a!:;;;a!BCCCCCr   c                    t          j                    } |dd          }|                    dt           j                    |dd          }|                     |t           j                   |                     |t           j                   |                     |t           j                   |                     |t           j                   d S 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1WXv&&Hn&MNNNWXv&&b.";<<<b."CDDDb.";<<<b."IJJJJJr   N)r-   r.   r/   r   r$   r0   r3   r7   r;   r>   rA   rF   r)   r   r   r   r      s        D D DJ J J       D D D8 8 8 8 8 8 8 82 2 2J J JD D DK K K K Kr   r   c                   2    e Zd Z ej                    Zd ZdS )TestHeaderBasec                 .    |                      ||          S r(   )r   )r   namevalues      r   make_headerzTestHeaderBase.make_headerN   s    ||D%(((r   N)r-   r.   r/   r	   r   r   rL   r)   r   r   rH   rH   J   s3        +n+--G) ) ) ) )r   rH   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	TestBaseHeaderFeaturesc                     |                      dd          }|                     |t                     |                     |d           |                     t          |          d           d S Nr=   this is a test)rL   r   strassertEqualr   r   s     r   test_strzTestBaseHeaderFeatures.test_strT   sh    Y(899a%%%,---Q!122222r   c                 n    |                      dd          }|                     |dd         d           d S )Nr=   rQ         is)rL   rS   rT   s     r   test_substrz"TestBaseHeaderFeatures.test_substrZ   s<    Y(8991Q3&&&&&r   c                 h    |                      dd          }|                     |j        d           d S rP   )rL   rS   rJ   rT   s     r   test_has_namez$TestBaseHeaderFeatures.test_has_name^   s6    Y(899+++++r   c                     |                      dd          }|                     t                    5  t          ||d           d d d            d S # 1 swxY w Y   d S )Nr=   rQ   foo)rL   assertRaisesAttributeErrorsetattr)r   attrr   s      r   _test_attr_roz$TestBaseHeaderFeatures._test_attr_rob   s    Y(899~.. 	$ 	$AtU###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   AAAc                 0    |                      d           d S )NrJ   rc   r   s    r   test_name_read_onlyz*TestBaseHeaderFeatures.test_name_read_onlyg   s    6"""""r   c                 0    |                      d           d S )Ndefectsre   rf   s    r   test_defects_read_onlyz-TestBaseHeaderFeatures.test_defects_read_onlyj   s    9%%%%%r   c                 ~   |                      dd          }|                     t          |j                  d           |                     |j        t
                     |                      dd          }|                     t          |j                  d           |                     |j        t
                     d S )Nr=   rQ   r   date    )rL   rS   lenri   r   tuplerT   s     r   test_defects_is_tuplez,TestBaseHeaderFeatures.test_defects_is_tuplem   s    Y(899QY+++ai///VR((QY+++ai/////r   N)
r-   r.   r/   rU   rZ   r\   rc   rg   rj   rq   r)   r   r   rN   rN   R   s}        3 3 3' ' ', , ,$ $ $
# # #& & &0 0 0 0 0r   rN   c                   2    e Zd Zd Zddg dfddg dfddd	Zd
S )TestUnstructuredHeaderc                 x   t          |          }|dk    r|d         ng }d|rdndz   }||dk    r|d         n|z   dz   }|                     d|          }|                     ||           |                     |j        |           |                     |                    t          j                  |           d S )	Nr   zSubject: rm   rn   
r    r   )ro   rL   rS   assertDefectsEqualri   foldr   default)	r   sourcedecodedr*   lri   headerfoldedr   s	            r   string_as_valuez&TestUnstructuredHeader.string_as_value   s     IIqSS$q''bf4ss"5acc477v6=Y//G$$$	7333v~66?????r   z=?utf-8?q?this_is_a_test?=rQ   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.   r/   r   string_paramsr)   r   r   rs   rs      s\        @ @ @  )	" 086	"8+-"% MMMr   rs   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dS )TestDateHeaderzSun, 23 Sep 2001 20:10:55 -0700i)hoursi  	         
   7   )tzinfoc                 L   |                      d| j                  }|                     || j                   |                     |j        | j                   |                     |j                                        | j                   |                     |j        d           d S Nrl   r)   )rL   
datestringrS   datetimedt	utcoffsetri   rT   s     r   test_parse_datezTestDateHeader.test_parse_date   s    VT_55DO,,,TW-----//@@@B'''''r   c                     |                      d| j                  }|                     || j                   |                     |j        | j                   |                     |j        d           d S r   )rL   r   rS   r   r   ri   rT   s     r   test_set_from_datetimez%TestDateHeader.test_set_from_datetime   si    VTW--DO,,,TW---B'''''r   c                     |                      d| j                  }|                     |t          j                   |                     |j        d           |                     |j        d           d S )Nrl   rn   r)   )rL   r   r   r	   UniqueDateHeaderrS   	max_countri   rT   s     r   test_date_header_propertiesz*TestDateHeader.test_date_header_properties   sh    VT_55a!@AAAa(((B'''''r   c                     |                      d| j                  }|                     |t          j                   |                     |j        d            |                     |j        d           d S )Nzresent-dater)   )rL   r   r   r	   
DateHeaderrS   r   ri   rT   s     r   "test_resent_date_header_propertiesz1TestDateHeader.test_resent_date_header_properties   sh    ]DO<<a!:;;;d+++B'''''r   c                     |                      dd          }|                     t          |j                  d           |                     |j        d         t
          j                   d S )Nrl   rm   rn   r   )rL   rS   ro   ri   r   r   HeaderMissingRequiredValuerT   s     r   test_no_value_is_defectz&TestDateHeader.test_no_value_is_defect   sZ    VR((QY+++ailF,MNNNNNr   c                 <   d}|                      d|          }|                     ||           |                     |j                   |                     t	          |j                  d           |                     |j        d         t          j                   d S )NzNot a date headerrl   rn   r   	rL   rS   assertIsNoner   ro   ri   r   r   InvalidDateDefectr   sr   s      r   test_invalid_date_formatz'TestDateHeader.test_invalid_date_format   s    VQ''A!*%%%QY+++ailF,DEEEEEr   c                 <   d}|                      d|          }|                     ||           |                     |j                   |                     t	          |j                  d           |                     |j        d         t          j                   d S )NzTue, 06 Jun 2017 27:39:33 +0600rl   rn   r   r   r   s      r   test_invalid_date_valuez&TestDateHeader.test_invalid_date_value   s    -VQ''A!*%%%QY+++ailF,DEEEEEr   c                     |                      d| j                  }|                     t                    5  d|_        d d d            d S # 1 swxY w Y   d S )Nrl   r^   )rL   r   r_   r`   r   rT   s     r   test_datetime_read_onlyz&TestDateHeader.test_datetime_read_only   s    VT_55~.. 	 	AJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     t          t          j                  }| j        |d<   |                     |d         | j                   |                     |d         j        | j                   d S )Nr   Date)r   r   ry   r   rS   r   r   )r   ms     r   "test_set_date_header_from_datetimez1TestDateHeader.test_set_date_header_from_datetime   s`    6>***G&	6DO4446+TW55555r   N)r-   r.   r/   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 O O
F F FF F F  
6 6 6 6 6r   r   c                      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[                    d\                              dd]          d^d_d`dadbdcej        gd7z  dddefdfdgdBdCdDdRdhig difdjdkdBdCdDd`dlig dmfdndo                    d\                              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	dS )TestContentTypeHeaderc                     t          |          }|dk    r|d         ni }|dk    r|d         ng }|dk    r|d         t          ur|d         n|}	|rdnd}
|dk    r|d         n|
|	z   dz   }|                     d|          }|                     |j        |           |                     |j        |           |                     |j        |           |                     |j        |           |                     t                    5  d	|j        d
<   d d d            n# 1 swxY w Y   | 
                    |j        |           |                     ||	           |                     |                    t          j                  |           d S )Nr   rn      zContent-Type: rm      rv   zContent-Typexyzabcr   )ro   DITTOrL   rS   content_typemaintypesubtypeparamsr_   	TypeErrorrw   ri   rx   r   ry   )r   rz   r   r   r   r*   r|   parmdictri   r{   r}   r~   r   s                r   content_type_as_valuez+TestContentTypeHeader.content_type_as_value   s    IIcc477rcc477rccd1gU&:&:477*08&&baCCaVg%5%<^V44666X...G,,,8,,,y)) 	$ 	$#AHUO	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$	7333G$$$v~66?????s   DD"%D"
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; boorm   )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)rJ   
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)rJ   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"rJ   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.   r/   r   r   InvalidHeaderDefectencodedecodeUndecodableBytesDefectcontent_type_paramsr)   r   r   r   r      s       @ @ @.[ 	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0
8I2K 2K|44*+A-4,! _[J 	*6Z ),+K[\ 	&=$%1(3][n 	"#VI..vvj5F0H 0H"-CDD+,H>$o[L	 	"=
#,$.M	[`	 	++ 67@-a	[|	 	-+ @A'(*J/}	[V
 	4( "-QR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                   H    e Zd Zd Zdddej        gddfddej        gfdZdS )	TestContentTransferEncodingc                    t          |          }|dk    r|d         ng }|dk    r|d         t          ur|d         n|}|rdnd}|dk    r|d         n||z   dz   }|                     d|          }	|                     |	j        |           |                     |	j        |           |                     |	|           |                     |	                    t          j	                  |           d S )	Nr   rn   zContent-Transfer-Encoding: rm   r   rv   zContent-Transfer-Encodingr   )
ro   r   rL   rS   cterw   ri   rx   r   ry   )
r   rz   r  r*   r|   ri   r{   r}   r~   r   s
             r   cte_as_valuez(TestContentTransferEncoding.cte_as_value&  s     IIcc477rccd1gU&:&:4777=E332aCCaVf_t%;8&AA$$$	7333G$$$v~66?????r   )base64r  rm   7bitzContent-Transfer-Encoding:
z7bit and a bunch more)
RFC_2183_1no_valuejunk_after_cteN)r-   r.   r/   r  r   r   r  
cte_paramsr)   r   r   r  r  #  sc        @ @ @"
 ./* $'(* JJJr   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dS )TestContentDispositionc                 <   t          |          }|dk    r|d         ni }|dk    r|d         ng }|dk    r|d         t          ur|d         n|}|rdnd}|dk    r|d         n||z   dz   }	|                     d|          }
|                     |
j        |           |                     |
j        |           |                     |
j        |           |                     |
|           |                     |
                    t          j
        	          |	           d S )
Nr   rn   r   zContent-Disposition: rm   r   rv   zContent-Dispositionr   )ro   r   rL   rS   content_dispositionr   rw   ri   rx   r   ry   )r   rz   r!  r*   r|   r   ri   r{   r}   r~   r   s              r   content_disp_as_valuez,TestContentDisposition.content_disp_as_valueN  s,    IIcc477rcc477rccd1gU&:&:47717?--RaCCaVf_t%;2F;;.0CDDD8,,,	7333G$$$v~6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"
rm   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.   r/   r"  r   r   r  content_disp_paramsr)   r   r   r  r  K  s       @ @ @*
F&"CE 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dS )TestMIMEVersionHeaderc                    |                      d|          }|                     ||           |                     |j        |           |                     |j        |           |                     |j        |           |                     |j        |           |rd|z   }|                     |                    t          j	                  d|z   dz              d S )NzMIME-Versionru   r   zMIME-Version:rv   )
rL   rS   versionmajorminorrw   ri   rx   r   ry   )r   rz   r{   r/  r0  r1  ri   r   s           r   version_string_as_MIME_Versionz4TestMIMEVersionHeader.version_string_as_MIME_Version  s     ^V44G$$$G,,,%(((%(((	7333 	"6\Fv~66(61D8	: 	: 	: 	: 	:r   z1.0rn   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^   rm   )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.   r/   r2  r   r  r   version_string_paramsr)   r   r   r-  r-    s       : : :.  .- .- -,    0 '(&* '('* '('* '(* '(* '(* ./1}F
 F
r   r-  c                      e Zd Zdej        gddddddfdg ddddddfdg ddddddfd	g d	dd
dddfdg ddddddfdg ddddddfdej        gddddddfdej        gdz  ddddddfdg ddddddfd ej        gd!z  d"dd"d#ddfd$ej        gd%z  d&dd&d'ddfd(ej        gd)dd)d*ddfd+g d,d-d.d/ddfd0g d1d2d.d/ddfd3ej        ej        gd,d-d.d/ddfd4Zd5 Zd6 Zd7 Z	d8 Z
d9 Zd: Zd; Zd< Zd= Zd> Zd? Zd@ ZdA ZdS )BTestAddressHeader<>rm   Nzzippy@pinhead.comzippyzpinhead.comz%Zaphrod Beblebrux <zippy@pinhead.com>zZaphrod Beblebruxz)Zaphrod Beblebrux <"foo bar"@pinhead.com>z"foo bar"@pinhead.comfoo barz'"A \(Special\) Person" <person@dom.ain>z%"A (Special) Person" <person@dom.ain>zA (Special) Personzperson@dom.ainpersonzdom.ainz."Arthur \\Backslash\\ Foobar" <person@dom.ain>zArthur \Backslash\ FoobarzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>zJohn X. Doezjxd@example.comjxdexample.comz""example" example"@example.comr   z"example example"@example.comzexample examplez!"\"example\" example"@example.comz"example" examplez#"\\"example\\" example"@example.comrW   z#"\\example\\\\ example"@example.comz\example\\ examplezmerwok  wok  @example.comr   z"merwok wok"@example.comz
merwok wokzmerwok. wok .  wok@example.comzmerwok.wok.wok@example.comzmerwok.wok.wokz'=?utf-8?q?=C3=89ric?= <foo@example.com>u   Éric <foo@example.com>r   foo@example.comr^   z6The =?utf-8?q?=C3=89ric=2C?= Himself <foo@example.com>u&   "The Éric, Himself" <foo@example.com>r   z)"=?utf-8?q?=C3=89ric?=" <foo@example.com>)emptyaddress_onlyname_and_addressquoted_local_partquoted_parens_in_namequoted_backslashes_in_namename_with_dotquoted_strings_in_local_part$escaped_quoted_strings_in_local_partescaped_escapes_in_local_part'spaces_in_unquoted_local_part_collapsed(spaces_around_dots_in_local_part_removedrfc2047_atom_is_decoded!rfc2047_atom_in_phrase_is_decoded(rfc2047_atom_in_quoted_string_is_decodedc	                    |                      d|          }	|                     |	|           |                     |	j        |           |	j        }
|                     t          |
          |           |                     t          |	j                  d           |                     |
gt          |	j        d         j	                             |                     |
gt          |	j	                             |                     |
j
        |           |                     |
j        |           |                     |
j        |           |                     |
j        |           d S )Nsenderrn   r   )rL   rS   rw   ri   addressrR   ro   groupslist	addressesdisplay_name	addr_specusernamedomain)r   rz   ri   r{   r]  r^  r_  r`  commentr   as              r   example_as_addressz$TestAddressHeader.example_as_address  s7   Xv..G$$$	7333IQ)))QX***!d18A;#899:::!d1;//000666i000X...6*****r   c	                    d                     |          }|rd                     |          nd}	|                     d|          }
|                     |
|	           |                     |
j        |           |                     |
j        d         j        |
j                   |                     t          |
j                  d           |                     t          |
j                  d           |
j        d         }|                     t          |          |           |                     |j	        |           |                     |j
        |           |                     |j        |           |                     |j        |           d S )Nzfoo: {};foo:;tor   rn   )formatrL   rS   rw   ri   rZ  r\  ro   rR   r]  r^  r_  r`  )r   rz   ri   r{   r]  r^  r_  r`  ra  gdecodedr   rb  s               r   example_as_groupz"TestAddressHeader.example_as_group  sa   ""6**18E:$$W---gT6**H%%%	7333!.<<<QX***Q[))1---KNQ)))666i000X...6*****r   c                    d}|                      d|          }|                     ||           |                     t          |j                  d           |                     t          |j                  d           t          d          D ]9}|                     |j        |         j        d         |j        |                    :|                     t          |j        d                   d           |                     t          |j        d                   d           |                     t          |j        d                   d	           |                     |j        d         j        d
           d S )NzTFred <dinsdale@python.org>, foo@example.com, "Harry W. Hastings" <hasty@example.com>rf  r   r   zFred <dinsdale@python.org>rn   rG  r   z'"Harry W. Hastings" <hasty@example.com>zHarry W. Hastings)rL   rS   ro   rZ  r\  rangerR   r]  )r   rK   r   is       r   test_simple_address_listz*TestAddressHeader.test_simple_address_list   s[   >T5))E"""QX***Q[))1---q 	G 	GAQXa[215q{1~FFFFQ[^,,.JKKKQ[^,,.?@@@Q[^,,5	7 	7 	7Q4	! 	! 	! 	! 	!r   c                 2   t          | j                                                  }dd                    d |d d         D                       z   dz   dz   d                    d |dd         D                       z   dz   d                    d	 |dd          D                       z   }d
d                    d |d d         D                       z   dz   dz   d                    d |dd         D                       z   dz   d                    d |dd          D                       z   }|                     d|          }|                     |                    d          |                    d                     |                     ||           |                     t          |j                  dt          |          z   dz
             |                     |j        d         j	        d           |                     |j        d         j	        d           |                     |j        d         j	        d           |                     t          |j
                  t          |                     t          d          D ]r}|                     |j        |dz            j	                   |                     t          |j        |dz            j
        d                   ||         d                    st          ddt          |          z   dz
            D ]o}|                     |j        |         j	                   |                     t          |j        |         j
        d                   ||dz
           d                    pt          t          |                    D ]n}|                     t          |j
        |                   ||         d                    |                     |j
        |         j        ||         d                    od S )Nz dummy list:;, another: (empty);,z, c                     g | ]
}|d          S r   r)   .0xs     r   
<listcomp>z?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>      777QAaD777r      z"A \"list\"": c                     g | ]
}|d          S rp  r)   rq  s     r   rt  z?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>      ;;;qt;;;r      z;,c                     g | ]
}|d          S rp  r)   rq  s     r   rt  z?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>  ru  r   zdummy list:;, another:;, c                     g | ]
}|d          S r   r)   rq  s     r   rt  z?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>  ru  r   c                     g | ]
}|d          S r|  r)   rq  s     r   rt  z?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>  rx  r   z;, c                     g | ]
}|d          S r|  r)   rq  s     r   rt  z?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>  ru  r   rf  ,rX   r   z
dummy listrn   anotherzA "list"r   )r[  example_paramsvaluesjoinrL   rS   splitro   rZ  r]  r\  rk  r   rR   r^  )r   examplesrz   expectedr   rl  s         r   test_complex_address_listz+TestAddressHeader.test_complex_address_list  s   +224455477(2A2,777889;?@"# II;;Xac];;;<<= @DD 77(122,77788	9 077(2A2,777889;?@"# II;;Xac];;;<<= @EE 77(122,77788	9 T6**x~~c':':;;;H%%%QXCMM(9A(=>>>!1<@@@!19===!1:>>>Q[))3x==999q 	N 	NAahqsm8999S!A#!8!;<<hqk!nMMMMq!c(mm+a/00 	N 	NAahqk6777S!!6q!9::HQqSM!<LMMMMs8}}%% 	G 	GASQ00(1+a.AAAQ[^5x{1~FFFF	G 	Gr   c                     |                      dd          }|                     t                    5  d|_        d d d            d S # 1 swxY w Y   d S NrX  zabc@xyz.comr^   )rL   r_   r`   rY  rT   s     r   test_address_read_onlyz(TestAddressHeader.test_address_read_only3  s    X}55~.. 	 	AI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AA
A
c                     |                      dd          }|                     t                    5  d|_        d d d            d S # 1 swxY w Y   d S r  )rL   r_   r`   r\  rT   s     r   test_addresses_read_onlyz*TestAddressHeader.test_addresses_read_only8  s    X}55~.. 	  	 AK	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 r  c                     |                      dd          }|                     t                    5  d|_        d d d            d S # 1 swxY w Y   d S r  )rL   r_   r`   rZ  rT   s     r   test_groups_read_onlyz'TestAddressHeader.test_groups_read_only=  s    X}55~.. 	 	AH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  c                     d}|                      d|          }|                     |j        t                     |                     |j        d         t                     d S Nzme <who@example.com>rf  r   )rL   r   r\  rp   r
   r   rz   r   s      r   test_addresses_typesz&TestAddressHeader.test_addresses_typesB  sV    'T6**ak5111ak!ng66666r   c                     d}|                      d|          }|                     |j        t                     |                     |j        d         t                     d S r  )rL   r   rZ  rp   r   r  s      r   test_groups_typesz#TestAddressHeader.test_groups_typesH  sV    'T6**ah...ahqk511111r   c                 |    |                      dt          ddd                    }|                     |d           d S )Nrf  mer^   rF  zme <foo@example.com>rL   r
   rS   rT   s     r   test_set_from_Addressz'TestAddressHeader.test_set_from_AddressN  s@    T74#F#FGG233333r   c           	          |                      dt          ddd          t          ddd          g          }|                     |d           d S )Nrf  r  r^   rF  your   z+me <foo@example.com>, you <bar@example.com>r  rT   s     r   test_set_from_Address_listz,TestAddressHeader.test_set_from_Address_listR  s[    TGD%$G$G$+E5-$H$H$J K KIJJJJJr   c                    |                      dt          ddd          t          dt          ddd          t          d	d
d          g          t          ddd          g          }|                     |d           |                     |                    t
          j                            d                    d           d S )Nrf  r  r^   rF  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>
)rL   r
   r   rS   rx   r   ry   clonerT   s     r   $test_set_from_Address_and_Group_listz6TestAddressHeader.test_set_from_Address_and_Group_listW  s    TGD%$G$G$)&75#w3O3O3:5#w3O3O3Q %R %R$+E5-$H$H$J K K 	 D 	E 	E 	Ev~';';B';'O'OPP3	4 	4 	4 	4 	4r   c                     |                      dt          dt          ddd          t          ddd          g          g          }|                     |d	           d S )
Nrf  r  r  r  r  r  r  r  z#bing: fiz <z@b.com>, zif <f@c.com>;)rL   r   r
   rS   rT   s     r   test_set_from_Group_listz*TestAddressHeader.test_set_from_Group_listc  sq    TE&75#w3O3O3:5#w3O3O3Q %R %R $S T TABBBBBr   )r-   r.   r/   r   r  ObsoleteHeaderDefectr  rc  ri  rm  r  r  r  r  r  r  r  r  r  r  r)   r   r   r@  r@  <  s        () !   54   98 $ 84! ?>) -)*. /()!+,, 211! 4()!+33" )()!+'' .)*)) 7% F4  9'&(%_Y
 Y
N~+ + +"+ + +"! ! ! !G !G !GF  
     
  
7 7 72 2 24 4 4K K K

4 
4 
4C C C C 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#S )$TestAddressAndGroupc                     |                      t                    5  t          ||d           d d d            d S # 1 swxY w Y   d S )Nr^   )r_   r`   ra   )r   objrb   s      r   rc   z!TestAddressAndGroup._test_attr_rok  s    ~.. 	& 	&Cu%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   :>>c                 P    |                      t          ddd          d           d S )Nr^   r   r   r]  rc   r
   rf   s    r   test_address_display_name_roz0TestAddressAndGroup.test_address_display_name_roo  s*    75%77HHHHHr   c                 P    |                      t          ddd          d           d S )Nr^   r   r   r_  r  rf   s    r   test_address_username_roz,TestAddressAndGroup.test_address_username_ror  s*    75%77DDDDDr   c                 P    |                      t          ddd          d           d S )Nr^   r   r   r`  r  rf   s    r   test_address_domain_roz*TestAddressAndGroup.test_address_domain_rou  s*    75%77BBBBBr   c                 L    |                      t          d          d           d S )Nr^   r]  rc   r   rf   s    r   test_group_display_name_roz.TestAddressAndGroup.test_group_display_name_rox  s$    5<<88888r   c                 L    |                      t          d          d           d S )Nr^   r\  r  rf   s    r   test_group_addresses_roz+TestAddressAndGroup.test_group_addresses_ro{  s$    5<<55555r   c                 F   t          ddd          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nr^   r   r   bar@bazfoo <bar@baz>r
   rS   r]  r_  r`  r^  rR   r   rb  s     r   !test_address_from_username_domainz5TestAddressAndGroup.test_address_from_username_domain~  s    E5%((///U+++5)))i000Q11111r   c                 F   t          dd          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nr^   r  r^  r   r   r  r  r  s     r   test_address_from_addr_specz/TestAddressAndGroup.test_address_from_addr_spec  s    EY//////U+++5)))i000Q11111r   c                 D   t          d          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nr  r  rm   r   r   r  r  s     r   !test_address_with_no_display_namez5TestAddressAndGroup.test_address_with_no_display_name  s    i(((,,,U+++5)))i000Q+++++r   c                 @   t                      }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nrm   rA  r  r  s     r   test_null_addressz%TestAddressAndGroup.test_null_address  s    II,,,R(((2&&&d+++Q&&&&&r   c                 D   t          d          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nbuzzr`  rm   z@buzzr  r  s     r   test_domain_onlyz$TestAddressAndGroup.test_domain_only  s    6""",,,R(((6***g...Q)))))r   c                 D   t          d          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nr  r_  rm   r  r  s     r   test_username_onlyz&TestAddressAndGroup.test_username_only  s    V$$$,,,V,,,2&&&f---Q(((((r   c                 B   t          d          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nr  rm   rA  zbuzz <>r  r  s     r   test_display_name_onlyz*TestAddressAndGroup.test_display_name_only  s    FOO000R(((2&&&d+++Q+++++r   c                 F   t          ddd          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )NzSara J.zbad namerF  z"bad name"@example.comz""Sara J." <"bad name"@example.com>r  r  s     r   test_quotingz TestAddressAndGroup.test_quoting  s     Iz=99333Z000=111&>???Q!EFFFFFr   c                 F   t          ddd          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           d S )Nr   woku   exàmple.comu   wok@exàmple.comu   Éric <wok@exàmple.com>r  r  s     r   	test_il8nzTestAddressAndGroup.test_il8n  s    GUN33111U+++>222&8999Q!;<<<<<r   c                 V   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 ]o}|                     |          5  |                     t          d          5  t	          di | d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   pd S )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11
  	" 	"FV,, " "d.D.DZQd.e.e " "!!&!!!" " " " " " " " " " " " " " " " " " " " " " " " " " " " " "	" 	"s6   D-D:DD

DD
DD!	$D!	c                     |                      t                    5  t          dd           d d d            d S # 1 swxY w Y   d S )Nr^   u   wők@example.comr  r_   r  r
   rf   s    r   +test_non_ascii_username_in_addr_spec_raisesz?TestAddressAndGroup.test_non_ascii_username_in_addr_spec_raises  s    z** 	9 	9E%78888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9r  c                     |                      t                    5  t          ddd           d d d            d S # 1 swxY w Y   d S )Nr^   r  r  )r_  r^  r_   r   r
   rf   s    r   *test_address_addr_spec_and_username_raisesz>TestAddressAndGroup.test_address_addr_spec_and_username_raises  s    y)) 	A 	AEFi@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A   ;??c                     |                      t                    5  t          ddd           d d d            d S # 1 swxY w Y   d S )Nr^   r  r  )r`  r^  r  rf   s    r   (test_address_addr_spec_and_domain_raisesz<TestAddressAndGroup.test_address_addr_spec_and_domain_raises  s    y)) 	? 	?E&I>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?r  c                     |                      t                    5  t          dddd           d d d            d S # 1 swxY w Y   d S )Nr^   bongr  r  )r_  r`  r^  r  rf   s    r   5test_address_addr_spec_and_username_and_domain_raiseszITestAddressAndGroup.test_address_addr_spec_and_username_and_domain_raises  s    y)) 	P 	PEF6YOOOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps   <A A c                     |                      t                    5  t          dd           d d d            d S # 1 swxY w Y   d S )Nr^   zbad name@example.comr  r  rf   s    r   'test_space_in_addr_spec_username_raisesz;TestAddressAndGroup.test_space_in_addr_spec_username_raises  s    z** 	= 	=E%;<<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=r  c                     |                      t                    5  t          dd           d d d            d S # 1 swxY w Y   d S )Nr^   zname@ex[]ample.comr  r  rf   s    r   test_bad_addr_sepc_raisesz-TestAddressAndGroup.test_bad_addr_sepc_raises  s    z** 	; 	;E%9::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;r  c                     t          d          }|                     |j        d           |                     |j        t	                                 |                     t          |          d           d S )Nr^   re  r   rS   r]  r\  rp   rR   r   gs     r   test_empty_groupz$TestAddressAndGroup.test_empty_group  sc    %LL///egg...Q)))))r   c                     t          dg           }|                     |j        d           |                     |j        t	                                 |                     t          |          d           d S )Nr^   r\  re  r  r  s     r   test_empty_group_listz)TestAddressAndGroup.test_empty_group_list   sj    %2&&&///egg...Q)))))r   c                     t                      }|                     |j                   |                     |j        t                                 |                     t          |          d           d S )NzNone:;)r   r   r]  rS   r\  rp   rR   r  s     r   test_null_groupz#TestAddressAndGroup.test_null_group  s_    GG!.)))egg...Q*****r   c                 6   t          ddd          t          ddd          g}t          d|          }|                     |j        d           |                     |j        t          |                     |                     t          |          d           d S )Nbcrb  r^   zfoo: b <b@c>, a <b@c>;)r
   r   rS   r]  r\  rp   rR   r   addrsr  s      r   test_group_with_addressesz-TestAddressAndGroup.test_group_with_addresses  s    c3''c#)>)>?%///eEll333Q!9:::::r   c                 4   t          ddd          t          ddd          g}t          |          }|                     |j                   |                     |j        t          |                     |                     t          |          d           d S )Nr  r  rb  r  zNone: b <b@c>, a <b@c>;r
   r   r   r]  rS   r\  rp   rR   r  s      r   )test_group_with_addresses_no_display_namez=TestAddressAndGroup.test_group_with_addresses_no_display_name  s    c3''c#)>)>?E"""!.)))eEll333Q!:;;;;;r   c                    t          ddd          g}t          |          }|                     |j                   |                     |j        t          |                     |                     t          |          d           d S )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"""!.)))eEll333Q+++++r   c                     t          d          }|                     |j        d           |                     |j        t	                                 |                     t          |          d           d S )Nzfoo.barz"foo.bar":;r  r  s     r   test_display_name_quotingz-TestAddressAndGroup.test_display_name_quoting!  se    )333egg...Q/////r   c                     t          d          }|                     |j        d           |                     |j        t	                                 |                     t          |          d           d S )NrC  	foo bar:;r  r  s     r   #test_display_name_blanks_not_quotedz7TestAddressAndGroup.test_display_name_blanks_not_quoted'  se    )333egg...Q-----r   c                     t          ddd          }t          t          j                  }||d<   |                     |d         d           |                     |d         j        |f           d S )Nr^   r   rF  r   Torf  zfoo <bar@example.com>)r
   r   r   ry   rS   r\  )r   rb  r   s      r   $test_set_message_header_from_addressz8TestAddressAndGroup.test_set_message_header_from_address-  sn    E5-006>***$4"9:::4*QD11111r   c                     t          d          }t          t          j                  }||d<   |                     |d         d           |                     |d         j        |j                   d S )NrC  r   r  rf  r	  )r   r   r   ry   rS   r\  )r   r  r   s      r   "test_set_message_header_from_groupz6TestAddressAndGroup.test_set_message_header_from_group4  si    )6>***$4+...4*AK88888r   c                    t          ddd          }|                     t          ddd          |           |                     t          ddd          |           |                     t          ddd          |           |                     t          ddd          |           |                     |t	                      k               |                     |t          k               d S )Nr^   r   rF  r   )r
   rS   assertNotEqualassertFalseobject
assertTruer   r  s     r   test_address_comparisonz+TestAddressAndGroup.test_address_comparison;  s    E5-00}==qAAAGE5-@@!DDDGE5-@@!DDDGE5%88!<<<fhh'''Y'''''r   c                    t          ddd          }t          d|g          }|                     t          d|f          |           |                     t          d|g          |           |                     t          dg           |           |                     |t                      k               |                     |t          k               d S )Nr^   r   rF  rC  r   )r
   r   rS   r  r  r  r  r   )r   rb  r  s      r   test_group_comparisonz)TestAddressAndGroup.test_group_comparisonD  s    E5-00)aS!!y1$//333E%!--q111E)R00!444fhh'''Y'''''r   N)%r-   r.   r/   rc   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r
  r  r  r  r  r)   r   r   r  r  i  s$       & & &I I IE E EC C C9 9 96 6 62 2 22 2 2, , ,' ' '* * *) ) ), , ,G G G= = =" " "&9 9 9A A A? ? ?P P P= = =; ; ;* * ** * *+ + +; ; ;< < <, , ,0 0 0. . .2 2 29 9 9( ( (( ( ( ( (r   r  c                   b    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S )TestFoldingc                     dD ]a\  }}|                      dt          |d                    }|                     |                    t          j                  d|z             bdS )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)rL   r
   rS   rx   r   ry   )r   rJ   resultr   s       r   test_address_display_namesz&TestFolding.test_address_display_namesP  s     	C 	CLD&$   wty'I'I'IJJAQVV6>V::$86$AC C C C'	C 	Cr   c                     |                      dd          }|                     |                    t          j                  d           d S )Nr=   rQ   r   zsubject: this is a test
rL   rS   rx   r   ry   rT   s     r   test_short_unstructuredz#TestFolding.test_short_unstructuredh  sO    Y(899v~664	6 	6 	6 	6 	6r   c                     |                      dd          }|                     |                    t          j                  d           d S )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  rT   s     r   test_long_unstructuredz"TestFolding.test_long_unstructuredm  s_    Y )1 2 2 	v~66@	A 	A 	A 	A 	Ar   c                     |                      dd          }|                     |                    t          j                            d                    t          j        d                     d S )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
                rL   rS   rx   r   ry   r  textwrapdedentrT   s     r   'test_unstructured_short_max_line_lengthz3TestFolding.test_unstructured_short_max_line_lengthv  sx    Y )) * *FF&...r.BBFCCO   	 	 	 	 	r   c                     |                      dd          }|                     |                    t          j                  d           d S )Nr    r   r   zSubject: test
r  rT   s     r   "test_fold_unstructured_single_wordz.TestFolding.test_fold_unstructured_single_word  sD    Y//v~668IJJJJJr   c                     |                      dd          }|                     |                    t          j                  d           d S )Nr    ztest test testr   zSubject: test test test
r  rT   s     r   test_fold_unstructured_shortz(TestFolding.test_fold_unstructured_short  sO    Y(899v~663	5 	5 	5 	5 	5r   c                     |                      dd          }|                     |                    t          j                            d                    d           d S )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?=
rL   rS   rx   r   ry   r  rT   s     r   )test_fold_unstructured_with_overlong_wordz5TestFolding.test_fold_unstructured_with_overlong_word  si    Y )$ % %FF&...r.BBFCC"	 	 	 	 	r   c                     |                      dd          }|                     |                    t          j                            d                    d           d S )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-  rT   s     r   .test_fold_unstructured_with_two_overlong_wordsz:TestFolding.test_fold_unstructured_with_two_overlong_words  sl    Y )G H HFF&...r.BBFCC"	 	 	 	 	r   c                     |                      dd          }|                     |                    t          j                            d                    d           d S )Nr     thislongwordislessthanmaxlinelen#   r  r   z+Subject:
 thislongwordislessthanmaxlinelen
r-  rT   s     r   .test_fold_unstructured_with_slightly_long_wordz:TestFolding.test_fold_unstructured_with_slightly_long_word  sa    Y(JKKFF&...r.BBFCC;	= 	= 	= 	= 	=r   c                     |                      dd          }|                     |                    t          j                            d                    t          j        d                     d S )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#  rT   s     r   "test_fold_unstructured_with_commasz.TestFolding.test_fold_unstructured_with_commas  s}    Y )F G G 	FF&...r.BBFCCO   	 	 	 	 	r   c                     |                      dd          }|                     |                    t          j                  t          j        d                     d S )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>
             )rL   rS   rx   r   ry   r$  r%  rT   s     r   test_fold_address_listz"TestFolding.test_fold_address_list  sh    T $, - - 	v~66 I 9 9 	 	 	 	 	r   c                     |                      dd          }|                     |                    t          j                  d           d S )Nr   zSat, 2 Feb 2002 17:00:06 -0800r   z&Date: Sat, 02 Feb 2002 17:00:06 -0800
r  rT   s     r   test_fold_date_headerz!TestFolding.test_fold_date_header  sT    V%EFFv~66A	C 	C 	C 	C 	Cr   c                     |                      dd          }|                     |                    t          j                  d           d S )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  rT   s     r   &test_fold_overlong_words_using_RFC2047z2TestFolding.test_fold_overlong_words_using_RFC2047  s^    BC C 	FF&.F))!	" 	" 	" 	" 	"r   c                    |                      dd          }|                     |                    t          j                            d                    d           |                      dd          }|                     |                    t          j                            d                    d           |                      dd	          }|                     |                    t          j                            d
                    d           |                      dd          }|                     |                    t          j                            d                    d           d S )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-  rT   s     r   $test_message_id_header_is_not_foldedz0TestFolding.test_message_id_header_is_not_folded  s   9; ; 	FF&...r.BBFCCG	I 	I 	I
 ?A A 	FF&...r.BBFCCM	O 	O 	O
 \+DEEFF&...r.BBFCC3	5 	5 	5 \+OPPFF&...r.BBFCC@	B 	B 	B 	B 	Br   N)r-   r.   r/   r  r  r!  r&  r(  r*  r.  r0  r4  r7  r9  r;  r=  r@  r)   r   r   r  r  N  s        C C C06 6 6
A A A
 
 
K K K5 5 5
     .= = =    C C C
" " "B B B B Br   r  __main__)!r   r$  unittestemailr   r   email.messager   test.test_emailr   r   r	   email.headerregistryr
   r   test.supportr   r  r   r   rH   rN   rs   r   r   r  r  r-  r@  r  r  r-   mainr)   r   r   <module>rI     s|                  ! ! ! ! ! ! 7 7 7 7 7 7 7 7             / / / / / / / / " " " " " " 	7K 7K 7K 7K 7K 7K 7K 7Kt) ) ) ) )] ) ) )"0 "0 "0 "0 "0^ "0 "0 "0\ % % % % %^ % % %P >6 >6 >6 >6 >6^ >6 >6 >6B t t t t tN t t tn $ $ $ $ $. $ $ $N O O O O O^ O O Od Z
 Z
 Z
 Z
 Z
N Z
 Z
 Z
z iC iC iC iC iC iC iC iCX	b( b( b( b( b(- b( b( b(JnB nB nB nB nB. nB nB nB` zHMOOOOO r   