[PATCH 2/3] IMAP folder: expose the message keywords

Igor Almeida igor.contato at gmail.com
Sat Nov 7 14:16:54 GMT 2015


The keywords are in the flag string, so imaputil can just strip the
usual \Flags.

Signed-off-by: Igor Almeida <igor.contato at gmail.com>
---
 offlineimap/folder/Base.py | 5 +++++
 offlineimap/folder/IMAP.py | 8 +++++++-
 offlineimap/imaputil.py    | 8 ++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index d2a0706..5031a40 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -420,6 +420,11 @@ class BaseFolder(object):
 
         raise NotImplementedError
 
+    def getmessagekeywords(self, uid):
+        """Returns the keywords for the specified message."""
+
+        raise NotImplementedError
+
     def savemessageflags(self, uid, flags):
         """Sets the specified message's flags to the given set.
 
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 60b5301..7f0fd6d 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -251,8 +251,10 @@ class IMAPFolder(BaseFolder):
                 uid = long(options['UID'])
                 self.messagelist[uid] = self.msglist_item_initializer(uid)
                 flags = imaputil.flagsimap2maildir(options['FLAGS'])
+                keywords = imaputil.flagsimap2keywords(options['FLAGS'])
                 rtime = imaplibutil.Internaldate2epoch(messagestr)
-                self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime}
+                self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime,
+                    'keywords': keywords}
         self.ui.messagelistloaded(self.repository, self, self.getmessagecount())
 
     def dropmessagelistcache(self):
@@ -309,6 +311,10 @@ class IMAPFolder(BaseFolder):
     def getmessageflags(self, uid):
         return self.messagelist[uid]['flags']
 
+    # Interface from BaseFolder
+    def getmessagekeywords(self, uid):
+        return self.messagelist[uid]['keywords']
+
     def __generate_randomheader(self, content):
         """Returns a unique X-OfflineIMAP header
 
diff --git a/offlineimap/imaputil.py b/offlineimap/imaputil.py
index 6d8b444..6a18732 100644
--- a/offlineimap/imaputil.py
+++ b/offlineimap/imaputil.py
@@ -195,6 +195,14 @@ def flagsimap2maildir(flagstring):
             retval.add(maildirflag)
     return retval
 
+def flagsimap2keywords(flagstring):
+    """Convert string '(\\Draft \\Deleted somekeyword otherkeyword)' into a
+    keyword set (somekeyword otherkeyword)."""
+
+    imapflagset = set(flagstring[1:-1].split())
+    serverflagset = set([flag for (flag, c) in flagmap])
+    return imapflagset - serverflagset
+
 def flagsmaildir2imap(maildirflaglist):
     """Convert set of flags ([DR]) into a string '(\\Deleted \\Draft)'."""
 
-- 
2.5.3





More information about the OfflineIMAP-project mailing list