[PATCH v2 1/6] Maildir repository: add config keys for IMAP keywords

Igor Almeida igor.contato at gmail.com
Fri Nov 20 19:09:09 GMT 2015


This commit assembles a dictionary mapping user-specified IMAP keywords
to Maildir lower-case flags, similar to Dovecot's format
http://wiki2.dovecot.org/MailboxFormat/Maildir

Configuration example:

[Repository Local]
type = Maildir
localfolders = ~/Maildir/
customflag_a = $label1
customflag_b = $Forwarded
customflag_c = Junk

Signed-off-by: Igor Almeida <igor.contato at gmail.com>
---
 offlineimap/repository/Base.py    |  3 +++
 offlineimap/repository/Maildir.py | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py
index adae16d..8634628 100644
--- a/offlineimap/repository/Base.py
+++ b/offlineimap/repository/Base.py
@@ -133,6 +133,9 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
     def getsep(self):
         raise NotImplementedError
 
+    def getkeywordmap(self):
+        raise NotImplementedError
+
     def should_sync_folder(self, fname):
         """Should this folder be synced?"""
 
diff --git a/offlineimap/repository/Maildir.py b/offlineimap/repository/Maildir.py
index 0262ba2..fef57f3 100644
--- a/offlineimap/repository/Maildir.py
+++ b/offlineimap/repository/Maildir.py
@@ -39,6 +39,14 @@ class MaildirRepository(BaseRepository):
         if not os.path.isdir(self.root):
             os.mkdir(self.root, 0o700)
 
+        # Create the keyword->char mapping
+        self.keyword2char = dict()
+        for c in 'abcdefghijklmnopqrstuvwxyz':
+            confkey = 'customflag_' + c
+            keyword = self.getconf(confkey, None)
+            if keyword is not None:
+                self.keyword2char[keyword] = c
+
     def _append_folder_atimes(self, foldername):
         """Store the atimes of a folder's new|cur in self.folder_atimes"""
 
@@ -72,6 +80,9 @@ class MaildirRepository(BaseRepository):
     def getsep(self):
         return self.getconf('sep', '.').strip()
 
+    def getkeywordmap(self):
+        return self.keyword2char
+
     def makefolder(self, foldername):
         """Create new Maildir folder if necessary
 
-- 
2.5.3





More information about the OfflineIMAP-project mailing list