Add mmassive e-mail update for performance by using message set STORE command
[imap-mark-seen] / mail_iterator.py
index 4fb7bc2..f7c8013 100644 (file)
@@ -76,7 +76,7 @@ class MailIterator:
                 self.mail_con.select(mailbox[2])
                 logging.info("Processing mailbox %s", mailbox[2])
             except self.mail_con.readonly:
-                logging.warning("Mailbox %s is not writable and therefore skipped.", mailbox[2])
+                logging.warning("Mailbox %s is not writable and therefore skipped", mailbox[2])
                 continue
             yield mailbox
 
@@ -88,18 +88,18 @@ class MailIterator:
             self.mail_con.response('SEARCH')
             _result, data = self.mail_con.uid('search', None, "ALL")
         except (self.mail_con.error):
-            raise UserWarning("Could not fetch messages.")
+            raise UserWarning("Could not fetch messages")
         mailid_list = data[0].split()
         return mailid_list
 
-    def set_message_seen(self, mid):
-        """Sets the \\Seen flag for a message."""
+    def set_seen_messages(self, mid_range):
+        """Sets the \\Seen flag for all messages with the respective mids."""
         
         try:
             # Work around unsolicited server responses in imaplib by clearing them
             self.mail_con.response('STORE')
-            _result, data = self.mail_con.uid('STORE', mid, '+FLAGS', "(\Seen)")
-            logging.debug("New flags for message %s are %s", mid, data)
-        except (self.mail_con.error):
-            raise UserWarning("Could not set the flags for the e-mail " + mid.decode('iso-8859-1') + ".")
+            _result, data = self.mail_con.uid('STORE', mid_range, '+FLAGS', "(\Seen)")
+            logging.info("New flags for messages %s are %s", mid_range, data)
+        except (self.mail_con.error) as ex:
+            raise UserWarning("Could not set the flags for some messages: %s", ex)
         self.mail_con.expunge()