
    <e                         d dl Z d dlmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
mZ e G d de                      Ze G d d	e                      Zed
k    r e j                     dS dS )    N)TestEmailBaseparameterize)policy)EmailMessage)ContentManagerraw_data_managerc                       e Zd Zej        ZeZddddZd Zd Z	d Z
 G d d	e          Ze d
z   dz   Z G d de          Ze d
z   dz   ZdefdefdddefdefdddefddddZd Zd Zd Zd Zd  Zd!S )"TestContentManager)   
text/plain)   text)    )	full_typemaintype_onlynull_keyc                     d	d}t                      }|                    ||           |                                 }d|d<   d|d<   |                     |                    |d          d           d S )
Nc                     | d         }||fS NX-Bar-Header )msgfoobars      :/usr/lib/python3.11/test/test_email/test_contentmanager.py
foo_getterzATestContentManager.get_key_as_get_content_key.<locals>.foo_getter   s    n%C8O    r   Content-Typer   r   r   r   )r   r   N)r   add_get_handler_make_messageassertEqualget_content)selforderkeyr   cmms         r   get_key_as_get_content_keyz-TestContentManager.get_key_as_get_content_key   s    	 	 	 	 
3
+++  (.!.u55~FFFFFr   c                 h   d }d }t                      }|                    ||           | j                                        D ]!\  }}||k    r|                    ||           "|                                 }d|d<   d|d<   d|d<   |                     |                    |          d           d S )	Nc                     | d         S r   r   r   s    r   
bar_getterzGTestContentManager.get_key_as_get_content_key_order.<locals>.bar_getter!       ~&&r   c                     | d         S NX-Foo-Headerr   r.   s    r   r   zGTestContentManager.get_key_as_get_content_key_order.<locals>.foo_getter#   r0   r   r   r   r   r   r   r3   )r   r"   get_key_paramsvaluesr#   r$   r%   )r&   r'   r(   r/   r   r)   
precedencer*   s           r    get_key_as_get_content_key_orderz3TestContentManager.get_key_as_get_content_key_order    s    	' 	' 	'	' 	' 	'
3
+++#299;; 	4 	4OJE!!""3
333  (.!.!.**U44444r   c                     t                      }|                                 }d|d<   |                     t          d          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nr   r   )r   r#   assertRaisesRegexKeyErrorr%   r&   r)   r*   s      r   :test_get_content_raises_if_unknown_mimetype_and_no_defaultzMTestContentManager.test_get_content_raises_if_unknown_mimetype_and_no_default0   s      (.##Hl;; 	 	NN1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A&&A*-A*c                       e Zd ZdS )TestContentManager.BaseThingN__name__
__module____qualname__r   r   r   	BaseThingr>   7           r   rC   .r>   c                       e Zd ZdS )TestContentManager.ThingNr?   r   r   r   ThingrG   :   rD   r   rH   rG   r   r   )r   rG   )r   rH         )   r>   )   rC      )	   zbuiltins.str)
   str)   N)type	full_pathqualnamename	base_typebase_full_pathbase_qualname	base_namestr_typestr_full_pathstr_namer   c                 ^   dd}t                      }|                    ||           |                                 }|                                 }|                    ||d           |                     |d         d           |                     |                                |           d S )Nc                 :    || d<   |                      |           d S r2   set_payload)r   objr   s      r   
foo_setterzATestContentManager.set_key_as_set_content_key.<locals>.foo_setterN   s$    "%COOC     r   r   r    r3   r!   )r   add_set_handlerr#   rH   set_contentr$   get_payload)r&   r'   r(   rb   r)   r*   msg_objs          r   set_key_as_set_content_keyz-TestContentManager.set_key_as_set_content_keyM   s    	! 	! 	! 	! 
3
+++  **,,
q'u--->*E222'22222r   c                    d }d }t                      }|                    ||           | j                                        D ]!\  }}||k    r|                    ||           "|                                 }|                                 }|                    ||           |                     |d         d           |                     |                                |           d S )Nc                 :    d| d<   |                      |           d S )Nr   X-FooBar-Headerr_   r   ra   s     r   rb   zGTestContentManager.set_key_as_set_content_key_order.<locals>.foo_setterZ   s%    %*C!"OOC     r   c                     d| d<   d S )Nr   rj   r   rk   s     r   
bar_setterzGTestContentManager.set_key_as_set_content_key_order.<locals>.bar_setter]   s    %*C!"""r   rj   r   )	r   rc   r4   r5   r#   rH   rd   r$   re   )	r&   r'   r(   rb   rm   r)   r6   r*   rf   s	            r    set_key_as_set_content_key_orderz3TestContentManager.set_key_as_set_content_key_orderY   s    	! 	! 	!	+ 	+ 	+
3
+++#299;; 	4 	4OJE!!""3
333  **,,
q'""",-u555'22222r   c                    t                      }|                                 }|                                 }|                     t          | j                  5  |                    ||           d d d            d S # 1 swxY w Y   d S r!   )r   r#   rH   r9   r:   testobject_full_pathrd   )r&   r)   r*   rf   s       r   6test_set_content_raises_if_unknown_type_and_no_defaultzITestContentManager.test_set_content_raises_if_unknown_type_and_no_defaultj   s      **,,##Hd.GHH 	' 	'NN1g&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   A;;A?A?c                     t                      }|                                 }d|d<   |                     t                    5  |                    |d           d d d            d S # 1 swxY w Y   d S )Nzmultipart/foor   test)r   r#   assertRaises	TypeErrorrd   r;   s      r   .test_set_content_raises_if_called_on_multipartzATestContentManager.test_set_content_raises_if_called_on_multipartq   s      +.y)) 	& 	&NN1f%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   A&&A*-A*c                    |                                  }d|d<   d|d<   d|d<   |                    d           t                      }|                    t          d            |                    d	|
           |                     |d                    |                     |d                    |                     |d         d           |                     |                                           d S )Nr   zContent-Fooz	text/htmlr   rs   Toabcc                      d S r!   r   )argskws     r   <lambda>zITestContentManager.test_set_content_calls_clear_content.<locals>.<lambda>   s    D r   xyz)content_manager)	r#   r`   r   rc   rP   rd   assertIsNoner$   re   )r&   r*   r)   s      r   $test_set_content_calls_clear_contentz7TestContentManager.test_set_content_calls_clear_contentx   s       -'.$	e
