Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/test_email/__pycache__/test_headerregistry.cpython-38.pyc

U

i�f���@s`ddlZddlZddlZddlmZddlmZddlmZddlm	Z	m
Z
ddlmZddlm
Z
mZe�ZGdd	�d	e	�ZGd
d�de	�ZGdd
�d
e�Ze
Gdd�de��Ze
Gdd�de��Ze
Gdd�de��Ze
Gdd�de��Ze
Gdd�de��Ze
Gdd�de��Ze
Gdd�de��ZGdd�de	�ZGdd�de�Zed k�r\e��dS)!�N)�errors��policy)�Message)�
TestEmailBase�parameterize)�headerregistry)�Address�Groupc@s`eZdZdd�Zdd�ZGdd�d�Zdd�ZGd	d
�d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestHeaderRegistrycCs2t��}|dd�}|�|tj�|�|tj�dS�N�foobar�test�r�HeaderRegistry�assertIsInstance�
BaseHeader�UnstructuredHeader��self�factory�h�r�H/opt/alt/python38/lib64/python3.8/test/test_email/test_headerregistry.py� test_arbitrary_name_unstructureds
z3TestHeaderRegistry.test_arbitrary_name_unstructuredcCs@t��}|�d|j�|dd�}|�|tj�|�|tj�dS)N�Subjectr)rrZassertNotIn�registryrr�UniqueUnstructuredHeaderrrrr�test_name_case_ignoreds

z)TestHeaderRegistry.test_name_case_ignoredc@seZdZdd�ZdS)zTestHeaderRegistry.FooBasecOsdS�Nr)r�args�kwrrr�__init__ sz#TestHeaderRegistry.FooBase.__init__N)�__name__�
__module__�__qualname__r"rrrr�FooBasesr&cCs8tj|jd�}|dd�}|�||j�|�|tj�dS)N)Z
base_classr
r)rrr&rrrrrr� test_override_default_base_class#s
z3TestHeaderRegistry.test_override_default_base_classc@seZdZejjZdS)zTestHeaderRegistry.FooDefaultN)r#r$r%rr�parserrrr�
FooDefault)sr)cCs8tj|jd�}|dd�}|�|tj�|�||j�dS)N�Z
default_classr
r)rrr)rrrrrr�test_override_default_class,s
z.TestHeaderRegistry.test_override_default_classcCs8tj|jd�}|dd�}|�|tj�|�|tj�dS)Nr*�subjectr)rrr)rrrrrrr�2test_override_default_class_only_overrides_default2s
zETestHeaderRegistry.test_override_default_class_only_overrides_defaultcCs6tjdd�}|dd�}|�|tj�|�|tj�dS)NF)Zuse_default_mapr,rrrrrr�test_dont_use_default_map8s
z,TestHeaderRegistry.test_dont_use_default_mapcCsft��}|dd�}|�dtj�|dd�}|�|tj�|�|tj�|�|tj�|�|tj�dSr)rrZmap_to_typerrrr)rrZh1Zh2rrr�test_map_to_type>s

