Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7318e52b94 | ||
|
|
f2a43a948a | ||
|
|
de41f90943 | ||
|
|
f36515f233 | ||
|
|
7423d4941d | ||
|
|
44182ddd45 | ||
|
|
9956b94649 |
No files matched your search
@@ -6,7 +6,7 @@ from twisted.python import failure
|
|||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from twisted.internet.task import LoopingCall
|
from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
from zope.interface import implements
|
from zope.interface import implementer
|
||||||
|
|
||||||
from mech_smtp import SerpentSMTPFactory, smtp_portal
|
from mech_smtp import SerpentSMTPFactory, smtp_portal
|
||||||
from mech_imap import SerpentIMAPFactory, imap_portal
|
from mech_imap import SerpentIMAPFactory, imap_portal
|
||||||
@@ -14,10 +14,10 @@ from serpent.usrpwd import dbs
|
|||||||
from serpent.queue import squeue
|
from serpent.queue import squeue
|
||||||
from serpent.config import conf
|
from serpent.config import conf
|
||||||
|
|
||||||
|
@implementer(ICredentialsChecker)
|
||||||
class CredChecker(object):
|
class CredChecker(object):
|
||||||
'''Класс проверки данных авторизации.
|
'''Класс проверки данных авторизации.
|
||||||
Параметром в конструктор передаётся список (list()) объектов баз пользователей.'''
|
Параметром в конструктор передаётся список (list()) объектов баз пользователей.'''
|
||||||
implements(ICredentialsChecker)
|
|
||||||
credentialInterfaces = (credentials.IUsernamePassword,
|
credentialInterfaces = (credentials.IUsernamePassword,
|
||||||
credentials.IUsernameHashedPassword)
|
credentials.IUsernameHashedPassword)
|
||||||
|
|
||||||
|
|||||||
+35
-70
@@ -2,20 +2,19 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from zope.interface import implements
|
from zope.interface import implementer
|
||||||
|
|
||||||
from twisted.cred import portal
|
from twisted.cred import portal
|
||||||
from twisted.internet import protocol, ssl
|
from twisted.internet import protocol, ssl
|
||||||
from twisted.mail import imap4
|
from twisted.mail import imap4
|
||||||
|
|
||||||
from serpent.config import conf
|
from serpent.config import conf
|
||||||
from serpent.imap.mbox import ExtendedMaildir
|
from serpent.imap.mailbox import ExtendedMaildir
|
||||||
from serpent.misc import IMAP_HDELIM, IMAP_MBOX_REG, IMAP_ACC_CONN_NUM
|
from serpent.misc import IMAP_HDELIM, IMAP_MBOX_REG, IMAP_ACC_CONN_NUM
|
||||||
from shutil import rmtree, move
|
from shutil import rmtree, move
|
||||||
|
|
||||||
|
@implementer(imap4.IAccount)
|
||||||
class IMAPUserAccount(object):
|
class IMAPUserAccount(object):
|
||||||
implements(imap4.IAccount)
|
|
||||||
|
|
||||||
def __init__(self, mdir):
|
def __init__(self, mdir):
|
||||||
if not os.path.exists(mdir):
|
if not os.path.exists(mdir):
|
||||||
os.makedirs(mdir)
|
os.makedirs(mdir)
|
||||||
@@ -25,24 +24,16 @@ class IMAPUserAccount(object):
|
|||||||
else:
|
else:
|
||||||
IMAP_MBOX_REG[self.dir] = {}
|
IMAP_MBOX_REG[self.dir] = {}
|
||||||
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.keys():
|
for m in conf.imap_auto_mbox:
|
||||||
name = m
|
|
||||||
if isinstance(m, unicode):
|
|
||||||
m = m.encode('imap4-utf-7')
|
|
||||||
if m not in IMAP_MBOX_REG[self.dir].keys():
|
if m not in IMAP_MBOX_REG[self.dir].keys():
|
||||||
<<<<<<< HEAD
|
if isinstance(m, str):
|
||||||
if isinstance(m, unicode):
|
|
||||||
m = m.encode('imap4-utf-7')
|
m = m.encode('imap4-utf-7')
|
||||||
IMAP_MBOX_REG[self.dir][m] = ExtendedMaildir(os.path.join(self.dir, m))
|
IMAP_MBOX_REG[self.dir][m] = ExtendedMaildir(os.path.join(self.dir, m))
|
||||||
=======
|
|
||||||
IMAP_MBOX_REG[self.dir][m] = self.create(m)
|
|
||||||
IMAP_MBOX_REG[self.dir][m].setSpecial(conf.imap_auto_mbox[name])
|
|
||||||
>>>>>>> refs/remotes/origin/sqlitedict
|
|
||||||
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 = ExtendedMaildir(fullPath)
|
mbox = ExtendedMaildir(fullPath)
|
||||||
@@ -54,7 +45,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]
|
||||||
@@ -62,7 +53,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:
|
||||||
return None
|
raise imap4.NoSuchMailbox(path)
|
||||||
|
|
||||||
def addMailbox(self, name, mbox = None):
|
def addMailbox(self, name, mbox = None):
|
||||||
if mbox:
|
if mbox:
|
||||||
@@ -70,7 +61,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))
|
||||||
@@ -79,29 +70,25 @@ class IMAPUserAccount(object):
|
|||||||
if subpath not in IMAP_MBOX_REG[self.dir].keys():
|
if subpath not in IMAP_MBOX_REG[self.dir].keys():
|
||||||
try:
|
try:
|
||||||
IMAP_MBOX_REG[self.dir][subpath] = self._getMailbox(IMAP_HDELIM.join(paths[:accum]))
|
IMAP_MBOX_REG[self.dir][subpath] = self._getMailbox(IMAP_HDELIM.join(paths[:accum]))
|
||||||
IMAP_MBOX_REG[self.dir][subpath].subscribe()
|
|
||||||
except imap4.MailboxCollision:
|
except imap4.MailboxCollision:
|
||||||
pass
|
pass
|
||||||
IMAP_MBOX_REG[self.dir][subpath].hasChildren()
|
|
||||||
IMAP_MBOX_REG[self.dir][pathspec] = self._getMailbox(pathspec)
|
IMAP_MBOX_REG[self.dir][pathspec] = self._getMailbox(pathspec)
|
||||||
IMAP_MBOX_REG[self.dir][pathspec].hasNoChildren()
|
|
||||||
IMAP_MBOX_REG[self.dir][pathspec].subscribe()
|
|
||||||
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.keys():
|
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.NoSuchMailbox, pathspec
|
raise imap4.MailboxException("No such mailbox")
|
||||||
inferiors = self._inferiorNames(pathspec)
|
inferiors = self._inferiorNames(pathspec)
|
||||||
if r'\Noselect' in IMAP_MBOX_REG[self.dir][pathspec].getFlags():
|
if r'\Noselect' in IMAP_MBOX_REG[self.dir][pathspec].getFlags():
|
||||||
# Check for hierarchically inferior mailboxes with this one
|
# Check for hierarchically inferior mailboxes with this one
|
||||||
# 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()
|
||||||
@@ -110,57 +97,45 @@ class IMAPUserAccount(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def rename(self, oldname, newname):
|
def rename(self, oldname, newname):
|
||||||
if oldname in conf.imap_auto_mbox.keys():
|
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:
|
||||||
IMAP_MBOX_REG[self.dir][old]._stop_monitor()
|
|
||||||
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]
|
||||||
IMAP_MBOX_REG[self.dir][new].path = os.path.join(self.dir, new)
|
IMAP_MBOX_REG[self.dir][new].path = os.path.join(self.dir, new)
|
||||||
<<<<<<< HEAD
|
IMAP_MBOX_REG[self.dir][new].path_msg_info = os.path.join(self.dir, conf.imap_msg_info)
|
||||||
=======
|
IMAP_MBOX_REG[self.dir][new].path_mbox_info = os.path.join(self.dir, conf.imap_mbox_info)
|
||||||
IMAP_MBOX_REG[self.dir][new].open_flags()
|
|
||||||
IMAP_MBOX_REG[self.dir][new]._start_monitor()
|
|
||||||
>>>>>>> refs/remotes/origin/sqlitedict
|
|
||||||
del IMAP_MBOX_REG[self.dir][old]
|
del IMAP_MBOX_REG[self.dir][old]
|
||||||
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()
|
||||||
return True
|
|
||||||
#raise imap4.NoSuchMailbox, name
|
|
||||||
|
|
||||||
def unsubscribe(self, name):
|
def unsubscribe(self, name):
|
||||||
if name in conf.imap_auto_mbox.keys():
|
if name in conf.imap_auto_mbox:
|
||||||
return False
|
raise imap4.MailboxException(name)
|
||||||
# raise imap4.MailboxException, name
|
if isinstance(name, str):
|
||||||
if isinstance(name, unicode):
|
|
||||||
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()
|
||||||
return True
|
|
||||||
#raise imap4.NoSuchMailbox, name
|
|
||||||
|
|
||||||
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')
|
||||||
if name in IMAP_MBOX_REG[self.dir].keys():
|
|
||||||
return IMAP_MBOX_REG[self.dir][name].is_subscribed()
|
return IMAP_MBOX_REG[self.dir][name].is_subscribed()
|
||||||
else:
|
|
||||||
raise imap4.NoSuchMailbox, name
|
|
||||||
|
|
||||||
def _inferiorNames(self, name):
|
def _inferiorNames(self, name):
|
||||||
name_l = name.split(IMAP_HDELIM)
|
name_l = name.split(IMAP_HDELIM)
|
||||||
@@ -170,9 +145,8 @@ class IMAPUserAccount(object):
|
|||||||
inferiors.append(infname)
|
inferiors.append(infname)
|
||||||
return inferiors
|
return inferiors
|
||||||
|
|
||||||
|
@implementer(portal.IRealm)
|
||||||
class SerpentIMAPRealm(object):
|
class SerpentIMAPRealm(object):
|
||||||
implements(portal.IRealm)
|
|
||||||
|
|
||||||
def requestAvatar(self, avatarId, mind, *interfaces):
|
def requestAvatar(self, avatarId, mind, *interfaces):
|
||||||
if imap4.IAccount not in interfaces:
|
if imap4.IAccount not in interfaces:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
@@ -185,16 +159,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)
|
||||||
@@ -210,7 +184,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')
|
||||||
@@ -301,20 +275,12 @@ 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')
|
||||||
def __ebStatus(self, failure, tag, box):
|
def __ebStatus(self, failure, tag, box):
|
||||||
self.sendBadResponse(tag, 'STATUS %s failed: %s' % (box, str(failure.value)))
|
self.sendBadResponse(tag, 'STATUS %s failed: %s' % (box, str(failure.value)))
|
||||||
def _cbListWork(self, mailboxes, tag, sub, cmdName):
|
|
||||||
for (name, box) in mailboxes:
|
|
||||||
if not sub or self.account.isSubscribed(name):
|
|
||||||
flags = box.getMboxFlags()
|
|
||||||
delim = box.getHierarchicalDelimiter()
|
|
||||||
resp = (imap4.DontQuoteMe(cmdName), map(imap4.DontQuoteMe, flags), delim, name.encode('imap4-utf-7'))
|
|
||||||
self.sendUntaggedResponse(imap4.collapseNestedLists(resp))
|
|
||||||
self.sendPositiveResponse(tag, '%s completed' % (cmdName,))
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
@@ -325,11 +291,10 @@ 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)
|
||||||
p.setTimeout(conf.imap_connection_timeout)
|
|
||||||
if conf.tls:
|
if conf.tls:
|
||||||
p.canStartTLS = True
|
p.canStartTLS = True
|
||||||
p.IDENT = '%s ready' % conf.SRVNAME
|
p.IDENT = '%s ready' % conf.SRVNAME
|
||||||
|
|||||||
+6
-11
@@ -5,8 +5,8 @@ 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 implementer
|
||||||
|
|
||||||
from twisted.internet import defer, ssl
|
from twisted.internet import defer, ssl
|
||||||
from twisted.mail import smtp
|
from twisted.mail import smtp
|
||||||
@@ -16,10 +16,8 @@ from twisted.cred.portal import IRealm, Portal
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@implementer(smtp.IMessageDelivery)
|
||||||
class SmtpMessageDelivery:
|
class SmtpMessageDelivery:
|
||||||
implements(smtp.IMessageDelivery)
|
|
||||||
|
|
||||||
def __init__(self, avatarId = None):
|
def __init__(self, avatarId = None):
|
||||||
self.avatarId = avatarId
|
self.avatarId = avatarId
|
||||||
|
|
||||||
@@ -59,9 +57,8 @@ class SmtpMessageDelivery:
|
|||||||
}
|
}
|
||||||
return lambda: SmtpMessage(msg)
|
return lambda: SmtpMessage(msg)
|
||||||
|
|
||||||
|
@implementer(smtp.IMessage)
|
||||||
class SmtpMessage:
|
class SmtpMessage:
|
||||||
implements(smtp.IMessage)
|
|
||||||
|
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
self.lines = []
|
self.lines = []
|
||||||
self.size = 0
|
self.size = 0
|
||||||
@@ -113,7 +110,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)
|
||||||
@@ -126,10 +123,8 @@ class SerpentSMTPFactory(smtp.SMTPFactory):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
|
@implementer(IRealm)
|
||||||
class SmtpRealm:
|
class SmtpRealm:
|
||||||
implements(IRealm)
|
|
||||||
|
|
||||||
def requestAvatar(self, avatarId, mind, *interfaces):
|
def requestAvatar(self, avatarId, mind, *interfaces):
|
||||||
if smtp.IMessageDelivery in interfaces:
|
if smtp.IMessageDelivery in interfaces:
|
||||||
return smtp.IMessageDelivery, SmtpMessageDelivery(avatarId), lambda: None
|
return smtp.IMessageDelivery, SmtpMessageDelivery(avatarId), lambda: None
|
||||||
|
|||||||
+3
-12
@@ -6,10 +6,9 @@ conf = Config()
|
|||||||
conf.VERSION = '0.1.0'
|
conf.VERSION = '0.1.0'
|
||||||
conf.SRVNAME = 'Serpent'
|
conf.SRVNAME = 'Serpent'
|
||||||
conf.srv_version = '%s %s' % (conf.SRVNAME, conf.VERSION)
|
conf.srv_version = '%s %s' % (conf.SRVNAME, conf.VERSION)
|
||||||
conf.imap_connection_timeout = 120
|
|
||||||
conf.local_domains = ['dom.lan'] # Список доменов, для которых будет приниматься почта
|
conf.local_domains = ['dom.lan'] # Список доменов, для которых будет приниматься почта
|
||||||
conf.tls = True
|
conf.tls = True
|
||||||
conf.tls_pem = u'./serpent.pem'
|
conf.tls_pem = './serpent.pem'
|
||||||
conf.smtp_open_relay = False # Разрешить ли пересылку откуда угодно куда угодно
|
conf.smtp_open_relay = False # Разрешить ли пересылку откуда угодно куда угодно
|
||||||
conf.smtp_email_delim = '@'
|
conf.smtp_email_delim = '@'
|
||||||
conf.smtp_header = '''from [{sender_ip}] (helo={sender_host})
|
conf.smtp_header = '''from [{sender_ip}] (helo={sender_host})
|
||||||
@@ -29,17 +28,9 @@ conf.smtp_email_tls_required = True
|
|||||||
|
|
||||||
conf.imap_SENT = 'Sent'
|
conf.imap_SENT = 'Sent'
|
||||||
conf.imap_TRASH = 'Trash'
|
conf.imap_TRASH = 'Trash'
|
||||||
conf.imap_JUNK = 'Junk'
|
conf.imap_subscribed = '.subscribed'
|
||||||
conf.imap_ARCHIVE = 'Archive'
|
|
||||||
conf.imap_DRAFTS = 'Drafts'
|
|
||||||
conf.imap_msg_info = 'msg_info.db'
|
conf.imap_msg_info = 'msg_info.db'
|
||||||
conf.imap_mbox_info = 'mbox_info.db'
|
conf.imap_mbox_info = 'mbox_info.db'
|
||||||
conf.imap_auto_mbox = {'INBOX': '\\INBOX',
|
conf.imap_auto_mbox = ['INBOX', 'Sent', 'Trash']
|
||||||
conf.imap_SENT: '\\Sent',
|
|
||||||
conf.imap_TRASH: '\\Trash',
|
|
||||||
conf.imap_JUNK: '\\Junk',
|
|
||||||
conf.imap_ARCHIVE: '\\Archive',
|
|
||||||
conf.imap_DRAFTS: '\\Drafts'
|
|
||||||
}
|
|
||||||
conf.imap_expunge_on_close = True
|
conf.imap_expunge_on_close = True
|
||||||
conf.imap_check_new_interval = 10.0 # Период проверки новых сообщений в ящике
|
conf.imap_check_new_interval = 10.0 # Период проверки новых сообщений в ящике
|
||||||
+3
-6
@@ -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):
|
||||||
@@ -60,16 +59,14 @@ class SmtpFileStore(object):
|
|||||||
|
|
||||||
class MailDirStore(object):
|
class MailDirStore(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
from serpent.imap import mbox
|
import mailbox
|
||||||
from mailbox import MaildirMessage
|
self.mbox = mailbox
|
||||||
self.mbox = mbox
|
|
||||||
self.mbox.MaildirMessage = MaildirMessage
|
|
||||||
def deliver(self, user, message):
|
def deliver(self, user, message):
|
||||||
mdir = os.path.join(conf.app_dir, conf.maildir_user_path % user)
|
mdir = os.path.join(conf.app_dir, conf.maildir_user_path % user)
|
||||||
if not os.path.exists(mdir):
|
if not os.path.exists(mdir):
|
||||||
os.makedirs(mdir)
|
os.makedirs(mdir)
|
||||||
inbox = os.path.join(mdir, 'INBOX')
|
inbox = os.path.join(mdir, 'INBOX')
|
||||||
mailbox = self.mbox.ExtendedMaildir(inbox)
|
mailbox = self.mbox.Maildir(inbox)
|
||||||
msg = self.mbox.MaildirMessage(message)
|
msg = self.mbox.MaildirMessage(message)
|
||||||
try:
|
try:
|
||||||
mailbox.add(msg, [])
|
mailbox.add(msg, [])
|
||||||
|
|||||||
File renamed without changes.
@@ -10,14 +10,6 @@ IMAP_FLAGS = {
|
|||||||
'T': '\\Trashed',
|
'T': '\\Trashed',
|
||||||
'D': '\\Draft'
|
'D': '\\Draft'
|
||||||
}
|
}
|
||||||
MBOX_FLAGS = {
|
|
||||||
'NOINFERIORS': '\\Noinferiors',
|
|
||||||
'NOSELECT': '\\Noselect',
|
|
||||||
'MARKED': '\\Marked',
|
|
||||||
'UNMARKED': '\\Unmarked',
|
|
||||||
'HASCHILDREN': '\\HasChildren',
|
|
||||||
'HASNOCHILDREN': '\\HasNoChildren'
|
|
||||||
}
|
|
||||||
IMAP_HDELIM = '.'
|
IMAP_HDELIM = '.'
|
||||||
IMAP_ACC_CONN_NUM = '...ConnectionNumber...'
|
IMAP_ACC_CONN_NUM = '...ConnectionNumber...'
|
||||||
IMAP_MBOX_REG = {}
|
IMAP_MBOX_REG = {}
|
||||||
+1
-1
@@ -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
|
||||||
|
|||||||
Reference in new issue
Block a user