[PATCH 5/8] Debug log/error proof the creation of new IMAP folders

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Aug 29 15:00:14 BST 2011


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 at SSpaeth.de>
---
 offlineimap/repository/IMAP.py |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py
index 11ec25b..4ca7494 100644
--- a/offlineimap/repository/IMAP.py
+++ b/offlineimap/repository/IMAP.py
@@ -330,16 +330,27 @@ class IMAPRepository(BaseRepository):
         return self.folders
 
     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() != '""':
         #    newname = self.getreference() + self.getsep() + foldername
         #else:
         #    newname = foldername
-        newname = foldername
         imapobj = self.imapserver.acquireconnection()
         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':
-                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:
             self.imapserver.releaseconnection(imapobj)
             
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list