z#TestHeaderRegistry.test_map_to_typeN)r#r$r%rrr&r'r)r+r-r.r/rrrrrsrc@seZdZe��Zdd�ZdS)�TestHeaderBasecCs|�||�Sr)r)r�name�valuerrr�make_headerMszTestHeaderBase.make_headerN)r#r$r%rrrr3rrrrr0Isr0c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestBaseHeaderFeaturescCs8|�dd�}|�|t�|�|d�|�t|�d�dS�Nr,�this is a test)r3r�str�assertEqual�rrrrr�test_strSszTestBaseHeaderFeatures.test_strcCs$|�dd�}|�|dd�d�dS)Nr,r6���is)r3r8r9rrr�test_substrYsz"TestBaseHeaderFeatures.test_substrcCs|�dd�}|�|jd�dSr5)r3r8r1r9rrr�
test_has_name]sz$TestBaseHeaderFeatures.test_has_namec	Cs2|�dd�}|�t��t||d�W5QRXdS)Nr,r6�foo)r3�assertRaises�AttributeError�setattr)r�attrrrrr�
_test_attr_roasz$TestBaseHeaderFeatures._test_attr_rocCs|�d�dS)Nr1�rE�rrrr�test_name_read_onlyfsz*TestBaseHeaderFeatures.test_name_read_onlycCs|�d�dS)N�defectsrFrGrrr�test_defects_read_onlyisz-TestBaseHeaderFeatures.test_defects_read_onlycCs\|�dd�}|�t|j�d�|�|jt�|�dd�}|�t|j�d�|�|jt�dS)Nr,r6r�date��)r3r8�lenrIr�tupler9rrr�test_defects_is_tuplelsz,TestBaseHeaderFeatures.test_defects_is_tupleN)
r#r$r%r:r>r?rErHrJrPrrrrr4Qsr4c@s2eZdZdd�Zddgdfddgdfdd	d
�ZdS)�TestUnstructuredHeaderc	Gs�t|�}|dkr|dng}d|r&dnd}||dkr>|dn|d}|�d|�}|�||�|�|j|�|�|jtjd�|�dS)	NrzSubject:� rLrM�
rr)rNr3r8�assertDefectsEqualrI�foldr�default)	r�source�decodedr �lrI�header�foldedrrrr�string_as_value�sz&TestUnstructuredHeader.string_as_valuez=?utf-8?q?this_is_a_test?=r6z!=?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)Zrfc2047_simple_quopriZrfc2047_gb2312_base64Zrfc2047_simple_nonascii_quopriZ rfc2047_quopri_with_regular_textN)r#r$r%r\Z
string_paramsrrrrrQs���rQc	@sveZdZdZejdd�Ze�e�Zejdddddd	ed
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�TestDateHeaderzSun, 23 Sep 2001 20:10:55 -0700i����)Zhoursi��	���
�7)ZtzinfocCsR|�d|j�}|�||j�|�|j|j�|�|j��|j�|�|jd�dS�NrKr)r3�
datestringr8�datetime�dt�	utcoffsetrIr9rrr�test_parse_date�s
zTestDateHeader.test_parse_datecCs>|�d|j�}|�||j�|�|j|j�|�|jd�dSre)r3rhr8rfrgrIr9rrr�test_set_from_datetime�sz%TestDateHeader.test_set_from_datetimecCs<|�d|j�}|�|tj�|�|jd�|�|jd�dS)NrKrMr)r3rfrrZUniqueDateHeaderr8�	max_countrIr9rrr�test_date_header_properties�sz*TestDateHeader.test_date_header_propertiescCs<|�d|j�}|�|tj�|�|jd�|�|jd�dS)Nzresent-dater)r3rfrrZ
DateHeaderr8rlrIr9rrr�"test_resent_date_header_properties�sz1TestDateHeader.test_resent_date_header_propertiescCs6|�dd�}|�t|j�d�|�|jdtj�dS)NrKrLrMr)r3r8rNrIrr�HeaderMissingRequiredValuer9rrr�test_no_value_is_defect�sz&TestDateHeader.test_no_value_is_defectc	Cs.|�d|j�}|�t��d|_W5QRXdS)NrKr@)r3rfrArBrgr9rrr�test_datetime_read_only�sz&TestDateHeader.test_datetime_read_onlycCs@ttjd�}|j|d<|�|d|j�|�|dj|j�dS)Nr�Date)rrrVrhr8rfrg)r�mrrr�"test_set_date_header_from_datetime�s
z1TestDateHeader.test_set_date_header_from_datetimeN)r#r$r%rfrgZ	timedeltari�timezoneZtzrhrjrkrmrnrprqrtrrrrr_�s
r_c5@s�eZdZdd�Zddddddigd	fd
dddddigd	fd	dddddifddddiejgfddddiejgfd
dddiejgfddddiejgfddddddddddifddddddifddddddifddddddigdfddddddigdfddddddifd ddddd!ifd"dddd#d#d$�ejgd%fd&d'd(d)d*d+igd,fd-d.d/d0d1d2d3d4�gd5d6fd7d.d/d0d1d2d3d8d9�gd7d:fd;d.d/d0d<d=ifd>d.d/d0d<d?ifd@d.d/d0d<dAigd@fdB�dC��ddD�dEdFdGdHdIdJ�ejgd%dKdLfdMd.d/d0d<dNigdOfdPd.d/d0dGdQigdRfdS�dC��ddD�dddddTdU�ejgdVdWfdXdddddigd	fdYdddd<dZigd[fd\dddd<d]iejgd^d_fd`dddddadU�ejgd^dbdcfdddedfdgd<dhiejgd^difdjdedfdgd<dkigdlfdmdddd<dniejgdofdpdddd<dqiejgd^drfdpdddd<dqiejgd^drfdsdddd<dtiejgdudvfdwdddd<dxigdyfdzddddd{iejgd|d}fd~dddddiejgd�d�fd�dedfdgd<d�iejgd�fd�dedfdgd<d�iejgd%d�fd�dedfdgd<d�iejgd^d�fd�dedfdgd<d�igd�d�fd��.Z	d�S)��TestContentTypeHeaderc
	Gst|�}|dkr|dni}|dkr,|dng}|dkrL|dtk	rL|dn|}	|rXdnd}
