f YRdZddgZddlZddlmZddlmZddlmZddl m Z ejd Z ejd Z ejd Zejd Zejd Zd ZdZeZGddeZGddZGddeZy)aFeedParser - An email feed parser. The feed parser implements an interface for incrementally parsing an email message, line by line. This has advantages for certain applications, such as those reading email messages off a socket. FeedParser.feed() is the primary interface for pushing new data into the parser. It returns when there's nothing more it can do with the available data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. FeedParserBytesFeedParserN)errors)compat32)deque)StringIOz \r\n|\r|\nz (\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ]) cLeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) BufferedSubFileakA file-ish object that can have new data loaded into it. You can also push and pop line-matching predicates onto a stack. When the current predicate matches the current line, a false EOF response (i.e. empty string) is returned instead. This lets the parser adhere to a simple abstraction -- it parses until EOF closes the current message. c`td|_t|_g|_d|_y)Nr )newlineF)r_partialr_lines _eofstack_closedselfs '/usr/lib/python3.12/email/feedparser.py__init__zBufferedSubFile.__init__4s'!, g  c:|jj|yN)rappend)rpreds rpush_eof_matcherz BufferedSubFile.push_eof_matcher?s d#rc6|jjSr)rpoprs rpop_eof_matcherzBufferedSubFile.pop_eof_matcherBs~~!!##rc|jjd|j|jj|jjd|jj d|_y)NrT)rseek pushlines readlinestruncaterrs rclosezBufferedSubFile.closeEsV 1 t}}..01 1   rc|js|jrytS|jj}t |j D]'}||s |jj |y|SNr )rr NeedMoreDatapopleftreversedr appendleft)rlineateofs rreadlinezBufferedSubFile.readlineMsj{{|| {{""$dnn- ET{ &&t,    rcN|tusJ|jj|yr)r(rr+rr,s r unreadlinezBufferedSubFile.unreadline_s"<''' t$rc|jj|d|vrd|vry|jjd|jj}|jjd|jj |dj ds)|jj|j |j|y)z$Push some new data into this object.r  Nr)rwriter!r#r$endswithrr")rdatapartss rpushzBufferedSubFile.pushds D! t D 0  1 '') 1  Ry!!$' MM   , urc:|jj|yr)rextend)rliness rr"zBufferedSubFile.pushlinesys 5!rc|Srrs r__iter__zBufferedSubFile.__iter__|s rc<|j}|dk(rt|Sr')r. StopIterationr0s r__next__zBufferedSubFile.__next__s}} 2:  rN)__name__ __module__ __qualname____doc__rrrr%r.r1r9r"r?rBr>rrr r ,s9 $$$% *"rr cNeZdZdZd eddZdZdZdZdZ d Z d Z d Z d Z y)rzA feed-style parser of email.Npolicycr||_d|_|,|jddlm}||_n-|j|_n||_ ||jt|_g|_ |jj|_ d|_ d|_d|_y#t $r d|_Y]wxYw)a_factory is called with no arguments to create a new message obj The policy keyword specifies a policy object that controls a number of aspects of the parser's operation. The default policy maintains backward compatibility. FNr)MessagerHT)rI_old_style_factorymessage_factory email.messagerK_factory TypeErrorr _input _msgstack _parsegenrB_parse_cur_last _headersonly)rrOrIrKs rrzFeedParser.__init__s "'  %%-1 ' & 6 6 $DM / ,&' nn&//   ! /*.' /sB##B65B6cd|_y)NT)rWrs r_set_headersonlyzFeedParser._set_headersonlys  rcZ|jj||jy)zPush more data into the parser.N)rQr9 _call_parse)rr7s rfeedzFeedParser.feeds   rcD |jy#t$rYywxYwr)rTrArs rr[zFeedParser._call_parses"  KKM   s  cT|jj|j|j}|jrJ|j dk(rL|j s<|js0tj}|jj|||S)z>!!  $ $ &+ 5((*43D3D==?F KK % %dF 3 rc|jr|j}n|j|j}|jr.|jj dk(r|j d|j r|j dj||j j|||_||_ y)NrHzmultipart/digestzmessage/rfc822r4) rLrOrIrUget_content_typeset_default_typerRattachrrV)rmsgs r _new_messagezFeedParser._new_messages  " "--/C--t{{-3C 993359KK  !1 2 >> NN2  % %c * c"  rc|jj}|jr|jd|_|Sd|_|S)Nr4)rRrrU)rretvals rr`zFeedParser._pop_messages@##% >>r*DI DI rc#JK|jg}|jD]}|tur ttj |slt j |sUt j}|jj|j||jj|n|j||j||jrug} |jj}|tur t,|dk(rn|j|C|jj!t"j%|y|jj'dk(r |jj)t j|j+D]}|tur tn|j-|jj/ |jj}|tur t, |jj}|tur t, |dk(r y|jj||jj1dk(r8|j+D]}|tur tn|j-y|jj1dk(r|jj3}|t j4}|jj|j|g}|jD]$}|tur t|j|&|jj!t"j%|yt7|jj9ddj;dvr:t j<}|jj|j|d |z}t?j@d t?jB|zd z}d} g} d } d } |jj}|tur t,|dk(rn|j |} | r| jEd rd} | jEd} n}| r| ra| d}tFjI|}|r!|dtK|jEd | d<t"j%| |j_&d } |jj| |jj}|tur t,|j |} | s|jj|n[|jj)|j|j+D]}|tur tn|jNj1dk(rv|jNjP}|dk(rd|jN_(n|tFjI|} | rtK| jEd}|d| |jN_(nl|jNjR}tU|t6rFtFjI|} | r/|dtK| jEd }||jN_)|jj/|j-|j|_'n| sJ| j|| rt jV}|jj|j||jj!t"j%| g}|jD]}|tus tt"j%||j_(y| s;t jX}|jj|j|y| rdg}ng}|jD]$}|tur t|j|&|r<|d}tZj |}|r |tK|jEdd|d<t"j%||j_(yg}|jD]$}|tur t|j|&|jj!t"j%|yw)NTr zmessage/delivery-statusmessager_zcontent-transfer-encoding8bit)7bitrqbinaryz--z(?Pz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$Fendlinesepr4r).rlrQr(headerREmatchNLCREr MissingHeaderBodySeparatorDefectrIrdrUr1r_parse_headersrWr. set_payload EMPTYSTRINGjoinrhrrSr`rra get_boundaryNoBoundaryInMultipartDefectstrgetlower-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup NLCRE_eolsearchlenpreamblerVepilogue_payload isinstanceStartBoundaryNotFoundDefectCloseBoundaryNotFoundDefect NLCRE_bol)rheadersr,rfr<rnboundary separator boundaryrecapturing_preamblerruclose_boundary_seenmolastlineeolmorrtpayload firstlinebolmos rrSzFeedParser._parsegens KK !D|#"">>$'{{4(#DDFFKK--dii@KK**40 NN4  ! G$   E{{++-<'&&2: T" II ! !+"2"25"9 :  99 % % '+D D  ,,U[[9"nn.F-**   !!# ++- ;;//1D|+** ;;//1D|+** 2:  &&t,?B 99 ) ) +y 8..* \)&&        99 ) ) +{ :yy--/H  ;;= ))$))V< KK'D|+** LL& '  %%k&6&6u&=>DIIMM"=vFGMMO56MMO ))$))V< xIRYYy11GHIJ"& HG"' {{++-<'&&2:%%d+ xx.2+"$((9"5)#(0|H$-$4$4X$>E$/78M#ekk!n:M9M/N 1<1A1A(1KDII.-2* ..t4 #{{335</"..$'--d3! KK2248!KK001A1AB"&.."2!\1"..$ zz668KG#'::#6#6#r>26DJJ/%1!*!1!1(!;B!&)"((1+&66>uo 3"&**"5"5%gs3!*!1!1'!:B!*12DC 4D3D*E6= 3KK//1%%'"&DJ.--OOD)_f";;= ))$))V< %%k&6&6x&@A KK!D|+** !&1%5%5h%? "';;= ))$))V<4  &<'&&%  &$QK ! 2"+C A,?,@"AHQK!,!1!1(!;DII  KK D|#"" LL    k..u56s ^2d#5E.d#c,d}g}t|D]\}}|ddvrP|s>yI J rr)rCrDrErFrrrYr\r[r%rlr`rSrzr>rrrrs<'"">!   {7z:Krc"eZdZdZfdZxZS)rz(Like FeedParser, but feed accepts bytes.cDt||jddy)Nasciisurrogateescape)superr\decode)rr7 __class__s rr\zBytesFeedParser.feeds  T[[*;<=r)rCrDrErFr\ __classcell__)rs@rrrs2>>r)rF__all__remailremail._policybaser collectionsriorrrxrr NLCRE_crackrvr|NLobjectr(r rrr>rrrs " * + & =! BJJ ' BJJ( ) bjj)  2::> ?  x WfWtIKIKX >j>r