
    daf=                         d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ e G d d	             Z G d
 dee      Z G d dee      Zedk(  r ej*                          yy)    N)message_from_stringmessage_from_bytes)EmailMessage)	GeneratorBytesGenerator)Addresspolicy)TestEmailBaseparameterizec                   Z   e Zd Zej                  ZddZ ej                  d       ej                  d       ej                  d      dZed   ed<   ej                         Z
d	e
d<   d
e
d<   eD  cg c]  }| c}} Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zyc c}} w )TestGeneratorBaseNc                 H    || j                   n|}| j                  ||      S )Nr	   )r
   msgfunc)selfmsgr
   s      9/root/Python-3.12.4/Lib/test/test_email/test_generator.pymsgmakerzTestGeneratorBase.msgmaker   s$     &F||C|//    af              To: whom_it_may_concern@example.com
            From: nobody_you_want_to_know@example.com
            Subject: We the willing led by the unknowing are doing the
             impossible for the ungrateful. We have done so much for so long with so little
             we are now qualified to do anything with nothing.

            None
            a              To: whom_it_may_concern@example.com
            From:
             nobody_you_want_to_know@example.com
            Subject: We the willing led by the
             unknowing are doing the impossible for
             the ungrateful. We have done so much
             for so long with so little we are now
             qualified to do anything with nothing.

            None
            a              To:
             whom_it_may_concern@example.com
            From:
             nobody_you_want_to_know@example.com
            Subject: We the
             willing led by the
             unknowing are doing
             the impossible for
             the ungrateful. We
             have done so much
             for so long with so
             little we are now
             qualified to do
             anything with
             nothing.

            None
            )r   (      r   d   a  To: whom_it_may_concern@example.com
From: nobody_you_want_to_know@example.com
Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing.

None
a  To: whom_it_may_concern@example.com
From: nobody_you_want_to_know@example.com
Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have
 done so much for so long with so little we are now qualified to do anything with nothing.

None
c                 T   | j                  | j                  | j                  d               }| j                         }| j	                  ||| j
                        }|j                  |       | j                  |j                         | j                  | j                  |                y )Nr   maxheaderlenr
   )	r   typrefold_long_expectedioclassgenclassr
   flattenassertEqualgetvaluer   nr   sgs        r    length_as_maxheaderlen_parameterz2TestGeneratorBase.length_as_maxheaderlen_parameterW   s|    mmDHHT%>%>q%ABCLLNMM!!DKKM@			#txx0I0I!0L'MNr   c                 r   | j                  | j                  | j                  d               }| j                         }| j	                  || j
                  j                  |            }|j                  |       | j                  |j                         | j                  | j                  |                y Nr   max_line_lengthr	   
r   r   r   r   r   r
   cloner    r!   r"   r#   s        r    length_as_max_line_length_policyz2TestGeneratorBase.length_as_max_line_length_policy^   s    mmDHHT%>%>q%ABCLLNMM!DKK$5$5a$5$HMI			#txx0I0I!0L'MNr   c                 t   | j                  | j                  | j                  d               }| j                         }| j	                  ||| j
                  j                  d            }|j                  |       | j                  |j                         | j                  | j                  |                y )Nr   
   r*   r   r,   r#   s        r   ,length_as_maxheaderlen_parm_overrides_policyz>TestGeneratorBase.length_as_maxheaderlen_parm_overrides_policye   s    mmDHHT%>%>q%ABCLLNMM!!!%!2!22!2!F  H			#txx0I0I!0L'MNr   c                 t   | j                  | j                  | j                  d               }| j                         }| j	                  || j
                  j                  d|            }|j                  |       | j                  |j                         | j                  | j                  d                y )Nr   nonerefold_sourcer+   r	   r,   r#   s        r   8length_as_max_line_length_with_refold_none_does_not_foldzJTestGeneratorBase.length_as_max_line_length_with_refold_none_does_not_foldm   s    mmDHHT%>%>q%ABCLLNMM!DKK$5$5FFG %6 %IM J			#txx0I0I!0L'MNr   c                 t   | j                  | j                  | j                  d               }| j                         }| j	                  || j
                  j                  d|            }|j                  |       | j                  |j                         | j                  | j                  |                y )Nr   allr4   r	   )r   r   r   r   r   r
   r-   r    r!   r"   refold_all_expectedr#   s        r   /length_as_max_line_length_with_refold_all_foldszATestGeneratorBase.length_as_max_line_length_with_refold_all_foldsu   s    mmDHHT%>%>q%ABCLLNMM!DKK$5$5EFG %6 %IM J			#txx0H0H0K'LMr   c                 .   d}|}| j                  | j                  |            }| j                         }| j                  |t        j
                        }|j                  |       | j                  |j                         | j                  |             y )NzSubject: test

