3 f@svddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z e dZee d BZe d ZeeBZee d Zee d Zee d Be d ZeeBZee dBZeeBZee dZddhZeeBZddZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gd d!d!eZ#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*Gd0d1d1eZ+Gd2d3d3eZ,Gd4d5d5eZ-Gd6d7d7eZ.Gd8d9d9eZ/Gd:d;d;eZ0Gdd?d?eZ2Gd@dAdAeZ3GdBdCdCeZ4GdDdEdEeZ5GdFdGdGeZ6GdHdIdIeZ7GdJdKdKe Z8GdLdMdMeZ9GdNdOdOeZ:GdPdQdQeZ;GdRdSdSeZGdXdYdYeZ?GdZd[d[eZ@Gd\d]d]eZAGd^d_d_eZBGd`dadaeBZCGdbdcdceBZDGdddedeeZEGdfdgdgeZFGdhdidieZGGdjdkdkeHZIGdldmdmeIZJGdndodoeIZKGdpdqdqeJZLeKd drZMeKdsdtZNeKdudvZOejPdwjQdxjRejSZTejPdyjQdxjRejUdzd{jUd|d}jVZWejPd~jXZYejPdyjQdxjRejUdzd{jUd|d}jVZZejPdyjQdxjRejUdzd{jUd|d}jVZ[ejPdyjQdxjRejUdzd{jUd|d}jVZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}dd„Z~ddĄZddƄZddȄZddʄZdd̄Zdd΄ZddЄZdd҄ZddԄZddքZdd؄ZddڄZdd܄ZddބZddZddZddZddZddZddZddZdS)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_stringbsrcseZdZdZdZdZfddZddZfddZe d d Z e d d Z d dZ e ddZ e ddZddZdddZdddZdddZZS) TokenListNTcstj||g|_dS)N)super__init__defects)selfargskw) __class__rrroszTokenList.__init__cCsdjdd|DS)Ncss|]}t|VqdS)N)r).0xrrr tsz$TokenList.__str__..)join)rrrr__str__sszTokenList.__str__csdj|jjtjS)Nz{}({}))formatr__name__r__repr__)r)rrrr%vs zTokenList.__repr__cCsdjdd|DS)Nrcss|]}|jr|jVqdS)N)r)rrrrrr |sz"TokenList.value..)r!)rrrrrzszTokenList.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)rpartrrrr sz*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)rr2rrrpprintszTokenList.pprintcCsdj|j|dS)Nr )r2)r!_pp)rr2rrrr4szTokenList.ppstrccs~dj||jj|jVx<|D]4}t|ds<|dj|Vq|j|dEdHqW|jrhdj|j}nd}dj||VdS)Nz{}{}/{}(r6z* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r#rr$ token_typehasattrr6r)rr2r.Zextrarrrr6s    z TokenList._pp)r)r)r)r$ __module__ __qualname__r7syntactic_breakew_combine_allowedrr"r%propertyrr&r(r)r-r1r5r4r6 __classcell__rr)rrris        rc@s$eZdZeddZeddZdS)WhiteSpaceTokenListcCsdS)N r)rrrrrszWhiteSpaceTokenList.valuecCsdd|DS)NcSsg|]}|jdkr|jqS)comment)r7content)rrrrr sz0WhiteSpaceTokenList.comments..r)rrrrr-szWhiteSpaceTokenList.commentsN)r$r9r:r=rr-rrrrr?s r?c@seZdZdZdS)UnstructuredTokenList unstructuredN)r$r9r:r7rrrrrDsrDc@seZdZdZdS)PhrasephraseN)r$r9r:r7rrrrrFsrFc@seZdZdZdS)WordZwordN)r$r9r:r7rrrrrHsrHc@seZdZdZdS)CFWSListcfwsN)r$r9r:r7rrrrrIsrIc@seZdZdZdS)AtomatomN)r$r9r:r7rrrrrKsrKc@seZdZdZdZdS)Tokenr.FN)r$r9r:r7Z encode_as_ewrrrrrMsrMc@seZdZdZdZdZdZdS) EncodedWordz encoded-wordN)r$r9r:r7ctecharsetlangrrrrrNsrNc@s4eZdZdZeddZeddZeddZdS) QuotedStringz quoted-stringcCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rrrrrrBs  zQuotedString.contentcCsBg}x2|D]*}|jdkr(|jt|q |j|jq Wdj|S)Nzbare-quoted-stringr)r7appendrrr!)rresrrrr quoted_values   zQuotedString.quoted_valuecCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rr.rrrstripped_values  zQuotedString.stripped_valueN)r$r9r:r7r=rBrUrVrrrrrRs  rRc@s$eZdZdZddZeddZdS)BareQuotedStringzbare-quoted-stringcCstdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz+BareQuotedString.__str__..)rr!)rrrrr"szBareQuotedString.__str__cCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz)BareQuotedString.value..)r!)rrrrrszBareQuotedString.valueN)r$r9r:r7r"r=rrrrrrWsrWc@s8eZdZdZddZddZeddZedd Zd S) CommentrAcs(djtdgfddDdgggS)Nrrcsg|]}j|qSr)quote)rr)rrrrC sz#Comment.__str__..))r!r')rr)rrr"s zComment.__str__cCs2|jdkrt|St|jddjddjddS)NrArz\\rz\(rZz\))r7rr)rrrrrrYs  z Comment.quotecCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz"Comment.content..)r!)rrrrrBszComment.contentcCs|jgS)N)rB)rrrrr-szComment.commentsN) r$r9r:r7r"rYr=rBr-rrrrrXs  rXc@s4eZdZdZeddZeddZeddZdS) AddressListz address-listcCsdd|DS)NcSsg|]}|jdkr|qS)address)r7)rrrrrrC$sz)AddressList.addresses..r)rrrr addresses"szAddressList.addressescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 mailboxes)rrrrrr (sz(AddressList.mailboxes..)r')rrrrr^&szAddressList.mailboxescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 all_mailboxes)rrrrrr -sz,AddressList.all_mailboxes..)r')rrrrr_+szAddressList.all_mailboxesN)r$r9r:r7r=r]r^r_rrrrr[s  r[c@s4eZdZdZeddZeddZeddZdS) Addressr\cCs|djdkr|djSdS)Nrgroup)r7 display_name)rrrrrb5szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djS)Nrmailboxzinvalid-mailbox)r7r^)rrrrr^:s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djS)Nrrczinvalid-mailbox)r7r_)rrrrr_Bs   zAddress.all_mailboxesN)r$r9r:r7r=rbr^r_rrrrr`1s  r`c@s(eZdZdZeddZeddZdS) MailboxListz mailbox-listcCsdd|DS)NcSsg|]}|jdkr|qS)rc)r7)rrrrrrCPsz)MailboxList.mailboxes..r)rrrrr^NszMailboxList.mailboxescCsdd|DS)NcSsg|]}|jdkr|qS)rcinvalid-mailbox)rcre)r7)rrrrrrCTsz-MailboxList.all_mailboxes..r)rrrrr_RszMailboxList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrdJs rdc@s(eZdZdZeddZeddZdS) GroupListz group-listcCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r^)rrrrr^\szGroupList.mailboxescCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r_)rrrrr_bszGroupList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrfXs rfc@s4eZdZdZeddZeddZeddZdS) GroupracCs|djdkrgS|djS)Nz group-list)r7r^)rrrrr^mszGroup.mailboxescCs|djdkrgS|djS)Nrhz group-list)r7r_)rrrrr_sszGroup.all_mailboxescCs |djS)Nr)rb)rrrrrbyszGroup.display_nameN)r$r9r:r7r=r^r_rbrrrrrgis  rgc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) NameAddrz name-addrcCst|dkrdS|djS)Nr)lenrb)rrrrrbs zNameAddr.display_namecCs |djS)Nrj) local_part)rrrrrmszNameAddr.local_partcCs |djS)Nrjrl)domain)rrrrrnszNameAddr.domaincCs |djS)Nrjrl)route)rrrrroszNameAddr.routecCs |djS)Nrjrl) addr_spec)rrrrrpszNameAddr.addr_specN) r$r9r:r7r=rbrmrnrorprrrrri~s     ric@s@eZdZdZeddZeddZeddZedd Zd S) AngleAddrz angle-addrcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rm)rrrrrrms  zAngleAddr.local_partcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rn)rrrrrrns  zAngleAddr.domaincCs"x|D]}|jdkr|jSqWdS)Nz obs-route)r7domains)rrrrrros  zAngleAddr.routecCs<x6|D]*}|jdkr|jr |jSt|j|jSqWdSdS)Nz addr-specz<>)r7rmrpr)rrrrrrps   zAngleAddr.addr_specN) r$r9r:r7r=rmrnrorprrrrrqs    rqc@seZdZdZeddZdS)ObsRoutez obs-routecCsdd|DS)NcSsg|]}|jdkr|jqS)rn)r7rn)rrrrrrCsz$ObsRoute.domains..r)rrrrrrszObsRoute.domainsN)r$r9r:r7r=rrrrrrrssrsc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) MailboxrccCs|djdkr|djSdS)Nrz name-addr)r7rb)rrrrrbszMailbox.display_namecCs |djS)Nr)rm)rrrrrmszMailbox.local_partcCs |djS)Nr)rn)rrrrrnszMailbox.domaincCs|djdkr|djSdS)Nrz name-addr)r7ro)rrrrrosz Mailbox.routecCs |djS)Nr)rp)rrrrrpszMailbox.addr_specN) r$r9r:r7r=rbrmrnrorprrrrrts     rtc@s,eZdZdZeddZeZZZZ dS)InvalidMailboxzinvalid-mailboxcCsdS)Nr)rrrrrbszInvalidMailbox.display_nameN) r$r9r:r7r=rbrmrnrorprrrrrus rucs(eZdZdZdZefddZZS)DomainrnFcsdjtjjS)Nr)r!rrsplit)r)rrrrnsz Domain.domain)r$r9r:r7r)r=rnr>rr)rrrvsrvc@seZdZdZdS)DotAtomzdot-atomN)r$r9r:r7rrrrrxsrxc@seZdZdZdZdS) DotAtomTextz dot-atom-textTN)r$r9r:r7r)rrrrrysryc@sDeZdZdZdZeddZeddZeddZed d Z d S) AddrSpecz addr-specFcCs |djS)Nr)rm)rrrrrmszAddrSpec.local_partcCst|dkrdS|djS)Nrjrl)rkrn)rrrrrns zAddrSpec.domaincCs<t|dkr|djS|djj|dj|djjS)Nr{rrjrh)rkrrstriplstrip)rrrrrs  zAddrSpec.valuecCsLt|j}t|t|tkr*t|j}n|j}|jdk rH|d|jS|S)N@)setrmrk DOT_ATOM_ENDSrrn)rZnamesetZlprrrrps   zAddrSpec.addr_specN) r$r9r:r7r)r=rmrnrrprrrrrzs    rzc@seZdZdZdZdS) ObsLocalPartzobs-local-partFN)r$r9r:r7r)rrrrr srcs4eZdZdZdZeddZefddZZS) DisplayNamez display-nameFcCst|}|djdkr"|jdn*|ddjdkrLt|ddd|d<|djdkrd|jn*|ddjdkrt|ddd|d <|jS) NrrJrjrlrlrlrlrlrl)rr7popr)rrTrrrrb+s  zDisplayName.display_namecsd}|jrd}nx|D]}|jdkrd}qW|rd}}|djdksX|ddjdkr\d}|d jdks||d d jdkrd}|t|j|StjSdS) NFTz quoted-stringrrrJr@rjrlrlrl)rr7rrbrr)rrYrZpreZpost)rrrr:s    zDisplayName.value) r$r9r:r7r<r=rbrr>rr)rrr&s rc@s,eZdZdZdZeddZeddZdS) LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrz quoted-string)r7rUr)rrrrrSs 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) NFrrJdotrjrlrlrlrlrl)DOTr7r isinstancerSr)rrTZlastZ last_is_tltokZis_tlrrrrmZs$   zLocalPart.local_partN)r$r9r:r7r)r=rrmrrrrrNs rcs4eZdZdZdZefddZeddZZS) DomainLiteralzdomain-literalFcsdjtjjS)Nr)r!rrrw)r)rrrrnwszDomainLiteral.domaincCs"x|D]}|jdkr|jSqWdS)Nptext)r7r)rrrrrip{s  zDomainLiteral.ip) r$r9r:r7r)r=rnrr>rr)rrrrsrc@seZdZdZdZdZdS) MIMEVersionz mime-versionN)r$r9r:r7majorminorrrrrrsrc@s4eZdZdZdZdZdZeddZeddZ dS) Parameter parameterFzus-asciicCs|jr|djSdS)Nrjr) sectionednumber)rrrrsection_numberszParameter.section_numbercCsbx\|D]T}|jdkr|jS|jdkrx4|D],}|jdkr*x|D]}|jdkr>|jSq>Wq*WqWdS)Nrz quoted-stringzbare-quoted-stringr)r7rV)rr.rrr param_values       zParameter.param_valueN) r$r9r:r7rextendedrPr=rrrrrrrs  rc@seZdZdZdS)InvalidParameterzinvalid-parameterN)r$r9r:r7rrrrrsrc@seZdZdZeddZdS) Attribute attributecCs$x|D]}|jjdr|jSqWdS)Nattrtext)r7endswithr)rr.rrrrVs  zAttribute.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@seZdZdZdZdS)SectionsectionN)r$r9r:r7rrrrrrsrc@seZdZdZeddZdS)ValuercCs2|d}|jdkr|d}|jjdr,|jS|jS)NrrJrj quoted-stringrextended-attribute)rrr)r7rrVr)rr.rrrrVs zValue.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@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)keyrjz.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)encodingsurrogateescapezus-asciir)rr7rrstriprSritemssortedrrPrrkrrInvalidHeaderDefectrurllibparseZunquote_to_bytesUnicodeEncodeErrorZunquotedecode LookupErrorr_has_surrogatesUndecodableBytesDefectr!) rparamsr.namepartsZ first_paramrPZ value_partsirparamrrrrrsZ         zMimeParameters.paramscCsXg}x8|jD].\}}|r0|jdj|t|q |j|q Wdj|}|rTd|SdS)Nz{}={}z; r@r)rrSr#rr!)rrrrrrrr"s zMimeParameters.__str__N)r$r9r:r7r;r=rr"rrrrrs Frc@seZdZdZeddZdS)ParameterizedHeaderValueFcCs&x t|D]}|jdkr |jSq WiS)Nzmime-parameters)reversedr7r)rr.rrrr%s  zParameterizedHeaderValue.paramsN)r$r9r:r;r=rrrrrrsrc@seZdZdZdZdZdZdS) ContentTypez content-typeFtextZplainN)r$r9r:r7r)maintypesubtyperrrrr-src@seZdZdZdZdZdS)ContentDispositionzcontent-dispositionFN)r$r9r:r7r)content_dispositionrrrrr5src@seZdZdZdZdZdS)ContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r$r9r:r7r)rOrrrrr<src@seZdZdZdZdS) HeaderLabelz header-labelFN)r$r9r:r7r)rrrrrCsrc@seZdZdZdS)HeaderheaderN)r$r9r:r7rrrrrIsrcsreZdZdZdZdZfddZfddZddZe dd Z dfd d Z d dZ e ddZ ddZZS)TerminalTcstj||}||_g|_|S)N)r__new__r7r)clsrr7r)rrrrXszTerminal.__new__csdj|jjtjS)Nz{}({}))r#rr$rr%)r)rrrr%^szTerminal.__repr__cCst|jjd|jdS)N/)r3rr$r7)rrrrr5aszTerminal.pprintcCs t|jS)N)listr)rrrrr&dszTerminal.all_defectsrcs2dj||jj|jtj|js"dn dj|jgS)Nz {}{}/{}({}){}rz {})r#rr$r7rr%r)rr2)rrrr6hs z Terminal._ppcCsdS)Nr)rrrrpop_trailing_wsqszTerminal.pop_trailing_wscCsgS)Nr)rrrrr-uszTerminal.commentscCst||jfS)N)rr7)rrrr__getnewargs__yszTerminal.__getnewargs__)r)r$r9r:r)r<r;rr%r5r=r&r6rr-rr>rr)rrrRs     rc@s eZdZeddZddZdS)WhiteSpaceTerminalcCsdS)Nr@r)rrrrrszWhiteSpaceTerminal.valuecCsdS)NTr)rrrrr(sz!WhiteSpaceTerminal.startswith_fwsN)r$r9r:r=rr(rrrrr}s rc@s eZdZeddZddZdS) ValueTerminalcCs|S)Nr)rrrrrszValueTerminal.valuecCsdS)NFr)rrrrr(szValueTerminal.startswith_fwsN)r$r9r:r=rr(rrrrrs rc@s eZdZeddZddZdS)EWWhiteSpaceTerminalcCsdS)Nrr)rrrrrszEWWhiteSpaceTerminal.valuecCsdS)Nrr)rrrrr"szEWWhiteSpaceTerminal.__str__N)r$r9r:r=rr"rrrrrs rr,zlist-separatorr~zroute-component-markerz([{}]+)rz[^{}]+rz\\]z\]z[\x00-\x20\x7F]cCs>t|}|r|jjtj|tj|r:|jjtjddS)Nz*Non-ASCII characters found in header token)_non_printable_finderrrSrZNonPrintableDefectrrr)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)NrjFrTr) _wsp_splitterrangerkrSr!)rendcharsZfragment remainderZvcharsescapehad_qpposrrr_get_ptext_to_endcharss$   rcCs.|j}t|dt|t|d}||fS)Nfws)r}rrk)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 {}rhz?=rjrrzwhitespace inside encoded wordz!encoded word format invalid: '{}'vtext)rN startswithrHeaderParseErrorr#rwr!rkrrrSrrO_ewr ValueErrorrPrQr,WSPrrrr) rewrrZremstrrestrrPrQrr.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=?Trjrz&missing whitespace before encoded wordFrhz encoded-wordrrrlrlrl)rDrrrSrrrrrkr7rrrrrrr!)rrEr.Zhave_wsrrrrrrget_unstructured!s:          rcCs*t|d\}}}t|d}t|||fS)Nz()r)rrr)rr_rrr get_qp_ctextYs  rcCs*t|d\}}}t|d}t|||fS)Nr r)rrr)rrrrrr get_qcontentjs  rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nzexpected atext but found '{}'atext)_non_atom_end_matcherrrr#rarkrr)rmrrrr get_atextys  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 '{}'rjrhz=?z!encoded word inside quoted stringz"end of header inside quoted string) rrr#rWrrSrrrrr)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 '{}'rjrZzend of header inside comment) rrr#rXrr get_commentrrSrr)rrAr.rrrrs"      rcCsTt}xD|rJ|dtkrJ|dtkr2t|\}}n t|\}}|j|qW||fS)Nr)rI CFWS_LEADERrrrrS)rrJr.rrrget_cfwss  rcCspt}|r,|dtkr,t|\}}|j|t|\}}|j||rh|dtkrht|\}}|j|||fS)Nr)rRrrrSr)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=?) rKrrrS ATOM_ENDSrrr#rrr)rrLr.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 rjz4expected atom at end of dot-atom-text but found '{}'rl)ryrrrr#rrSr)rZ dot_atom_textr.rrrget_dot_atom_texts     rc Cst}|dtkr(t|\}}|j||jdrhyt|\}}Wqttjk rdt|\}}YqtXn t|\}}|j||r|dtkrt|\}}|j|||fS)Nrz=?) rxrrrSrrrrr)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'rjzcomment found without atom) rFrrSrrrr PHRASE_ENDSrObsoleteHeaderDefectrr)rrGr.rrr get_phraseIs.          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 '{}'rzinvalid-obs-local-partzsB               r cCst}|dtkr(t|\}}|j|| s:|ddkrJtjdj||jtdd|dd}|ddkr|jtdd|jjtj d|dd}||fSyt |\}}Wnztjk r2y"t |\}}|jjtj d Wn(tjk rtjd j|YnX|j|t |\}}YnX|j||r`|ddkr`|dd}n|jjtj d |jtdd|r|dtkrt|\}}|j|||fS) Nrzangle-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) rqrrrSrrr#rrrrr r)rZ angle_addrr.rrrget_angle_addrgsJ                r cCs<t}t|\}}|j|dd|jdd|_||fS)N)rrr,r)rrbr.rrrget_display_names  rcCst}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 ) rirrrrr#rrrSr )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)rrrrrr szget_mailbox..zinvalid-mailbox) rtrrrrr#anyr&r7rS)rrcr.rrr get_mailboxs  rcCsht}xX|r^|d|kr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)Nrzmisplaced-specialrj)rurrSrr)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-listrrjzinvalid-mailboxrl)rdrrSrrrrrrrrr7r,r)rZ mailbox_listr.rrcrrrget_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) rfrrSrrrrrrkr_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-terminatorrjrzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rgrrrr#rSrrrrrr)rrar.rrr get_groupGs2            rcCsxt}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnX|j|||fS)Nzexpected address but found '{}')r`rrrrr#rS)rr\r.rrr get_addresses 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-listrjzinvalid-mailboxzlist-separatorrl)r[rrSrrrrrrrr`rr7r,r)rZ address_listr.errrrcrrrget_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 rjz1Expected 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)rrrSrHeaderMissingRequiredValuerrisdigitrr#rintrr)rZ mime_versionr.rrrrparse_mime_versionsv                        rcCsht}xX|r^|ddkr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)Nrrzmisplaced-specialrj)rrrSrr)rZinvalid_parameterr.rrrget_invalid_parameters   rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nzexpected ttext but found '{}'ttext)_non_token_end_matcherrrr#rarkrr)rrr rrr get_ttexts   r"cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rMrrrS 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#rarkrr)rrrrrr get_attrtext@s   r&cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rrrrSATTRIBUTE_ENDSrrr#r&)rrr.rrr get_attributeSs        r(cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nz)expected extended attrtext but found {!r}zextended-attrtext)#_non_extended_attribute_end_matcherrrr#rarkrr)rrrrrrget_extended_attrtextjs  r*cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rrrrSEXTENDED_ATTRIBUTE_ENDSrrr#r*)rrr.rrrget_extended_attribute|s       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-markerrjz$Expected section number but found {}r0z'section number has an invalid leading 0r) rrrr#rSrrrZInvalidHeaderErrorrr)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,rS)rvrr.rrr get_values       r1c 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-markerrj=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(rSrrrr#r/rrrrrrrrVrr&r*r7r1rrPrQrrrr) rrr.rrZappendtoZqstringZ inner_valueZ semi_validrtr0rrr get_parameters                                             r5cCsht}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}rjzinvalid-parameterz)parameter with invalid trailing text {!r}zparameter-separatorrl)rr5rSrrrrrrrr#r7r,r)rZmime_parametersr.rrrrrrparse_mime_parametersQ sD                 r6cCsxX|rX|ddkrX|dtkr@|jt|dd|dd}qt|\}}|j|qW|sbdS|jtdd|jt|dddS)Nrrzmisplaced-specialrjzparameter-separator)rrSrrr6)Z tokenlistrr.rrr_find_mime_parameters s  r7cCst}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-separatorrjz'Expected content subtype but found {!r}rz.z unknown-8bitTzmime-parameters)r/rrlrlrlrlrlrl)Zmax_line_lengthfloatutf8rrrrr7 SPECIALSNL isdisjointNLSETrrrr&_fold_mime_parametersr)r;r1lineseprkr=rSr8 _fold_as_ewr<r(insertr!)Z parse_treer/maxlenrr<last_ewr>Z want_encodingZend_ew_not_allowedrr*tstrrPZ encoded_partnewlineZnewpartsrrrr0" s                 r0cCs|dk r<|rFs           C  "   !($ V +            *8" &'/'&).9%>D 49/j7