# Global maildrop filter file (used on Debian) # For use with Postfix/Courier IMAP/Amavisd-new virtual mailbox domains. # # This maildroprc automagically creates a Spam folder for the recipient # and places spam there. It also subscibes the recipient to the folder. # # Example maildir: /var/vmail/example.com/user/ # Configure 'plus addressing' in amavisd-new and Postfix in order to deliver # spam to user+spam@example.com. In main.cf: # recipient_delimiter = + # # in amavisd.conf: # $recipient_delimiter = '+'; # @addr_extension_spam_maps = ('spam'); # # Remember that 'plus addressing' occurs at tag2_level, not kill_level. kill_level needs # to be sufficiently high in order to allow some mail at tag2_level or greater to be # delivered to the recipient. Also be aware: if you create virtual aliases designed to # send mail to remote domains, either those remote domains must also support # 'plus addressing' or you will need to create additional aliases to remove +spam: # # user+spam@example.org user@example.org # # This means address rewriting cannot be disabled on the amavisd-new reinjection port. # # Also in main.cf: # virtual_transport = maildrop # maildrop_destination_concurrency_limit = 2 # maildrop_destination_recipient_limit = 1 # # and in master.cf: # # maildrop unix - n n - - pipe # flags=DRhu user=vmail:daemon argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop} # ${extension} ${recipient} ${user} ${nexthop} # # /var/log/maildroprc.log needs to exist and owned by vmail:vmail and # a logrotate script needs to be created. # HOME_DIR="/var/vmail" logfile "/var/log/maildroprc.log" EXTENSION="$1" RECIPIENT=tolower("$2") USER="$3" HOST="$4" SENDER="$5" if ( $EXTENSION eq "spam" ) { # Change 'spam' to 'Spam' since folder names are typically capitalized EXTENSION = "Spam" # Autocreate extension maildir # # See if the user exists `test -e $HOME_DIR/$HOST/$USER` #log "Testing for $HOME_DIR/$HOST/$USER subdirectory: result=$RETURNCODE" # Only continue if user is valid if ( $RETURNCODE == 0 ) { # See if the spam directory already exists `test -e $HOME_DIR/$HOST/$USER/.$EXTENSION` #log "Testing for $EXTENSION subdirectory: result=$RETURNCODE" if ( $RETURNCODE != 0 ) # spam directory does not exist - so we create it { # Create the subdirectory `maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER` log "Ran \"maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER\"" # Auto-subscribe the subdirectory `if ! grep -q INBOX.$EXTENSION $HOME_DIR/$HOST/$USER/courierimapsubscribed; then echo INBOX.$EXTENSION >> $HOME_DIR/$HOST/$USER/courierimapsubscribed; fi` # Set permissions on the mailbox `chmod -R 0700 $HOME_DIR/$HOST/$USER` log " Ran \"chmod -R 0700 $HOME_DIR/$HOST/$USER\"" } # Deliver the message to the mailbox exception { # for those who unsubscribed themselves - subscribe them `if ! grep -q INBOX.$EXTENSION $HOME_DIR/$HOST/$USER/courierimapsubscribed; then echo INBOX.$EXTENSION >> $HOME_DIR/$HOST/$USER/courierimapsubscribed; fi` to "$HOME_DIR/$HOST/$USER/.$EXTENSION" } } }