|dkrl|dn
|
|	d}|�d|�}|�|j|�|�|j|�|�|j|�|�|j|�|�t	��d	|jd
<W5QRX|�
|j|�|�||	�|�|jt
jd�|�dS)NrrM�zContent-Type: rL�rSzContent-TypeZxyz�abcr)rN�DITTOr3r8�content_type�maintype�subtype�paramsrA�	TypeErrorrTrIrUrrV)
rrWr{r|r}r rY�parmdictrIrXrZr[rrrr�content_type_as_value�s  z+TestContentTypeHeader.content_type_as_valuez)text/plain; charset=us-ascii (Plain text)�
text/plain�text�plain�charsetzus-asciiztext/plain; charset="us-ascii"ztext/plain; charset=us-asciiztext/r@z<crazy "stuff">zimage/jpeg/foo)�	bad/namesr�Zbad�names)z
ImAge/JPeg�
image/jpeg�image�jpeg)z  text  /  plain  r�r�r�)z"(foo) text (bar)/(baz)plain(stuff)r�r�r�ztext/plain; charset="utf-8"zutf-8ztext/plain; charset="US-ASCII"zUS-ASCIIztext/plain; charset="fOo"ZfOoz*text/plain; (interjection) Charset="utf-8"ztext/plain; Charset="utf-8"ztext/plain; title=foo�titleztext/plain; title="foo"z!text/plain; title="(bar)foo blue"z
(bar)foo bluez0text/plain; title="  a     loong  way 	 home   "z  a     loong  way 	 home   zblarg; baz; boorL)�bazZboorxz0Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"zmultipart/mixedZ	multipartZmixed�boundaryZCPIMSSMTPC06p5f3tGz.Multipart/mixed; boundary="CPIMSSMTPC06p5f3tG"zPimage/jpeg; name="wibble.JPG" ; x-mac-type="4A504547" ; x-mac-creator="474B4F4E"r�r�r�z
wibble.JPGZ4A504547Z474B4F4E)r1�
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"
zmimage/jpeg; name="wibble.JPG"; x-mac-type="4A504547"; x-mac-creator="474B4F4E"; x-extrastuff="make it longer"zmake it longer)r1r�r�zx-extrastuffz}Content-Type: image/jpeg; name="wibble.JPG"; x-mac-type="4A504547";
 x-mac-creator="474B4F4E"; x-extrastuff="make it longer"
z$image/jpeg; name="Jim&amp;&amp;Jill"r1zJim&amp;&amp;Jillz!image/jpeg; name="Jim 'Bob' Jill"zJim 'Bob' Jillz#image/jpeg; name="Jim \"Bob\" Jill"zJim "Bob" Jillufoo§/bar; b§r=two; baz=thr§ezlatin-1�surrogateescapeu
foo�/barufoo��barZtwouthr�e)ub�rr�u&foo�/bar; b�r="two"; baz="thr�e"uVContent-Type: =?unknown-8bit?q?foo=A7?=/bar; b�r="two";
 baz*=unknown-8bit''thr%A7e
z(image/jpeg; name*0="abc"; name*1=".html"zabc.htmlzimage/jpeg; name="abc.html"z.image/jpeg; bar*0="baz\"foobar"; bar*1="\"baz"zbaz"foobar"bazz"image/jpeg; bar="baz\"foobar\"baz"uGtext/plain; charset=us-ascii; title*=us-ascii'en'This%20is%20not%20f§nuThis is not f�n)r�r�u9text/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
z-text/plain; charset*=ansi-x3.4-1968''us-asciiz\text/plain;	name*0*=''This%20is%20;	name*1*=%2A%2A%2Afun%2A%2A%2A%20;	name*2="is it not.pdf"zThis is ***fun*** is it not.pdfz2text/plain; name="This is ***fun*** is it not.pdf"zvtext/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.pdfrwz<text/plain; name="This is even more ***fun*** is it not.pdf"z�text/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!"
zHapplication/x-foo;	name*0*="us-ascii'en-us'Frank's"; name*1*=" Document"zapplication/x-fooZapplicationzx-foozFrank's Documentz*application/x-foo; name="Frank's Document"zFapplication/x-foo;	name*0="us-ascii'en-us'Frank's"; name*1=" Document"zus-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.htmlzenglish_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_defaultZascii_is_the_defaultz'text/plain; name="ascii_is_the_default"z*text/plain; charset*=ascii''utf-8%F1%F2%F3uutf-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%9Duutf-8”utext/plain; charset="utf-8”"z@Content-Type: text/plain; charset*=unknown-8bit''utf-8%E2%80%9D
zUapplication/x-foo;	name*0*="us-ascii'en-us'My";	name*1=" Document";	name*2=" For You"zMy 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"z�Content-Type: application/x-foo;
 name*0*=us-ascii''with%20spaceswith%20spaceswith%20spaceswith%20spaceswith;
 name*1*=%20spaceswith%20spaceswith%20spaceswith%20spaces
).�
RFC_2045_1�
RFC_2045_2�
RFC_2045_3Zno_subtype_in_content_typeZno_slash_in_content_typeZjunk_text_in_content_typeZ too_many_slashes_in_content_typeZunknown_content_typeZmixed_case_content_typeZspaces_in_content_typeZcfws_in_content_typeZ
charset_paramZcapitalized_charsetZunknown_charsetZ*capitalized_charset_param_name_and_commentZunquoted_param_valueZparam_value_with_tspecialsZ"param_with_extra_quoted_whitespaceZ
bad_paramsZspaces_around_param_equalsZspaces_around_semisZlots_of_mime_paramsZsemis_inside_quotesZsingle_quotes_inside_quotesZdouble_quotes_inside_quotesZnon_ascii_in_paramsZrfc2231_segmented_normal_valuesZquotes_inside_rfc2231_valueZnon_ascii_rfc2231_valueZrfc2231_encoded_charsetZ rfc2231_encoded_no_double_quotesZ"rfc2231_encoded_with_double_quotesZ)rfc2231_single_quote_inside_double_quotesZ3rfc2231_single_quote_in_value_with_charset_and_langZ)rfc2231_single_quote_in_non_encoded_valueZrfc2231_no_language_or_charsetZrfc2231_encoded_no_charsetZrfc2231_partly_encodedZrfc2231_partly_encoded_2Z(rfc2231_unknown_charset_treated_as_asciiZ0rfc2231_bad_character_in_charset_parameter_valueZ8rfc2231_utf8_in_supposedly_ascii_charset_parameter_valueZ'rfc2231_encoded_then_unencoded_segmentsZ'rfc2231_unencoded_then_encoded_segmentsZ.rfc2231_quoted_unencoded_then_encoded_segmentsZ+rfc2231_folded_segments_correctly_formattedN)
r#r$r%r�r�InvalidHeaderDefect�encode�decodeZUndecodableBytesDefectZcontent_type_paramsrrrrrv�s��
�
��	�	�	��������
�	��������
��
��
�
�����
�
�
���

