From cb80f133d74aa1c6d5b549e77a1fe763d89cef71 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Thu, 18 Dec 2014 22:02:27 +0100 Subject: [PATCH 1/2] Simple fix for notmuch database not in sync --- i3pystatus/mail/notmuchmail.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/i3pystatus/mail/notmuchmail.py b/i3pystatus/mail/notmuchmail.py index 00e99c0..3919d45 100644 --- a/i3pystatus/mail/notmuchmail.py +++ b/i3pystatus/mail/notmuchmail.py @@ -35,11 +35,10 @@ class Notmuch(Backend): self.db_path = config.get("database", "path") - self.db = notmuch.Database(self.db_path) - @property def unread(self): - return notmuch.Query(self.db, "tag:unread and tag:inbox").count_messages() + db = notmuch.Database(self.db_path) + return notmuch.Query(db, "tag:unread and tag:inbox").count_messages() Backend = Notmuch From a480701ee611ce5850e876037e013ad105a75dcd Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 19 Dec 2014 14:31:10 +0100 Subject: [PATCH 2/2] Added doc for unread method in mail/__init__/py + make sure that db is closed before deleting the notmuch db object --- i3pystatus/mail/__init__.py | 4 ++++ i3pystatus/mail/notmuchmail.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/i3pystatus/mail/__init__.py b/i3pystatus/mail/__init__.py index e683f0e..330494c 100644 --- a/i3pystatus/mail/__init__.py +++ b/i3pystatus/mail/__init__.py @@ -43,6 +43,10 @@ class Mail(IntervalModule): pass def run(self): + """ + Returns the sum of unread messages across all registered backends + """ + unread = sum(map(lambda backend: backend.unread, self.backends)) if not unread: diff --git a/i3pystatus/mail/notmuchmail.py b/i3pystatus/mail/notmuchmail.py index 3919d45..bd3ffe3 100644 --- a/i3pystatus/mail/notmuchmail.py +++ b/i3pystatus/mail/notmuchmail.py @@ -38,7 +38,9 @@ class Notmuch(Backend): @property def unread(self): db = notmuch.Database(self.db_path) - return notmuch.Query(db, "tag:unread and tag:inbox").count_messages() + result = notmuch.Query(db, "tag:unread and tag:inbox").count_messages() + db.close() + return result Backend = Notmuch