Ported notmuchmail (needs testing)
This commit is contained in:
parent
7fceb73ff3
commit
93b7ba9af9
25
i3pystatus/mail/notmuchmail.py
Normal file
25
i3pystatus/mail/notmuchmail.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
from i3pystatus.mail import Backend
|
||||||
|
|
||||||
|
class NotmuchMailChecker(Backend):
|
||||||
|
"""
|
||||||
|
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 = required = ("db_path",)
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.db = notmuch.Database(self.db_path)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unread(self):
|
||||||
|
return notmuch.Query(self.db, "tag:unread and tag:inbox").count_messages()
|
@ -1,36 +0,0 @@
|
|||||||
#!/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
|
|
||||||
|
|
||||||
from i3pystatus import IntervalModule
|
|
||||||
|
|
||||||
class NotmuchMailChecker(IntervalModule):
|
|
||||||
"""
|
|
||||||
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 = required = ("db_path",)
|
|
||||||
|
|
||||||
def run(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"
|
|
||||||
|
|
||||||
self.output = {
|
|
||||||
"full_text" : "%d new email%s" % (unread, ("s" if unread > 1 else "")),
|
|
||||||
"name" : "newmail",
|
|
||||||
"urgent" : urgent,
|
|
||||||
"color" : color
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user