3 8 8999	eR000!M*+++!N+,,,4&)))!--//*****r   N)r@   rA   rB   r   defaultr   messager4   r+   r7   r<   rP   rC   baseobject_full_pathrH   rp   set_key_paramsrg   rn   rq   rv   r   r   r   r   r
   r
   	   ss        ^FG /($
 
N	G 	G 	G5 5 5       C   #c>,JJ    	   #c>,FF L!57=*,!57A.J1('
 
N
3 
3 
33 3 3"' ' '& & &+ + + + +r   r
   c                      e Zd Zej                            de          ZeZd Z	d Z
d Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d' Z-d( Z.d) Z/d* Z0d+ Z1d, Z2d- Z3d. Z4d/ Z5d0 Z6d1 Z7d2 Z8d3 Z9d4d5d6d7 e            d8f e            d9fd:Z:d; Z;d< Z<d= Z=d> Z>d? Z?d@S )ATestRawDataManager<   )max_line_lengthr   c                     |                      t          j        d                    }|                     t	          j        |          d           d S )NJ            Content-Type: text/plain

            Basic text.
            zBasic text.
_str_msgtextwrapdedentr$   r   r%   r&   r*   s     r   test_get_text_plainz&TestRawDataManager.test_get_text_plain   sR    MM(/ +    
 	)5a88/JJJJJr   c                     |                      t          j        d                    }|                     t	          j        |          d           d S )NzP            Content-Type: text/html

            <p>Basic text.</p>
            z<p>Basic text.</p>
r   r   s     r   test_get_text_htmlz%TestRawDataManager.test_get_text_html   s]    MM(/ +    
 	)5a88/	1 	1 	1 	1 	1r   c                     |                      t          j        d                              d                    }|                     t          j        |          d           d S )Nu\               Content-Type: text/plain; charset=latin1

            Basìc tëxt.
            latin1   Basìc tëxt.
)
_bytes_msgr   r   encoder$   r   r%   r   s     r   test_get_text_plain_latin1z-TestRawDataManager.test_get_text_plain_latin1   sb    OOHO -   !!	# #
 	)5a88:KLLLLLr   c                     |                      t          j        d                    }|                     t	          j        |          d           d S )Nz            Content-Type: text/plain; charset="latin-1"
            Content-Transfer-Encoding: quoted-printable

            Bas=ECc t=EBxt.
            r   r   r   s     r   +test_get_text_plain_latin1_quoted_printablez>TestRawDataManager.test_get_text_plain_latin1_quoted_printable   S    MM(/ +     	)5a88:KLLLLLr   c                     |                      t          j        d                    }|                     t	          j        |          d           d S )Nz            Content-Type: text/plain; charset="utf8"
            Content-Transfer-Encoding: base64

            QmFzw6xjIHTDq3h0Lgo=
            r   r   r   s     r   test_get_text_plain_utf8_base64z2TestRawDataManager.test_get_text_plain_utf8_base64   r   r   c                     |                      t          j        d                    }|                     t	          j        |          d           d S )N            Content-Type: text/plain; charset="utf8"
            Content-Transfer-Encoding: quoted-printable

            Bas=c3=acc t=c3=abxt=fd.
            u   Basìc tëxt�.
