summaryrefslogtreecommitdiffhomepage
path: root/plugins/weblog/procmail
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/weblog/procmail')
-rwxr-xr-xplugins/weblog/procmail/procmail.sh30
1 files changed, 27 insertions, 3 deletions
diff --git a/plugins/weblog/procmail/procmail.sh b/plugins/weblog/procmail/procmail.sh
index 44fa68f..473ff8e 100755
--- a/plugins/weblog/procmail/procmail.sh
+++ b/plugins/weblog/procmail/procmail.sh
@@ -17,9 +17,29 @@ function mimedecode() {
perl -ne 'require MIME::Head; $head = MIME::Head->read(\*STDIN); $head->decode(); print $head->get("Subject")'
}
+function next_index() {
+ DIR=$1
+
+ LASTENTRY=`ls -1r $DIR/$(date +%Y)/$(date +%Y%m%d)* 2>/dev/null | xargs -n 1 basename | head -n1`
+
+ if [ "$LASTENTRY" == "" ] ; then
+ echo 001
+ return
+ fi
+
+ INDEX=${LASTENTRY:9:3}
+
+ INDEX=$(($INDEX + 2))
+
+ while [ "$((${#INDEX} < 3))" == "1" ] ; do INDEX=0$INDEX ; done
+
+ echo $INDEX
+}
+
echo "Log at `date`:" >> ~/log 2>&1
-BLOGDIR=/var/www/blog
+BLOGDIR=/var/www/rolandreichwein.de-blog
+#BLOGDIR=/var/www/blog
# Default: Error
ERRORMSG="General error."
@@ -64,8 +84,9 @@ echo "$BODY" > /home/weblog-bloginput/body.txt
SUBJECT=`echo "$HEADER" | mimedecode`
SUBJECT_PATH=`echo "$SUBJECT" | sed -e 's/[^a-zA-Z0-9]/_/g'`
+ARTICLEINDEX=`next_index $BLOGDIR`
-ARTICLEDIR="$BLOGDIR/`date +%Y/%Y%m%d`_$SUBJECT_PATH"
+ARTICLEDIR="$BLOGDIR/`date +%Y/%Y%m%d`_${ARTICLEINDEX}_$SUBJECT_PATH"
mkdir -p $ARTICLEDIR
echo "Subject: $SUBJECT" >> $ARTICLEDIR/article.data
@@ -85,7 +106,10 @@ fi
chmod -R a+r $ARTICLEDIR
chmod a+x $ARTICLEDIR
-echo "Processed successfully." | mutt -s "Bloginput: $SUBJECT_PATH" -- "$ADDR" >> ~/log 2>&1
+(
+echo "Processed successfully."
+echo "ARTICLEDIR=$ARTICLEDIR"
+) | mutt -s "Bloginput: $SUBJECT_PATH" -- "$ADDR" >> ~/log 2>&1
echo "User log:" >> ~/log
cat body.txt >> ~/log