o w[e^;@shdZddlZddlZddlZddlZzddlZdZWn ey%dZYnwddgZGddde Z dZ d Z d Z d Ze eZd ZGd ddZerVGdddeZededkrddlZeejdZeeeejdeejdee\ZZededD]Z e!e \Z"Z#Z$ede e#D]Z%ede%qedqe&dSdS)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.10/poplib.pyrs ni  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__cCs(|dur |s tdt|j|jf|S)Nz0Non-blocking socket (timeout=0) is not supported) ValueErrorsocketcreate_connectionr r)rrrrrrms zPOP3._create_socketcCs:|jdkr tdt|td|||j|tdS)Nz*put*zpoplib.putline)rprintreprrrrsendallCRLFrlinerrr_putlinersz POP3._putlinecCs.|jr tdt|t||j}||dS)Nz*cmd*)rr r!bytesencodingr&r$rrr_putcmdzs z POP3._putcmdcCs|jtd}t|tkrtd|jdkrtdt||s$tdt|}|ddtkr8|dd|fS|ddt krH|dd|fS|dd|fS)Nrz line too longz*get*z-ERR EOF) rreadline_MAXLINElenrrr r!r#CR)rr%octetsrrr_getlines  z POP3._getlinecCs:|\}}|jdkrtdt||dst||S)Nrz*resp*+)r1rr r! startswithr)rresporrrrs  z POP3._getrespcCsr|}g}d}|\}}|dkr4|dr!|d}|dd}||}|||\}}|dks|||fS)Nr.s..r)rr1r3append)rr4listr0r%r5rrr _getlongresps      zPOP3._getlongrespcC|||SN)r)rr$rrr _shortcmd zPOP3._shortcmdcCr:r;)r)r9r$rrr_longcmdr=z POP3._longcmdcCs|jSr;)rrrrr getwelcomeszPOP3.getwelcomecCs ||_dSr;)r)rlevelrrrset_debuglevels zPOP3.set_debuglevelcC|d|S)zVSend user name, return response (should indicate password required). zUSER %sr<ruserrrrrFz POP3.usercCrC)zSend password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' zPASS %srD)rpswdrrrpass_sz POP3.pass_cCsF|d}|}|jrtdt|t|d}t|d}||fS)z]Get mailbox status. Result is tuple of 2 ints (message count, mailbox size) STATz*stat*r)r<splitrr r!int)rretvalrets numMessages sizeMessagesrrrstats   z POP3.statNcC |dur |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 %sLISTr<r>rwhichrrrr8s  z POP3.listcCrC)zoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. zRETR %sr>rVrrrretrrGz POP3.retrcCrC)zFDelete message number 'which'. Result is 'response'. zDELE %srDrVrrrdelerGz POP3.delecC |dS)zXDoes nothing. One supposes the response indicates the server is alive. NOOPrDr?rrrnoops z POP3.noopcCr[)z(Unmark all messages marked for deletion.RSETrDr?rrrrsets z POP3.rsetcCs|d}||S)zDSignoff: commit changes on server, unlock mailbox, close connection.QUIT)r<close)rr4rrrquits z POP3.quitcCsBzY|j}d|_|dur|W|j}d|_|durXz8z|tjWn!tyD}z|jtjkr:t |dddkr:WYd}~n d}~wwW|dSW|dS|wdS|j}d|_|durz6z|tjWn!ty}z|jtjkrt |dddkrWYd}~n d}~wwW|wW|w|ww)z8Close the connection without assuming anything about it.Nwinerrorri&') rrarshutdownr SHUT_RDWROSErrorerrnoENOTCONNgetattr)rrrexcrrrrasL    z POP3.closecCrC)zNot sure what this does.zRPOP %srDrErrrrpop7sz POP3.rpops\+OK.[^<]*(<.*>)cCs\t||j}|j|j}|stdddl}|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( timestampmatchrrhashlibgroupmd5 hexdigestr<)rrFpasswordsecretmrndigestrrrapop>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 %srX)rrWhowmuchrrrtopSszPOP3.topcCrS)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 %sUIDLrUrVrrruidl\s z POP3.uidlcCr[)zITry to enter UTF-8 mode (see RFC 6856). Returns server response. UTF8rDr?rrrutf8hs z POP3.utf8cCsZdd}i}z|d}|d}|D] }||\}}|||<qW|Sty,tdw)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)decoderL)r%lstrrr _parsecap{szPOP3.capa.._parsecapCAPArz!-ERR CAPA not supported by server)r>r)rrcapsr4rawcapscaplinecapnmcapargsrrrcapans     z POP3.capacCsxtstd|jr td|}d|vrtd|dur!t}|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 establishedSTLSz!-ERR STLS not supported by serverNserver_hostnamer T) HAVE_SSLrrrssl_create_stdlib_contextr< wrap_socketrr rr)rcontextrr4rrrstlss  z POP3.stlsr;)'rrr__doc__r( POP3_PORTr_GLOBAL_DEFAULT_TIMEOUTrrr&r)r1rr9r<r>r@rBrFrIrRr8rYrZr]r_rbrarkrecompilerlrvrxrzr|rrrrrrr3sD+        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|dur |dur td|dur|durtd|dus |dur+ddl}|dtd||_||_|dursR p 0