
    4pfX                        d Z ddlmZ ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZ ddgZdd	lZdd
lmZ ddlmZ ddlmZ  ej        d          Z ej        d          Z ej        d          Z ej        d          Z ej        d          ZdZdZ e            Z G d de          Z G d de          Z G d de          Zd	S )a  FeedParser - 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.
    )unicode_literals)division)absolute_import)objectrangesuper)implements_iteratorPY3
FeedParserBytesFeedParserN)errors)message)compat32z
||
z(
||
)z
(
||
)\Zz(^(From |[\041-\071\073-\176]{1,}:|[\t ]) 
c                   N    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZdS )BufferedSubFileak  A 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                 >    d| _         g | _        g | _        d| _        d S )Nr   F)_partial_lines	_eofstack_closedselfs    a/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/future/backports/email/feedparser.py__init__zBufferedSubFile.__init__9   s"        c                 :    | j                             |           d S N)r   append)r   preds     r   push_eof_matcherz BufferedSubFile.push_eof_matcherC   s    d#####r   c                 4    | j                                         S r   )r   popr   s    r   pop_eof_matcherzBufferedSubFile.pop_eof_matcherF   s    ~!!###r   c                 `    | j                             | j                   d| _        d| _        d S )Nr   T)r   r    r   r   r   s    r   closezBufferedSubFile.closeI   s,    4=)))r   c                     | j         s| j        rdS t          S | j                                         }| j        d d d         D ]*} ||          r| j                             |            dS +|S )Nr   )r   r   NeedMoreDatar$   r   r    )r   lineateofs      r   readlinezBufferedSubFile.readlineO   s    { 	 | r {   ^DDbD) 	 	EuT{{ ""4(((rr r   c                 P    |t           usJ | j                            |           d S r   )r*   r   r    r   r+   s     r   
unreadlinezBufferedSubFile.unreadlinea   s/    <''''4     r   c                    | j         |z   dc}| _         t                              |          }|                                | _         | j         sL|rJ|d                             d          r/|                    d          |                                z   | _         g }t          t          |          dz            D ]/}|                    ||dz           ||dz  dz            z              0|                     |           dS )z$Push some new data into this object.r   r)         N)	r   NLCRE_cracksplitr$   endswithr   lenr    	pushlines)r   datapartslinesis        r   pushzBufferedSubFile.pushf   s     #md2Bdm!!$''
 		 } 	6 	659+=+=d+C+C 	6!IIbMM%))++5DM s5zzQ'' 	4 	4ALLqseAaCEl23333ur   c                 0    |d d d         | j         d d<   d S )Nr)   r   )r   )r   r=   s     r   r:   zBufferedSubFile.pushlines}   s    "+BQBr   c                     | S r    r   s    r   __iter__zBufferedSubFile.__iter__   s    r   c                 H    |                                  }|dk    rt          |S )Nr   )r-   StopIterationr/   s     r   __next__zBufferedSubFile.__next__   s#    }}2::r   N)__name__
__module____qualname____doc__r   r"   r%   r'   r-   r0   r?   r:   rC   rF   rB   r   r   r   r   1   s           $ $ $$ $ $    $! ! !
  .& & &      r   r   c                   V    e Zd ZdZej        fdZd Zd Zd Z	d Z
d Zd Zd	 Zd
 ZdS )r   zA feed-style parser of email.c                     d|v r|d         }|d= nt           }	 | _        | _        	  | j                    fd _        n# t          $ r d  _        Y nw xY wt                       _        g  _        t          r 	                                j
         _        n 	                                j         _        d  _        d  _        d _        d S )NpolicyrM   c                      d j         iS )NrM   rN   r   s   r   <lambda>z%FeedParser.__init__.<locals>.<lambda>   s    (DK)@ r   c                      i S r   rB   rB   r   r   rP   z%FeedParser.__init__.<locals>.<lambda>   s     r   F)r   _factoryrM   _factory_kwds	TypeErrorr   _input	_msgstackr
   	_parsegenrF   _parsenext_cur_last_headersonly)r   rR   _3to2kwargsrM   s   `   r   r   zFeedParser.__init__   s    {""[-BFT\H]H]f	 !	,HDK((((!@!@!@!@D 	, 	, 	,!+D	, &'' 	0..**3DKK..**/DK	
!s   A AAc                     d| _         d S )NT)r\   r   s    r   _set_headersonlyzFeedParser._set_headersonly   s     r   c                 b    | j                             |           |                                  dS )zPush more data into the parser.N)rU   r?   _call_parse)r   r;   s     r   feedzFeedParser.feed   s0    r   c                 R    	 |                                   d S # t          $ r Y d S w xY wr   )rX   rE   r   s    r   ra   zFeedParser._call_parse   s:    	KKMMMMM 	 	 	DD	s    
&&c                 N   | j                                          |                                  |                                 }| j        rJ |                                dk    rB|                                s.t          j                    }| j	        
                    ||           |S )z<Parse all remaining data and return the root message object.	multipart)rU   r'   ra   _pop_messagerV   get_content_maintypeis_multipartr   !MultipartInvariantViolationDefectrM   handle_defect)r   rootdefects      r   r'   zFeedParser.close   s      "">!!!$$&&+55((** 6=??FK%%dF333r   c                 T    | j         di |                                 }| j        r2| j                                        dk    r|                    d           | j        r | j        d                             |           | j                            |           || _        || _        d S )Nzmultipart/digestzmessage/rfc822r)   rB   )	rR   rS   rZ   get_content_typeset_default_typerV   attachr    r[   )r   msgs     r   _new_messagezFeedParser._new_message   s    dm33d0022339 	333559KKK  !1222> 	+N2%%c***c"""	


r   c                 z    | j                                         }| j         r| j         d         | _        nd | _        |S )Nr)   )rV   r$   rZ   )r   retvals     r   rf   zFeedParser._pop_message   s;    ##%%> 	r*DIIDIr   c              #     K   |                                   g }| j        D ]}|t          u r
t          V  t                              |          sit
                              |          sMt          j                    }| j        	                    | j
        |           | j                            |            n|                    |           |                     |           | j        rg }	 | j                                        }|t          u r
t          V  -|dk    rn|                    |           I| j
                            t"                              |                     d S | j
                                        dk    r	 | j                            t
          j                   |                                 D ]}|t          u r
t          V   |                                 }| j                                         	 | j                                        }|t          u r
t          V  -	 	 | j                                        }|t          u r
t          V  -	 |dk    rn| j                            |           d S | j
                                        dk    r@|                                 D ]}|t          u r
t          V   |                                  d S | j
                                        dk    r| j
                                        }|t          j                    }| j        	                    | j
        |           g }| j        D ]*}|t          u r
t          V  |                    |           +| j
                            t"                              |                     d S | j
                            dd                                          dvr3t          j                    }| j        	                    | j
        |           d	|z   }t=          j        d
t=          j         |          z   dz             }	d}
g }d}d}	 | j                                        }|t          u r
t          V  -|dk    rn|	                    |          }|r|!                    d          rd}|!                    d          }n|
r|rv|d         }tD          #                    |          }|r.|d tI          |!                    d                              |d<   t"                              |          | j
        _%        d}
| j                            |           	 | j                                        }|t          u r
t          V  -|	                    |          }|s| j                            |           n_| j                            |	j                   |                                 D ]}|t          u r
t          V   | j&                                        dk    ru| j&        j'        }|dk    rd | j&        _'        n|StD          #                    |          }|r7tI          |!                    d                    }|d |          | j&        _'        nt| j&        j(        }tS          |tT                    rStD          #                    |          }|r7|d tI          |!                    d                              }|| j&        _(        | j                                         |                                  | j
        | _&        n|
sJ |                    |           |
rt          j+                    }| j        	                    | j
        |           | j
                            t"                              |                     g }| j        D ]}|t          u r
t          V  t"                              |          | j
        _'        d S |s5t          j,                    }| j        	                    | j
        |           d S |rdg}ng }| j        D ]*}|t          u r
t          V  |                    |           +|rQ|d         }tZ                              |          }|r-|tI          |!                    d                    d          |d<   t"                              |          | j
        _'        d S g }| j        D ]*}|t          u r
t          V  |                    |           +| j
                            t"                              |                     d S )NTr   zmessage/delivery-statusr   re   zcontent-transfer-encoding8bit)7bitrv   binaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$Fendlinesepr)   r   ).rr   rU   r*   headerREmatchNLCREr    MissingHeaderBodySeparatorDefectrM   rj   rZ   r0   r    _parse_headersr\   r-   set_payloadEMPTYSTRINGjoinrn   r"   rW   rf   r%   rg   get_boundaryNoBoundaryInMultipartDefectgetlower-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup	NLCRE_eolsearchr9   preambler[   epilogue_payload
isinstancestrStartBoundaryNotFoundDefectCloseBoundaryNotFoundDefect	NLCRE_bol)r   headersr+   rl   r=   rt   rq   boundary	separator
boundaryrecapturing_preambler   rz   close_boundary_seenmolastlineeolmor   ry   payload	firstlinebolmos                         r   rW   zFeedParser._parsegen   s	      K 	! 	!D|##"""">>$''  {{4(( 1#DFFFK--di@@@K**4000NN4     	G$$$  	E#{++--<''&&&&2::T"""# I!!+"2"25"9"9:::F9%%''+DDD-,,U[999"nn..  F--**** '')) ++---
;//11D|++**** ;//11D|++**** 2::&&t,,,?-@ F9))++y88 ..**  \))&&&&F9))++{::y--//H
  ;==))$)V<<< K ' 'D|++**** LL&&&&	%%k&6&6u&=&=>>>	96BBHHJJ56 6MOO))$)V<<<
 xIRYy111GHI IJ "&HG"'O*{++--<''&&&&2::%%d++ G*
 xx .2+"$((9"5"5) !# L (0|H$-$4$4X$>$>E$ O/78M#ekk!nn:M:M9M8M/N1<1A1A(1K1KDI.-2*..t444 
"#{3355<//"....$'--d33! " K224888!" K001ABBB"&.."2"2  !\11"....$
 z6688KGG#':#6#r>>26DJ//%1!*!1!1(!;!;B! F&)"((1++&6&66>uuo
 3"&*"5%gs33 >!*!1!1'!:!:B! >*12DC4D4D3D2D*E6=
 3K//111%%''' "&DJJ .---OOD)))_O*f " 
