<commit_before>#!/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 json
import threading
import time
from functools import partial

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop

from i3pystatus.mail import Backend

class Thunderbird(Backend):
    """
    This class listens for dbus signals emitted by
    the dbus-sender extension for thunderbird.

    Requires
    * python-dbus
    * python-gobject2
    """

    unread = set()

    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()

        self.run = partial(self.context.iteration, False)

    def new_msg(self, id, author, subject):
        if id not in self.unread:
            self.unread.add(id)

    def changed_msg(self, id, event):
        if event == "read" and id in self.unread:
            self.unread.remove(id)

    @property
    def unread(self):
        self.run()
        return len(self.unread)
<commit_msg>Fixed thunderbird<commit_after>#!/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 json
import threading
import time
from functools import partial

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop

from i3pystatus.mail import Backend

class Thunderbird(Backend):
    """
    This class listens for dbus signals emitted by
    the dbus-sender extension for thunderbird.

    Requires
    * python-dbus
    * python-gobject2
    """

    _unread = set()

    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()

        self.run = partial(self.context.iteration, False)

    def new_msg(self, id, author, subject):
        if id not in self._unread:
            self._unread.add(id)

    def changed_msg(self, id, event):
        if event == "read" and id in self._unread:
            self._unread.remove(id)

    @property
    def unread(self):
        self.run()
        return len(self._unread)

{'fraction_non_alphanumeric': 0.09212827988338193, 'fraction_numerical': 0.0023323615160349854, 'mean_word_length': 2.376968503937008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6319764', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1021, 'n_words': 243}