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.

10 thoughts on “Synchronizing Thunderbird e-mail filters using Dropbox

  1. 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. 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. 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. 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. I have succesfully created the symlink, but whenever I start thunderbird it deletes the symlink and it creates a new and empty msgfilterrules.dat.

    Help?

    • Okay… I made it into a hard-link, but that gives me another problem.

      The version in dropbox does not get updated after I close thunderbird.

      • Update:

        I noticed this:
        – The hard link is correctly made. after the link is made I can alter text in any of the files, and the other one updates.
        – After opening and closing thunderbird the files will stay hard linked (same test method)

        BUT:
        – If I change or add an e-mailfilter in mozilla thunderbird it will destroy the link. Both files will continue to excist, but they will no longer update the other one if any of them is changed. So the link is no longer present.

        Any help?

  6. The symlink needs to be for msgFilterRules.dat, not msgfilterrules.dat. Capitalization matters.

    If that’s not the issue I’m not sure what is. Thunderbird should write to the file named msgFilterRules.dat regardless of whether it’s a file or a symlink.

    I stopped using Thunderbird about a year ago, but this method was still working fine when I stopped using it. I just fired up Thunderbird to see what’s changed and it couldn’t import my old account settings which are still in the ~/.thunderbird directory. I can tell it’s using the directory because it did update some files, but it’s not loading any of my mail account settings.

    Let me poke around a bit and see what’s up.

  7. yes something is wrong, at least on Windows,i have the same problem as Tycjan. Thunderbird doesn’t recognize the symlink as a pointer to a valid file, it shows an empty list of rules instead. As soon as i close Thunderbird, it creates an empty msgFilterRules.dat in place of my symlink, so that it gets overwritten. The funny thing is that the symlink works perfectly for the address book, the abook.mab file. Curious!

Leave a Reply to Ben Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.