From 944613de3a73aed2024ef2264dffce6ad6a2b143 Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Sat, 17 Nov 2012 12:39:41 +0100 Subject: [PATCH] added thunderbird new mail checker. --- thunderbirdnewmail.py | 51 +++++++++++++++++++++++++++++++++++++++++++ wrapper.py.dist | 8 ++++++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 thunderbirdnewmail.py diff --git a/thunderbirdnewmail.py b/thunderbirdnewmail.py new file mode 100644 index 0000000..c92ea81 --- /dev/null +++ b/thunderbirdnewmail.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# +# This plugin listens for dbus signals emitted by the +# thunderbird-dbus-sender extension for TB: +# https://github.com/janoliver/thunderbird-dbus-sender +# The plugin must be active and thunderbird running for the module to work +# properly. + +import dbus, gobject +from dbus.mainloop.glib import DBusGMainLoop +import json + +class ThunderbirdMailChecker(object): + """ + This class listens for dbus signals emitted by + the dbus-sender extension for thunderbird. + """ + + unread = [] + + def __init__(self): + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + bus = dbus.SessionBus() + bus.add_signal_receiver(self.new_msg, + dbus_interface="org.mozilla.thunderbird.DBus", + signal_name="NewMessageSignal") + bus.add_signal_receiver(self.changed_msg, + dbus_interface="org.mozilla.thunderbird.DBus", + signal_name="ChangedMessageSignal") + loop = gobject.MainLoop() + dbus.mainloop.glib.threads_init() + self.context = loop.get_context() + + def new_msg(self, id, author, subject): + if id not in self.unread: + self.unread.append(id) + + def changed_msg(self, id, event): + if event == "read" and id in self.unread: + self.unread.remove(id) + + def output(self): + self.context.iteration(False) + + unread = len(self.unread) + + return {'full_text' : '%d new email' % unread, + 'name' : 'newmail-tb', + 'urgent' : True, + 'color' : '#ff0000' } if unread else None \ No newline at end of file diff --git a/wrapper.py.dist b/wrapper.py.dist index 3f79911..55388da 100755 --- a/wrapper.py.dist +++ b/wrapper.py.dist @@ -10,7 +10,7 @@ if __name__ == '__main__': status = I3statusHandler() - #List the modules + # The imap checker module mailsettings = { 'color': '#ff0000', 'servers': [ @@ -35,6 +35,7 @@ if __name__ == '__main__': mailchecker = mailchecker.MailChecker(mailsettings) status.register_module(mailchecker) + # the mods.de forum new bookmarks module mdesettings = { 'username': "your_username", 'password': "your_password" @@ -42,9 +43,14 @@ if __name__ == '__main__': mde = modsde.ModsDeChecker(mdesettings) status.register_module(mde) + # the notmuch mail checker module db_path = 'path_to_your_notmuch_database' notmuch = notmuchmailchecker.NotmuchMailChecker(db_path) status.register_module(notmuch) + # the thunderbird dbus new mail checker module + tb = thunderbirdnewmail.ThunderbirdMailChecker() + status.register_module(tb) + # start the handler status.run()