проблема с rename

master
inpos 2016-05-30 17:41:12 +03:00
parent 4547c85237
commit 9956b94649
2 changed files with 19 additions and 12 deletions

View File

@ -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):

View File

@ -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)