r   r   s     r   -test_get_text_plain_bad_utf8_quoted_printablez@TestRawDataManager.test_get_text_plain_bad_utf8_quoted_printable   sS    MM(/ +     	)5a88:NOOOOOr   c                     |                      t          j        d                    }|                     t	          j        |d          d           d S )Nr   ignoreerrorsr   r   r   s     r   ;test_get_text_plain_bad_utf8_quoted_printable_ignore_errorszNTestRawDataManager.test_get_text_plain_bad_utf8_quoted_printable_ignore_errors   b    MM(/ +     	)5aIII*	, 	, 	, 	, 	,r   c                     |                      t          j        d                    }|                     t	          j        |d          d           d S )Nu               Content-Type: text/plain; charset="utf8"
            Content-Transfer-Encoding: base64

            QmFzw6xjIHTDq3h0Lgoÿ=
            r   r   r   r   r   s     r   8test_get_text_plain_utf8_base64_recoverable_bad_CTE_datazKTestRawDataManager.test_get_text_plain_utf8_base64_recoverable_bad_CTE_data   r   r   c                     |                      t          j        d                    }|                     t                    5  t          j        |d           d d d            d S # 1 swxY w Y   d S )Nr   r   r    r   r   r   rt   ru   r   r%   r   s     r   test_get_text_invalid_keywordz0TestRawDataManager.test_get_text_invalid_keyword   s    MM(/ +    
 y)) 	: 	:(9999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:rw   c                 ^   t          j        d          }d                                D ]}|                     |          5  |                     |                    |dz                       }|                     t          j        |          d           d d d            n# 1 swxY w Y   d S )Nzu            Content-Type: {}
            Content-Transfer-Encoding: base64

            Ym9ndXMgZGF0YQ==
            zaudio image video application)maintypez/foos
   bogus data)	r   r   splitsubTestr   formatr$   r   r%   )r&   templater   r*   s       r   test_get_non_textz$TestRawDataManager.test_get_non_text   s   ? $   8==?? 	Q 	QHx00 Q QMM(//(6/"B"BCC  !1!=a!@!@-PPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q	Q 	Qs   AB!!B%	(B%	c                     |                      t          j        d                    }|                     t                    5  t          j        |d           d d d            d S # 1 swxY w Y   d S )Nz|            Content-Type: image/jpg
            Content-Transfer-Encoding: base64

            Ym9ndXMgZGF0YQ==
            r   r   r   r   s     r   !test_get_non_text_invalid_keywordz4TestRawDataManager.test_get_non_text_invalid_keyword   s    MM(/ +     y)) 	= 	=(8<<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=rw   c                     |                      t          j        d                    }|                     t                    5  t          j        |           d d d            d S # 1 swxY w Y   d S )Nzm            Content-Type: multipart/mixed; boundary="==="

            --===
            --===--
            )r   r   r   rt   r:   r   r%   r   s     r   test_get_raises_on_multipartz/TestRawDataManager.test_get_raises_on_multipart   s    MM(/ +     x(( 	, 	,(+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   A$$A(+A(c                 F   t          j        d          }d                                D ]}|                     |          5  |                     |                    |                    }t          j        |          }|                     || j	                   | 
                    t          j        |          d           | 
                    |d         d           | 
                    |d         j        d         j        d	           d d d            n# 1 swxY w Y   d S )
Nz            Content-Type: message/{}

            To: foo@example.com
            From: bar@example.com
            Subject: example

            an example message
            rfc822 external-bodysubtypezan example message
tofoo@example.comfromr   r   )r   r   r   r   r   r   r   r%   assertIsInstancer   r$   	addressesusername)r&   r   r   r*   sub_msgs        r   )test_get_message_rfc822_and_external_bodyz<TestRawDataManager.test_get_message_rfc822_and_external_body  sl   ? $   .3355 	O 	OGg.. O OMM(//'":":;;*6q99%%gt|<<<  !1!=g!F!F!79 9 9  0ABBB  !:1!=!FNNNO O O O O O O O O O O O O O O	O 	Os   CDD	D	c                     |                      t          j        d                    }|                     t	          j        |          d d         d           d S )Nz            Content-Type: message/partial

            To: foo@example.com
            From: bar@example.com
            Subject: example

            The real body is in another message.
            rO   s
   To: foo@exr   r   s     r   9test_get_message_non_rfc822_or_external_body_yields_byteszLTestRawDataManager.test_get_message_non_rfc822_or_external_body_yields_bytes  s[    MM(/ +     	)5a88"=}MMMMMr   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                     |                     |                    d                              d          |           |                     |	                                |           d S )NSimple message.
z            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 7bit

            Simple message.
            Tdecodeutf-8
r#   r   rd   r$   rP   r   r   re   r   r%   r&   r*   contents      r   test_set_text_plainz&TestRawDataManager.test_set_text_plain%  s      %$Q000Q 2 " " 	 	 	 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                     |                     |                    d                              d          d           |                     |	                                d           d S )Nr   zp            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 7bit


            Tr   r   
r   r   s      r   test_set_text_plain_nullz+TestRawDataManager.test_set_text_plain_null2  s      $Q000Q 2 " " 	 	 	 	d33::7CCTJJJ$/////r   c                    |                                  }d}t          j        ||d           |                     t	          |          t          j        d                     |                     |                    d                              d          |           |                     |	                                |           d S )Nz<p>Simple message.</p>
htmlr   z            Content-Type: text/html; charset="utf-8"
            Content-Transfer-Encoding: 7bit

            <p>Simple message.</p>
            Tr   r   r   r   s      r   test_set_text_htmlz%TestRawDataManager.test_set_text_html?  s      ,$Q@@@@Q 2 " " 	 	 	 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||d           |                     t	          |          t          j        d                     |                     |                    d                              d          |           |                     |	                                |           d S )Nr   latin-1charsetz            Content-Type: text/plain; charset="iso-8859-1"
            Content-Transfer-Encoding: 7bit

            Simple message.
            Tr   r   r   r   s      r   test_set_text_charset_latin_1z0TestRawDataManager.test_set_text_charset_latin_1L  s      %$QCCCCQ 2 " " 	 	 	 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                     |                     |                    d                              d          |           |                     |	                                |           d S )NzTSimple but long message that is over 78 characters long to force transfer encoding.
