Maildrop

is the mail filter/mail delivery agent that's used by the mail server. You do not need to install Maildrop if you already have Courier installed. This is a standalone build of the mail utility for use with other mail servers (MTA's).

maildrop is a replacement for your local mail delivery agent. reads a mail message from standard input, then delivers the message to your mailbox. knows how to deliver mail to mbox-style mailboxes, and maildirs. Maildir is a mailbox format used by and.

maildrop optionally reads instructions from a file describing how to filter incoming mail. These instructions can direct Maildrop to deliver the message to an alternate mailbox, or forward it somewhere else. Unlike, Maildrop uses a structured filtering language.

maildrop is written in C++ and is significantly larger than. However, it uses resources much more efficiently. Unlike Procmail, will not read a 10 megabyte mail message into memory. Large messages are saved in a temporary file and are filtered from the temporary file. If the standard input to Maildrop is a file and not a pipe, a temporary file will not be necessary.

maildrop checks the mail delivery instruction syntax from the filter file before attempting delivery of a message. Unlike procmail, if the filter file contains syntax errors, terminates without delivering the message. The user can fix the typo without any email lost!

Installation
emerge maildrop

Per User Filter
touch ~/.mailfilter chmod 600 ~/.mailfilter
 * will be included from
 * so be sure it exist and have a permission 600 (otherwise it will give you an error)

Autoreply
Here is Rolan Yang  little autoreply recipe which uses mailbot (included with the courier-imap package) with a few lines which prevent autoreplying to spam marked by spamassassin and also an extra line to prevent mailing lists autoreplies. The -D parameter prevents duplicate autoresponses from being sent to the same individual for a period of x days (here it is set to 1 day)

This is used in a completely virtual user hosted environment. A squirrelmail module add or removes this to ".mailfilter" located in the users home directory. If anyone has suggestions on improving this feel free to email me - Rolan Yang .

Autoreplying adds to spam. Make sure you configure your spam filtering agent to learn and, if possible, allow users to report spam.

Additionally, Stefan Hornburg  excluded the following headers from autoreplies, because they are used by mailing lists as well:

Random Visitor suggests the following, which assumes mail has already been passed through ClamAV and SpamAssassin, then avoids replying to mailing lists, bounces, and status messages, and only replies once every 7 days per unique sender address (appropriate for vacation and Out Of The Office messages):

Mail Headers Manipulation
Chris Holleman  gave an idea of how change mail header

Adjust the rule for your needs.

Mailbox Creation and Subscription

 * You have to create mailboxes for every single destination. Without doing so, maildrop will complain.


 * And subscribe for the new mailfolder

Postfix
You have to let Postfix know we have a local delivery agent:

(I have this at line # 113.)

(As of 2007.08.28, I'm seeing a maildrop entry within the master.cf file already. I don't think this "editing master.cf" section is needed for the average user. --Roger 09:32, 28 August 2007 (UTC))

Restart postfix after configuration change


 * 1) /etc/init.d/postfix restart

Qmail Integration
add ~/.qmail file inside user mailbox folder with following:

and

~/.mailfilter file with maildrop commands

Scanning for Viruses with ClamAV
if (`/usr/bin/clamdscan --no-summary --stdout - | grep -c 'FOUND'` == 1) {        MAILDIR="$MAILDIR/.Quarantine" `test -f $MAILDIR/maildirsize && exit 1 || exit 0` if ( $RETURNCODE == 0 ) {                `maildirmake $MAILDIR` }        to "$MAILDIR"; } exception { VIRUS_TAG=`clamscan -V` VIRUS_TAG="$VIRUS_TAG on $HOSTNAME" xfilter "reformail -A 'X-Virus-Checker-Version: $VIRUS_TAG'" xfilter "reformail -A 'X-Virus-Status: Clean'" } You may also use clamassassin, which tries to act like SpamAssassin. Clamassassin still requires ClamAV being installed and clamd must be running as a daemon.

