[PATCH 3/4] maildir: read and parse dovecot-keywords

Igor Mammedov imammedo at redhat.com
Thu Aug 16 02:50:10 BST 2012


into (maildirflag, imapflag) list and override get_flags_remap() to return
dovecot_flagsmap for MaildirFolder

Signed-off-by: Igor Mammedov <imammedo at redhat.com>
---
 offlineimap/folder/Maildir.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index 6609baa..1eb63c2 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -78,6 +78,7 @@ class MaildirFolder(BaseFolder):
         self._foldermd5 = md5(self.getvisiblename()).hexdigest()
         # Cache the full folder path, as we use getfullname() very often
         self._fullname = os.path.join(self.getroot(), self.getname())
+        self.dovecot_flagsmap = []
 
     def getfullname(self):
         """Return the absolute file path to the Maildir folder (sans cur|new)"""
@@ -143,6 +144,23 @@ class MaildirFolder(BaseFolder):
             flags = set((c for c in flagmatch.group(1)))
         return prefix, uid, fmd5, flags
 
+    def _read_dovecot_flagsmap(self):
+        """Cache dovecot mapping its custom flags into imap flags."""
+
+        try:
+            dovecot_keys_file = os.path.join(self.getfullname(), "dovecot-keywords")
+            with open(dovecot_keys_file, 'r') as f:
+                d = dict(x.rstrip().split(None, 1) for x in f)
+            self.dovecot_flagsmap = []
+            for key in d:
+                v = chr(int(key) + ord('a'))
+                self.dovecot_flagsmap.append((d[key], v))
+        except IOError:
+            pass
+
+    def get_flags_remap(self):
+        return self.dovecot_flagsmap
+
     def _scanfolder(self):
         """Cache the message list from a Maildir.
 
@@ -155,6 +173,8 @@ class MaildirFolder(BaseFolder):
                                             "maxsize", None)
         retval = {}
         files = []
+        self._read_dovecot_flagsmap()
+        self.set_flags_remap(self.get_flags_remap())
         nouidcounter = -1          # Messages without UIDs get negative UIDs.
         for dirannex in ['new', 'cur']:
             fulldirname = os.path.join(self.getfullname(), dirannex)
-- 
1.7.11.2





More information about the OfflineIMAP-project mailing list