3 fP@sdddgZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z d Zd Zejd Zejd ejZejd ZGdddZGdddeZdZGdddeZeeejdZdeZejZdS) GeneratorDecodedGeneratorBytesGeneratorN)deepcopy)StringIOBytesIO)_has_surrogates)HeaderWriteError_ z \r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c@seZdZd&ddddZddZd'dd Zd d Zd d ZddZddZ ddZ ddZ ddZ ddZ e ZddZddZddZd d!Zed(d"d#Zed$d%ZdS))rN)policycCs6|dkr|dkrdn|j}||_||_||_||_dS)NT) mangle_from__fp _mangle_from_ maxheaderlenr )selfoutfpr rr r'/usr/lib64/python3.6/email/generator.py__init__&s zGenerator.__init__cCs|jj|dS)N)rwrite)rsrrrrFszGenerator.writeFc Cs|jdkr|jn|j}|dk r*|j|d}|jdk rB|j|jd}|j|_|j|j|_d|_|j|j|_|j}|j}zL||_||_|r|j }|sdt j t j }|j ||j|j |Wd||_||_XdS)N)linesep)max_line_lengthz From nobody )r clonerr_NL_encode _encoded_NLZ_EMPTY_encoded_EMPTYZ get_unixfromtimeZctimer_write)rmsgunixfromrr Zold_gen_policyZold_msg_policyZufromrrrflattenJs,  zGenerator.flattencCs|j||jd|jdS)N)r ) __class__rr )rfprrrr{szGenerator.clonecCstS)N)r)rrrr _new_bufferszGenerator._new_buffercCs|S)Nr)rrrrrrszGenerator._encodecCsX|sdStj|}x*|ddD]}|j||j|jq W|drT|j|ddS)Nr)r))NLCREsplitrr)rlineslinerrr _write_liness  zGenerator._write_linesc Cs|j}z"d|_|j|_}|j|Wd||_|j}|`X|rht|}|jd|d|jd|dt|dd}|dkr|j|n|||jj|j dS)Nzcontent-transfer-encodingrz content-typer(_write_headers) r _munge_cter' _dispatchrZreplace_headergetattrr/rgetvalue)rr"ZoldfpZsfpZ munge_ctemethrrrr!s"   zGenerator._writecCst|j}|j}tj||fjdd}t|d|d}|dkrh|jdd}t|d|d}|dkrh|j}||dS)N-r Z_handle_)get_content_maintypeget_content_subtype UNDERSCOREjoinreplacer2 _writeBody)rr"mainsubZspecificr4Zgenericrrrr1s zGenerator._dispatchcCsx|jD]\}}|jj||}|jjr|jj}|j|jjsRtd|d||}|j|rr|dt| }tj |rtd||j |q W|j |j dS)Nz folded header does not end with z: z folded header contains newline: ) raw_itemsr ZfoldZverify_generated_headersrendswithr lenNEWLINE_WITHOUT_FWSPsearchrr)rr"hvZfoldedrZfolded_no_lineseprrrr/s   zGenerator._write_headerscCs|j}|dkrdSt|ts.tdt|t|jr~|jd}|dk r~t|}|d=|j |||j}|d|df|_ |j rt j d|}|j|dS)Nzstring payload expected: %scharsetzcontent-transfer-encodingz content-typez>From ) get_payload isinstancestr TypeErrortyper_payloadZ get_paramrZ set_payloadr0rfcrer=r.)rr"payloadrErrr _handle_texts"      zGenerator._handle_textc Csg}|j}|dkrg}n(t|tr2|j|dSt|tsB|g}x>|D]6}|j}|j|}|j|d|jd|j |j qHW|j }|s|j j |}|j|}|j||jdk r|jrtjd|j} n|j} |j| |j|j|jd||j|r|jj|jdx4|D],} |j|jd||j|jj| qW|j|jd|d|j|jdk r|jrtjd|j} n|j} |j| dS)NF)r#rz>From z--r)rFrGrHrlistr'rr$rappendr3Z get_boundaryrr9_make_boundaryZ set_boundarypreamblerrLr=r.rpopepilogue) rr"ZmsgtextsZsubpartspartrgboundaryZalltextrRZ body_partrTrrr_handle_multipart sJ             zGenerator._handle_multipartc Cs0|j}|jdd|_z|j|Wd||_XdS)Nr)r)r rrX)rr"prrr_handle_multipart_signedFs z"Generator._handle_multipart_signedcCsg}x|jD]t}|j}|j|}|j|d|jd|j}|j|j}|rx|d|jkrx|j |jj |ddq|j |qW|j j |jj |dS)NF)r#rr(r)r)) rFr'rr$rr3r+rrrPr9rr)rr"ZblocksrUrrVtextr,rrr_handle_message_delivery_statusQs  z)Generator._handle_message_delivery_statuscCs^|j}|j|}|j}t|trD|j|jdd|jd|j}n |j |}|j j |dS)NrF)r#r) r'rrKrGrOr$rFrr3rrr)rr"rrVrMrrr_handle_messagefs    zGenerator._handle_messagecCsztjtj}d t|d}|dkr(|S|}d}xD|jdtj|dtj}|j |sZP|dt |}|d7}q2W|S) N=z==rz^--z(--)?$.r(z===============) randomZ randrangesysmaxsize_fmt _compile_rereescape MULTILINErBrH)clsr[tokenrWbZcounterZcrerrrrQs   zGenerator._make_boundarycCs tj||S)N)rfcompile)rirflagsrrrreszGenerator._compile_re)NN)FN)N)__name__ __module__ __qualname__rrr$rr'rr.r!r1r/rNr;rXrZr\r] classmethodrQrerrrrrs(  1#:  csLeZdZddZddZddZddZfd d ZeZe d d Z Z S) rcCs|jj|jdddS)Nasciisurrogateescape)rrencode)rrrrrrszBytesGenerator.writecCstS)N)r)rrrrr'szBytesGenerator._new_buffercCs |jdS)Nrr)rt)rrrrrrszBytesGenerator._encodecCs<x*|jD]\}}|jj|jj||q W|j|jdS)N)r>rrr Z fold_binaryr)rr"rCrDrrrr/szBytesGenerator._write_headerscs^|jdkrdSt|jrJ|jjdk rJ|jrFrom ) rKrr Zcte_typerrLr=r.superrrN)rr")r%rrrNs zBytesGenerator._handle_textcCstj|jd|S)Nrr)rfrlrt)rirrmrrrreszBytesGenerator._compile_re) rnrorprr'rr/rNr;rqre __classcell__rr)r%rrs  zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s$eZdZdddddZddZdS)rN)r cCs.tj|||||d|dkr$t|_n||_dS)N)r )rr_FMTrd)rrr rZfmtr rrrrs  zDecodedGenerator.__init__c Csx|jD]v}|j}|dkr4t|jdd|dq |dkr>q t|j|j|j|j|jd|jdd|jd d d |dq WdS) Nr[F)decode)fileZ multipartz [no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz [no encoding])rJmaintypesubtypefilenameZ descriptionencoding) walkr6printrFrdZget_content_typer7 get_filenameget)rr"rUrzrrrr1s  zDecodedGenerator._dispatch)NNN)rnrorprr1rrrrrsr(z%%0%dd)__all__rfrbr racopyriorrZ email.utilsrZ email.errorsr r8NLrlr*rhrLrArrrwrr@reprrcZ_widthrdrQrrrrs,      |3;