test body
r	   	r   r   r   r   r
   SMTPr    r!   r"   r   sourceexpectedr   r%   r&   s         r   test_crlf_control_via_policyz.TestGeneratorBase.test_crlf_control_via_policy}   sn    5mmDHHV,-LLNMM!FKKM0			#txx'9:r   c                 2   d}|}| j                  | j                  |            }| j                         }| j                  |t        j
                        }|j                  |d       | j                  |j                         | j                  |             y )NzSubject: test

test body
r	   
)linesepr<   r>   s         r   %test_flatten_linesep_overrides_policyz7TestGeneratorBase.test_flatten_linesep_overrides_policy   ss    /mmDHHV,-LLNMM!FKKM0			#t	$txx'9:r   c                 6   d}| j                  | j                  |            }| j                  |d   d       d}| j                         }| j	                  |      }|j                  |       | j                  |j                         | j                  |             d}| j                         }| j	                  || j                  j                  d            }|j                  |       | j                  |j                         | j                  |             y )	Nz.Subject: one
 two three
 four

test body
Subjectzone two three fourz*Subject: one
 two
 three
 four

test body
z'Subject: one two three four

test body
r8   r5   r	   	r   r   r!   r   r   r    r"   r
   r-   r   r?   r   r@   r%   r&   s         r   test_flatten_linesepz&TestGeneratorBase.test_flatten_linesep   s    KmmDHHV,-Y)=>ELLNMM!			#txx'9:?LLNMM!DKK$5$5E$5$JMK			#txx'9:r   c                 2   d}| j                  | j                  |            }| j                  |d   d       d}| j                         }| j	                  |      }|j                  |       | j                  |j                         | j                  |             | j                         }| j	                  || j                  j                  d            }|j                  |       | j                  |j                         | j                  |             y )Nz8Subject: one two three four five six

test body
rG   z one two three four five sixz5Subject: one two three four five six

