More details on folder translator function

Philippe LeCavalier support at plecavalier.com
Thu Jan 13 14:22:40 GMT 2011


On Thu, 2011-01-13 at 08:51 +0100, Thomas Kahle wrote:
> Hi,
> 
> On 10:07 Mon 10 Jan     , Philippe LeCavalier wrote:
> > Hi.
> > 
> > I'm trying to translate INBOX to INBOX.folder.subfolder so that all
> > mails in the INBOX on one IMAP server get synced to subfolder on another
> > IMAP server. I've managed to include/exclude all the folders I want on
> > both sides but I can quite seem to translate the folder name.
> > 
> > The INBOX on the recipient side is for another mail account so I don't
> > want the mails merged.
> > 
> > This is all I've come up with so far...
> > 
> > nametrans = lambda foldername: re.sub('^INBOX\.', 'INBOX.folder.IN\.',
> > foldername)
> > 
> > Offlineimap isn't complaining with the above but it's not moving mail
> > into the desired folder but rather simply moving mail from INBOX to
> > INBOX which is exactly what I'm trying to avoid.
> 
> I'm using python for this.  You can specify a file with python
> source code in your config as follows:
> 
> pythonfile=~/bin/offlineimap-helpers.py
> 
> Then some account might look like this
> 
> [Repository acc1remote]
> type = IMAP
> remotehost = imap.acc1.com
> remoteusereval = get_username("imap.acc1.net")
> remotepasseval = get_password("imap.acc1.net")
> nametrans = oimaptransfolder_acc1
> ssl = yes
> 
> Note how nametrans is set to a function in the python file which looks
> like this:
> 
> import re
> def oimaptransfolder_acc1(foldername):
>     if(foldername == "INBOX"):
>         retval = "acc1"
>     else:
>         retval = "acc1." + foldername
>     retval = re.sub("/", ".", retval)
>     return retval
Thanks again Thomas. This appears to be exactly what I want.

***The OfflineIMAP part of your guide should definitely be included in
the working examples for this project***

As a side note; I was surprised to see you don't use IMAPFilter as part
of your solution. Is that because you feel mairix removes the need for
filtration?

Phil





More information about the OfflineIMAP-project mailing list