�
���
�
��
�
������rvc@s8eZdZdd�Zdddejgddfddejgfd�Zd	S)
�TestContentTransferEncodingc
Gs�t|�}|dkr|dng}|dkr8|dtk	r8|dn|}|rDdnd}|dkrX|dn
||d}|�d|�}	|�|	j|�|�|	j|�|�|	|�|�|	jtj	d�|�dS)	NrrMzContent-Transfer-Encoding: rLrwrSzContent-Transfer-Encodingr)
rNrzr3r8�cterTrIrUrrV)
rrWr�r rYrIrXrZr[rrrr�cte_as_value	s z(TestContentTransferEncoding.cte_as_value)�base64r�rLZ7bitzContent-Transfer-Encoding:
z7bit and a bunch more)�
RFC_2183_1�no_valueZjunk_after_cteN)r#r$r%r�rror�Z
cte_paramsrrrrr�s�	��r�c@s�eZdZdd�Zdddddd�gd	d
fddiejgdd
fddiejgfddddiejgfddddiejgdddfddddiejgddfd�ZdS)�TestContentDispositioncGs�t|�}|dkr|dni}|dkr,|dng}|dkrL|dtk	rL|dn|}|rXdnd}|dkrl|dn
||d}	|�d|�}
|�|
j|�|�|
j|�|�|
j|�|�|
|�|�|
jt	j
d	�|	�dS)
NrrMrwzContent-Disposition: rLrxrSzContent-Dispositionr)rNrzr3r8�content_dispositionr~rTrIrUrrV)rrWr�r rYr�rIrXrZr[rrrr�content_disp_as_value1s z,TestContentDisposition.content_disp_as_value)�inliner�zWattachment; filename=genome.jpeg;  modification-date="Wed, 12 Feb 1997 16:29:51 -0500";Z
attachmentzgenome.jpegzWed, 12 Feb 1997 16:29:51 -0500)�filenamezmodification-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"
rLNzContent-Disposition:
zab./kzab.zab./k; filename="foo"r�r@zaattachment; filename="=?UTF-8?Q?Schulbesuchsbest=C3=A4ttigung=2E?=               =?UTF-8?Q?pdf?="uSchulbesuchsbestättigung.pdfrxu4attachment; 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"zFile Name With Spaces.pdfz0attachment; filename="File Name With Spaces.pdf"zFContent-Disposition: attachment; filename="File Name With Spaces.pdf"
)r�Z
RFC_2183_2r�Z
invalid_valueZinvalid_value_with_paramsZ+invalid_parameter_value_with_fws_between_ewZ'parameter_value_with_fws_between_tokens)r#r$r%r�rror�Zcontent_disp_paramsrrrrr�.sV���	��
���r�c@seZdZdd�Zdddddgfdddddgfdddddgfdddddgfd	d	d	ddgfd
d
d
ddgfdddddgfd
d
dddgfdddddejgfdddddejgfdddddejgfdddddejgfdddddejgfdddddejgfdddddejgfd�ZdS)�TestMIMEVersionHeadercCs~|�d|�}|�||�|�|j|�|�|j|�|�|j|�|�|j|�|r\d|}|�|jtj	d�d|d�dS)NzMIME-VersionrRrz
MIME-Version:rS)
r3r8�version�major�minorrTrIrUrrV)rrWrXr�r�r�rIrrrr�version_string_as_MIME_Version�s
�z4TestMIMEVersionHeader.version_string_as_MIME_Versionz1.0rMrz1.0 (produced by MetaSend Vx.x)z(produced by MetaSend Vx.x) 1.0z1.(produced by MetaSend Vx.x)0z1.1z2.1rwz1 .0z  1.0  z	1.0 <abc>z	<abc> 1.0Nz1.<abc>0z1..0z2.xr@rL)r�r�r�Z
RFC_2045_4Z1_1Z2_1Z
whitespaceZ#leading_trailing_whitespace_ignoredZnon_comment_garbage_afterZnon_comment_garbage_beforeZnon_comment_garbage_insideZtwo_periodsZ2_xr@Zmissing)r#r$r%r�rr�roZversion_string_paramsrrrrr��s��	�	�	��	�	�	�
�
�	�	�	�	�	��r�c@s�eZdZdejgddddddfdgddddddfdgddddddfd	gd	dd
dddfdgd
dddddfdgddddddfdejgddddddfdejgdddddddfdgddddddfd ejgd!d"dd"d#ddfd$ejgd%d&dd&d'ddfd(ejgd)dd)d*ddfd+gd,d-d.d/ddfd0gd1d2d.d/ddfd3ejejgd,d-d.d/ddfd4�Zd5d6�Zd7d8�Zd9d:�Z	d;d<�Z
d=d>�Zd?d@�ZdAdB�Z
dCdD�ZdEdF�ZdGdH�ZdIdJ�ZdKdL�ZdMdN�ZdS)O�TestAddressHeader�<>rLNzzippy@pinhead.comZzippyzpinhead.comz%Zaphrod Beblebrux <zippy@pinhead.com>zZaphrod 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>zA (Special) Personzperson@dom.ainZpersonzdom.ainz."Arthur \\Backslash\\ Foobar" <person@dom.ain>zArthur \Backslash\ FoobarzJohn X. Doe <jxd@example.com>z"John X. Doe" <jxd@example.com>zJohn X. Doezjxd@example.comZjxd�example.comz""example" example"@example.comrxz"example example"@example.comzexample examplez!"\"example\" example"@example.comz"example" examplez#"\\"example\\" example"@example.comr;z#"\\example\\\\ example"@example.comz\example\\ examplezmerwok  wok  @example.comrwz"merwok wok"@example.comz
merwok wokzmerwok. wok .  wok@example.comzmerwok.wok.wok@example.comzmerwok.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>)�emptyZaddress_onlyZname_and_addressZquoted_local_partZquoted_parens_in_nameZquoted_backslashes_in_nameZ
name_with_dotZquoted_strings_in_local_partZ$escaped_quoted_strings_in_local_partZescaped_escapes_in_local_partZ'spaces_in_unquoted_local_part_collapsedZ(spaces_around_dots_in_local_part_removedZrfc2047_atom_is_decodedZ!rfc2047_atom_in_phrase_is_decodedZ(rfc2047_atom_in_quoted_string_is_decodedc	Cs�|�d|�}	|�|	|�|�|	j|�|	j}
|�t|
�|�|�t|	j�d�|�|
gt|	jdj	��|�|
gt|	j	��|�|
j
|�|�|
j|�|�|
j|�|�|
j
|�dS)N�senderrMr)r3r8rTrI�addressr7rN�groups�list�	addresses�display_name�	addr_spec�username�domain)rrWrIrXr�r�r�r��commentr�arrr�example_as_address�sz$TestAddressHeader.example_as_addressc	Cs�d�|�}|rd�|�nd}	|�d|�}
|�|
|	�|�|
j|�|�|
jdj|
j�|�t|
j�d�|�t|
j�d�|
jd}|�t|�|�|�|j	|�|�|j
|�|�|j|�|�|j|�dS)Nzfoo: {};�foo:;�torrM)
�formatr3r8rTrIr�r�rNr7r�r�r�r�)rrWrIrXr�r�r�r�r�Zgdecodedrr�rrr�example_as_group�s

