How to rename a local OfflineIMAP managed folder

Since quite some time I am using OfflineIMAP to keep my mailbox status from various servers locally available on my machine. I did more or less follow the excellent guide A unix style mail setup, but didn’t use folder name translation right from the beginning. So I got stuck with four folders named INBOX: acc1/INBOX, acc2/INBOX, etc. This wouldn’t be a big problem, but when using Mutt with the folder sidebar patch (as available in the mutt-patched package in Debian), there is the problem that only the INBOX part is shown.

offlineimap

So I decided to rename all the local folders to the scheme described in the above guide. At the end I want to have a folder layout as follows:

  Maildir/acc1/acc1
  Maildir/acc1/acc1.folder1
  Maildir/acc1/acc1.folder2

where the acc1 related to the INBOX on the remote account acc1, and the others are folders on the remote end.

Unfortunately, renaming is not supported in offlineimap, it would simply download everything again – at best! So I checked what needs to be done, and it turned out it is not as complicated as I thought. The necessary steps are:

  • rename the actual maildir folders
  • rename the status files in ~/.offlineimap/Account-acc1/LocalStatus/
  • rename the status files in ~/.offlineimap/Repository-acc1local/FolderValidity/
  • add the correct nametrans functions to your configuration file
  • do a dry-run test

To make this more specific, let us assume I want to reorganize the account acc1 in this way, and there are two folders synced. That is, before we start the Maildir folder contains:

Maildir/acc1/INBOX
Maildir/acc1/folder1
Maildir/acc1/folder2

and we want to achieve that the layout is

Maildir/acc1/acc1
Maildir/acc1/acc1.folder1
Maildir/acc1/acc1.folder2

Due to the fact that both the LocalStatus files and the FolderValidity files are naned in the same way as the folders, the following trivial script does all the necessary renaming for this simple case:

for d in ~/Maildir/acc1 ~/.offlineimap/Account-acc1/LocalStatus ~/.offlineimap/Repository-acc1local/FolderValidity ; do
  mv $d/INBOX $d/acc1
  mv $d/folder1 $d/acc1.folder1
  mv $d/folder2 $d/acc1.folder2
done

Finally, the correct renaming has to be done by adding nametrans rules to the helper script. The functions oimaptransfolder_acc1 and localtransfolder_acc1 as defined in the above tutorial can be used as is, and need only be added to the respective Repository sections in the configuration file.

After having done the necessary renaming, what remains is to give it a good test. Best way to do it is with

offlineimap --dry-run -o -a acc1

which runs the syncronization in dry-run mode, so nothing is actually copied, and only once and only for acc1.

If during this test run nothing strange appears, like many many emails are deleted on either end, then you are fine.

Enjoy.

Email this to someonePrint this pageShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInFlattr the author

3 Responses

  1. adrian15 says:

    You are probably missing a done in your script.

    • Well spotted that there is an error, but it is not the missing done, but the completely bogus first line (“was” I have to say). Fixed now. First I thought about making a double loop, but that was too much pain 😉

      Thanks for spotting it!

  1. 2015/09/06

    […] How to rename a local OfflineIMAP managed folder […]

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>