[PATCH v2 3/6] __syncmessagesto_flags: store keywords

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


This uses the destination folder's keyword mapping to translate the
message's keywords into some appropriate format.

Tested only with local Maildir.

Signed-off-by: Igor Almeida <igor.contato at gmail.com>
---
 offlineimap/folder/Base.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 5031a40..b48afbe 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -937,6 +937,32 @@ class BaseFolder(object):
             else:
                 statusflags = set()
 
+            #keywords: if there is a keyword map, use it to figure out what
+            #other 'flags' we should add
+            try:
+                keywordmap = dstfolder.getrepository().getkeywordmap()
+                knownkeywords = set(keywordmap.keys())
+
+                selfkeywords = self.getmessagekeywords(uid)
+
+                if not knownkeywords >= selfkeywords:
+                    #some of the message's keywords are not in the mapping, so
+                    #skip them
+
+                    skipped_keywords = list(selfkeywords - knownkeywords)
+                    selfkeywords &= knownkeywords
+
+                    self.ui.warn("Unknown keywords skipped: %s\n"
+                        "You may want to change your configuration to include "
+                        "those\n" % (skipped_keywords))
+
+                keywordletterset = set([keywordmap[keyw] for keyw in selfkeywords])
+
+                #add the lower-case letters to the list of message flags
+                selfflags |= keywordletterset
+            except NotImplementedError:
+                pass
+
             addflags = selfflags - statusflags
             delflags = statusflags - selfflags
 
-- 
2.5.3





More information about the OfflineIMAP-project mailing list