
    d^;                     &   d Z ddlZddlZddlZddlZ	 ddlZdZn# e$ r dZY nw xY wddgZ G d de	          Z
dZd	Zd
ZdZeez   ZdZ G d d          Zer# G d de          Ze                    d           edk    rddlZ eej        d                   Z ee                                           e                    ej        d                    e                    ej        d                    e                                 e                                \  ZZ ededz             D ]GZ e!                    e           \  Z"Z#Z$ ede z             e#D ]Z% ede%z               ed           He&                                 dS dS )z@A POP3 client class.

Based on the J. Myers POP3 draft, Jan. 96
    NTFPOP3error_protoc                       e Zd ZdS )r   N)__name__
__module____qualname__       /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/poplib.pyr   r      s          r
   n   i        
i   c                       e Zd ZdZdZeej        f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 Zd Zd!dZd Zd Zd Zd Zd Zd Zd Z ej        d          Z d Z!d Z"d!dZ#d Z$d Z%d!d Z&dS )"r   aP  This class supports both the minimal and optional command sets.
    Arguments can be strings or integers (where appropriate)
    (e.g.: retr(1) and retr('1') both work equally well.

    Minimal Command Set:
            USER name               user(name)
            PASS string             pass_(string)
            STAT                    stat()
            LIST [msg]              list(msg = None)
            RETR msg                retr(msg)
            DELE msg                dele(msg)
            NOOP                    noop()
            RSET                    rset()
            QUIT                    quit()

    Optional Commands (some servers support these):
            RPOP name               rpop(name)
            APOP name digest        apop(name, digest)
            TOP msg n               top(msg, n)
            UIDL [msg]              uidl(msg = None)
            CAPA                    capa()
            STLS                    stls()
            UTF8                    utf8()

    Raises one exception: 'error_proto'.

    Instantiate with:
            POP3(hostname, port=110)

    NB:     the POP protocol locks the mailbox from user
            authorization until QUIT, so be sure to get in, suck
            the messages, and quit, each time you access the
            mailbox.

            POP is a line-based protocol, which means large mail
            messages consume lots of python cycles reading them
            line-by-line.

            If it's available on your mail server, use IMAP4
            instead, it doesn't suffer from the two problems
            above.
    zUTF-8c                    || _         || _        d| _        t          j        d| ||           |                     |          | _        | j                            d          | _        d| _	        | 
                                | _        d S )NFzpoplib.connectrbr   )hostport_tls_establishedsysaudit_create_socketsockmakefilefile
_debugging_getrespwelcome)selfr   r   timeouts       r   __init__zPOP3.__init__b   su    		 %	"D$555''00	I&&t,,	}}r
   c                 j    ||st          d          t          j        | j        | j        f|          S )Nz0Non-blocking socket (timeout=0) is not supported)
ValueErrorsocketcreate_connectionr   r   )r   r   s     r   r   zPOP3._create_socketm   s8    wOPPP'DI(>HHHr
   c                     | j         dk    rt          dt          |                     t          j        d| |           | j                            |t          z              d S )N   z*put*zpoplib.putline)r   printreprr   r   r   sendallCRLFr   lines     r   _putlinezPOP3._putliner   sY    ?QgtDzz : : :	"D$///	$+&&&&&r
   c                     | j         rt          dt          |                     t          || j                  }|                     |           d S )Nz*cmd*)r   r'   r(   bytesencodingr-   r+   s     r   _putcmdzPOP3._putcmdz   sH    ?6E'4::666T4=))dr
   c                    | j                             t          dz             }t          |          t          k    rt	          d          | j        dk    rt          dt          |                     |st	          d          t          |          }|dd          t          k    r|d d         |fS |d d         t          k    r|dd         |fS |d d         |fS )Nr&   zline too longz*get*z-ERR EOF)
r   readline_MAXLINElenr   r   r'   r(   r*   CR)r   r,   octetss      r   _getlinezPOP3._getline   s    y!!(Q,//t99xo...?QgtDzz : : :2;z222T 99f$$8r>>":v%%CRCy&  r
   c                     |                                  \  }}| j        dk    rt          dt          |                     |                    d          st          |          |S )Nr&   z*resp*   +)r:   r   r'   r(   
