[PATCH 4/4] set and use additional flags map if available

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


Translate non standard extra flags into imap flags if ext_flags_remap is
not empty.

Signed-off-by: Igor Mammedov <imammedo at redhat.com>
---
 offlineimap/accounts.py    |  1 +
 offlineimap/folder/IMAP.py | 12 ++++++------
 offlineimap/imaputil.py    | 10 ++++++++--
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 8b39c7e..9056197 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -428,6 +428,7 @@ def syncfolder(account, remotefolder, quick):
 
         # Load remote folder.
         ui.loadmessagelist(remoterepos, remotefolder)
+        remotefolder.set_flags_remap(localfolder.get_flags_remap())
         remotefolder.cachemessagelist()
         ui.messagelistloaded(remoterepos, remotefolder,
                              remotefolder.getmessagecount())
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index bb1b51f..f9c5750 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -195,7 +195,7 @@ class IMAPFolder(BaseFolder):
                                           minor = 1)
             else:
                 uid = long(options['UID'])
-                flags = imaputil.flagsimap2maildir(options['FLAGS'])
+                flags = imaputil.flagsimap2maildir(options['FLAGS'], self.ext_flags_remap)
                 rtime = imaplibutil.Internaldate2epoch(messagestr)
                 self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime}
 
@@ -545,7 +545,7 @@ class IMAPFolder(BaseFolder):
                 #Do the APPEND
                 try:
                     (typ, dat) = imapobj.append(self.getfullname(),
-                                       imaputil.flagsmaildir2imap(flags),
+                                       imaputil.flagsmaildir2imap(flags, self.ext_flags_remap),
                                        date, content)
                     retry_left = 0                # Mark as success
                 except imapobj.abort as e:
@@ -630,7 +630,7 @@ class IMAPFolder(BaseFolder):
                 self.ui.flagstoreadonly(self, [uid], flags)
                 return
             result = imapobj.uid('store', '%d' % uid, 'FLAGS',
-                                 imaputil.flagsmaildir2imap(flags))
+                                 imaputil.flagsmaildir2imap(flags), self.ext_flags_remap)
             assert result[0] == 'OK', 'Error with store: ' + '. '.join(result[1])
         finally:
             self.imapserver.releaseconnection(imapobj)
@@ -639,7 +639,7 @@ class IMAPFolder(BaseFolder):
             self.messagelist[uid]['flags'] = flags
         else:
             flags = imaputil.flags2hash(imaputil.imapsplit(result)[1])['FLAGS']
-            self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags)
+            self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags, self.ext_flags_remap)
 
     def addmessageflags(self, uid, flags):
         self.addmessagesflags([uid], flags)
@@ -676,7 +676,7 @@ class IMAPFolder(BaseFolder):
             r = imapobj.uid('store',
                             imaputil.uid_sequence(uidlist),
                             operation + 'FLAGS',
-                            imaputil.flagsmaildir2imap(flags))
+                            imaputil.flagsmaildir2imap(flags, self.ext_flags_remap))
             assert r[0] == 'OK', 'Error with store: ' + '. '.join(r[1])
             r = r[1]
         finally:
@@ -696,7 +696,7 @@ class IMAPFolder(BaseFolder):
                 continue
             flagstr = attributehash['FLAGS']
             uid = long(attributehash['UID'])
-            self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flagstr)
+            self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flagstr, self.ext_flags_remap)
             try:
                 needupdate.remove(uid)
             except ValueError:          # Let it slide if it's not in the list
diff --git a/offlineimap/imaputil.py b/offlineimap/imaputil.py
index 557064b..0c70503 100644
--- a/offlineimap/imaputil.py
+++ b/offlineimap/imaputil.py
@@ -172,21 +172,27 @@ flagmap = [('\\Seen', 'S'),
            ('\\Deleted', 'T'),
            ('\\Draft', 'D')]
 
-def flagsimap2maildir(flagstring):
+def flagsimap2maildir(flagstring, ext_remap):
     """Convert string '(\\Draft \\Deleted)' into a flags set(DR)"""
     retval = set()
     imapflaglist = flagstring[1:-1].split()
     for imapflag, maildirflag in flagmap:
         if imapflag in imapflaglist:
             retval.add(maildirflag)
+    for imapflag, maildirflag in ext_remap:
+        if imapflag in imapflaglist:
+            retval.add(maildirflag)
     return retval
 
-def flagsmaildir2imap(maildirflaglist):
+def flagsmaildir2imap(maildirflaglist, ext_remap):
     """Convert set of flags ([DR]) into a string '(\\Deleted \\Draft)'"""
     retval = []
     for imapflag, maildirflag in flagmap:
         if maildirflag in maildirflaglist:
             retval.append(imapflag)
+    for imapflag, maildirflag in ext_remap:
+        if maildirflag in maildirflaglist:
+            retval.append(imapflag)
     return '(' + ' '.join(sorted(retval)) + ')'
 
 def uid_sequence(uidlist):
-- 
1.7.11.2





More information about the OfflineIMAP-project mailing list