
    ;eN                     R   	 g d Z ddlZddl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 dZdZ ej        d          Z ej        d	ej                  Z G d
 d          Z G d de          ZdZ G d de          Z e eej        dz
                      Zdez  Zej        ZdS ))	GeneratorDecodedGeneratorBytesGenerator    N)deepcopy)StringIOBytesIO)_has_surrogates_
z
\r\n|\r|\nz^From c                       e Zd Z	 ddddZd ZddZd Zd Zd	 Zd
 Z	d Z
d Zd Zd ZeZd Zd Zd Zd Zedd            Zed             ZdS )r   Npolicyc                Z    	 ||dn|j         }|| _        || _        || _        || _        d S )NT)mangle_from__fp_mangle_from_maxheaderlenr   )selfoutfpr   r   r   s        &/usr/lib/python3.11/email/generator.py__init__zGenerator.__init__#   sA    	. #)>44v7JL)(    c                 :    | j                             |           d S N)r   writer   ss     r   r   zGenerator.writeC   s    qr   Fc                    	 | j         |j         n| j         }||                    |          }| j        |                    | j                  }|j        | _        |                     | j                  | _        d| _        |                     | j                  | _        | j         }|j         }	 || _         ||_         |r[|	                                }|s(dt          j        t          j
                              z   }|                     || j        z              |                     |           || _         ||_         d S # || _         ||_         w xY w)N)linesepmax_line_length zFrom nobody )r   cloner   r   _NL_encode_encoded_NL_EMPTY_encoded_EMPTYget_unixfromtimectimer   _write)r   msgunixfromr   r   old_gen_policyold_msg_policyufroms           r   flattenzGenerator.flattenG   sJ   	(  ${2\\'\22F(\\$2C\DDF><<11"ll4;77
 	( DKCJ -((** E*TZ	-D-DDE

548+,,,KK(DK'CJJJ )DK'CJ''''s   1B E Ec                 J    	 |                      || j        d | j                  S Nr   )	__class__r   r   )r   fps     r   r#   zGenerator.clonex   s0    ?~~b"0"%)[  2 2 	2r   c                     t                      S r   )r   r   s    r   _new_bufferzGenerator._new_buffer   s    zzr   c                     |S r    r   s     r   r%   zGenerator._encode   s    r   c                    |sd S t                               |          }|d d         D ]1}|                     |           |                     | j                   2|d         r|                     |d                    d S d S )N)NLCREsplitr   r$   )r   lineslines      r   _write_lineszGenerator._write_lines   s     	FE""#2#J 	! 	!DJJtJJtx    9 	"JJuRy!!!!!	" 	"r   c                 d   | j         }	 d | _        |                                 x| _         }|                     |           || _         | j        }| `n# || _         | j        }| `w xY w|rht	          |          }|                    d          |d         |d<   n|                    d|d                    |                    d|d                    t          |dd           }||                     |           n ||            | j         	                    |
                                           d S )Ncontent-transfer-encodingr   Content-Transfer-Encodingcontent-type   _write_headers)r   
_munge_cter9   	_dispatchr   getreplace_headergetattrrH   r   getvalue)r   r-   oldfpsfp	munge_ctemeths         r   r,   zGenerator._write   sD    	 "DO!--///DHsNN3DHI DHI 	=3--Cww233;3<Q</00""#>	!MMM~y|<<< s,d33<$$$$DJJJs||~~&&&&&s   7A A#c                 ^   |                                 }|                                }t                              ||f                              dd          }t          | d|z   d           }|3|                    dd          }t          | d|z   d           }|| j        } ||           d S )N-r
   _handle_)get_content_maintypeget_content_subtype
UNDERSCOREjoinreplacerM   
_writeBody)r   r-   mainsubspecificrR   generics          r   rJ   zGenerator._dispatch   s    
 ''))%%''??D#;//77SAAtZ(2D99<ll3,,G4g!5t<<D|S					r   c                     |                                 D ]3\  }}|                     | j                            ||                     4|                     | j                   d S r   )	raw_itemsr   r   foldr$   r   r-   hvs       r   rH   zGenerator._write_headers   s^    MMOO 	/ 	/DAqJJt{''1--....

48r   c                    |                                 }|d S t          |t                    st          dt	          |          z            t          |j                  rh|                    d          }|Qt          |          }|d= |	                    ||           |                                 }|d         |d         f| _
        | j        rt                              d|          }|                     |           d S )Nzstring payload expected: %scharsetrD   rF   >From )get_payload
isinstancestr	TypeErrortyper	   _payload	get_paramr   set_payloadrI   r   fcrer]   rB   )r   r-   payloadrg   s       r   _handle_textzGenerator._handle_text   s    //##?F'3'' 	K9DMMIJJJ3<(( 
	8mmI..G" smm34111//++#&'B#C#&~#6#8 	2hhx11G'"""""r   c                 B   g }|                                 }|g }nDt          |t                    r|                     |           d S t          |t                    s|g}|D ]o}|                                 }|                     |          }|                    |d| j                   |	                    |
                                           p|                                }|sD| j                            |          }|                     |          }|                    |           |j        ^| j        r!t$                              d|j                  }	n|j        }	|                     |	           |                     | j                   |                     d|z   | j        z              |r-| j                            |                    d                     |D ]D}
|                     | j        dz   |z   | j        z              | j                            |
           E|                     | j        dz   |z   dz   | j        z              |j        F| j        r!t$                              d|j                  }n|j        }|                     |           d S d S )NFr.   r   rh   z--r   )ri   rj   rk   r   listr9   r#   r2   r$   appendrN   get_boundaryr&   rY   _make_boundaryset_boundarypreambler   rq   r]   rB   r   popepilogue)r   r-   msgtextssubpartspartr   gboundaryalltextr{   	body_partr}   s               r   _handle_multipartzGenerator._handle_multipart  s    ??$$HH#&& 	"JJx   FHd++ 	" zH 	* 	*D  ""A

1AIIdUDHI===OOAJJLL))))##%% 	' &++H55G**733HX&&&<#! (88Hcl;;<h'''JJtx   

4(?TX-... 	,HNN8<<??+++ " 	& 	&IJJtx$1DH<===HNN9%%%%

48d?X-4tx?@@@<#! (88Hcl;;<h''''' $#r   c                     | j         }|                    d          | _         	 |                     |           || _         d S # || _         w xY w)Nr   r    )r   r#   r   )r   r-   ps      r   _handle_multipart_signedz"Generator._handle_multipart_signed;  sS     Kggag00	""3'''DKKK!DKOOOOs   A 	Ac                 @   g }|                                 D ]}|                                 }|                     |          }|                    |d| j                   |                                }|                    | j                  }|rG|d         | j        k    r6|	                    | j        
                    |d d                              |	                    |           | j                            | j        
                    |                     d S )NFru   r=   )ri   r9   r#   r2   r$   rN   r?   r&   r(   rw   rY   r   r   )r   r-   blocksr   r   r   textr@   s           r   _handle_message_delivery_statusz)Generator._handle_message_delivery_statusF  s    OO%% 
	$ 
	$D  ""A

1AIIdUDHI===::<<DJJt/00E $rd&999d.33E#2#J??@@@@d#### 	t',,V4455555r   c                 x   |                                  }|                     |          }|j        }t          |t                    rE|                    |                    d          d| j                   |                                }n| 	                    |          }| j
                            |           d S )Nr   Fru   )r9   r#   rn   rj   rv   r2   ri   r$   rN   r%   r   r   )r   r-   r   r   rr   s        r   _handle_messagezGenerator._handle_message[  s    JJqMM ,gt$$ 	,IIcooa((5$(IKKKjjllGGll7++Gwr   c                 F   t          j        t          j                  }dt          |z  z   dz   }||S |}d}	 |                     dt          j        |          z   dz   t          j                  }|	                    |          sn|dz   t          |          z   }|dz  }i|S )	Nz===============z==r   Tz^--z(--)?$.rG   )random	randrangesysmaxsize_fmt_compile_rereescape	MULTILINEsearchrk   )clsr   tokenr   bcountercres          r   ry   zGenerator._make_boundaryt  s      --.5<O	//%")A,,"6"A2<PPC::d## 3W-AqLG	 r   c                 ,    t          j        ||          S r   )r   compiler   r   flagss      r   r   zGenerator._compile_re  s    z!U###r   )NN)FNr   )__name__
__module____qualname__r   r   r2   r#   r9   r%   rB   r,   rJ   rH   rs   r[   r   r   r   r   classmethodry   r   r;   r   r   r   r      sW           @  /( /( /( /(b2 2 2(    	" 	" 	" %' %' %'N  (  # # #, J8( 8( 8(t	 	 	6 6 6*     2    [" $ $ [$ $ $r   r   c                   R     e Zd Z	 d Zd Zd Zd Z fdZeZe	d             Z
 xZS )r   c                 b    | j                             |                    dd                     d S )Nasciisurrogateescape)r   r   encoder   s     r   r   zBytesGenerator.write  s+    qxx):;;<<<<<r   c                     t                      S r   )r   r8   s    r   r9   zBytesGenerator._new_buffer  s    yyr   c                 ,    |                     d          S Nr   )r   r   s     r   r%   zBytesGenerator._encode  s    xx   r   c                     |                                 D ]8\  }}| j                            | j                            ||                     9|                     | j                   d S r   )ra   r   r   r   fold_binaryr$   rc   s       r   rH   zBytesGenerator._write_headers  sb     MMOO 	: 	:DAqHNN4;221a889999

