grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î   fï7ã @sádZddlZddlZddlZyddlZdZWnek rZdZYnXddgZGdd„deƒZ dZ d Z d Z d Z e e Zd ZGd d„dƒZeräGdd„deƒZejdƒnedkrÝddlZeejdƒZeejƒƒejejdƒejejdƒejƒejƒ\ZZxjededƒD]UZ ej!e ƒ\Z"Z#Z$ede ƒxe#D]Z%ede%ƒqªWedƒqwWej&ƒndS)z@A POP3 client class. Based on the J. Myers POP3 draft, Jan. 96 éNTFÚPOP3Ú error_protoc@seZdZdS)rN)Ú__name__Ú __module__Ú __qualname__©rrú+/opt/alt/python34/lib64/python3.4/poplib.pyrs éniãs s ic@s�eZdZdZdZeejdd„Zdd„Z dd„Z d d „Z d d „Z d d„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zejd0ƒZ d1d2„Z!d3d4„Z"dd5d6„Z#d7d8„Z$dd9d:„Z%dS);ra%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() 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-8cCs^||_||_d|_|j|ƒ|_|jjdƒ|_d|_|jƒ|_ dS)NFÚrbr) ÚhostÚportÚ_tls_establishedÚ_create_socketÚsockÚmakefileÚfileÚ _debuggingÚ_getrespÚwelcome)Úselfr r ÚtimeoutrrrÚ__init__`s    z POP3.__init__cCstj|j|jf|ƒS)N)ÚsocketZcreate_connectionr r )rrrrrrjszPOP3._create_socketcCs=|jdkr%tdt|ƒƒn|jj|tƒdS)Néz*put*)rÚprintÚreprrZsendallÚCRLF)rÚlinerrrÚ_putlinemsz POP3._putlinecCsB|jrtdt|ƒƒnt||jƒ}|j|ƒdS)Nz*cmd*)rrrÚbytesÚencodingr)rrrrrÚ_putcmdts z POP3._putcmdcCså|jjtdƒ}t|ƒtkr7tdƒ‚n|jdkr\tdt|ƒƒn|sqtdƒ‚nt|ƒ}|dd…tkr§|dd…|fS|dd…t krÑ|dd…|fS|dd …|fS) Nrz line too longz*get*z-ERR EOFééþÿÿÿr#éÿÿÿÿr$) rÚreadlineÚ_MAXLINEÚlenrrrrrÚCR)rrÚoctetsrrrÚ_getline~s z POP3._getlinecCsY|jƒ\}}|jdkr7tdt|ƒƒn|jdƒsUt|ƒ‚n|S)Nrz*resp*ó+)r*rrrÚ startswithr)rÚrespÚorrrr“s z POP3._getrespcCsŸ|jƒ}g}d}|jƒ\}}xe|dkr‘|jdƒre|d}|dd…}n||}|j|ƒ|jƒ\}}q-W|||fS)Nró.s..r)rr*r,Úappend)rr-Úlistr)rr.rrrÚ _getlongresp�s    zPOP3._getlongrespcCs|j|ƒ|jƒS)N)r!r)rrrrrÚ _shortcmd­s zPOP3._shortcmdcCs|j|ƒ|jƒS)N)r!r2)rrrrrÚ_longcmd´s z POP3._longcmdcCs|jS)N)r)rrrrÚ getwelcome»szPOP3.getwelcomecCs ||_dS)N)r)rÚlevelrrrÚset_debuglevel¿szPOP3.set_debuglevelcCs|jd|ƒS)zVSend user name, return response (should indicate password required). zUSER %s)r3)rÚuserrrrr8Åsz POP3.usercCs|jd|ƒS)z Send password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' zPASS %s)r3)rZpswdrrrÚpass_Ísz POP3.pass_cCsd|jdƒ}|jƒ}|jr:tdt|ƒƒnt|dƒ}t|dƒ}||fS)z]Get mailbox status. Result is tuple of 2 ints (message count, mailbox size) ZSTATz*stat*rr")r3ÚsplitrrrÚint)rZretvalZretsZ numMessagesZ sizeMessagesrrrÚstat×s  z POP3.statNcCs*|dk r|jd|ƒS|jdƒS)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 %sZLIST)r3r4)rÚwhichrrrr1äs z POP3.listcCs|jd|ƒS)zoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. zRETR %s)r4)rr=rrrÚretròsz POP3.retrcCs|jd|ƒS)zFDelete message number 'which'. Result is 'response'. zDELE %s)r3)rr=rrrÚdeleúsz POP3.delecCs |jdƒS)zXDoes nothing. One supposes the response indicates the server is alive. ZNOOP)r3)rrrrÚnoopsz POP3.noopcCs |jdƒS)z(Unmark all messages marked for deletion.ZRSET)r3)rrrrÚrset sz POP3.rsetcCs|jdƒ}|jƒ|S)zDSignoff: commit changes on server, unlock mailbox, close connection.ZQUIT)r3Úclose)rr-rrrÚquits z POP3.quitcCs¾z/|j}d|_|dk r.|jƒnWd|j}d|_|dk r¹zXy|jtjƒWn=tk r¦}z|jtjkr”‚nWYdd}~XnXWd|jƒXnXdS)z8Close the connection without assuming anything about it.N) rrBrZshutdownrZ SHUT_RDWRÚOSErrorÚerrnoZENOTCONN)rrrÚerrrrBs      z POP3.closecCs|jd|ƒS)zNot sure what this does.zRPOP %s)r3)rr8rrrÚrpop.sz POP3.rpops\+OK.[^<]*(<.*>)cCs‡t||jƒ}|jj|jƒ}|s<tdƒ‚nddl}|jdƒ|}|j|ƒj ƒ}|j d||fƒ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 serverrNrz APOP %s %s) rr Ú timestampÚmatchrrÚhashlibÚgroupZmd5Z hexdigestr3)rr8ZpasswordZsecretÚmrJZdigestrrrÚapop5s  z POP3.apopcCs|jd||fƒS)z­Retrieve message header of message number 'which' and first 'howmuch' lines of message body. Result is in form ['response', ['line', ...], octets]. z TOP %s %s)r4)rr=ZhowmuchrrrÚtopJszPOP3.topcCs*|dk r|jd|ƒS|jdƒS)zìReturn 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 %sZUIDL)r3r4)rr=rrrÚuidlSs z POP3.uidlc Cs”dd„}i}yJ|jdƒ}|d}x*|D]"}||ƒ\}}|||>> 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-|jdƒjƒ}|d|dd…fS)NÚasciirr)Údecoder:)rZlstrrrÚ _parsecaplszPOP3.capa.._parsecapZCAPArz!-ERR CAPA not supported by serverN)r4r) rrRÚcapsr-ZrawcapsZcaplineZcapnmZcapargsZ_errrrrÚcapa_s   z POP3.capacCs¾tstdƒ‚n|jr-tdƒ‚n|jƒ}d|krTtdƒ‚n|dkrotjƒ}n|jdƒ}|j|jd|j ƒ|_|jj 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 missingz$-ERR TLS session already establishedZSTLSz!-ERR STLS not supported by serverNÚserver_hostnamer T) ÚHAVE_SSLrr rTÚsslÚ_create_stdlib_contextr3Ú wrap_socketrr rr)rÚcontextrSr-rrrÚstls|s     z POP3.stls)&rrrÚ__doc__r Ú POP3_PORTrÚ_GLOBAL_DEFAULT_TIMEOUTrrrr!r*rr2r3r4r5r7r8r9r<r1r>r?r@rArCrBrGÚreÚcompilerHrMrNrOrTr[rrrrr2s> *                    c@sUeZdZdZeddejddd„Zdd„Zddddd„Z 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 r'tdƒ‚n|dk rN|dk rNtdƒ‚n||_||_|dkr‡tjd|d|ƒ}n||_tj||||ƒdS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiveÚcertfileÚkeyfile)Ú ValueErrorrcrbrWrXrZrr)rr r rcrbrrZrrrr£s     zPOP3_SSL.__init__cCs1tj||ƒ}|jj|d|jƒ}|S)NrU)rrrZrYr )rrrrrrr³s zPOP3_SSL._create_socketcCstdƒ‚dS)z¬The method unconditionally raises an exception since the STLS command doesn't make any sense on an already established SSL/TLS session. z$-ERR TLS session already establishedN)r)rrcrbrZrrrr[¹sz POP3_SSL.stls) rrrr\Ú POP3_SSL_PORTrr^rrr[rrrrra”s   raÚ__main__rr"éz Message %d:z z-----------------------)'r\rEr_rrWrVÚ ImportErrorÚ__all__Ú Exceptionrr]rer(ZLFrr&rrar0rÚsysÚargvÚarr5r8r9r1r<ZnumMsgsZ totalSizeÚrangeÚir>ÚheaderÚmsgr)rrCrrrrÚsH         ÿa,