fOQdZgdZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZdZd Zej"d Zej"d ej&Zej"d ZGd dZGddeZdZGddeZeeej8dz ZdezZej>Zy)z:Classes to generate plain text from a message object tree.) GeneratorDecodedGeneratorBytesGeneratorN)deepcopy)StringIOBytesIO)_has_surrogates)HeaderWriteError_ z \r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]ceZdZdZddddZdZddZdZdZd Z d Z d Z d Z d Z dZeZdZdZdZdZeddZedZy)rzGenerates output from a Message object tree. This basic generator writes the message to the given file object as plain text. Npolicyc`||dn |j}||_||_||_||_y)aCreate the generator for message flattening. outfp is the output file-like object for writing the message to. It must have a write() method. Optional mangle_from_ is a flag that, when True (the default if policy is not set), escapes From_ lines in the body of the message by putting a `>' in front of them. Optional maxheaderlen specifies the longest length for a non-continued header. When a header line is longer (in characters, with tabs expanded to 8 spaces) than maxheaderlen, the header will split as defined in the Header class. Set maxheaderlen to zero to disable header wrapping. The default is 78, as recommended (but not required) by RFC 2822. The policy keyword specifies a policy object that controls a number of aspects of the generator's operation. If no policy is specified, the policy associated with the Message object passed to the flatten method is used. NT) mangle_from__fp _mangle_from_ maxheaderlenr)selfoutfprrrs &/usr/lib/python3.12/email/generator.py__init__zGenerator.__init__%s92  #)>4v7J7JL)( c:|jj|yN)rwriterss rrzGenerator.writeEs qrc|j |jn |j}||j|}|j|j|j}|j|_|j |j|_d|_|j |j|_|j}|j} ||_||_|rZ|j}|s*dtjtjz}|j||jz|j|||_||_y#||_||_wxYw)aPrint the message object tree rooted at msg to the output file specified when the Generator instance was created. unixfrom is a flag that forces the printing of a Unix From_ delimiter before the first object in the message tree. If the original message has no From_ delimiter, a `standard' one is crafted. By default, this is False to inhibit the printing of any From_ delimiter. Note that for subobjects, no From_ line is printed. linesep specifies the characters used to indicate a new line in the output. The default value is determined by the policy specified when the Generator instance was created or, if none was specified, from the policy associated with the msg. N)linesepmax_line_lengthz From nobody )rclonerr _NL_encode _encoded_NL_EMPTY_encoded_EMPTY get_unixfromtimectimer_write)rmsgunixfromr rold_gen_policyold_msg_policyufroms rflattenzGenerator.flattenIs%* ${{2   \\'\2F    (\\$2C2C\DF>><<1 "ll4;;7  ( DKCJ((**TZZ -DDE 5488+, KK (DK'CJ)DK'CJs A;EE,cT|j||jd|jS)z1Clone this generator with the exact same options.Nr) __class__rr)rfps rr$zGenerator.clonezs-~~b"00"%)[[2 2rctSr)rrs r _new_bufferzGenerator._new_buffers zrc|Srrs rr&zGenerator._encodesrc|sytj|}|ddD].}|j||j|j0|dr|j|dyy)N)NLCREsplitrr%)rlineslines r _write_lineszGenerator._write_linesse  E"#2J !D JJt  JJtxx  ! 9 JJuRy ! rc |j} d|_|jx|_}|j|||_|j}|`|rOt |}|j d |d|d<n|j d|d|j d|dt|dd}||j|n|||jj|jy#||_|j}|`wxYw)Ncontent-transfer-encodingrContent-Transfer-Encoding content-type_write_headers) r _munge_cter9 _dispatchrgetreplace_headergetattrrHrgetvalue)rr.oldfpsfp munge_ctemeths rr-zGenerator._writes "DO!--/ /DHs NN3 DHI 3-Cww23;3 ! M   ~y| <s,d3 <    $ J s||~&'DHIs /C66D c&|j}|j}tj||fj dd}t |d|zd}|0|j dd}t |d|zd}| |j }||y)N-r _handle_)get_content_maintypeget_content_subtype UNDERSCOREjoinreplacerM _writeBody)rr.mainsubspecificrRgenerics rrJzGenerator._dispatchs '')%%'??D#;/77SAtZ(2D9 <ll3,G4g!5tFrom ) get_payload isinstancestr TypeErrortyper _payload get_paramr set_payloadrIrfcrer]rB)rr.payloadrls r _handle_textzGenerator._handle_texts//# ? '3'9DMIJ J 3<< (mmI.G"sm34 g6//+#&'B#C#&~#6#8   hhx1G '"rc0g}|j}|g}n5t|tr|j|yt|ts|g}|D]`}|j }|j |}|j|d|j|j|jb|j}|s=|jj|}|j|}|j||j e|j"r!t$j'd|j } n |j } |j)| |j|j|jd|z|jz|r*|j*j|j-d|D]K} |j|jdz|z|jz|j*j| M|j|jdz|zdz|jz|j.K|j"r!t$j'd|j.} n |j.} |j)| yy)NFr/r rmz--r)rnrorprlistr9r$r3r%appendrN get_boundaryr'rY_make_boundary set_boundarypreamblerrvr]rBrpopepilogue) rr.msgtextssubpartspartrgboundaryalltextr body_partrs r_handle_multipartzGenerator._handle_multipart s??$  H # & JJx Hd+ zH *D  "A 1 A IIdUDHHI = OOAJJL )  * ##%&&++H5G**73H   X & << #!!88Hcll;<<   h ' JJtxx  4(?TXX-.  HHNN8<<? +" &I JJtxx$1DHH< = HHNN9 %  & 488d?X-4txx?@ << #!!88Hcll;<<   h ' $rc|j}|jd|_ |j|||_y#||_wxYw)Nrr!)rr$r)rr.ps r_handle_multipart_signedz"Generator._handle_multipart_signedFsA KKggag0    " "3 'DK!DKs > Acg}|jD]}|j}|j|}|j|d|j|j }|j |j}|r@|d|jk(r.|j|jj|dd|j||jj|jj|y)NFrzr=) rnr9r$r3r%rNr?r'r)r|rYrr)rr.blocksrrrtextr@s r_handle_message_delivery_statusz)Generator._handle_message_delivery_statusQsOO% $D  "A 1 A IIdUDHHI =::|j |j dd|j|j}n|j|}|jj|y)NrFrz) r9r$rsror{r3rnr%rNr&rr)rr.rrrws r_handle_messagezGenerator._handle_messagefsz     JJqM,, gt $ IIcooa(5$((I KjjlGll7+G wrc@tjtj}dt|zzdz}||S|}d} |j dt j|zdzt j}|j|s |S|dzt|z}|dz }d)Nz===============z==rz^--z(--)?$.rG) random randrangesysmaxsize_fmt _compile_rereescape MULTILINErfrp)clsrtokenrbcountercres rr~zGenerator._make_boundarys  -.5 <O //%"))A,"6"A2<<PC::d#3W-A qLG rc.tj||Sr)rcompilerrflagss rrzGenerator._compile_reszz!U##r)NN)FNr)__name__ __module__ __qualname____doc__rrr3r$r9r&rBr-rJrHrxr[rrrr classmethodr~rr;rrrrs@/(b2( " %'N( &#,J8(t 6* 2"$$rrcNeZdZdZdZdZdZdZfdZeZ e dZ xZ S)raGenerates a bytes version of a Message object tree. Functionally identical to the base Generator except that the output is bytes and not string. When surrogates were used in the input to encode bytes, these are decoded back to bytes for output. If the policy has cte_type set to 7bit, then the message is transformed such that the non-ASCII bytes are properly content transfer encoded, using the charset unknown-8bit. The outfp object must accept bytes in its write method. cZ|jj|jddy)Nasciisurrogateescape)rrencoders rrzBytesGenerator.writes qxx):;#'#;#;#=#'#4#4_#E#'88,A,>$@#'88,G,;$= # ! " "r)NNN)rrrrrrJr;rrrrs <"rrrGz%%0%dd) r__all__rrr+rcopyriorr email.utilsr email.errorsr rXNLrr>rrvrerrrrlenreprr_widthrr~r;rrrs A =  ')    =!rzz)R\\*!rzz"CDx$x$v /4Y/4dN6"y6"t T#++a- !&))r