
    Vh                        d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlmZ d dlmZ  G d d	ej"                        Zy)
    )annotationsN)Message)BytesIOStringIO)IOAnyStrCallable)bounce)unittestc                  H    e Zd ZdZddZddZddZ	 	 	 	 	 	 	 	 d	dZddZy)
BounceTestsz#
    Bounce message generation
    c                   t        j                  t        d      dd      \  }}}| j                  |d       | j                  |d       t        j
                  j                         }|j                  t        |j                  d                  }| j                  |d   d       | j                  |d   d	       | j                  |d
   d       y)zN
        L{twisted.mail.bounce.generateBounce} can accept L{unicode}.
        zRFrom: Moshe Zadka <moshez@example.com>
To: nonexistent@example.org
Subject: test

moshez@example.comnonexistent@example.org       moshez@example.comutf-8ToFrompostmaster@example.orgsubject)Returned Mail: see transcript for detailsN)	r
   generateBouncer   assertEqualemailparserParserparsedecodeselffromAddresstosemailParsermesss         M/home/dcms/DCMS/lib/python3.12/site-packages/twisted/mail/test/test_bounce.pytest_bounceMessageUnicodez%BounceTests.test_bounceMessageUnicode   s     $22 !%
R 	c*23ll))+  !((7*;!<=d%9:f'?@i*UVr   c                   t        j                  t        d      dd      \  }}}| j                  |d       | j                  |d       t        j
                  j                         }|j                  t        |j                  d                  }| j                  |d   d       | j                  |d   d	       | j                  |d
   d       y)zL
        L{twisted.mail.bounce.generateBounce} can accept L{bytes}.
        R   From: Moshe Zadka <moshez@example.com>
To: nonexistent@example.org
Subject: test

r      nonexistent@example.orgr   r   r   r   r   r   r   r   N)
r
   r   r   r   r   r   r   r   r   r   r    s         r'   test_bounceMessageBytesz#BounceTests.test_bounceMessageBytes,   s     $22 "&
R 	c*23ll))+  !((7*;!<=d%9:f'?@i*UVr   c                F   t        j                  t        d      ddd      \  }}}| j                  |d       | j                  |d       t        j
                  j                         }|j                  t        |j                  d                  }| j                  |d   d       | j                  |d	   d
       | j                  |d   d       | j                  |j                                |j                         }| j                  |d   j                         d       y)z\
        Pass a custom transcript message to L{twisted.mail.bounce.generateBounce}.
        r*   r   r+   zCustom transcriptr   r   r   r   r   r   r   r   r   zCustom transcript
N)r
   r   r   r   r   r   r   r   r   r   
assertTrueis_multipartget_payload)r!   r"   r#   r$   r%   r&   partss          r'   "test_bounceMessageCustomTranscriptz.BounceTests.test_bounceMessageCustomTranscriptD   s	    $22 "&
R 	c*23ll))+  !((7*;!<=d%9:f'?@i*UV))+,#//1!H  "!	
r   c                t   t        j                   |||z         dd      \  }}}t        j                  j	                         }|j                  t        |j                  d                  }| j                  |d   d       | j                  |d   d       | j                  |d   d       | j                  |j                                |j                         }	|	d	   j                         }
t        |t              r|j                  d      }n|}|
d
   j                         }| j                  |dz   |       y)zU
        Pass a really big message to L{twisted.mail.bounce.generateBounce}.
        r   r   r   r   r   r   r   r      r   
N)r
   r   r   r   r   r   r   r   r   r.   r/   r0   
isinstancebytes)r!   headermessageioTyper"   r#   r$   r%   r&   r1   innerMessagemessageTextpls                r'   _bounceBigMessagezBounceTests._bounceBigMessagec   s    $226G#$&:<U
R ll))+  !((7*;!<=d%9:f'?@i*UV))+,#//1&+Ah&:&:&<gu%!..1K!Kq/--/dK0r   c                    d}| j                  |ddz  t               | j                  |j                  d      ddz  t               y)zj
        L{twisted.mail.bounce.generateBounce} with big L{unicode} and
        L{bytes} messages.
        r*   s
   Test test
i'  r   z
More test
N)r>   r   r   r   )r!   r8   s     r'   test_bounceBigMessagez!BounceTests.test_bounceBigMessage{   sB    
 	v~'=wGv}}W5}u7LhWr   N)returnNone)r8   r   r9   r   r:   zCallable[[AnyStr], IO[AnyStr]]rA   rB   )	__name__
__module____qualname____doc__r(   r,   r2   r>   r@    r   r'   r   r      sC    W0W0
>11'-17U1	10Xr   r   )
__future__r   email.messager   email.parserr   ior   r   typingr   r   r	   twisted.mailr
   twisted.trialr   TestCaser   rG   r   r'   <module>rP      s8    #   !   ' '  "xX(## xXr   