Installation:FreeBSD:Maildrop

From PMWH2 - PHPMyWebHosting's official wiki
Jump to: navigation, search

see also Installation:Debian

I'm assuming that you already have succesfully installed maildrop with mysql and quota support.

When you want to use per user anti-spam settings, read from a mysql database, there are 2 options:

  1. Let amavisd-new read the preferences from a mysql table.
  2. Let spamassassin read the preferences from a mysql table.

Using the second option: To do this you should disable the spam checks by amavisd-new by putting the following line in your amavisd.conf:

@bypass_spam_checks_maps  = (1);

The next step is to configure Maildrop to check the spam before it delivers the mail to the mailbox.

This maildroprc does the following things:

  1. Check if the Maildir already exists
  2. If the Maildir doesn't exist, make sure the homedir exists, then create the maildir and create the quota with it.
  3. Put it through spamc which connects to spamd, which checks if the message is spam
  4. If the message is spam, then put it in a seperate Spam folder, when that folder doesn't exist create it first.
  5. If the message is not spam deliver it to the maildir.



SHELL="/usr/local/bin/bash"
USER=`echo $DEFAULT | awk '{split($0,a,"/"); print a[2]}'`
DOMAIN=`echo $DEFAULT | awk '{split($0,a,"/"); print a[1]}'`
import $MAILDIRQUOTA

`/bin/test -d $HOME/$DOMAIN/$USER`
if ($RETURNCODE != 0)
{
       `/bin/mkdir -p $HOME/$DOMAIN`
       if ($RETURNCODE==0)
       {
            logfile maildrop.log
            log "$DATE Creating directory: $HOME/$DOMAIN/$USER"
       }
       else
       {
            logfile maildrop.log
            log "$DATE Failed creating directory: $HOME/$DOMAIN/$USER"
       }

       `/usr/local/bin/maildirmake $HOME/$DOMAIN/$USER`
       if ($RETURNCODE==0)
       {
            logfile maildrop.log
            log "$DATE Creating maildir: $HOME/$DOMAIN/$USER"
       }
       else
       {
            logfile maildrop.log
            log "$DATE Failed creating maildir: $HOME/$DOMAIN/$USER"
       }

       if ($MAILDIRQUOTA==0)
       {
            logfile maildrop.log
            log "$DATE Quota is null: $MAILDIRQUOTA"
       }
       else
       {
               QUOTA="$MAILDIRQUOTA"'S'
               `/usr/local/bin/maildirmake -q $QUOTA $HOME/$DOMAIN/$USER`
               if ($RETURNCODE==0)
               {
                    logfile maildrop.log
                    log "$DATE Adding quota $MAILDIRQUOTA to maildir: $HOME/$DOMAIN/$USER"
               }
               else
               {
                    logfile maildrop.log
                    log "$DATE Failed adding quota $MAILDIRQUOTA to maildir: $HOME/$DOMAIN/$USER"
               }
       }
}

if ( $SIZE < 26144 )
{
   exception {
      xfilter "/usr/local/bin/spamc -x -u $USER"
   }
}
if ( /^X-Spam-Flag: *YES/ )
{
       `/bin/test -d $HOME/$DOMAIN/$USER/.Spam/`
       if ($RETURNCODE != 0)
       {
               `/usr/local/bin/maildirmake $HOME/$DOMAIN/$USER/.Spam/`
               if ($RETURNCODE==0)
               {
                       logfile maildrop.log
                       log "$DATE Creating $HOME/$DEFAULT/.Spam/"
               }
               else
               {
                       logfile maildrop.log
                       log "$DATE Failed creating $HOME/$DEFAULT/.Spam/"
               }
       }

       logfile maildrop.log
       to $HOME/$DOMAIN/$USER/.Spam/
}



Make sure the maildroprc and maildropmysql.config are only readable by the user under which maildrop is suid installed, probably vmail.