U kg:@sldZddlZddlZddlZddlZzddlZdZWnek rLdZYnXddgZGddde Z dZ d Z d Z d Ze eZd ZGd ddZerGdddeZededkrhddlZeejdZeeeejdeejdee\ZZededD]BZ e!e \Z"Z#Z$ede e#D]Z%ede%q@edqe&dS)z@A POP3 client class. Based on the J. Myers POP3 draft, Jan. 96 NTFPOP3 error_protoc@s eZdZdS)rN)__name__ __module__ __qualname__rr/usr/lib/python3.8/poplib.pyrsni  ic@s eZdZdZdZeejfddZddZ ddZ d d Z d d Z d dZ ddZddZddZddZddZddZddZddZd=d d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zed0Z d1d2Z!d3d4Z"d>d5d6Z#d7d8Z$d9d:Z%d?d;d<Z&dS)@raPThis 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. zUTF-8cCsP||_||_d|_td||||||_|jd|_d|_ | |_ dS)NFzpoplib.connectrbr) hostport_tls_establishedsysaudit_create_socketsockmakefilefile _debugging_getrespwelcome)selfr rtimeoutrrr__init__bs z POP3.__init__cCst|j|jf|SN)socketZcreate_connectionr r)rrrrrrmszPOP3._create_socketcCs:|jdkrtdt|td|||j|tdS)Nz*put*zpoplib.putline)rprintreprrrrZsendallCRLFrlinerrr_putlineps z POP3._putlinecCs.|jrtdt|t||j}||dS)Nz*cmd*)rrr bytesencodingr$r"rrr_putcmdxs z POP3._putcmdcCs|jtd}t|tkr$td|jdkr)rZpswdrrrpass_sz POP3.pass_cCsF|d}|}|jr&tdt|t|d}t|d}||fS)z]Get mailbox status. Result is tuple of 2 ints (message count, mailbox size) ZSTATz*stat*r)r8splitrrr int)rZretvalZretsZ numMessagesZ sizeMessagesrrrstats   z POP3.statNcCs |dk r|d|S|dS)aRequest 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. NzLIST %sZLISTr8r9rwhichrrrr6s z POP3.listcCs|d|S)zoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. zRETR %sr9rGrrrretrsz POP3.retrcCs|d|S)zFDelete message number 'which'. Result is 'response'. zDELE %sr>rGrrrdelesz POP3.delecCs |dS)zXDoes nothing. One supposes the response indicates the server is alive. ZNOOPr>r:rrrnoopsz POP3.noopcCs |dS)z(Unmark all messages marked for deletion.ZRSETr>r:rrrrsetsz POP3.rsetcCs|d}||S)zDSignoff: commit changes on server, unlock mailbox, close connection.ZQUIT)r8close)rr2rrrquits z POP3.quitcCsz |j }d|_ |dk r|W5|j}d|_|dk rzVz|tjWn@tk r}z"|jtjkrxt|dddkrxW5d}~XYnXW5|XXdS)z8Close the connection without assuming anything about it.NZwinerrorri&') rrNZshutdownrZ SHUT_RDWROSErrorerrnoZENOTCONNgetattrr)rrexcrrrrrNs   z POP3.closecCs|d|S)zNot sure what this does.zRPOP %sr>r?rrrrpop5sz POP3.rpops\+OK.[^<]*(<.*>)cCs\t||j}|j|j}|s&tdddl}|d|}|| }| d||fS)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 serverrNrz APOP %s %s) r%r& timestampmatchrrhashlibgroupZmd5Z hexdigestr8)rr@ZpasswordZsecretmrWZdigestrrrapop<s z POP3.apopcCs|d||fS)zRetrieve message header of message number 'which' and first 'howmuch' lines of message body. Result is in form ['response', ['line', ...], octets]. z TOP %s %srI)rrHZhowmuchrrrtopQszPOP3.topcCs |dk r|d|S|dS)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] NzUIDL %sZUIDLrFrGrrruidlZsz POP3.uidlcCs |dS)zITry to enter UTF-8 mode (see RFC 6856). Returns server response. ZUTF8r>r:rrrutf8fsz POP3.utf8c Cspdd}i}z4|d}|d}|D]}||\}}|||<q$Wn*tk rj}z tdW5d}~XYnX|S)aReturn 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... cSs"|d}|d|ddfS)Nasciirr)decoderC)r#Zlstrrr _parsecapyszPOP3.capa.._parsecapZCAPArz!-ERR CAPA not supported by serverN)r9r) rr`capsr2ZrawcapsZcaplineZcapnmZcapargsZ_errrrrcapals   z POP3.capacCsxts td|jrtd|}d|kr2td|dkrBt}|d}|j|j|j d|_|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 establishedZSTLSz!-ERR STLS not supported by serverNZserver_hostnamer T) HAVE_SSLrrrbssl_create_stdlib_contextr8 wrap_socketrr rr)rcontextrar2rrrstlss  z POP3.stls)N)N)N)'rrr__doc__r& POP3_PORTr_GLOBAL_DEFAULT_TIMEOUTrrr$r'r/rr7r8r9r;r=r@rArEr6rJrKrLrMrOrNrTrecompilerUrZr[r\r]rbrjrrrrr3sB+       c@s8eZdZdZeddejdfddZddZd ddZ dS) POP3_SSLaPOP3 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. NcCs|dk r|dk rtd|dk r0|dk r0td|dk s@|dk rVddl}|dtd||_||_|dkrxtj||d}||_t ||||dS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiverzAkeyfile and certfile are deprecated, use a custom context insteadrB)certfilekeyfile) ValueErrorwarningswarnDeprecationWarningrrrqrfrgrirr)rr rrrrqrrirtrrrrs$zPOP3_SSL.__init__cCs"t||}|jj||jd}|S)Nrd)rrrirhr )rrrrrrrs  zPOP3_SSL._create_socketcCs tddS)zThe method unconditionally raises an exception since the STLS command doesn't make any sense on an already established SSL/TLS session. rcN)r)rrrrqrirrrrjsz POP3_SSL.stls)NNN) rrrrk POP3_SSL_PORTrrmrrrjrrrrrps rp__main__rrBz Message %d:z z-----------------------)'rkrQrnrrrfre ImportError__all__ Exceptionrrlrwr-ZLFr!r+rrpr5rargvarr;r@rAr6rEZnumMsgsZ totalSizerangeirJheadermsgr.r#rOrrrrsL n0