U e5dKQã@szdZddlmZddlmZddlmZddlmZGdd„dƒZGdd „d ƒZ Gd d „d e ƒZ d d „Z Gdd„dƒZ Gdd„de ƒZGdd„dƒZGdd„deƒZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„dƒZGd d!„d!ƒZGd"d#„d#eƒZGd$d%„d%eƒZGd&d'„d'ƒZGd(d)„d)ƒZeeeeeeeeeeeeeeeeeeeed*œZGd+d,„d,ƒZd-S).a;Representing and manipulating email headers via custom objects. This module provides an implementation of the HeaderRegistry API. The implementation is designed to flexibly follow RFC5322 rules. Eventually HeaderRegistry will be a public API, but it isn't yet, and will probably change some before that happens. é)ÚMappingProxyType)Úutils)Úerrors)Ú_header_value_parserc@s^eZdZddd„Zedd„ƒZedd„ƒZed d „ƒZed d „ƒZd d„Z dd„Z dd„Z dS)ÚAddressÚNcCsœd td||||fƒ¡}d|ks(d|kr0tdƒ‚|dk r†|s@|rHtdƒ‚t |¡\}}|rjtd ||¡ƒ‚|jrz|jd‚|j}|j }||_ ||_ ||_ dS) a÷Create an object representing a full email address. An address can have a 'display_name', a 'username', and a 'domain'. In addition to specifying the username and domain separately, they may be specified together by using the addr_spec keyword *instead of* the username and domain keywords. If an addr_spec string is specified it must be properly quoted according to RFC 5322 rules; an error will be raised if it is not. An Address object has display_name, username, domain, and addr_spec attributes, all of which are read-only. The addr_spec and the string value of the object are both quoted according to RFC5322 rules, but without any Content Transfer Encoding. rNú Ú z8invalid arguments; address parts cannot contain CR or LFz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r) ÚjoinÚfilterÚ ValueErrorÚ TypeErrorÚparserZ get_addr_specÚformatÚ all_defectsÚ local_partÚdomainÚ _display_nameÚ _usernameÚ_domain)ÚselfÚ display_nameÚusernamerÚ addr_specZinputsZa_sÚrest©rú,/usr/lib64/python3.8/email/headerregistry.pyÚ__init__s&þ zAddress.__init__cCs|jS©N©r©rrrrr<szAddress.display_namecCs|jSr)rr rrrr@szAddress.usernamecCs|jSr)rr rrrrDszAddress.domaincCsTt|jƒ}t|ƒt|tjƒkr.t |j¡}n|j}|jrH|d|jS|sPdS|S)z“The addr_spec (username@domain) portion of the address, quoted according to RFC 5322 rules, but with no Content Transfer Encoding. ú@ú<>)ÚsetrÚlenrZ DOT_ATOM_ENDSÚ quote_stringr)rÚnamesetZlprrrrHs zAddress.addr_speccCsd |jj|j|j|j¡S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))rÚ __class__Ú__name__rrrr rrrÚ__repr__Xs þzAddress.__repr__cCs^t|jƒ}t|ƒt|tjƒkr.t |j¡}n|j}|rX|jdkrFdn|j}d ||¡S|jS)Nr"rz{} <{}>)r#rr$rÚSPECIALSr%rr)rr&ÚdisprrrrÚ__str__]s  zAddress.__str__cCs8t|ƒt|ƒkrdS|j|jko6|j|jko6|j|jkS©NF)Útyperrr©rÚotherrrrÚ__eq__hs  ÿ þzAddress.__eq__)rrrN) r(Ú __module__Ú __qualname__rÚpropertyrrrrr)r,r1rrrrrs *     rc@sFeZdZddd„Zedd„ƒZedd„ƒZdd „Zd d „Zd d „Z dS)ÚGroupNcCs||_|rt|ƒntƒ|_dS)aCreate an object representing an address group. An address group consists of a display_name followed by colon and a list of addresses (see Address) terminated by a semi-colon. The Group is created by specifying a display_name and a possibly empty list of Address objects. A Group can also be used to represent a single address that is not in a group, which is convenient when manipulating lists that are a combination of Groups and individual Addresses. In this case the display_name should be set to None. In particular, the string representation of a Group whose display_name is None is the same as the Address object, if there is one and only one Address object in the addresses list. N)rÚtupleÚ _addresses)rrÚ addressesrrrrrszGroup.__init__cCs|jSrrr rrrr„szGroup.display_namecCs|jSr)r7r rrrr8ˆszGroup.addressescCsd |jj|j|j¡S)Nz${}(display_name={!r}, addresses={!r})rr'r(rr8r rrrr)Œs þzGroup.__repr__cCsŽ|jdkr&t|jƒdkr&t|jdƒS|j}|dk r\t|ƒ}t|ƒt|tjƒkr\t |¡}d dd„|jDƒ¡}|r~d|n|}d  ||¡S)Nérú, css|]}t|ƒVqdSr©Ústr)Ú.0ÚxrrrÚ ™sz Group.__str__..ú z{}:{};) rr$r8r<r#rr*r%r r)rr+r&Zadrstrrrrr,‘s z Group.__str__cCs,t|ƒt|ƒkrdS|j|jko*|j|jkSr-)r.rr8r/rrrr1�s   ÿz Group.__eq__)NN) r(r2r3rr4rr8r)r,r1rrrrr5ps    r5c@sTeZdZdZdd„Zdd„Zedd„ƒZedd „ƒZd d „Z e d d „ƒZ dd„Z dS)Ú BaseHeadera|Base class for message headers. Implements generic behavior and provides tools for subclasses. A subclass must define a classmethod named 'parse' that takes an unfolded value string and a dictionary as its arguments. The dictionary will contain one key, 'defects', initialized to an empty list. After the call the dictionary must contain two additional keys: parse_tree, set to the parse tree obtained from parsing the header, and 'decoded', set to the string value of the idealized representation of the data from the value. (That is, encoded words are decoded, and values that have canonical representations are so represented.) The defects key is intended to collect parsing defects, which the message parser will subsequently dispose of as appropriate. The parser should not, insofar as practical, raise any errors. Defects should be added to the list instead. The standard header parsers register defects for RFC compliance issues, for obsolete RFC syntax, and for unrecoverable parsing errors. The parse method may add additional keys to the dictionary. In this case the subclass must define an 'init' method, which will be passed the dictionary as its keyword arguments. The method should use (usually by setting them as the value of similarly named attributes) and remove all the extra keys added by its parse method, and then use super to call its parent class with the remaining arguments and keywords. The subclass should also make sure that a 'max_count' attribute is defined that is either None or 1. XXX: need to better define this API. cCs\dgi}| ||¡t |d¡r4t |d¡|d<t ||d¡}|d=|j|f|Ž|S)NÚdefectsÚdecoded)ÚparserZ_has_surrogatesÚ _sanitizer<Ú__new__Úinit)ÚclsÚnameÚvalueÚkwdsrrrrrFÈs zBaseHeader.__new__cCs||_||_||_dSr)Ú_nameÚ _parse_treeÚ_defects)rrIÚ parse_treerBrrrrGÒszBaseHeader.initcCs|jSr)rLr rrrrI×szBaseHeader.namecCs t|jƒSr)r6rNr rrrrBÛszBaseHeader.defectscCst|jj|jjt|ƒf|jfSr)Ú_reconstruct_headerr'r(Ú __bases__r<Ú__dict__r rrrÚ __reduce__ßsýùzBaseHeader.__reduce__cCs t ||¡Sr)r<rF)rHrJrrrÚ _reconstructészBaseHeader._reconstructc Cs`t t t |jd¡t dd¡g¡g¡}|jrH| t t dd¡g¡¡| |j¡|j |d�S)atFold header according to policy. The parsed representation of the header is folded according to RFC5322 rules, as modified by the policy. If the parse tree contains surrogateescaped bytes, the bytes are CTE encoded using the charset 'unknown-8bit". Any non-ASCII characters in the parse tree are CTE encoded using charset utf-8. XXX: make this a policy setting. The returned value is an ASCII-only string possibly containing linesep characters, and ending with a linesep character. The string includes the header name and the ': ' separator. z header-nameú:z header-sepr@Zfws)Úpolicy) rZHeaderZ HeaderLabelZ ValueTerminalrIrMÚappendZCFWSListZWhiteSpaceTerminalÚfold)rrVÚheaderrrrrXís  þÿÿ zBaseHeader.foldN) r(r2r3Ú__doc__rFrGr4rIrBrSÚ classmethodrTrXrrrrrA¦s      rAcCst||iƒ |¡Sr)r.rT)Zcls_nameÚbasesrJrrrrP srPc@s&eZdZdZeejƒZedd„ƒZ dS)ÚUnstructuredHeaderNcCs"| |¡|d<t|dƒ|d<dS)NrOrC)Ú value_parserr<©rHrJrKrrrrDszUnstructuredHeader.parse) r(r2r3Ú max_countÚ staticmethodrÚget_unstructuredr^r[rDrrrrr]s r]c@seZdZdZdS)ÚUniqueUnstructuredHeaderr9N©r(r2r3r`rrrrrcsrccsFeZdZdZdZeejƒZe dd„ƒZ ‡fdd„Z e dd„ƒZ ‡ZS) Ú DateHeadera‘Header whose value consists of a single timestamp. Provides an additional attribute, datetime, which is either an aware datetime using a timezone, or a naive datetime if the timezone in the input string is -0000. Also accepts a datetime as input. The 'value' attribute is the normalized form of the timestamp, which means it is the output of format_datetime on the datetime. NcCsz|s6|d t ¡¡d|d<d|d<t ¡|d<dSt|tƒrJt |¡}||d<t  |d¡|d<|  |d¡|d<dS)NrBÚdatetimerrCrO) rWrZHeaderMissingRequiredValuerZ TokenListÚ isinstancer<rZparsedate_to_datetimeZformat_datetimer^r_rrrrD.s   zDateHeader.parsecs| d¡|_tƒj||ŽdS)Nrf)ÚpopÚ _datetimeÚsuperrG©rÚargsÚkw©r'rrrG<s zDateHeader.initcCs|jSr)rir rrrrf@szDateHeader.datetime)r(r2r3rZr`rarrbr^r[rDrGr4rfÚ __classcell__rrrnrres   rec@seZdZdZdS)ÚUniqueDateHeaderr9NrdrrrrrpEsrpcsPeZdZdZedd„ƒZedd„ƒZ‡fdd„Ze dd „ƒZ e d d „ƒZ ‡Z S) Ú AddressHeaderNcCst |¡\}}|Sr)rZget_address_list)rJÚ address_listrrrr^NszAddressHeader.value_parsercCs¾t|tƒrV| |¡|d<}g}|jD]"}| t|jdd„|jDƒƒ¡q&t|j ƒ}n"t |dƒsf|g}dd„|Dƒ}g}||d<||d<d  d d„|Dƒ¡|d <d|krº| |d ¡|d<dS) NrOcSs*g|]"}t|jpd|jpd|jp"dƒ‘qS)r)rrrr)r=ZmbrrrÚ ]s ý þz'AddressHeader.parse..Ú__iter__cSs&g|]}t|dƒstd|gƒn|‘qS)r8N)Úhasattrr5©r=ÚitemrrrrsfsþÚgroupsrBr:cSsg|] }t|ƒ‘qSrr;rvrrrrslsrC) rgr<r^r8rWr5rZ all_mailboxesÚlistrrur )rHrJrKrrrxZaddrrBrrrrDTs*   ýÿ  þzAddressHeader.parsecs(t| d¡ƒ|_d|_tƒj||ŽdS)Nrx)r6rhÚ_groupsr7rjrGrkrnrrrGpszAddressHeader.initcCs|jSr)rzr rrrrxuszAddressHeader.groupscCs&|jdkr tdd„|jDƒƒ|_|jS)Ncss|]}|jD] }|Vq qdSr)r8)r=ÚgroupÚaddressrrrr?|sÿz*AddressHeader.addresses..)r7r6rzr rrrr8ys zAddressHeader.addresses) r(r2r3r`rar^r[rDrGr4rxr8rorrrnrrqJs    rqc@seZdZdZdS)ÚUniqueAddressHeaderr9Nrdrrrrr}�sr}c@seZdZedd„ƒZdS)ÚSingleAddressHeadercCs(t|jƒdkrtd |j¡ƒ‚|jdS)Nr9z9value of single address header {} is not a single addressr)r$r8r rrIr rrrr|ˆs ÿzSingleAddressHeader.addressN)r(r2r3r4r|rrrrr~†sr~c@seZdZdZdS)ÚUniqueSingleAddressHeaderr9Nrdrrrrr�srcsZeZdZdZeejƒZedd„ƒZ ‡fdd„Z e dd„ƒZ e dd „ƒZ e d d „ƒZ‡ZS) ÚMIMEVersionHeaderr9cCs€| |¡|d<}t|ƒ|d<|d |j¡|jdkrÊsþ z1ParameterizedMIMEHeader.parse..)r^r<r„rrŠr…rrrrDÁs   þzParameterizedMIMEHeader.parsecs| d¡|_tƒj||ŽdS)NrŠ)rhÚ_paramsrjrGrkrnrrrGÎs zParameterizedMIMEHeader.initcCs t|jƒSr)rr�r rrrrŠÒszParameterizedMIMEHeader.params) r(r2r3r`r[rDrGr4rŠrorrrnrr‰ºs  r‰csJeZdZeejƒZ‡fdd„Zedd„ƒZ edd„ƒZ edd„ƒZ ‡Z S) ÚContentTypeHeadercs2tƒj||Žt |jj¡|_t |jj¡|_dSr) rjrGrrErMÚmaintypeÚ _maintypeÚsubtypeÚ_subtyperkrnrrrGÛszContentTypeHeader.initcCs|jSr)r�r rrrr�àszContentTypeHeader.maintypecCs|jSr)r’r rrrr‘äszContentTypeHeader.subtypecCs|jd|jS)Nú/)r�r‘r rrrÚ content_typeèszContentTypeHeader.content_type) r(r2r3rarZparse_content_type_headerr^rGr4r�r‘r”rorrrnrrŽ×s    rŽcs2eZdZeejƒZ‡fdd„Zedd„ƒZ ‡Z S)ÚContentDispositionHeadercs2tƒj||Ž|jj}|dkr"|nt |¡|_dSr)rjrGrMÚcontent_dispositionrrEÚ_content_disposition)rrlrmZcdrnrrrGñszContentDispositionHeader.initcCs|jSr)r—r rrrr–ösz,ContentDispositionHeader.content_disposition) r(r2r3rarZ parse_content_disposition_headerr^rGr4r–rorrrnrr•ís  r•csBeZdZdZeejƒZedd„ƒZ ‡fdd„Z e dd„ƒZ ‡Z S)ÚContentTransferEncodingHeaderr9cCs2| |¡|d<}t|ƒ|d<|d |j¡dS©NrOrCrB©r^r<r„rr…rrrrDs z#ContentTransferEncodingHeader.parsecs"tƒj||Žt |jj¡|_dSr)rjrGrrErMÚcteÚ_cterkrnrrrGsz"ContentTransferEncodingHeader.initcCs|jSr)rœr rrrr› sz!ContentTransferEncodingHeader.cte)r(r2r3r`rarZ&parse_content_transfer_encoding_headerr^r[rDrGr4r›rorrrnrr˜ûs   r˜c@s&eZdZdZeejƒZedd„ƒZ dS)ÚMessageIDHeaderr9cCs2| |¡|d<}t|ƒ|d<|d |j¡dSr™ršr…rrrrDs zMessageIDHeader.parseN) r(r2r3r`rarZparse_message_idr^r[rDrrrrr�s r�)ZsubjectÚdatez resent-datez orig-dateZsenderz resent-senderÚtoz resent-toZccz resent-ccZbccz resent-bccÚfromz resent-fromzreply-toz mime-versionz content-typezcontent-dispositionzcontent-transfer-encodingz message-idc@s8eZdZdZeedfdd„Zdd„Zdd„Zd d „Z d S) ÚHeaderRegistryz%A header_factory and header registry.TcCs&i|_||_||_|r"|j t¡dS)aèCreate a header_factory that works with the Policy API. base_class is the class that will be the last class in the created header class's __bases__ list. default_class is the class that will be used if "name" (see __call__) does not appear in the registry. use_default_map controls whether or not the default mapping of names to specialized classes is copied in to the registry when the factory is created. The default is True. N)ÚregistryÚ base_classÚ default_classÚupdateÚ_default_header_map)rr£r¤Zuse_default_maprrrr9s zHeaderRegistry.__init__cCs||j| ¡<dS)zLRegister cls as the specialized class for handling "name" headers. N)r¢r‹©rrIrHrrrÚ map_to_typeKszHeaderRegistry.map_to_typecCs,|j | ¡|j¡}td|j||jfiƒS)NÚ_)r¢Úgetr‹r¤r.r(r£r§rrrÚ __getitem__QszHeaderRegistry.__getitem__cCs||||ƒS)aƒCreate a header instance for header 'name' from 'value'. Creates a header instance by creating a specialized class for parsing and representing the specified header by combining the factory base_class with a specialized class from the registry or the default_class, and passing the name and value to the constructed class's constructor. r)rrIrJrrrÚ__call__Us zHeaderRegistry.__call__N) r(r2r3rZrAr]rr¨r«r¬rrrrr¡5sÿ r¡N)rZÚtypesrZemailrrrrrr5r<rArPr]rcrerprqr}r~rr€r‰rŽr•r˜r�r¦r¡rrrrÚsX    `6d '7 %ì