/head: changeset 81
Updated with preliminary tunnel support
This commit is contained in:
@ -17,10 +17,11 @@ Public functions: Internaldate2tuple
|
||||
# GET/SETACL contributed by Anthony Baxter <anthony@interlink.com.au> April 2001.
|
||||
# IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002.
|
||||
# GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002.
|
||||
# IMAP4_Tunnel contributed by John Goerzen <jgoerzen@complete.org> July 2002
|
||||
|
||||
__version__ = "2.52"
|
||||
|
||||
import binascii, re, socket, time, random, sys
|
||||
import binascii, re, socket, time, random, sys, os
|
||||
|
||||
__all__ = ["IMAP4", "Internaldate2tuple",
|
||||
"Int2AP", "ParseFlags", "Time2Internaldate"]
|
||||
@ -1020,7 +1021,37 @@ class IMAP4:
|
||||
i = 0
|
||||
n -= 1
|
||||
|
||||
class IMAP4_Tunnel(IMAP4):
|
||||
"""IMAP4 client class over a tunnel
|
||||
|
||||
Instantiate with: IMAP4_Tunnel(tunnelcmd)
|
||||
|
||||
tunnelcmd -- shell command to generate the tunnel.
|
||||
The result will be in PREAUTH stage."""
|
||||
|
||||
def __init__(self, tunnelcmd):
|
||||
IMAP4.__init__(self, tunnelcmd)
|
||||
|
||||
def open(self, host, port):
|
||||
"""The tunnelcmd comes in on host!"""
|
||||
self.outfd, self.infd = os.popen2(host, "t", 0)
|
||||
|
||||
def read(self, size):
|
||||
retval = ''
|
||||
while len(retval) < size:
|
||||
retval += self.infd.read(size - len(retval))
|
||||
return retval
|
||||
|
||||
def readline(self):
|
||||
return self.infd.readline()
|
||||
|
||||
def send(self, data):
|
||||
self.outfd.write(data)
|
||||
|
||||
def shutdown(self):
|
||||
self.infd.close()
|
||||
self.outfd.close()
|
||||
|
||||
|
||||
class IMAP4_SSL(IMAP4):
|
||||
|
||||
|
@ -41,13 +41,15 @@ class UsefulIMAPMixIn:
|
||||
|
||||
class UsefulIMAP4(UsefulIMAPMixIn, imaplib.IMAP4): pass
|
||||
class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplib.IMAP4_SSL): pass
|
||||
class UsefulIMAP4_Tunnel(UsefulIMAPMixIn, imaplib.IMAP4_Tunnel): pass
|
||||
|
||||
class IMAPServer:
|
||||
def __init__(self, username, password, hostname, port = None, ssl = 1,
|
||||
maxconnections = 1):
|
||||
def __init__(self, username = None, password = None, hostname = None,
|
||||
port = None, ssl = 1, maxconnections = 1, tunnel = None):
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.hostname = hostname
|
||||
self.tunnel = tunnel
|
||||
self.port = port
|
||||
self.usessl = ssl
|
||||
self.delim = None
|
||||
@ -102,12 +104,15 @@ class IMAPServer:
|
||||
self.connectionlock.release() # Release until need to modify data
|
||||
|
||||
# Generate a new connection.
|
||||
if self.usessl:
|
||||
if self.tunnel:
|
||||
imapobj = UsefulIMAP4_Tunnel(self.tunnel)
|
||||
elif self.usessl:
|
||||
imapobj = UsefulIMAP4_SSL(self.hostname, self.port)
|
||||
else:
|
||||
imapobj = UsefulIMAP4(self.hostname, self.port)
|
||||
|
||||
imapobj.login(self.username, self.password)
|
||||
|
||||
if not self.tunnel:
|
||||
imapobj.login(self.username, self.password)
|
||||
|
||||
if self.delim == None:
|
||||
self.delim, self.root = \
|
||||
|
Reference in New Issue
Block a user