diff options
| author | rixx <rixx-git@cutebit.de> | 2015-03-15 01:26:38 +0100 |
|---|---|---|
| committer | rixx <rixx-git@cutebit.de> | 2015-03-15 01:26:38 +0100 |
| commit | 7c861be75335f9542e847272aa8a4c9d4f0f079b (patch) | |
| tree | ebac5e1e28c1444ccd7626e5b0ffb5793220103d /py3status/modules | |
| parent | 930469fcb4c0693a9a0572e7cb4a9914823442ba (diff) | |
IMAP module may now check several IMAP folders
Returns sum of unseen mails in given folders. Former behaviour with only
one given directory is unchanged.
Diffstat (limited to 'py3status/modules')
| -rw-r--r-- | py3status/modules/imap.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/py3status/modules/imap.py b/py3status/modules/imap.py index d7ce5be..9228a28 100644 --- a/py3status/modules/imap.py +++ b/py3status/modules/imap.py @@ -1,7 +1,8 @@ # -*- coding: utf8 -*- """ Module displaying the number of unread messages -on an IMAP inbox (configurable). +on an IMAP inbox (configurable, may also be a +comma-separated list of IMAP folders). @author obb """ @@ -42,13 +43,19 @@ class Py3status: def _get_mail_count(self): try: - connection = imaplib.IMAP4_SSL(self.imap_server, self.port) - connection.login(self.user, self.password) - connection.select(self.mailbox) - unseen_response = connection.search(None, self.criterion) - mails = unseen_response[1][0].split() - mail_count = len(mails) + mail_count = 0 + directories = self.mailbox.split(',') + + for directory in directories: + connection = imaplib.IMAP4_SSL(self.imap_server, self.port) + connection.login(self.user, self.password) + connection.select(directory) + unseen_response = connection.search(None, self.criterion) + connection.close() + mails = unseen_response[1][0].split() + mail_count += len(mails) return mail_count + except: return 'N/A' |