startswithr   )r   respos      r   r   zPOP3._getresp   s\    --//a?QhT

 ; ; ;t$$ 	$d###r
   c                 ,   |                                  }g }d}|                                 \  }}|dk    r[|                    d          r|dz
  }|dd          }||z   }|                    |           |                                 \  }}|dk    [|||fS )Nr      .s   ..r&   )r   r:   r=   append)r   r>   listr9   r,   r?   s         r   _getlongrespzPOP3._getlongresp   s    }}A6--//adllu%%  aCABBxaZFKKmmooGD! dll T6!!r
   c                 T    |                      |           |                                 S N)r1   r   r+   s     r   	_shortcmdzPOP3._shortcmd   s"    T}}r
   c                 T    |                      |           |                                 S rF   )r1   rD   r+   s     r   _longcmdzPOP3._longcmd   s&    T  """r
   c                     | j         S rF   )r   r   s    r   
getwelcomezPOP3.getwelcome   s
    |r
   c                     || _         d S rF   )r   )r   levels     r   set_debuglevelzPOP3.set_debuglevel   s    r
   c                 2    |                      d|z            S )zVSend user name, return response

        (should indicate password required).
        zUSER %srG   r   users     r   rS   z	POP3.user   s    
 ~~i$.///r
   c                 2    |                      d|z            S )zSend password, return response

        (response includes message count, mailbox size).

        NB: mailbox is locked by server from here to 'quit()'
        zPASS %srQ   )r   pswds     r   pass_z
POP3.pass_   s     ~~i$.///r
   c                     |                      d          }|                                }| j        rt          dt	          |                     t          |d                   }t          |d                   }||fS )z]Get mailbox status.

        Result is tuple of 2 ints (message count, mailbox size)
        STATz*stat*r&      )rG   splitr   r'   r(   int)r   retvalretsnumMessagessizeMessagess        r   statz	POP3.stat   sh    
 ''||~~?7E(DJJ777$q'll47||\**r
   Nc                 `    ||                      d|z            S |                     d          S )a  Request listing, return result.

        Result without a message number argument is in form
        ['response', ['mesg_num octets', ...], octets].

        Result when a message number argument is given is a
        single response: the "scan listing" for that message.
        NzLIST %sLISTrG   rI   r   whichs     r   rC   z	POP3.list   s3     >>)e"3444}}V$$$r
   c                 2    |                      d|z            S )zoRetrieve whole message number 'which'.

        Result is in form ['response', ['line', ...], octets].
        zRETR %srI   rd   s     r   retrz	POP3.retr   s    
 }}Y.///r
   c                 2    |                      d|z            S )zFDelete message number 'which'.

        Result is 'response'.
        zDELE %srQ   rd   s     r   delez	POP3.dele   s    
 ~~i%/000r
   c                 ,    |                      d          S )zXDoes nothing.

        One supposes the response indicates the server is alive.
        NOOPrQ   rK   s    r   noopz	POP3.noop  s    
 ~~f%%%r
   c                 ,    |                      d          S )z(Unmark all messages marked for deletion.RSETrQ   rK   s    r   rsetz	POP3.rset  s    ~~f%%%r
   c                 X    |                      d          }|                                  |S )zDSignoff: commit changes on server, unlock mailbox, close connection.QUIT)rG   close)r   r>   s     r   quitz	POP3.quit  s%    ~~f%%

r
   c                    	 | j         }d| _         ||                                 | j        }d| _        |	 |                    t          j                   nB# t          $ r5}|j        t          j        k    rt          |dd          dk    r Y d}~nd}~ww xY w|                                 dS # |                                 w xY wdS # | j        }d| _        |	 |                    t          j                   nB# t          $ r5}|j        t          j        k    rt          |dd          dk    r Y d}~nd}~ww xY w|                                 w # |                                 w xY ww xY w)z8Close the connection without assuming anything about it.Nwinerrorr   i&'  )
r   rs   r   shutdownr#   	SHUT_RDWROSErrorerrnoENOTCONNgetattr)r   r   r   excs       r   rs   z
POP3.close  s   	!9DDI

9DDI
!MM&"23333    	U^33"3
A66%?? JJLLLLLDJJLLLL   9DDI
!MM&"23333    	U^33"3
A66%?? JJLLLLDJJLLLL  sv   $C
 A B/ 
B!+BB/ BB/ /C
E-C<;E<
D;+D61E6D;;E>E-E))E-c                 2    |                      d|z            S )zNot sure what this does.zRPOP %srQ   rR   s     r   rpopz	POP3.rpop7  s    ~~i$.///r
   s   \+OK.[^<]*(<.*>)c                 H   t          || j                  }| j                            | j                  }|st          d          ddl}|                    d          |z   }|                    |          	                                }| 
                    d|d|          S )a  Authorisation

        - only possible if server has supplied a timestamp in initial greeting.

        Args:
                user     - mailbox user;
                password - mailbox password.

        NB: mailbox is locked by server from here to 'quit()'
        z!-ERR APOP not supported by serverr   Nr&   zAPOP  )r/   r0   	timestampmatchr   r   hashlibgroupmd5	hexdigestrG   )r   rS   passwordsecretmr   digests          r   apopz	POP3.apop>  s     x//N  .. 	CABBBF"V$$..00~~~dddFF;<<<r
   c                 8    |                      d|d|          S )zRetrieve message header of message number 'which'
        and first 'howmuch' lines of message body.

        Result is in form ['response', ['line', ...], octets].
        zTOP r   rg   )r   re   howmuchs      r   topzPOP3.topS  s#     }}}EEE77;<<<r
   c                 `    ||                      d|z            S |                     d          S )zReturn message digest (unique id) list.

        If 'which', result contains unique id for that message
        in the form 'response mesgnum uid', otherwise result is
        the list ['response', ['mesgnum uid', ...], octets]
        NzUIDL %sUIDLrc   rd   s     r   uidlz	POP3.uidl\  s3     >>)e"3444}}V$$$r
   c                 ,    |                      d          S )zITry to enter UTF-8 mode (see RFC 6856). Returns server response.
        UTF8rQ   rK   s    r   utf8z	POP3.utf8h  s     ~~f%%%r
   c                     d }i }	 |                      d          }|d         }|D ]} ||          \  }}|||<   n# t          $ r t          d          w xY w|S )a   Return server capabilities (RFC 2449) as a dictionary
        >>> c=poplib.POP3('localhost')
        >>> c.capa()
        {'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],
         'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],
         'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],
         'UIDL': [], 'RESP-CODES': []}
        >>>

        Really, according to RFC 2449, the cyrus folks should avoid
        having the implementation split into multiple arguments...
        c                 t    |                      d                                          }|d         |dd          fS )Nasciir   r&   )decoderZ   )r,   lsts     r   	_parsecapzPOP3.capa.<locals>._parsecap{  s5    ++g&&,,..Cq63qrr7?"r
   CAPAr&   z!-ERR CAPA not supported by server)rI   r   )r   r   capsr>   rawcapscaplinecapnmcapargss           r   capaz	POP3.capan  s    	# 	# 	# 	C==((D1gG" & &!*7!3!3w%U&  	C 	C 	CABBB	Cs	   5= Ac                    t           st          d          | j        rt          d          |                                 }d|vrt          d          |t	          j                    }|                     d          }|                    | j        | j	                  | _        | j        
                    d          | _        d| _        |S )	z{Start a TLS session on the active connection as specified in RFC 2595.

                context - a ssl.SSLContext
        z-ERR TLS support missing$-ERR TLS session already establishedSTLSz!-ERR STLS not supported by serverNserver_hostnamer   T)HAVE_SSLr   r   r   ssl_create_stdlib_contextrG   wrap_socketr   r   r   r   )r   contextr   r>   s       r   stlsz	POP3.stls  s    
  	:8999  	FDEEEyy{{~~ABBB?022G~~f%%''	8<	 ( C C	I&&t,,	 $r
   rF   )'r   r   r   __doc__r0   	POP3_PORTr#   _GLOBAL_DEFAULT_TIMEOUTr    r   r-   r1   r:   r   rD   rG   rI   rL   rO   rS   rV   r`   rC   rh   rj   rm   rp   rt   rs   r   recompiler   r   r   r   r   r   r   r	   r
   r   r   r   3   s       ) )V H"+7	' 	' 	' 	'I I I
' ' '  ! ! !*  " " "   # # #       0 0 00 0 0
+ 
+ 
+% % % %0 0 01 1 1& & && & &
  ! ! !80 0 0
 
/00I= = =*= = =	% 	% 	% 	%& & &  :     r
   c                   <    e Zd ZdZeddej        dfdZd ZddZ	dS )POP3_SSLa  POP3 client class over SSL connection

        Instantiate with: POP3_SSL(hostname, port=995, keyfile=None, certfile=None,
                                   context=None)

               hostname - the hostname of the pop3 over ssl server
               port - port number
               keyfile - PEM formatted file that contains your private key
               certfile - PEM formatted certificate chain file
               context - a ssl.SSLContext

        See the methods of the parent class POP3 for more documentation.
        Nc                 .   ||t          d          ||t          d          || dd l}|                    dt          d           || _        || _        |t          j        ||          }|| _        t          
                    | |||           d S )Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiver   zAkeyfile and certfile are deprecated, use a custom context insteadrY   )certfilekeyfile)r"   warningswarnDeprecationWarningr   r   r   r   r   r   r    )r   r   r   r   r   r   r   r   s           r   r    zPOP3_SSL.__init__  s    "w':  "- . . ."x';  "- . . ."h&: 78JAO O O"DL$DM4h=DF F F"DLMM$dG44444r
   c                 ~    t                               | |          }| j                            || j                  }|S )Nr   )r   r   r   r   r   )r   r   r   s      r   r   zPOP3_SSL._create_socket  sA    &&tW55D<++D<@I , G GDKr
   c                      t          d          )zThe method unconditionally raises an exception since the
            STLS command doesn't make any sense on an already established
            SSL/TLS session.
            r   )r   )r   r   r   r   s       r   r   zPOP3_SSL.stls  s    
 DEEEr
   )NNN)
r   r   r   r   POP3_SSL_PORTr#   r   r    r   r   r	   r
   r   r   r     sl        	 	 '4TD#;T	5 	5 	5 	5(	 	 		F 	F 	F 	F 	F 	Fr
   r   __main__r&   rY      zMessage %d:z   z-----------------------)'r   rz   r   r#   r   r   r   ImportError__all__	Exceptionr   r   r   r8   LFr*   r6   r   r   rB   r   argvar'   rL   rS   rV   rC   r`   numMsgs	totalSizerangeirh   headermsgr9   r,   rt   r	   r
   r   <module>r      so     				  



JJJHH   HHH -
  # " " " ") " " " 	  
	"u k k k k k k k k\  2.F .F .F .F .F4 .F .F .F` NN:zJJJSXa[A	E!,,..FF38A;GGCHQKFFHHH6688WiU1gk"" ) ) !q		fma    	  	 DE%$,'((((FFHHHHH s    %%