leaving the computer at home: email filters

leaving the computer at home: email filters

In the previous installment of this series, I wrote about managing email sync and more importantly the sorting of the hundreds of emails I receive daily into hierarchy of folders. Without any kind of rules-based sorting, it is incredibly difficult to manage and prioritize things considering the sheer volume of email that arrives each day.

To recap, that first step was to “move” my local folders into the Gmail hierarchy. When an email arrives in Mail.app on my OS X system, it goes through the series of rules and gets moved into the desired folder. These appear as folders in Mail.app, but for Gmail they are effectively labels with the same name. The problem with this approach is that I need Mail.app running to do my filters. It would be much more effective to have the filters running at Gmail and have the labels applied there and they would still appear as folders in Mail.app.

I found that manually creating the filters via the Gmail web site was kind of a pain. Doable for sure, but there were too many steps, especially with some of my multi-step filters. With over 30 individual rules that needed to be migrated, I thought I’d be spending a lot of time recreating them online.

But I was saved by Google Labs, which has an optional import/export XML functionality that allows you to create filters in a text file and then upload. To enable it, select “Labs” under the Gmail settings cog icon. Once you do this, you’ll have an option for importing and exporting when you list filters. You don’t really need to know XML in order to roll your own filters. What I did was select two of my filters and export them. I then used this reference to re-create all my Mail.app rules as XML items.

XML file for Gmail label import

A text file can look a bit intimidating at first, but they’re quite easy to work with. The example to the right contains an export of two individual filters. I have highlighted one of the filters and it is structured as follows:

  • Each individual filter is contained between the “<entry>” and “</entry>” tags.
  • You don’t need to change anything other than the actual filter information which are the three lines that begin with “<apps:property”
  • The first apps line determines that the filter will looks for “from” values that contain “facebook” or “twitter”
  • The second apps line determines that if there is a match, it applies the label “Facebook”
  • The third line determines that if there is a match, it also “archives” the message which effectively skips the inbox, so it doesn’t appear there
  • You do not need to worry about the other lines such as <title>, <id> or <updated>

To add another filter, simply copy the content between a single “<entry>” and “</entry>” tag and paste it after the last “</entry>” tag. This way, you can have all your filters in a single XML file. Once you’re done, simply import them back into Gmail on the Filters settings page. It does take a bit of work, but it’s much easier than creating them individually. If you have a question about how to do something, create the filter via the web UI and then export the single filter via XML for reference.

Once I transferred all my Mail.app Rules to Gmail, I deactivated the rules on OSX. Now all the filtering is done via Gmail and even on the iPhone and iPad mail clients, my email will be correctly filtered.