U e5dϡ @sddlZddlZddlZddlmZddlmZddlmZ ddlm Z ddlm Z e dZ e e dBZe d Zee BZee d Zee d Zee d Be d Zee BZee d BZee BZee dZddZedejejBZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#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/Gd6d7d7eZ0Gd8d9d9eZ1Gd:d;d;eZ2Gdd?d?eZ4Gd@dAdAeZ5GdBdCdCeZ6GdDdEdEeZ7GdFdGdGeZ8GdHdIdIeZ9GdJdKdKe!Z:GdLdMdMeZ;GdNdOdOeZGdTdUdUe>Z?GdVdWdWeZ@GdXdYdYeZAGdZd[d[eZBGd\d]d]eZCGd^d_d_eZDGd`dadaeDZEGdbdcdceDZFGdddedeeZGGdfdgdgeZHGdhdidieZIGdjdkdkeIZJGdldmdmeJZKGdndodoeZLGdpdqdqeMZNGdrdsdseNZOGdtdudueNZPGdvdwdweOZQGdxdydye jRZSePd dzZTePd{d|ZUePd}d~ZVedWdXe jYZZedWe[dXej\Z]edj^Z_edWe[dXej\Z`edWe[dXej\ZaedWe[dXej\ZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddZddZddZdd„ZddĄZddƄZddȄZddʄZdd̄Zdd΄ZddЄZdd҄ZddԄZddքZdd؄ZddڄZdd܄ZddބZddZddZddZddZddZddZddZddZddZddZddZddZdS)N) hexdigits) itemgetter)_encoded_words)errors)utilsz (z ()<>@,:;.\"[].z."(z/?=z*'%%cCs dt|dddddS)N"\\\z\")strreplacevaluer2/usr/lib64/python3.8/email/_header_value_parser.py quote_string`srz =\? # literal =? [^?]* # charset \? # literal ? [qQbB] # literal 'q' or 'b', case insensitive \? # literal ? .*? # encoded word \?= # literal ?= cseZdZdZdZdZfddZddZfddZe d d Z e d d Z d dZ e ddZ e ddZddZdddZdddZdddZZS) TokenListNTcstj||g|_dSN)super__init__defects)selfargskw __class__rrryszTokenList.__init__cCsddd|DS)Ncss|]}t|VqdSrr .0xrrr ~sz$TokenList.__str__..joinrrrr__str__}szTokenList.__str__csd|jjtSNz{}({})formatr__name__r__repr__r&rrrr,s zTokenList.__repr__cCsddd|DS)Nrcss|]}|jr|jVqdSrrr rrrr#sz"TokenList.value..r$r&rrrrszTokenList.valuecCstdd|D|jS)Ncss|] }|jVqdSr) all_defectsr rrrr#sz(TokenList.all_defects..)sumrr&rrrr-szTokenList.all_defectscCs |dSNr)startswith_fwsr&rrrr0szTokenList.startswith_fwscCstdd|DS)Ncss|] }|jVqdSr) as_ew_allowed)r!partrrrr#sz*TokenList.as_ew_allowed..)allr&rrrr1szTokenList.as_ew_allowedcCsg}|D]}||jq|Sr)extendcomments)rr5tokenrrrr5szTokenList.commentscCs t||dS)Npolicy)_refold_parse_treerr8rrrfoldszTokenList.foldrcCst|j|ddS)Nindent)printppstrrr=rrrpprintszTokenList.pprintcCsd|j|dS)N r<)r%_ppr@rrrr?szTokenList.ppstrccszd||jj|jV|D]4}t|ds:|d|Vq||dEdHq|jrdd|j}nd}d||VdS)Nz{}{}/{}(rCz* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r*rr+ token_typehasattrrCr)rr=r6ZextrarrrrCs  z TokenList._pp)r)r)r)r+ __module__ __qualname__rDsyntactic_breakew_combine_allowedrr'r,propertyrr-r0r1r5r;rAr?rC __classcell__rrrrrss&        rc@s$eZdZeddZeddZdS)WhiteSpaceTokenListcCsdSN rr&rrrrszWhiteSpaceTokenList.valuecCsdd|DS)NcSsg|]}|jdkr|jqS)comment)rDcontentr rrr s z0WhiteSpaceTokenList.comments..rr&rrrr5szWhiteSpaceTokenList.commentsN)r+rFrGrJrr5rrrrrLs rLc@seZdZdZdS)UnstructuredTokenList unstructuredNr+rFrGrDrrrrrRsrRc@seZdZdZdS)PhrasephraseNrTrrrrrUsrUc@seZdZdZdS)WordZwordNrTrrrrrWsrWc@seZdZdZdS)CFWSListcfwsNrTrrrrrXsrXc@seZdZdZdS)AtomatomNrTrrrrrZsrZc@seZdZdZdZdS)Tokenr6FN)r+rFrGrDZ encode_as_ewrrrrr\sr\c@seZdZdZdZdZdZdS) EncodedWord encoded-wordN)r+rFrGrDctecharsetlangrrrrr]sr]c@s4eZdZdZeddZeddZeddZdS) QuotedString quoted-stringcCs"|D]}|jdkr|jSqdSNbare-quoted-stringrDrrr"rrrrPs zQuotedString.contentcCs>g}|D]*}|jdkr&|t|q||jqd|S)Nrer)rDappendr rr%)rresr"rrr quoted_values  zQuotedString.quoted_valuecCs"|D]}|jdkr|jSqdSrdrfrr6rrrstripped_values zQuotedString.stripped_valueN)r+rFrGrDrJrPrjrlrrrrrbs  rbc@s$eZdZdZddZeddZdS)BareQuotedStringrecCstddd|DS)Nrcss|]}t|VqdSrrr rrrr#sz+BareQuotedString.__str__..)rr%r&rrrr'szBareQuotedString.__str__cCsddd|DS)Nrcss|]}t|VqdSrrr rrrr#sz)BareQuotedString.value..r$r&rrrrszBareQuotedString.valueN)r+rFrGrDr'rJrrrrrrmsrmc@s8eZdZdZddZddZeddZedd Zd S) CommentrOcs(dtdgfddDdgggS)Nrrcsg|]}|qSr)quoter r&rrrQsz#Comment.__str__..))r%r.r&rr&rr' szComment.__str__cCs2|jdkrt|St|ddddddS)NrOr r rz\(rpz\))rDr r)rrrrrros z Comment.quotecCsddd|DS)Nrcss|]}t|VqdSrrr rrrr#sz"Comment.content..r$r&rrrrPszComment.contentcCs|jgSr)rPr&rrrr5szComment.commentsN) r+rFrGrDr'rorJrPr5rrrrrns rnc@s4eZdZdZeddZeddZeddZdS) AddressListz address-listcCsdd|DS)NcSsg|]}|jdkr|qS)addressrDr rrrrQ's z)AddressList.addresses..rr&rrr addresses%szAddressList.addressescCstdd|DgS)Ncss|]}|jdkr|jVqdSrrNrD mailboxesr rrrr#+s z(AddressList.mailboxes..r.r&rrrrw)s zAddressList.mailboxescCstdd|DgS)Ncss|]}|jdkr|jVqdSrurD all_mailboxesr rrrr#0s z,AddressList.all_mailboxes..rxr&rrrrz.s zAddressList.all_mailboxesN)r+rFrGrDrJrtrwrzrrrrrq!s  rqc@s4eZdZdZeddZeddZeddZdS) AddressrrcCs|djdkr|djSdS)NrgrouprD display_namer&rrrr~8szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djSNrmailboxinvalid-mailboxrvr&rrrrw=s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djSrryr&rrrrzEs   zAddress.all_mailboxesN)r+rFrGrDrJr~rwrzrrrrr{4s  r{c@s(eZdZdZeddZeddZdS) MailboxList mailbox-listcCsdd|DS)NcSsg|]}|jdkr|qS)rrsr rrrrQSs z)MailboxList.mailboxes..rr&rrrrwQszMailboxList.mailboxescCsdd|DS)NcSsg|]}|jdkr|qS))rrrsr rrrrQWs z-MailboxList.all_mailboxes..rr&rrrrzUszMailboxList.all_mailboxesNr+rFrGrDrJrwrzrrrrrMs  rc@s(eZdZdZeddZeddZdS) GroupList group-listcCs |r|djdkrgS|djSNrrrvr&rrrrw_szGroupList.mailboxescCs |r|djdkrgS|djSrryr&rrrrzeszGroupList.all_mailboxesNrrrrrr[s  rc@s4eZdZdZeddZeddZeddZdS) Groupr|cCs|djdkrgS|djSNrrvr&rrrrwpszGroup.mailboxescCs|djdkrgS|djSrryr&rrrrzvszGroup.all_mailboxescCs |djSr/)r~r&rrrr~|szGroup.display_nameN)r+rFrGrDrJrwrzr~rrrrrls  rc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) NameAddr name-addrcCst|dkrdS|djSNr)lenr~r&rrrr~s zNameAddr.display_namecCs |djSN local_partr&rrrrszNameAddr.local_partcCs |djSrdomainr&rrrrszNameAddr.domaincCs |djSr)router&rrrrszNameAddr.routecCs |djSr addr_specr&rrrrszNameAddr.addr_specN r+rFrGrDrJr~rrrrrrrrrs    rc@s@eZdZdZeddZeddZeddZedd Zd S) AngleAddrz angle-addrcCs"|D]}|jdkr|jSqdSN addr-spec)rDrrgrrrrs zAngleAddr.local_partcCs"|D]}|jdkr|jSqdSrrDrrgrrrrs zAngleAddr.domaincCs"|D]}|jdkr|jSqdS)N obs-route)rDdomainsrgrrrrs zAngleAddr.routecCs<|D]2}|jdkr|jr"|jSt|j|jSqdS)Nrz<>)rDrrrrgrrrrs   zAngleAddr.addr_specN) r+rFrGrDrJrrrrrrrrrs   rc@seZdZdZeddZdS)ObsRoutercCsdd|DS)NcSsg|]}|jdkr|jqSrrr rrrrQs z$ObsRoute.domains..rr&rrrrszObsRoute.domainsN)r+rFrGrDrJrrrrrrsrc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) MailboxrcCs|djdkr|djSdSNrrr}r&rrrr~szMailbox.display_namecCs |djSr/rr&rrrrszMailbox.local_partcCs |djSr/rr&rrrrszMailbox.domaincCs|djdkr|djSdSr)rDrr&rrrrsz Mailbox.routecCs |djSr/rr&rrrrszMailbox.addr_specNrrrrrrs    rc@s,eZdZdZeddZeZZZZ dS)InvalidMailboxrcCsdSrrr&rrrr~szInvalidMailbox.display_nameNrrrrrrs rcs(eZdZdZdZefddZZS)DomainrFcsdtjSNrr%rrsplitr&rrrrsz Domain.domain)r+rFrGrDr1rJrrKrrrrrsrc@seZdZdZdS)DotAtomdot-atomNrTrrrrrsrc@seZdZdZdZdS) DotAtomTextz dot-atom-textTNr+rFrGrDr1rrrrrsrc@seZdZdZdZdS) NoFoldLiteralzno-fold-literalFNrrrrrrsrc@sDeZdZdZdZeddZeddZeddZed d Z d S) AddrSpecrFcCs |djSr/rr&rrrr szAddrSpec.local_partcCst|dkrdS|djS)Nr)rrr&rrrrs zAddrSpec.domaincCs<t|dkr|djS|dj|dj|djS)Nrrrr)rrrstriplstripr&rrrrs  zAddrSpec.valuecCsLt|j}t|t|tkr*t|j}n|j}|jdk rH|d|jS|S)N@)setrr DOT_ATOM_ENDSrr)rZnamesetZlprrrrs   zAddrSpec.addr_specN) r+rFrGrDr1rJrrrrrrrrrs   rc@seZdZdZdZdS) ObsLocalPartzobs-local-partFNrrrrrr&srcs4eZdZdZdZeddZefddZZS) DisplayNamez display-nameFcCst|}t|dkr|jS|djdkr4|dn*|ddjdkr^t|ddd|d<|djdkrv|n*|ddjdkrt|ddd|d<|jS)NrrYrr)rrrrDpop)rrirrrr~1s   zDisplayName.display_namecsd}|jrd}n|D]}|jdkrd}qt|dkr|rd}}|djdks`|ddjdkrdd}|djdks|ddjdkrd}|t|j|StjSdS) NFTrcrrrYrNr)rrDrrr~rr)rror"ZpreZpostrrrrBs   zDisplayName.value) r+rFrGrDrIrJr~rrKrrrrr,s  rc@s,eZdZdZdZeddZeddZdS) LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrrc)rDrjrr&rrrr[s zLocalPart.valuecCstg}t}d}|dtgD]}|jdkr,q|r\|jdkr\|djdkr\t|dd|d<t|t}|r|jdkr|djdkr|t|ddn |||d}|}qt|dd}|jS)NFrrYdotrr)DOTrDr isinstancerhr)rriZlastZ last_is_tltokZis_tlrrrrbs(     zLocalPart.local_partN)r+rFrGrDr1rJrrrrrrrVs  rcs4eZdZdZdZefddZeddZZS) DomainLiteralzdomain-literalFcsdtjSrrr&rrrrszDomainLiteral.domaincCs"|D]}|jdkr|jSqdS)Nptextrfrgrrrips zDomainLiteral.ip) r+rFrGrDr1rJrrrKrrrrrzs rc@seZdZdZdZdZdS) MIMEVersionz mime-versionN)r+rFrGrDmajorminorrrrrrsrc@s4eZdZdZdZdZdZeddZeddZ dS) Parameter parameterFus-asciicCs|jr|djSdSr) sectionednumberr&rrrsection_numberszParameter.section_numbercCsf|D]\}|jdkr|jS|jdkr|D]4}|jdkr*|D] }|jdkr<|jSqrr+rDr&rrrrAuszTerminal.pprintcCs t|jSr)listrr&rrrr-xszTerminal.all_defectsrc s2d||jj|jt|js"dn d|jgS)Nz {}{}/{}({}){}rz {})r*rr+rDrr,rr@rrrrC|sz Terminal._ppcCsdSrrr&rrrpop_trailing_wsszTerminal.pop_trailing_wscCsgSrrr&rrrr5szTerminal.commentscCst||jfSr)r rDr&rrr__getnewargs__szTerminal.__getnewargs__)r)r+rFrGr1rIrHrr,rArJr-rCrr5rrKrrrrrfs     rc@s eZdZeddZddZdS)WhiteSpaceTerminalcCsdSrMrr&rrrrszWhiteSpaceTerminal.valuecCsdS)NTrr&rrrr0sz!WhiteSpaceTerminal.startswith_fwsNr+rFrGrJrr0rrrrrs rc@s eZdZeddZddZdS) ValueTerminalcCs|Srrr&rrrrszValueTerminal.valuecCsdS)NFrr&rrrr0szValueTerminal.startswith_fwsNrrrrrrs rc@s eZdZeddZddZdS)EWWhiteSpaceTerminalcCsdSrrr&rrrrszEWWhiteSpaceTerminal.valuecCsdSrrr&rrrr'szEWWhiteSpaceTerminal.__str__N)r+rFrGrJrr'rrrrrs rc@s eZdZdS)_InvalidEwErrorN)r+rFrGrrrrrsrr,list-separatorrzroute-component-markerz([{}]+)rz[^{}]+z[\x00-\x20\x7F]cCs>t|}|r|jt|t|r:|jtddS)Nz*Non-ASCII characters found in header token)_non_printable_finderrrhrZNonPrintableDefectrrr)xtextZnon_printablesrrr_validate_xtexts  r cCst|d^}}g}d}d}tt|D]L}||dkrJ|rDd}d}nd}q&|rTd}n|||krdq||||q&|d}d|d||dg||fS)NrFr Tr) _wsp_splitterrangerrhr%)rendcharsZfragment remainderZvcharsescapehad_qpposrrr_get_ptext_to_endcharss$   rcCs.|}t|dt|t|d}||fS)Nfws)rrr)rZnewvaluerrrrget_fwssrc Cst}|ds td||dddd^}}||ddkrXtd|d|}t|dkr|dtkr|dtkr| ddkr|dd^}}|d|}t|dkr|j t d ||_ d|}ztd|d\}}}} Wn*ttfk r*td |j YnX||_||_|j | |r|dtkrrt|\} }| | qDt|d^} }t| d } t| | | d|}qD|r|dtkr|j t d ||fS) N=?z"expected encoded word but found {}rz?=rrr?zwhitespace inside encoded wordz!encoded word format invalid: '{}'vtextz.missing trailing whitespace after encoded-word)r] startswithrHeaderParseErrorr*rr%rrcountrrhrr__ewr ValueErrorKeyErrorrr`rar4WSPrr rr ) rZewrrZremstrrestrr`rarr6charsrrrrget_encoded_wordsd                r!cCsFt}|rB|dtkr0t|\}}||qd}|drzt|\}}Wn,tk rfd}Yntjk rzYnrXd}t |dkr|dj dkr|j t dd}|rt |dkr|d j d krt |dd|d<||qt|d^}}|rt|r|d^}}t|d }t|||d |}q|S) NrTrFrrz&missing whitespace before encoded wordrr^rr)rRrrrhrr!rrrrrDrrrr rfc2047_matchersearch partitionrr r%)rrSr6valid_ewZhave_wsrrrrrrget_unstructured?sJ          r'cCs*t|d\}}}t|d}t|||fS)Nz()r)rrr rr_rrr get_qp_ctexts  r*cCs*t|d\}}}t|d}t|||fS)Nr r)rrr r(rrr get_qcontents  r+cCsNt|}|std||}|t|d}t|d}t|||fS)Nzexpected atext but found '{}'atext)_non_atom_end_matcherrrr*r|rrr )rmr,rrr get_atexts r/cCsr|ddkrtd|t}|dd}|rT|ddkrTt|\}}|||rB|ddkrB|dtkrt|\}}n|dddkr*d}z&t|\}}|j t dd }Wn"tjk rt|\}}YnX|r6t |dkr6|d j d kr6|d j d kr6t |d d |d <n t|\}}||qT|sb|j t d||fS||ddfS)Nrr zexpected '"' but found '{}'rrrFz!encoded word inside quoted stringTrrr"r^z"end of header inside quoted string)rrr*rmr+rhrrr!rrrrDr)rZbare_quoted_stringr6r&rrrget_bare_quoted_stringsL            r0cCs|r |ddkr td|t}|dd}|r|ddkr|dtkr\t|\}}n&|ddkrvt|\}}n t|\}}||q2|s|j t d||fS||ddfS)Nrrzexpected '(' but found '{}'rrpzend of header inside comment) rrr*rnrr get_commentr*rhrr)rrOr6rrrr1s&      r1cCsPt}|rH|dtkrH|dtkr0t|\}}n t|\}}||q||fSr/)rX CFWS_LEADERrrr1rh)rrYr6rrrget_cfwss   r3cCspt}|r,|dtkr,t|\}}||t|\}}|||rh|dtkrht|\}}||||fSr/)rbr2r3rhr0)rZ quoted_stringr6rrrget_quoted_strings      r4cCst}|r,|dtkr,t|\}}|||rL|dtkrLtd||drzt |\}}Wqtjk rt |\}}YqXn t |\}}|||r|dtkrt|\}}||||fS)Nrzexpected atom but found '{}'r) rZr2r3rh ATOM_ENDSrrr*rr!r/)rr[r6rrrget_atoms&       r6cCst}|r|dtkr&td||rt|dtkrtt|\}}|||r&|ddkr&|t|dd}q&|dtkrtdd|||fS)Nrz8expected atom at a start of dot-atom-text but found '{}'rrrz4expected atom at end of dot-atom-text but found '{}')rr5rrr*r/rhr)rZ dot_atom_textr6rrrget_dot_atom_text0s     r7cCst}|dtkr(t|\}}|||drhzt|\}}Wqttjk rdt|\}}YqtXn t|\}}|||r|dtkrt|\}}||||fS)Nrr) rr2r3rhrr!rrr7)rZdot_atomr6rrr get_dot_atomCs        r8cCs|dtkrt|\}}nd}|s,td|ddkrFt|\}}n*|dtkrdtd|n t|\}}|dk r|g|dd<||fS)Nrz5Expected 'atom' or 'quoted-string' but found nothing.r z1Expected 'atom' or 'quoted-string' but found '{}')r2r3rrr4SPECIALSr*r6)rleaderr6rrrget_word\s"    r;cCst}zt|\}}||Wn(tjk rH|jtdYnX|r|dtkr|ddkr|t|jt d|dd}qJzt|\}}WnDtjk r|dt krt |\}}|jt dnYnX||qJ||fS)Nzphrase does not start with wordrrzperiod in 'phrase'rzcomment found without atom) rUr;rhrrrr PHRASE_ENDSrObsoleteHeaderDefectr2r3)rrVr6rrr get_phrase~s4           r>c Csvt}d}|dtkr"t|\}}|s6td|zt|\}}Wn^tjk rzt|\}}Wn6tjk r|ddkr|dtkrt }YnXYnX|dk r|g|dd<| ||r4|ddks|dtkr4t t ||\}}|j dkr|j tdn|j td||d<z|jdWn(tk rl|j tdYnX||fS) Nrz"expected local-part but found '{}'r invalid-obs-local-partz|ddkr>|t|dd}|sq>|dtkrt|\}}|||ddkr|tt |dd\}}||q|sNtd|ddkrltd||t dd ||ddfS) Nrrrrz(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) rr2r3rh ListSeparatorrrr*RouteComponentMarkerrMr)rZ obs_router6rrr get_obs_routessF               rSc Cst}|dtkr(t|\}}|||r8|ddkrHtd||tdd|dd}|ddkr|tdd|jt d|dd}||fSzt |\}}Wnztjk r0z"t |\}}|jt d Wn(tjk rtd |YnX||t |\}}YnX|||r^|ddkr^|dd}n|jt d |tdd|r|dtkrt|\}}||||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) rr2r3rhrrr*rrrrOrSr=)rZ angle_addrr6rrrget_angle_addrsT                rVcCs<t}t|\}}||dd|jdd|_||fSr)rr>r4r)rr~r6rrrget_display_names  rWcCst}d}|dtkr6t|\}}|s6td||ddkr|dtkr^td|t|\}}|s~td||dk r|g|ddd<d}||t |\}}|dk r|g|dd<||||fS)Nrz!expected name-addr but found '{}'rT) rr2r3rrr*r<rWrhrV)rZ name_addrr:r6rrr get_name_addrs6        rXc Cst}zt|\}}WnNtjk rdzt|\}}Wn&tjk r^td|YnXYnXtdd|jDrd|_| |||fS)Nzexpected mailbox but found '{}'css|]}t|tjVqdSr)rrrr rrrr#szget_mailbox..r) rrXrrrOr*anyr-rDrh)rrr6rrr get_mailboxs  rZcCsdt}|r\|d|kr\|dtkrD|t|dd|dd}qt|\}}||q||fS)NrrEr)rr<rhrr>)rr Zinvalid_mailboxr6rrrget_invalid_mailbox s    r[cCst}|r|ddkrzt|\}}||Wntjk r<d}|dtkrt|\}}|rv|ddkr|||jtdn@t |d\}}|dk r|g|dd<|||jt dnb|ddkr|jtdnBt |d\}}|dk r|g|dd<|||jt dYnX|r|ddkr|d}d|_ t |d\}}| ||jt d|r|ddkr|t |d d}q||fS) Nr;z,;zempty element in mailbox-listzinvalid mailbox in mailbox-listrrrr)rrZrhrrr2r3rr=r[rrDr4rQ)rZ mailbox_listr6r:rrrrget_mailbox_listsX                 r]cCst}|s$|jtd||fSd}|r|dtkrt|\}}|sl|jtd||||fS|ddkr||||fSt|\}}t|j dkr|dk r||| ||jt d||fS|dk r|g|dd<||||fS)Nzend of header before group-listrzend of header in group-listr\zgroup-list with empty entries) rrrhrrr2r3r]rrzr4r=)rZ group_listr:r6rrrget_group_listWs>           r^cCs t}t|\}}|r"|ddkr2td||||tdd|dd}|r|ddkr|tdd||ddfSt|\}}|||s|jt dn|ddkrtd ||tdd|dd}|r|dt krt |\}}||||fS) NrrPz8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorrr\zgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rrWrrr*rhrr^rrr2r3)rr|r6rrr get_group|s8          r_c Csxt}zt|\}}WnNtjk rdzt|\}}Wn&tjk r^td|YnXYnX||||fS)Nzexpected address but found '{}')r{r_rrrZr*rh)rrrr6rrr get_addresss r`c Cst}|rzt|\}}||Wn tjk rH}zd}|dtkrt|\}}|rj|ddkr|||jtdnFt |d\}}|dk r|g|dd<|t |g|jt dnh|ddkr|jtdnHt |d\}}|dk r|g|dd<|t |g|jt dW5d}~XYnX|r|ddkr|dd}d|_ t |d\}}| ||jt d|r|tdd|d d}q||fS) Nrrz"address-list entry with no contentzinvalid address in address-listzempty element in address-listrrrr)rqr`rhrrr2r3rr=r[r{rrDr4r)rZ address_listr6errr:rrrrget_address_listsX              rbcCst}|std||ddkr6td||tdd|dd}t|\}}|||rx|ddkrtd||tdd ||ddfS) Nz'expected no-fold-literal but found '{}'rrKz;expected '[' at the start of no-fold-literal but found '{}'zno-fold-literal-startrrGz9expected ']' at the end of no-fold-literal but found '{}'zno-fold-literal-end)rrrr*rhrrF)rZno_fold_literalr6rrrget_no_fold_literals.    rccCst}|r,|dtkr,t|\}}|||r<|ddkrLtd||tdd|dd}zt|\}}Wn`tjk rz"t |\}}|j t dWn&tjk rtd|YnXYnX|||r|ddkr@|j t d |r8|dd kr8|td d |dd}||fS|tdd |dd}zt|\}}Wntjk rzt |\}}Wnrtjk r}zPz"t|\}}|j t d Wn(tjk rtd|YnXW5d}~XYnXYnX|||r6|dd kr6|dd}n|j t d|td d |r|dtkrt|\}}||||fS)NrrTzexpected msg-id but found '{}'z msg-id-startrzobsolete id-left in msg-idz4expected dot-atom-text or obs-id-left but found '{}'rzmsg-id with no id-rightrUz msg-id-endrNzobsolete id-right in msg-idzFexpected dot-atom-text, no-fold-literal or obs-id-right but found '{}'zmissing trailing '>' on msg-id)rr2r3rhrrr*rr7rArr=rrcrM)rZmsg_idr6errr get_msg_ids~             "    rec Cst}zt|\}}||WnLtjk rl}z,t|}t|}|jtd |W5d}~XYnX|r|jtd ||S)NzInvalid msg-id: {!r}zUnexpected {!r}) rrerhrrr'rrrr*)rZ message_idr6Zexrrrparse_message_idIs  rfcCst}|s |jtd|S|dtkrXt|\}}|||sX|jtdd}|r|ddkr|dtkr||d7}|dd}q\|s|jtd ||t |dnt ||_ |t |d |r|dtkrt|\}}|||r|ddkrT|j dk r:|jtd |rP|t |d|S|t dd |dd}|r|dtkrt|\}}|||s|j dk r|jtd |Sd}|r|dtkr||d7}|dd}q|s*|jtd ||t |dnt ||_ |t |d |rn|dtkrnt|\}}|||r|jtd |t |d|S)Nz%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSrrrz1Expected 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)rrrhrHeaderMissingRequiredValuer2r3isdigitrr*rintrr)rZ mime_versionr6rgrrrparse_mime_versiones                        rkcCsdt}|r\|ddkr\|dtkrD|t|dd|dd}qt|\}}||q||fS)Nrr\rEr)rr<rhrr>)rZinvalid_parameterr6rrrget_invalid_parameters    rlcCsNt|}|std||}|t|d}t|d}t|||fS)Nzexpected ttext but found '{}'ttext)_non_token_end_matcherrrr*r|rrr )rr.rmrrr get_ttexts  rocCst}|r,|dtkr,t|\}}|||rL|dtkrLtd|t|\}}|||r|dtkrt|\}}||||fSNrzexpected token but found '{}') r\r2r3rh TOKEN_ENDSrrr*ro)rZmtokenr6rrr get_tokens       rrcCsNt|}|std||}|t|d}t|d}t|||fS)Nz expected attrtext but found {!r}r)_non_attribute_end_matcherrrr*r|rrr rr.rrrr get_attrtexts  rucCst}|r,|dtkr,t|\}}|||rL|dtkrLtd|t|\}}|||r|dtkrt|\}}||||fSrp) rr2r3rhATTRIBUTE_ENDSrrr*rurrr6rrr get_attributes       rxcCsNt|}|std||}|t|d}t|d}t|||fS)Nz)expected extended attrtext but found {!r}extended-attrtext)#_non_extended_attribute_end_matcherrrr*r|rrr rtrrrget_extended_attrtext s r{cCst}|r,|dtkr,t|\}}|||rL|dtkrLtd|t|\}}|||r|dtkrt|\}}||||fSrp) rr2r3rhEXTENDED_ATTRIBUTE_ENDSrrr*r{rwrrrget_extended_attribute! s      r}cCst}|r|ddkr&td||tdd|dd}|rR|dsbtd|d}|r|dr||d7}|dd}qf|ddkr|dkr|jtd t ||_ |t|d ||fS) Nr*zExpected section but found {}zsection-markerrz$Expected section number but found {}r0z'section number has an invalid leading 0rg) rrrr*rhrrirZInvalidHeaderErrorrjr)rrrgrrr get_section7 s,     rcCst}|stdd}|dtkr0t|\}}|sDtd||ddkr^t|\}}n t|\}}|dk r|g|dd<||||fS)Nz&Expected value but found end of stringrz Expected value but found only {}r ) rrrr2r3r*r4r}rh)rvr:r6rrr get_valueU s"      rc Cst}t|\}}|||r,|ddkrL|jtd|||fS|ddkrz t|\}}d|_||Wntj k rYnX|st d|ddkr|t dd|dd}d|_ |dd krt d |t d d |dd}d}|r,|dt kr,t |\}}||d}|}|j rF|rF|dd krFt|\}}|j}d }|jdkr|r|ddkrd}n$t|\}} | r| ddkrd}n(zt|\}} Wn Yn X| sd}|r0|jtd|||D](} | jdkrg| dd<| }q*q|}nd}|jtd|r`|ddkr`d}n t|\}}|j r|jdkr|r|ddkr|||dk r|}||fS|jtd|s|jtd|||dkr||fSn|dk r@|D]} | jdkr q$q | jdk|| | j|_|ddkr^t d||t dd|dd}|r|ddkrt|\}}|||j|_|r|ddkrt d||t dd|dd}|dk rdt} |r^|dtkrt|\}}n2|dd krDt d d}|dd}n t|\}}| |q| }n t|\}}|||dk r|}||fS)Nrr\z)Parameter contains name ({}) but no valuer~TzIncomplete parameterzextended-parameter-markerr=zParameter not followed by '='parameter-separatorr F'z5Quoted string value for extended parameter is invalidrezZParameter 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 delimitersryrz=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {}ZDQUOTE)rrxrhrrrr*rrrrrr2r3r4rlrrur{rDrrr`rarrrr+) rrr6r:rZappendtoZqstringZ inner_valueZ semi_validrtrrrr get_parameterk s                                             rc Csjt}|rfzt|\}}||Wntjk r}zd}|dtkrVt|\}}|sp|||WYxS|ddkr|dk r|||jtdn@t |\}}|r|g|dd<|||jtd |W5d}~XYnX|rD|ddkrD|d}d|_ t |\}}| ||jtd ||r|t dd|d d}q|S) Nrr\zparameter entry with no contentzinvalid parameter {!r}rrz)parameter with invalid trailing text {!r}rr)rrrhrrr2r3rrrlr*rDr4r)rZmime_parametersr6rar:rrrrparse_mime_parameters sJ               rcCs|rV|ddkrV|dtkr>|t|dd|dd}qt|\}}||q|s^dS|tdd|t|dddS)Nrr\rErr)r<rhrr>r)Z tokenlistrr6rrr_find_mime_parameters- s   rc Cst}d}|s$|jtd|Szt|\}}Wn<tjk rp|jtd|t |||YSX|||r|ddkr|jtd|rt |||S|j |_ |tdd|dd}zt|\}}Wn>tjk r*|jtd |t |||YSX|||j |_|sP|S|dd kr|jtd ||` |`t |||S|td d |t|dd|S) NFz"Missing content type specificationz(Expected content maintype but found {!r}rrzInvalid content typezcontent-type-separatorrz'Expected content subtype but found {!r}r\z)rZ cte_headerr6rrr&parse_content_transfer_encoding_header s4        rcCsDd}|r@|dr@|ddtkr@|dd}|ddd|d<|S)Nrr)r)linesZwsprrr_steal_trailing_WSP_if_exists s  rcCs|jp tj}|jrdnd}dg}d}d}d}tdd}t|} | r| d} | |kr`|d8}q>t| } | jdkrt | t @rd }z| ||} Wn6t k rt d d | jDrd } nd} d }YnX| jd krt| |||q>|r|s| jspd}d}| jrp| j|ddt|j } |j| krpt| |t|dkr^t|}|||d| 7<q>t| dst| | } nt| |||| j| }d}q>t| |t|dkr|d| 7<q>| jrt| d|krt|}|s| r||| d}q>t| dsNt| }| jsD|d7}|||| } q>| jrn|sn| d| d }q>t|}|s| r||| q>|d| 7<q>|j||jS)Nutf-8rrrFwrap_as_ew_blockedrrTcss|]}t|tjVqdSr)rrrr rrrr# sz%_refold_parse_tree.. unknown-8bitrr7rrB)Zmax_line_lengthsysmaxsizeutf8rrrr rDrr9rBrrYr-_fold_mime_parametersr1rHr;rrrrhrE _fold_as_ewrIr0insertr%)Z parse_treer8maxlenrrlast_ewrZ want_encodingZend_ew_not_allowedrr2tstrr`Z encoded_partnewlineZnewpartsrrrr9 s              r9cCs|dk r<|rrDrArFrJrLrMrOrSrVrWrXrZr[r]r^r_r`rbrcrerfrkrlrorrrurxr{r}rrrrrrrrrr9rrrrrrFs,           C  "   !*$ V +         1C+ "&'/'&).9%7ED49/gA