z            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: quoted-printable

            Simple but long message that is over 78 characters long to =
            force transfer encoding.
            Tr   r   r   r   s      r   (test_set_text_plain_long_line_heuristicsz;TestRawDataManager.test_set_text_plain_long_line_heuristicsY  s      9$Q000Q 2 " " 	 	 	 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )Nu7   et là il est monté sur moi et il commence à m'éto.
u               Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit

            et là il est monté sur moi et il commence à m'éto.
            r   Tr   r#   r   rd   r$   bytesr   r   r   re   r   r%   r   s      r   5test_set_text_short_line_minimal_non_ascii_heuristicszHTestRawDataManager.test_set_text_short_line_minimal_non_ascii_heuristicsh  s      L$Q000q8? 4 $ $
 	" 	" 	" 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )Nus   j'ai un problème de python. il est sorti de son vivarium.  et là il est monté sur moi et il commence à m'éto.
a*              Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: quoted-printable

            j'ai un probl=C3=A8me de python. il est sorti de son vivari=
            um.  et l=C3=A0 il est mont=C3=A9 sur moi et il commence =
            =C3=A0 m'=C3=A9to.
            r   Tr   r   r   s      r   4test_set_text_long_line_minimal_non_ascii_heuristicszGTestRawDataManager.test_set_text_long_line_minimal_non_ascii_heuristicsu  s      # 	$Q000q8? 4 $ $ 	" 	" 	" 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )Nu}   









j'ai un problème de python. il est sorti de son vivarium.  et là il est monté sur moi et il commence à m'éto.
a@              Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: quoted-printable
            










            j'ai un probl=C3=A8me de python. il est sorti de son vivari=
            um.  et l=C3=A0 il est mont=C3=A9 sur moi et il commence =
            =C3=A0 m'=C3=A9to.
            r   Tr   r   r   s      r   =test_set_text_11_lines_long_line_minimal_non_ascii_heuristicszPTestRawDataManager.test_set_text_11_lines_long_line_minimal_non_ascii_heuristics  s      # 	$Q000q8? 4 $ $ 	" 	" 	" 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )N   áàäéèęöő.
u               Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit

            áàäéèęöő.
            r   Tr   r   r   s      r   *test_set_text_maximal_non_ascii_heuristicsz=TestRawDataManager.test_set_text_maximal_non_ascii_heuristics  s      '$Q000q8? 4 $ $
 	" 	" 	" 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )Nu   









áàäéèęöő.
u               Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit
            










            áàäéèęöő.
            r   Tr   r   r   s      r   3test_set_text_11_lines_maximal_non_ascii_heuristicszFTestRawDataManager.test_set_text_11_lines_maximal_non_ascii_heuristics  s      1$Q000q8? 4 $ $
 	" 	" 	" 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        ||           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )Nu   áàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöő.
a              Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: base64

            w6HDoMOkw6nDqMSZw7bFkcOhw6DDpMOpw6jEmcO2xZHDocOgw6TDqcOoxJnD
            tsWRw6HDoMOkw6nDqMSZw7bFkcOhw6DDpMOpw6jEmcO2xZHDocOgw6TDqcOo
            xJnDtsWRw6HDoMOkw6nDqMSZw7bFkcOhw6DDpMOpw6jEmcO2xZHDocOgw6TD
            qcOoxJnDtsWRw6HDoMOkw6nDqMSZw7bFkcOhw6DDpMOpw6jEmcO2xZHDocOg
            w6TDqcOoxJnDtsWRLgo=
            r   Tr   r   r   s      r   4test_set_text_long_line_maximal_non_ascii_heuristicszGTestRawDataManager.test_set_text_long_line_maximal_non_ascii_heuristics  s      Y 	$Q000q8? 	4 	$ 	$ 		" 		" 		" 	d33::7CCWMMM'22222r   c                    |                                  }d}t          j        |d           |                     t	          |          t          j        d                              d                     |                     |                    d          	                    d          |           |                     |
                                |           d S )Nu   









áàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöőáàäéèęöő.
ak              Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: quoted-printable
            










            =C3=A1=C3=A0=C3=A4=C3=A9=C3=A8=C4=99=C3=B6=C5=91=C3=A1=C3=
            =A0=C3=A4=C3=A9=C3=A8=C4=99=C3=B6=C5=91=C3=A1=C3=A0=C3=A4=
            =C3=A9=C3=A8=C4=99=C3=B6=C5=91=C3=A1=C3=A0=C3=A4=C3=A9=C3=
            =A8=C4=99=C3=B6=C5=91=C3=A1=C3=A0=C3=A4=C3=A9=C3=A8=C4=99=
            =C3=B6=C5=91=C3=A1=C3=A0=C3=A4=C3=A9=C3=A8=C4=99=C3=B6=C5=
            =91=C3=A1=C3=A0=C3=A4=C3=A9=C3=A8=C4=99=C3=B6=C5=91=C3=A1=
            =C3=A0=C3=A4=C3=A9=C3=A8=C4=99=C3=B6=C5=91=C3=A1=C3=A0=C3=
            =A4=C3=A9=C3=A8=C4=99=C3=B6=C5=91=C3=A1=C3=A0=C3=A4=C3=A9=
            =C3=A8=C4=99=C3=B6=C5=91=C3=A1=C3=A0=C3=A4=C3=A9=C3=A8=C4=
            =99=C3=B6=C5=91=C3=A1=C3=A0=C3=A4=C3=A9=C3=A8=C4=99=C3=B6=
            =C5=91.
            r   Tr   r   r   s      r   =test_set_text_11_lines_long_line_maximal_non_ascii_heuristicszPTestRawDataManager.test_set_text_11_lines_long_line_maximal_non_ascii_heuristics  s       Y 	$Q )n 	o 	o 	o 	q8? 4 $ $ 	" 	" 	"  	d33::7CCWMMM'22222r   c                     |                                  }|                     t                    5  t          j        |dd           d d d            d S # 1 swxY w Y   d S )Nr   7bitcter#   rt   UnicodeErrorr   rd   r   s     r   ,test_set_text_non_ascii_with_cte_7bit_raisesz?TestRawDataManager.test_set_text_non_ascii_with_cte_7bit_raises  s      |,, 	N 	N(+@fMMMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N   AAAc                     |                                  }|                     t                    5  t          j        |dd           d d d            d S # 1 swxY w Y   d S )Nr   asciir   r   r   s     r   1test_set_text_non_ascii_with_charset_ascii_raiseszDTestRawDataManager.test_set_text_non_ascii_with_charset_ascii_raises  s      |,, 	S 	S(+@'RRRR	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	Sr   c                     |                                  }|                     t                    5  t          j        |ddd           d d d            d S # 1 swxY w Y   d S )Nr   r   r   )r   r   r   r   s     r   >test_set_text_non_ascii_with_cte_7bit_and_charset_ascii_raiseszQTestRawDataManager.test_set_text_non_ascii_with_cte_7bit_and_charset_ascii_raises  s      |,, 	_ 	_(+@fV]^^^^	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_s   AAAc                    |                                  }d|d<   |                                  }d|d<   d|d<   d|d<   |                    d           t          j        ||           |                     t	          |          t          j        d	                     |                    d
          }|                     || j	                   |                     t	          |          t	          |                     |                     |
                                | j	                   |                     t	          |
                                          t	          |                     d S )NzForwarded messageSubjectzpython@vivarium.orgry   police@monty.orgFromzget back in your boxzOr face the comfy chair.a              Subject: Forwarded message
            Content-Type: message/rfc822
            Content-Transfer-Encoding: 8bit

            To: python@vivarium.org
            From: police@monty.org
            Subject: get back in your box
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 7bit
            MIME-Version: 1.0

            Or face the comfy chair.
            r   )r#   rd   r   r$   rP   r   r   re   r   r   r%   )r&   r*   r   payloads       r   test_set_messagez#TestRawDataManager.test_set_message  sC     *)$$&&-,3	6777$Q000Q 2 " " 	 	 	 --""gt|444Ws7||444ammoot|<<<Q]]__--s7||<<<<<r   c                    |                                  }d|d<   |                                  }d|d<   d|d<   d|d<   |                    d           t          j        ||           |                     t	          |          t          j        d	                              d
                     |                     |                    | j	        j
                  t          j        d                     |                     |                                | j                   |                     t          |                                          t          |                     d S )NzEscape reportr   r   ry   zvictim@monty.orgr   Helpu:   j'ai un problème de python. il est sorti de son vivarium.u              Subject: Escape report
            Content-Type: message/rfc822
            Content-Transfer-Encoding: 8bit

            To: police@monty.org
            From: victim@monty.org
            Subject: Help
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit
            MIME-Version: 1.0

            j'ai un problème de python. il est sorti de son vivarium.
            r   )maxheaderlena              Subject: Escape report
            Content-Type: message/rfc822
            Content-Transfer-Encoding: 8bit

            To: police@monty.org
            From: victim@monty.org
            Subject: Help
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: base64
            MIME-Version: 1.0

            aidhaSB1biBwcm9ibMOobWUgZGUgcHl0aG9uLiBpbCBlc3Qgc29ydGkgZGUgc29uIHZpdmFyaXVt
            Lgo=
            )r#   rd   r   r$   r   r   r   r   	as_stringr   r   r   r%   r   rP   r   s      r   4test_set_message_with_non_ascii_and_coercion_to_7bitzGTestRawDataManager.test_set_message_with_non_ascii_and_coercion_to_7bit  sP     &)$$&&*,#	 ) 	* 	* 	*$Q000q8? 4 $ $ 	" 	" 	"& 	$+2MNN! *  	 	 	  	ammoot|<<<Q]]__--s7||<<<<<r   c           	         |                                  }|                                  }d                                D ]}d                                D ]}|                     ||          5  |                     t                    5 }|                    |||           d d d            n# 1 swxY w Y   t          |j                  }|                     ||           |                     ||           d d d            n# 1 swxY w Y   d}d                                D ]}|                     ||          5  |                     t                    5 }|                    |||           d d d            n# 1 swxY w Y   t          |j                  }|                     ||           |                     ||           d d d            n# 1 swxY w Y   d S )Nzquoted-printable base64r   )r   r   r   external-bodyz8bit binary)	r#   r   r   rt   
