
    F\h9                        S r SSKrSSKrSSKrSSKr SSKrSrSS/r " S S\	5      r
SrS	rS
rSr\\-   rSr " S S5      r\(       a   " S S\5      r\R'                  S5        \S:X  a  \" \R*                  S   5      r\" \R1                  5       5        \R3                  \R*                  S   5        \R5                  \R*                  S   5        \R7                  5         \R9                  5       u  rr\" S\S-   5       H?  r \RC                  \ 5      u  r"r#r$\" S\ -  5        \# H  r%\" S\%-   5        M     \" S5        MA     \RM                  5         gg! \ a    Sr GNGf = f)z@A POP3 client class.

Based on the J. Myers POP3 draft, Jan. 96
    NTFPOP3error_protoc                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       /usr/lib/python3.13/poplib.pyr   r      s    dr   n   i        
i   c                      \ rS rSrSrSr\\R                  4S jr	S r
S rS rS rS	 rS
 rS rS rS rS rS rS rS rS#S jrS rS rS rS rS rS rS r\R@                  " S5      r!S r"S r#S#S jr$S r%S  r&S#S! jr'S"r(g)$r   3   a  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                     Xl         X l        SU l        [        R                  " SXU5        U R                  U5      U l        U R                  R                  S5      U l        SU l	        U R                  5       U l        g )NFzpoplib.connectrbr   )hostport_tls_establishedsysaudit_create_socketsockmakefilefile
_debugging_getrespwelcome)selfr   r   timeouts       r   __init__POP3.__init__b   sa    		 %		"D5''0	II&&t,	}}r   c                     Ub  U(       d  [        S5      e[        R                  " U R                  U R                  4U5      $ )Nz0Non-blocking socket (timeout=0) is not supported)
ValueErrorsocketcreate_connectionr   r   )r"   r#   s     r   r   POP3._create_socketm   s6    wOPP''DII(>HHr   c                     U R                   S:  a  [        S[        U5      5        [        R                  " SX5        U R
                  R                  U[        -   5        g )N   z*put*zpoplib.putline)r   printreprr   r   r   sendallCRLFr"   lines     r   _putlinePOP3._putliner   s@    ??QgtDz :		"D/		$+&r   c                     U R                   (       a  [        S[        U5      5        [        XR                  5      nU R                  U5        g )Nz*cmd*)r   r-   r.   bytesencodingr3   r1   s     r   _putcmdPOP3._putcmdz   s0    ??E'4:6T==)dr   c                 d   U R                   R                  [        S-   5      n[        U5      [        :  a  [	        S5      eU R
                  S:  a  [        S[        U5      5        U(       d  [	        S5      e[        U5      nUSS  [        :X  a  US S U4$ US S [        :X  a  USS U4$ US S U4$ )Nr,   zline too longz*get*z-ERR EOF)
r   readline_MAXLINElenr   r   r-   r.   r0   CR)r"   r2   octetss      r   _getlinePOP3._getline   s    yy!!(Q,/t9xo..??QgtDz :;z22T 99f$$8r>":v%%CRy&  r   c                     U R                  5       u  pU R                  S:  a  [        S[        U5      5        UR	                  S5      (       d  [        U5      eU$ )Nr,   z*resp*   +)rB   r   r-   r.   
startswithr   )r"   respos      r   r    POP3._getresp   sG    --/??QhT
 ;t$$d##r   c                     U R                  5       n/ nSnU R                  5       u  pEUS:w  aO  UR                  S5      (       a
  US-
  nUSS  nX5-   nUR                  U5        U R                  5       u  pEUS:w  a  MO  XU4$ )Nr      .s   ..r,   )r    rB   rF   append)r"   rG   listrA   r2   rH   s         r   _getlongrespPOP3._getlongresp   s    }}A6--/dlu%%aCABxZFKKmmoGD dl 6!!r   c                 D    U R                  U5        U R                  5       $ N)r8   r    r1   s     r   	_shortcmdPOP3._shortcmd   s    T}}r   c                 D    U R                  U5        U R                  5       $ rQ   )r8   rN   r1   s     r   _longcmdPOP3._longcmd   s    T  ""r   c                     U R                   $ rQ   )r!   r"   s    r   
getwelcomePOP3.getwelcome   s    ||r   c                     Xl         g rQ   )r   )r"   levels     r   set_debuglevelPOP3.set_debuglevel   s    r   c                 *    U R                  SU-  5      $ )zFSend user name, return response

(should indicate password required).
zUSER %srR   r"   users     r   rb   	POP3.user   s    
 ~~i$.//r   c                 *    U R                  SU-  5      $ )zSend password, return response

(response includes message count, mailbox size).

NB: mailbox is locked by server from here to 'quit()'
zPASS %sr`   )r"   pswds     r   pass_
POP3.pass_   s     ~~i$.//r   c                 6   U R                  S5      nUR                  5       nU R                  (       a  [        S[	        U5      5        [        U5      S:  a  [        S5      e [        US   5      n[        US   5      nX44$ ! [         a    [        S5      ef = f)zMGet mailbox status.

Result is tuple of 2 ints (message count, mailbox size)
STATz*stat*   zInvalid STAT response formatr,      z.Invalid STAT response data: non-numeric values)	rR   splitr   r-   r.   r?   r   intr'   )r"   retvalretsnumMessagessizeMessagess        r   stat	POP3.stat   s    
 '||~??E(DJ7
 t9q=<==	Pd1g,KtAw<L **  	PNOO	Ps   #B BNc                 R    Ub  U R                  SU-  5      $ U R                  S5      $ )zRequest 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.
zLIST %sLISTrR   rU   r"   whichs     r   rM   	POP3.list   s-     >>)e"344}}V$$r   c                 *    U R                  SU-  5      $ )z_Retrieve whole message number 'which'.

Result is in form ['response', ['line', ...], octets].
zRETR %srU   rw   s     r   retr	POP3.retr  s    
 }}Y.//r   c                 *    U R                  SU-  5      $ )z6Delete message number 'which'.

Result is 'response'.
zDELE %sr`   rw   s     r   dele	POP3.dele  s    
 ~~i%/00r   c                 $    U R                  S5      $ )zHDoes nothing.

One supposes the response indicates the server is alive.
NOOPr`   rX   s    r   noop	POP3.noop  s    
 ~~f%%r   c                 $    U R                  S5      $ )z(Unmark all messages marked for deletion.RSETr`   rX   s    r   rset	POP3.rset  s    ~~f%%r   c                 H    U R                  S5      nU R                  5         U$ )zDSignoff: commit changes on server, unlock mailbox, close connection.QUIT)rR   close)r"   rG   s     r   quit	POP3.quit   s    ~~f%

