Beispiel #1
0
    def save(self, event=None):
        self.name = name = self.name_entry.get().strip()
        if name != self.mailbox:
            # change name of mailbox
            os.remove(os.path.join(LOCAL_PATH, self.mailbox))

            active = CONFIG.get("Mailboxes", "active").split(", ")
            inactive = CONFIG.get("Mailboxes", "inactive").split(", ")
            while "" in active:
                active.remove("")
            while "" in inactive:
                inactive.remove("")
            if self.mailbox in active:
                active.remove(self.mailbox)
                active.append(name)
            elif self.mailbox in inactive:
                inactive.remove(self.mailbox)
                inactive.append(name)
            CONFIG.set("Mailboxes", "active", ", ".join(active))
            CONFIG.set("Mailboxes", "inactive", ", ".join(inactive))
            save_config()

        encrypt(name, self.pwd, self.server_entry.get().strip(),
                self.login_entry.get().strip(), self.password_entry.get().strip(),
                self.folder_entry.get().strip())

        self.destroy()
Beispiel #2
0
 def ok(self):
     time = float(self.time_entry.get()) * 60000
     timeout = float(self.timeout_entry.get()) * 60000
     CONFIG.set("General", "time", "%i" % time)
     CONFIG.set("General", "timeout", "%i" % timeout)
     CONFIG.set("General", "language", self.lang.get().lower()[:2])
     CONFIG.set("General", "font", self.font.get())
     CONFIG.set("General", "trayicon", self.gui.get().lower())
     save_config()
     self.destroy()
Beispiel #3
0
 def quit(self):
     """Save configuration and destroy the dialog."""
     active = []
     inactive = []
     for box, (c, l, b1, b2) in self.mailboxes.items():
         if "selected" in c.state():
             active.append(box)
         else:
             inactive.append(box)
     CONFIG.set("Mailboxes", "active", ", ".join(active))
     CONFIG.set("Mailboxes", "inactive", ", ".join(inactive))
     save_config()
     self.destroy()
Beispiel #4
0
 def launch_check(self, force_notify=False):
     """
     Check every 20 s if the login to all the mailboxes is done.
     Once it is the case, launch the unread mail check.
     """
     b = [
         self.threads_connect[box].is_alive()
         for box in self.threads_connect
     ]
     if len(b) < len(self.info_conn) or True in b:
         logging.info("Waiting for connexion ...")
         try:
             self.after_cancel(self.check_id)
         except ValueError:
             pass
         self.check_id = self.after(20000, self.launch_check, force_notify)
     else:
         logging.info("Launching check")
         if not self.login_err_queue.empty():
             correct = False
             while not self.login_err_queue.empty():
                 box = self.login_err_queue.get()
                 action = show_failed_auth_msg(self, box)
                 if action == 'correct':
                     dialog = EditMailbox(self, self.pwd, box)
                     self.wait_window(dialog)
                     self.connect(box)
                     correct = dialog.name or correct
                 else:
                     # remove box from the active mailboxes
                     del (self.boxes[box])
                     active = CONFIG.get("Mailboxes", "active").split(", ")
                     inactive = CONFIG.get("Mailboxes",
                                           "inactive").split(", ")
                     while "" in active:
                         active.remove("")
                     while "" in inactive:
                         inactive.remove("")
                     active.remove(box)
                     inactive.append(box)
                     CONFIG.set("Mailboxes", "active", ", ".join(active))
                     CONFIG.set("Mailboxes", "inactive",
                                ", ".join(inactive))
             if correct:
                 self.after_cancel(self.check_id)
                 self.check_id = self.after(20000, self.launch_check,
                                            force_notify)
             else:
                 self.check_mails(force_notify)
         else:
             self.check_mails(force_notify)
