X-Git-Url: http://developer.intra2net.com/git/?p=imap-mark-seen;a=blobdiff_plain;f=mail_iterator.py;h=f7c8013a8856737f1e08022460ddddb631657d88;hp=4fb7bc27aeb46425d61a0f2f15c623da550eb6ed;hb=9d32827599488b7c57f04a6c0586da7c9f039e97;hpb=7c7f439f4bd233e1d771cfdd43a19e91a72666d1 diff --git a/mail_iterator.py b/mail_iterator.py index 4fb7bc2..f7c8013 100644 --- a/mail_iterator.py +++ b/mail_iterator.py @@ -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()