U e5düXã@s²ddgZddlZddlmZddlmZddlmZddlm Z e  d¡Z e  d ¡Z e  d ¡Z e  d ¡Ze  d ¡Zd Zd ZeƒZGdd„deƒZGdd„dƒZGdd„deƒZdS)Ú FeedParserÚBytesFeedParseréN)Úerrors)Úcompat32)Údeque)ÚStringIOz \r\n|\r|\nz (\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])ÚÚ c@s\eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dS)ÚBufferedSubFilecCs$tdd|_tƒ|_g|_d|_dS)Nr)ÚnewlineF)rÚ_partialrÚ_linesÚ _eofstackÚ_closed©Úself©rú(/usr/lib64/python3.8/email/feedparser.pyÚ__init__5s zBufferedSubFile.__init__cCs|j |¡dS©N)rÚappend)rZpredrrrÚpush_eof_matcher@sz BufferedSubFile.push_eof_matchercCs |j ¡Sr)rÚpoprrrrÚpop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|j d¡| |j ¡¡|j d¡|j ¡d|_dS)NrT)r ÚseekÚ pushlinesÚ readlinesÚtruncaterrrrrÚcloseFs    zBufferedSubFile.closecCsL|js|jrdStS|j ¡}t|jƒD]}||ƒr(|j |¡dSq(|S©Nr)r rÚ NeedMoreDataÚpopleftÚreversedrÚ appendleft)rÚlineZateofrrrÚreadlineNs  zBufferedSubFile.readlinecCs|j |¡dSr)r r#©rr$rrrÚ unreadline`szBufferedSubFile.unreadlinecCsx|j |¡d|kr d|kr dS|j d¡|j ¡}|j d¡|j ¡|d d¡sj|j | ¡¡| |¡dS)Nr ú réÿÿÿÿ)r ÚwriterrrÚendswithrr)rÚdataÚpartsrrrÚpushes     zBufferedSubFile.pushcCs|j |¡dSr)r Úextend)rÚlinesrrrrzszBufferedSubFile.pushlinescCs|SrrrrrrÚ__iter__}szBufferedSubFile.__iter__cCs| ¡}|dkrt‚|Sr)r%Ú StopIterationr&rrrÚ__next__€szBufferedSubFile.__next__N) Ú__name__Ú __module__Ú __qualname__rrrrr%r'r.rr1r3rrrrr -s r c@s\eZdZdedœdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dS)rN©ÚpolicycCsž||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_z||jdWntk rld|_YnXtƒ|_g|_ |  ¡j |_ d|_ d|_d|_dS)NFr)ÚMessager7T)r8Ú_old_style_factoryZmessage_factoryZ email.messager9Ú_factoryÚ TypeErrorr Ú_inputÚ _msgstackÚ _parsegenr3Ú_parseÚ_curÚ_lastÚ _headersonly)rr;r8r9rrrr‹s$     zFeedParser.__init__cCs d|_dS)NT)rCrrrrÚ_set_headersonlyªszFeedParser._set_headersonlycCs|j |¡| ¡dSr)r=r.Ú _call_parse©rr,rrrÚfeed­s zFeedParser.feedcCs&z | ¡Wntk r YnXdSr)r@r2rrrrrE²s zFeedParser._call_parsecCsH|j ¡| ¡| ¡}| ¡dkrD| ¡sDt ¡}|j  ||¡|S)NÚ multipart) r=rrEÚ _pop_messageÚget_content_maintypeZ is_multipartrZ!MultipartInvariantViolationDefectr8Ú handle_defect)rÚrootÚdefectrrrr¸s  ÿzFeedParser.closecCsn|jr| ¡}n|j|jd}|jr<|j ¡dkr<| d¡|jrR|jd |¡|j |¡||_||_ dS)Nr7zmultipart/digestzmessage/rfc822r)) r:r;r8rAÚget_content_typeZset_default_typer>ZattachrrB)rÚmsgrrrÚ _new_messageÅs   zFeedParser._new_messagecCs(|j ¡}|jr|jd|_nd|_|S)Nr))r>rrA)rÚretvalrrrrIÒs  zFeedParser._pop_messageccs| ¡g}|jD]Z}|tkr&tVqt |¡sbt |¡s^t ¡}|j  |j |¡|j  |¡qn|  |¡q|  |¡|jrÈg}|j ¡}|tkrœtVq‚|dkr¦q²|  |¡q‚|j  t |¡¡dS|j  ¡dkrŠ|j tj¡| ¡D]}|tkrtVqîq qî| ¡}|j ¡|j ¡}|tkrDtVqqDq|j ¡}|tkrjtVqDqjqD|dkrxq†|j  |¡qØdS|j  ¡dkrÐ| ¡D] }|tkrºtVq¢qÄq¢| ¡dS|j  ¡dkrÔ|j  ¡}|dkrRt ¡}|j  |j |¡g}|jD]$}|tkr.tVq|  |¡q|j  t |¡¡dSt|j  dd¡ƒ ¡dkr†t ¡}|j  |j |¡d|}t  d t !|¡d ¡} d } g} d } d } |j ¡}|tkrÔtVq¶|dkrâqÂ|  |¡}|r´| "d ¡rd } | "d¡} qÂ| rr| r^| d}t# $|¡}|rP|dt%| "d¡ƒ …| d<t | ¡|j _&d } |j  |¡q¶|j ¡}|tkrtVqr|  |¡}|sr|j  |¡q´qr|j | j¡| ¡D] }|tkrâtVqÊqìqÊ|j' ¡dkrT|j'j(}|dkrd|j'_(n:|dk r˜t# $|¡}|r˜t%| "d¡ƒ}|d| …|j'_(nD|j'j)}t*|tƒr˜t# $|¡}|r˜|dt%| "d¡ƒ …}||j'_)|j ¡| ¡|j |_'n |   |¡q¶| r*t +¡}|j  |j |¡|j  t | ¡¡g}|jD]}|tkrütVqüqüt |¡|j _(dS| sLt ,¡}|j  |j |¡dS| rZdg}ng}|jD]$}|tkr|tVqd|  |¡qd|rÂ|d}t- |¡}|rÂ|t%| "d¡ƒd…|d<t |¡|j _(dSg}|jD]$}|tkrötVqÞ|  |¡qÞ|j  t |¡¡dS)Nrzmessage/delivery-statusÚmessagerHzcontent-transfer-encodingÚ8bit)Z7bitrSZbinaryz--z(?Pz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFÚendÚlinesepr)r).rPr=r ÚheaderREÚmatchÚNLCRErZ MissingHeaderBodySeparatorDefectr8rKrAr'rÚ_parse_headersrCr%Z set_payloadÚ EMPTYSTRINGÚjoinrNrr?rIrrJZ get_boundaryZNoBoundaryInMultipartDefectÚstrÚgetÚlowerZ-InvalidMultipartContentTransferEncodingDefectÚreÚcompileÚescapeÚgroupÚ NLCRE_eolÚsearchÚlenÚpreamblerBÚepilogueZ_payloadÚ isinstanceZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefectÚ NLCRE_bol)rZheadersr$rMr0rQrOÚboundaryZ separatorZ boundaryreZcapturing_preamblerfrUZclose_boundary_seenÚmoZlastlineZeolmorgrTZpayloadÚ firstlineZbolmorrrr?Ús`                       ÿ ÿÿ                              zFeedParser._parsegenc CsXd}g}t|ƒD]&\}}|ddkrR|sFt |¡}|j |j|¡q| |¡q|rt|jj|j |¡Ždg}}|  d¡rø|dkr¼t   |¡}|r¬|dt |  d¡ƒ …}|j |¡qn<|t |ƒdkrÞ|j |¡dSt |¡}|jj |¡q| d¡}|dkr&t d¡}|jj |¡q|d|…}|g}q|rT|jj|j |¡ŽdS)Nrrz zFrom éú:zMissing header name.)Ú enumeraterZ#FirstHeaderLineIsContinuationDefectr8rKrArZset_rawZheader_source_parseÚ startswithrcrdrerbZ set_unixfromr=r'ZMisplacedEnvelopeHeaderDefectZdefectsÚfindZInvalidHeaderDefect) rr0Z lastheaderZ lastvalueÚlinenor$rMrkÚirrrrY×sF             zFeedParser._parse_headers)N) r4r5r6rrrDrGrErrPrIr?rYrrrrrˆs  ~cseZdZ‡fdd„Z‡ZS)rcstƒ | dd¡¡dS)NÚasciiÚsurrogateescape)ÚsuperrGÚdecoderF©Ú __class__rrrGszBytesFeedParser.feed)r4r5r6rGÚ __classcell__rrrxrrs)Ú__all__r_ZemailrZemail._policybaserÚ collectionsrÚiorr`rXrircZ NLCRE_crackrVrZÚNLÚobjectr r rrrrrrÚs&         [