Debug log/error proof the creation of new IMAP folders

Output a debug log line whenever we create a new folder on an IMAP
server. Also raise an OfflineImap Error in case we failed to create it.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-08-29 14:18:53 +02:00
parent 8ba17c5bd1
commit c7420e6ad4

View File

@ -327,16 +327,27 @@ class IMAPRepository(BaseRepository):
return self.folders return self.folders
def makefolder(self, foldername): def makefolder(self, foldername):
"""Create a folder on the IMAP server
:param foldername: Full path of the folder to be created."""
#TODO: IMHO this existing commented out code is correct and
#should be enabled, but this would change the behavior for
#existing configurations who have a 'reference' set on a Mapped
#IMAP server....:
#if self.getreference() != '""': #if self.getreference() != '""':
# newname = self.getreference() + self.getsep() + foldername # newname = self.getreference() + self.getsep() + foldername
#else: #else:
# newname = foldername # newname = foldername
newname = foldername
imapobj = self.imapserver.acquireconnection() imapobj = self.imapserver.acquireconnection()
try: try:
result = imapobj.create(newname) self.ui._msg("Creating new IMAP folder '%s' on server %s" %\
(foldername, self))
result = imapobj.create(foldername)
if result[0] != 'OK': if result[0] != 'OK':
raise RuntimeError, "Repository %s could not create folder %s: %s" % (self.getname(), foldername, str(result)) raise OfflineImapError("Folder '%s'[%s] could not be created. "
"Server responded: %s" % \
(foldername, self, str(result)),
OfflineImapError.ERROR.FOLDER)
finally: finally:
self.imapserver.releaseconnection(imapobj) self.imapserver.releaseconnection(imapobj)