z"TestAddressHeader.example_as_groupcCs�d}|�d|�}|�||�|�t|j�d�|�t|j�d�td�D]"}|�|j|jd|j|�qH|�t|jd�d�|�t|jd�d�|�t|jd�d	�|�|jdjd
�dS)NzTFred <dinsdale@python.org>, foo@example.com, "Harry W. Hastings" <hasty@example.com>r�rxrzFred <dinsdale@python.org>rMr�rwz'"Harry W. Hastings" <hasty@example.com>zHarry W. Hastings)r3r8rNr�r��ranger7r�)rr2r�irrr�test_simple_address_list�s ��z*TestAddressHeader.test_simple_address_listcCsnt|j���}dd�dd�|dd�D��ddd�dd�|dd�D��d	d�d
d�|dd�D��}dd�dd�|dd�D��ddd�d
d�|dd�D��dd�dd�|dd�D��}|�d|�}|�|�d�|�d��|�||�|�t|j�dt|�d�|�|jdj	d�|�|jdj	d�|�|jdj	d�|�t|j
�t|��td�D]D}|�|j|dj	�|�t
|j|dj
d�||d��q~tddt|�d�D]@}|�|j|j	�|�t
|j|j
d�||dd��q�tt|��D]@}|�t
|j
|�||d�|�|j
|j||d��q(dS)Nz dummy list:;, another: (empty);,z, cSsg|]}|d�qS�rr��.0�xrrr�
<listcomp>�sz?TestAddressHeader.test_complex_address_list.<locals>.<listcomp>�z"A \"list\"": cSsg|]}|d�qSr�rr�rrrr��s�z;,cSsg|]}|d�qSr�rr�rrrr��szdummy list:;, another:;, cSsg|]}|d�qS�rwrr�rrrr��scSsg|]}|d�qSr�rr�rrrr�sz;, cSsg|]}|d�qSr�rr�rrrr�sr��,r<rz
dummy listrMZanotherzA "list"rw)r��example_params�values�joinr3r8�splitrNr�r�r�r��assertIsNoner7r�)rZexamplesrWZexpectedrr�rrr�test_complex_address_list�sX������������,,z+TestAddressHeader.test_complex_address_listc	Cs,|�dd�}|�t��d|_W5QRXdS�Nr�zabc@xyz.comr@)r3rArBr�r9rrr�test_address_read_onlysz(TestAddressHeader.test_address_read_onlyc	Cs,|�dd�}|�t��d|_W5QRXdSr�)r3rArBr�r9rrr�test_addresses_read_onlysz*TestAddressHeader.test_addresses_read_onlyc	Cs,|�dd�}|�t��d|_W5QRXdSr�)r3rArBr�r9rrr�test_groups_read_only sz'TestAddressHeader.test_groups_read_onlycCs4d}|�d|�}|�|jt�|�|jdt�dS�Nzme <who@example.com>r�r)r3rr�rOr	�rrWrrrr�test_addresses_types%sz&TestAddressHeader.test_addresses_typescCs4d}|�d|�}|�|jt�|�|jdt�dSr�)r3rr�rOr
r�rrr�test_groups_types+sz#TestAddressHeader.test_groups_typescCs$|�dtddd��}|�|d�dS)Nr��mer@r�zme <foo@example.com>�r3r	r8r9rrr�test_set_from_Address1sz'TestAddressHeader.test_set_from_AddresscCs0|�dtddd�tddd�g�}|�|d�dS)Nr�r�r@r��your�z+me <foo@example.com>, you <bar@example.com>r�r9rrr�test_set_from_Address_list5s
�z,TestAddressHeader.test_set_from_Address_listcCsj|�dtddd�tdtddd�td	d
d�g�tdd
d�g�}|�|d�|�|jtjjdd�d�d�dS)Nr�r�r@r��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>�(�Zmax_line_lengthrzWto: me <foo@example.com>,
 bing: fiz <z@b.com>, zif <f@c.com>;,
 you <bar@example.com>
)r3r	r
r8rUrrV�cloner9rrr�$test_set_from_Address_and_Group_list:s
�
��z6TestAddressHeader.test_set_from_Address_and_Group_listc
Cs8|�dtdtddd�tddd�g�g�}|�|d	�dS)
Nr�r�r�r�r�r�r�r�z#bing: fiz <z@b.com>, zif <f@c.com>;)r3r
r	r8r9rrr�test_set_from_Group_listFs
�
z*TestAddressHeader.test_set_from_Group_list)r#r$r%rr�ZObsoleteHeaderDefectr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s2�
�
�
�
�
�
�

