Improve logging to show skipped mailboxes
[imap-mark-seen] / src / mail_iterator.py
index 9ae25b1..2a35c1c 100644 (file)
@@ -64,12 +64,12 @@ class MailIterator:
         try:
             _result, mailboxes = self.mail_con.list()
         except self.mail_con.error as ex:
-            logging.warning("Could not retrieve mailboxes for user %s: %s", username, ex)
+            logging.error("Could not retrieve mailboxes for user %s: %s", username, ex)
         self.mailboxes = []
         for mailbox in mailboxes:
             mailbox = MAILBOX_RESP.match(mailbox.decode('iso-8859-1')).groups()
             self.mailboxes.append(mailbox)
-        self.mailboxes = sorted(self.mailboxes, key=lambda box: box[2], reverse=True)
+        self.mailboxes = sorted(self.mailboxes, key=lambda box: box[2], reverse=False)
 
         return
 
@@ -93,7 +93,6 @@ class MailIterator:
             # select mailbox if writable
             try:
                 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])
                 continue
@@ -111,9 +110,10 @@ class MailIterator:
         mailid_list = data[0].split()
         return mailid_list
 
-    def set_seen_messages(self, mid_range):
+    def set_seen_messages(self, mailbox, mid_range):
         """Sets the \\Seen flag for all messages with the respective mids."""
 
+        logging.info("Processing mailbox %s", mailbox[2])
         try:
             # Work around unsolicited server responses in imaplib by clearing them
             self.mail_con.response('STORE')