ž Ľ˙fl,c @sŔdZddlZddlZddgZGdd„deƒZdZdZdZd Z ee Z d Z Gd d„dƒZ yddl Z Wnek rŸYn$XGd d „d e ƒZejd ƒedkrźddlZe ejdƒZeejƒƒejejdƒejejdƒejƒejƒ\ZZxjededƒD]UZejeƒ\Z Z!Z"edeƒxe!D]Z#ede#ƒq‰WedƒqVWej$ƒndS(u@A POP3 client class. Based on the J. Myers POP3 draft, Jan. 96 iNuPOP3u error_protocBs|EeZdZdS(u error_protoN(u__name__u __module__u __qualname__(u __locals__((u+/opt/alt/python33/lib64/python3.3/poplib.pyu error_protosiniăs s icBsj|EeZdZdZdZeejdd„Zdd„Z dd„Z d d „Z d d „Z d d„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd6dd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zej d/ƒZ!d0d1„Z"d2d3„Z#d6d4d5„Z$d6S(7uPOP3uĎ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) 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. uUTF-8cCsU||_||_|j|ƒ|_|jjdƒ|_d|_|jƒ|_dS(Nurbi( uhostuportu_create_socketusockumakefileufileu _debuggingu_getrespuwelcome(uselfuhostuportutimeout((u+/opt/alt/python33/lib64/python3.3/poplib.pyu__init__Vs    u POP3.__init__cCstj|j|jf|ƒS(N(usocketucreate_connectionuhostuport(uselfutimeout((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_create_socket_suPOP3._create_socketcCs=|jdkr%tdt|ƒƒn|jj|tƒdS(Niu*put*(u _debugginguprintureprusockusendalluCRLF(uselfuline((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_putlinebsu POP3._putlinecCsB|jrtdt|ƒƒnt||jƒ}|j|ƒdS(Nu*cmd*(u _debugginguprintureprubytesuencodingu_putline(uselfuline((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_putcmdis u POP3._putcmdcCsß|jjtdƒ}t|ƒtkr7tdƒ‚n|jdkr\tdt|ƒƒn|sqtdƒ‚nt|ƒ}|dd…tkr§|dd…|fS|dt krË|dd …|fS|dd …|fS( Niu line too longu*get*u-ERR EOFiiiţ˙˙˙iţ˙˙˙i˙˙˙˙i˙˙˙˙( ufileureadlineu_MAXLINEulenu error_protou _debugginguprinturepruCRLFuCR(uselfulineuoctets((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_getliness u POP3._getlinecCsY|jƒ\}}|jdkr7tdt|ƒƒn|jdƒsUt|ƒ‚n|S(Niu*resp*s+(u_getlineu _debugginguprinturepru startswithu error_proto(uselfurespuo((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_getrespˆs u POP3._getrespcCsŸ|jƒ}g}d}|jƒ\}}xe|dkr‘|jdƒre|d}|dd…}n||}|j|ƒ|jƒ\}}q-W|||fS(Nis.s..i(u_getrespu_getlineu startswithuappend(uselfurespulistuoctetsulineuo((u+/opt/alt/python33/lib64/python3.3/poplib.pyu _getlongresp’s    uPOP3._getlongrespcCs|j|ƒ|jƒS(N(u_putcmdu_getresp(uselfuline((u+/opt/alt/python33/lib64/python3.3/poplib.pyu _shortcmd˘s uPOP3._shortcmdcCs|j|ƒ|jƒS(N(u_putcmdu _getlongresp(uselfuline((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_longcmdŠs u POP3._longcmdcCs|jS(N(uwelcome(uself((u+/opt/alt/python33/lib64/python3.3/poplib.pyu getwelcome°suPOP3.getwelcomecCs ||_dS(N(u _debugging(uselfulevel((u+/opt/alt/python33/lib64/python3.3/poplib.pyuset_debuglevel´suPOP3.set_debuglevelcCs|jd|ƒS(uVSend user name, return response (should indicate password required). uUSER %s(u _shortcmd(uselfuuser((u+/opt/alt/python33/lib64/python3.3/poplib.pyuuserşsu POP3.usercCs|jd|ƒS(u Send password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' uPASS %s(u _shortcmd(uselfupswd((u+/opt/alt/python33/lib64/python3.3/poplib.pyupass_Âsu POP3.pass_cCsd|jdƒ}|jƒ}|jr:tdt|ƒƒnt|dƒ}t|dƒ}||fS(u]Get mailbox status. Result is tuple of 2 ints (message count, mailbox size) uSTATu*stat*ii(u _shortcmdusplitu _debugginguprinturepruint(uselfuretvaluretsu numMessagesu sizeMessages((u+/opt/alt/python33/lib64/python3.3/poplib.pyustatĚs  u POP3.statcCs*|dk r|jd|ƒS|jdƒS(uRequest 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. uLIST %suLISTN(uNoneu _shortcmdu_longcmd(uselfuwhich((u+/opt/alt/python33/lib64/python3.3/poplib.pyulistŮs u POP3.listcCs|jd|ƒS(uoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. uRETR %s(u_longcmd(uselfuwhich((u+/opt/alt/python33/lib64/python3.3/poplib.pyuretrçsu POP3.retrcCs|jd|ƒS(uFDelete message number 'which'. Result is 'response'. uDELE %s(u _shortcmd(uselfuwhich((u+/opt/alt/python33/lib64/python3.3/poplib.pyudeleďsu POP3.delecCs |jdƒS(uXDoes nothing. One supposes the response indicates the server is alive. uNOOP(u _shortcmd(uself((u+/opt/alt/python33/lib64/python3.3/poplib.pyunoop÷su POP3.noopcCs |jdƒS(u(Unmark all messages marked for deletion.uRSET(u _shortcmd(uself((u+/opt/alt/python33/lib64/python3.3/poplib.pyurset˙su POP3.rsetcCs|jdƒ}|jƒ|S(uDSignoff: commit changes on server, unlock mailbox, close connection.uQUIT(u _shortcmduclose(uselfuresp((u+/opt/alt/python33/lib64/python3.3/poplib.pyuquits u POP3.quitcCsR|jdk r|jjƒn|jdk r>|jjƒnd|_|_dS(u8Close the connection without assuming anything about it.N(ufileuNoneucloseusock(uself((u+/opt/alt/python33/lib64/python3.3/poplib.pyuclose s u POP3.closecCs|jd|ƒS(uNot sure what this does.uRPOP %s(u _shortcmd(uselfuuser((u+/opt/alt/python33/lib64/python3.3/poplib.pyurpopsu POP3.rpops\+OK.*(<[^>]+>)cCs‡t||jƒ}|jj|jƒ}|s<tdƒ‚nddl}|jdƒ|}|j|ƒj ƒ}|j d||fƒS(u 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()' u!-ERR APOP not supported by serveriNiu APOP %s %s( ubytesuencodingu timestampumatchuwelcomeu error_protouhashlibugroupumd5u hexdigestu _shortcmd(uselfuuserupasswordusecretumuhashlibudigest((u+/opt/alt/python33/lib64/python3.3/poplib.pyuapops  u POP3.apopcCs|jd||fƒS(u­Retrieve message header of message number 'which' and first 'howmuch' lines of message body. Result is in form ['response', ['line', ...], octets]. u TOP %s %s(u_longcmd(uselfuwhichuhowmuch((u+/opt/alt/python33/lib64/python3.3/poplib.pyutop3suPOP3.topcCs*|dk r|jd|ƒS|jdƒS(uě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] uUIDL %suUIDLN(uNoneu _shortcmdu_longcmd(uselfuwhich((u+/opt/alt/python33/lib64/python3.3/poplib.pyuuidl<s u POP3.uidlN(%u__name__u __module__u __qualname__u__doc__uencodingu POP3_PORTusocketu_GLOBAL_DEFAULT_TIMEOUTu__init__u_create_socketu_putlineu_putcmdu_getlineu_getrespu _getlongrespu _shortcmdu_longcmdu getwelcomeuset_debugleveluuserupass_ustatuNoneulisturetrudeleunoopursetuquitucloseurpopureucompileu timestampuapoputopuuidl(u __locals__((u+/opt/alt/python33/lib64/python3.3/poplib.pyuPOP3*s:(                  cBsD|EeZdZdZeddejddd„Zdd„Z dS(uPOP3_SSLu˝POP3 client class over SSL connection Instantiate with: POP3_SSL(hostname, port=995, keyfile=None, certfile=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 See the methods of the parent class POP3 for more documentation. cCsƒ|dk r'|dk r'tdƒ‚n|dk rN|dk rNtdƒ‚n||_||_||_tj||||ƒdS(Nu4context and keyfile arguments are mutually exclusiveu5context and certfile arguments are mutually exclusive(uNoneu ValueErrorukeyfileucertfileucontextuPOP3u__init__(uselfuhostuportukeyfileucertfileutimeoutucontext((u+/opt/alt/python33/lib64/python3.3/poplib.pyu__init__Zs   uPOP3_SSL.__init__cCsUtj||ƒ}|jdk r6|jj|ƒ}ntj||j|jƒ}|S(N(uPOP3u_create_socketucontextuNoneu wrap_socketusslukeyfileucertfile(uselfutimeoutusock((u+/opt/alt/python33/lib64/python3.3/poplib.pyu_create_socketgs uPOP3_SSL._create_socketN( u__name__u __module__u __qualname__u__doc__u POP3_SSL_PORTuNoneusocketu_GLOBAL_DEFAULT_TIMEOUTu__init__u_create_socket(u __locals__((u+/opt/alt/python33/lib64/python3.3/poplib.pyuPOP3_SSLMs   uPOP3_SSLu__main__iiiu Message %d:u u-----------------------(%u__doc__ureusocketu__all__u Exceptionu error_protou POP3_PORTu POP3_SSL_PORTuCRuLFuCRLFu_MAXLINEuPOP3usslu ImportErroruPOP3_SSLuappendu__name__usysuargvuauprintu getwelcomeuuserupass_ulistustatunumMsgsu totalSizeurangeuiuretruheaderumsguoctetsulineuquit(((u+/opt/alt/python33/lib64/python3.3/poplib.pyus@   ˙ "