r   c                     U R                   nSU l         Ub  UR                  5         U R                  nSU l        Ub1   UR                  [        R
                  5        UR                  5         gg! [         a:  nUR                  [        R                  :w  a  [        USS5      S:w  a  e  SnANQSnAff = f! UR                  5         f = f! U R                  nSU l        Ub   UR                  [        R
                  5        OG! [         a:  nUR                  [        R                  :w  a  [        USS5      S:w  a  e  SnAOSnAff = fUR                  5         f ! UR                  5         f = ff = f)z8Close the connection without assuming anything about it.Nwinerrorr   i&'  )
r   r   r   shutdownr(   	SHUT_RDWROSErrorerrnoENOTCONNgetattr)r"   r   r   excs       r   r   
POP3.close&  s)   	!99DDI

99DDI
!MM&"2"23 JJL     		U^^3"3
A6%? JJL 99DDI
!MM&"2"23  		U^^3"3
A6%? JJLDJJL  sp   &C A0 0
B4:0B/*B7 /B44B7 7C	E2$DE
E0E>EEEE2E..E2c                 *    U R                  SU-  5      $ )z?Send RPOP command to access the mailbox with an alternate user.zRPOP %sr`   ra   s     r   rpop	POP3.rpopB  s    ~~i$.//r   s   \+OK.[^<]*(<.*>)c                 :   [        X R                  5      nU R                  R                  U R                  5      nU(       d  [        S5      eSSKnUR                  S5      U-   nUR                  U5      R                  5       nU R                  SU< SU< 35      $ )zAuthorisation

- 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  )r6   r7   	timestampmatchr!   r   hashlibgroupmd5	hexdigestrR   )r"   rb   passwordsecretmr   digests          r   apop	POP3.apopI  sy     x/NN  .ABBF"V$..0~~dF;<<r   c                 4    U R                  SU< SU< 35      $ )zRetrieve message header of message number 'which'
and first 'howmuch' lines of message body.

Result is in form ['response', ['line', ...], octets].
zTOP r   r{   )r"   rx   howmuchs      r   topPOP3.top^  s     }}E7;<<r   c                 R    Ub  U R                  SU-  5      $ U R                  S5      $ )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]
zUIDL %sUIDLrv   rw   s     r   uidl	POP3.uidlg  s-     >>)e"344}}V$$r   c                 $    U R                  S5      $ )zITry to enter UTF-8 mode (see RFC 6856). Returns server response.
        UTF8r`   rX   s    r   utf8	POP3.utf8s  s     ~~f%%r   c                     S n0 n U R                  S5      nUS   nU H  nU" U5      u  pgXrU'   M     U$ ! [         a    [        S5      ef = f)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    U R                  S5      R                  5       nUS   USS  4$ )Nasciir   r,   )decoderl   )r2   lsts     r   	_parsecapPOP3.capa.<locals>._parsecap  s-    ++g&,,.Cq63qr7?"r   CAPAr,   z!-ERR CAPA not supported by server)rU   r   )r"   r   capsrG   rawcapscaplinecapnmcapargss           r   capa	POP3.capay  sn    	# 	C==(D1gG"!*7!3%U #
   	CABB	Cs	   -6 Ac                    [         (       d  [        S5      eU R                  (       a  [        S5      eU R                  5       nSU;  a  [        S5      eUc  [        R
                  " 5       nU R                  S5      nUR                  U R                  U R                  S9U l        U R                  R                  S5      U l        SU l        U$ )zcStart 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 serverserver_hostnamer   T)HAVE_SSLr   r   r   ssl_create_stdlib_contextrR   wrap_socketr   r   r   r   )r"   contextr   rG   s       r   stls	POP3.stls  s    
 x899  DEEyy{~ABB?002G~~f%''		8<		 ( C	II&&t,	 $r   )r   r   r   r   r   r   r!   rQ   ))r   r	   r
   r   __doc__r7   	POP3_PORTr(   _GLOBAL_DEFAULT_TIMEOUTr$   r   r3   r8   rB   r    rN   rR   rU   rY   r]   rb   rf   rr   rM   r|   r   r   r   r   r   r   recompiler   r   r   r   r   r   r   r   r   r   r   r   r   3   s    )V H"+77	'I
'!*" # 00+0%01&&
!80
 

/0I=*=	%&:r   c                   R    \ rS rSrSr\4\R                  SS.S jjrS r	S	S jr
Srg)
POP3_SSLi  a  POP3 client class over SSL connection

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

       hostname - the hostname of the pop3 over ssl server
       port - port number
       context - a ssl.SSLContext

See the methods of the parent class POP3 for more documentation.
N)r#   r   c                l    Uc  [         R                  " 5       nX@l        [        R	                  XX#5        g rQ   )r   r   r   r   r$   )r"   r   r   r#   r   s        r   r$   POP3_SSL.__init__  s(    446"LMM$d4r   c                 x    [         R                  X5      nU R                  R                  UU R                  S9nU$ )Nr   )r   r   r   r   r   )r"   r#   r   s      r   r   POP3_SSL._create_socket  s:    &&t5D<<++D<@II , GDKr   c                     [        S5      e)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   s     r   r   POP3_SSL.stls  s    
 DEEr   )r   rQ   )r   r	   r
   r   r   POP3_SSL_PORTr(   r   r$   r   r   r   r   r   r   r   r     s,    		 '4 	5 & > >	5		Fr   r   __main__r,   rk   rj   zMessage %d:z   z-----------------------)'r   r   r   r(   r   r   r   ImportError__all__	Exceptionr   r   r   r@   LFr0   r>   r   r   rL   r   argvar-   rY   rb   rf   rM   rr   numMsgs	totalSizerangeir|   headermsgrA   r2   r   r   r   r   <module>r      sy    	  
H -
  #) " 	  
	"u v vr F4 F@ NN:zSXXa[A	!,,.FF388A;GGCHHQKFFH668Wi1gk" !q	fma D%$, '( # FFH q  Hs   E E"!E"