o ?Og^;@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-/opt/alt/python310/lib64/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) ValueErrorsocketZcreate_connectionr r)rrrrrrms zPOP3._create_socketcCs:|jdkr tdt|td|||j|tdS)Nz*put*zpoplib.putline)rprintreprrrrZsendallCRLFrlinerrr_putlinersz POP3._putlinecCs.|jr tdt|t||j}||dS)Nz*cmd*)rrr 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_MAXLINElenrrrr r!CR)rr#octetsrrr_getlines  z POP3._getlinecCs:|\}}|jdkrtdt||dst||S)Nrz*resp*+)r/rrr startswithr)rresporrrrs  z POP3._getrespcCsr|}g}d}|\}}|dkr4|dr!|d}|dd}||}|||\}}|dks|||fS)Nr.s..r)rr/r1append)rr2listr.r#r3rrr _getlongresps      zPOP3._getlongrespcC|||SN)r'rr"rrr _shortcmd zPOP3._shortcmdcCr8r9)r'r7r"rrr_longcmdr;z POP3._longcmdcCs|jSr9)rrrrr getwelcomeszPOP3.getwelcomecCs ||_dSr9)r)rlevelrrrset_debuglevels zPOP3.set_debuglevelcC|d|S)zVSend user name, return response (should indicate password required). zUSER %sr:ruserrrrrDz POP3.usercCrA)zSend password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' zPASS %srB)rZpswdrrrpass_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) ZSTATz*stat*r)r:splitrrr int)rZretvalZretsZ numMessagesZ 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 %sZLISTr:r<rwhichrrrr6s  z POP3.listcCrA)zoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. zRETR %sr<rMrrrretrrEz POP3.retrcCrA)zFDelete message number 'which'. Result is 'response'. zDELE %srBrMrrrdelerEz POP3.delecC |dS)zXDoes nothing. One supposes the response indicates the server is alive. ZNOOPrBr=rrrnoops z POP3.noopcCrR)z(Unmark all messages marked for deletion.ZRSETrBr=rrrrsets z POP3.rsetcCs|d}||S)zDSignoff: commit changes on server, unlock mailbox, close connection.ZQUIT)r:close)rr2rrrquits 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.NZwinerrorri&') rrUrZshutdownrZ SHUT_RDWROSErrorerrnoZENOTCONNgetattr)rrrexcrrrrUsL    z POP3.closecCrA)zNot sure what this does.zRPOP %srBrCrrrrpop7sz 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& timestampmatchrrhashlibgroupZmd5Z hexdigestr:)rrDZpasswordZsecretmr^Zdigestrrrapop>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 %srO)rrNZhowmuchrrrtopSszPOP3.topcCrK)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 %sZUIDLrLrMrrruidl\s z POP3.uidlcCrR)zITry to enter UTF-8 mode (see RFC 6856). Returns server response. ZUTF8rBr=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)decoderH)r#Zlstrrr _parsecap{szPOP3.capa.._parsecapZCAPArz!-ERR CAPA not supported by server)r<r)rrgcapsr2ZrawcapsZcaplineZcapnmZcapargsrrrcapans     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 establishedZSTLSz!-ERR STLS not supported by serverNZserver_hostnamer T) HAVE_SSLrrrissl_create_stdlib_contextr: wrap_socketrr rr)rcontextrhr2rrrstlss  z POP3.stlsr9)'rrr__doc__r& POP3_PORTr_GLOBAL_DEFAULT_TIMEOUTrrr$r'r/rr7r:r<r>r@rDrFrJr6rPrQrSrTrVrUr[recompiler\rarbrcrdrirqrrrrr3sD+        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||_||_|durrDrFr6rJZnumMsgsZ totalSizerangeirPheadermsgr.r#rVrrrrsR p 0