I fought with this for a few hours, so I thought I'd share what I've learned.
I check my Lunarpages email from four or five different machines using IMAP, and I wanted to come up with a better way to sort mail into folders on the server (before it's sent to my email reader).I have my main email folder that should receive emails addressed to me, and a few sub-folders (Junk, Mailing Lists) that should get my lower priority email.
Here's the quick overview:
1) Open your mail client (and make sure that you're configured for IMAP access to your Lunarpages server). Create the folders you want as sub-folders of your main folder. I'll use "Junk" and "Mailing Lists" as an example.
2) We're going to create the filter file now. For this example, your Lunarpages account username (used to get into cPanel) is acme1 and your email address is
joe@acme.com. Open up Notepad or TextEdit on your PC, and copy in the following:
# Exim filter
if not first_delivery and error_message then finish endif
# This section send all emails from baddomain.com and reallybaddomain.com that are sent to joe@acme.com to the trash.
if
$header_from: contains "baddomain.com"
or $header_from: contains "reallybaddomain.com"
and $header_to: contains "joe@acme.com"
then
save "/dev/null" 660
endif
# This puts all mail from united.com and aa.com that are sent to joe@acme.com into a folder called Junk (make sure you put in a period in front of the folder name and include the trailing slash).
if
$header_from: contains "united.com"
or $header_from: contains "aa.com"
and $header_to: contains "joe@acme.com"
then
save "/home/acme1/mail/acme.com/joe/.Junk/" 660
endif
# This puts all mail from delta.com, jetblue.com and nwa.com that are sent to joe@acme.com into a folder called Mailing Lists (once again, don't forget the period in front of the folder name and the training slash).
if
$header_from: contains "delta.com"
or $header_from: contains "nwa.com"
or $header_from: contains "jetblue.com"
and $header_to: contains "joe@acme.com"
then
save "/home/acme1/mail/acme.com/joe/.Mailing Lists/" 660
endif
All other mail is delivered normally.
Notes:
- If you have 100 domains that you want to go into the Mailing Lists folder, just add 100 "or" lines.
- In this example, the only email that's filtered is to joe@acme.com (because of the $header_to condition). If you want to filter all email to your domain, just leave that out. For instance, my domain only has one user (me) and a catch-all - this way, all email is filtered, regardless of the destination.
3) Save the file as acme.com (your domain name). It needs to be compressed in the GZip format. On Mac, open a Terminal and type "gzip <filename>". On a PC, go to
www.gzip.org and download GZip for Windows. That'll add the .gz extension to it.
4) Now, open CPanel, go to Backup. Under Restore an Email Domain Forwarder/Filter, find your .gz file and upload it.
From there, your filtering should be active. You can't edit that file directly, so every time you edit the file, you need to compress and reupload it.
Enjoy!