;==))$)V<<<	%%k&6&6x&@&@AAA K ! !D|++****  , &1%5%5h%?%?	" ' ;==))$)V<<<  4 & &<''&&&&%%%%  B$QK	!	22 B"+CA,?,?,@,@"AHQK!,!1!1(!;!;DIF K 	 	D|##""""LL	k..u5566666r   c                    d}g }t          |          D ]\  }}|d         dv rM|s5t          j        |          }| j                            | j        |           G|                    |           ]|r+ | j        j        | j                            |            dg }}|	                    d          r|dk    rct                              |          }|r+|d t          |                    d                              }| j                            |           |t          |          dz
  k    r| j                            |            d S t          j        |          }| j        j                            |           p|                    d          }|dk    s
J d            |d |         }|g}|r) | j        j        | j                            |            d S d S )Nr   r   z 	zFrom r5   :z3_parse_headers fed line with no : and no leading WS)	enumerater   #FirstHeaderLineIsContinuationDefectrM   rj   rZ   r    set_rawheader_source_parse
startswithr   r   r9   r   set_unixfromrU   r0   MisplacedEnvelopeHeaderDefectdefectsfind)	r   r=   
lastheader	lastvaluelinenor+   rl   r   r>   s	            r   r   zFeedParser._parse_headers  s   
	%e,, *	 *	LFDAw%!  $GMMFK--di@@@  &&& /!	!4;#B#B9#M#MNN(*BI
w'' Q;;"))$//B 8#$6c"((1++&6&6%6$67I**4000s5zzA~-- K**4000FF $A$GGFI%,,V444 		#AQ333M333bqbJII 	KDIt{>>yIIJJJJ	K 	Kr   N)rG   rH   rI   rJ   r   Messager   r_   rb   ra   r'   rr   rf   rW   r   rB   r   r   r   r      s        '' ' " " " ":! ! !  
        {7 {7 {7z1K 1K 1K 1K 1Kr   c                   "     e Zd ZdZ fdZ xZS )r   z(Like FeedParser, but feed accepts bytes.c                 r    t                                          |                    dd                     d S )Nasciisurrogateescape)r   rb   decode)r   r;   	__class__s     r   rb   zBytesFeedParser.feed  s.    T[[*;<<=====r   )rG   rH   rI   rJ   rb   __classcell__)r   s   @r   r   r   	  s>        22> > > > > > > > >r   )rJ   
__future__r   r   r   future.builtinsr   r   r   future.utilsr	   r
   __all__r   future.backports.emailr   r   "future.backports.email._policybaser   r   r}   r   r   r6   r{   r   NLr*   r   r   r   rB   r   r   <module>r      s  
   ( ' ' ' ' '       & & & & & & 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1*
+ 				 ) ) ) ) ) ) * * * * * * 7 7 7 7 7 7
<  BJ~&&	BJ'((	bj(( 2:ABB	vxxW W W W Wf W W Wt{K {K {K {K {K {K {K {K|> > > > >j > > > > >r   