3 /fD@sdZddddgZddlZddlZdZdZd Zd d d d dddddddddddddddddddd gZd!d"d#d$d%d&d'gZddddd9d:d;dd?d@dAdBd.Z d/dZ d0d1Z d2dZ d3dZ d4dZGd5d6d6ZGd7d8d8eZdS)CzcEmail address parsing code. Lifted directly from rfc822.py. This should eventually be rewritten. mktime_tz parsedate parsedate_tzquoteN z, ZjanZfebZmarZaprZmayZjunZjulZaugsepoctZnovZdecZjanuaryZfebruaryZmarchZaprilZjuneZjulyZaugustZ septemberZoctoberZnovemberZdecemberZmonZtueZwedZthuZfriZsatZsunii,iiXii )ZUTZUTCZGMTZZASTZADTZESTZEDTZCSTZCDTZMSTZMDTZPSTZPDTcCs,t|}|sdS|ddkr$d|d<t|S)zQConvert a date string to a time tuple. Accounts for military timezones. N r) _parsedate_tztuple)dataresr"/usr/lib64/python3.6/_parseaddr.pyr-s  cCs|sdS|j}|djds.|djtkr6|d=n.|djd}|dkrd|d|dd|d<t|dkr|djd}t|dkr||dd}t|dkr|d}|jd}|dkr|jd}|dkr|d|||dg|dd<n |jd t|d krdS|dd }|\}}}}}|j}|tkrZ||j}}|tkrZdStj |d}|d krz|d 8}|ddkr|dd}|jd }|dkr||}}|ddkr|dd}|dj s||}}|ddkr|dd}|jd }t|d kr$|\} } d} n~t|dkr>|\} } } ndt|dkrd|dkr|djd}t|d kr|\} } d} nt|dkr|\} } } ndSy,t |}t |}t | } t | } t | } Wnt k rdSX|dkr |dkr|d7}n|d7}d} |j }|tkr,t|} n>y t |} Wnt k rNYnX| dkrj|jdrjd} | r| dkrd} | } nd} | | dd| dd} |||| | | ddd| g S)aConvert date to extended time tuple. The last (additional) element is the time zone offset in seconds, except if the timezone was specified as -0000. In that case the last element is None. This indicates a UTC timestamp that explicitly declaims knowledge of the source timezone, as opposed to a +0000 timestamp that indicates the source timezone really was UTC. Nr,-+r :0.dDilii<r!r!r!r!r!r!r!r!)splitendswithlower _daynamesrfindlenfindappend _monthnamesindexisdigitint ValueErrorupper _timezones startswith)riZstuffsZddZmmZyyZtmZtzZthhZtmmZtssZtzoffsetZtzsignrrrr 9s     "                       r cCs&t|}t|tr|ddS|SdS)z&Convert a time string to a time tuple.Nr )r isinstancer )rtrrrrs  cCs<|ddkr"tj|dddStj|}||dSdS)zETurn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.r Nrr!)r!)timeZmktimecalendarZtimegm)rr5rrrrs  cCs|jddjddS)zPrepare string to be used in a quoted string. Turns backslash and double quote characters into quoted pairs. These are the only characters that need to be quoted inside a quoted string. Does not add the surrounding double quotes. \z\\"z\")replace)strrrrrsc@s|eZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ ddZ ddZ ddZdddZddZdS) AddrlistClassaAddress parser class by Ben Escoto. To understand what this class does, it helps to have a copy of RFC 2822 in front of you. Note: this class interface is deprecated and may be removed in the future. Use email.utils.AddressList instead. cCsZd|_d|_d|_d|_|j|j|_|j|j|j|_|jjdd|_||_g|_ dS)zInitialize a new instance. `field' is an unparsed address header field, containing one or more addresses. z ()<>@,:;."[]rz z rrN) specialsposLWSZCRFWSatomendsr; phraseendsfield commentlist)selfrDrrr__init__szAddrlistClass.__init__cCsg}x|jt|jkr|j|j|jdkr^|j|jdkrN|j|j|j|jd7_q|j|jdkr|jj|jqPqWtj|S)z&Skip white space and extract comments.z r() r?r'rDr@r)rE getcomment EMPTYSTRINGjoin)rFZwslistrrrgotonextszAddrlistClass.gotonextcCs>g}x4|jt|jkr8|j}|r,||7}q|jdqW|S)zVParse all addresses. Returns a list containing all of the addresses. r)rr)r?r'rD getaddressr))rFresultZadrrr getaddrlists zAddrlistClass.getaddrlistcCsg|_|j|j}|j}|j}|jg}|jt|jkr\|rXtj|j|dfg}n\|j|jdkr||_||_|j}tj|j|fg}n"|j|jdkrg}t|j}|jd7_x|jt|jkr|j|j|ko|j|jdkr |jd7_P||j }qWn|j|jdkrx|j }|jrftj|ddj|jd |fg}ntj||fg}n@|rtj|j|dfg}n"|j|j|j kr|jd7_|j|jt|jkr|j|jd kr|jd7_|S) zParse the next address.rz.@rr;)rFZoldposZoldclplistZ returnlistZaddrspecZfieldlenZ routeaddrrrrrMsL &$zAddrlistClass.getaddresscCs|j|jdkrdSd}|jd7_|jd}x|jt|jkr|rV|jd}n~|j|jdkrx|jd7_Pn\|j|jdkr|jd7_d}n8|j|jd kr|jd7_n|j}|jd7_P|jq4W|S) zParse a route address (Return-path value). This method just skips all the route stuff and returns the addrspec. rQNFrr>@Tr)rDr?rLr' getdomainrU)rFZ expectrouteZadlistrrrrV?s. zAddrlistClass.getrouteaddrcCs\g}|jx|jt|jkrd}|j|jdkrj|rL|dj rL|j|jd|jd7_d}nf|j|jdkr|jdt|jn>|j|j|j kr|r|d j r|jPn|j|j |j}|r|r|j|qW|jt|jks|j|jdkrt j |S|jd|jd7_|j|j }|sNt St j ||S) zParse an RFC 2822 addr-spec.TrrFr:z"%s"rYr!r!)rLr?r'rDstrippopr)rgetquoterBgetatomrJrKrZ)rFZaslistZ preserve_wsZwsZdomainrrrrU_s: $  zAddrlistClass.getaddrspeccCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrZ|jj|jq|j|jdkrz|j|jq|j|jdkr|jd7_|jdq|j|jdkrtS|j|j|j krPq|j|j qWtj |S)z-Get the complete domain name from an address.rrH[rrY) r?r'rDr@rEr)rIgetdomainliteralrJrBr^rK)rFZsdlistrrrrZs" zAddrlistClass.getdomainTcCs|j|j|krdSdg}d}|jd7_x|jt|jkr|rZ|j|j|jd}np|j|j|kr||jd7_PnN|r|j|jdkr|j|jq.n(|j|jdkrd}n|j|j|j|jd7_q.Wtj|S)aParse a header fragment delimited by special characters. `beginchar' is the start character for the fragment. If self is not looking at an instance of `beginchar' then getdelimited returns the empty string. `endchars' is a sequence of allowable end-delimiting characters. Parsing stops when one of these is encountered. If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed within the parsed fragment. rFrrHr9T)rDr?r'r)rIrJrK)rFZ begincharZendcharsZ allowcommentsZslistrrrr getdelimiteds( zAddrlistClass.getdelimitedcCs|jdddS)z1Get a quote-delimited fragment from self's field.r:z" F)ra)rFrrrr]szAddrlistClass.getquotecCs|jdddS)z7Get a parenthesis-delimited fragment from self's field.rHz) T)ra)rFrrrrIszAddrlistClass.getcommentcCsd|jdddS)z!Parse an RFC 2822 domain-literal.z[%s]r_z] F)ra)rFrrrr`szAddrlistClass.getdomainliteralNcCshdg}|dkr|j}xH|jt|jkr\|j|j|kr:Pn|j|j|j|jd7_qWtj|S)aParse an RFC 2822 atom. Optional atomends specifies a different set of end token delimiters (the default is to use self.atomends). This is used e.g. in getphraselist() since phrase endings must not include the `.' (which is legal in phrases).rNr)rBr?r'rDr)rJrK)rFrBZatomlistrrrr^szAddrlistClass.getatomcCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrX|j|jq|j|jdkrz|jj|jq|j|j|jkrPq|j|j |jqW|S)zParse a sequence of RFC 2822 phrases. A phrase is a sequence of words, which are in turn either RFC 2822 atoms or quoted-strings. Phrases are canonicalized by squeezing all runs of continuous whitespace into one space. rr:rH) r?r'rDrAr)r]rErIrCr^)rFrWrrrrSszAddrlistClass.getphraselist)T)N)__name__ __module__ __qualname____doc__rGrLrOrMrVrUrZrar]rIr`r^rSrrrrr=s; & % r=c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS) AddressListz@An AddressList encapsulates a list of parsed RFC 2822 addresses.cCs&tj|||r|j|_ng|_dS)N)r=rGrO addresslist)rFrDrrrrGs  zAddressList.__init__cCs t|jS)N)r'rg)rFrrr__len__szAddressList.__len__cCsBtd}|jdd|_x$|jD]}||jkr |jj|q W|S)N)rfrgr))rFothernewaddrxrrr__add__s   zAddressList.__add__cCs*x$|jD]}||jkr|jj|qW|S)N)rgr))rFrirkrrr__iadd__ s  zAddressList.__iadd__cCs2td}x$|jD]}||jkr|jj|qW|S)N)rfrgr))rFrirjrkrrr__sub__s   zAddressList.__sub__cCs*x$|jD]}||jkr|jj|qW|S)N)rgremove)rFrirkrrr__isub__s  zAddressList.__isub__cCs |j|S)N)rg)rFr+rrr __getitem__#szAddressList.__getitem__N) rbrcrdrerGrhrlrmrnrprqrrrrrfs rfipii ipii iDiiiD)re__all__r7r8rTrJZ COMMASPACEr*r%r0rr rrrr=rfrrrrs8   u   /