ValueErrorrd   rP   	exceptionassertIn)r&   r*   r   r   r   arexcs          r   #test_set_message_invalid_cte_raisesz6TestRawDataManager.test_set_message_invalid_cte_raises@  s     $$&&,2244 	0 	0C17799 0 0\\c7\;; 0 0**:66 A"gwC@@@A A A A A A A A A A A A A A Abl++CMM#s+++MM'3///0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 " &&(( 	, 	,C#w77 , ,&&z22 =bMM'7M<<<= = = = = = = = = = = = = = =",''c3'''gs+++, , , , , , , , , , , , , , ,	, 	,sn   ,DB,	 D,B00D3B04ADD
D?GE?3G?FGFAGG	G	c                 
   dt          d          t          d          fD ]}|                     |          5  |                                 }t	          j        ||dd           |                     t          |          t          j	        d                     |                     |
                    d          |           |                     |                                |           d d d            n# 1 swxY w Y   d S )Ns   bogus content)r   imagejpegz                    Content-Type: image/jpeg
                    Content-Transfer-Encoding: base64

                    Ym9ndXMgY29udGVudA==
                    Tr   )	bytearray
memoryviewr   r#   r   rd   r$   rP   r   r   re   r%   )r&   r   r*   s      r   test_set_image_jpgz%TestRawDataManager.test_set_image_jpgT  sC   (!"233"#3446 	; 	;G g.. 
; 
;&&(( ,Q&III  Q : * *      d!;!;WEEE  ':::
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
; 
;	; 	;s   B3C77C;	>C;	c                    |                                  }d}|                    |ddd           |                     t          |          t	          j        d                              d                     |                     |                    d	          |           |                     |                                |           d S )
Nt   bgus	con
tent zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaudioaifzquoted-printabler   a              Content-Type: audio/aif
            Content-Transfer-Encoding: quoted-printable
            MIME-Version: 1.0

            b=FFgus=09con=0At=0Dent=20zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=
            zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzr   Tr   	r#   rd   r$   r   r   r   r   re   r%   r   s      r   ,test_set_audio_aif_with_quoted_printable_ctez?TestRawDataManager.test_set_audio_aif_with_quoted_printable_cted  s       6	gw3EFFFq8? 4C $D $D EKF9DUDU	W 	W 	W 	d33W==='22222r   c                    |                                  }d}|                    |ddd           |                     t          |          t	          j        d                              d          dz   d	z              |                     |                    d
          |           |                     |                                |           d S )Nr  videompegbinaryr   z~            Content-Type: video/mpeg
            Content-Transfer-Encoding: binary
            MIME-Version: 1.0

            r   s7   bgus	con
t
ent zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzs=   zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzTr   r  r   s      r   #test_set_video_mpeg_with_binary_ctez6TestRawDataManager.test_set_video_mpeg_with_binary_ctez  s      6	gwH===q8? 4 $ $
  M$M M	$M 		N 		N 		N 	d33W==='22222r   c                    |                                  }d}|                    |ddd           |                     t          |          t	          j        d                              d          dz   d	z              |                     |                    d
          |           |                     |                                |           d S )NsM   bgus	con
