
    z%i/                         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                   N   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yc c}} w )TestGeneratorBaseNc                 H    || j                   n|}| j                  ||      S )Nr	   )r
   msgfunc)selfmsgr
   s      R/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/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                 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
   rG   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
   rJ   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   rH   rI   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 )NrU   z            To: nobody
            Content-Disposition:
             attachment;
             filename*0*=us-ascii''afilenamelongenoghtowraphere

            None
            r   r*   r	   rW   rX   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
   rK   r   rH   rI   r   copyr9   length_paramsr'   r.   r1   r6   r:   rA   rE   rQ   rS   rY   r[   ).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                   <    e Zd Z ee      ZeZej                  Z
eZy)TestGeneratorN)r\   r]   r^   staticmethodr   r   r   r   ioStringIOr   strr    r   r   rc   rc      s     ./GHkkG
Cr   rc   c                   V    e Zd Z ee      ZeZej                  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                 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?=

rl   7bit)cte_typer	   )
rm   r   re   BytesIOr   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?
            rl   rr   rC   )rs   rD   r	   )rH   rI   rm   r   re   rt   r   r
   r-   r    r!   r"   )r   r?   r   r@   r%   r&   s         r   &test_cte_type_7bit_transforms_8bit_ctez9TestBytesGenerator.test_cte_type_7bit_transforms_8bit_cte   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 ὠ9Subjectu/   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?
            rq      
   
r	   )r   set_contentrH   rI   rm   rL   re   rt   r   r
   SMTPUTF8r    r!   r"   rX   s        r   test_smtputf8_policyz'TestBytesGenerator.test_smtputf8_policy  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_namerz   zbar@foo.comr{   r|   zNudge nudge, wink, winkr}   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   rH   rI   rm   rL   re   rt   r   r
   r=   r    r!   r"   rX   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)r\   r]   r^   rd   r   r   r   r   re   rt   r   r   ru   rx   r   r   rh   r   r   rj   rj      s4    -.GHjjG
+C	1181*1r   rj   __main__)re   rH   unittestemailr   r   email.messager   email.generatorr   r   email.headerregistryr   r
   test.test_emailr   r   r   rc   rj   r\   mainrh   r   r   <module>r      sx    	   9 & 5 (  7 L; L; L;^%} V1*M V1r zHMMO r   