Beispiel #1
0
    def open_mailbox(self, session, mailbox_id):
        try:
            mbx_id = mailbox_id.lower()
            mfn = self.sys.mailbox[mbx_id]
            pfn = 'pickled-mailbox.%s' % mbx_id
        except KeyError:
            raise NoSuchMailboxError(_('No such mailbox: %s') % mbx_id)

        try:
            if mbx_id in self._mbox_cache:
                self._mbox_cache[mbx_id].update_toc()
            else:
                if session:
                    session.ui.mark(_('%s: Updating: %s') % (mbx_id, mfn))
                self._mbox_cache[mbx_id] = self.load_pickle(pfn)
        except:
            if self.sys.debug:
                import traceback
                traceback.print_exc()
            if session:
                session.ui.mark(
                    _('%s: Opening: %s (may take a while)') % (mbx_id, mfn))
            editable = self.is_editable_mailbox(mbx_id)
            mbox = OpenMailbox(mfn, create=editable)
            mbox.editable = editable
            mbox.save(session,
                      to=pfn,
                      pickler=lambda o, f: self.save_pickle(o, f))
            self._mbox_cache[mbx_id] = mbox

        # Always set this, it can't be pickled
        self._mbox_cache[mbx_id]._encryption_key_func = \
            lambda: self.prefs.obfuscate_index

        return self._mbox_cache[mbx_id]
Beispiel #2
0
 def __setstate__(self, dict):
     self.__dict__.update(dict)
     self._lock = MboxLock()
     with self._lock:
         self._save_to = None
         self._encryption_key_func = lambda: None
         self._decryption_key_func = lambda: None
         try:
             if not os.path.exists(self._path):
                 raise NoSuchMailboxError(self._path)
             self._file = self._get_fd()
         except IOError, e:
             if e.errno == errno.ENOENT:
                 raise NoSuchMailboxError(self._path)
             elif e.errno == errno.EACCES:
                 self._file = self._get_fd()
             else:
                 raise
Beispiel #3
0
 def __setstate__(self, dict):
     self.__dict__.update(dict)
     self._lock = threading.Lock()
     self._lock.acquire()
     self._save_to = None
     try:
         try:
             if not os.path.exists(self._path):
                 raise NoSuchMailboxError(self._path)
             self._file = self._get_fd()
         except IOError, e:
             if e.errno == errno.ENOENT:
                 raise NoSuchMailboxError(self._path)
             elif e.errno == errno.EACCES:
                 self._file = self._get_fd()
             else:
                 raise
     finally:
         self._lock.release()
     self.update_toc()