<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">The solution was not perfect.<br>
<br>
The nametrans and the separator replacement and not commutative
operations, hence they must be performed in different order
depending on the direction.<br>
More precisely, one must do first nametrans and then replace on
the source repository, for example:<br>
<br>
# Transform, replace:<br>
a/b.c -> a/b&ALc-c -> a.b&ALc-c<br>
<br>
while replace and then nametrans in the reverse direction:<br>
<br>
# Replace, transform:<br>
a.b&ALc-c -> a/b&ALc-c -> a/b.c<br>
<br>
This requires the following change to sync_folder_structure():<br>
<br>
src_hash = {}<br>
for folder in src_folders:<br>
# Transform, replace:<br>
# a/b.c -> a/b&ALc-c -> a.b&ALc-c<br>
src_hash[folder.getvisiblename().replace(<br>
src_repo.getsep(), dst_repo.getsep())] =
folder<br>
dst_hash = {}<br>
for folder in dst_folders:<br>
# Replace, transform:<br>
# a.b&ALc-c -> a/b&ALc-c -> a/b.c<br>
src_name = folder.name.replace(<br>
dst_repo.getsep(), src_repo.getsep())<br>
src_name = folder.repository.nametrans(src_name)<br>
dst_hash[src_name] = folder<br>
<br>
Note that this entails that all transformations be done in the
space of the srouce repository.<br>
The documentation page
<a class="moz-txt-link-freetext" href="http://docs.offlineimap.org/en/latest/nametrans.html">http://docs.offlineimap.org/en/latest/nametrans.html</a><br>
says that the mapping should use the separator of the repository,
without specifying which.<br>
It should read the source repository for both the direct and
reverse nametrans.<br>
<br>
-- Giuseppe<br>
<br>
On 7/17/2013 15:10, Giuseppe Attardi wrote:<br>
</div>
<blockquote cite="mid:51E697E2.5070903@di.unipi.it" type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
I need to migrate a number of accounts in my deparment from
Exchange to Maildir (Postifx).<br>
<br>
Since migration has to be done in stages, bidirectional
synchronization is necessary.<br>
<br>
Mapping between folder names is complicated by the fact that
Exhange folders may contain dots.<br>
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.<br>
There is no pattern of use that would allow recognizing them.<br>
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.<br>
<br>
Since many accounts must be migrated, it is impossible to go
through them and change the names by hand.<br>
<br>
I decided to adopt the solution to convert '.' to Unicode <span
class="st">MIDDLE <em>DOT</em>' (U+00B7), which looks similar.<br>
I wrote nametrans functions that encode the names in mUTF-7, as
used by IMAP.<br>
</span><br>
<span class="st"><span class="st"><span class="st"><span
class="st">I had to patch the code </span></span>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.<br>
Here is the patch:<br>
<br>
*** Base.py 2013-07-17 15:06:15.000000000 +0200<br>
--- Base.py~ 2013-04-16 17:02:14.000000000 +0200<br>
***************<br>
*** 216,225 ****<br>
# succeed in getting inexisting folders
which I would<br>
# like to change. Take care!<br>
folder = self.getfolder(dst_name_t)<br>
newdst_name =
folder.getvisiblename().replace(<br>
src_repo.getsep(), dst_repo.getsep())<br>
! if dst_folder.name != newdst_name and \<br>
! dst_folder.name.replace('&ALc-',
'.') != newdst_name:<br>
raise OfflineImapError("INFINITE FOLDER
CREATION DETECTED! "<br>
"Folder '%s' (repository '%s') would
be created as fold"<br>
"er '%s' (repository '%s'). The
latter becomes '%s' in "<br>
--- 216,225 ----<br>
# succeed in getting inexisting folders
which I would<br>
# like to change. Take care!<br>
folder = self.getfolder(dst_name_t)<br>
+ # apply reverse nametrans to see if we end
up with the same name<br>
newdst_name =
folder.getvisiblename().replace(<br>
src_repo.getsep(), dst_repo.getsep())<br>
! if dst_folder.name != newdst_name:<br>
raise OfflineImapError("INFINITE FOLDER
CREATION DETECTED! "<br>
"Folder '%s' (repository '%s') would
be created as fold"<br>
"er '%s' (repository '%s'). The
latter becomes '%s' in "<br>
</span><br>
The solution seems to work fine.<br>
<br>
Here is a test run:<br>
<br>
*** Processing account me<br>
Establishing connection to ex.di.unipi.it:993<br>
Establishing connection to imap.unipi.it:143<br>
Creating folder aa&ALc-a[Maildir]<br>
Creating folder aa.a[Maildir]<br>
Skipping aa/a (not changed)<br>
Syncing aa.a: IMAP -> MappedIMAP<br>
Copy message 1 (1 of 1) Exchange:aa.a -> Maildir<br>
*** Finished account 'me' in 0:03<br>
<br>
Comments and suggestions welcome.<br>
<br>
Giuseppe Attardi<br>
Università di Pisa<br>
<br>
</span> </blockquote>
<br>
</body>
</html>