From: Olivier Matz Date: Tue, 29 Mar 2016 08:38:13 +0000 (+0200) Subject: use uids to manipulate mails X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c3f8bd76c0ca6ccaf323c0df86cf6b233b90fe1d;p=imapami.git use uids to manipulate mails The item identifier can be modified in some conditions, for instance after an expunge operation. This could leads to manipulate the wrong mail. Use uids instead, which does not vary for a given mail. Signed-off-by: Olivier Matz --- diff --git a/imapami/actions.py b/imapami/actions.py index 169588c..8653ea0 100644 --- a/imapami/actions.py +++ b/imapami/actions.py @@ -170,7 +170,7 @@ class ImapamiActionCopy(ImapamiAction): imap = ami.imap dest = self.evaluate(self.dest, ami, mail.msg) imap.create(dest) - ret, msg = imap.copy(mail.item, dest) + ret, msg = imap.uid("COPY", mail.item, dest) if ret != "OK": ami.logger.warning( "imap copy returned %s: %s" % (ret, str(msg))) @@ -205,7 +205,7 @@ class ImapamiActionChangeFlag(ImapamiAction): cmd = '-FLAGS' flag = '\\' + self.evaluate(self.flag, ami, mail.msg) - ret, msg = imap.store(mail.item, cmd, flag) + ret, msg = imap.uid("STORE", mail.item, cmd, flag) if ret != "OK": ami.logger.warning( "imap store '%s %s' returned %s: %s" % ( @@ -276,12 +276,12 @@ class ImapamiActionMove(ImapamiAction): imap = ami.imap dest = self.evaluate(self.dest, ami, mail.msg) imap.create(dest) - ret, msg = imap.copy(mail.item, dest) + ret, msg = imap.uid("COPY", mail.item, dest) if ret != "OK": ami.logger.warning( "imap copy returned %s: %s" % (ret, str(msg))) return False - ret, msg = imap.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))) diff --git a/imapami/rules.py b/imapami/rules.py index 840d1aa..9efd6dd 100644 --- a/imapami/rules.py +++ b/imapami/rules.py @@ -166,7 +166,7 @@ class ImapamiRule(object): criteria = "(%s)" % self.get_criteria(ami) ami.logger.debug("processing rule %s, inbox %s, imap criteria %s", self.name, inbox, criteria) - resp, items = ami.imap.search(None, criteria) + resp, items = ami.imap.uid("SEARCH", None, criteria) if resp != 'OK': ami.logger.warning( "search failed: server response = %s, skip rule", resp) @@ -220,7 +220,8 @@ class ImapamiRule(object): for item in item_list: mail_data = {'item': item, 'inbox': inbox} if parts != []: - resp, data = ami.imap.fetch(item, parts_str) + resp, data = ami.imap.uid("FETCH", item, parts_str) + print resp, data if resp != 'OK': ami.logger.warning( "search failed: server response = %s, skip item",