Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 22, 2012, 06:41:50 AM

Pages: [1]   Go Down
  Print  
Author Topic: HOWTO: Perform server side IMAP filtering (using /etc/vfilters)  (Read 1269 times)
stranded
Newbie
*
Offline Offline

Posts: 1


« on: January 24, 2009, 12:54:26 PM »

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!

Logged
Mitch
Berserker Poster
*****
Offline Offline

Posts: 12837


WWW
« Reply #1 on: January 26, 2009, 05:21:29 AM »

Nice work, thanks!  Thumbs Up
Logged

New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!
PunaroDotCom
Trekkie
**
Offline Offline

Posts: 14


WWW
« Reply #2 on: April 27, 2010, 10:19:39 AM »

Thanks for this...  I am trying to create account-specific forwarders and I used your example plus the Exim specs to create my script.  One problem I had following your formula was that it wasn't obeying the $header_to condition, so I rearranged and made the conditions more explicit:

if
 $header_to: contains "me@mydomain.com" and
 (
 $header_from: contains "abc.com"
 or $header_from: contains "xyz.com"
 )
then
 unseen deliver "myotheraccount@gmail.com"
endif


This seems to have fixed the issue for me.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: