From fbd3120a9aa73b508383aa78eaa67801526eb95a Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Fri, 13 Jul 2012 17:16:06 +0200 Subject: [PATCH] Improve logging to show skipped mailboxes --- src/imap_mark_seen.py | 5 ++++- src/mail_iterator.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/imap_mark_seen.py b/src/imap_mark_seen.py index d5a33f0..c765511 100644 --- a/src/imap_mark_seen.py +++ b/src/imap_mark_seen.py @@ -41,6 +41,7 @@ def main(): delimiter = re.escape(mailbox[1]) pattern = '^\"?INBOX' + delimiter + re.escape(args.folder) + "[\"?$|" + delimiter + "]" if args.folder != "all folders" and re.compile(pattern).match(mailbox[2]) == None: + logging.info("Skipping mailbox %s", mailbox[2]) continue try: mail_ids = session.fetch_messages() @@ -50,8 +51,10 @@ def main(): try: if len(mail_ids) > 0: mail_id_range = min(mail_ids, key=int).decode('iso-8859-1') + ':' + max(mail_ids, key=int).decode('iso-8859-1') - session.set_seen_messages(mail_id_range) + session.set_seen_messages(mailbox, mail_id_range) total_messages += len(mail_ids) + else: + logging.info("Skipping empty mailbox %s", mailbox[2]) except UserWarning as ex: logging.error(ex) diff --git a/src/mail_iterator.py b/src/mail_iterator.py index 0b67bdd..2a35c1c 100644 --- a/src/mail_iterator.py +++ b/src/mail_iterator.py @@ -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') -- 1.7.1