#
# dot-procmailrc - an example of ~/.procmailrc for personal use of abmail
#
# Copyright (C) 2006-2008 Taiji Yamada <taiji@aihara.co.jp>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
SHELL=/bin/sh
PATH=/opt/local/clamav/bin:/opt/local/bin:/usr/bin:/bin
LD_LIBRARY_PATH=/opt/local/clamav/lib:/opt/local/lib
MAILDIR=$HOME/Mail	# You'd better make sure it exists
#LOGFILE=$MAILDIR/from-log
LOCKFILE=$HOME/.lockmail
MYDOMAIN=aihara.co.jp

#
# variables for duplicated messages to remove
#
SW_DUPLICATED_MESSAGES_TO_REMOVE=off

#
# variables for antivirus
#
SW_ANTIVIRUS=off

#
# variables for antispam
#
:0
* SW_ANTISPAM ?? ^^^^
{
  SW_ANTISPAM=off
  SW_ANTISPAM_ADD_HEADER=off
  #
  # spam report
  #
  :0
  * !SW_ANTISPAM_ADD_HEADER ?? on
  {
    SW_SPAMREPORT=on
  }
  #
  # duplicated messages to remove
  #
  :0
  * SW_DUPLICATED_MESSAGES_TO_REMOVE ?? on
  {
    :0 Wh: $HOME/msgid.lock
    | formail -D 8192 $MAILDIR/msgid.cache
  }
}

#
# antivirus
#
:0
* SW_ANTIVIRUS ?? on
{
  :0 HB
  * ? /opt/local/clamav/bin/clamdscan --quiet -; test "$?" = "1"
  /dev/null
}

#
# antispam
#
:0
* SW_ANTISPAM ?? on
{
  ANTISPAMDIR=spam-`/bin/date +%Y%m%d`
  :0 HB
  * ? /opt/local/bin/abmail -b -g -d; test "$?" = "1"
  {
    :0
    * !SW_ANTISPAM_ADD_HEADER ?? on
    ${ANTISPAMDIR}/.
    :0 Efw
    | formail -i "X-Abmail-Flag: Yes"
  }
}

#
# spam report
#
:0
* SW_SPAMREPORT ?? on
{
  SPAMREPORT_SUBJECT="\[abmails report for $LOGNAME\]"

  :0
  *$ ^Subject: ${SPAMREPORT_SUBJECT}
  {
    :0 H
    *$ ^From $LOGNAME@$MYDOMAIN
    * ? /opt/local/bin/abmailsreport -R; test "$?" = "0"
    {
      LOG='(abmails report)'
    }
    :0 E
    /dev/null
  }
  :0
  *$ ^Subject: Re: ${SPAMREPORT_SUBJECT}
  {
    :0 H
    *$ ^From $LOGNAME@$MYDOMAIN
    * ? /opt/local/bin/abmailsreport -Q; test "$?" = "0"
    {
      LOG='(reply abmails report)'
      :0 HBc
      | /opt/local/bin/abmailsreport -r
    }
    :0 E
    /dev/null
  }
}
