a  ze&^@sgdZddlZddlZddlZddlZddlmZddlmZ e j Z dZ dZ dZ dZd Zd Zd Ze d Ze d ZedejejBZedZedZejjZddZdddZGdddZGdddZGddde Z!dS))Header decode_header make_headerN)HeaderParseError)charset   z Nz us-asciizutf-8ai =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qQbB]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= z[\041-\176]+:$z \n[^ \t]+:c Cst|drdd|jDSt|s.|dfgSg}|D]}t|}d}|r:|d}|rj|}d}|r~||ddf|rL|d }|d }|d}||||fqLq:g} t |D]J\} } | dkr| dr|| ddr|| dd r| | dqt | D] } || =qg} |D]\}}}|durV| ||fn|d kr|t j|}| ||fn||d krt|d }|r|d dd |7}zt j|}Wntjytd Yn0| ||fn td|q2g}d}}| D]v\}}t|tr*t|d}|dur>|}|}nB||kr`|||f|}|}n |durx|t|7}n||7}q |||f|S)N_chunkscSs(g|] \}}t|t|t|fqS)_charsetZ_encodestr).0stringrrr@/opt/bitninja-python-dojo/embedded/lib/python3.9/email/header.py Msz!decode_header..TrFqbz===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)hasattrr ecresearch splitlinessplitpoplstripappendlower enumerateisspacereversedemail quoprimimeZ header_decodelenZ base64mimedecodebinasciiErrorrAssertionError isinstancerbytesBSPACE)headerwordslinepartsfirstZ unencodedrencodingencodedZdroplistnwdZ decoded_wordsZencoded_stringZwordZpaderrZ collapsedZ last_word last_charsetrrrr=s|       4              rcCsFt|||d}|D].\}}|dur4t|ts4t|}|||q|S)N) maxlinelen header_namecontinuation_ws)rr-Charsetr!)Z decoded_seqr;r<r=hsrrrrrs  rc@sJeZdZdddZddZdd Zdd d Zd d ZdddZddZ dS)rNrstrictcCs||durt}nt|ts t|}||_||_g|_|durH|||||durTt}||_|durjd|_ nt |d|_ dS)Nrr) USASCIIr-r>r_continuation_wsr r! MAXLINELEN _maxlinelen _headerlenr()selfr@rr;r<r=errorsrrr__init__s zHeader.__init__c Cs|g}d}d}|jD]\}}|}|tjkrH|dd}|dd}|r|o\||d}|dvr|dvr|s|td}n|dvr|s|t|o||d}|}||qt |S)NasciisurrogateescapereplacerNr ) _normalizer r UNKNOWN8BITencoder) _nonctextr!SPACE EMPTYSTRINGjoin) rGZuchunkslastcs lastspacerrZnextcsZoriginal_byteshasspacerrr__str__s*        zHeader.__str__cCs |t|kSN)r)rGotherrrr__eq__sz Header.__eq__cCs|dur|j}nt|ts"t|}t|tsZ|jp4d}|tjkrN|dd}n |||}|jpbd}|tjkrz|||Wn t y|dkrt }Yn0|j ||fdS)Nr rK) rr-r>rZ input_codecrPr)Z output_codecrQUnicodeEncodeErrorUTF8r r!)rGr@rrHZ input_charsetoutput_charsetrrrr! s$         z Header.appendcCs|p|dvS)N)()\)r$)rGr@rrrrR4szHeader._nonctext;, rcCs||dur|j}|dkr"d}t|j||j|}d}d}}|jD]\}} |dur|oh||d}|dvr|r~| dvr|n| dvr|s||o||d}| }d}|} | r| d| d| n| dd| | ddD]`} | | j dur"| |jd| | q| } | dt | t | } | | | | qt | dkrF| qF|jrx|||}t|rtd ||S) Nri@BrMrNFr rrz8header value appears to contain an embedded header: {!r})rOrE_ValueFormatterrFrCr rRadd_transitionrfeednewlineheader_encodingr r(_str_embedded_headerrrformat)rG splitcharsr;linesep formatterrVrXrWrrlinesr2ZslinefwsvaluerrrrQ9sX!        z Header.encodecCsxg}d}g}|jD]B\}}||kr.||q|durJ|t||f|g}|}q|rn|t||f||_dSrZ)r r!rSrU)rGchunksr:Z last_chunkrrrrrrOs zHeader._normalize)NNNNrrA)NrA)rcNr) __name__ __module__ __qualname__rIrYr\r!rRrQrOrrrrrs /  + Prc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)rdcCs0||_||_t||_||_g|_t||_dSrZ)_maxlenrCr(_continuation_ws_len _splitchars_lines _Accumulator _current_line)rGZ headerlenmaxlenr=rlrrrrIs  z_ValueFormatter.__init__cCs|||jSrZ)rgrUry)rGrmrrrrisz_ValueFormatter._strcCs |tSrZ)riNLrGrrrrYsz_ValueFormatter.__str__cCsv|j}|dkr|jj|t|jdkrh|jrV|jrV|jdt|j7<n|jt|j|jdS)N)rr rrN) r{rpushr( is_onlywsryrr!reset)rGZ end_of_linerrrrgs  z_ValueFormatter.newlinecCs|jdddS)Nrr )r{rr~rrrresz_ValueFormatter.add_transitioncCs|jdur||||jdS|||}z|d}WntyPYdS0|durf|||z |}WntyYdS0||j |j ||D]}|j |j |qdSNr)rh _ascii_splitrxZheader_encode_lines _maxlengthsr IndexError _append_chunkrgr{rrCryr!)rGrprrZ encoded_linesZ first_line last_liner2rrrrfs$     z_ValueFormatter.feedccs&|jt|jV|j|jVqdSrZ)rvr(r{rwr~rrrrsz_ValueFormatter._maxlengthscCsftdtd||}|dr0dg|dd<n |dtt|gdD]\}}|||qLdS)Nz([z]+)rr r)rerFWSrzipiterr)rGrprrlr3partrrrrs  z_ValueFormatter._ascii_splitcCs|j||t|j|jkr|jD]v}t|jdddD]T}|rn|j|d}|rn|d|krnq|j|dd}|r@|d|kr@qq@q&qq&|j\}}|jj dkr| |sd}|j||dS|j |}|j t|j|j|dS)NrrrNr)r{rr(rvrxrange part_countr$r _initial_sizergpop_fromryr!rr)rGrprZchiZprevpartr remainderrrrrs.   z_ValueFormatter._append_chunkN) rsrtrurIrirYrgrerfrrrrrrrrds %rdcsjeZdZdfdd ZddZdddZfdd Zd d Zd d ZdddZ ddZ fddZ Z S)rzrcs||_tdSrZ)rsuperrI)rGZ initial_size __class__rrrIsz_Accumulator.__init__cCs|||fdSrZ)r!)rGrprrrrr#sz_Accumulator.pushcCs||d}g||d<|SrZr)rGrZpoppedrrrr&s  z_Accumulator.pop_fromcs|dkrdStS)Nr)r r )rrrr~rrrr+s z_Accumulator.popcCstdd|D|jS)Ncss"|]\}}t|t|VqdSrZ)r(rrprrrr 1z'_Accumulator.__len__..)sumrr~rrr__len__0sz_Accumulator.__len__cCstdd|DS)Ncss |]\}}t||fVqdSrZrTrUrrrrr5sz'_Accumulator.__str__..rr~rrrrY4s z_Accumulator.__str__NcCs"|dur g}||dd<d|_dSr)r)rGZstartvalrrrr8s z_Accumulator.resetcCs|jdko| pt|Sr)rrr$r~rrrr>sz_Accumulator.is_onlywscs tSrZ)rrr~rrrrAsz_Accumulator.part_count)r)r)N) rsrtrurIrrrrrYrrr __classcell__rrrrrzs   rz)NNr)"__all__rr*Zemail.quoprimimer&Zemail.base64mimeZ email.errorsrrrr>r}rSr/ZSPACE8rTrDrrBr^compileVERBOSE MULTILINErZfcrerjr'Z _max_appendrrrrdlistrzrrrrs>     _ k