2to3
parent
44182ddd45
commit
7423d4941d
48
mech_imap.py
48
mech_imap.py
|
@ -27,14 +27,14 @@ class IMAPUserAccount(object):
|
||||||
IMAP_MBOX_REG[self.dir][IMAP_ACC_CONN_NUM] = 0
|
IMAP_MBOX_REG[self.dir][IMAP_ACC_CONN_NUM] = 0
|
||||||
for m in conf.imap_auto_mbox:
|
for m in conf.imap_auto_mbox:
|
||||||
if m not in IMAP_MBOX_REG[self.dir].keys():
|
if m not in IMAP_MBOX_REG[self.dir].keys():
|
||||||
if isinstance(m, unicode):
|
if isinstance(m, str):
|
||||||
m = m.encode('imap4-utf-7')
|
m = m.encode('imap4-utf-7')
|
||||||
IMAP_MBOX_REG[self.dir][m] = IMAPMailbox(os.path.join(self.dir, m))
|
IMAP_MBOX_REG[self.dir][m] = IMAPMailbox(os.path.join(self.dir, m))
|
||||||
IMAP_MBOX_REG[self.dir][m]._start_monitor()
|
IMAP_MBOX_REG[self.dir][m]._start_monitor()
|
||||||
self.subscribe(m)
|
self.subscribe(m)
|
||||||
|
|
||||||
def _getMailbox(self, path):
|
def _getMailbox(self, path):
|
||||||
if isinstance(path, unicode):
|
if isinstance(path, str):
|
||||||
path = path.encode('imap4-utf-7')
|
path = path.encode('imap4-utf-7')
|
||||||
fullPath = os.path.join(self.dir, path)
|
fullPath = os.path.join(self.dir, path)
|
||||||
mbox = IMAPMailbox(fullPath)
|
mbox = IMAPMailbox(fullPath)
|
||||||
|
@ -46,7 +46,7 @@ class IMAPUserAccount(object):
|
||||||
yield box.decode('imap4-utf-7'), self.create(box)
|
yield box.decode('imap4-utf-7'), self.create(box)
|
||||||
|
|
||||||
def select(self, path, rw=False):
|
def select(self, path, rw=False):
|
||||||
if isinstance(path, unicode):
|
if isinstance(path, str):
|
||||||
path = path.encode('imap4-utf-7')
|
path = path.encode('imap4-utf-7')
|
||||||
if path in IMAP_MBOX_REG[self.dir].keys():
|
if path in IMAP_MBOX_REG[self.dir].keys():
|
||||||
return IMAP_MBOX_REG[self.dir][path]
|
return IMAP_MBOX_REG[self.dir][path]
|
||||||
|
@ -54,7 +54,7 @@ class IMAPUserAccount(object):
|
||||||
if path in os.listdir(self.dir):
|
if path in os.listdir(self.dir):
|
||||||
return self.create(path)
|
return self.create(path)
|
||||||
else:
|
else:
|
||||||
raise imap4.NoSuchMailbox, path
|
raise imap4.NoSuchMailbox(path)
|
||||||
|
|
||||||
def addMailbox(self, name, mbox = None):
|
def addMailbox(self, name, mbox = None):
|
||||||
if mbox:
|
if mbox:
|
||||||
|
@ -62,7 +62,7 @@ class IMAPUserAccount(object):
|
||||||
return self.create(name)
|
return self.create(name)
|
||||||
|
|
||||||
def create(self, pathspec):
|
def create(self, pathspec):
|
||||||
if isinstance(pathspec, unicode):
|
if isinstance(pathspec, str):
|
||||||
pathspec = pathspec.encode('imap4-utf-7')
|
pathspec = pathspec.encode('imap4-utf-7')
|
||||||
if pathspec not in IMAP_MBOX_REG[self.dir].keys():
|
if pathspec not in IMAP_MBOX_REG[self.dir].keys():
|
||||||
paths = filter(None, pathspec.split(IMAP_HDELIM))
|
paths = filter(None, pathspec.split(IMAP_HDELIM))
|
||||||
|
@ -77,10 +77,10 @@ class IMAPUserAccount(object):
|
||||||
return IMAP_MBOX_REG[self.dir][pathspec]
|
return IMAP_MBOX_REG[self.dir][pathspec]
|
||||||
|
|
||||||
def delete(self, pathspec):
|
def delete(self, pathspec):
|
||||||
if isinstance(pathspec, unicode):
|
if isinstance(pathspec, str):
|
||||||
pathspec = pathspec.encode('imap4-utf-7')
|
pathspec = pathspec.encode('imap4-utf-7')
|
||||||
if pathspec in conf.imap_auto_mbox:
|
if pathspec in conf.imap_auto_mbox:
|
||||||
raise imap4.MailboxException, pathspec
|
raise imap4.MailboxException(pathspec)
|
||||||
if pathspec not in IMAP_MBOX_REG[self.dir].keys():
|
if pathspec not in IMAP_MBOX_REG[self.dir].keys():
|
||||||
raise imap4.MailboxException("No such mailbox")
|
raise imap4.MailboxException("No such mailbox")
|
||||||
inferiors = self._inferiorNames(pathspec)
|
inferiors = self._inferiorNames(pathspec)
|
||||||
|
@ -89,7 +89,7 @@ class IMAPUserAccount(object):
|
||||||
# as part of their root.
|
# as part of their root.
|
||||||
for inferior in inferiors:
|
for inferior in inferiors:
|
||||||
if inferior != pathspec:
|
if inferior != pathspec:
|
||||||
raise imap4.MailboxException, "Hierarchically inferior mailboxes exist and \\Noselect is set"
|
raise imap4.MailboxException("Hierarchically inferior mailboxes exist and \\Noselect is set")
|
||||||
for inferior in inferiors:
|
for inferior in inferiors:
|
||||||
mdir = IMAP_MBOX_REG[self.dir][inferior].path
|
mdir = IMAP_MBOX_REG[self.dir][inferior].path
|
||||||
IMAP_MBOX_REG[self.dir][inferior].destroy()
|
IMAP_MBOX_REG[self.dir][inferior].destroy()
|
||||||
|
@ -99,17 +99,17 @@ class IMAPUserAccount(object):
|
||||||
|
|
||||||
def rename(self, oldname, newname):
|
def rename(self, oldname, newname):
|
||||||
if oldname in conf.imap_auto_mbox:
|
if oldname in conf.imap_auto_mbox:
|
||||||
raise imap4.MailboxException, oldname
|
raise imap4.MailboxException(oldname)
|
||||||
if isinstance(oldname, unicode):
|
if isinstance(oldname, str):
|
||||||
oldname = oldname.encode('imap4-utf-7')
|
oldname = oldname.encode('imap4-utf-7')
|
||||||
if isinstance(newname, unicode):
|
if isinstance(newname, str):
|
||||||
newname = newname.encode('imap4-utf-7')
|
newname = newname.encode('imap4-utf-7')
|
||||||
if oldname not in IMAP_MBOX_REG[self.dir].keys():
|
if oldname not in IMAP_MBOX_REG[self.dir].keys():
|
||||||
raise imap4.NoSuchMailbox, oldname
|
raise imap4.NoSuchMailbox(oldname)
|
||||||
inferiors = [(o, o.replace(oldname, newname, 1)) for o in self._inferiorNames(oldname)]
|
inferiors = [(o, o.replace(oldname, newname, 1)) for o in self._inferiorNames(oldname)]
|
||||||
for (old, new) in inferiors:
|
for (old, new) in inferiors:
|
||||||
if new in IMAP_MBOX_REG[self.dir].keys():
|
if new in IMAP_MBOX_REG[self.dir].keys():
|
||||||
raise imap4.MailboxCollision, new
|
raise imap4.MailboxCollision(new)
|
||||||
for (old, new) in inferiors:
|
for (old, new) in inferiors:
|
||||||
move(os.path.join(self.dir, old), os.path.join(self.dir, new))
|
move(os.path.join(self.dir, old), os.path.join(self.dir, new))
|
||||||
IMAP_MBOX_REG[self.dir][new] = IMAP_MBOX_REG[self.dir][old]
|
IMAP_MBOX_REG[self.dir][new] = IMAP_MBOX_REG[self.dir][old]
|
||||||
|
@ -120,21 +120,21 @@ class IMAPUserAccount(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def subscribe(self, name):
|
def subscribe(self, name):
|
||||||
if isinstance(name, unicode):
|
if isinstance(name, str):
|
||||||
name = name.encode('imap4-utf-7')
|
name = name.encode('imap4-utf-7')
|
||||||
if name in IMAP_MBOX_REG[self.dir].keys():
|
if name in IMAP_MBOX_REG[self.dir].keys():
|
||||||
IMAP_MBOX_REG[self.dir][name].subscribe()
|
IMAP_MBOX_REG[self.dir][name].subscribe()
|
||||||
|
|
||||||
def unsubscribe(self, name):
|
def unsubscribe(self, name):
|
||||||
if name in conf.imap_auto_mbox:
|
if name in conf.imap_auto_mbox:
|
||||||
raise imap4.MailboxException, name
|
raise imap4.MailboxException(name)
|
||||||
if isinstance(name, unicode):
|
if isinstance(name, str):
|
||||||
name = name.encode('imap4-utf-7')
|
name = name.encode('imap4-utf-7')
|
||||||
if name in IMAP_MBOX_REG[self.dir].keys():
|
if name in IMAP_MBOX_REG[self.dir].keys():
|
||||||
IMAP_MBOX_REG[self.dir][name].unsubscribe()
|
IMAP_MBOX_REG[self.dir][name].unsubscribe()
|
||||||
|
|
||||||
def isSubscribed(self, name):
|
def isSubscribed(self, name):
|
||||||
if isinstance(name, unicode):
|
if isinstance(name, str):
|
||||||
name = name.encode('imap4-utf-7')
|
name = name.encode('imap4-utf-7')
|
||||||
return IMAP_MBOX_REG[self.dir][name].is_subscribed()
|
return IMAP_MBOX_REG[self.dir][name].is_subscribed()
|
||||||
|
|
||||||
|
@ -161,16 +161,16 @@ class SerpentIMAPRealm(object):
|
||||||
|
|
||||||
class IMAPServerProtocol(imap4.IMAP4Server):
|
class IMAPServerProtocol(imap4.IMAP4Server):
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
if isinstance(line, unicode):
|
if isinstance(line, str):
|
||||||
line = line.encode('utf-8')
|
line = line.encode('utf-8')
|
||||||
print "CLIENT:", line
|
print("CLIENT:", line)
|
||||||
imap4.IMAP4Server.lineReceived(self, line)
|
imap4.IMAP4Server.lineReceived(self, line)
|
||||||
|
|
||||||
def sendLine(self, line):
|
def sendLine(self, line):
|
||||||
imap4.IMAP4Server.sendLine(self, line)
|
imap4.IMAP4Server.sendLine(self, line)
|
||||||
if isinstance(line, unicode):
|
if isinstance(line, str):
|
||||||
line = line.encode('utf-8')
|
line = line.encode('utf-8')
|
||||||
print "SERVER:", line
|
print("SERVER:", line)
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
self.setTimeout(None)
|
self.setTimeout(None)
|
||||||
|
@ -186,7 +186,7 @@ class IMAPServerProtocol(imap4.IMAP4Server):
|
||||||
self.account = None
|
self.account = None
|
||||||
|
|
||||||
def _parseMbox(self, name):
|
def _parseMbox(self, name):
|
||||||
if isinstance(name, unicode):
|
if isinstance(name, str):
|
||||||
return name
|
return name
|
||||||
try:
|
try:
|
||||||
return name.decode('imap4-utf-7')
|
return name.decode('imap4-utf-7')
|
||||||
|
@ -277,7 +277,7 @@ class IMAPServerProtocol(imap4.IMAP4Server):
|
||||||
|
|
||||||
def __cbStatus(self, status, tag, box):
|
def __cbStatus(self, status, tag, box):
|
||||||
line = ' '.join(['%s %s' % x for x in status.iteritems()])
|
line = ' '.join(['%s %s' % x for x in status.iteritems()])
|
||||||
if isinstance(box, unicode):
|
if isinstance(box, str):
|
||||||
box = box.encode('imap4-utf-7')
|
box = box.encode('imap4-utf-7')
|
||||||
self.sendUntaggedResponse('STATUS %s (%s)' % (box, line))
|
self.sendUntaggedResponse('STATUS %s (%s)' % (box, line))
|
||||||
self.sendPositiveResponse(tag, 'STATUS complete')
|
self.sendPositiveResponse(tag, 'STATUS complete')
|
||||||
|
@ -293,7 +293,7 @@ class SerpentIMAPFactory(protocol.Factory):
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
contextFactory = None
|
contextFactory = None
|
||||||
if conf.tls:
|
if conf.tls:
|
||||||
tls_data = file(conf.tls_pem, 'rb').read()
|
tls_data = open(conf.tls_pem, 'rb').read()
|
||||||
cert = ssl.PrivateCertificate.loadPEM(tls_data)
|
cert = ssl.PrivateCertificate.loadPEM(tls_data)
|
||||||
contextFactory = cert.options()
|
contextFactory = cert.options()
|
||||||
p = IMAPServerProtocol(contextFactory = contextFactory)
|
p = IMAPServerProtocol(contextFactory = contextFactory)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from serpent import rules
|
||||||
from serpent.queue import squeue
|
from serpent.queue import squeue
|
||||||
|
|
||||||
|
|
||||||
from email.Header import Header
|
from email.header import Header
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
|
||||||
from twisted.internet import defer, ssl
|
from twisted.internet import defer, ssl
|
||||||
|
@ -113,7 +113,7 @@ class SerpentSMTPFactory(smtp.SMTPFactory):
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
contextFactory = None
|
contextFactory = None
|
||||||
if conf.tls:
|
if conf.tls:
|
||||||
tls_data = file(conf.tls_pem, 'rb').read()
|
tls_data = open(conf.tls_pem, 'rb').read()
|
||||||
cert = ssl.PrivateCertificate.loadPEM(tls_data)
|
cert = ssl.PrivateCertificate.loadPEM(tls_data)
|
||||||
contextFactory = cert.options()
|
contextFactory = cert.options()
|
||||||
p = smtp.SMTPFactory.buildProtocol(self, addr)
|
p = smtp.SMTPFactory.buildProtocol(self, addr)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import os
|
||||||
import pickle
|
import pickle
|
||||||
from glob import iglob
|
from glob import iglob
|
||||||
from serpent.config import conf
|
from serpent.config import conf
|
||||||
from serpent.misc import IMAP_FLAGS
|
|
||||||
|
|
||||||
class SmtpFileStore(object):
|
class SmtpFileStore(object):
|
||||||
def __init__(self, dpath):
|
def __init__(self, dpath):
|
||||||
|
|
|
@ -51,7 +51,7 @@ class SmtpQueue(object):
|
||||||
for _, mx in mail_servers:
|
for _, mx in mail_servers:
|
||||||
s = SMTP(local_hostname = conf.smtp_hostname)
|
s = SMTP(local_hostname = conf.smtp_hostname)
|
||||||
try:
|
try:
|
||||||
ret_code, banner = s.connect(mx, 25)
|
ret_code, _ = s.connect(mx, 25)
|
||||||
except:
|
except:
|
||||||
s.quit()
|
s.quit()
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue