Today I’ve finished one more long taken purpose. It is not great work but it does what it is designed for.
spam-learn-report
[CODE]#! /bin/bash
mailpath=”/path/to/Spam/cur/*”
mailbox_oldspam=”/path/to/Spam/Old/”
template_path=”/path/to/Spam-Report.m4”
name=“Yourname”
rec=“mail@blubb.de”
subject=“Spam statistics $(date –iso)”
if [ “$(ls –color=no ${mailpath/\*/} | wc -l)” -gt “0” ] ; then
total_count=$(for file in ${mailpath} ; do
echo “${file}”
done | wc -l)
learned_count=0
for file in ${mailpath} ; do
sa_output=$(sa-learn –spam –showdots “${file}” 2>/dev/stdout)
exitcode=$?
learned=$(echo “${sa_output}” | awk -F “Learned from “ ‘{print $2}’ | awk -F “ “ ‘{print $1}’)
learned_count=$((${learned_count}+${learned}))
if [ “${exitcode}” == “0” ] && procmail -a “${mailbox_oldspam}” ~/.procmailrc_put < “${file}” ; then
rm -rf “${file}”
fi
done
known_count=$(($total_count-$learned_count))
date=$(date –iso)
m4 -D NAME=”${name}” -D TO=”${rec}” -D SUBJECT=”${subject}” -D DATE=”${date}” -D \
LEARNED=”${learned_count}” -D KNOWN=”${known_count}” -D TOTAL=”${total_count}” \
-D TO=”${rec}” “${template_path}” | sendmail -t
fi[/CODE]
m4-Template
[CODE]To: NAME <TO>
Subject: SUBJECT
| Spam statistics for DATE | ============================
ifelse(TOTAL, 1, Your received one mail today., Your received TOTAL mails today.)
ifelse(LEARNED, 1, We learned to know only one new spammail this day., We learned to know LEARNED spammails these day.)
ifelse(KNOWN, 1, One spammail was already known.)ifelse(KNOWN, 0, Zero known spammails this day.)ifelse(KNOWN, 2, KNOWN spammails were already known.)[/CODE]
Filed under Gentoo, Linux, Me & no comments & one trackback
Trackback specific URI for this entry