dealing with dots in Exchange folders

Giuseppe Attardi attardi at di.unipi.it
Wed Jul 17 14:10:58 BST 2013


I need to migrate a number of accounts in my deparment from Exchange to 
Maildir (Postifx).

Since migration has to be done in stages, bidirectional synchronization 
is necessary.

Mapping between folder names is complicated by the fact that Exhange 
folders may contain dots.
There are plenty of cases were it makes sense to use dots in folders, 
for instance company names (registry.it), group names (WG 2.1), etc.
There is no pattern of use that would allow recognizing them.
Some programs like imapsync map them to '-', but this does not work in 
the other direction, since there is no way to distinguish other 
occurences of '-', when doing the reverse mapping.

Since many accounts must be migrated, it is impossible to go through 
them and change the names by hand.

I decided to adopt the solution to convert '.' to Unicode MIDDLE /DOT/' 
(U+00B7), which looks similar.
I wrote nametrans functions that encode the names in mUTF-7, as used by 
IMAP.

I had to patch the code for sync_folder_structure in class Base to avoid 
complains when doing the reverse translation, since after the middle dot 
is converted back to '.', it replaces '.' with '/ and raises an error 
about possible loops.
Here is the patch:

*** Base.py 2013-07-17 15:06:15.000000000 +0200
--- Base.py~    2013-04-16 17:02:14.000000000 +0200
***************
*** 216,225 ****
                   # succeed in getting inexisting folders which I would
                   # like to change. Take care!
                   folder = self.getfolder(dst_name_t)
                   newdst_name = folder.getvisiblename().replace(
                       src_repo.getsep(), dst_repo.getsep())
!                 if dst_folder.name != newdst_name and \
!                         dst_folder.name.replace('&ALc-', '.') != 
newdst_name:
                       raise OfflineImapError("INFINITE FOLDER CREATION 
DETECTED! "
                           "Folder '%s' (repository '%s') would be 
created as fold"
                           "er '%s' (repository '%s'). The latter 
becomes '%s' in "
--- 216,225 ----
                   # succeed in getting inexisting folders which I would
                   # like to change. Take care!
                   folder = self.getfolder(dst_name_t)
+                 # apply reverse nametrans to see if we end up with the 
same name
                   newdst_name = folder.getvisiblename().replace(
                       src_repo.getsep(), dst_repo.getsep())
!                 if dst_folder.name != newdst_name:
                       raise OfflineImapError("INFINITE FOLDER CREATION 
DETECTED! "
                           "Folder '%s' (repository '%s') would be 
created as fold"
                           "er '%s' (repository '%s'). The latter 
becomes '%s' in "

The solution seems to work fine.

Here is a test run:

*** Processing account me
Establishing connection to ex.di.unipi.it:993
Establishing connection to imap.unipi.it:143
Creating folder aa&ALc-a[Maildir]
Creating folder aa.a[Maildir]
Skipping aa/a (not changed)
Syncing aa.a: IMAP -> MappedIMAP
Copy message 1 (1 of 1) Exchange:aa.a -> Maildir
*** Finished account 'me' in 0:03

Comments and suggestions welcome.

Giuseppe Attardi
Università di Pisa

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/offlineimap-project/attachments/20130717/2f1d16b4/attachment-0002.html>


More information about the OfflineIMAP-project mailing list