�
�

�

�
�
�
�
���� #r�c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAS)B�TestAddressAndGroupc	Cs&|�t��t||d�W5QRXdS)Nr@)rArBrC)r�objrDrrrrENsz!TestAddressAndGroup._test_attr_rocCs|�tddd�d�dS)Nr@r�r�r��rEr	rGrrr�test_address_display_name_roRsz0TestAddressAndGroup.test_address_display_name_rocCs|�tddd�d�dS)Nr@r�r�r�r�rGrrr�test_address_username_roUsz,TestAddressAndGroup.test_address_username_rocCs|�tddd�d�dS)Nr@r�r�r�r�rGrrr�test_address_domain_roXsz*TestAddressAndGroup.test_address_domain_rocCs|�td�d�dS)Nr@r��rEr
rGrrr�test_group_display_name_ro[sz.TestAddressAndGroup.test_group_display_name_rocCs|�td�d�dS)Nr@r�r�rGrrr�test_group_addresses_ro^sz+TestAddressAndGroup.test_group_addresses_rocCsXtddd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)Nr@r�r��bar@baz�
foo <bar@baz>�r	r8r�r�r�r�r7�rr�rrr�!test_address_from_username_domainasz5TestAddressAndGroup.test_address_from_username_domaincCsXtddd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)Nr@r��r�r�r�r�r�r�rrr�test_address_from_addr_specisz/TestAddressAndGroup.test_address_from_addr_speccCsVtdd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)Nr�r�rLr�r�r�r�rrr�!test_address_with_no_display_nameqs
z5TestAddressAndGroup.test_address_with_no_display_namecCsRt�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)NrLr�r�r�rrr�test_null_addressysz%TestAddressAndGroup.test_null_addresscCsVtdd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)N�buzz�r�rLz@buzzr�r�rrr�test_domain_only�s
z$TestAddressAndGroup.test_domain_onlycCsVtdd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)Nr��r�rLr�r�rrr�test_username_only�s
z&TestAddressAndGroup.test_username_onlycCsTtd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)Nr�rLr�zbuzz <>r�r�rrr�test_display_name_only�sz*TestAddressAndGroup.test_display_name_onlycCsXtddd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)NzSara J.zbad namer�z"bad name"@example.comz""Sara J." <"bad name"@example.com>r�r�rrr�test_quoting�sz TestAddressAndGroup.test_quotingcCsXtddd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t|�d�dS)Nr]Zwokuexàmple.comuwok@exàmple.comuÉric <wok@exàmple.com>r�r�rrr�	test_il8n�szTestAddressAndGroup.test_il8ncCs�tdd�tdd�tdd�tdd�tdd�tdd�td	d
�tdd
�tdd
�td
d�tdd�tdd�f}|D]>}|j|d��(|�td��tf|�W5QRXW5QRXqhdS)Nzfoo
)r�zfoo
zfoo
zexample.com
r�zexample.com
z
example.com
zwok
r�zwok
zwok
zwok@example.com
r�zwok@example.com
zwok@example.com
)�kwargszinvalid arguments)�dictZsubTestZassertRaisesRegex�
ValueErrorr	)rZcasesrrrr�$test_crlf_in_constructor_args_raises�s �z8TestAddressAndGroup.test_crlf_in_constructor_args_raisesc	Cs&|�t��tddd�W5QRXdS)Nr@uwők@example.comr��rArr	rGrrr�+test_non_ascii_username_in_addr_spec_raises�sz?TestAddressAndGroup.test_non_ascii_username_in_addr_spec_raisesc	Cs(|�t��tdddd�W5QRXdS)Nr@r�r�)r�r��rArr	rGrrr�*test_address_addr_spec_and_username_raises�sz>TestAddressAndGroup.test_address_addr_spec_and_username_raisesc	Cs(|�t��tdddd�W5QRXdS)Nr@r�r�)r�r�r	rGrrr�(test_address_addr_spec_and_domain_raises�sz<TestAddressAndGroup.test_address_addr_spec_and_domain_raisesc	Cs*|�t��tddddd�W5QRXdS)Nr@Zbongr�r�)r�r�r�r	rGrrr�5test_address_addr_spec_and_username_and_domain_raises�szITestAddressAndGroup.test_address_addr_spec_and_username_and_domain_raisesc	Cs&|�t��tddd�W5QRXdS)Nr@zbad name@example.comr�rrGrrr�'test_space_in_addr_spec_username_raises�sz;TestAddressAndGroup.test_space_in_addr_spec_username_raisesc	Cs&|�t��tddd�W5QRXdS)Nr@zname@ex[]ample.comr�rrGrrr�test_bad_addr_sepc_raises�sz-TestAddressAndGroup.test_bad_addr_sepc_raisescCs:td�}|�|jd�|�|jt��|�t|�d�dS)Nr@r��r
r8r�r�rOr7�r�grrr�test_empty_group�sz$TestAddressAndGroup.test_empty_groupcCs>tdgd�}|�|jd�|�|jt��|�t|�d�dS)Nr@�r�r�rrrrr�test_empty_group_list�sz)TestAddressAndGroup.test_empty_group_listcCs6t�}|�|j�|�|jt��|�t|�d�dS)NzNone:;)r
r�r�r8r�rOr7rrrr�test_null_group�sz#TestAddressAndGroup.test_null_groupcCsVtddd�tddd�g}td|�}|�|jd�|�|jt|��|�t|�d�dS)N�b�cr�r@zfoo: b <b@c>, a <b@c>;)r	r
r8r�r�rOr7�rZaddrsrrrr�test_group_with_addresses�s

