Skip to content

Instantly share code, notes, and snippets.

@udonchan
Created April 12, 2010 06:02
Show Gist options
  • Save udonchan/363316 to your computer and use it in GitHub Desktop.
Save udonchan/363316 to your computer and use it in GitHub Desktop.
Spamasassin が.Junk に分類したメールを norify するスクリプト
#!/bin/sh
export LANG=ja_JP.UTF-8
USERLIST='/etc/.notify_users'
DOMAIN="udonchan.org"
SUBJECT="[${DOMAIN}]SpamMail Notify From MailServer"
for user in `grep -v "^#" $USERLIST`;
do
CNT=0
SBJLS=""
quota=`quota $user`
QUOTAMSG="領域は無制限です."
if ! expr "$quota" : "Disk quotas for user .* none" > /dev/null ;then
QUOTAMSG=`echo "$quota" |tail -n 1|awk '{print $2 / $3 * 100 "%"}'`"の領域を使用しています"
fi
for mails in `sh -c "find /home/${user}/Maildir/.Junk/cur -type f; \
find /home/${user}/Maildir/.Junk/new -type f" 2> /dev/null`;
do
CNT=`expr $CNT + 1`
SBJLS="${SBJLS}"`cat "${mails}" |grep '^Subject: '|head -1|sed 's/^Subject: //'|nkf -W8`" \n"
done
if [ $CNT -gt 0 ]; then
addr="${user}@${DOMAIN}"
#addr="[email protected]"
echo -e $user "様:\n"\
"現在" $CNT "件のスパムメールを受信しています。\n"\
"コントロールパネルにログインしご確認をお願い致します。\n"\
"$QUOTAMSG\n"\
"\n"\
"受信しているスパムメールのリスト\n"\
"${SBJLS}" |sed 's/^ //g'|nkf -j -W8|mail -s "$SUBJECT" "$addr"
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment