Synchronizing Thunderbird e-mail filters using Dropbox

Two words: Use symlinks.

If you already know what a symlink is then you don’t need to read the rest of this article. If you want a better explanation, read on…

I use the Thunderbird e-mail client to read mail stored on my company’s IMAP mail server. I have a lot of filters set up that sort the mail into different folders, and Thunderbird stores the filter definitions in a file called msgFilterRules.dat. I read mail on different machines, some running various Linux distros and some running Mac OS X. I wanted all of the different machines to use the same rules for filtering e-mail into different folders, and if I make changes to the filters on one host I want those changes to take effect on all of the other hosts as well.

To do this I first set up a Dropbox account and installed the Dropbox software on my different machines, so now there’s a directory called “Dropbox” in my home directory that is synchronized between all of my different machines. I moved my filter file into the Dropbox directory and symlinked that to the location where Thunderbird expects to find the filter rules.

The step-by-step explanation if you want to do this:

Set up Dropbox on all of your machines.

Shut down Thunderbird if it’s running.

Start up a terminal window.

Find the msgFilterRules.dat file that you want to use as your “master” copy. On both my Mac laptop and Linux hosts the file is stored in ~/.thunderbird/[profile name]/ImapMail/[imap server name]/, where [profile name] is your Thunderbird profile name on that host, usually some random characters followed by ‘.default’. (Type cat ~/.thunderbird/profiles.ini if you want to see all of your profile names.)

Make a backup copy of the msgFilterRules.dat file:

cd ~/.thunderbird/[profile name]/ImapMail/[imap server name]/

cp msgFilterRules.dat msgFilterRules.dat.backup

Move the filter file to Dropbox:

mv msgFilterRules.dat ~/Dropbox/

Symlink the Dropbox copy of the file to the current directory, where Thunderbird expects to find it:

ln -s ~/Dropbox/msgFilterRules.dat .

Verify that the symlink was created correctly:

ls -al

You should see a line that looks like:

lrwxrwxrwx  1 earl users        37 Oct 25 21:12 msgFilterRules.dat -> /home/earl/Dropbox/msgFilterRules.dat

Now the machine you’re on is using the Dropbox copy of the filter file. To set this up on your other machines:

Verify that the file exists in the ~/Dropbox directory:

ls -al ~/Dropbox

Get to the directory where the filter file lives, remove the local copy, then create the symlink:

cd ~/.thunderbird/[profile name]/ImapMail/[imap server name]/

rm msgFilterRules.dat

ln -s ~/Dropbox/msgFilterRules.dat .

One word of warning: Thunderbird reads the filters into memory when it starts, and writes them back to disk when it exits. That means that if you have two hosts and Thunderbird is running on both of them, the last host that exits will write it’s version of the filters to disk. So if you make a change to the filters on one host and exit from Thunderbird, then exit from Thunderbird on the second host, the older filters on second host will overwrite the filter you just added. Because of this, I recommend exiting from Thunderbird whenever you leave your computer. I added a “killall thunderbird-bin” that runs from cron at 2am just to make sure that my copy at work isn’t running if I check mail from home in the morning.

5 Comments »

  1. nicolas roy Said,

    October 16, 2012 @ 7:33 am

    Hej.
    Thanks for the idea. I encounter a strange issue. In my Box, i prefer to rename the mail filter file, because i have several of them:
    /box/msgFilterRules-1.dat
    /box/msgFilterRules-2.dat

    Then, in the first IMAP directory, i create the links msgFilterRules.dat pointing to /box/msgFilterRules-1.dat
    and in the second IMPA directory, a link called msgFilterRules.dat pointing to /box/msgFilterRules-2.dat

    But if i start TB and make so modifications in the filters, TB does not modifie the existing file in /box, but it CREATES a new file in /box. If i check in the IMAP directory, the links points apparently still to /box/msgFilterRules-1.dat … but in fact the new created file /box/msgFilterRules.dat is modified.
    I just can’t get it … :(

  2. Earl Ruby Said,

    October 16, 2012 @ 2:57 pm

    Interesting. Have you tried storing the files in separate directories instead? e.g.:

    /Dropbox/imap1/msgFilterRules.dat
    /Dropbox/imap2/msgFilterRules.dat

    Then symlink to those files from your Thunderbird directory.

  3. nicolas roy Said,

    October 18, 2012 @ 9:12 am

    Yes, this is the solution i adopted. This works. But only if the File has the same name as TB expects. I found this very strange.

  4. Earl Ruby Said,

    October 18, 2012 @ 11:51 am

    That is odd. Not how symlinks are supposed to work at all, but at least the work-around fixes the issue.

    I think you’d have to look at Thunderbird’s source to figure out what’s going on.

  5. Ben Said,

    February 7, 2014 @ 4:37 am

    Thank you, that really helps!

Leave a Comment