From f2a43a948a97540b6d23793b88ff84e85f14cdf7 Mon Sep 17 00:00:00 2001 From: inpos Date: Sun, 5 Jun 2016 11:28:26 +0300 Subject: [PATCH] mech_imap --- mech_imap.py | 6 +++--- serpent/imap/mailbox.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mech_imap.py b/mech_imap.py index 702c055..21c8dcd 100644 --- a/mech_imap.py +++ b/mech_imap.py @@ -9,7 +9,7 @@ from twisted.internet import protocol, ssl from twisted.mail import imap4 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 shutil import rmtree, move @@ -29,7 +29,7 @@ class IMAPUserAccount(object): if m not in IMAP_MBOX_REG[self.dir].keys(): if isinstance(m, str): 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() self.subscribe(m) @@ -37,7 +37,7 @@ class IMAPUserAccount(object): if isinstance(path, str): path = path.encode('imap4-utf-7') fullPath = os.path.join(self.dir, path) - mbox = IMAPMailbox(fullPath) + mbox = ExtendedMaildir(fullPath) mbox._start_monitor() return mbox diff --git a/serpent/imap/mailbox.py b/serpent/imap/mailbox.py index 0cc1755..be87ad3 100644 --- a/serpent/imap/mailbox.py +++ b/serpent/imap/mailbox.py @@ -10,8 +10,10 @@ class ExtendedMaildir(Maildir): oldpath = os.path.join(self._path, subpath) newsubdir = os.path.split(subpath)[0] newname = key + self.colon + info - if 'S' not in sflags and newsubdir == 'new': + if 'S' in sflags and newsubdir == 'new': newsubdir = 'cur' + if 'S' not in sflags and newsubdir == 'cur': + newsubdir = 'new' newpath = os.path.join(self._path, newsubdir, newname) if hasattr(os, 'link'): os.link(oldpath, newpath) @@ -27,8 +29,9 @@ class ExtendedMaildir(Maildir): return info[2:] else: return '' - def add_flag(self, flag): - self.set_flags(''.join(set(self.get_flags()) | set(flag))) - def remove_flag(self, flag): - if self.get_flags(): - self.set_flags(''.join(set(self.get_flags()) - set(flag))) \ No newline at end of file + def add_flag(self, key, flag): + self.set_flags(key, ''.join(set(self.get_flags(key)) | set(flag))) + def remove_flag(self, key, flag): + if flag not in self.get_flags(key): return True + if self.get_flags(key): + self.set_flags(key, ''.join(set(self.get_flags(key)) - set(flag))) \ No newline at end of file