diff options
-rw-r--r-- | TODO | 2 | ||||
-rwxr-xr-x | plugins/weblog/procmail/procmail.sh | 94 | ||||
-rw-r--r-- | plugins/weblog/procmail/procmailrc | 12 |
3 files changed, 107 insertions, 1 deletions
@@ -1,4 +1,4 @@ -weblog: mail procmail +weblog: blättern weblog: link consistency check (cron?) weblog: style: zitate Integrate into Debian diff --git a/plugins/weblog/procmail/procmail.sh b/plugins/weblog/procmail/procmail.sh new file mode 100755 index 0000000..bafe889 --- /dev/null +++ b/plugins/weblog/procmail/procmail.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# +# Mail Blog input script, to be called by procmail +# +set -e + +function atexit { + if [ "$ERRORMSG" != "" -o -s errormsg.txt ] ; then + (echo "$ERRORMSG" ; cat errormsg.txt) | mutt -s "bloginput: Error" -- "$ADDR" >> ~/log 2>&1 + fi + cd + rm -rf "$DIR" +} +trap atexit EXIT + +function mimedecode() { + perl -ne 'require MIME::Head; $head = MIME::Head->read(\*STDIN); $head->decode(); print $head->get("Subject")' +} + +echo "Log at `date`:" >> ~/log 2>&1 + +BLOGDIR=/var/www/blog + +# Default: Error +ERRORMSG="General error." +USERLOG="" + +DIR=`mktemp -d` + +cd "$DIR" + +touch body.txt +touch errormsg.txt + +cat > inmail + +ADDR=`grep "^From: " inmail | sed -e 's/^From: //'` +if echo "$ADDR" | grep -q -v "^[a-zA-Z0-9@._-<>\" ]\+$" ; then + # can't send error message to unknown requester + ERRORMSG="" + exit 1 +fi +if echo "$ADDR" | grep -q "weblog-bloginput" ; then + # don't reply to mails from weblog-bloginput, i.e. prevent mail loops + ERRORMSG="" + exit 1 +fi + +#if grep -q "^pitch " inmail ; then +# PITCH=`grep "^pitch " inmail|head -n1|sed -e 's/^pitch \([+-]\?[0-9]\+\(\.[0-9]\+\)\?\).*/\1/'` +# if echo "$PITCH" | grep -q "^pitch " ; then +# # no pitch match +# ERRORMSG="Bad pitch syntax." +# exit 1 +# fi +# USERLOG="pitch $PITCH" +#else +# PITCH=0 +#fi + +ALLLINES=`wc -l inmail | cut -f1 -d" "` + +HEADERLINES=`cat inmail | (n=0; while read i ; do + if [ "$i" == "" ] ; then + echo $n + break + fi + n=$(($n + 1)) +done)` + +HEADER=`head -n$HEADERLINES inmail` +BODY=`tail -n$(($ALLLINES - $HEADERLINES - 1)) inmail` + +echo "$HEADER" > /home/weblog-bloginput/header.txt +echo "$BODY" > /home/weblog-bloginput/body.txt + +SUBJECT=`echo "$HEADER" | mimedecode` +SUBJECT_PATH=`echo "$SUBJECT" | sed -e 's/[^a-zA-Z0-9]/_/g'` + +ARTICLEDIR="$BLOGDIR/`date +%Y/%Y%m%d_%H%M`_$SUBJECT_PATH" + +mkdir -p $ARTICLEDIR +echo "Subject: $SUBJECT" >> $ARTICLEDIR/article.data +echo "" >> $ARTICLEDIR/article.data +echo "$BODY" >> $ARTICLEDIR/article.data + +echo "Processed successfully." | mutt -s "Bloginput: $SUBJECT_PATH" -- "$ADDR" >> ~/log 2>&1 + +echo "User log:" >> ~/log +cat body.txt >> ~/log + +ERRORMSG="" +echo "Done successfully at `date`." >> ~/log 2>&1 + diff --git a/plugins/weblog/procmail/procmailrc b/plugins/weblog/procmail/procmailrc new file mode 100644 index 0000000..fa1fe6f --- /dev/null +++ b/plugins/weblog/procmail/procmailrc @@ -0,0 +1,12 @@ +:0: +* ^X-Virus-Infected +Virus +# TODO: can be /dev/null later + +:0: +* ^X-Spam-Flag: YES +Spam +# TODO: can be /dev/null later + +:0 fhbw +| /home/weblog-bloginput/procmail.sh |