[PATCH] Avoid trying to synchronize folders that have empty names

Dodji Seketeli dodji at seketeli.org
Tue Jun 26 14:45:03 BST 2012


Hello,

I am hitting the same issue as Jes Sorensen[1], where at some point,
offlineimap 6.5.4 would error out with the message:

 Establishing connection to mail.corp.foo.com:993
 Creating new IMAP folder '/' on server RemoteFoo
 ERROR: Creating folder  on repository RemoteFoo
  Folder '/'[RemoteFoo] could not be created. Server responded:
('NO', ['CREATE failed: invalid mailbox name'])
 ERROR: Folder '/'[RemoteFoo] could not be created. Server responded:
('NO', ['CREATE failed: invalid mailbox name'])
 *** Finished account 'Foo' in 0:03

I chased it down and it looks like the issue happens when we have a
local Maildir format, subfolders and where the separator is '/'.

Since commit a279aa7 [2], it can happen that offlineimap wrongly tries
to create a folder named '/' on the remote server.

I believe the problem is that MaildirRepository._getfolders_scandir
which is supposed to scan the list of IMAP folders under a given root
folder can now return a folder that has an empty path.  A consumer of
that function then appends the IMAP folder path separator to that empty
folder name, and tries to create the resulting folder name '/' on the
server.  Oops.

The patch accompanying this message addresses the issue by ensuring that
that function never yields an empty path.

Though, in the grand scheme of things, I don't understand why the change
in [2] would be the right fix to begin with. Is that function the right
place to make nametrans related decisions?  It seems to like that
function ought to returns what it really sees on the physical Maildir
directory.

[1]: http://article.gmane.org/gmane.mail.imap.offlineimap.general/5696

[2]: commit a279aa7307ca036f93b660ade84099550ff1a4f2
     Author: Sebastian Spaeth <Sebastian at SSpaeth.de>
     Date:   Mon Sep 19 14:14:44 2011 +0200

        Maildir: Call top-level directory '', not '.'

        If nametrans translates to an empty directory we want to find the
        top-level directory by name '' and not by name '.'. This unbreaks
        nametrans rules that result in empty folder names.

        Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>


And now the patch.

---
 offlineimap/repository/Maildir.py |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/offlineimap/repository/Maildir.py b/offlineimap/repository/Maildir.py
index f197002..4fdd2e7 100644
--- a/offlineimap/repository/Maildir.py
+++ b/offlineimap/repository/Maildir.py
@@ -152,8 +152,15 @@ class MaildirRepository(BaseRepository):
         # Iterate over directories in top & top itself.
         for dirname in os.listdir(toppath) + ['']:
             self.debug("  dirname = %s" % dirname)
-            if dirname == '' and extension is not None:
-                self.debug('  skip this entry (already scanned)')
+            if dirname == '':
+                if extension is not None:
+                    # We are skipping this because it has already be
+                    # scanned
+                    self.debug('  skip this entry (already scanned)')
+                else:
+                    # We are skipping this because a directory with an
+                    # empty path name does not make sense
+                    self.debug('  skip this entry (None)')
                 continue
             if dirname in ['cur', 'new', 'tmp']:
                 self.debug("  skip this entry (Maildir special)")
-- 

		Dodji





More information about the OfflineIMAP-project mailing list