Exemplo n.º 1
0
    def _right_click_event(self, icon, button, time):
        debug("StatusIcon right click event")

        if self.menu is None:
            menu = Gtk.Menu()

            itm = self._menu_item("view-refresh", "Refresh")
            itm.connect("activate", self._refresh)
            menu.append(itm)

            itm = Gtk.SeparatorMenuItem()
            menu.append(itm)

            # itm = self._menu_item('preferences-system', 'Preferences')
            # itm.connect('activate', self._show_preferences_dialog)
            # menu.append(itm)

            itm = self._menu_item("help-about", "About")
            itm.connect("activate", self._show_about_dialog)
            menu.append(itm)

            itm = Gtk.SeparatorMenuItem()
            menu.append(itm)

            itm = self._menu_item("application-exit", "Quit")
            itm.connect("activate", self._quit)
            menu.append(itm)
            menu.show_all()

            self.menu = menu

        self.menu.popup(None, None, None, None, button, time)
Exemplo n.º 2
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)
Exemplo n.º 3
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()
Exemplo n.º 4
0
    def _left_click_event(self, icon):
        debug("StatusIcon clicked")
        # Thread safe
        self.lock.acquire()
        try:
            for label in list(self.mailboxes.keys()):
                mailbox = self.mailboxes[label]
                if not mailbox.inerror:
                    if label not in self.markedasread:
                        self.markedasread[label] = []
                    markedasread = self.markedasread[label]
                    markedasread = markedasread + mailbox.unread_ids
                    self.markedasread[label] = markedasread
                else:
                    if label not in self.ignoreerrors:
                        self.ignoreerrors[label] = []
                    ignoreerrors = self.ignoreerrors[label]
                    ignoreerrors += [mailbox.errormessage]
                    self.ignoreerrors[label] = ignoreerrors
                del self.mailboxes[label]
        finally:
            self.lock.release()

        self._update_status()