3 48e@sfddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z e dZee d BZe d ZeeBZee d Zee d Zee d Be d ZeeBZee dBZeeBZee dZddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZ GdddeZ!Gd d!d!eZ"Gd"d#d#eZ#Gd$d%d%eZ$Gd&d'd'e$Z%Gd(d)d)eZ&Gd*d+d+eZ'Gd,d-d-eZ(Gd.d/d/eZ)Gd0d1d1eZ*Gd2d3d3eZ+Gd4d5d5eZ,Gd6d7d7eZ-Gd8d9d9eZ.Gd:d;d;eZ/Gdd?d?eZ1Gd@dAdAeZ2GdBdCdCeZ3GdDdEdEeZ4GdFdGdGeZ5GdHdIdIeZ6GdJdKdKeZ7GdLdMdMeZ8GdNdOdOeZ9GdPdQdQeZ:GdRdSdSe:Z;GdTdUdUeZGdZd[d[eZ?Gd\d]d]eZ@Gd^d_d_e@ZAGd`dadae@ZBGdbdcdceZCGdddedeeZDGdfdgdgeZEGdhdidieFZGGdjdkdkeGZHGdldmdmeGZIGdndodoeHZJeId dpZKeIdqdrZLeIdsdtZMejNdujOdvjPejQZRejNdwjOdvjPejSdxdyjSdzd{jTZUejNd|jVZWejNdwjOdvjPejSdxdyjSdzd{jTZXejNdwjOdvjPejSdxdyjSdzd{jTZYejNdwjOdvjPejSdxdyjSdzd{jTZZd}d~Z[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|dd„Z}ddĄZ~ddƄZddȄZddʄZdd̄Zdd΄ZddЄZdd҄ZddԄZddքZdd؄ZddڄZdd܄ZddބZddZddZddZddZddZddZdS)N) hexdigits) OrderedDict) itemgetter)_encoded_words)errors)utilsz (z ()<>@,:;.\"[].z."(z/?=z*'%%cCs dt|jddjdddS)N"\z\\z\")strreplace)valuer2/usr/lib64/python3.6/email/_header_value_parser.py quote_string`srcseZdZdZdZdZfddZddZfddZe d d Z e d d Z d dZ e ddZ e ddZddZdddZdddZdddZZS) TokenListNTcstj||g|_dS)N)super__init__defects)selfargskw) __class__rrrmszTokenList.__init__cCsdjdd|DS)Ncss|]}t|VqdS)N)r ).0xrrr rsz$TokenList.__str__..)join)rrrr__str__qszTokenList.__str__csdj|jjtjS)Nz{}({}))formatr__name__r__repr__)r)rrrr#ts zTokenList.__repr__cCsdjdd|DS)Nrcss|]}|jr|jVqdS)N)r)rrrrrrzsz"TokenList.value..)r)rrrrrxszTokenList.valuecCstdd|D|jS)Ncss|] }|jVqdS)N) all_defects)rrrrrr~sz(TokenList.all_defects..)sumr)rrrrr$|szTokenList.all_defectscCs |djS)Nr)startswith_fws)rrrrr&szTokenList.startswith_fwscCstdd|DS)Ncss|] }|jVqdS)N) as_ew_allowed)rpartrrrrsz*TokenList.as_ew_allowed..)all)rrrrr'szTokenList.as_ew_allowedcCs"g}x|D]}|j|jq W|S)N)extendcomments)rr+tokenrrrr+s zTokenList.commentscCs t||dS)N)policy)_refold_parse_tree)rr-rrrfoldszTokenList.foldrcCst|j|ddS)N)indent)printppstr)rr0rrrpprintszTokenList.pprintcCsdj|j|dS)N )r0)r_pp)rr0rrrr2szTokenList.ppstrccs~dj||jj|jVx<|D]4}t|ds<|dj|Vq|j|dEdHqW|jrhdj|j}nd}dj||VdS)Nz{}{}/{}(r5z* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r!rr" token_typehasattrr5r)rr0r,Zextrarrrr5s    z TokenList._pp)r)r)r)r" __module__ __qualname__r6syntactic_breakew_combine_allowedrr r#propertyrr$r&r'r+r/r3r2r5 __classcell__rr)rrrgs        rc@s$eZdZeddZeddZdS)WhiteSpaceTokenListcCsdS)N r)rrrrrszWhiteSpaceTokenList.valuecCsdd|DS)NcSsg|]}|jdkr|jqS)comment)r6content)rrrrr sz0WhiteSpaceTokenList.comments..r)rrrrr+szWhiteSpaceTokenList.commentsN)r"r8r9r<rr+rrrrr>s r>c@seZdZdZdS)UnstructuredTokenList unstructuredN)r"r8r9r6rrrrrCsrCc@seZdZdZdS)PhrasephraseN)r"r8r9r6rrrrrEsrEc@seZdZdZdS)WordZwordN)r"r8r9r6rrrrrGsrGc@seZdZdZdS)CFWSListcfwsN)r"r8r9r6rrrrrHsrHc@seZdZdZdS)AtomatomN)r"r8r9r6rrrrrJsrJc@seZdZdZdZdS)Tokenr,FN)r"r8r9r6Z encode_as_ewrrrrrLsrLc@seZdZdZdZdZdZdS) EncodedWordz encoded-wordN)r"r8r9r6ctecharsetlangrrrrrMsrMc@s4eZdZdZeddZeddZeddZdS) QuotedStringz quoted-stringcCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r6r)rrrrrrAs  zQuotedString.contentcCsBg}x2|D]*}|jdkr(|jt|q |j|jq Wdj|S)Nzbare-quoted-stringr)r6appendr rr)rresrrrr quoted_values   zQuotedString.quoted_valuecCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r6r)rr,rrrstripped_values  zQuotedString.stripped_valueN)r"r8r9r6r<rArTrUrrrrrQs  rQc@s$eZdZdZddZeddZdS)BareQuotedStringzbare-quoted-stringcCstdjdd|DS)Nrcss|]}t|VqdS)N)r )rrrrrrsz+BareQuotedString.__str__..)rr)rrrrr szBareQuotedString.__str__cCsdjdd|DS)Nrcss|]}t|VqdS)N)r )rrrrrrsz)BareQuotedString.value..)r)rrrrrszBareQuotedString.valueN)r"r8r9r6r r<rrrrrrVsrVc@s8eZdZdZddZddZeddZedd Zd S) Commentr@cs(djtdgfddDdgggS)Nrrcsg|]}j|qSr)quote)rr)rrrrB sz#Comment.__str__..))rr%)rr)rrr s zComment.__str__cCs2|jdkrt|St|jddjddjddS)Nr@r z\\rz\(rYz\))r6r r)rrrrrrX s  z Comment.quotecCsdjdd|DS)Nrcss|]}t|VqdS)N)r )rrrrrrsz"Comment.content..)r)rrrrrAszComment.contentcCs|jgS)N)rA)rrrrr+szComment.commentsN) r"r8r9r6r rXr<rAr+rrrrrWs  rWc@s4eZdZdZeddZeddZeddZdS) AddressListz address-listcCsdd|DS)NcSsg|]}|jdkr|qS)address)r6)rrrrrrB"sz)AddressList.addresses..r)rrrr addresses szAddressList.addressescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r[N)r6 mailboxes)rrrrrr&sz(AddressList.mailboxes..)r%)rrrrr]$szAddressList.mailboxescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r[N)r6 all_mailboxes)rrrrrr+sz,AddressList.all_mailboxes..)r%)rrrrr^)szAddressList.all_mailboxesN)r"r8r9r6r<r\r]r^rrrrrZs  rZc@s4eZdZdZeddZeddZeddZdS) Addressr[cCs|djdkr|djSdS)Nrgroup)r6 display_name)rrrrra3szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djS)Nrmailboxzinvalid-mailbox)r6r])rrrrr]8s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djS)Nrrbzinvalid-mailbox)r6r^)rrrrr^@s   zAddress.all_mailboxesN)r"r8r9r6r<rar]r^rrrrr_/s  r_c@s(eZdZdZeddZeddZdS) MailboxListz mailbox-listcCsdd|DS)NcSsg|]}|jdkr|qS)rb)r6)rrrrrrBNsz)MailboxList.mailboxes..r)rrrrr]LszMailboxList.mailboxescCsdd|DS)NcSsg|]}|jdkr|qS)rbinvalid-mailbox)rbrd)r6)rrrrrrBRsz-MailboxList.all_mailboxes..r)rrrrr^PszMailboxList.all_mailboxesN)r"r8r9r6r<r]r^rrrrrcHs rcc@s(eZdZdZeddZeddZdS) GroupListz group-listcCs"| s|djdkrgS|djS)Nrz mailbox-list)r6r])rrrrr]ZszGroupList.mailboxescCs"| s|djdkrgS|djS)Nrz mailbox-list)r6r^)rrrrr^`szGroupList.all_mailboxesN)r"r8r9r6r<r]r^rrrrreVs rec@s4eZdZdZeddZeddZeddZdS) Groupr`cCs|djdkrgS|djS)Nz group-list)r6r])rrrrr]kszGroup.mailboxescCs|djdkrgS|djS)Nrgz group-list)r6r^)rrrrr^qszGroup.all_mailboxescCs |djS)Nr)ra)rrrrrawszGroup.display_nameN)r"r8r9r6r<r]r^rarrrrrfgs  rfc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) NameAddrz name-addrcCst|dkrdS|djS)Nr)lenra)rrrrras zNameAddr.display_namecCs |djS)Nri) local_part)rrrrrlszNameAddr.local_partcCs |djS)Nrirk)domain)rrrrrmszNameAddr.domaincCs |djS)Nrirk)route)rrrrrnszNameAddr.routecCs |djS)Nrirk) addr_spec)rrrrroszNameAddr.addr_specN) r"r8r9r6r<rarlrmrnrorrrrrh|s     rhc@s@eZdZdZeddZeddZeddZedd Zd S) AngleAddrz angle-addrcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r6rl)rrrrrrls  zAngleAddr.local_partcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r6rm)rrrrrrms  zAngleAddr.domaincCs"x|D]}|jdkr|jSqWdS)Nz obs-route)r6domains)rrrrrrns  zAngleAddr.routecCs<x6|D]*}|jdkr|jr |jSt|j|jSqWdSdS)Nz addr-specz<>)r6rlror)rrrrrros   zAngleAddr.addr_specN) r"r8r9r6r<rlrmrnrorrrrrps    rpc@seZdZdZeddZdS)ObsRoutez obs-routecCsdd|DS)NcSsg|]}|jdkr|jqS)rm)r6rm)rrrrrrBsz$ObsRoute.domains..r)rrrrrqszObsRoute.domainsN)r"r8r9r6r<rqrrrrrrsrrc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) MailboxrbcCs|djdkr|djSdS)Nrz name-addr)r6ra)rrrrraszMailbox.display_namecCs |djS)Nr)rl)rrrrrlszMailbox.local_partcCs |djS)Nr)rm)rrrrrmszMailbox.domaincCs|djdkr|djSdS)Nrz name-addr)r6rn)rrrrrnsz Mailbox.routecCs |djS)Nr)ro)rrrrroszMailbox.addr_specN) r"r8r9r6r<rarlrmrnrorrrrrss     rsc@s,eZdZdZeddZeZZZZ dS)InvalidMailboxzinvalid-mailboxcCsdS)Nr)rrrrraszInvalidMailbox.display_nameN) r"r8r9r6r<rarlrmrnrorrrrrts rtcs(eZdZdZdZefddZZS)DomainrmFcsdjtjjS)Nr)rrrsplit)r)rrrrmsz Domain.domain)r"r8r9r6r'r<rmr=rr)rrrusruc@seZdZdZdS)DotAtomzdot-atomN)r"r8r9r6rrrrrwsrwc@seZdZdZdZdS) DotAtomTextz dot-atom-textTN)r"r8r9r6r'rrrrrxsrxc@sDeZdZdZdZeddZeddZeddZed d Z d S) AddrSpecz addr-specFcCs |djS)Nr)rl)rrrrrlszAddrSpec.local_partcCst|dkrdS|djS)Nrirk)rjrm)rrrrrms zAddrSpec.domaincCs<t|dkr|djS|djj|dj|djjS)Nrzrrirg)rjrrstriplstrip)rrrrr s  zAddrSpec.valuecCsLt|j}t|t|tkr*t|j}n|j}|jdk rH|d|jS|S)N@)setrlrj DOT_ATOM_ENDSrrm)rZnamesetZlprrrros   zAddrSpec.addr_specN) r"r8r9r6r'r<rlrmrrorrrrrys    ryc@seZdZdZdZdS) ObsLocalPartzobs-local-partFN)r"r8r9r6r'rrrrrsrcs4eZdZdZdZeddZefddZZS) DisplayNamez display-nameFcCst|}|djdkr"|jdn*|ddjdkrLt|ddd|d<|djdkrd|jn*|ddjdkrt|ddd|d <|jS) NrrIrirkrkrkrkrkrk)rr6popr)rrSrrrra)s  zDisplayName.display_namecsd}|jrd}nx|D]}|jdkrd}qW|rd}}|djdksX|ddjdkr\d}|d jdks||d d jdkrd}|t|j|StjSdS) NFTz quoted-stringrrrIr?rirkrkrk)rr6rrarr)rrXrZpreZpost)rrrr8s    zDisplayName.value) r"r8r9r6r;r<rarr=rr)rrr$s rc@s,eZdZdZdZeddZeddZdS) LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrz quoted-string)r6rTr)rrrrrQs zLocalPart.valuecCstg}t}d}x|dtgD]}|jdkr.q|r^|jdkr^|djdkr^t|dd|d<t|t}|r|jdkr|djdkr|jt|ddn |j||d }|}qWt|dd }|jS) NFrrIdotrirkrkrkrkrk)DOTr6r isinstancerRr)rrSZlastZ last_is_tltokZis_tlrrrrlXs$   zLocalPart.local_partN)r"r8r9r6r'r<rrlrrrrrLs rcs4eZdZdZdZefddZeddZZS) DomainLiteralzdomain-literalFcsdjtjjS)Nr)rrrrv)r)rrrrmuszDomainLiteral.domaincCs"x|D]}|jdkr|jSqWdS)Nptext)r6r)rrrrripys  zDomainLiteral.ip) r"r8r9r6r'r<rmrr=rr)rrrpsrc@seZdZdZdZdZdS) MIMEVersionz mime-versionN)r"r8r9r6majorminorrrrrrsrc@s4eZdZdZdZdZdZeddZeddZ dS) Parameter parameterFzus-asciicCs|jr|djSdS)Nrir) sectionednumber)rrrrsection_numberszParameter.section_numbercCsbx\|D]T}|jdkr|jS|jdkrx4|D],}|jdkr*x|D]}|jdkr>|jSq>Wq*WqWdS)Nrz quoted-stringzbare-quoted-stringr)r6rU)rr,rrr param_values       zParameter.param_valueN) r"r8r9r6rextendedrOr<rrrrrrrs  rc@seZdZdZdS)InvalidParameterzinvalid-parameterN)r"r8r9r6rrrrrsrc@seZdZdZeddZdS) Attribute attributecCs$x|D]}|jjdr|jSqWdS)Nattrtext)r6endswithr)rr,rrrrUs  zAttribute.stripped_valueN)r"r8r9r6r<rUrrrrrsrc@seZdZdZdZdS)SectionsectionN)r"r8r9r6rrrrrrsrc@seZdZdZeddZdS)ValuercCs2|d}|jdkr|d}|jjdr,|jS|jS)NrrIri quoted-stringrextended-attribute)rrr)r6rrUr)rr,rrrrUs zValue.stripped_valueN)r"r8r9r6r<rUrrrrrsrc@s(eZdZdZdZeddZddZdS)MimeParameterszmime-parametersFc cst}x\|D]T}|jjdsq |djdkr.q |djj}||krLg||<||j|j|fq Wx|jD]\}}t|t dd}|dd}|j }|j rt |dkr|dddkr|ddj jtjd|dd}g}d}x|D]\} } | |kr6| j s$| j jtjdqn| j jtjd|d7}| j} | j rytjj| } Wn&tk rtjj| d d } YnRXy| j|d } Wn"tk r| jd d } YnXtj| r| j jtj|j| qWd j|} || fVqpWdS)Nrrr)keyriz.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)encodingsurrogateescapezus-asciir)rr6rrstriprRritemssortedrrOrrjrrInvalidHeaderDefectrurllibparseZunquote_to_bytesUnicodeEncodeErrorZunquotedecode LookupErrorr_has_surrogatesUndecodableBytesDefectr) rparamsr,namepartsZ first_paramrOZ value_partsirparamrrrrrsZ         zMimeParameters.paramscCsXg}x8|jD].\}}|r0|jdj|t|q |j|q Wdj|}|rTd|SdS)Nz{}={}z; r?r)rrRr!rr)rrrrrrrr s zMimeParameters.__str__N)r"r8r9r6r:r<rr rrrrrs Frc@seZdZdZeddZdS)ParameterizedHeaderValueFcCs&x t|D]}|jdkr |jSq WiS)Nzmime-parameters)reversedr6r)rr,rrrr#s  zParameterizedHeaderValue.paramsN)r"r8r9r:r<rrrrrrsrc@seZdZdZdZdZdZdS) ContentTypez content-typeFtextZplainN)r"r8r9r6r'maintypesubtyperrrrr+src@seZdZdZdZdZdS)ContentDispositionzcontent-dispositionFN)r"r8r9r6r'content_dispositionrrrrr3src@seZdZdZdZdZdS)ContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r"r8r9r6r'rNrrrrr:src@seZdZdZdZdS) HeaderLabelz header-labelFN)r"r8r9r6r'rrrrrAsrc@seZdZdZdS)HeaderheaderN)r"r8r9r6rrrrrGsrcsreZdZdZdZdZfddZfddZddZe dd Z dfd d Z d dZ e ddZ ddZZS)TerminalTcstj||}||_g|_|S)N)r__new__r6r)clsrr6r)rrrrVszTerminal.__new__csdj|jjtjS)Nz{}({}))r!rr"rr#)r)rrrr#\szTerminal.__repr__cCst|jjd|jdS)N/)r1rr"r6)rrrrr3_szTerminal.pprintcCs t|jS)N)listr)rrrrr$bszTerminal.all_defectsrcs2dj||jj|jtj|js"dn dj|jgS)Nz {}{}/{}({}){}rz {})r!rr"r6rr#r)rr0)rrrr5fs z Terminal._ppcCsdS)Nr)rrrrpop_trailing_wsoszTerminal.pop_trailing_wscCsgS)Nr)rrrrr+sszTerminal.commentscCst||jfS)N)r r6)rrrr__getnewargs__wszTerminal.__getnewargs__)r)r"r8r9r'r;r:rr#r3r<r$r5rr+rr=rr)rrrPs     rc@s eZdZeddZddZdS)WhiteSpaceTerminalcCsdS)Nr?r)rrrrr}szWhiteSpaceTerminal.valuecCsdS)NTr)rrrrr&sz!WhiteSpaceTerminal.startswith_fwsN)r"r8r9r<rr&rrrrr{s rc@s eZdZeddZddZdS) ValueTerminalcCs|S)Nr)rrrrrszValueTerminal.valuecCsdS)NFr)rrrrr&szValueTerminal.startswith_fwsN)r"r8r9r<rr&rrrrrs rc@s eZdZeddZddZdS)EWWhiteSpaceTerminalcCsdS)Nrr)rrrrrszEWWhiteSpaceTerminal.valuecCsdS)Nrr)rrrrr szEWWhiteSpaceTerminal.__str__N)r"r8r9r<rr rrrrrs rr,zlist-separatorr}zroute-component-markerz([{}]+)rz[^{}]+r z\\]z\]z[\x00-\x20\x7F]cCs>t|}|r|jjtj|tj|r:|jjtjddS)Nz*Non-ASCII characters found in header token)_non_printable_finderrrRrZNonPrintableDefectrrr)xtextZnon_printablesrrr_validate_xtexts   rcCst|d^}}g}d}d}xbtt|D]J}||dkrL|rFd}d}nd}q(|rVd}n|||krdP|j||q(W|d}dj|dj||dg||fS)NriFr Tr) _wsp_splitterrangerjrRr)rendcharsZfragment remainderZvcharsescapehad_qpposrrr_get_ptext_to_endcharss$   rcCs.|j}t|dt|t|d}||fS)Nfws)r|rrj)rZnewvaluerrrrget_fwssrc Cst}|jds tjdj||ddjdd^}}||ddkrXtjdj|dj|}t|dkr|dtkr|dtkr|jdd^}}|d|}t|jdkr|j j tj d||_ dj|}yt jd|d\}}}} Wn(tk rtjd j|j YnX||_||_|j j| xh|r|dtkrdt|\} }|j | q6t|d^} }t| d } t| |j | dj|}q6W||fS) Nz=?z"expected encoded word but found {}rgz?=rirrzwhitespace inside encoded wordz!encoded word format invalid: '{}'vtext)rM startswithrHeaderParseErrorr!rvrrjrrrRrrN_ewr ValueErrorrOrPr*WSPrrrr) rewrrZremstrrestrrOrPrr,charsrrrrget_encoded_wordsH    $        rc Cst}x|r |dtkr4t|\}}|j|q |jdryt|\}}Wntjk rdYnrXd}t|dkr|d j dkr|j jtj dd}|rt|dkr|d j d krt |dd|d<|j|q t |d^}}t|d }t||j|d j|}q W|S)Nrz=?Trirz&missing whitespace before encoded wordFrgz encoded-wordrrrkrkrk)rCrrrRrrrrrjr6rrrrrrr)rrDr,Zhave_wsrrrrrrget_unstructureds:          rcCs*t|d\}}}t|d}t|||fS)Nz()r)rrr)rr_rrr get_qp_ctextWs  rcCs*t|d\}}}t|d}t|||fS)Nr r)rrr)rrrrrr get_qcontenths  rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nzexpected atext but found '{}'atext)_non_atom_end_matcherrrr!r`rjrr)rmrrrr get_atextws  rc Cs|ddkrtjdj|t}|dd}|ddkrPt|\}}|j|x|r|ddkr|dtkr|t|\}}nd|dddkry"t|\}}|j jtj dWqtjk rt|\}}YqXn t|\}}|j|qRW|s|j jtj d||fS||ddfS) Nrr zexpected '"' but found '{}'rirgz=?z!encoded word inside quoted stringz"end of header inside quoted string) rrr!rVrrRrrrrr)rZbare_quoted_stringr,rrrget_bare_quoted_strings2            rcCs|r |ddkr tjdj|t}|dd}x^|r|ddkr|dtkr^t|\}}n&|ddkrxt|\}}n t|\}}|j|q4W|s|j jtj d||fS||ddfS)Nrrzexpected '(' but found '{}'rirYzend of header inside comment) rrr!rWrr get_commentrrRrr)rr@r,rrrrs"      rcCsTt}xD|rJ|dtkrJ|dtkr2t|\}}n t|\}}|j|qW||fS)Nr)rH CFWS_LEADERrrrrR)rrIr,rrrget_cfwss  rcCspt}|r,|dtkr,t|\}}|j|t|\}}|j||rh|dtkrht|\}}|j|||fS)Nr)rQrrrRr)rZ quoted_stringr,rrrget_quoted_strings      rc Cst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj||jdryt |\}}Wqtjk rt |\}}YqXn t |\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected atom but found '{}'z=?) rJrrrR ATOM_ENDSrrr!rrr)rrKr,rrrget_atoms$        rcCst}| s|dtkr(tjdj|xP|rx|dtkrxt|\}}|j||r*|ddkr*|jt|dd}q*W|dtkrtjdjd|||fS)Nrz8expected atom at a start of dot-atom-text but found '{}'r riz4expected atom at end of dot-atom-text but found '{}'rk)rxrrrr!rrRr)rZ dot_atom_textr,rrrget_dot_atom_texts     rc Cst}|dtkr(t|\}}|j||jdrhyt|\}}Wqttjk rdt|\}}YqtXn t|\}}|j||r|dtkrt|\}}|j|||fS)Nrz=?) rwrrrRrrrrr)rZdot_atomr,rrr get_dot_atoms        rcCs|dtkrt|\}}nd}|ddkr8t|\}}n*|dtkrVtjdj|n t|\}}|dk rx|g|dd<||fS)Nrr z1Expected 'atom' or 'quoted-string' but found '{}')rrrSPECIALSrrr!r)rleaderr,rrrget_word(s     rcCst}yt|\}}|j|Wn(tjk rH|jjtjdYnXx|r|dtkr|ddkr|jt|jjtj d|dd}qLyt|\}}WnDtjk r|dt krt |\}}|jjtj dnYnX|j|qLW||fS)Nzphrase does not start with wordrr zperiod in 'phrase'rizcomment found without atom) rErrRrrrr PHRASE_ENDSrObsoleteHeaderDefectrr)rrFr,rrr get_phraseGs.          rcCstt}d}|dtkr"t|\}}|s6tjdj|yt|\}}Wn^tjk ryt|\}}Wn6tjk r|ddkr|dtkrt }YnXYnX|dk r|g|dd<|j ||o|ddks|dtkr2t t ||\}}|j dkr|jj tjdn|jj tjd||d<y|jjdWn(tk rj|jj tjdYnX||fS) Nrz"expected local-part but found '{}'r zinvalid-obs-local-partzzangle-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) rprrrRrrr!rrrrr r)rZ angle_addrr,rrrget_angle_addresJ                r cCs<t}t|\}}|j|dd|jdd|_||fS)N)rrr*r)rrar,rrrget_display_names  r cCst}d}|dtkr6t|\}}|s6tjdj||ddkr|dtkr^tjdj|t|\}}|s~tjdj||dk r|g|ddd<d}|j|t |\}}|dk r|g|dd<|j|||fS)Nrz!expected name-addr but found '{}'r ) rhrrrrr!rr rRr )rZ name_addrrr,rrr get_name_addrs0           rcCst}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnXtdd|jDrd|_|j |||fS)Nzexpected mailbox but found '{}'css|]}t|tjVqdS)N)rrr)rrrrrrszget_mailbox..zinvalid-mailbox) rsrrrrr!anyr$r6rR)rrbr,rrr get_mailboxs  rcCsht}xX|r^|d|kr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)Nrzmisplaced-specialri)rtrrRrr)rrZinvalid_mailboxr,rrrget_invalid_mailboxs   rc Cst}x|o|ddkryt|\}}|j|Wntjk r@d}|dtkrt|\}}| sz|ddkr|j||jjtjdn@t |d\}}|dk r|g|dd<|j||jjtj dnb|ddkr|jjtjdnBt |d\}}|dk r |g|dd<|j||jjtj dYnX|r|ddkr|d }d|_ t |d\}}|j ||jjtj d|r |ddkr |jt |dd}q W||fS) Nr;z,;zempty element in mailbox-listzinvalid mailbox in mailbox-listrrizinvalid-mailboxrk)rcrrRrrrrrrrrr6r*r)rZ mailbox_listr,rrbrrrget_mailbox_listsN                   rcCst}|s$|jjtjd||fSd}|r|dtkrt|\}}|sl|jjtjd|j|||fS|ddkr|j|||fSt|\}}t|j dkr|dk r|j||j ||jjtj d||fS|dk r|g|dd<|j|||fS)Nzend of header before group-listrzend of header in group-listrzgroup-list with empty entries) rerrRrrrrrrjr^r*r)rZ group_listrr,rrrget_group_list s8           rcCs"t}t|\}}| s$|ddkr4tjdj||j||jtdd|dd}|r|ddkr|jtdd||ddfSt|\}}|j||s|jjtj dn|ddkrtjd j||jtdd|dd}|r|dt krt |\}}|j|||fS) Nrrz8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorrirzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rfr rrr!rRrrrrrr)rr`r,rrr get_groupEs2            rcCsxt}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnX|j|||fS)Nzexpected address but found '{}')r_rrrrr!rR)rr[r,rrr get_addresscs rcCst}x|ryt|\}}|j|Wn$tjk rP}zd}|dtkrt|\}}| sr|ddkr|j||jjtjdnFt |d\}}|dk r|g|dd<|jt |g|jjtj dnh|ddkr|jjtjdnHt |d\}}|dk r|g|dd<|jt |g|jjtj dWYdd}~XnX|r|ddkr|d d}d|_ t |d\}}|j ||jjtj d|r |jtdd|dd}q W||fS) Nrrz"address-list entry with no contentzinvalid address in address-listzempty element in address-listrizinvalid-mailboxzlist-separatorrk)rZrrRrrrrrrrr_rr6r*r)rZ address_listr,errrrbrrrget_address_listsN                  rcCst}|s |jjtjd|S|dtkrXt|\}}|j||sX|jjtjdd}x8|r|ddkr|dtkr||d7}|dd}q^W|js|jjtjdj ||jt |dnt ||_ |jt |d |o|dtkr t|\}}|j|| s |ddkrX|j dk r>|jjtjd |rT|jt |d|S|jt dd |dd}|r|dtkrt|\}}|j||s|j dk r|jjtjd |Sd}x2|r|dtkr||d7}|dd}qW|js2|jjtjd j ||jt |dnt ||_ |jt |d |rv|dtkrvt|\}}|j||r|jjtjd |jt |d|S)Nz%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSrr riz1Expected MIME major version number but found {!r}rdigitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rrrRrHeaderMissingRequiredValuerrisdigitrr!rintrr)rZ mime_versionr,rrrrparse_mime_versionsv                        rcCsht}xX|r^|ddkr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)Nrrzmisplaced-specialri)rrrRrr)rZinvalid_parameterr,rrrget_invalid_parameters   rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nzexpected ttext but found '{}'ttext)_non_token_end_matcherrrr!r`rjrr)rrrrrr get_ttexts   r!cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rLrrrR TOKEN_ENDSrrr!r!)rZmtokenr,rrr get_token's        r#cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nz expected attrtext but found {!r}r)_non_attribute_end_matcherrrr!r`rjrr)rrrrrr get_attrtext>s   r%cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rrrrRATTRIBUTE_ENDSrrr!r%)rrr,rrr get_attributeQs        r'cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nz)expected extended attrtext but found {!r}zextended-attrtext)#_non_extended_attribute_end_matcherrrr!r`rjrr)rrrrrrget_extended_attrtexths  r)cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rrrrREXTENDED_ATTRIBUTE_ENDSrrr!r))rrr,rrrget_extended_attributezs       r+cCst}| s|ddkr(tjdj||jtdd|dd}| sX|dj rhtjdj|d}x,|r|djr||d7}|dd}qnW|ddkr|dkr|jjtjd t ||_ |jt|d ||fS) Nr*zExpected section but found {}zsection-markerriz$Expected section number but found {}r0z'section number has an invalid leading 0r) rrrr!rRrrrZInvalidHeaderErrorrr)rrrrrr get_sections&     r.cCst}|stjdd}|dtkr0t|\}}|sDtjdj||ddkr^t|\}}n t|\}}|dk r|g|dd<|j|||fS)Nz&Expected value but found end of stringrz Expected value but found only {}r ) rrrrrr!rr+rR)rvrr,rrr get_values       r0c Csvt}t|\}}|j|| s.|ddkrN|jjtjdj|||fS|ddkry t|\}}d|_|j|Wntj k rYnX|stj d|ddkr|jt dd|dd}d|_ |dd krtj d |jt d d |dd}d}|r.|dt kr.t |\}}|j|d}|}|j rH|rH|dd krHt|\}}|j}d }|jdkr|r|ddkrd}n$t|\}} | r| ddkrd}n(yt|\}} Wn Yn X| sd}|r2|jjtjd|j|x,|D]$} | jdkrg| dd<| }PqW|}nd}|jjtjd|rb|ddkrbd}n t|\}}|j s|jdkr| s|ddkr|j||dk r|}||fS|jjtjd|s|jjtjd|j||dkr||fSn|dk rFx|D]} | jdkrPqW| jdk|j| | j|_|ddkrdtj dj||jt dd|dd}|r|ddkrt|\}}|j||j|_| s|ddkrtj dj||jt dd|dd}|dk rJt} x>|rB|dtkr(t|\}}n t|\}}| j|qW| }n t|\}}|j||dk rn|}||fS)Nrrz)Parameter contains name ({}) but no valuer,TzIncomplete parameterzextended-parameter-markerri=zParameter not followed by '='zparameter-separatorr F'z5Quoted string value for extended parameter is invalidzbare-quoted-stringzZParameter 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 delimiterszextended-attrtextrz=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {})rr'rRrrrr!r.rrrrrrrrUrr%r)r6r0rrOrPrrrr) rrr,rrZappendtoZqstringZ inner_valueZ semi_validrtr/rrr get_parameters                                             r4cCsht}xZ|rbyt|\}}|j|Wntjk r}zd}|dtkrZt|\}}|sl|j||S|ddkr|dk r|j||jjtjdn@t |\}}|r|g|dd<|j||jjtjdj |WYdd}~XnX|r@|ddkr@|d }d|_ t |\}}|j ||jjtjdj ||r |jt dd|dd}q W|S) Nrrzparameter entry with no contentzinvalid parameter {!r}rizinvalid-parameterz)parameter with invalid trailing text {!r}zparameter-separatorrk)rr4rRrrrrrrrr!r6r*r)rZmime_parametersr,rrrrrrparse_mime_parametersO sD                 r5cCsxX|rX|ddkrX|dtkr@|jt|dd|dd}qt|\}}|j|qW|sbdS|jtdd|jt|dddS)Nrrzmisplaced-specialrizparameter-separator)rrRrrr5)Z tokenlistrr,rrr_find_mime_parameters s  r6cCst}d}|s$|jjtjd|Syt|\}}Wn8tjk rl|jjtjdj|t |||SX|j|| s|ddkr|jjtjd|rt |||S|j j j |_ |jtdd|dd}yt|\}}Wn:tjk r$|jjtjd j|t |||SX|j||j j j |_|sJ|S|dd kr|jjtjd j||` |`t |||S|jtd d |jt|dd|S) NFz"Missing content type specificationz(Expected content maintype but found {!r}rrzInvalid content typezcontent-type-separatorriz'Expected content subtype but found {!r}rz.z unknown-8bitTzmime-parameters)r-rrkrkrkrkrkrk)Zmax_line_lengthfloatutf8rrrr rrrr$r6_fold_mime_parametersr'r:r/lineseprjr<rRr7 _fold_as_ewr;r&insertr)Z parse_treer-maxlenrr;last_ewr=Z want_encodingZend_ew_not_allowedrr(tstrrOZ encoded_partnewlineZnewpartsrrrr. s                r.cCs|dk r<|rrCrErGrHrJrLrMrQrVrWrZr_rcrerfrhrprrrsrtrurwrxryrrrrrrrrrrrrrrrrrr rrrrrrrcompiler!rrvrrmatchrfindallrr r$r(rrrrrrrrrrrrrrrrrrrrrrrrr r r rrrrrrrrrrr!r#r%r'r)r+r.r0r4r5r6r8r9r:r<r.rBr@rrrrFs           C  "   !($ V +            *8" &'/'&).9%>D 49/c7