tent
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
applicationoctet-stream8bitr   z            Content-Type: application/octet-stream
            Content-Transfer-Encoding: 8bit
            MIME-Version: 1.0

            r   s   bgus	con
t
ent
s=   zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Tr   r  r   s      r   /test_set_application_octet_stream_with_8bit_ctezBTestRawDataManager.test_set_application_octet_stream_with_8bit_cte  s       >	g}n&IIIq8? 4 $ $
 &$' N$N 	O 	O 	O 	d33W==='22222r   c           
      $   |                                  }d}| j        j        }t          j        || |dd           |dd           |dd          f           |                     t          |          t          j        d                     d S )	Nr   ry   r   r   r   zI'm talking to myself.headersz            Content-Type: text/plain; charset="utf-8"
            To: foo@example.com
            From: foo@example.com
            Subject: I'm talking to myself.
            Content-Transfer-Encoding: 7bit

            Simple message.
            )	r#   r   header_factoryr   rd   r$   rP   r   r   r&   r*   r   r'  s       r   $test_set_headers_from_header_objectsz7TestRawDataManager.test_set_headers_from_header_objects  s      %3$QN4!233N6#455N9&>??:A 	B 	B 	B 	B 	Q 2 " " 	 	 	 	 	r   c                     |                                  }d}t          j        ||d           |                     t	          |          t          j        d                     d S )Nr   )zX-Foo-Header: foozX-Bar-Header: barr%  z            Content-Type: text/plain; charset="utf-8"
            X-Foo-Header: foo
            X-Bar-Header: bar
            Content-Transfer-Encoding: 7bit

            Simple message.
            )r#   r   rd   r$   rP   r   r   r   s      r   test_set_headers_from_stringsz0TestRawDataManager.test_set_headers_from_strings  sz      %$Q :" 	# 	# 	# 	# 	Q 2 " " 	 	 	 	 	r   c                     |                                  }d}|                     t          d          5  t          j        ||d           d d d            d S # 1 swxY w Y   d S )Nr   r   )zContent-Type: foo/barr%  )r#   r9   r  r   rd   r   s      r   <test_set_headers_with_invalid_duplicate_string_header_raiseszOTestRawDataManager.test_set_headers_with_invalid_duplicate_string_header_raises  s      %##J?? 	 	(G >*    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc           	          |                                  }d}| j        j        }|                     t          d          5  t          j        || |dd          f           d d d            d S # 1 swxY w Y   d S )Nr   r   z foo/barr%  )r#   r   r'  r9   r  r   rd   r(  s       r   <test_set_headers_with_invalid_duplicate_header_header_raiseszOTestRawDataManager.test_set_headers_with_invalid_duplicate_header_header_raises  s      %3##J?? 	 	(G~z::>=    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   #A..A25A2c                     |                                  }d}|                     t          d          5  t          j        ||d           t          |d         j                   d d d            d S # 1 swxY w Y   d S )Nr   a@fairly@@invalid@address)zTo: a@fairly@@invalid@addressr%  ry   )r#   r9   r  r   rd   printdefectsr   s      r   4test_set_headers_with_defective_string_header_raiseszGTestRawDataManager.test_set_headers_with_defective_string_header_raises  s      %##J0KLL 	# 	#(G >2     !D'/"""		# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   2A11A58A5c           	      *   |                                  }d}| j        j        }|                     t          d          5  t          j        || |dd          f           t          |d         j                   d d d            d S # 1 swxY w Y   d S )Nr   r1  ry   r%  )	r#   r   r'  r9   r  r   rd   r2  r3  r(  s       r   4test_set_headers_with_defective_header_header_raiseszGTestRawDataManager.test_set_headers_with_defective_header_header_raises  s      %3##J0KLL 	# 	#(Gt%@AA>D     !D'/"""		# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   =BBBc                     |                                  }|                    dd           |                     |d         d           d S )Nr   inlinedispositionContent-Dispositionr#   rd   r$   r   s     r   test_set_disposition_inlinez.TestRawDataManager.test_set_disposition_inline  sK      	e222018<<<<<r   c                     |                                  }|                    dd           |                     |d         d           d S )Nr   
