diff options
author | Piers Lauder <piers@cs.su.oz.au> | 2002-03-08 01:53:24 (GMT) |
---|---|---|
committer | Piers Lauder <piers@cs.su.oz.au> | 2002-03-08 01:53:24 (GMT) |
commit | a4f8313cbb5239a5f18abad93b4156246de2c13b (patch) | |
tree | d7b638f76e2cb3a6a4366fcf5963a5f1e92f44e3 /Lib/imaplib.py | |
parent | 6cb64f9e4650c101179134850f414435abab95ee (diff) | |
download | cpython-a4f8313cbb5239a5f18abad93b4156246de2c13b.zip cpython-a4f8313cbb5239a5f18abad93b4156246de2c13b.tar.gz cpython-a4f8313cbb5239a5f18abad93b4156246de2c13b.tar.bz2 |
add SSL class submitted by Tino Lange
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r-- | Lib/imaplib.py | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 5141d08..4a9200b 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -15,8 +15,9 @@ Public functions: Internaldate2tuple # Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998. # String method conversion by ESR, February 2001. # GET/SETACL contributed by Anthony Baxter <anthony@interlink.com.au> April 2001. +# IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002. -__version__ = "2.50" +__version__ = "2.51" import binascii, re, socket, time, random, sys @@ -982,6 +983,78 @@ class IMAP4: +class IMAP4_SSL(IMAP4): + + """IMAP4 client class over SSL connection + + Instantiate with: IMAP4_SSL([, host[, port[, keyfile[, certfile]]]]) + + host - host's name (default: localhost); + port - port number (default: standard IMAP4 SSL port). + keyfile - PEM formatted file that contains your private key (default: None); + certfile - PEM formatted certificate chain file (default: None); + + for more documentation see the docstring of the parent class IMAP4. + """ + + + def __init__(self, host = '', port = IMAP4_SSL_PORT, keyfile = None, certfile = None): + self.keyfile = keyfile + self.certfile = certfile + IMAP4.__init__(self, host, port) + + + def open(self, host, port): + """Setup connection to remote server on "host:port". + This connection will be used by the routines: + read, readline, send, shutdown. + """ + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.connect((self.host, self.port)) + self.sslobj = socket.ssl(self.sock,self.keyfile, self.certfile) + + + def read(self, size): + """Read 'size' bytes from remote.""" + return self.sslobj.read(size) + + + def readline(self): + """Read line from remote.""" + line = "" + while 1: + char = self.sslobj.read(1) + line += char + if char == "\n": return line + + + def send(self, data): + """Send data to remote.""" + self.sslobj.write(data) + + + def shutdown(self): + """Close I/O established in "open".""" + self.sock.close() + + + def socket(self): + """Return socket instance used to connect to IMAP4 server. + + socket = <instance>.socket() + """ + return self.sock + + + def ssl(self): + """Return SSLObject instance used to communicate with the IMAP4 server. + + ssl = <instance>.socket.ssl() + """ + return self.sslobj + + + class _Authenticator: """Private class to provide en/decoding |