From 9956b94649ec5083e48f507645060d5768000158 Mon Sep 17 00:00:00 2001 From: inpos Date: Mon, 30 May 2016 17:41:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D1=81=20rename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mech_imap.py | 19 ++++++++++++------- serpent/imap/mailbox.py | 12 +++++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/mech_imap.py b/mech_imap.py index fb245de..4b25fb0 100644 --- a/mech_imap.py +++ b/mech_imap.py @@ -82,7 +82,7 @@ class IMAPUserAccount(object): if pathspec in conf.imap_auto_mbox: raise imap4.MailboxException, pathspec if pathspec not in IMAP_MBOX_REG[self.dir].keys(): - raise imap4.MailboxException("No such mailbox") + raise imap4.NoSuchMailbox, pathspec inferiors = self._inferiorNames(pathspec) if r'\Noselect' in IMAP_MBOX_REG[self.dir][pathspec].getFlags(): # Check for hierarchically inferior mailboxes with this one @@ -111,19 +111,22 @@ class IMAPUserAccount(object): if new in IMAP_MBOX_REG[self.dir].keys(): raise imap4.MailboxCollision, new for (old, new) in inferiors: - move(os.path.join(self.dir, old), os.path.join(self.dir, new)) - IMAP_MBOX_REG[self.dir][new] = IMAP_MBOX_REG[self.dir][old] - IMAP_MBOX_REG[self.dir][new].path = os.path.join(self.dir, new) - IMAP_MBOX_REG[self.dir][new].path_msg_info = os.path.join(self.dir, conf.imap_msg_info) - IMAP_MBOX_REG[self.dir][new].path_mbox_info = os.path.join(self.dir, conf.imap_mbox_info) + m = IMAP_MBOX_REG[self.dir][old] del IMAP_MBOX_REG[self.dir][old] - return True + for l in m.listeners: m.listeners.remove(l) + m.close() + move(os.path.join(self.dir, old), os.path.join(self.dir, new)) + IMAP_MBOX_REG[self.dir][new] = self._getMailbox(new) + IMAP_MBOX_REG[self.dir][new].subscribe() + return IMAP_MBOX_REG[self.dir][newname] def subscribe(self, name): if isinstance(name, unicode): name = name.encode('imap4-utf-7') if name in IMAP_MBOX_REG[self.dir].keys(): IMAP_MBOX_REG[self.dir][name].subscribe() + return True + raise imap4.NoSuchMailbox, name def unsubscribe(self, name): if name in conf.imap_auto_mbox: @@ -132,6 +135,8 @@ class IMAPUserAccount(object): name = name.encode('imap4-utf-7') if name in IMAP_MBOX_REG[self.dir].keys(): IMAP_MBOX_REG[self.dir][name].unsubscribe() + return True + raise imap4.NoSuchMailbox, name def isSubscribed(self, name): if isinstance(name, unicode): diff --git a/serpent/imap/mailbox.py b/serpent/imap/mailbox.py index 206ed8a..a091bee 100644 --- a/serpent/imap/mailbox.py +++ b/serpent/imap/mailbox.py @@ -10,7 +10,7 @@ from threading import Thread import random import email -from pickle import load, dump + from StringIO import StringIO import os @@ -38,7 +38,7 @@ class SerpentAppendMessageTask(maildir._MaildirMailboxAppendMessageTask): try: self.osrename(self.tmpname, newname) break - except OSError, (err, estr): + except OSError, (err, _): import errno # if the newname exists, retry with a new newname. if err != errno.EEXIST: @@ -94,7 +94,7 @@ class IMAPMailbox(ExtendedMaildir): l = [l for l in self.__msg_list_()] for i in l: fn = i.split('/')[-1] - if fn not in msg_info.keys(): + if fn not in self.msg_info.keys(): val1 = {'uid': self.getUIDNext()} if i.split('/')[-2] == 'new': val1['flags'] = [] @@ -223,7 +223,7 @@ class IMAPMailbox(ExtendedMaildir): new_path = os.path.join(self.path, 'cur', filename) os.rename(path, new_path) d[_id] = self.msg_info[filename]['flags'] - msg_info.commit(blocking=False) + self.msg_info.commit(blocking=False) return d def expunge(self): @@ -258,7 +258,9 @@ class IMAPMailbox(ExtendedMaildir): self.notifier.stopReading() self.notifier.loseConnection() if conf.imap_expunge_on_close: - l = self.expunge() + self.expunge() + self.mbox_info.close() + self.msg_info.close() class MaildirMessagePart(object): implements(imap4.IMessagePart)