mò ŠDc@s˜dZdddgZdkZdklZlZlZlZlZdk Tdk Z e i i ƒZdZdefd„ƒYZdefd „ƒYZdS( s$Provide an SSL-capable POP3 class. t POP3_ssl_portt sslsockettPOP3SSLN(sPOP3sCRsLFsCRLFs error_proto(t*iãcBsAtZdZeed„Zd„Zd„Zd„Zd„ZRS(s‡The Python poplib.POP3() class mixes socket-like .sendall() and file-like .readline() for communications. That would be okay, except that the new socket.ssl objects provide only read() and write(), so they don't act like a socket /or/ like a file. Argh. This class takes a standard, connected socket.socket() object, sets it to blocking mode (required for socket.ssl() to work correctly, though apparently not documented), wraps .write() for .sendall() and implements .readline(). The modified POP3 class below can then use this to provide POP3-over-SSL. Thanks to Frank Benkstein for the inspiration. cCs{tiƒ||_|iidƒ|o&|oti|i||ƒ|_nti|iƒ|_d|_ d|_ dS(Niti€( tlogttracetsocktselft setblockingtkeyfiletcertfiletsockettssltbuftbufsize(RRR R ((t8/usr/lib/python2.4/site-packages/getmailcore/_pop3ssl.pyt__init__$s   cCsˆtiƒ|it|iƒ}tid|ƒ|djodSn|ii|ƒ}t|ƒ}tid|ƒ|i|7_dS(s8Fill an internal buffer for .readline() to use. swant %i bytes iNs got %i bytes ( RRRRtlenRtwantR treadtstgot(RRRR((Rt_fillbuf/s   cCs|iiƒd|_dS(N(RRtclosetNoneR (R((RR<s cCs|ii|ƒdS(N(RR twriteR(RR((RtsendallAscCs‡tiƒd}y?|ip|iƒntidƒ|io÷tid|it|iƒfƒxÑtoÅtidƒ|iidƒ}|djo?tid|ƒ||i|d 7}|i|d|_Pntid ƒ||i7}d|_|iƒ|iptid ƒPntid ƒqhWntid |ƒ|SWn1t i t i fj o}td |ƒ‚nXdS(sfSimple hack to implement .readline() on a non-file object that only supports .read(). Rschecking self.buf sself.buf = "%r", len %i slooking for EOL s iÿÿÿÿsEOL found at %d is'EOL not found, trying to fill self.buf snothing read, exiting s end of loop sreturning line "%r" s/socket/ssl error while reading from server (%s)N(RRtlineRRRRtTruetfindtiR tsslerrorterrortotgetmailOperationError(RRR"R((RtreadlineFs<    #        ( t__name__t __module__t__doc__RRRRRR$(((RRs   cBs2tZdZeeed„Zd„Zd„ZRS(s2Thin subclass to add SSL functionality to the built-in POP3 class. Note that Python's socket module does not do certificate verification for SSL connections. This gets rid of the .file attribute from os.makefile(rawsock) and relies on sslsocket() above to provide .readline() instead. c Csˆ|o|p||jo djnptdƒ‚n||_||_d} d|_d|_ xét i |i|idt i ƒD]Æ}|\}}}} } yht i |||ƒ|_|ii| ƒ|o#|ot|i||ƒ|_ nt|iƒ|_ Wn?t ij o0} |io|iiƒnd|_qˆnXPqˆW|i pt i| ‚nd|_|iƒ|_dS(Nscertfile requires keyfiles!getaddrinfo returns an empty listi(R R RtgetmailConfigurationErrorthostRtporttmsgtrawsockRR t getaddrinfot SOCK_STREAMtrestaftsocktypetprotot canonnametsatconnectRR!Rt _debuggingt_getresptwelcome( RR)R*R R R0R1R/R2R+R3R4((RRrs4,    "    cCs§|iiƒ}|idjodG| GHn|ptdƒ‚nt|ƒ}|dtjo|d |fSn|dt jo|dd!|fSn|d |fS(Nis*get*s-ERR EOFiþÿÿÿiiÿÿÿÿ( RRR$RR6t error_protoRtoctetstCRLFtCR(RR:R((Rt_getline‘s cCsQy|idƒ}Wn$ttifj o}|}nX|iiƒ|`|S(sDSignoff: commit changes on server, unlock mailbox, close connection.tQUITN( Rt _shortcmdtrespR9R R!tvalRR(RR@RA((RtquitŸs  (R%R&R'RRRR=RB(((RRjs  (R't__all__R tpoplibtPOP3R<tLFR;R9tgetmailcore.exceptionstgetmailcore.loggingt getmailcoretloggingtLoggerRRtobjectRR( RFR RCRRERRIRR;R<R9R((Rt?s % U