3 fJ@sdddddddddd d d d d dgZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZmZmZddlmZdZdZdZdZdZejdZejdZdZdaddZdd Zd!d"Zd#d$Z dHd&dZ!d'd(Z"d)d*Z#d+Z$dd,d-dZ%d.d/Z&d0d1Z'd2d3Z(ejd4ej)ej*BZ+d5d6Z,dId8dZ-dJd9dZ.dKd:dZ/d;d Z0dd,ddZ3dLd?dZ4ejd@ej5Z6dAdZ7dMdDdZ8dOdFdGZ9dS)Pcollapse_rfc2231_value decode_paramsdecode_rfc2231encode_rfc2231 formataddr formatdateformat_datetime getaddresses make_msgid mktime_tz parseaddr parsedate parsedate_tzparsedate_to_datetimeunquoteN)quote) AddressList)r )r r _parsedate_tz)Charsetz, z 'z[][\\()<>@,:;".]z[\\"]z/etc/python/email.cfgcCstdkrtatS)N)_cached_strict_addr_parsing_use_strict_email_parsing_implrr#/usr/lib64/python3.6/email/utils.py_use_strict_email_parsing7srcCsttjjd}|rdSy tt}Wntk r8YnBX|6ddl}|jdd d}|j ||j dddd}WdQRX|rdSdS) NZ(PYTHON_EMAIL_DISABLE_STRICT_ADDR_PARSINGFr#)Z interpolationZcomment_prefixesZemail_addr_parsing)ZfallbackT)r) boolosenvirongetopen_EMAIL_CONFIG_FILEFileNotFoundError configparserZ ConfigParserZ read_fileZ getboolean)Zdisabledfiler$configrrrr?s"  rc Cs&y |jdStk r dSXdS)NFT)encodeUnicodeEncodeError)srrr_has_surrogates\s r*cCs|jdd}|jddS)Nzutf-8surrogateescapereplace)r'decode)stringZoriginal_bytesrrr _sanitizeis r/utf-8c Cs|\}}|jd|ry|jdWn8tk r\t|trFt|}|j|}d||fSXd}tj|rpd}tj d|}d||||fS|S)Nasciiz%s <%s>r"z\\\g<0>z %s%s%s <%s>) r'r( isinstancestrrZ header_encode specialsresearch escapesresub)ZpaircharsetnameZaddressZ encoded_nameZquotesrrrrus      ccs`d}d}xDt|D]8\}}|r2|d|fVd}q|dkr@d}q||fVqW|r\|dfVdS)NrF\T) enumerate)addrposescapechrrr_iter_escaped_charssrAcCsd|kr |Sd}d}g}xPt|D]D\}}|dkr"|dkr@|}q"||krZ|j||||d}d}q"W|t|kr|j||ddj|S)Nr2rr)rAappendlenjoin)r=startZopen_posresultr>r@rrr_strip_quoted_realnamess  rHT)strictcCs|dkrt}|s4tjdd|D}t|}|jSdd|D}t|}tj|}t|}t|j}d}x&|D]}t|}|d|jd7}qpWt ||krd gS|S) Ncss|]}t|VqdS)N)r4).0vrrr szgetaddresses..cSsg|] }t|qSr)r4)rJrKrrr sz getaddresses..rrB,r)rr) r COMMASPACErE _AddressList addresslist_pre_parse_validation_post_parse_validationrHcountrD)Z fieldvaluesrIallar=rGnrKrrrrs$      cCsXt|}d}xBt|D]6\}}|dkr0|d7}q|dkr|d8}|dkrdSqW|dkS)Nr(rB)F)rHrA)r=Zopensr>r@rrr_check_parenthesiss rZcCs,g}x"|D]}t|sd}|j|q W|S)Nz('', ''))rZrC)Zemail_header_fieldsaccepted_valuesrKrrrrRs  rRcCs0g}x&|D]}d|dkrd}|j|q W|S)N[rBr)rr)rC)Zparsed_email_header_tuplesr[rKrrrrS s   rSa_ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the atom \?= # literal ?= cCsfddddddddg|d |d d d d dddddddddg |dd|d|d|d|d|fS)Nz"%s, %02d %s %04d %02d:%02d:%02d %sZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecrBrr) timetuplezonerrr_format_timetuple_and_zone"s rdFcCsR|dkrtj}|s|r,tjj|tjj}n tjj|}|rH|j}d}t||S)NF)timedatetimeZ fromtimestamptimezoneutcZutcfromtimestamp astimezoner)timeval localtimeusegmtdtrrrr+s cCsV|j}|r2|jdks$|jtjjkr,tdd}n|jdkrBd}n |jd}t||S)Nz%usegmt option requires a UTC datetimeZGMTz-0000z%z)rbtzinforfrgrh ValueErrorZstrftimerd)rmrlnowrcrrrrHs  cCs^ttjd}tj}tjd}|dkr0d}nd|}|dkrHtj}d|||||f}|S)Nd@r.z<%d.%d.%d%s@%s>)intrergetpidrandomZ getrandbitssocketZgetfqdn)ZidstringZdomainrjpidZrandintZmsgidrrrr [s  cCsNt|^}}|dkr(tj|ddStj|dddtjtj|diS)Nr]rn)seconds)rrfrg timedelta)dataZdtupletzrrrrrs cCs|dkrt}|s,t|j}|s$dS|dSt|tr>|d}t|tsLdSt|gd}tt|j}| szt|dkr~dS|dS)NrrrB)rr)rr)rr) rrPrQr3listr4rRrSrD)r=rIZaddrsrrrr zs    cCs`t|dkr\|jdr<|jdr<|ddjddjddS|jdr\|jdr\|dd S|S) NrBr2z\\r;z\"<>r)rD startswithendswithr,)r4rrrrs   cCs&|jtd}t|dkr"dd|fS|S)Nr^)splitTICKrD)r)partsrrrrs   cCsDtjj|d|pdd}|dkr*|dkr*|S|dkr6d}d|||fS)Nrr1)Zsafeencodingz%s'%s'%s)urllibparser)r)r9languagerrrrs z&^(?P\w+)\*((?P[0-9]+)\*?)?$c Csx|dd}g}i}|jd\}}|j||fx|r|jd\}}|jdrTd}nd}t|}tj|}|r|jdd\}}|dk rt|}|j|gj|||fq2|j|dt |fq2W|rtx|j D]\}}g}d} |j x6|D].\}} }|rt j j| dd } d} |j| qWt tj|}| r^t|\} } }|j|| | d|ffq|j|d|fqW|S) Nr*TFr:numz"%s"zlatin-1)r)poprCrrrfc2231_continuationmatchgrouprt setdefaultritemssortrr EMPTYSTRINGrEr) ZparamsZ new_paramsZrfc2231_paramsr:valueZencodedZmorZ continuationsZextendedr)r9rrrrrsD   r,us-asciic Csjt|t st|dkr t|S|\}}}|dkr6|}t|d}y t|||Stk rdt|SXdS)Nr_zraw-unicode-escape)r3tuplerDrbytesr4 LookupError)rerrorsZfallback_charsetr9rtextZrawbytesrrrrs   rBc Cs|dkrtjjtjjjS|jdk r.|jS|jdd|f}tj|}tj |}y tj |j d}tj||j }Wnt k r|tjtj|dd}tjo|jdk}|rtjntj }|tj |dkrtj|tj|}n tj|}YnX|j|dS)NrB)ryr]r)rnr)rfrprgrhrirnrbreZmktimerkrzZ tm_gmtoffZtm_zoneAttributeErrorZgmtimeZdaylightZtm_isdstZaltzoneZtznamer,) rmZisdstZtmryZlocaltmZdeltar|dstZgmtoffrrrrks$   rk)r0)NFF)F)NN)NN)r,rr)Nr):__all__rrerervrwrfZ urllib.parserZemail._parseaddrrrrPr r r rZ email.charsetrrOrZ UEMPTYSTRINGZCRLFrcompiler5r7r"rrrr*r/rrArHZsupports_strict_parsingrrZrRrSVERBOSE IGNORECASEZecrerdrrr rr rrrASCIIrrrrkrrrrs        !1     $  8