Ejemplo n.º 1
0
    def refresh(self):
        """Refresh mailbox status."""

        info('MailboxMonitor %s: refresh.' % self.label)

        if network_available():
            # pylint: disable=broad-except
            try:
                mails = self.fetchmail()

                if len(mails) > 0:
                    debug('MailboxMonitor %s: %s Mail found' % (self.label, len(mails)))
                else:
                    debug('MailboxMonitor %s: No Mail found' % self.label)

                self.status_icon.set_mails(self.label, mails)
            except mailindicator.AuthenticationError as ex:
                message = 'Login failed, wrong user or password.'
                self.status_icon.set_error(self.label, message)
            except Exception as ex:
                debug_ex()
                message = 'Exception %s' % str(ex)
                self.status_icon.set_error(self.label, message)
        else:
            info('MailboxMonitor %s: Network not available' % self.label)
Ejemplo n.º 2
0
    def set_mails(self, label, mails):
        """Set mails."""
        # Thread safe
        self.lock.acquire()
        try:
            unread = 0
            if len(mails) > 0:

                if label not in self.markedasread:
                    self.markedasread[label] = []
                markedasread = self.markedasread[label]

                unread_ids = []
                summary = ""
                for mail in mails:
                    if mail.id not in markedasread:
                        unread += 1
                        unread_ids.append(mail.id)
                        if len(mail.subject) > 40:
                            mail.subject = mail.subject[0:40]
                        smr = "Mailbox: %s\n" + "From:       %s\n" + "Subject:   %s\n" + "Sent:         %s\n\n"
                        smr = smr % (label, mail.mfrom, mail.subject, mail.date)
                        summary += smr

                        if self.pynotify_available:
                            if label not in self.notified:
                                self.notified[label] = []
                            notified = self.notified[label]

                            if mail.id not in notified:
                                debug("StatusIcon %s: Mail not notified %s" % (label, mail))
                                notified.append(mail.id)
                                smr = smr.replace("<", "&lt;")
                                smr = smr.replace(">", "&gt;")
                                ntf = Notify.Notification.new("New Message", smr)
                                ntf.show()
                            else:
                                debug("StatusIcon %s: Mail already notified %s" % (label, mail))
                    else:
                        debug("StatusIcon %s: Mail marked as read %s" % (label, mail))

            if label in self.ignoreerrors:
                del self.ignoreerrors[label]

            if unread > 0:
                mailbox = MB(label)
                mailbox.unread = unread
                mailbox.unread_ids = unread_ids
                mailbox.summary = summary
                self.mailboxes[label] = mailbox
            else:
                info("StatusIcon %s: No unread mail found" % label)
                if label in self.mailboxes:
                    del self.mailboxes[label]
        finally:
            self.lock.release()

        self._update_status()
Ejemplo n.º 3
0
def main():
    """Main function"""

    args = _parse_cmdline()

    if args.debug:
        logging.set_level(logging.DEBUG)
    elif args.quiet:
        logging.set_level(logging.NONE)
    else:
        logging.set_level(logging.INFO)

    if args.file:
        config.load(args.file)
    else:
        config.load()

    logging.info("Mailindicator started.")

    mailboxes = config.mailboxes
    monitors = []

    if len(mailboxes) > 0:
        status_icon = StatusIcon()

        for mailbox in mailboxes:
            mb_monitor = MailboxMonitor(status_icon,
                                        mailbox.label,
                                        mailbox.sleep_time,
                                        mailbox.fetcher.fetchmail)
            mb_monitor.start()
            monitors.append(mb_monitor)

        status_icon.set_monitors(monitors)

        Gdk.threads_init()
        Gtk.main()
Ejemplo n.º 4
0
    def _quit(self, widget):
        info("StatusIcon: Quitting")
        import sys

        sys.exit(0)