ó DŃŐfc@sŤdZddlZddlZddgZdefd„ƒYZdZdZdZd Z ee Z d Z dfd „ƒYZ yddl Z Wnek ržn$Xd e fd „ƒYZejd ƒedkr§ddlZe ejdƒZejƒGHejejdƒejejdƒejƒejƒ\ZZx[ededƒD]FZejeƒ\ZZ Z!deGHxe D]Z"de"GHq~WdGHqPWej#ƒndS(s@A POP3 client class. Based on the J. Myers POP3 draft, Jan. 96 i˙˙˙˙NtPOP3t error_protocBseZRS((t__name__t __module__(((s/usr/lib64/python2.7/poplib.pyRsiniăs s icBsűeZdZeejd„Zd„Zd„Zd„Z d„Z d„Z d„Z d„Z d „Zd „Zd „Zd „Zd „Zdd„Zd„Zd„Zd„Zd„Zd„Zd„ZejdƒZd„Zd„Zdd„Z RS(sĎ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. cCs^||_||_tj||f|ƒ|_|jjdƒ|_d|_|jƒ|_ dS(Ntrbi( thosttporttsockettcreate_connectiontsocktmakefiletfilet _debuggingt_getresptwelcome(tselfRRttimeout((s/usr/lib64/python2.7/poplib.pyt__init__Us    cCs?|jdkr!dGt|ƒGHn|jjd|tfƒdS(Nis*put*s%s%s(R treprR tsendalltCRLF(Rtline((s/usr/lib64/python2.7/poplib.pyt_putline_scCs,|jrdGt|ƒGHn|j|ƒdS(Ns*cmd*(R RR(RR((s/usr/lib64/python2.7/poplib.pyt_putcmdfs cCsĆ|jjtdƒ}t|ƒtkr7tdƒ‚n|jdkrXdGt|ƒGHn|smtdƒ‚nt|ƒ}|dtkr—|d |fS|dtkr¸|dd!|fS|d |fS(Nis line too longs*get*s-ERR EOFiţ˙˙˙ii˙˙˙˙( R treadlinet_MAXLINEtlenRR RRtCR(RRtoctets((s/usr/lib64/python2.7/poplib.pyt_getlineos cCs\|jƒ\}}|jdkr3dGt|ƒGHn|d }|dkrXt|ƒ‚n|S(Nis*resp*t+(RR RR(Rtresptotc((s/usr/lib64/python2.7/poplib.pyR ƒs  cCsš|jƒ}g}d}|jƒ\}}x`|dkrŒ|d dkr`|d}|d}n||}|j|ƒ|jƒ\}}q-W|||fS(Nit.is..i(R Rtappend(RRtlistRRR ((s/usr/lib64/python2.7/poplib.pyt _getlongrespŽs     cCs|j|ƒ|jƒS(N(RR (RR((s/usr/lib64/python2.7/poplib.pyt _shortcmdžs cCs|j|ƒ|jƒS(N(RR%(RR((s/usr/lib64/python2.7/poplib.pyt_longcmdĽs cCs|jS(N(R(R((s/usr/lib64/python2.7/poplib.pyt getwelcomeŹscCs ||_dS(N(R (Rtlevel((s/usr/lib64/python2.7/poplib.pytset_debuglevel°scCs|jd|ƒS(sVSend user name, return response (should indicate password required). sUSER %s(R&(Rtuser((s/usr/lib64/python2.7/poplib.pyR+śscCs|jd|ƒS(s Send password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' sPASS %s(R&(Rtpswd((s/usr/lib64/python2.7/poplib.pytpass_žscCs`|jdƒ}|jƒ}|jr6dGt|ƒGHnt|dƒ}t|dƒ}||fS(s]Get mailbox status. Result is tuple of 2 ints (message count, mailbox size) tSTATs*stat*ii(R&tsplitR Rtint(Rtretvaltretst numMessagest sizeMessages((s/usr/lib64/python2.7/poplib.pytstatČs  cCs*|dk r|jd|ƒS|jdƒS(sRequest 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. sLIST %stLISTN(tNoneR&R'(Rtwhich((s/usr/lib64/python2.7/poplib.pyR$Ős cCs|jd|ƒS(soRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. sRETR %s(R'(RR8((s/usr/lib64/python2.7/poplib.pytretrăscCs|jd|ƒS(sFDelete message number 'which'. Result is 'response'. sDELE %s(R&(RR8((s/usr/lib64/python2.7/poplib.pytdeleëscCs |jdƒS(sXDoes nothing. One supposes the response indicates the server is alive. tNOOP(R&(R((s/usr/lib64/python2.7/poplib.pytnoopóscCs |jdƒS(s(Unmark all messages marked for deletion.tRSET(R&(R((s/usr/lib64/python2.7/poplib.pytrsetűscCsYy|jdƒ}Wntk r.}|}nX|jjƒ|jjƒ|`|`|S(sDSignoff: commit changes on server, unlock mailbox, close connection.tQUIT(R&RR tcloseR (RRtval((s/usr/lib64/python2.7/poplib.pytquits    cCs|jd|ƒS(sNot sure what this does.sRPOP %s(R&(RR+((s/usr/lib64/python2.7/poplib.pytrpopss\+OK.[^<]*(<.*>)cCsŠ|jj|jƒ}|s*tdƒ‚nddl}|j|jdƒ|ƒjƒ}djt d„|ƒƒ}|j d||fƒS(s Authorisation - only possible if server has supplied a timestamp in initial greeting. Args: user - mailbox user; secret - secret shared between client and server. NB: mailbox is locked by server from here to 'quit()' s!-ERR APOP not supported by serveri˙˙˙˙NitcSsdt|ƒS(Ns%02x(tord(tx((s/usr/lib64/python2.7/poplib.pyt'ss APOP %s %s( t timestamptmatchRRthashlibtmd5tgrouptdigesttjointmapR&(RR+tsecrettmRJRM((s/usr/lib64/python2.7/poplib.pytapops  "cCs|jd||fƒS(s­Retrieve message header of message number 'which' and first 'howmuch' lines of message body. Result is in form ['response', ['line', ...], octets]. s TOP %s %s(R'(RR8thowmuch((s/usr/lib64/python2.7/poplib.pyttop+scCs*|dk r|jd|ƒS|jdƒS(sě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] sUIDL %stUIDLN(R7R&R'(RR8((s/usr/lib64/python2.7/poplib.pytuidl4s N(!RRt__doc__t POP3_PORTRt_GLOBAL_DEFAULT_TIMEOUTRRRRR R%R&R'R(R*R+R-R5R7R$R9R:R<R>RBRCtretcompileRHRRRTRV(((s/usr/lib64/python2.7/poplib.pyR*s4(                 tPOP3_SSLcBsDeZdZeddd„Zd„Zd„Zd„Zd„Z RS(sÂ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 countains your private key certfile - PEM formatted certificate chain file See the methods of the parent class POP3 for more documentation. c CsR||_||_||_||_d|_d}d|_xŠtj|j|jdtj ƒD]†}|\}}} } } y,tj||| ƒ|_|jj | ƒWn;tj k râ}|jrÓ|jj ƒnd|_q^nXPq^W|jstj |‚n|jj dƒ|_tj|j|j|jƒ|_d|_|jƒ|_dS(NRDs!getaddrinfo returns an empty listiR(RRtkeyfiletcertfiletbufferR7R Rt getaddrinfot SOCK_STREAMtconnectterrorR@R R tsslt wrap_sockettsslobjR R R( RRRR]R^tmsgtrestaftsocktypetprotot canonnametsa((s/usr/lib64/python2.7/poplib.pyRRs0      (   ! cCsC|jjƒ}t|ƒdkr0tdƒ‚n|j|7_dS(Nis-ERR EOF(RftreadRRR_(Rtlocalbuf((s/usr/lib64/python2.7/poplib.pyt _fillBufferlscCsd}tjdƒ}|j|jƒ}xJ|ss|jƒt|jƒtkr^tdƒ‚n|j|jƒ}q*W|jdƒ}|j d|jdƒ|_|j dkrżdGt |ƒGHnt|ƒ}|dt kré|d |fS|dt kr |dd!|fS|d |fS( NRDs.*?\ns line too longiis*get*iţ˙˙˙i˙˙˙˙(RZR[RIR_RpRRRRLtsubR RRR(RRt renewlineRIR((s/usr/lib64/python2.7/poplib.pyRrs$   cCs„|jdkr!dGt|ƒGHn|t7}t|ƒ}xF|dkr|jj|ƒ}||krhPn||}||}q:WdS(Nis*put*i(R RRRRftwrite(RRtbytestsent((s/usr/lib64/python2.7/poplib.pyR†s    cCsLy|jdƒ}Wntk r.}|}nX|jjƒ|`|`|S(sDSignoff: commit changes on server, unlock mailbox, close connection.R?(R&RR R@Rf(RRRA((s/usr/lib64/python2.7/poplib.pyRB‘s   N( RRRWt POP3_SSL_PORTR7RRpRRRB(((s/usr/lib64/python2.7/poplib.pyR\Es     t__main__iiis Message %d:s s-----------------------($RWRZRt__all__t ExceptionRRXRvRtLFRRRRdt ImportErrorR\R#RtsystargvtaR(R+R-R$R5tnumMsgst totalSizetrangetiR9theaderRgRRRB(((s/usr/lib64/python2.7/poplib.pyts@   ˙ V