Scanning for Spam with SpamAssassin
(Since I use Evolution client for collecting & managing my email, I'm only concerned about one Inbox folder. As such, I commented-out the command moving spam "to $MAILDIR".  Additionally, "log "$TICKS : >>> TAGGED AS *** HAM ***" should probably also be added to the non-spam section of this script as this is good info when reading the Maildrop log file. --Roger 10:34, 28 August 2007 (UTC))

if ( $SIZE < 26144 ) {        exception { xfilter "spamc -u $RECIPIENT" } } if ( (/^X-Spam-Flag: YES/:h) || (/^X-Spam-Status: Yes/:h) ) {        #         # Run sa-learn: Learn as spam #        if ( /^X-Spam-Level: *-.*$/:h ) {                cc "| sa-learn --sync --spam" }        MAILDIR="$MAILDIR/.Spam" log "$TICKS : >>> TAGGED AS *** SPAM ***" #        # deliver to maildir #        log "$TICKS : >>> Mail successfully delivered to $MAILDIR" exception { to "$MAILDIR"; } } else {        if ( /^X-Spam-Level: *-.*$/:h ) {                #                 # Run sa-learn: Learn as ham #                cc "| sa-learn --sync --ham" } }

Invalid home directory permissions - world writable.
Delivery error (command maildrop 24688 error (75, /usr/bin/maildrop: Invalid home directory permissions - world writable.)) msg 1/1 (812 bytes), delivery error (command maildrop 24688 error (75, /usr/bin/maildrop: Invalid home directory permissions - world writable.)) 1 messages retrieved, 0 skipped


 * the fix

For your own good
Delivery error (command maildrop 5485 error (75, /usr/bin/maildrop: Cannot have world/group permissions on the filter file - for your own good.)) msg 1/1 (842 bytes), delivery error (command maildrop 5485 error (75, /usr/bin/maildrop: Cannot have world/group permissions on the filter file - for your own good.))
 * the fix

Get rid of [arguments] line in file

Unable to create a dot-lock
msg 1/1 (3612 bytes), delivery error (command maildrop 10143 error (75, /usr/bin/maildrop: Unable to create a dot-lock.)) 1 messages retrieved, 0 skipped

When maildrop is told to route a message into a directory, it tries to create a "dot-lock" file within that directory, as a signal to tell other processes that the directory is being maintained and that they should wait for this maintenance to finish before trying to make any changes within the directory. After the message has been delivered, this dot-lock file is deleted so that other processes can work with the directory as needed.

If the directory does not exist, or if maildrop doesn't have permission to create files in the directory, you will see the Unable to create a dot-lock error message.

The fix, of course, is to create the directory and make sure it is owned by (or has permissions which make it writable by) the same userid which maildrop will be running as, which will almost always be the userid which owns the mailbox itself.

Of course, finding out which directory of which user maildrop is complaining about can be quite a challenge, since the error message fails to tell you. If you have users with extremely complex maildrop files this can be near impossible.

-- Another thing to ensure is that maildrop creates the virtual user's mail directory. Add this to /etc/maildroprc;

`[ -d $DEFAULT ] || (maildirmake $DEFAULT && maildirmake -f Spam $DEFAULT)`
 * 1) If the destination maildir doesn't exist, create it.

Hope this helps. email:dmurungi@dicts.mak.ac.ug
 * Replace maildrimake with the path to the maildirmake binary

Postfix log shows Syntax Error while parsing $HOME/.mailfilter
This was confusing as the only verbose switch for maildrop was augmenting Postfix's main.cf with: mailbox_command = maildrop -V3"

This didn't help with debugging much at all. But I found changing the indent style of the $HOME/.mailfilter file to be the culprit.

Pay specific attention to non-bash commands such as "exception" and "xfilter". These commands are provided by maildrop and reading the maildropfilter manual will explain their usage. Specifically, the command "exception" needed the bracket one space after it's command and indenting the bracket on the following line apparently spawned the Syntax Error.

I would imagine this might be resolved within the future if somebody files a bug report or fixes it.

--Roger 09:50, 28 August 2007 (UTC)

Getting Mailutils reading Maildir Folders
I use the command line mail utilities for simple mail checking using the command "mail". Since mailx doesn't support maildir folders, I needed to move to using Mailutils.

By default Mailx, is probably installed. Uninstall this package as it conflicts with Mailutils and then install.
 * 1) emerge -C mail-client/mailx && emerge net-mail/mailutils

Add the following line within your $HOME/.bashrc file: alias mail="/usr/bin/mail -m maildir:$HOME/.maildir" (If somebody has a mail.rc command, please document here. Else, using the '-m' switch is the only method I know of for allowing maildir reading.)

Restart Bash within each open terminal so the .bashrc file gets read.
 * 1) bash -$-

It's a good idea to add this to your /etc/mail.rc. (Else, read messages with the command line utility are usually moved to another maildir folder keeping your GUI email client from seeing them.) set hold
 * 1) Hold read or saved messages in the system mailbox

--Roger 19:49, 28 August 2007 (UTC)

Getting Nail reading Maildir Folders
I've moved to using Nail as Nail now handles maildir. Mailutils hasn't been version bumped for a while (due to issues with Guile). Not only this, but Nail source code has been officially merged back into Mailx. However, Gentoo Portage will still use the same Nail ebuild for current future releases of Mailx containing Nail code.


 * 1) emerge -C mail-client/mailutils && emerge net-mail/nail

Add the following lines within your $HOME/.bashrc file: alias mail="mail -f $HOME/.maildir" alias mailx="mailx -f $HOME/.maildir" (I do not know what ~/.mailrc or /etc/nail.rc setting would set the maildir folder.)
 * 1) alias nail="nail -f $HOME/.maildir"

Issue the following command within ~/ for rereading ~/.bashrc: $ bash -$- --Roger 23:19, 12 January 2008 (UTC)

A better command for rereading user/global bashrc's is $ sudo env-update && source /etc/profile or $ sudo env-update &&. /etc/profile Executing these commands will load all system-wide changes, so you end up with the most up-to-date environment possible in a multiuser system or a system that is going through an emerge update cycle. --Anonymous User

Instead of specifying the maildir in an alias, one can set the MAIL environement variable to "$HOME/.maildir/".

YoungFrog 11:17, 17 January 2011 (GMT)