Lots of people use IMAP instead of POP3 for their email access, but not so many people pick up on advantages that can be had by making that choice. We’re going to take a quick look today at one of the best reasons for using IMAP access to your email inbox.
Because this is the Internet, we’re allowed to use made up statistics. My made up statistic for this article will be that 99.99% of people who use IMAP to access their email have at least one filter, and if they’re not, perhaps they just haven’t realized the usefulness of it.
The great benefit of IMAP is that all email is left on the server. So no matter if you check it from home, work, or your friend’s house (via webmail!), you have access to every piece of email as if you were sitting at your usual computer.
The only problem with this method, especially my problem with this method originally, was it meant if I didn’t leave my email program open at home, then my emails would never be filtered, and they’d be one giant mess in my inbox when accessing from other locations.
So today, we’re going to talk about filtering with Exim Filters.
How Do I Make An Exim Filter?
First you will need to know, and probably write down, two things:
- The path to your email inbox on the server.
- The path to your exim filter file.
For the path to your email inbox on a cPanel server, it will look like:
mail/EXAMPLE.COM/EMAIL_NAME/
The path to your exim filter will be:
etc/EXAMPLE.COM/EMAIL_NAME/filter
So for example, say your email address is ‘bob@example.com’, your two paths will be:
Email Inbox: mail/example.com/bob/
Exim Filter: etc/example.com/bob/filter
Now that we have the paths out of the way, let’s continue.
Exim Filter usage started out here as a custom modification we had made to cPanel, though eventually they integrated it into their base configuration, which is excellent news for everyone. Now we just need to teach people how to use them.
To start using an Exim Filter on your incoming email, you will need to log into FTP, or go to your file manager in cPanel. From your home directory, the directory structure is ‘etc/example.com/email-account-name’. For me, that’s etc/webonce.com/jmather, however for you it will be different.
Once you have the last directory made, you need to create a file named ‘filter’. This is the file that Exim will check for to find filter rules. Not only that, but it needs a special ‘header’ (the first few lines of the file) just to make sure that you’re trying to filter email and didn’t place the file there randomly. The begining of an exim filter file looks like:
# Exim filter
# Error trapping
if error_message then finish endif
The first line tells Exim “Yes, okay, use this as a filter.” The second is just a comment for your information, and the third basically tells exim “If there’s a problem, then just stop.” So problems don’t cause too much of an issue.
Now for your first rule. My favorite rule automatically puts emails that SpamAssassin has marked as spam, into the trash.
# SPAM CHECK
if $header_x-spam-flag is "YES"
then
save mail/webonce.com/jmather/.Trash/
finish
endif
This tells exim if the header ($header_) X-Spam-Flag (x-spam-flag) is YES, then to save it to the folder named Trash (with cPanel’s IMAP setup, folders under your inbox are prefixed with a .).
Now say your friend Billy emails you a lot. So much, in fact, that you want to give him his own email folder. Billy’s email address is billy@example.com. Here is the rule you would use:
if $header_from contains "billy@example.com"
then
save mail/webonce.com/jmather/.Billy/
finish
endif
we use $header_from as we’re working with the “From:” header in the email. You will notice I used ‘contains’ instead of ‘is’. The reason I did that is because Billy sets up his email with his name in it as well, so the From: header actually looks like:
From: Billy Boy <billy@example.com>
We could match the whole thing, but this gives us flexibility to only specify the email address.
So there’s the basics of how to use Exim Filters to filter your email on the server. If this topic proves of some interest, I will go into further ways you can use Exim Filters to make things simple for you, and also cover some of the cavets of using this method, like tweaks you will want to do to your configuration of Thunderbird.