grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a ä”|jÙ;ã@sjdZddlZddlZddlZddlZzddlZdZWneyJdZYn0ddgZGdd„de ƒZ dZ d Z d Z d Ze eZd ZGd d„dƒZer¬Gdd„deƒZe d¡edk�rfddlZeejdƒZee ¡ƒe ejd¡e ejd¡e ¡e ¡\ZZededƒD]BZ e !e ¡\Z"Z#Z$ede ƒe#D]Z%ede%ƒ�q>edƒ�qe &¡dS)z@A POP3 client class. Based on the J. Myers POP3 draft, Jan. 96 éNTFÚPOP3Ú error_protoc@s eZdZdS)rN)Ú__name__Ú __module__Ú __qualname__©rrú/usr/lib64/python3.9/poplib.pyróéniãó ó ic@s eZdZdZdZeejfdd„Zdd„Z dd„Z d d „Z d d „Z d d„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd=d d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Ze d0¡Z d1d2„Z!d3d4„Z"d>d5d6„Z#d7d8„Z$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|_t d|||¡| |¡|_|j d¡|_d|_ |  ¡|_ dS)NFzpoplib.connectÚrbr) ÚhostÚportÚ_tls_establishedÚsysÚauditÚ_create_socketÚsockÚmakefileÚfileÚ _debuggingÚ_getrespÚwelcome)ÚselfrrÚtimeoutrrrÚ__init__bs z POP3.__init__cCs(|dur|stdƒ‚t |j|jf|¡S)Nz0Non-blocking socket (timeout=0) is not supported)Ú ValueErrorÚsocketÚcreate_connectionrr)rrrrrrms zPOP3._create_socketcCs:|jdkrtdt|ƒƒt d||¡|j |t¡dS)Néz*put*zpoplib.putline)rÚprintÚreprrrrÚsendallÚCRLF©rÚlinerrrÚ_putlinersz POP3._putlinecCsB|jrtdt|ƒƒt||jƒ}t d|¡r4tdƒ‚| |¡dS)Nz*cmd*s[-]z*Control characters not allowed in commands) rr!r"ÚbytesÚencodingÚreÚsearchrr'r%rrrÚ_putcmdzs   z POP3._putcmdcCs |j td¡}t|ƒtkr$tdƒ‚|jdkr©rÚuserrrrrFÍsz POP3.usercCs| d|¡S)z Send password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' zPASS %srD)rZpswdrrrÚpass_Õ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 é)r>Úsplitrr!r"Úint)rZretvalZretsZ numMessagesZ sizeMessagesrrrÚstatßs    z POP3.statNcCs |dur| d|¡S| d¡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 %sÚLIST©r>r?©rÚwhichrrrr;ìs z POP3.listcCs| d|¡S)zoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. zRETR %s©r?rNrrrÚretrúsz POP3.retrcCs| d|¡S)zFDelete message number 'which'. Result is 'response'. zDELE %srDrNrrrÚdelesz POP3.delecCs | d¡S)zXDoes nothing. One supposes the response indicates the server is alive. ZNOOPrDr@rrrÚnoop sz POP3.noopcCs | d¡S)z(Unmark all messages marked for deletion.ZRSETrDr@rrrÚrsetsz POP3.rsetcCs| d¡}| ¡|S)zDSignoff: commit changes on server, unlock mailbox, close connection.ZQUIT)r>Úclose)rr7rrrÚquits z POP3.quitcCs,z |j}d|_|dur| ¡W|j}d|_|dur z`z| tj¡WnBtyˆ}z*|jtjkrtt |ddƒdkrt‚WYd}~n d}~00W| ¡n | ¡0n†|j}d|_|du�r&zbz| tj¡WnDt�y}z*|jtjkrút |ddƒdkrú‚WYd}~n d}~00W| ¡n | ¡00dS)z8Close the connection without assuming anything about it.NÚwinerrorri&') rrUrÚshutdownrÚ SHUT_RDWRÚOSErrorÚerrnoZENOTCONNÚgetattr)rrrÚexcrrrrUs6  ÿó  ÿz POP3.closecCs| d|¡S)zNot sure what this does.zRPOP %srDrErrrÚrpop9sz POP3.rpops\+OK.[^<]*(<.*>)cCs\t||jƒ}|j |j¡}|s&tdƒ‚ddl}| d¡|}| |¡  ¡}|  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 serverrNr z APOP %s %s) r(r)Ú timestampÚmatchrrÚhashlibÚgroupÚmd5Ú hexdigestr>)rrFÚpasswordZsecretÚmraÚdigestrrrÚapop@s z POP3.apopcCs| d||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 %srP)rrOZhowmuchrrrÚtopUszPOP3.topcCs |dur| d|¡S| d¡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 %sZUIDLrMrNrrrÚuidl^sz POP3.uidlcCs | d¡S)zITry to enter UTF-8 mode (see RFC 6856). Returns server response. ZUTF8rDr@rrrÚutf8jsz POP3.utf8cCs`dd„}i}z4| d¡}|d}|D]}||ƒ\}}|||<q$WntyZtdƒ‚Yn0|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|dd…fS)NÚasciirr )ÚdecoderI)r&ZlstrrrÚ _parsecap}szPOP3.capa.._parsecapZCAPAr z!-ERR CAPA not supported by server)r?r)rrnÚcapsr7ZrawcapsZcaplineZcapnmZcapargsrrrÚcapaps    z POP3.capacCsxts tdƒ‚|jrtdƒ‚| ¡}d|vr2tdƒ‚|durBt ¡}| 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 serverN©Zserver_hostnamer T) ÚHAVE_SSLrrrpÚsslÚ_create_stdlib_contextr>Ú wrap_socketrrrr)rÚcontextror7rrrÚstls�s  ÿz POP3.stls)N)N)N)'rrrÚ__doc__r)Ú POP3_PORTrÚ_GLOBAL_DEFAULT_TIMEOUTrrr'r,r4rr<r>r?rArCrFrGrKr;rQrRrSrTrVrUr^r*Úcompiler_rhrirjrkrprxrrrrr3sB+ÿ       c@s8eZdZdZeddejdfdd„Zdd„Zd dd„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’|dur|durtdƒ‚|dur0|dur0tdƒ‚|dus@|durVddl}| dtd¡||_||_|durxtj||d�}||_t   ||||¡dS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiverzAkeyfile and certfile are deprecated, use a custom context insteadrH)ÚcertfileÚkeyfile) rÚwarningsÚwarnÚDeprecationWarningrr~rtrurwrr)rrrrr~rrwr€rrrr´s"ÿÿzPOP3_SSL.__init__cCs"t ||¡}|jj||jd�}|S)Nrr)rrrwrvr)rrrrrrrÈs  ÿzPOP3_SSL._create_socketcCs tdƒ‚dS)z¬The method unconditionally raises an exception since the STLS command doesn't make any sense on an already established SSL/TLS session. rqN)r)rrr~rwrrrrxÎsz POP3_SSL.stls)NNN) rrrryÚ POP3_SSL_PORTrr{rrrxrrrrr}¥s ÿ r}Ú__main__r rHéz Message %d:z z-----------------------)'ryr[r*rrrtrsÚ ImportErrorÚ__all__Ú Exceptionrrzrƒr2ZLFr$r0rr}r:rÚargvÚar!rArFrGr;rKZnumMsgsZ totalSizeÚrangeÚirQÚheaderÚmsgr3r&rVrrrrÚsL  r0