actions: surround flags with parenthesis
authorOlivier Matz <zer0@droids-corp.org>
Sun, 27 Nov 2016 14:40:04 +0000 (15:40 +0100)
committerOlivier Matz <olivier.matz@6wind.com>
Mon, 28 Nov 2016 10:01:38 +0000 (11:01 +0100)
It looks that when using uid, some servers expects that the flags
are surrounded by parenthesis. Else, we get this error:

UID command error: BAD
['Error in IMAP command UID STORE: Flags list contains non-atoms.']

Seen also here:
https://github.com/coddingtonbear/django-mailbox/commit/dad65d802c7eab86c88dca3ef466dc4c43daffc0

Signed-off-by: Olivier Matz <zer0@droids-corp.org>
imapami/actions.py

index 8653ea0..ae3c9ef 100644 (file)
@@ -203,8 +203,7 @@ class ImapamiActionChangeFlag(ImapamiAction):
             cmd = '+FLAGS'
         else:
             cmd = '-FLAGS'
-        flag = '\\' + self.evaluate(self.flag, ami,
-                                    mail.msg)
+        flag = '(\\%s)' % self.evaluate(self.flag, ami, mail.msg)
         ret, msg = imap.uid("STORE", mail.item, cmd, flag)
         if ret != "OK":
             ami.logger.warning(
@@ -281,7 +280,7 @@ class ImapamiActionMove(ImapamiAction):
             ami.logger.warning(
                 "imap copy returned %s: %s" % (ret, str(msg)))
             return False
-        ret, msg = imap.uid("STORE", mail.item, '+FLAGS', '\\Deleted')
+        ret, msg = imap.uid("STORE", mail.item, '+FLAGS', '(\\Deleted)')
         if ret != "OK":
             ami.logger.warning(
                 "imap delete returned %s: %s" % (ret, str(msg)))