48r   c                 B   |j         d S t          |j                   rX| j        j        dk    sH| j        r%t
                              d|j                   |_         |                     |j                    d S t          t          |           
                    |           d S )N7bitrh   )rn   r	   r   cte_typer   rq   r]   rB   superr   rs   )r   r-   r5   s     r   rs   zBytesGenerator._handle_text  s     <F3<(( 	91Ev1M1M! @#xx#,??cl+++++.&&33C88888r   c                 R    t          j        |                    d          |          S r   )r   r   r   r   s      r   r   zBytesGenerator._compile_re  s     z!((7++U333r   )r   r   r   r   r9   r%   rH   rs   r[   r   r   __classcell__)r5   s   @r   r   r     s        
= = =  ! ! !  
9 
9 
9 
9 
9 J4 4 [4 4 4 4 4r   r   zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c                   $    e Zd Z	 ddddZd ZdS )r   Nr   c                t    	 t                               | ||||           |t          | _        d S || _        d S r4   )r   r   _FMTr   )r   r   r   r   fmtr   s         r   r   zDecodedGenerator.__init__  sL    	* 	4l"( 	 	* 	* 	*;DIIIDIIIr   c                    |                                 D ]}|                                }|dk    r&t          |                    d          |            B|dk    rIt          | j        |                                |                                |                                |                    d          |                    dd          |                    d	d
          dz  |            d S )Nr   F)decode)file	multipartz[no filename]zContent-Descriptionz[no description]rE   z[no encoding])rm   maintypesubtypefilenamedescriptionencoding)	walkrV   printri   r   get_content_typerW   get_filenamerK   )r   r-   r   r   s       r   rJ   zDecodedGenerator._dispatch  s   HHJJ 	" 	"D0022H6!!d&&e&444@@@@@[((di#'#8#8#:#:#'#<#<#>#>#'#;#;#=#=#'#4#4_#E#E#'88,A,>$@ $@#'88,G,;$= $=	# 	# 	 !	" 	" 	" 	" 	"	" 	"r   )NNN)r   r   r   r   rJ   r;   r   r   r   r     sI        
    <" " " " "r   r   rG   z%%0%dd)__all__r   r   r*   r   copyr   ior   r   email.utilsr	   rX   NLr   r>   r   rq   r   r   r   r   lenreprr   _widthr   ry   r;   r   r   <module>r      sn  
 A
=
=
= 				 



                         ' ' ' ' ' '
	
=!!rz)R\**o$ o$ o$ o$ o$ o$ o$ o$d/4 /4 /4 /4 /4Y /4 /4 /4d N6" 6" 6" 6" 6"y 6" 6" 6"t 
TT#+a-  	!	!& )r   