Beispiel #5
0
 def reset_password(self):
     """
     Reset the master password and delete all the mailboxes config files
     since they cannot be decrypted without the password.
     """
     rep = askokcancel(
         _("Confirmation"),
         _("The reset of the password will erase all the stored mailbox connection information"
           ),
         icon="warning")
     if rep:
         mailboxes = CONFIG.get("Mailboxes",
                                "active").split(", ") + CONFIG.get(
                                    "Mailboxes", "inactive").split(", ")
         while "" in mailboxes:
             mailboxes.remove("")
         CONFIG.set("Mailboxes", "active", "")
         CONFIG.set("Mailboxes", "inactive", "")
         save_config()
         for mailbox in mailboxes:
             os.remove(os.path.join(LOCAL_PATH, mailbox))
         logging.info('Reset')
         self.set_password()
Beispiel #6
0
 def quit(self):
     CONFIG.set("General", "check_update",
                str("selected" in self.ch.state()))
     save_config()
     self.destroy()
Beispiel #7
0
    def connect_mailbox(self, box):
        """Connect to the mailbox box and select the folder."""
        try:
            logging.info("Connecting to %s" % box)
            serveur, loginfo, folder = self.info_conn[box]
            # reinitialize the connection if it takes too long
            timeout_id = self.after(self.timeout, self.timed_out, box, False,
                                    True)
            self.boxes[box] = IMAP4_SSL(serveur)
            self.boxes[box].login(*loginfo)
            self.boxes[box].select(folder)
            try:
                self.after_cancel(timeout_id)
            except ValueError:
                pass
            logging.info("Connected to %s" % box)

        except (IMAP4.error, ConnectionResetError, TimeoutError) as e:
            try:
                self.after_cancel(timeout_id)
            except ValueError:
                pass
            if e.args[0] in [
                    b'Invalid login or password', b'Authenticate error',
                    b'Login failed: authentication failure', b'LOGIN failed'
            ]:
                # Identification error
                logging.error("Incorrect login or password for %(mailbox)s" %
                              {"mailbox": box})
                self.login_err_queue.put(box)
            else:
                # try to reconnect
                logging.error('%s: %s' % (box, e))
                self.logout(box, reconnect=True)
        except gaierror as e:
            if e.errno == -2:
                # Either there is No Internet connection or the IMAP server is wrong
                if internet_on():
                    run([
                        "notify-send", "-i", "dialog-error",
                        _("Error"),
                        _("Wrong IMAP server for %(mailbox)s.") % {
                            "mailbox": box
                        }
                    ])
                    # remove box from the active mailboxes
                    active = CONFIG.get("Mailboxes", "active").split(", ")
                    inactive = CONFIG.get("Mailboxes", "inactive").split(", ")
                    while "" in active:
                        active.remove("")
                    while "" in inactive:
                        inactive.remove("")
                    active.remove(box)
                    inactive.append(box)
                    CONFIG.set("Mailboxes", "active", ", ".join(active))
                    CONFIG.set("Mailboxes", "inactive", ", ".join(inactive))
                    logging.error("Wrong IMAP server for %(mailbox)s." %
                                  {"mailbox": box})
                else:
                    if self.notify_no_internet:
                        run([
                            "notify-send", "-i", "dialog-error",
                            _("Error"),
                            _("No Internet connection.")
                        ])
                        self.notify_no_internet = False
                    logging.warning("No Internet connection")
                    # cancel everything
                    try:
                        self.after_cancel(self.check_id)
                    except ValueError:
                        pass
                    try:
                        self.after_cancel(self.timer_id)
                    except ValueError:
                        pass
                    try:
                        self.after_cancel(self.notif_id)
                    except ValueError:
                        pass
                    try:
                        self.after_cancel(self.internet_id)
                    except ValueError:
                        pass
                    # periodically checks if the internet connection is turned on
                    self.internet_id = self.after(self.timeout,
                                                  self.test_connection)
            else:
                # try to reconnect
                logging.exception(str(type(e)))
                run([
                    "notify-send", "-i", "dialog-error",
                    _("Error"),
                    traceback.format_exc()
                ])
                self.logout(box, reconnect=True)

        except ValueError:
            # Error sometimes raised when a connection process is interrupted by a logout process
            pass