attachmentr9  r;  r<  r   s     r   test_set_disposition_attachmentz2TestRawDataManager.test_set_disposition_attachment  sK      	e66601<@@@@@r   c                     |                                  }|                    dd           |                     |d         d           d S )Nr   r9  r;  r<  r   s     r   test_set_disposition_fooz+TestRawDataManager.test_set_disposition_foo  sK      	e///01599999r   c                     |                                  }|                    dd           |                     |d         d           d S )Nr   bar.txtfilenamer;  zattachment; filename="bar.txt"r<  r   s     r   test_set_filenamez$TestRawDataManager.test_set_filename  sV      	ei000019	; 	; 	; 	; 	;r   c                     |                                  }|                    ddd           |                     |d         d           d S )Nr   r8  rD  r:  rF  r;  zinline; filename="bar.txt"r<  r   s     r   (test_set_filename_and_disposition_inlinez;TestRawDataManager.test_set_filename_and_disposition_inline  sN      	eIFFF013OPPPPPr   c                     |                                  }|                    dd           |                     t          |          t	          j        d                              d                     d S )Nr   u   ábárî.txtrE  a              Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 7bit
            Content-Disposition: attachment;
             filename*=utf-8''%C3%A1b%C3%A1r%C3%AE.txt
            MIME-Version: 1.0

            foo
            r   )r#   rd   r$   r   r   r   r   r   s     r   test_set_non_ascii_filenamez.TestRawDataManager.test_set_non_ascii_filename  ss      	en555q8? 4 $ $ 	" 	" 	" 	" 	"r   c                     |                                  }|                    dddd           |                     t          |          t	          j        d                     d S )Ns   ASCII-only message.
r   r!  r   )r   r   r   z            Content-Type: application/octet-stream
            Content-Transfer-Encoding: 7bit
            MIME-Version: 1.0

            ASCII-only message.
            )r#   rd   r$   rP   r   r   r   s     r   test_set_content_bytes_cte_7bitz2TestRawDataManager.test_set_content_bytes_cte_7bit  sx      	."N 	 	H 	H 	HQ 2 " " 	 	 	 	 	r   )r   r   )r   )r   )   content)r   octet_stream)rO  )r  r  r   )r  )
text_plain	text_htmlapplication_octet_stream
image_jpegmessage_rfc822message_external_bodyc                     |                                  } |j        |g|R ddi |                     |d         d           |                     |d         d           d S )Nr&  )zTo: foo@example.comzFrom: bar@simple.netr   r   r   zbar@simple.netr<  r&   ra   mimetyper*   s       r   !content_object_as_header_receiverz4TestRawDataManager.content_object_as_header_receiver!  s      c 	%H 	% 	% 	% /$ 	% 	% 	% 	4"34446$455555r   c                     |                                  } |j        |g|R ddi |                     |d         d           d S )Nr:  r8  r;  r<  rX  s       r   -content_object_as_disposition_inline_receiverz@TestRawDataManager.content_object_as_disposition_inline_receiver)  sW      c;H;;;(;;;018<<<<<r   c                 (   |                                  } |j        |g|R ddd |                     |d         d           |                     |                                d           |                     |d         j        d         d           d S )Nr8  u   bár.txtrI  r;  u   inline; filename="bár.txt"rF  )r#   rd   r$   get_filenameparamsrX  s       r   -content_object_as_non_ascii_filename_receiverz@TestRawDataManager.content_object_as_non_ascii_filename_receiver.  s      cPHPP(ZPPPP013PQQQ)):666018DjQQQQQr   c                     |                                  } |j        |g|R ddi |                     |d         d           d S )Ncidsome_random_stuffz
Content-IDr<  rX  s       r   content_object_as_cid_receiverz1TestRawDataManager.content_object_as_cid_receiver5  sW      c>H>>>*=>>><*=>>>>>r   c                     |                                  }ddd} |j        |g|R d|i t          |t                    rd|d<   |                     |d         j        |           d S )Nu   bárr   )r   rz   r_  r   r   r   )r#   rd   
isinstancerP   r$   r_  )r&   ra   rY  r*   r_  s        r   !content_object_as_params_receiverz4TestRawDataManager.content_object_as_params_receiver:  s      ..c4H444V444c3 	( 'F9>*16:::::r   N)@r@   rA   rB   r   r   cloner   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r#  r)  r+  r-  r/  r4  r6  r=  r@  rB  rG  rJ  rL  rN  content_object_paramsrZ  r\  r`  rd  rg  r   r   r   r   r      s        ^!!"2B " D DFGK K K1 1 1M M MM M MM M MP P P, , ,, , ,: : :
Q 
Q 
Q= = =, , ,O O O(
N 
N 
N3 3 30 0 03 3 33 3 33 3 33 3 33 3 3"3 3 3$3 3 33 3 33 3 3&3 3 3>N N N
S S S
_ _ _
= = =:.= .= .=`, , ,(; ; ; 3 3 3,3 3 3"3 3 3"  $      # # ## # #= = =
A A A
: : :; ; ;Q Q Q
" " "
 
 
 &+%F5"799b/")'))-?!@
 
6 6 6= = =
R R R? ? ?
; ; ; ; ;r   r   __main__)unittesttest.test_emailr   r   r   emailr   email.messager   email.contentmanagerr   r   r
   r   r@   mainr   r   r   <module>rq     s    7 7 7 7 7 7 7 7        & & & & & & A A A A A A A A z+ z+ z+ z+ z+ z+ z+ z+z x
; x
; x
; x
; x
; x
; x
; x
;v zHMOOOOO r   