From d03ffcfd3466873611a85064896e49817697ba30 Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Mon, 3 Nov 2014 12:00:53 +0100 Subject: email2irc: refactor --- bin/email2irc.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'bin/email2irc.sh') diff --git a/bin/email2irc.sh b/bin/email2irc.sh index 8633dd0f..dd02f39d 100755 --- a/bin/email2irc.sh +++ b/bin/email2irc.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2012 Holger Levsen +# Copyright 2012-2014 Holger Levsen # released under the GPLv=2 # @@ -8,7 +8,14 @@ # to turn jenkins email notifications into irc announcements with kgb # see http://kgb.alioth.debian.org/ # -LOGFILE=/var/lib/jenkins/email_log +LOGFILE=/var/log/jenkins/email.log +# FIXME: add logrotate rule for /var/log/jenkins/email.log + +debug123() { + if $DEBUG ; then + echo "Debug: $1 $2 $3" >> $LOGFILE + fi +} # # parse email headers to check if they come from jenkins @@ -47,25 +54,28 @@ while read line ; do JENKINS_JOB=${line:15} fi fi + DEBUG=true # catch first line of email body (to send to IRC later) if [ "$HEADER" == "false" ] && [ -z "$MY_LINE" ] ; then MY_LINE=$line + debug123 "#1" MY_LINE $MY_LINE # if this is a multipart email it comes from the email extension plugin - if [ "${line:0:5}" = "-----" ] ; then - read line - read line - read line - MY_LINE=$(echo $line | cut -d " " -f1-2) + if [ "${line:0:7}" = "------=" ] ; then + debug123 "#2" line $line + MY_LINE="" else - MY_LINE=$(echo $line | tr -d \< | tr -d \>) + debug123 "#3" line $line + MY_LINE=$(echo $line | tr -d \< | tr -d \> | cut -d " " -f1-2) + debug123 "#4" MY_LINE $MY_LINE fi fi - + DEBUG=false done # check that it's a valid job if [ -z $JENKINS_JOB ] ; then VALID_MAIL=false fi +debug123 "#5" MY_LINE $MY_LINE # only send notifications for valid emails if [ "$VALID_MAIL" == "true" ] ; then -- cgit v1.2.3-54-g00ecf