z-TestAddressAndGroup.test_group_with_addressescCsTtddd�tddd�g}t|d�}|�|j�|�|jt|��|�t|�d�dS)Nrrr�rzNone: b <b@c>, a <b@c>;�r	r
r�r�r8r�rOr7rrrr�)test_group_with_addresses_no_display_name�s

z=TestAddressAndGroup.test_group_with_addresses_no_display_namecCsJtddd�g}t|d�}|�|j�|�|jt|��|�t|�d�dS)Nrrrzb <b@c>rrrrr�+test_group_with_one_address_no_display_name�s

z?TestAddressAndGroup.test_group_with_one_address_no_display_namecCs:td�}|�|jd�|�|jt��|�t|�d�dS)Nzfoo.barz"foo.bar":;rrrrr�test_display_name_quotingsz-TestAddressAndGroup.test_display_name_quotingcCs:td�}|�|jd�|�|jt��|�t|�d�dS)Nr��	foo bar:;rrrrr�#test_display_name_blanks_not_quoted
sz7TestAddressAndGroup.test_display_name_blanks_not_quotedcCsHtddd�}ttjd�}||d<|�|dd�|�|dj|f�dS)Nr@r�r�r�Tor�zfoo <bar@example.com>)r	rrrVr8r�)rr�rsrrr�$test_set_message_header_from_addresss
z8TestAddressAndGroup.test_set_message_header_from_addresscCsDtd�}ttjd�}||d<|�|dd�|�|dj|j�dS)Nr�rr r�r)r
rrrVr8r�)rrrsrrr�"test_set_message_header_from_groups
z6TestAddressAndGroup.test_set_message_header_from_groupN)#r#r$r%rEr�r�r�r�r�r�r�r�r�r�r�rrrrrr
rrr
rrrrrrrrrr!r"rrrrr�Ls@		

