Maildrop is the mail filter/mail delivery agent used by the Courier Mail Server. maildrop reads a mail message from standard input and based on your filtering rules, performs the appropriate action on the message. The maildrop package allows you to perform server side mail filtering. This allows you to write your filters once rather than having to write them for each additional client. I use maildrop to sort my email, report my spam and forward email from my wife to all my accounts. Needless to say it has made my life very easy.
There are multiple ways to ensure creation of folders for new users. One approach would be to use the onchange patch for vpopmail. While this approach allows you to create a folder on user creation, it does not recreate folders which users accidentally delete or rename. The below setup handles that situation by checking for the folder's existance with each email and creates it if it is not there.
The installation instructions for maildrop can be found here in the INSTALL file in the tarball.
The below example is a maildrop filter for a system running qmail and virtual domains with vpopmail.
SHELL="/bin/sh"
import EXT
import HOST
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
VDHOME=`dirname "$VHOME"`
# Test for the existance of the SPAM directory. Create it if it doesn't
# exist
`test -d $VHOME/Maildir/.SPAM`
if ( $RETURNCODE == 1 )
{
`/usr/lib/courier-imap/bin/maildirmake -f SPAM $VHOME/Maildir`
`echo INBOX.SPAM >> $VHOME/Maildir/courierimapsubscribed`
}
The filter works as described below.
Creating a SPAM folder does not buy you anything unless you can move email to it based on a particular set of criteria. The below filter moves tagged spam to the SPAM folder. The following lines to the previous filter.
if ( /^X-Spam-Status: Yes/ )
{
cc "!spam@uce.gov"
to "$VHOME/Maildir/.SPAM"
}
The filter works as described below.
It is highly recommended before implementing the above filters that you familiarize yourself with the maildropfilter man page. The vpopmail man pages are located here.
2007-07-24 Correct FTC spam reporting address to spam@uce.gov. Thanks to Rajeev Sekhar for notifying me regarding the change.
2007-07-23 Added forward to uce@ftc.gov to "Sending Email to Folder Based on Criteria" section. Hopefully this encourages people continue to fight spam.
2007-05-04 Thanks to Bob from QMR for noting the missing double quote (") in the SPAM folder example and suggesting the clarification on the maildirmake PATH.
2007-04-23 Thanks to John Simpson for noting the error in setting the VPOP variable and for suggesting clarification on from where the mailfilter imports the EXT and HOST variables.