From de41f90943fb96ee7c1b8851f14840c5b2a6d70f Mon Sep 17 00:00:00 2001 From: inpos Date: Tue, 31 May 2016 14:11:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=BB=D0=B0=D0=B3=D0=B8=20=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D1=8C=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- serpent/imap/mailbox.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/serpent/imap/mailbox.py b/serpent/imap/mailbox.py index da7e4b1..0cc1755 100644 --- a/serpent/imap/mailbox.py +++ b/serpent/imap/mailbox.py @@ -1,11 +1,34 @@ from mailbox import Maildir +import os class ExtendedMaildir(Maildir): - def set_flags(self, key): - pass + def set_flags(self, key, flags): + sflags = sorted(flags) + if sflags == self.get_flags(key): return True + subpath = self._lookup(key) + info = '2,' + ''.join(sflags) + 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': + newsubdir = 'cur' + newpath = os.path.join(self._path, newsubdir, newname) + if hasattr(os, 'link'): + os.link(oldpath, newpath) + os.remove(oldpath) + else: + os.rename(oldpath, newpath) + self._toc[key] = os.path.join(newsubdir, newname) def get_flags(self, key): - pass - def add_flag(self): - pass - def remove_flag(self): - pass \ No newline at end of file + subpath = self._lookup(key) + _, name = os.path.split(subpath) + info = name.split(self.colon)[-1] + if info.startswith('2,'): + 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