diff --git a/notmuchmailchecker.py b/notmuchmailchecker.py new file mode 100644 index 0000000..51e59b0 --- /dev/null +++ b/notmuchmailchecker.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# note that this needs the notmuch python bindings. For more info see: +# http://notmuchmail.org/howto/#index4h2 +import notmuch +import json + +class NotmuchMailChecker(object): + """ + This class uses the notmuch python bindings to check for the + number of messages in the notmuch database with the tags "inbox" + and "unread" + """ + + db_path = '' + + 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 } diff --git a/wrapper.py.dist b/wrapper.py.dist index 7e035c0..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__': @@ -41,5 +42,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()