From 66077beac30ba917e581169fad95cfbd9d82ad4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 3 Oct 2021 02:17:13 +0200 Subject: [PATCH] mail: Count unread mail from all mailboxes Before it only counted unread mails in the default folder (INBOX), but now I use sieve to sort into subfolders. --- modules/mail.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/mail.py b/modules/mail.py index 37955cf..fbc165c 100644 --- a/modules/mail.py +++ b/modules/mail.py @@ -2,10 +2,13 @@ import imaplib def get_unread(ip, port, user, password): + count = 0 mail = imaplib.IMAP4_SSL(ip, port) mail.login(user, password) - mail.select() - count = len(mail.search(None, "UnSeen")[1][0].split()) + for folder in mail.list()[1]: + foldername = folder.decode().split(' "/" ')[1] + mail.select(foldername) + count += len(mail.search(None, "UnSeen")[1][0].split()) mail.close() mail.logout() return count -- 2.44.0