test body
r8   rH   r	   rI   rJ   s         r   test_flatten_control_linesepz.TestGeneratorBase.test_flatten_control_linesep   s    \mmDHHV,-Y)VWXLLNMM!			#txx'9:LLNMM!DKK$5$5E$5$JMK			#txx'9:r   c                 P   t        j                  d      }dt        j                  dft        j                  dft        j                  j                  d      dff}|D ]  \  }}|r|j                  dd      n|}| j                  ||      5  | j                  | j                  |            }| j                         }| j                  ||	      }|j                  |       | j                  |j                         | j                  |             d d d         y # 1 sw Y   xY w)
Nz            Subject: test that
             from is mangled in the body!

            From time to time I write a rhyme.
            )NTTF)mangle_from_zFrom z>From )r
   rO   r	   )textwrapdedentr
   compat32defaultr-   replacesubTestr   r   r   r   r    r!   r"   )	r   r?   variantspmangler@   r   r%   r&   s	            r   test_set_mangle_from_via_policyz1TestGeneratorBase.test_set_mangle_from_via_policy   s    "  __d#^^U#^^!!t!4d;	 " 	CIAv<Bv~~gx8HQV< CmmDHHV$45LLNMM!AM.		#  txx/ABC C	CC Cs   BDD%	c                 z   | j                  | j                  | j                  d               }| j                         }| j	                  |t
        j                  j                  d             }|j                  |       | j                  |j                         | j                  | j                  d                y r)   )r   r   r   r   r   r
   rR   r-   r    r!   r"   )r   r   r%   r&   s       r   5test_compat32_max_line_length_does_not_fold_when_nonezGTestGeneratorBase.test_compat32_max_line_length_does_not_fold_when_none   s    mmDHHT%>%>q%ABCLLNMM!FOO$9$9$$9$OMP			#txx0I0I!0L'MNr   c                    | j                  | j                  t        j                  d                  }t        j                  d      }| j	                         }| j                  || j                  j                  d            }|j                  |       | j                  |j                         | j                  |             y )N            To: nobody
            Content-Disposition: attachment;
             filename="afilenamelongenoghtowraphere"

            None
            z            To: nobody
            Content-Disposition: attachment;
             filename*0*=us-ascii''afilename;
             filename*1*=longenoghtowraphere

            None
            !   r*   r	   r   r   rP   rQ   r   r   r
   r-   r    r!   r"   r   r   r@   r%   r&   s        r   test_rfc2231_wrappingz'TestGeneratorBase.test_rfc2231_wrapping   s     mmDHHX__ 6 &   ?? $  LLNMM!DKK$5$5b$5$IMJ			#txx'9:r   c                    | j                  | j                  t        j                  d                  }t        j                  d      }| j	                         }| j                  || j                  j                  d            }|j                  |       | j                  |j                         | j                  |             y )Nr]   z            To: nobody
            Content-Disposition:
             attachment;
             filename*0*=us-ascii''afilenamelongenoghtowraphere

            None
            r   r*   r	   r_   r`   s        r   ;test_rfc2231_wrapping_switches_to_default_len_if_too_narrowzMTestGeneratorBase.test_rfc2231_wrapping_switches_to_default_len_if_too_narrow   s     mmDHHX__ 6 &   ?? $  LLNMM!DKK$5$5b$5$IMJ			#txx'9:r   )N)__name__
__module____qualname__r
   rS   r   rP   rQ   r   copyr9   length_paramsr'   r.   r1   r6   r:   rA   rE   rK   rM   rY   r[   ra   rc   ).0r$   s   00r   r   r      s     ^^F0
 8??   HOO   HOO  -)
T !5Q 7.335   !551Q5MOOOON;;;"; C,O;.;_ 6s   2	B'r   c                   B    e Zd Z ee      ZeZej                  Z
eZd Zy)TestGeneratorc                 2   d}| j                  | j                  |            }| j                  |d   d       d}| j                         }| j	                  |      }|j                  |       | j                  |j                         | j                  |             | j                         }| j	                  || j                  j                  d            }|j                  |       | j                  |j                         | j                  |             y )Nu2   Subject: one two  three  four

test body
rG   u   one two  three  fourzBSubject: =?utf-8?b?b25lwoUgdHdv4oCoIHRocmVl4oCp?= four

test body
r8   rH   r	   rI   rJ   s         r   test_flatten_unicode_linesepz*TestGenerator.test_flatten_unicode_linesep  s    SmmDHHV,-Y)MNZLLNMM!			#txx'9:LLNMM!DKK$5$5E$5$JMK			#txx'9:r   N)rd   re   rf   staticmethodr   r   r   r   ioStringIOr   strr   rm    r   r   rk   rk      s%    ./GHkkG
C;r   rk   c                   h    e Zd Z ee      ZeZej                  Z
d Zd Zd Zd Zd Zd Zd Zd Zy	)
TestBytesGeneratorc                 $    |j                  d      S )Nascii)encode)r   xs     r   <lambda>zTestBytesGenerator.<lambda>  s    !((7+ r   c                     d}dj                  d      }t               }||d<   t        j                         }t	        |      }|j                  |       | j                  |j                         |       y )Nux   Уведомление о принятии в работу обращения для подключения услугиzSubject: =?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtSDQviDQv9GA0LjQvdGP0YLQuNC4?=
 =?utf-8?b?INCyINGA0LDQsdC+0YLRgyDQvtCx0YDQsNGJ0LXQvdC40Y8g0LTQu9GPINC/0L4=?=
 =?utf-8?b?0LTQutC70Y7Rh9C10L3QuNGPINGD0YHQu9GD0LPQuA==?=

rv   rG   )rw   r   ro   BytesIOr   r    r!   r"   r>   s         r   =test_defaults_handle_spaces_between_encoded_words_when_foldedzPTestBytesGenerator.test_defaults_handle_spaces_between_encoded_words_when_folded  sh    9TU[U[\cUd 	 nIJJL1			#x0r   c                     d}d}t               }||d<   t        j                         }t        |      }|j	                  |       | j                  |j                         |       y )Nu    Уведомлениеs8   Subject:  =?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtQ==?=

rG   r   ro   r{   r   r    r!   r"   r>   s         r   /test_defaults_handle_spaces_at_start_of_subjectzBTestBytesGenerator.test_defaults_handle_spaces_at_start_of_subject)  sR    *PnIJJL1			#x0r   c                     d}d}t               }||d<   t        j                         }t        |      }|j	                  |       | j                  |j                         |       y )Nu0    ф ффффффффффффффффффф ф фsf   Subject:  =?utf-8?b?0YQg0YTRhNGE0YTRhNGE0YTRhNGE0YTRhNGE0YTRhNGE0YTRhNGE0YQ=?=
 =?utf-8?b?INGEINGE?=

rG   r~   r>   s         r   9test_defaults_handle_spaces_at_start_of_continuation_linezLTestBytesGenerator.test_defaults_handle_spaces_at_start_of_continuation_line3  sV    C1 nIJJL1			#x0r   c                 6   dj                  d      }dj                  d      }t        |      }t        j                         }t	        || j
                  j                  d            }|j                  |       | j                  |j                         |       y )Nu5   Subject: Maintenant je vous présente mon collègue

utf-8zPSubject: Maintenant je vous =?unknown-8bit?q?pr=C3=A9sente_mon_coll=C3=A8gue?=

rv   7bit)cte_typer	   )
rw   r   ro   r{   r   r
   r-   r    r!   r"   r>   s         r   'test_cte_type_7bit_handles_unknown_8bitz:TestBytesGenerator.test_cte_type_7bit_handles_unknown_8bit?  s|    !"(&/ 	<=CVG_ 	 (JJL1T[[%6%6%6%GH			#x0r   c                    t        j                  d      j                  d      }t        |      }t        j                  d      j                  d      }t	        j
                         }t        || j                  j                  dd            }|j                  |       | j                  |j                         |       y )	Nu/              From: foo@bar.com
            To: Dinsdale
            Subject: Nudge nudge, wink, wink
            Mime-Version: 1.0
            Content-Type: text/plain; charset="latin-1"
            Content-Transfer-Encoding: 8bit

            oh là là, know what I mean, know what I mean?
            latin1a@              From: foo@bar.com
            To: Dinsdale
            Subject: Nudge nudge, wink, wink
            Mime-Version: 1.0
            Content-Type: text/plain; charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            oh l=E0 l=E0, know what I mean, know what I mean?
            rv   r   rC   )r   rD   r	   )rP   rQ   rw   r   ro   r{   r   r
   r-   r    r!   r"   rJ   s         r   &test_cte_type_7bit_transforms_8bit_ctez9TestBytesGenerator.test_cte_type_7bit_transforms_8bit_cteJ  s     	" 	 ! 	 !(OO 	% 	  	 JJL1T[[%6%6?C &7 &E F			#x0r   c                    t               }d|d<   d|d<   d|d<   |j                  d       t        j                  d      j	                  d	      j                  d
d      }t        j                         }t        |t        j                        }|j                  |       | j                  |j                         |       y )Nu   Páolo <főo@bar.com>FromDinsdaleTou   Nudge nudge, wink, wink ὠ9rG   u/   oh là là, know what I mean, know what I mean?u<              From: Páolo <főo@bar.com>
            To: Dinsdale
            Subject: Nudge nudge, wink, wink ὠ9
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit
            MIME-Version: 1.0

            oh là là, know what I mean, know what I mean?
            r      
   
r	   )r   set_contentrP   rQ   rw   rT   ro   r{   r   r
   SMTPUTF8r    r!   r"   r`   s        r   test_smtputf8_policyz'TestBytesGenerator.test_smtputf8_policyf  s    n-FD	:IIJ?? 	$ 	 !8 	 JJL1V__5			#x0r   c                    t               }t        dd      |d<   t        dd      |d<   d|d	<   |j                  d
       t        j                  d      j                         j                  dd      }t        j                         }t        |t        j                        }|j                  |       | j                  |j                         |       y )Nzfoo@bar.comu   Páolo)	addr_specdisplay_namer   zbar@foo.comr   r   zNudge nudge, wink, winkrG   z+oh boy, know what I mean, know what I mean?aP              From: =?utf-8?q?P=C3=A1olo?= <foo@bar.com>
            To: Dinsdale <bar@foo.com>
            Subject: Nudge nudge, wink, wink
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 7bit
            MIME-Version: 1.0

            oh boy, know what I mean, know what I mean?
            r   r   r	   )r   r   r   rP   rQ   rw   rT   ro   r{   r   r
   r=   r    r!   r"   r`   s        r   test_smtp_policyz#TestBytesGenerator.test_smtp_policy{  s    nHMFm*MD	2IEF?? 	$ 	 ''%1 	 JJL1V[[1			#x0r   N)rd   re   rf   rn   r   r   r   r   ro   r{   r   r   r|   r   r   r   r   r   r   rr   r   r   rt   rt     sC    -.GHjjG
+C11
1	1181*1r   rt   __main__)ro   rP   unittestemailr   r   email.messager   email.generatorr   r   email.headerregistryr   r
   test.test_emailr   r   r   rk   rt   rd   mainrr   r   r   <module>r      sx    	   9 & 5 (  7 m; m; m;`;%} ;0y1*M y1x zHMMO r   