#!/usr/local/bin/bash
## by skp v.2 Dec 30 2004 ##
##
## i use this to generate a list of spam i've received and
## randomly pick one to use as a title for my website
##
## first you need to shim off spam using procmail:
## :0 HBci
## /apache/virtualhost.fif3/htdocs/spam2web
##
## then in html, add this to your title: SuperFresh Spam:
## and i use this in the body for the list:
RDIR=/apache/htdocs/spam2web
WDIR=/spam2web # path for website viewers
FILE1=$RDIR/results # file listing all the spam one subject per line
FILE2=$RDIR/results2 # file with just one spam subject
/sbin/chown www.daemon ${RDIR}/msg* ${RDIR}/*.txt 1>/dev/null 2>/dev/null
/bin/chmod a+rw ${RDIR}/msg* ${RDIR}/*.txt 1>/dev/null 2>/dev/null
while (( `ls -tr ${RDIR}/msg*txt |wc -w` > 7 )) ;do
rm `ls -trm ${RDIR}/msg*txt |tr -d "\r"|tr -d "\n" |cut -d',' -f -1`
done
for i in `ls -t ${RDIR}/msg* |grep -vi .txt`
#do if [[ ! -a $i.txt ]] ;then
do cat $i |/usr/local/bin/formail -k -X From: -X Subject: > ${i}.txt
rm $i
#fi
done
rm $FILE1
for i in `ls -t ${RDIR}/msg*txt`
do SUB=`cat ${i} |grep -e '^Subject:' |tr -cd "[:print:]" |grep -A50 -C1 Subject |cut -d' ' -f2- |cut -c -40`
WFILE=`echo ${i}|cut -d'/' -f6`
if [[ $SUB ]] ;then
echo "${SUB}
" >> $FILE1
fi
done
## pull a random line out just for our headline
RANDOM=$$ ; let number=0 ; let RANGE=5
while [ $number -eq 0 ]
do number=$RANDOM ; let "number %= $RANGE" ;done
cat $FILE1 |tail -"$number" |head -n1 > $FILE2
rm -f `ls ${RDIR}/msg* |grep -ve 'txt$'` 1>/dev/null 2>/dev/null