r�c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�TestFoldingcCs@dD]6\}}|�dt|dd��}|�|jtjd�d|�qdS)z1Test the folding and encoding of address headers.)	)zFoo Bar, Francez"Foo Bar, France")zFoo Bar (France)z"Foo Bar (France)")uFoo Bar, Españaz"Foo =?utf-8?q?Bar=2C_Espa=C3=B1a?=)uFoo Bar (España)z Foo Bar =?utf-8?b?KEVzcGHDsWEp?=)uFoo, Bar Españaz"=?utf-8?q?Foo=2C_Bar_Espa=C3=B1a?=)uFoo, Bar [España]z(=?utf-8?q?Foo=2C_Bar_=5BEspa=C3=B1a=5D?=)uFoo Bär, Francez"Foo =?utf-8?q?B=C3=A4r=2C?= France)uFoo Bär <France>z%Foo =?utf-8?q?B=C3=A4r_=3CFrance=3E?=)urLô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 za@b.comr�rzTo: %s <a@b.com>
N)r3r	r8rUrrV)rr1�resultrrrr�test_address_display_names!s
�z&TestFolding.test_address_display_namescCs&|�dd�}|�|jtjd�d�dS)Nr,r6rzsubject: this is a test
�r3r8rUrrVr9rrr�test_short_unstructured9s�z#TestFolding.test_short_unstructuredcCs&|�dd�}|�|jtjd�d�dS)NrzhThis is a long header line that will need to be folded into two lines and will demonstrate basic foldingrzsSubject: This is a long header line that will need to be folded into two lines
 and will demonstrate basic folding
r&r9rrr�test_long_unstructured>s�z"TestFolding.test_long_unstructuredcCs4|�dd�}|�|jtjjdd�d�t�d��dS)Nrz1this is a short header that will be folded anywayrbr�rz�                Subject: this is a
                 short header that
                 will be folded
                 anyway
                �r3r8rUrrVr��textwrap�dedentr9rrr�'test_unstructured_short_max_line_lengthGs
�z3TestFolding.test_unstructured_short_max_line_lengthcCs&|�dd�}|�|jtjd�d�dS)NrrrzSubject: test
r&r9rrr�"test_fold_unstructured_single_wordSsz.TestFolding.test_fold_unstructured_single_wordcCs&|�dd�}|�|jtjd�d�dS)Nrztest test testrzSubject: test test test
r&r9rrr�test_fold_unstructured_shortWs�z(TestFolding.test_fold_unstructured_shortcCs.|�dd�}|�|jtjjdd�d�d�dS)NrZ5thisisaverylonglineconsistingofasinglewordthatwontfitrbr�rz�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?=
�r3r8rUrrVr�r9rrr�)test_fold_unstructured_with_overlong_word\s
�z5TestFolding.test_fold_unstructured_with_overlong_wordcCs.|�dd�}|�|jtjjdd�d�d�dS)NrzXthisisaverylonglineconsistingofasinglewordthatwontfit plusanotherverylongwordthatwontfitrbr�raSubject: 
 =?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/r9rrr�.test_fold_unstructured_with_two_overlong_wordsls
�z:TestFolding.test_fold_unstructured_with_two_overlong_wordscCs.|�dd�}|�|jtjjdd�d�d�dS)NrZ thislongwordislessthanmaxlinelen�#r�rz+Subject:
 thislongwordislessthanmaxlinelen
r/r9rrr�.test_fold_unstructured_with_slightly_long_word�s
�z:TestFolding.test_fold_unstructured_with_slightly_long_wordcCs4|�dd�}|�|jtjjdd�d�t�d��dS)Nrz�This header is intended to demonstrate, in a fairly succinct way, that we now do not give a , special treatment in unstructured headers.�<r�rz�                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)r9rrr�"test_fold_unstructured_with_commas�s
�z.TestFolding.test_fold_unstructured_with_commascCs,|�dd�}|�|jtjd�t�d��dS)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>rz�            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>
             )r3r8rUrrVr*r+r9rrr�test_fold_address_list�sz"TestFolding.test_fold_address_listcCs&|�dd�}|�|jtjd�d�dS)NrrzSat, 2 Feb 2002 17:00:06 -0800rz&Date: Sat, 02 Feb 2002 17:00:06 -0800
r&r9rrr�test_fold_date_header�s�z!TestFolding.test_fold_date_headercCs&|�dd�}|�|jtjd�d�dS)NzX-Report-Abusez]<https://www.mailitapp.com/report_abuse.php?mid=xxx-xxx-xxxxxxxxxxxxxxxxxxxxxxxx==-xxx-xx-xx>rz�X-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&r9rrr�&test_fold_overlong_words_using_RFC2047�s��z2TestFolding.test_fold_overlong_words_using_RFC2047cCs�|�dd�}|�|jtjjdd�d�d�|�dd�}|�|jtjjdd�d�d�|�dd	�}|�|jtjjd
d�d�d�|�dd�}|�|jtjjdd�d�d
�dS)Nz
Message-IDz+<somemessageidlongerthan@maxlinelength.com>rbr�rz8Message-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>u0Message-ID:
 <ईमेलfromMessage@wők.com>
r/r9rrr�$test_message_id_header_is_not_folded�s4������z0TestFolding.test_message_id_header_is_not_foldedN)r#r$r%r%r'r(r,r-r.r0r1r3r5r6r7r8r:rrrrr#s	


r#�__main__)rgr*ZunittestZemailrrZ
email.messagerZtest.test_emailrrrZemail.headerregistryr	r
�objectrzrr0r4rQr_rvr�r�r�r�r�r#r#�mainrrrr�<module>sN:.(1/'R.T1