OwlCyberSecurity - MANAGER
Edit File: _header_value_parser.cpython-38.opt-1.pyc
U ����e5dϡ������������������ ���@���s���d�Z�ddlZddlZddlZddlmZ�ddlmZ�ddlm Z �ddlmZ�ddlmZ�e d�Zee d �B�Ze d �ZeeB�Zee d��Zee d��Zee d �B�e d��ZeeB�Zee d�B�ZeeB�Zee d��Zdd��Ze�dejejB��ZG�dd��de�ZG�dd��de�Z G�dd��de�Z!G�dd��de�Z"G�dd��de�Z#G�dd��de �Z$G�dd ��d e�Z%G�d!d"��d"e�Z&G�d#d$��d$e�Z'G�d%d&��d&e�Z(G�d'd(��d(e(�Z)G�d)d*��d*e �Z*G�d+d,��d,e�Z+G�d-d.��d.e�Z,G�d/d0��d0e�Z-G�d1d2��d2e�Z.G�d3d4��d4e�Z/G�d5d6��d6e�Z0G�d7d8��d8e�Z1G�d9d:��d:e�Z2G�d;d<��d<e�Z3G�d=d>��d>e�Z4G�d?d@��d@e�Z5G�dAdB��dBe�Z6G�dCdD��dDe�Z7G�dEdF��dFe�Z8G�dGdH��dHe�Z9G�dIdJ��dJe�Z:G�dKdL��dLe"�Z;G�dMdN��dNe�Z<G�dOdP��dPe�Z=G�dQdR��dRe�Z>G�dSdT��dTe�Z?G�dUdV��dVe?�Z@G�dWdX��dXe�ZAG�dYdZ��dZe�ZBG�d[d\��d\e�ZCG�d]d^��d^e�ZDG�d_d`��d`e�ZEG�dadb��dbeE�ZFG�dcdd��ddeE�ZGG�dedf��dfe�ZHG�dgdh��dhe�ZIG�didj��dje�ZJG�dkdl��dleJ�ZKG�dmdn��dneK�ZLG�dodp��dpe�ZMG�dqdr��dreN�ZOG�dsdt��dteO�ZPG�dudv��dveO�ZQG�dwdx��dxeP�ZRG�dydz��dzejS�ZTeQdd{�ZUeQd|d}�ZVeQd~d�ZWe�d��Xd��Ye���jZZ[e�d��Xe�\d��Ye����j]Z^e�d��j_Z`e�d��Xe�\d��Ye����j]Zae�d��Xe�\d��Ye����j]Zbe�d��Xe�\d��Ye����j]Zcd�d���Zdd�d���Zed�d���Zfd�d���Zgd�d���Zhd�d���Zid�d���Zjd�d���Zkd�d���Zld�d���Zmd�d���Znd�d���Zod�d���Zpd�d���Zqd�d���Zrd�d���Zsd�d���Ztd�d���Zud�d���Zvd�d���Zwd�d���Zxd�d���Zyd�d���Zzd�d���Z{d�d���Z|d�d���Z}d�d���Z~d�d���Zd�d���Z�d�d���Z�d�d���Z�d�dÄ�Z�d�dń�Z�d�dDŽ�Z�d�dɄ�Z�d�d˄�Z�d�d̈́�Z�d�dτ�Z�d�dф�Z�d�dӄ�Z�d�dՄ�Z�d�dׄ�Z�d�dل�Z�d�dۄ�Z�d�d݄�Z�d�d߄�Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d���Z�d�d���Z�dS�)�al��Header value parser implementing various email-related RFC parsing rules. The parsing methods defined in this module implement various email related parsing rules. Principal among them is RFC 5322, which is the followon to RFC 2822 and primarily a clarification of the former. It also implements RFC 2047 encoded word decoding. RFC 5322 goes to considerable trouble to maintain backward compatibility with RFC 822 in the parse phase, while cleaning up the structure on the generation phase. This parser supports correct RFC 5322 generation by tagging white space as folding white space only when folding is allowed in the non-obsolete rule sets. Actually, the parser is even more generous when accepting input than RFC 5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages. Where possible deviations from the standard are annotated on the 'defects' attribute of tokens that deviate. The general structure of the parser follows RFC 5322, and uses its terminology where there is a direct correspondence. Where the implementation requires a somewhat different structure than that used by the formal grammar, new terms that mimic the closest existing terms are used. Thus, it really helps to have a copy of RFC 5322 handy when studying this code. Input to the parser is a string that has already been unfolded according to RFC 5322 rules. According to the RFC this unfolding is the very first step, and this parser leaves the unfolding step to a higher level message parser, which will have already detected the line breaks that need unfolding while determining the beginning and end of each header. The output of the parser is a TokenList object, which is a list subclass. A TokenList is a recursive data structure. The terminal nodes of the structure are Terminal objects, which are subclasses of str. These do not correspond directly to terminal objects in the formal grammar, but are instead more practical higher level combinations of true terminals. All TokenList and Terminal objects have a 'value' attribute, which produces the semantically meaningful value of that part of the parse subtree. The value of all whitespace tokens (no matter how many sub-tokens they may contain) is a single space, as per the RFC rules. This includes 'CFWS', which is herein included in the general class of whitespace tokens. There is one exception to the rule that whitespace tokens are collapsed into single spaces in values: in the value of a 'bare-quoted-string' (a quoted-string with no leading or trailing whitespace), any whitespace that appeared between the quotation marks is preserved in the returned value. Note that in all Terminal strings quoted pairs are turned into their unquoted values. All TokenList and Terminal objects also have a string value, which attempts to be a "canonical" representation of the RFC-compliant form of the substring that produced the parsed subtree, including minimal use of quoted pair quoting. Whitespace runs are not collapsed. Comment tokens also have a 'content' attribute providing the string found between the parens (including any nested comments) with whitespace preserved. All TokenList and Terminal objects have a 'defects' attribute which is a possibly empty list all of the defects found while creating the token. Defects may appear on any token in the tree, and a composite list of all defects in the subtree is available through the 'all_defects' attribute of any node. (For Terminal notes x.defects == x.all_defects.) Each object in a parse tree is called a 'token', and each has a 'token_type' attribute that gives the name from the RFC 5322 grammar that it represents. Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that may be produced: 'ptext'. A 'ptext' is a string of printable ascii characters. It is returned in place of lists of (ctext/quoted-pair) and (qtext/quoted-pair). XXX: provide complete list of token types. �����N)� hexdigits)� itemgetter)�_encoded_words)�errors)�utilsz �(z ()<>@,:;.\"[]�.z."(z/?=z*'%�%c�����������������C���s ���dt�|���dd��dd��d�S�)N�"�\�\\z\")�str�replace��value��r����2/usr/lib64/python3.8/email/_header_value_parser.py�quote_string`���s����r���z� =\? # literal =? [^?]* # charset \? # literal ? [qQbB] # literal 'q' or 'b', case insensitive \? # literal ? .*? # encoded word \?= # literal ?= c�����������������������s����e�Zd�ZdZdZdZ��fdd�Zdd��Z��fdd�Ze d d ���Z e dd���Zd d��Ze dd���Z e dd���Zdd��Zddd�Zddd�Zddd�Z���ZS�)� TokenListNTc��������������������s���t���j||��g�|�_d�S��N)�super�__init__�defects)�self�args�kw�� __class__r���r���r���y���s����zTokenList.__init__c�����������������C���s���d��dd��|�D���S�)N��c�����������������s���s���|�]}t�|�V��qd�S�r����r �����.0�xr���r���r���� <genexpr>~���s�����z$TokenList.__str__.<locals>.<genexpr>��join�r���r���r���r����__str__}���s����zTokenList.__str__c��������������������s���d��|�jjt������S��Nz{}({})��formatr����__name__r����__repr__r&���r���r���r���r,�������s���� �zTokenList.__repr__c�����������������C���s���d��dd��|�D���S�)Nr���c�����������������s���s���|�]}|j�r|j�V��qd�S�r���r���r ���r���r���r���r#�������s������z"TokenList.value.<locals>.<genexpr>r$���r&���r���r���r���r�������s����zTokenList.valuec�����������������C���s���t�dd��|�D��|�j�S�)Nc�����������������s���s���|�]}|j�V��qd�S�r���)�all_defectsr ���r���r���r���r#�������s�����z(TokenList.all_defects.<locals>.<genexpr>)�sumr���r&���r���r���r���r-�������s����zTokenList.all_defectsc�����������������C���s���|�d�����S��Nr���)�startswith_fwsr&���r���r���r���r0�������s����zTokenList.startswith_fwsc�����������������C���s���t�dd��|�D���S�)zATrue if all top level tokens of this part may be RFC2047 encoded.c�����������������s���s���|�]}|j�V��qd�S�r���)� as_ew_allowed)r!����partr���r���r���r#�������s�����z*TokenList.as_ew_allowed.<locals>.<genexpr>)�allr&���r���r���r���r1�������s����zTokenList.as_ew_allowedc�����������������C���s���g�}|�D�]}|��|j��q|S�r���)�extend�comments)r���r5����tokenr���r���r���r5�������s����zTokenList.commentsc����������������C���s���t�|�|d�S�)N��policy)�_refold_parse_tree�r���r8���r���r���r����fold����s����zTokenList.foldr���c�����������������C���s���t�|�j|d���d�S�)N��indent)�print�ppstr�r���r=���r���r���r����pprint����s����zTokenList.pprintc�����������������C���s���d��|�j|d��S�)N� r<���)r%����_ppr@���r���r���r���r?�������s����zTokenList.ppstrc�����������������c���sz���d��||�jj|�j�V��|�D�]4}t|d�s:|d��|��V��q|�|d��E�d�H��q|�jrdd��|�j�}nd}d��||�V��d�S�)Nz{}{}/{}(rC���z* !! invalid element in token list: {!r}z z Defects: {}r���z{}){})r*���r���r+���� token_type�hasattrrC���r���)r���r=���r6���Zextrar���r���r���rC�������s����� � z TokenList._pp)r���)r���)r���)r+���� __module__�__qualname__rD����syntactic_break�ew_combine_allowedr���r'���r,����propertyr���r-���r0���r1���r5���r;���rA���r?���rC���� __classcell__r���r���r���r���r���s���s&��� r���c�������������������@���s$���e�Zd�Zedd���Zedd���ZdS�)�WhiteSpaceTokenListc�����������������C���s���dS��N� r���r&���r���r���r���r�������s����zWhiteSpaceTokenList.valuec�����������������C���s���dd��|�D��S�)Nc�����������������S���s���g�|�]}|j�d�kr|j�qS�)�comment)rD����contentr ���r���r���r���� <listcomp>����s����� �z0WhiteSpaceTokenList.comments.<locals>.<listcomp>r���r&���r���r���r���r5�������s����zWhiteSpaceTokenList.commentsN)r+���rF���rG���rJ���r���r5���r���r���r���r���rL�������s��� rL���c�������������������@���s���e�Zd�ZdZdS�)�UnstructuredTokenList�unstructuredN�r+���rF���rG���rD���r���r���r���r���rR�������s���rR���c�������������������@���s���e�Zd�ZdZdS�)�Phrase�phraseNrT���r���r���r���r���rU�������s���rU���c�������������������@���s���e�Zd�ZdZdS�)�WordZwordNrT���r���r���r���r���rW�������s���rW���c�������������������@���s���e�Zd�ZdZdS�)�CFWSList�cfwsNrT���r���r���r���r���rX�������s���rX���c�������������������@���s���e�Zd�ZdZdS�)�Atom�atomNrT���r���r���r���r���rZ�������s���rZ���c�������������������@���s���e�Zd�ZdZdZdS�)�Tokenr6���FN)r+���rF���rG���rD���Zencode_as_ewr���r���r���r���r\�������s���r\���c�������������������@���s���e�Zd�ZdZdZdZdZdS�)�EncodedWord�encoded-wordN)r+���rF���rG���rD����cte�charset�langr���r���r���r���r]�������s���r]���c�������������������@���s4���e�Zd�ZdZedd���Zedd���Zedd���ZdS�) �QuotedString� quoted-stringc�����������������C���s"���|�D�]}|j�dkr|j��S�qd�S��N�bare-quoted-string�rD���r����r���r"���r���r���r���rP�������s���� zQuotedString.contentc�����������������C���s>���g�}|�D�]*}|j�dkr&|�t|���q|�|j��qd�|�S�)Nre���r���)rD����appendr ���r���r%���)r����resr"���r���r���r����quoted_value����s���� zQuotedString.quoted_valuec�����������������C���s"���|�D�]}|j�dkr|j��S�qd�S�rd���rf����r���r6���r���r���r����stripped_value����s���� zQuotedString.stripped_valueN)r+���rF���rG���rD���rJ���rP���rj���rl���r���r���r���r���rb�������s��� rb���c�������������������@���s$���e�Zd�ZdZdd��Zedd���ZdS�)�BareQuotedStringre���c�����������������C���s���t�d�dd��|�D����S�)Nr���c�����������������s���s���|�]}t�|�V��qd�S�r���r���r ���r���r���r���r#������s�����z+BareQuotedString.__str__.<locals>.<genexpr>)r���r%���r&���r���r���r���r'�������s����zBareQuotedString.__str__c�����������������C���s���d��dd��|�D���S�)Nr���c�����������������s���s���|�]}t�|�V��qd�S�r���r���r ���r���r���r���r#�����s�����z)BareQuotedString.value.<locals>.<genexpr>r$���r&���r���r���r���r�����s����zBareQuotedString.valueN)r+���rF���rG���rD���r'���rJ���r���r���r���r���r���rm�������s���rm���c�������������������@���s8���e�Zd�ZdZdd��Zdd��Zedd���Zedd ���Zd S�)�CommentrO���c��������������������s(���d��tdg��fdd���D��dggg���S�)Nr���r���c��������������������s���g�|�]}����|��qS�r���)�quoter ���r&���r���r���rQ�����s�����z#Comment.__str__.<locals>.<listcomp>�))r%���r.���r&���r���r&���r���r'�����s������zComment.__str__c�����������������C���s2���|j�dkrt|�S�t|��dd��dd��dd�S�)NrO���r���r���r���z\(rp���z\))rD���r ���r���)r���r���r���r���r���ro�����s���� ����z Comment.quotec�����������������C���s���d��dd��|�D���S�)Nr���c�����������������s���s���|�]}t�|�V��qd�S�r���r���r ���r���r���r���r#�����s�����z"Comment.content.<locals>.<genexpr>r$���r&���r���r���r���rP�����s����zComment.contentc�����������������C���s���|�j�gS�r���)rP���r&���r���r���r���r5�����s����zComment.commentsN) r+���rF���rG���rD���r'���ro���rJ���rP���r5���r���r���r���r���rn�����s��� rn���c�������������������@���s4���e�Zd�ZdZedd���Zedd���Zedd���ZdS�) �AddressListzaddress-listc�����������������C���s���dd��|�D��S�)Nc�����������������S���s���g�|�]}|j�d�kr|�qS�)�address�rD���r ���r���r���r���rQ���'��s����� �z)AddressList.addresses.<locals>.<listcomp>r���r&���r���r���r���� addresses%��s����zAddressList.addressesc�����������������C���s���t�dd��|�D��g��S�)Nc�����������������s���s���|�]}|j�d�kr|jV��qdS��rr���N�rD���� mailboxesr ���r���r���r���r#���+��s���� �z(AddressList.mailboxes.<locals>.<genexpr>�r.���r&���r���r���r���rw���)��s ������zAddressList.mailboxesc�����������������C���s���t�dd��|�D��g��S�)Nc�����������������s���s���|�]}|j�d�kr|jV��qdS�ru����rD���� all_mailboxesr ���r���r���r���r#���0��s���� �z,AddressList.all_mailboxes.<locals>.<genexpr>rx���r&���r���r���r���rz���.��s ������zAddressList.all_mailboxesN)r+���rF���rG���rD���rJ���rt���rw���rz���r���r���r���r���rq���!��s��� rq���c�������������������@���s4���e�Zd�ZdZedd���Zedd���Zedd���ZdS�) �Addressrr���c�����������������C���s���|�d�j�dkr|�d�jS�d�S�)Nr����group�rD����display_namer&���r���r���r���r~���8��s����zAddress.display_namec�����������������C���s4���|�d�j�dkr|�d�gS�|�d�j�dkr*g�S�|�d�jS��Nr����mailbox�invalid-mailboxrv���r&���r���r���r���rw���=��s ���� zAddress.mailboxesc�����������������C���s:���|�d�j�dkr|�d�gS�|�d�j�dkr0|�d�gS�|�d�jS�r���ry���r&���r���r���r���rz���E��s ���� zAddress.all_mailboxesN)r+���rF���rG���rD���rJ���r~���rw���rz���r���r���r���r���r{���4��s��� r{���c�������������������@���s(���e�Zd�ZdZedd���Zedd���ZdS�)�MailboxList�mailbox-listc�����������������C���s���dd��|�D��S�)Nc�����������������S���s���g�|�]}|j�d�kr|�qS�)r����rs���r ���r���r���r���rQ���S��s����� �z)MailboxList.mailboxes.<locals>.<listcomp>r���r&���r���r���r���rw���Q��s����zMailboxList.mailboxesc�����������������C���s���dd��|�D��S�)Nc�����������������S���s���g�|�]}|j�d�kr|�qS�))r����r����rs���r ���r���r���r���rQ���W��s���� �z-MailboxList.all_mailboxes.<locals>.<listcomp>r���r&���r���r���r���rz���U��s����zMailboxList.all_mailboxesN�r+���rF���rG���rD���rJ���rw���rz���r���r���r���r���r����M��s ��� r����c�������������������@���s(���e�Zd�ZdZedd���Zedd���ZdS�)� GroupList� group-listc�����������������C���s ���|�r|�d�j�dkrg�S�|�d�jS��Nr���r����rv���r&���r���r���r���rw���_��s����zGroupList.mailboxesc�����������������C���s ���|�r|�d�j�dkrg�S�|�d�jS�r����ry���r&���r���r���r���rz���e��s����zGroupList.all_mailboxesNr����r���r���r���r���r����[��s ��� r����c�������������������@���s4���e�Zd�ZdZedd���Zedd���Zedd���ZdS�) �Groupr|���c�����������������C���s���|�d�j�dkrg�S�|�d�jS��N����r����rv���r&���r���r���r���rw���p��s����zGroup.mailboxesc�����������������C���s���|�d�j�dkrg�S�|�d�jS�r����ry���r&���r���r���r���rz���v��s����zGroup.all_mailboxesc�����������������C���s ���|�d�j�S�r/���)r~���r&���r���r���r���r~���|��s����zGroup.display_nameN)r+���rF���rG���rD���rJ���rw���rz���r~���r���r���r���r���r����l��s��� r����c�������������������@���sL���e�Zd�ZdZedd���Zedd���Zedd���Zedd ���Zed d���Z dS�) �NameAddr� name-addrc�����������������C���s���t�|��dkrd�S�|�d�jS��N����r���)�lenr~���r&���r���r���r���r~������s����zNameAddr.display_namec�����������������C���s ���|�d�j�S��N����� local_partr&���r���r���r���r�������s����zNameAddr.local_partc�����������������C���s ���|�d�j�S�r������domainr&���r���r���r���r�������s����zNameAddr.domainc�����������������C���s ���|�d�j�S�r����)�router&���r���r���r���r�������s����zNameAddr.routec�����������������C���s ���|�d�j�S�r������ addr_specr&���r���r���r���r�������s����zNameAddr.addr_specN� r+���rF���rG���rD���rJ���r~���r����r����r����r����r���r���r���r���r�������s��� r����c�������������������@���s@���e�Zd�ZdZedd���Zedd���Zedd���Zedd ���Zd S�)� AngleAddrz angle-addrc�����������������C���s"���|�D�]}|j�dkr|j��S�qd�S��N� addr-spec)rD���r����rg���r���r���r���r�������s���� zAngleAddr.local_partc�����������������C���s"���|�D�]}|j�dkr|j��S�qd�S�r�����rD���r����rg���r���r���r���r�������s���� zAngleAddr.domainc�����������������C���s"���|�D�]}|j�dkr|j��S�qd�S�)N� obs-route)rD����domainsrg���r���r���r���r�������s���� zAngleAddr.routec�����������������C���s<���|�D�]2}|j�dkr|jr"|j��S�t|j�|j���S�qdS�)Nr����z<>)rD���r����r����r���rg���r���r���r���r�������s���� zAngleAddr.addr_specN) r+���rF���rG���rD���rJ���r����r����r����r����r���r���r���r���r�������s��� r����c�������������������@���s���e�Zd�ZdZedd���ZdS�)�ObsRouter����c�����������������C���s���dd��|�D��S�)Nc�����������������S���s���g�|�]}|j�d�kr|j�qS�r����r����r ���r���r���r���rQ������s����� �z$ObsRoute.domains.<locals>.<listcomp>r���r&���r���r���r���r�������s����zObsRoute.domainsN)r+���rF���rG���rD���rJ���r����r���r���r���r���r�������s���r����c�������������������@���sL���e�Zd�ZdZedd���Zedd���Zedd���Zedd ���Zed d���Z dS�) �Mailboxr����c�����������������C���s���|�d�j�dkr|�d�jS�d�S��Nr���r����r}���r&���r���r���r���r~������s����zMailbox.display_namec�����������������C���s ���|�d�j�S�r/���r����r&���r���r���r���r�������s����zMailbox.local_partc�����������������C���s ���|�d�j�S�r/���r����r&���r���r���r���r�������s����zMailbox.domainc�����������������C���s���|�d�j�dkr|�d�jS�d�S�r����)rD���r����r&���r���r���r���r�������s����z Mailbox.routec�����������������C���s ���|�d�j�S�r/���r����r&���r���r���r���r�������s����zMailbox.addr_specNr����r���r���r���r���r�������s��� r����c�������������������@���s,���e�Zd�ZdZedd���Ze�Z�Z�ZZ dS�)�InvalidMailboxr����c�����������������C���s���d�S�r���r���r&���r���r���r���r~������s����zInvalidMailbox.display_nameNr����r���r���r���r���r�������s��� r����c�����������������������s(���e�Zd�ZdZdZe��fdd��Z���ZS�)�Domainr����Fc��������������������s���d��t��j����S��Nr����r%���r���r����splitr&���r���r���r���r�������s����z Domain.domain)r+���rF���rG���rD���r1���rJ���r����rK���r���r���r���r���r�������s���r����c�������������������@���s���e�Zd�ZdZdS�)�DotAtom�dot-atomNrT���r���r���r���r���r�������s���r����c�������������������@���s���e�Zd�ZdZdZdS�)�DotAtomTextz dot-atom-textTN�r+���rF���rG���rD���r1���r���r���r���r���r�������s���r����c�������������������@���s���e�Zd�ZdZdZdS�)� NoFoldLiteralzno-fold-literalFNr����r���r���r���r���r�������s���r����c�������������������@���sD���e�Zd�ZdZdZedd���Zedd���Zedd���Zed d ���Z dS�)�AddrSpecr����Fc�����������������C���s ���|�d�j�S�r/���r����r&���r���r���r���r���� ��s����zAddrSpec.local_partc�����������������C���s���t�|��dk�rd�S�|�d�jS�)N����r����)r����r����r&���r���r���r���r������s����zAddrSpec.domainc�����������������C���s<���t�|��dk�r|�d�jS�|�d�j���|�d�j�|�d�j����S�)Nr����r���r����r����)r����r����rstrip�lstripr&���r���r���r���r�����s���� zAddrSpec.valuec�����������������C���sL���t�|�j�}t|�t|t��kr*t|�j�}n|�j}|�jd�k rH|d�|�j�S�|S�)N�@)�setr����r����� DOT_ATOM_ENDSr���r����)r���ZnamesetZlpr���r���r���r������s���� zAddrSpec.addr_specN) r+���rF���rG���rD���r1���rJ���r����r����r���r����r���r���r���r���r������s��� r����c�������������������@���s���e�Zd�ZdZdZdS�)�ObsLocalPartzobs-local-partFNr����r���r���r���r���r����&��s���r����c�����������������������s4���e�Zd�ZdZdZedd���Ze��fdd��Z���ZS�)�DisplayNamezdisplay-nameFc�����������������C���s����t�|��}t|�dkr|jS�|d�jdkr4|�d��n*|d�d�jdkr^t�|d�dd����|d<�|d�jdkrv|����n*|d�d�jdkr�t�|d�d�d���|d<�|jS�)Nr���rY���r����r����)r���r����r���rD����pop)r���ri���r���r���r���r~���1��s���� zDisplayName.display_namec��������������������s����d}|�j�rd}n|�D�]}|jdkrd}qt|��dkr�|r�d�}}|�d�jdks`|�d�d�jdkrdd}|�d�jdks�|�d�d�jdkr�d}|t|�j��|�S�t��jS�d�S�) NFTrc���r���r���rY���rN���r����)r���rD���r����r���r~���r���r���)r���ro���r"���ZpreZpostr���r���r���r���B��s���� zDisplayName.value) r+���rF���rG���rD���rI���rJ���r~���r���rK���r���r���r���r���r����,��s��� r����c�������������������@���s,���e�Zd�ZdZdZedd���Zedd���ZdS�)� LocalPartz local-partFc�����������������C���s&���|�d�j�dkr|�d�jS�|�d�jS�d�S�)Nr���rc���)rD���rj���r���r&���r���r���r���r���[��s���� zLocalPart.valuec�����������������C���s����t�g}t�}d}|�d�t�g�D�]�}|jdkr,q|r\|jdkr\|d�jdkr\t|d�d���|d<�t|t�}|r�|jdkr�|d�jdkr�|�t|dd������n |�|��|d�}|}qt|dd���}|jS�)NFr���rY����dotr����r����)�DOTrD���r���� isinstancerh���r���)r���ri���ZlastZ last_is_tl�tokZis_tlr���r���r���r����b��s(���� � � zLocalPart.local_partN)r+���rF���rG���rD���r1���rJ���r���r����r���r���r���r���r����V��s��� r����c�����������������������s4���e�Zd�ZdZdZe��fdd��Zedd���Z���ZS�)� DomainLiteralzdomain-literalFc��������������������s���d��t��j����S�r����r����r&���r���r���r���r������s����zDomainLiteral.domainc�����������������C���s"���|�D�]}|j�dkr|j��S�qd�S�)N�ptextrf���rg���r���r���r����ip���s���� zDomainLiteral.ip) r+���rF���rG���rD���r1���rJ���r����r����rK���r���r���r���r���r����z��s���r����c�������������������@���s���e�Zd�ZdZdZdZdS�)�MIMEVersionzmime-versionN)r+���rF���rG���rD����major�minorr���r���r���r���r�������s���r����c�������������������@���s4���e�Zd�ZdZdZdZdZedd���Zedd���Z dS�) � Parameter� parameterF�us-asciic�����������������C���s���|�j�r|�d�jS�dS�r����)� sectioned�numberr&���r���r���r����section_number���s����zParameter.section_numberc�����������������C���sf���|�D�]\}|j�dkr|j��S�|j�dkr|D�]4}|j�dkr*|D�] }|j�dkr<|j������S�q<q*qdS�)Nr���rc���re���r���)rD���rl���rk���r���r���r����param_value���s���� zParameter.param_valueN) r+���rF���rG���rD���r�����extendedr`���rJ���r����r����r���r���r���r���r�������s��� r����c�������������������@���s���e�Zd�ZdZdS�)�InvalidParameter�invalid-parameterNrT���r���r���r���r���r�������s���r����c�������������������@���s���e�Zd�ZdZedd���ZdS�)� Attribute� attributec�����������������C���s$���|�D�]}|j��d�r|j��S�qd�S�)N�attrtext)rD����endswithr���rk���r���r���r���rl������s����zAttribute.stripped_valueN�r+���rF���rG���rD���rJ���rl���r���r���r���r���r�������s���r����c�������������������@���s���e�Zd�ZdZdZdS�)�Section�sectionN)r+���rF���rG���rD���r����r���r���r���r���r�������s���r����c�������������������@���s���e�Zd�ZdZedd���ZdS�)�Valuer���c�����������������C���s2���|�d�}|j�dkr|�d�}|j��d�r,|jS�|�jS�)Nr���rY���r����)rc���r����zextended-attribute)rD���r����rl���r���rk���r���r���r���rl������s���� �zValue.stripped_valueNr����r���r���r���r���r�������s���r����c�������������������@���s(���e�Zd�ZdZdZedd���Zdd��ZdS�)�MimeParameters�mime-parametersFc�������������� ���c���s���i�}|�D�]T}|j��d�sq|d�j�dkr*q|d�j���}||krHg�||<�||��|j|f��q|���D��]~\}}t|td�d�}|d�d�}|j }|j s�t|�dkr�|d�d�dkr�|d�d�j�t �d���|d�d��}g�}d}|D�]�\} } | |k�r(| j �s| j�t �d���q�n| j�t �d���|d7�}| j}| j �r�ztj�|�}W�n&�tk �rt���tjj|d d �}Y�nRX�z|�|d�}W�n"�tk �r����|�dd�}Y�nX�t�|��r�| j�t �����|�|��q�d �|�}||fV��qfd�S�)Nr����r���r����)�keyr����z.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)�encoding�surrogateescaper����r���)rD���r����r����striprh���r�����items�sortedr���r`���r����r����r���r����InvalidHeaderDefectr�����urllib�parseZunquote_to_bytes�UnicodeEncodeErrorZunquote�decode�LookupErrorr����_has_surrogates�UndecodableBytesDefectr%���)r����paramsr6����name�partsZfirst_paramr`���Zvalue_parts�ir�����paramr���r���r���r���r�������s`����� � � zMimeParameters.paramsc�����������������C���sT���g�}|�j�D�].\}}|r.|�d�|t|����q |�|��q d�|�}|rPd|�S�dS�)N�{}={}z; rN���r���)r����rh���r*���r���r%���)r���r����r����r���r���r���r���r'�����s���� zMimeParameters.__str__N)r+���rF���rG���rD���rH���rJ���r����r'���r���r���r���r���r�������s ��� Er����c�������������������@���s���e�Zd�ZdZedd���ZdS�)�ParameterizedHeaderValueFc�����������������C���s&���t�|��D�]}|jdkr|j��S�qi�S�)Nr����)�reversedrD���r����rk���r���r���r���r����-��s���� zParameterizedHeaderValue.paramsN)r+���rF���rG���rH���rJ���r����r���r���r���r���r����'��s���r����c�������������������@���s���e�Zd�ZdZdZdZdZdS�)�ContentTypezcontent-typeF�textZplainN)r+���rF���rG���rD���r1����maintype�subtyper���r���r���r���r����5��s���r����c�������������������@���s���e�Zd�ZdZdZdZdS�)�ContentDispositionzcontent-dispositionFN)r+���rF���rG���rD���r1����content_dispositionr���r���r���r���r����<��s���r����c�������������������@���s���e�Zd�ZdZdZdZdS�)�ContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r+���rF���rG���rD���r1���r_���r���r���r���r���r����B��s���r����c�������������������@���s���e�Zd�ZdZdZdS�)�HeaderLabelzheader-labelFNr����r���r���r���r���r����H��s���r����c�������������������@���s���e�Zd�ZdZdZdd��ZdS�)�MsgIDzmsg-idFc�����������������C���s���t�|��|j�S�r���)r ����linesepr:���r���r���r���r;���Q��s����z MsgID.foldN)r+���rF���rG���rD���r1���r;���r���r���r���r���r����M��s���r����c�������������������@���s���e�Zd�ZdZdS�)� MessageIDz message-idNrT���r���r���r���r���r����V��s���r����c�������������������@���s���e�Zd�ZdZdS�)�InvalidMessageIDzinvalid-message-idNrT���r���r���r���r���r����Z��s���r����c�������������������@���s���e�Zd�ZdZdS�)�Header�headerNrT���r���r���r���r���r����^��s���r����c�����������������������sr���e�Zd�ZdZdZdZ��fdd�Z��fdd�Zdd��Ze dd ���Z d��fdd� Zd d��Ze dd���Z dd��Z���ZS�)�TerminalTc��������������������s���t����|�|�}||_g�|_|S�r���)r����__new__rD���r���)�clsr���rD���r���r���r���r���r����l��s����zTerminal.__new__c��������������������s���d��|�jjt������S�r(���r)���r&���r���r���r���r,���r��s����zTerminal.__repr__c�����������������C���s���t�|�jjd�|�j���d�S�)N�/)r>���r���r+���rD���r&���r���r���r���rA���u��s����zTerminal.pprintc�����������������C���s ���t�|�j�S�r���)�listr���r&���r���r���r���r-���x��s����zTerminal.all_defectsr���c�������������� ������s2���d��||�jj|�jt�����|�js"dn d��|�j��gS�)Nz {}{}/{}({}){}r���z {})r*���r���r+���rD���r���r,���r���r@���r���r���r���rC���|��s�����zTerminal._ppc�����������������C���s���d�S�r���r���r&���r���r���r����pop_trailing_ws���s����zTerminal.pop_trailing_wsc�����������������C���s���g�S�r���r���r&���r���r���r���r5������s����zTerminal.commentsc�����������������C���s���t�|��|�jfS�r���)r ���rD���r&���r���r���r����__getnewargs__���s����zTerminal.__getnewargs__)r���)r+���rF���rG���r1���rI���rH���r����r,���rA���rJ���r-���rC���r����r5���r���rK���r���r���r���r���r����f��s��� r����c�������������������@���s ���e�Zd�Zedd���Zdd��ZdS�)�WhiteSpaceTerminalc�����������������C���s���dS�rM���r���r&���r���r���r���r������s����zWhiteSpaceTerminal.valuec�����������������C���s���dS�)NTr���r&���r���r���r���r0������s����z!WhiteSpaceTerminal.startswith_fwsN�r+���rF���rG���rJ���r���r0���r���r���r���r���r�����s��� r��c�������������������@���s ���e�Zd�Zedd���Zdd��ZdS�)� ValueTerminalc�����������������C���s���|�S�r���r���r&���r���r���r���r������s����zValueTerminal.valuec�����������������C���s���dS�)NFr���r&���r���r���r���r0������s����zValueTerminal.startswith_fwsNr��r���r���r���r���r�����s��� r��c�������������������@���s ���e�Zd�Zedd���Zdd��ZdS�)�EWWhiteSpaceTerminalc�����������������C���s���dS�r����r���r&���r���r���r���r������s����zEWWhiteSpaceTerminal.valuec�����������������C���s���dS�r����r���r&���r���r���r���r'������s����zEWWhiteSpaceTerminal.__str__N)r+���rF���rG���rJ���r���r'���r���r���r���r���r�����s��� r��c�������������������@���s���e�Zd�ZdZdS�)�_InvalidEwErrorz1Invalid encoded word found while parsing headers.N)r+���rF���rG����__doc__r���r���r���r���r�����s���r��r�����,�list-separatorr����zroute-component-markerz([{}]+)r���z[^{}]+z[\x00-\x20\x7F]c�����������������C���s>���t�|��}|r|�j�t�|���t�|��r:|�j�t�d���dS�)z@If input token contains ASCII non-printables, register a defect.z*Non-ASCII characters found in header tokenN)�_non_printable_finderr���rh���r���ZNonPrintableDefectr���r����r����)�xtextZnon_printablesr���r���r����_validate_xtext���s���� �r��c�����������������C���s����t�|�d�^}}g�}d}d}tt|��D�]L}||�dkrJ|rDd}d}nd}q&|rTd}n||�|krd�q||�||���q&|d�}d�|�d�||d��g|��|fS�)ak��Scan printables/quoted-pairs until endchars and return unquoted ptext. This function turns a run of qcontent, ccontent-without-comments, or dtext-with-quoted-printables into a single string by unquoting any quoted printables. It returns the string, the remaining value, and a flag that is True iff there were any quoted printables decoded. r����Fr���Tr���N)� _wsp_splitter�ranger����rh���r%���)r����endcharsZfragment� remainderZvchars�escape�had_qp�posr���r���r����_get_ptext_to_endchars���s$���� r��c�����������������C���s.���|�����}t|�dt|��t|����d�}||fS�)z�FWS = 1*WSP This isn't the RFC definition. We're using fws to represent tokens where folding can be done, but when we are parsing the *un*folding has already been done so we don't need to watch out for CRLF. N�fws)r����r��r����)r���Znewvaluer��r���r���r����get_fws��s����r��c����������� ��� ���C���s���t���}|��d�s t�d�|����|�dd���dd�^}}||�dd��krXt�d�|����d�|�}t|�dkr�|d�tkr�|d�tkr�|� d �dk�r�|�dd�^}}|d�|�}t|����dkr�|j �t�d ���|�|_ d�|�}�zt�d|�d��\}}}} W�n*�ttfk �r*���td�|j ���Y�nX�||_||_|j �| ��|�r�|d�tk�rrt|�\} }|�| ���qDt|d�^}}t|d�}t|��|�|��d�|�}�qD|��r�|�d�tk�r�|j �t�d ���||�fS�)zE encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" �=?z"expected encoded word but found {}r����Nz?=r����r���r����?zwhitespace inside encoded wordz!encoded word format invalid: '{}'�vtextz.missing trailing whitespace after encoded-word)r]���� startswithr����HeaderParseErrorr*���r����r%���r����r����countr���rh���r����r_����_ewr����� ValueError�KeyErrorr��r`���ra���r4����WSPr��r��r��r��) r���Zewr����r��Zremstr�restr����r`���ra���r���r6����charsr��r���r���r����get_encoded_word��sd���� �� � �� � � �r"��c�����������������C���sF��t���}|��rB|�d�tkr0t|��\}}�|�|��qd}|��d�r�zt|��\}}�W�n,�tk rf���d}Y�n��tjk rz���Y�nrX�d}t |�dkr�|d�j dkr�|j�t�d���d}|r�t |�dkr�|d �j d kr�t |d�d�|d<�|�|��qt|�d�^}}|�rt�|��r|��d�^}}t|d�}t|��|�|��d�|�}�q|S�) aO��unstructured = (*([FWS] vchar) *WSP) / obs-unstruct obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS) obs-utext = %d0 / obs-NO-WS-CTL / LF / CR obs-NO-WS-CTL is control characters except WSP/CR/LF. So, basically, we have printable runs, plus control characters or nulls in the obsolete syntax, separated by whitespace. Since RFC 2047 uses the obsolete syntax in its specification, but requires whitespace on either side of the encoded words, I can see no reason to need to separate the non-printable-non-whitespace from the printable runs if they occur, so we parse this into xtext tokens separated by WSP tokens. Because an 'unstructured' value must by definition constitute the entire value, this 'get' routine does not return a remaining value, only the parsed TokenList. r���Tr��Fr����r��z&missing whitespace before encoded wordr�������r^���r��r���)rR���r��r��rh���r��r"��r��r���r��r����rD���r���r����r��r���rfc2047_matcher�search� partitionr��r��r%���)r���rS���r6����valid_ewZhave_wsr����r��r��r���r���r����get_unstructured?��sJ���� ��� r(��c�����������������C���s*���t�|�d�\}}�}t|d�}t|��||�fS�)a��ctext = <printable ascii except \ ( )> This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Since quoted pairs are converted to their unquoted values, what is returned is a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value is ' '. z()r����)r��r��r���r���r�����_r���r���r����get_qp_ctext���s���� r+��c�����������������C���s*���t�|�d�\}}�}t|d�}t|��||�fS�)ao��qcontent = qtext / quoted-pair We allow anything except the DQUOTE character, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Any quoted pairs are converted to their unquoted values, so what is returned is a 'ptext' token. In this case it is a ValueTerminal. r ���r����)r��r��r��r)��r���r���r����get_qcontent���s���� r,��c�����������������C���sN���t�|��}|st�d�|����|���}|�t|�d��}�t|d�}t|��||�fS�)z�atext = <matches _atext_matcher> We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to the token's defects list if we find non-atext characters. zexpected atext but found '{}'N�atext)�_non_atom_end_matcherr���r��r*���r|���r����r��r��)r����mr-��r���r���r���� get_atext���s����� r0��c�����������������C���sr��|�d�dkrt��d�|����t��}|�dd��}�|�rT|�d�dkrTt|��\}}�|�|��|��rB|�d�dk�rB|�d�tkr�t|��\}}�n�|�dd��dk�r*d}z&t|��\}}�|j �t�� d ���d }W�n"�t�jk r����t|��\}}�Y�nX�|�r6t|�dk�r6|d�jdk�r6|d �jdk�r6t |d�d�|d<�nt|��\}}�|�|��qT|��sb|j �t�� d���||�fS�||�dd��fS�)z�bare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE A quoted-string without the leading or trailing white space. Its value is the text between the quote marks, with whitespace preserved and quoted pairs decoded. r���r ���zexpected '"' but found '{}'r����Nr����r��Fz!encoded word inside quoted stringTr����r��r#��r^���z"end of header inside quoted string)r���r��r*���rm���r,��rh���r��r��r"��r���r����r����rD���r��)r���Zbare_quoted_stringr6���r'��r���r���r����get_bare_quoted_string���sL����� ���� �r1��c�����������������C���s����|�r |�d�dkr t��d�|����t��}|�dd��}�|�r�|�d�dkr�|�d�tkr\t|��\}}�n&|�d�dkrvt|��\}}�nt|��\}}�|�|��q2|�s�|j �t�� d���||�fS�||�dd��fS�)z�comment = "(" *([FWS] ccontent) [FWS] ")" ccontent = ctext / quoted-pair / comment We handle nested comments here, and quoted-pair in our qp-ctext routine. r���r���zexpected '(' but found '{}'r����Nrp���zend of header inside comment)r���r��r*���rn���r��r���get_commentr+��rh���r���r����)r���rO���r6���r���r���r���r2�����s&����� �r2��c�����������������C���sP���t���}|�rH|�d�tkrH|�d�tkr0t|��\}}�nt|��\}}�|�|��q||�fS�)z,CFWS = (1*([FWS] comment) [FWS]) / FWS r���)rX����CFWS_LEADERr��r��r2��rh���)r���rY���r6���r���r���r����get_cfws���s����r4��c�����������������C���sp���t���}|�r,|�d�tkr,t|��\}}�|�|��t|��\}}�|�|��|�rh|�d�tkrht|��\}}�|�|��||�fS�)z�quoted-string = [CFWS] <bare-quoted-string> [CFWS] 'bare-quoted-string' is an intermediate class defined by this parser and not by the RFC grammar. It is the quoted string without any attached CFWS. r���)rb���r3��r4��rh���r1��)r���Z quoted_stringr6���r���r���r����get_quoted_string��s���� r5��c�����������������C���s����t���}|�r,|�d�tkr,t|��\}}�|�|��|�rL|�d�tkrLt�d�|����|��d�r�zt |��\}}�W�q��tjk r����t |��\}}�Y�q�X�nt |��\}}�|�|��|�r�|�d�tkr�t|��\}}�|�|��||�fS�)zPatom = [CFWS] 1*atext [CFWS] An atom could be an rfc2047 encoded word. r���zexpected atom but found '{}'r��)rZ���r3��r4��rh���� ATOM_ENDSr���r��r*���r��r"��r0��)r���r[���r6���r���r���r����get_atom��s&���� � r7��c�����������������C���s����t���}|�r|�d�tkr&t�d�|����|�rt|�d�tkrtt|��\}}�|�|��|�r&|�d�dkr&|�t��|�dd��}�q&|d�tkr�t�d�d|�����||�fS�)z( dot-text = 1*atext *("." 1*atext) r���z8expected atom at a start of dot-atom-text but found '{}'r���r����Nr����z4expected atom at end of dot-atom-text but found '{}')r����r6��r���r��r*���r0��rh���r����)r���Z dot_atom_textr6���r���r���r����get_dot_atom_text0��s ����� �r8��c�����������������C���s����t���}|�d�tkr(t|��\}}�|�|��|��d�rhzt|��\}}�W�qt�tjk rd���t|��\}}�Y�qtX�nt|��\}}�|�|��|�r�|�d�tkr�t|��\}}�|�|��||�fS�)z� dot-atom = [CFWS] dot-atom-text [CFWS] Any place we can have a dot atom, we could instead have an rfc2047 encoded word. r���r��) r����r3��r4��rh���r��r"��r���r��r8��)r���Zdot_atomr6���r���r���r����get_dot_atomC��s���� r9��c�����������������C���s����|�d�t�krt|��\}}�nd}|�s,t�d��|�d�dkrFt|��\}}�n*|�d�tkrdt�d�|����nt|��\}}�|dk r�|g|dd�<�||�fS�)a���word = atom / quoted-string Either atom or quoted-string may start with CFWS. We have to peel off this CFWS first to determine which type of word to parse. Afterward we splice the leading CFWS, if any, into the parsed sub-token. If neither an atom or a quoted-string is found before the next special, a HeaderParseError is raised. The token returned is either an Atom or a QuotedString, as appropriate. This means the 'word' level of the formal grammar is not represented in the parse tree; this is because having that extra layer when manipulating the parse tree is more confusing than it is helpful. r���Nz5Expected 'atom' or 'quoted-string' but found nothing.r ���z1Expected 'atom' or 'quoted-string' but found '{}')r3��r4��r���r��r5���SPECIALSr*���r7��)r����leaderr6���r���r���r����get_word\��s"������r<��c�����������������C���s����t���}zt|��\}}�|�|��W�n(�tjk rH���|j�t�d���Y�nX�|�r�|�d�tkr�|�d�dkr�|�t��|j�t� d���|�dd��}�qJzt|��\}}�W�nD�tjk r����|�d�t kr�t|��\}}�|j�t� d���n��Y�nX�|�|��qJ||�fS�)a��� phrase = 1*word / obs-phrase obs-phrase = word *(word / "." / CFWS) This means a phrase can be a sequence of words, periods, and CFWS in any order as long as it starts with at least one word. If anything other than words is detected, an ObsoleteHeaderDefect is added to the token's defect list. We also accept a phrase that starts with CFWS followed by a dot; this is registered as an InvalidHeaderDefect, since it is not supported by even the obsolete grammar. zphrase does not start with wordr���r���zperiod in 'phrase'r����Nzcomment found without atom)rU���r<��rh���r���r��r���r�����PHRASE_ENDSr�����ObsoleteHeaderDefectr3��r4��)r���rV���r6���r���r���r���� get_phrase~��s4���� � � �r?��c�����������������C���sv��t���}d}|�d�tkr"t|��\}}�|�s6t�d�|����zt|��\}}�W�n^�tjk r����zt|��\}}�W�n6�tjk r����|�d�dkr�|�d�tkr���t ��}Y�nX�Y�nX�|dk r�|g|dd�<�|� |��|��r4|�d�dks�|�d�tk�r4tt|�|���\}}�|j dk�r|j� t�d���n|j� t�d���||d<�z|j�d��W�n(�tk �rl���|j� t�d ���Y�nX�||�fS�) z= local-part = dot-atom / quoted-string / obs-local-part Nr���z"expected local-part but found '{}'r����invalid-obs-local-partz<local-part is not dot-atom, quoted-string, or obs-local-partz,local-part is not a dot-atom (contains CFWS)�asciiz)local-part contains non-ASCII characters))r����r3��r4��r���r��r*���r9��r<��r=��r���rh����get_obs_local_partr ���rD���r���r����r>��r����encoder����ZNonASCIILocalPartDefect)r���r����r;��r6����obs_local_partr���r���r����get_local_part���sJ����� � � �rE��c�����������������C���s���t���}d}|��r(|�d�dks*|�d�tk�r(|�d�dkrj|rL|j�t�d���|�t��d}|�dd��}�q nD|�d�dkr�|�t|�d�d ���|�dd��}�|j�t�d ���d}q |r�|d�jdkr�|j�t�d ���zt |��\}}�d}W�n4�tj k �r���|�d�tk�r ��t|��\}}�Y�nX�|�|��q |d�jdk�sX|d�jdk�rj|d�jdk�rj|j�t�d���|d�jdk�s�|d�jdk�r�|d�jdk�r�|j�t�d���|j�r�d|_||�fS�)z' obs-local-part = word *("." word) Fr���r���r���zinvalid repeated '.'Tr����N�misplaced-specialz/'\' character outside of quoted-string/ccontentr����r����zmissing '.' between wordsrY���z!Invalid leading '.' in local partr#��z"Invalid trailing '.' in local partr@��) r����r=��r���rh���r���r����r����r��rD���r<��r��r3��r4��)r���rD��Zlast_non_ws_was_dotr6���r���r���r���rB�����sj���� � � � ��� ��� �rB��c�����������������C���s@���t�|�d�\}}�}t|d�}|r0|j�t�d���t|��||�fS�)a�� dtext = <printable ascii except \ [ ]> / obs-dtext obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is added to the returned token's defect list. z[]r����z(quoted printable found in domain-literal)r��r��r���rh���r���r>��r��)r���r����r��r���r���r���� get_dtext���s���� �rG��c�����������������C���s,���|�rdS�|��t�d���|��tdd���dS�)NFz"end of input inside domain-literal�]�domain-literal-endT)rh���r���r����r��)r����domain_literalr���r���r����_check_for_early_dl_end��s�����rK��c�����������������C���sj��t���}|�d�tkr(t|��\}}�|�|��|�s6t�d��|�d�dkrRt�d�|����|�dd��}�t|�|�rp||�fS�|�tdd���|�d�t kr�t |��\}}�|�|��t|��\}}�|�|��t|�|�r�||�fS�|�d�t kr�t |��\}}�|�|��t|�|�r�||�fS�|�d�dk�rt�d �|����|�tdd ���|�dd��}�|��rb|�d�tk�rbt|��\}}�|�|��||�fS�)zB domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS] r���zexpected domain-literal�[z6expected '[' at start of domain-literal but found '{}'r����Nzdomain-literal-startrH��z4expected ']' at end of domain-literal but found '{}'rI��)r����r3��r4��rh���r���r��r*���rK��r��r��r��rG��)r���rJ��r6���r���r���r����get_domain_literal��sH���� � � rM��c�����������������C���sr��t���}d}|�d�tkr"t|��\}}�|�s6t�d�|����|�d�dkrvt|��\}}�|dk rd|g|dd�<�|�|��||�fS�zt|��\}}�W�n"�tjk r����t |��\}}�Y�nX�|�r�|�d�dkr�t�d��|dk r�|g|dd�<�|�|��|��rj|�d�dk�rj|j �t�d���|d�jd k�r*|d�|dd�<�|��rj|�d�dk�rj|�t ��t |�d d���\}}�|�|���q*||�fS�)z] domain = dot-atom / domain-literal / obs-domain obs-domain = atom *("." atom)) Nr���zexpected domain but found '{}'rL��r����zInvalid Domainr���z(domain is not a dot-atom (contains CFWS)r����r����)r����r3��r4��r���r��r*���rM��rh���r9��r7��r���r>��rD���r����)r���r����r;��r6���r���r���r���� get_domain=��sD����� � rN��c�����������������C���s|���t���}t|��\}}�|�|��|�r,|�d�dkrF|j�t�d���||�fS�|�tdd���t|�dd���\}}�|�|��||�fS�)z( addr-spec = local-part "@" domain r���r����z#addr-spec local part with no domain�address-at-symbolr����N)r����rE��rh���r���r���r����r��rN��)r���r����r6���r���r���r���� get_addr_specc��s���� � rP��c�����������������C���s���t���}|�rj|�d�dks"|�d�tkrj|�d�tkrFt|��\}}�|�|��q|�d�dkr|�t��|�dd��}�q|�rz|�d�dkr�t�d�|����|�t��t |�dd���\}}�|�|��|��r>|�d�dk�r>|�t��|�dd��}�|�s�q>|�d�tk�rt|��\}}�|�|��|�d�dkr�|�t��t |�dd���\}}�|�|��q�|��sNt�d��|�d�dk�rlt�d �|����|�t dd ���||�dd��fS�)z� obs-route = obs-domain-list ":" obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain]) Returns an obs-route token with the appropriate sub-tokens (that is, there is no obs-domain-list in the parse tree). r���r��r����Nr����z(expected obs-route domain but found '{}'z%end of header while parsing obs-route�:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker)r����r3��r4��rh���� ListSeparatorr���r��r*����RouteComponentMarkerrN��r��)r���Z obs_router6���r���r���r���� get_obs_routes��sF���� � �rT��c�����������������C���s���t���}|�d�tkr(t|��\}}�|�|��|�r8|�d�dkrHt�d�|����|�tdd���|�dd��}�|�d�dkr�|�tdd���|j�t� d ���|�dd��}�||�fS�zt |��\}}�W�nz�tjk �r0���z"t|��\}}�|j�t�d ���W�n(�tjk �r���t�d�|����Y�nX�|�|��t |��\}}�Y�nX�|�|��|��r^|�d�dk�r^|�dd��}�n|j�t� d���|�tdd���|��r�|�d�tk�r�t|��\}}�|�|��||�fS�) z� angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS] r����<z"expected angle-addr but found '{}'zangle-addr-startr����N�>zangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr) r����r3��r4��rh���r���r��r*���r��r���r����rP��rT��r>��)r���Z angle_addrr6���r���r���r����get_angle_addr���sT���� � � � � � rW��c�����������������C���s<���t���}t|��\}}�|�|dd����|jdd��|_||�fS�)z� display-name = phrase Because this is simply a name-rule, we don't return a display-name token containing a phrase, but rather a display-name token with the content of the phrase. N)r����r?��r4���r���)r���r~���r6���r���r���r����get_display_name���s ����rX��c�����������������C���s����t���}d}|�d�tkr6t|��\}}�|�s6t�d�|���|�d�dkr�|�d�tkr^t�d�|����t|��\}}�|�s~t�d�|���|dk r�|g|d�dd�<�d}|�|��t |��\}}�|dk r�|g|dd�<�|�|��||�fS�)z, name-addr = [display-name] angle-addr Nr���z!expected name-addr but found '{}'rU��) r����r3��r4��r���r��r*���r=��rX��rh���rW��)r���Z name_addrr;��r6���r���r���r���� get_name_addr���s6������� rY��c�����������������C���s����t���}zt|��\}}�W�nN�tjk rd���zt|��\}}�W�n&�tjk r^���t�d�|����Y�nX�Y�nX�tdd��|jD���r�d|_|� |��||�fS�)z& mailbox = name-addr / addr-spec zexpected mailbox but found '{}'c�����������������s���s���|�]}t�|tj�V��qd�S�r���)r����r���r����r ���r���r���r���r#�����s����zget_mailbox.<locals>.<genexpr>r����) r����rY��r���r��rP��r*����anyr-���rD���rh���)r���r����r6���r���r���r����get_mailbox���s ������ r[��c�����������������C���sd���t���}|�r\|�d�|kr\|�d�tkrD|�t|�d�d���|�dd��}�qt|��\}}�|�|��q||�fS�)z� Read everything up to one of the chars in endchars. This is outside the formal grammar. The InvalidMailbox TokenList that is returned acts like a Mailbox, but the data attributes are None. r���rF��r����N)r����r=��rh���r��r?��)r���r��Zinvalid_mailboxr6���r���r���r����get_invalid_mailbox��s�����r\��c�����������������C���s���t���}|��r�|�d�dk�r�zt|��\}}�|�|��W��n�tjk �r<���d}|�d�tkr�t|��\}}�|�rv|�d�dkr�|�|��|j�t�d���n@t |�d�\}}�|dk r�|g|dd�<�|�|��|j�t� d���nb|�d�dkr�|j�t�d���nBt |�d�\}}�|dk �r|g|dd�<�|�|��|j�t� d���Y�nX�|��r�|�d�dk�r�|d�}d |_t |�d�\}}�|�|��|j�t� d���|�r|�d�dkr|�t ��|�d d��}�q||�fS�)aJ�� mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS]) For this routine we go outside the formal grammar in order to improve error handling. We recognize the end of the mailbox list only at the end of the value or at a ';' (the group terminator). This is so that we can turn invalid mailboxes into InvalidMailbox tokens and continue parsing any remaining valid mailboxes. We also allow all mailbox entries to be null, and this condition is handled appropriately at a higher level. r����;Nz,;zempty element in mailbox-listzinvalid mailbox in mailbox-listr��r����r����r����)r����r[��rh���r���r��r3��r4��r���r>��r\��r����rD���r4���rR��)r���Zmailbox_listr6���r;��r����r���r���r����get_mailbox_list��sX���� � � � � � r^��c�����������������C���s��t���}|�s$|j�t�d���||�fS�d}|�r�|�d�tkr�t|��\}}�|�sl|j�t�d���|�|��||�fS�|�d�dkr�|�|��||�fS�t|��\}}�t|j �dkr�|dk r�|�|��|� |��|j�t�d���||�fS�|dk r�|g|dd�<�|�|��||�fS�)zg group-list = mailbox-list / CFWS / obs-group-list obs-group-list = 1*([CFWS] ",") [CFWS] zend of header before group-listNr���zend of header in group-listr]��zgroup-list with empty entries)r����r���rh���r���r����r3��r4��r^��r����rz���r4���r>��)r���Z group_listr;��r6���r���r���r����get_group_listW��s>���� � � � r_��c�����������������C���s ��t���}t|��\}}�|�r"|�d�dkr2t�d�|����|�|��|�tdd���|�dd��}�|�r�|�d�dkr�|�tdd���||�dd��fS�t|��\}}�|�|��|�s�|j�t� d ���n|�d�dkr�t�d �|����|�tdd���|�dd��}�|��r|�d�t k�rt|��\}}�|�|��||�fS�)z7 group = display-name ":" [group-list] ";" [CFWS] r���rQ��z8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorr����Nr]��zgroup-terminatorzend of header in groupz)expected ';' at end of group but found {})r����rX��r���r��r*���rh���r��r_��r���r����r3��r4��)r���r|���r6���r���r���r���� get_group|��s8����� �� r`��c�����������������C���sx���t���}zt|��\}}�W�nN�tjk rd���zt|��\}}�W�n&�tjk r^���t�d�|����Y�nX�Y�nX�|�|��||�fS�)a��� address = mailbox / group Note that counter-intuitively, an address can be either a single address or a list of addresses (a group). This is why the returned Address object has a 'mailboxes' attribute which treats a single address as a list of length one. When you need to differentiate between to two cases, extract the single element, which is either a mailbox or a group token. zexpected address but found '{}')r{���r`��r���r��r[��r*���rh���)r���rr���r6���r���r���r����get_address���s����� ra��c�������������� ���C���s���t���}|��r�zt|��\}}�|�|��W��n �tjk �rH�}�z�d}|�d�tkr�t|��\}}�|�rj|�d�dkr�|�|��|j�t�d���nFt |�d�\}}�|dk r�|g|dd�<�|�t |g���|j�t�d���nh|�d�dkr�|j�t�d���nHt |�d�\}}�|dk �r|g|dd�<�|�t |g���|j�t�d���W�5�d}~X�Y�nX�|��r�|�d�dk�r�|d�d�}d|_t |�d�\}}�|� |��|j�t�d���|�r|�tdd ���|�d d��}�q||�fS�)a��� address_list = (address *("," address)) / obs-addr-list obs-addr-list = *([CFWS] ",") address *("," [address / CFWS]) We depart from the formal grammar here by continuing to parse until the end of the input, assuming the input to be entirely composed of an address-list. This is always true in email parsing, and allows us to skip invalid addresses to parse additional valid ones. Nr���r��z"address-list entry with no contentzinvalid address in address-listzempty element in address-listr����r����r��r����)rq���ra��rh���r���r��r3��r4��r���r>��r\��r{���r����rD���r4���r��)r���Zaddress_listr6����errr;��r����r���r���r����get_address_list���sX���� � � � � �rc��c�����������������C���s����t���}|�st�d�|����|�d�dkr6t�d�|����|�tdd���|�dd��}�t|��\}}�|�|��|�rx|�d�dkr�t�d �|����|�tdd ���||�dd��fS�)z& no-fold-literal = "[" *dtext "]" z'expected no-fold-literal but found '{}'r���rL��z;expected '[' at the start of no-fold-literal but found '{}'zno-fold-literal-startr����NrH��z9expected ']' at the end of no-fold-literal but found '{}'zno-fold-literal-end)r����r���r��r*���rh���r��rG��)r���Zno_fold_literalr6���r���r���r����get_no_fold_literal���s.������� ��rd��c�����������������C���s���t���}|�r,|�d�tkr,t|��\}}�|�|��|�r<|�d�dkrLt�d�|����|�tdd���|�dd��}�zt|��\}}�W�n`�tjk r����z"t |��\}}�|j �t�d���W�n&�tjk r����t�d�|����Y�nX�Y�nX�|�|��|�r�|�d�d k�r@|j �t�d ���|��r8|�d�dk�r8|�tdd���|�dd��}�||�fS�|�td d ���|�dd��}�zt|��\}}�W�n��tjk �r���zt |��\}}�W�nr�tjk �r�}�zPz"t|��\}}�|j �t�d���W�n(�tjk �r����t�d�|����Y�nX�W�5�d}~X�Y�nX�Y�nX�|�|��|��r6|�d�dk�r6|�dd��}�n|j �t�d���|�tdd���|��r�|�d�tk�r�t|��\}}�|�|��||�fS�)z�msg-id = [CFWS] "<" id-left '@' id-right ">" [CFWS] id-left = dot-atom-text / obs-id-left id-right = dot-atom-text / no-fold-literal / obs-id-right no-fold-literal = "[" *dtext "]" r���rU��zexpected msg-id but found '{}'zmsg-id-startr����Nzobsolete id-left in msg-idz4expected dot-atom-text or obs-id-left but found '{}'r����zmsg-id with no id-rightrV��z msg-id-endrO��zobsolete id-right in msg-idzFexpected dot-atom-text, no-fold-literal or obs-id-right but found '{}'zmissing trailing '>' on msg-id)r����r3��r4��rh���r���r��r*���r��r8��rB��r���r>��r����rd��rN��)r���Zmsg_idr6����er���r���r���� get_msg_id��s~���� � � �� � � ��" � rf��c�������������� ���C���s����t���}zt|��\}}�|�|��W�nL�tjk rl�}�z,t|��}t|�}|j�t�d� |����W�5�d}~X�Y�nX�|�r�|j�t�d� |�����|S�)z2message-id = "Message-ID:" msg-id CRLF zInvalid msg-id: {!r}NzUnexpected {!r}) r����rf��rh���r���r��r(��r����r���r����r*���)r���Z message_idr6���Zexr���r���r����parse_message_idI��s����� �rg��c�����������������C���s���t���}|�s |j�t�d���|S�|�d�tkrXt|��\}}�|�|��|�sX|j�t�d���d}|�r�|�d�dkr�|�d�tkr�||�d�7�}|�dd��}�q\|���s�|j�t�d� |����|�t |d ���nt|�|_|�t |d ���|��r|�d�tk�rt|��\}}�|�|��|��r|�d�dk�rT|jdk �r:|j�t�d���|��rP|�t |�d ���|S�|�t dd���|�dd��}�|��r�|�d�tk�r�t|��\}}�|�|��|��s�|jdk �r�|j�t�d���|S�d}|��r�|�d�tk�r�||�d�7�}|�dd��}��q�|����s*|j�t�d � |����|�t |d ���nt|�|_ |�t |d ���|��rn|�d�tk�rnt|��\}}�|�|��|��r�|j�t�d���|�t |�d ���|S�)zE mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS] z%Missing MIME version number (eg: 1.0)r���z0Expected MIME version number but found only CFWSr���r���r����Nz1Expected MIME major version number but found {!r}r ���digitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)r����r���rh���r����HeaderMissingRequiredValuer3��r4���isdigitr����r*���r���intr����r����)r���Zmime_versionr6���rh��r���r���r����parse_mime_versione��s����� � � � � � � �rl��c�����������������C���sd���t���}|�r\|�d�dkr\|�d�tkrD|�t|�d�d���|�dd��}�qt|��\}}�|�|��q||�fS�)z� Read everything up to the next ';'. This is outside the formal grammar. The InvalidParameter TokenList that is returned acts like a Parameter, but the data attributes are None. r���r]��rF��r����N)r����r=��rh���r��r?��)r���Zinvalid_parameterr6���r���r���r����get_invalid_parameter���s�����rm��c�����������������C���sN���t�|��}|st�d�|����|���}|�t|�d��}�t|d�}t|��||�fS�)a8��ttext = <matches _ttext_matcher> We allow any non-TOKEN_ENDS in ttext, but add defects to the token's defects list if we find non-ttext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. zexpected ttext but found '{}'N�ttext)�_non_token_end_matcherr���r��r*���r|���r����r��r��)r���r/��rn��r���r���r���� get_ttext���s���� � rp��c�����������������C���s����t���}|�r,|�d�tkr,t|��\}}�|�|��|�rL|�d�tkrLt�d�|����t|��\}}�|�|��|�r�|�d�tkr�t|��\}}�|�|��||�fS�)z�token = [CFWS] 1*ttext [CFWS] The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or tspecials. We also exclude tabs even though the RFC doesn't. The RFC implies the CFWS but is not explicit about it in the BNF. r����expected token but found '{}') r\���r3��r4��rh���� TOKEN_ENDSr���r��r*���rp��)r���Zmtokenr6���r���r���r���� get_token���s���� � rs��c�����������������C���sN���t�|��}|st�d�|����|���}|�t|�d��}�t|d�}t|��||�fS�)aQ��attrtext = 1*(any non-ATTRIBUTE_ENDS character) We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the token's defects list if we find non-attrtext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. z expected attrtext but found {!r}Nr����)�_non_attribute_end_matcherr���r��r*���r|���r����r��r���r���r/��r����r���r���r����get_attrtext���s���� � rv��c�����������������C���s����t���}|�r,|�d�tkr,t|��\}}�|�|��|�rL|�d�tkrLt�d�|����t|��\}}�|�|��|�r�|�d�tkr�t|��\}}�|�|��||�fS�)aH�� [CFWS] 1*attrtext [CFWS] This version of the BNF makes the CFWS explicit, and as usual we use a value terminal for the actual run of characters. The RFC equivalent of attrtext is the token characters, with the subtraction of '*', "'", and '%'. We include tab in the excluded set just as we do for token. r���rq��) r����r3��r4��rh����ATTRIBUTE_ENDSr���r��r*���rv���r���r����r6���r���r���r���� get_attribute���s���� � ry��c�����������������C���sN���t�|��}|st�d�|����|���}|�t|�d��}�t|d�}t|��||�fS�)z�attrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%') This is a special parsing routine so that we get a value that includes % escapes as a single string (which we decode as a single string later). z)expected extended attrtext but found {!r}N�extended-attrtext)�#_non_extended_attribute_end_matcherr���r��r*���r|���r����r��r��ru��r���r���r����get_extended_attrtext ��s����� r|��c�����������������C���s����t���}|�r,|�d�tkr,t|��\}}�|�|��|�rL|�d�tkrLt�d�|����t|��\}}�|�|��|�r�|�d�tkr�t|��\}}�|�|��||�fS�)z� [CFWS] 1*extended_attrtext [CFWS] This is like the non-extended version except we allow % characters, so that we can pick up an encoded value as a single string. r���rq��) r����r3��r4��rh����EXTENDED_ATTRIBUTE_ENDSr���r��r*���r|��rx��r���r���r����get_extended_attribute! ��s���� � r~��c�����������������C���s����t���}|�r|�d�dkr&t�d�|����|�tdd���|�dd��}�|�rR|�d����sbt�d�|����d}|�r�|�d����r�||�d�7�}|�dd��}�qf|d�d kr�|d kr�|j�t�d ���t |�|_ |�t|d���||�fS�)a6�� '*' digits The formal BNF is more complicated because leading 0s are not allowed. We check for that and add a defect. We also assume no CFWS is allowed between the '*' and the digits, though the RFC is not crystal clear on that. The caller should already have dealt with leading CFWS. r����*zExpected section but found {}zsection-markerr����Nz$Expected section number but found {}r����0z'section number has an invalid leading 0rh��)r����r���r��r*���rh���r��rj��r���ZInvalidHeaderErrorrk��r����)r���r����rh��r���r���r����get_section7 ��s,���� �� � r���c�����������������C���s����t���}|�st�d��d}|�d�tkr0t|��\}}�|�sDt�d�|���|�d�dkr^t|��\}}�nt|��\}}�|dk r�|g|dd�<�|�|��||�fS�)z quoted-string / attribute z&Expected value but found end of stringNr���z Expected value but found only {}r ���) r����r���r��r3��r4��r*���r5��r~��rh���)r����vr;��r6���r���r���r���� get_valueU ��s"���� � r���c�����������������C���s���t���}t|��\}}�|�|��|�r,|�d�dkrL|j�t�d�|����||�fS�|�d�dkr�z t|��\}}�d|_|�|��W�n�tj k r����Y�nX�|�s�t� d��|�d�dkr�|�t dd���|�dd ��}�d|_|�d�d kr�t� d��|�t d d���|�dd ��}�d }|��r,|�d�tk�r,t |��\}}�|�|��d }|}|j�rF|��rF|�d�d k�rFt|��\}}|j}d}|jdk�r�|�r�|d�dk�r�d}n$t|�\}} | �r�| d�dk�r�d}n(zt|�\}} W�n���Y�nX�| �s�d}|�r0|j�t�d���|�|��|D�](} | jdk�r�g�| d d �<�| }��q*�q�|}�nd }|j�t�d���|��r`|�d�dk�r`d }nt|��\}}�|j�r�|jdk�r�|��r�|�d�dk�r�|�|��|d k �r�|}�||�fS�|j�t�d���|��s�|j�t�d���|�|��|d k�r�||�fS�n�|d k �r@|D�]} | jdk�r ��q$�q | jdk�|�| ��| j|_|�d�dk�r^t� d�|����|�t dd���|�dd ��}�|��r�|�d�dk�r�t|��\}}�|�|��|j|_|��r�|�d�dk�r�t� d�|����|�t dd���|�dd ��}�|d k �rdt��}|��r^|�d�tk�rt|��\}}�n2|�d�d k�rDt d d�}|�dd ��}�nt|��\}}�|�|���q�|}nt|��\}}�|�|��|d k �r�|}�||�fS�)aY�� attribute [section] ["*"] [CFWS] "=" value The CFWS is implied by the RFC but not made explicit in the BNF. This simplified form of the BNF from the RFC is made to conform with the RFC BNF through some extra checks. We do it this way because it makes both error recovery and working with the resulting parse tree easier. r���r]��z)Parameter contains name ({}) but no valuer��TzIncomplete parameterzextended-parameter-markerr����N�=zParameter not followed by '='�parameter-separatorr ���F�'z5Quoted string value for extended parameter is invalidre���zZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimitersrz��r����z=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {}ZDQUOTE)r����ry��rh���r���r���r����r*���r���r����r��r��r����r3��r4��r5��rl���r����rv��r|��rD���r���r���r`���ra���r����r��r��r,��)r���r����r6���r;��r��ZappendtoZqstringZinner_valueZ semi_validr ���tr���r���r���r���� get_parameterk ��s����� � � � � � � � r���c�������������� ���C���sj��t���}|��rfzt|��\}}�|�|��W�n��tjk r��}�z�d}|�d�tkrVt|��\}}�|�sp|�|��|�W�Y��xS�|�d�dkr�|dk r�|�|��|j�t�d���n@t |��\}}�|r�|g|dd�<�|�|��|j�t�d� |����W�5�d}~X�Y�nX�|��rD|�d�dk�rD|d�}d|_t |��\}}�|�|��|j�t�d� |����|�r|�t dd ���|�d d��}�q|S�)a!�� parameter *( ";" parameter ) That BNF is meant to indicate this routine should only be called after finding and handling the leading ';'. There is no corresponding rule in the formal RFC grammar, but it is more convenient for us for the set of parameters to be treated as its own TokenList. This is 'parse' routine because it consumes the remaining value, but it would never be called to parse a full header. Instead it is called to parse everything after the non-parameter value of a specific MIME header. Nr���r]��zparameter entry with no contentzinvalid parameter {!r}r����r����z)parameter with invalid trailing text {!r}r���r����)r����r���rh���r���r��r3��r4��r���r����rm��r*���rD���r4���r��)r���Zmime_parametersr6���rb��r;��r����r���r���r����parse_mime_parameters� ��sJ���� � � �r���c�����������������C���s����|rV|d�dkrV|d�t�kr>|��t|d�d���|dd��}q�t|�\}}|��|��q�|s^dS�|��tdd���|��t|dd�����dS�)zBDo our best to find the parameters in an invalid MIME header r���r]��rF��r����Nr���)r=��rh���r��r?��r���)Z tokenlistr���r6���r���r���r����_find_mime_parameters- ��s����r���c�������������� ���C���s���t���}d}|�s$|j�t�d���|S�zt|��\}}�W�n<�tjk rp���|j�t�d�|�����t ||���|�Y�S�X�|�|��|�r�|�d�dkr�|j�t�d���|�r�t ||���|S�|j ������|_ |�tdd���|�dd ��}�zt|��\}}�W�n>�tjk �r*���|j�t�d �|�����t ||���|�Y�S�X�|�|��|j ������|_|��sP|S�|�d�dk�r�|j�t�d�|�����|` |`t ||���|S�|�tdd ���|�t|�dd �����|S�)z� maintype "/" subtype *( ";" parameter ) The maintype and substype are tokens. Theoretically they could be checked against the official IANA list + x-token, but we don't do that. Fz"Missing content type specificationz(Expected content maintype but found {!r}r���r����zInvalid content typezcontent-type-separatorr����Nz'Expected content subtype but found {!r}r]��z<Only parameters are valid after content type, but found {!r}r���)r����r���rh���r���ri��rs��r��r����r*���r���r���r�����lowerr����r��r����r���)r���ZctypeZrecoverr6���r���r���r����parse_content_type_header= ��sd���� � � � � �� r���c�������������� ���C���s����t���}|�s |j�t�d���|S�zt|��\}}�W�n<�tjk rl���|j�t�d�|�����t ||���|�Y�S�X�|�|��|j ������|_ |�s�|S�|�d�dkr�|j�t�d�|�����t ||���|S�|�tdd���|�t|�dd�����|S�) z* disposition-type *( ";" parameter ) zMissing content dispositionz+Expected content disposition but found {!r}r���r]��zCOnly parameters are valid after content disposition, but found {!r}r���r����N)r����r���rh���r���ri��rs��r��r����r*���r���r���r����r���r����r��r���)r���Zdisp_headerr6���r���r���r���� parse_content_disposition_headerv ��s:���� � � �� r���c�������������� ���C���s����t���}|�s |j�t�d���|S�zt|��\}}�W�n.�tjk r^���|j�t�d�|�����Y�nX�|�|��|j � �����|_|�s�|S�|�r�|j�t�d���|�d�t kr�|�t|�d�d���|�dd��}�q�t|��\}}�|�|��q�|S�)z mechanism z!Missing content transfer encodingz1Expected content transfer encoding but found {!r}z*Extra text after content transfer encodingr���rF��r����N)r����r���rh���r���ri��rs��r��r����r*���r���r����r���r_���r=��r��r?��)r���Z cte_headerr6���r���r���r����&parse_content_transfer_encoding_header� ��s4���� � � �r���c�����������������C���sD���d}|�r@|�d�r@|�d�d�t�kr@|�d�d�}|�d�d�d��|�d<�|S�)Nr���r����)r��)�linesZwspr���r���r����_steal_trailing_WSP_if_exists� ��s ����r���c����������������C���s���|j�p tj}|jrdnd}dg}d}d}d}tdd�}t|��} | �r�| �d�} | |kr`|d8�}q>t| �}| jd kr�t |�t @�r�d }z|�|��|}W�n6�tk r����t dd��| jD���r�d }nd}d }Y�nX�| jdkr�t| |||��q>|�r�|�s�| j�spd}d}| j�rp| j|d�dt|j����} |j| k�rpt| �|t|d���k�r^t|�}|�|��|d��| 7��<�q>t| d��s�t| �| �} nt||||| j|�}d}q>t|�|t|d���k�r�|d��|7��<�q>| j�rt|�d�|k�rt|�}|�s| ����r|�||���d}q>t| d��sNt| �}| j�sD|d7�}|�|��|| �} q>| j�rn|�sn| �d| ��d }q>t|�}|�s�| ����r�|�||���q>|d��|7��<�q>|j�|�|j�S�)zLReturn string of contents of parse_tree folded according to RFC rules. �utf-8r����r���Nr���F�wrap_as_ew_blockedr����r����Tc�����������������s���s���|�]}t�|tj�V��qd�S�r���)r����r���r����r ���r���r���r���r#���� ��s����z%_refold_parse_tree.<locals>.<genexpr>�unknown-8bitr����r7���r����rC��)Zmax_line_length�sys�maxsize�utf8r����r����r����r ���rD���r����r:��rC��r����rZ��r-����_fold_mime_parametersr1���rH���r;���r����r����r���rh���rE����_fold_as_ewrI���r0����insertr%���)Z parse_treer8����maxlenr����r����last_ewr���Z want_encodingZend_ew_not_allowedr����r2����tstrr`���Zencoded_part�newlineZnewpartsr���r���r���r9���� ��s����� � ��� r9���c�����������������C���s���|dk r<|r<t�t|d�|d��|����}�|d�d|��|d<�|�d�tkr�|�d�}|�dd��}�t|d��|krz|�t|���|d��|7��<�d}|�d�tkr�|�d�}|�dd��}�|dkr�t|d��n|}|dkr�dn|} t| �d�} | d�|kr�t�d ��|��r�|t|d���}|| �}|dk�r,|�d ��q�|�d|��} tj | | d�}t|�|�}|dk�r�| dd��} tj | | d�}t|�|�}�qR|d��|7��<�|�t| �d��}�|�r�|�d ��t|d��}q�|d��|7��<�|�r�|S�dS�)a���Fold string to_encode into lines as encoded word, combining if allowed. Return the new value for last_ew, or None if ew_combine_allowed is False. If there is already an encoded word in the last line of lines (indicated by a non-None value for last_ew) and ew_combine_allowed is true, decode the existing ew, combine it with to_encode, and re-encode. Otherwise, encode to_encode. In either case, split to_encode as necessary so that the encoded segments fit within maxlen. Nr����r���r����r���r����r�������z3max_line_length is too small to fit an encoded wordrN���)r`���) r ���r(��r��r����rh���r���r���r��r��rC��)Z to_encoder���r���r���rI���r`���Zleading_wspZtrailing_wspZnew_last_ewZ encode_as� chrome_lenZremaining_spaceZ text_spaceZto_encode_wordZencoded_wordZexcessr���r���r���r���1��sT������ r���c�������������� ���C���s���|�j�D��]�\}}|d�����d�s2|d��d7��<�|}d}z|�|��d}W�n0�tk r|���d}t�|�rtd}d}nd}Y�nX�|r�tjj |d |d �} d� ||| �} nd� |t|��} t|d��t| ��d �|k�r�|d�d�| �|d<�qn"t| �d�|k�r |� d| ���qd}|d�}|rt|�tt|���d�t|��} || d�k�rLd}|| �d��}}|d|��}tjj |d |d �} t| �|k�r��q�|d 8�}�q\|� d� |||| ���d }|d 7�}||d��}|�r|d��d7��<��qqdS�)a>��Fold TokenList 'part' into the 'lines' list as mime parameters. Using the decoded list of parameters and values, format them according to the RFC rules, including using RFC2231 encoding if the value cannot be expressed in 'encoding' and/or the parameter+value is too long to fit within 'maxlen'. r����r]���strictFTr���r����r���r���)Zsafer���z {}*={}''{}r����r����rN���r����r���z''r�����N���Nz {}*{}*={}{})r����r����r����rC��r����r���r����r����r����ro���r*���r���r����rh���r ���)r2���r���r���r����r����r���r`���Z error_handlerZencoding_requiredZ encoded_valuer���r����Zextra_chromer���Z splitpointZmaxchars�partialr���r���r���r���r��sn���� ��� �������r���)�r���rer���r�����stringr����operatorr���Zemailr���r��r���r���r����r��r3��r:��r6��r����r=��Z TSPECIALSrr��Z ASPECIALSrw��r}��r����compile�VERBOSE� MULTILINEr$��r����r���rL���rR���rU���rW���rX���rZ���r\���r]���rb���rm���rn���rq���r{���r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r ���r����r��r��r��r��r��r����rR��rS��r*���r%���r����r��r���matchr.���findallr ��ro��rt��r{��r��r��r��r"��r(��r+��r,��r0��r1��r2��r4��r5��r7��r8��r9��r<��r?��rE��rB��rG��rK��rM��rN��rP��rT��rW��rX��rY��r[��r\��r^��r_��r`��ra��rc��rd��rf��rg��rl��rm��rp��rs��rv��ry��r|��r~��r���r���r���r���r���r���r���r���r���r9���r���r���r���r���r���r����<module>���s.��E �C" !*$ V + ���� 1C+ "&'/'&).9%7ED�49/gA