# chmod o+w /var/log/procmail.log
LOGFILE=/var/log/procmail.log
LOGABSTRACT=all
VERBOSE=on

PATH=$PATH
SHELL=/bin/sh
LANG=zh_TW.Big5
LC_ALL=zh_TW.Big5

#USERHOME=$HOME
#USER=`echo ${USERHOME##*/}`
SUBJ=`formail -zxSubject:`
SUBJ=`formail -zxSubject: | sed -e "s/['|"|$]//g"`
CHAR=`echo ${SUBJ#?*?}`
CHAR=`echo ${CHAR%?*?}`
CHAR=`echo ${CHAR%?Q?*}`
# 將 mail是什麼編碼放到暫存檔
CHARTMP=`echo ${CHAR} > /tmp/procmail_whatcode`
#SUBJ=`formail -zxSubject: | sed 's/=?.*?[bB]?(.*)=?=/1/'`
# Need to Compile mmencode
#SUBJ=`formail -zxSubject: | sed 's/=?.*?[bB]?(.*)=?=/1/'| mmencode -u `
#SUBJ=`echo $SUBJ | mmencode -u`
SUBJ=`perl /etc/procmail_parser  $SUBJ`
# 將 mail主旨已轉碼過的放到暫存檔
SUBJTMP=`echo $SUBJ > /tmp/procmail_subj`
#DECODE=`/etc/procmail_iconv.sh`
#SUBJ=`echo $SUBJ | iconv -f big-5  -t utf-8`
#SUBJ=`echo $SUBJ | iconv -f $CHAR  -t utf-8`
# 透過此 script判斷該由什麼編碼轉成 UTF-8
SUBJ=`sh /etc/procmail_iconv.sh`
FROM=`formail -zxFrom:`
FROM=`echo ${FROM##*<}`
FROM=`echo ${FROM%%>}`
TO=`formail -zxTo:|tr ',' '
'| sed 's/(.*) (.*)/2/'`
TO=`echo ${TO##*<}`
TO=`echo ${TO%%>}`
USER=`echo ${TO%%@*}`
HOME=/home/$USER
# 此設定檔可放到/etc/procmailrc底下全部有效, 或者使用者 $HOME/.procmailrc個別受限

FGREP=/bin/fgrep
DEFAULTBOX=/var/mail/$USER
BLACKLISTBOX=$HOME/blacklistbox
BLACKHOLE=/dev/null
TIME=`date +%F'.'%T'.'%N`
# chmod 777 /var/mail/quarantine
QUARANTINE=/var/mail/quarantine/
FILE=$TIME-$USER.eml
#TMP=`formail > $QUARANTINE$FILE`
DATE=`date +%F' '%T`

# MySQL
#DBHOST=lab100
#DBNAME=procmail_test
#DBUSER=procmail
#DBPASS=procmail123456

# PGSQL
DBHOST=localhost
DBNAME=procmaildb
DBUSER=procmailuser
DBPASS=procmailpassword

# 如果.whistlist是空白的,信件會放到 blacklistbox裡
# MySQL
#WHITELIST =`echo "select sender from maillist where recipient='$TO'" | mysql -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME | sed '/sender/d'>$HOME/.whitelist`
# PGSQL
WHITELIST =`echo "select sender from whitelist where recipient='$TO'" | psql -U $DBUSER $DBNAME | sed -e '/sender/d' -e '/^-/d' -e '/^(/d' | awk '{print $1}' > $HOME/.whitelist`

:0E
* ? (echo "$FROM" | $FGREP -i -f $HOME/.whitelist)
  ${DEFAULTBOX}

# 只有沒列在 whitelist裡的信會被寫到 /var/mail/quarantine/xxx.eml (每一封信存一檔案), 並記錄到資料庫
:0E
*!? (echo "$FROM" | $FGREP -i -f $HOME/.whitelist)
   ${BLACKHOLE} `echo "insert into blacklistboxlist(timestamp,recipient,sender,subject,file) values ('$DATE','$TO','$FROM','$SUBJ','$FILE');" | psql -U $DBUSER $DBNAME` `formail > $QUARANTINE$FILE`
  #`echo "insert into blacklistbox(timestamp,recipient,sender,subject,file) values ('$DATE','$TO','$FROM','$SUBJ','$FILE');" | mysql -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME` `formail > $QUARANTINE$FILE` /dev/null
#  ${BLACKLISTBOX}
#  $HOME/blacklistbox

# create database MySQL
#
#       CREATE DATABASE procmail_test;
#
#       —
#       — whitelist
#       —
#       CREATE TABLE `maillist` (
#         `id` int(11) NOT NULL auto_increment,
#         `recipient` varchar(128) NOT NULL default '',
#         `sender` varchar(128) NOT NULL default '',
#         PRIMARY KEY  (`id`)
#       ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
#
#       —
#       — blacklist recored
#       —
#       CREATE TABLE `blacklistbox` (
#         `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
#         `recipient` varchar(128) NOT NULL default '',
#         `sender` varchar(128) NOT NULL default '',
#         `subject` text NOT NULL,
#         `file` text NOT NULL
#       ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

最後修改日期: 2006 年 12 月 07 日

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。