Documents >> FreeBSD >> FreeBSD Maildrop filter

FreeBSD Maildrop - Move tagged mail

How to move tagged mail to another folder. This guide is made as an addition to my postfix guide.

I found myself in the need of getting spam mails moved to the Junk folder automatically. This i did by setting up a global maildropfilter.

Create or edit the following file and make sure it is readable by the user that is running maildrop, in my case the vmail user:

ee /usr/local/etc/maildroprc

# Start by adding a logfile to follow maildrop
logfile "/var/log/maildroprc.log"

# This is just a visual aid.
log "------------------------"

# This searches though the mail headder to se if it is a spam mail
if (/^X-Spam-Status: YES/)
{
# Redirect the mail to the Junk folder
       exception {
                to "$DEFAULT.Junk/"
        }
}

Remember to create the logfile, since maildrop does not have these permissions.  

In this case the mail is moved to the Junk folder if it is tagged as spam. Ofcourse this is not the case if the folder does not exist.

Therefore if this is to be used, the Junk folder should be created when maildirs are created. This can be done in the following way:

maildirmake -f "FOLDERNAME" "Existing maildir"  

The command above need a existing maildir to create a new folder in.

When the folder is created it should be added to courier imap, to make it appear when users logon to webmail and imap. This is done my adding it to or creating the following file in the root of a users maildir. 

echo 'INBOX.Junk' >> $mail_home/$1/$2/courierimapsubscribed
echo 'INBOX.Sent' >> $mail_home/$1/$2/courierimapsubscribed
echo 'INBOX.Trash' >> $mail_home/$1/$2/courierimapsubscribed

In the above I used it in a script that has the maildir path stored in $mail_home/$1/$1 

This can also be done automatically when maildrop tries to filter mail, but I decided to create the folders by default.


^ Top | Copyright © 2007 Afterschool.dk| css | xhtml