X-Git-Url: https://code.delx.au/offlineimap/blobdiff_plain/96fd23335546050036a8cb437ec59a11f67aa493..5fe379f66d2265f6ddd30f85384daf318f303be9:/offlineimap/imaplibutil.py diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py index 2dd3998..27ed1fa 100644 --- a/offlineimap/imaplibutil.py +++ b/offlineimap/imaplibutil.py @@ -1,4 +1,4 @@ -# imaplib +# imaplib utilities # Copyright (C) 2002-2007 John Goerzen # # @@ -18,8 +18,13 @@ import re, string, types, binascii, socket, time, random, subprocess, sys, os from offlineimap.ui import UIBase +from imaplib import * -class IMAP4_Tunnel(imaplib.IMAP4): +# Import the symbols we need that aren't exported by default +from imaplib import IMAP4_PORT, IMAP4_SSL_PORT, InternalDate, Mon2num + + +class IMAP4_Tunnel(IMAP4): """IMAP4 client class over a tunnel Instantiate with: IMAP4_Tunnel(tunnelcmd) @@ -28,7 +33,7 @@ class IMAP4_Tunnel(imaplib.IMAP4): The result will be in PREAUTH stage.""" def __init__(self, tunnelcmd): - imaplib.IMAP4.__init__(self, tunnelcmd) + IMAP4.__init__(self, tunnelcmd) def open(self, host, port): """The tunnelcmd comes in on host!""" @@ -53,7 +58,6 @@ class IMAP4_Tunnel(imaplib.IMAP4): self.outfd.close() self.process.wait() -# FIXME: need to use this in SSL instances class sslwrapper: def __init__(self, sslsock): self.sslsock = sslsock @@ -93,16 +97,21 @@ class sslwrapper: else: retval += linebuf -# FIXME: need to override this in IMAP instances - def new_mesg(self, s, secs=None): if secs is None: secs = time.time() tm = time.strftime('%M:%S', time.localtime(secs)) UIBase.getglobalui().debug('imap', ' %s.%02d %s' % (tm, (secs*100)%100, s)) -# FIXME: use this -def new_open(self, host = '', port = imaplib.IMAP4_PORT): +class WrappedIMAP4_SSL(IMAP4_SSL): + def open(self, host = '', port = IMAP4_SSL_PORT): + IMAP4_SSL.open(self, host, port) + self.sslobj = sslwrapper(self.sslobj) + + def readline(self): + return self.sslobj.readline() + +def new_open(self, host = '', port = IMAP4_PORT): """Setup connection to remote server on "host:port" (default: localhost:standard IMAP4 port). This connection will be used by the routines: @@ -112,7 +121,6 @@ def new_open(self, host = '', port = imaplib.IMAP4_PORT): self.port = port res = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM) - self.sock = socket.socket(af, socktype, proto) # Try each address returned by getaddrinfo in turn until we # manage to connect to one. @@ -158,10 +166,7 @@ def new_open_ssl(self, host = '', port = IMAP4_SSL_PORT): if last_error != 0: # FIXME raise socket.error(last_error) - if sys.version_info[0] <= 2 and sys.version_info[1] <= 2: - self.sslobj = socket.ssl(self.sock, self.keyfile, self.certfile) - else: - self.sslobj = socket.ssl(self.sock._sock, self.keyfile, self.certfile) + self.sslobj = socket.ssl(self.sock, self.keyfile, self.certfile) self.sslobj = sslwrapper(self.sslobj) mustquote = re.compile(r"[^\w!#$%&'+,.:;<=>?^`|~-]")