From d2643dad6d521a823b356539a9d6287920bb2f87 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:24:03 -0500 Subject: [PATCH 1/8] add exampe for NotmuchMailChecker --- wrapper.py.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wrapper.py.dist b/wrapper.py.dist index 7e035c0..b082ae3 100755 --- a/wrapper.py.dist +++ b/wrapper.py.dist @@ -41,5 +41,9 @@ if __name__ == '__main__': mde = modsde.ModsDeChecker(mdesettings) status.register_module(mde) + db_path = 'path_to_your_notmuch_database' + notmuch = notmuchmailchecker.NotmuchMailChecker(db_path) + status.register_module(notmuch) + # start the handler status.run() From 1009901e3b4254089967a99e3b817a082072fbdd Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:25:01 -0500 Subject: [PATCH 2/8] import notmuchmailchecker file --- wrapper.py.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/wrapper.py.dist b/wrapper.py.dist index b082ae3..3f79911 100755 --- a/wrapper.py.dist +++ b/wrapper.py.dist @@ -3,6 +3,7 @@ import mailchecker import modsde +import notmuchmailchecker from statushandler import I3statusHandler if __name__ == '__main__': From 602da44765440b1baed62802e7e43e227e3da466 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:25:35 -0500 Subject: [PATCH 3/8] Remove TODO, found a better way --- notmuchmailchecker.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 notmuchmailchecker.py diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py new file mode 100644 index 0000000..729df76 --- /dev/null +++ b/notmuchmailchecker.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +import json +from datetime import datetime,timedelta +import notmuch + +class NotmuchMailChecker(object): + """ + This class checks for the number of unread messages in the notmuch + database using the notmuch python bindings + """ + + settings = { + 'color': '#ff0000', + 'servers': [] + } + + db_path = '' + + servers = [] + + def __init__(self, db_path): + self.db_path = db_path + + def output(self): + db = notmuch.Database(self.db_path) + unread = notmuch.Query(db, 'tag:unread and tag:inbox').count_messages() + + if (unread == 0): + color = '#00FF00' + urgent = 'false' + else: + color = '#ff0000', + urgent = 'true' + + return {'full_text' : '%d new email%s' % (unread, ('s' if unread > 1 else '')), + 'name' : 'newmail', + 'urgent' : urgent, + 'color' : color } From 73107ec8731f344c1792dd2184b602c5b2a4fe3b Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:27:03 -0500 Subject: [PATCH 4/8] remove unneeded imports --- notmuchmailchecker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py index 729df76..37fdf3f 100644 --- a/notmuchmailchecker.py +++ b/notmuchmailchecker.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import sys -import json -from datetime import datetime,timedelta +# note that this needs the notmuch python bindings. For more info see: +# http://notmuchmail.org/howto/#index4h2 import notmuch +import json class NotmuchMailChecker(object): """ From 942a8635a094e2377efcdebb119fa469af350843 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:27:42 -0500 Subject: [PATCH 5/8] remove the servers array, there is no need for it --- notmuchmailchecker.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py index 37fdf3f..3268233 100644 --- a/notmuchmailchecker.py +++ b/notmuchmailchecker.py @@ -19,8 +19,6 @@ class NotmuchMailChecker(object): db_path = '' - servers = [] - def __init__(self, db_path): self.db_path = db_path From 61be416429c7071ce4507f33020a042fe6747e51 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:30:06 -0500 Subject: [PATCH 6/8] make class comment more clear --- notmuchmailchecker.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py index 3268233..f2ad311 100644 --- a/notmuchmailchecker.py +++ b/notmuchmailchecker.py @@ -8,8 +8,9 @@ import json class NotmuchMailChecker(object): """ - This class checks for the number of unread messages in the notmuch - database using the notmuch python bindings + This class uses the notmuch python bindings to check for the + number of messages in the notmuch database with the tags "inbox" + and "unread" """ settings = { From 814f365fbe98358c8f39654ec721262ae78cc162 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:31:54 -0500 Subject: [PATCH 7/8] remove extraneous comma --- notmuchmailchecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py index f2ad311..f150cd8 100644 --- a/notmuchmailchecker.py +++ b/notmuchmailchecker.py @@ -31,7 +31,7 @@ class NotmuchMailChecker(object): color = '#00FF00' urgent = 'false' else: - color = '#ff0000', + color = '#ff0000' urgent = 'true' return {'full_text' : '%d new email%s' % (unread, ('s' if unread > 1 else '')), From e279f8e2bf3bfad11c33900c3a4d43288fb93069 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 Oct 2012 17:41:33 -0500 Subject: [PATCH 8/8] remove settings variable --- notmuchmailchecker.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py index f150cd8..51e59b0 100644 --- a/notmuchmailchecker.py +++ b/notmuchmailchecker.py @@ -13,11 +13,6 @@ class NotmuchMailChecker(object): and "unread" """ - settings = { - 'color': '#ff0000', - 'servers': [] - } - db_path = '' def __init__(self, db_path):