dealing with dots in Exchange folders
Giuseppe Attardi
attardi at gmail.com
Wed Jul 17 17:38:23 BST 2013
The solution was not perfect.
The nametrans and the separator replacement and not commutative
operations, hence they must be performed in different order depending on
the direction.
More precisely, one must do first nametrans and then replace on the
source repository, for example:
# Transform, replace:
a/b.c -> a/b&ALc-c -> a.b&ALc-c
while replace and then nametrans in the reverse direction:
# Replace, transform:
a.b&ALc-c -> a/b&ALc-c -> a/b.c
This requires the following change to sync_folder_structure():
src_hash = {}
for folder in src_folders:
# Transform, replace:
# a/b.c -> a/b&ALc-c -> a.b&ALc-c
src_hash[folder.getvisiblename().replace(
src_repo.getsep(), dst_repo.getsep())] = folder
dst_hash = {}
for folder in dst_folders:
# Replace, transform:
# a.b&ALc-c -> a/b&ALc-c -> a/b.c
src_name = folder.name.replace(
dst_repo.getsep(), src_repo.getsep())
src_name = folder.repository.nametrans(src_name)
dst_hash[src_name] = folder
Note that this entails that all transformations be done in the space of
the srouce repository.
The documentation page http://docs.offlineimap.org/en/latest/nametrans.html
says that the mapping should use the separator of the repository,
without specifying which.
It should read the source repository for both the direct and reverse
nametrans.
-- Giuseppe
On 7/17/2013 15:10, Giuseppe Attardi wrote:
> 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/530fece6/attachment-0003.html>
More information about the OfflineIMAP-project
mailing list