mech_imap

python3
inpos 2016-06-05 11:28:26 +03:00
parent de41f90943
commit f2a43a948a
2 changed files with 12 additions and 9 deletions

View File

@ -9,7 +9,7 @@ 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.mailbox import IMAPMailbox 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
@ -29,7 +29,7 @@ class IMAPUserAccount(object):
if m not in IMAP_MBOX_REG[self.dir].keys(): if m not in IMAP_MBOX_REG[self.dir].keys():
if isinstance(m, str): 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] = ExtendedMaildir(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)
@ -37,7 +37,7 @@ class IMAPUserAccount(object):
if isinstance(path, str): 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 = ExtendedMaildir(fullPath)
mbox._start_monitor() mbox._start_monitor()
return mbox return mbox

View File

@ -10,8 +10,10 @@ class ExtendedMaildir(Maildir):
oldpath = os.path.join(self._path, subpath) oldpath = os.path.join(self._path, subpath)
newsubdir = os.path.split(subpath)[0] newsubdir = os.path.split(subpath)[0]
newname = key + self.colon + info newname = key + self.colon + info
if 'S' not in sflags and newsubdir == 'new': if 'S' in sflags and newsubdir == 'new':
newsubdir = 'cur' newsubdir = 'cur'
if 'S' not in sflags and newsubdir == 'cur':
newsubdir = 'new'
newpath = os.path.join(self._path, newsubdir, newname) newpath = os.path.join(self._path, newsubdir, newname)
if hasattr(os, 'link'): if hasattr(os, 'link'):
os.link(oldpath, newpath) os.link(oldpath, newpath)
@ -27,8 +29,9 @@ class ExtendedMaildir(Maildir):
return info[2:] return info[2:]
else: else:
return '' return ''
def add_flag(self, flag): def add_flag(self, key, flag):
self.set_flags(''.join(set(self.get_flags()) | set(flag))) self.set_flags(key, ''.join(set(self.get_flags(key)) | set(flag)))
def remove_flag(self, flag): def remove_flag(self, key, flag):
if self.get_flags(): if flag not in self.get_flags(key): return True
self.set_flags(''.join(set(self.get_flags()) - set(flag))) if self.get_flags(key):
self.set_flags(key, ''.join(set(self.get_flags(key)) - set(flag)))