Skip to content

Commit

Permalink
Errorhandling empty mail-from field
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnet committed Sep 27, 2021
1 parent f680f75 commit fc8be3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The script generates an HTML report based on rejected messages. Another script c
### PREREQUISITES PERL INTERPRETER

Install Perl Package
- Once System is fully updated, you can install perl package through ```yum install perl``` command.
- Once System is fully updated, you can install perl package through ```dnf install perl``` command.

Check Perl Version
- Since the package is installed now, you can check the Perl version through ```perl -v``` command.
Expand Down Expand Up @@ -64,4 +64,4 @@ Description
Please note that the script ```postfix-bounce-report.sh``` always generates the day before. Note if there are no conflict with your log-rotation jobs.

## LICENSE
postfix-bounce-report and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE
postfix-bounce-report and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE
14 changes: 10 additions & 4 deletions postfix-bounce-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
renice -n 10 $$ > /dev/null
export LC_ALL=de_DE.utf8

# Read XML configuration file and create variables set
CONFIGFILE="/root/postfix-bounce-report/config.xml"
MAILLOG=$(xmllint --xpath 'string(/config/maillog)' $CONFIGFILE)
LOGMAILFROM=$(xmllint --xpath 'string(/config/logmail_from)' $CONFIGFILE)
Expand All @@ -26,6 +27,7 @@ TIME_START=$(date +"%s")
ALLBOUNCES=`cat "${MAILLOG}" |grep "$(date -d '-'${PERIOD}' hour' '+%b %e')" |grep "${PATTERN}"`
COUNTBOUNCES=$( [ -n "$ALLBOUNCES" ] && echo "$ALLBOUNCES" | wc -l || echo 0 )

# Function for creating the HTML report
if [ ${COUNTBOUNCES} -gt 0 ]; then
MAILINFO='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title></title>'
MAILINFO+='<style>'
Expand All @@ -50,11 +52,13 @@ table.blueTable td, table.blueTable th { border: 1px solid #AAAAAA; padding: 3px

if [[ "$RECIPIENTS_CHECK" = true ]]; then
MAILFROM=$(perl -pe "s/.*?from=<(.*?)>.*/\1/gm" <<< ${BOUNCE})
if [[ "$MAILFROM" =~ $(echo ^\($(paste -sd'|' ${RECIPIENTS_LIST})\)$) ]]; then
if [ -z "${MAILFROM}" ]; then
MAILFROM="undefined"
elif [[ "$MAILFROM" =~ $(echo ^\($(paste -sd'|' ${RECIPIENTS_LIST})\)$) ]]; then
#echo "$MAILFROM is in the list"
MAILFROM=$(perl -pe "s/.*?from=<(.*?)>.*/\1/gm" <<< ${BOUNCE})
MAILFROM="<span style='color:#FFFFFF; background-color:#FF0000'><b> ${MAILFROM} </b></span>"
BOUNCESEVERETY="[CRITICAL] "
BOUNCESEVERETY="[CRITICAL]"
else
#echo "$MAILFROM is not in the list"
MAILFROM=$(perl -pe "s/.*?from=<(.*?)>.*/\1/gm" <<< ${BOUNCE})
Expand Down Expand Up @@ -91,14 +95,16 @@ table.blueTable td, table.blueTable th { border: 1px solid #AAAAAA; padding: 3px
MAILINFO+="<tr><td><strong>Script runtime:</strong></td><td>$((${TIME_DIFF} / 60)) Minutes</td><td>$((${TIME_DIFF} % 60)) Seconds</td><td></td></tr>"
MAILINFO+="</table></body></html>"

# If the criticality is CRITICAL it will always remain
if [ ! $BOUNCESEVERETY ]; then
if [ ${COUNTBOUNCES} -gt "${BOUNCESEVERETY_THRESHOLD}" ]; then BOUNCESEVERETY="[WARNING] "; else BOUNCESEVERETY="[INFO] "; fi
if [ ${COUNTBOUNCES} -gt "${BOUNCESEVERETY_THRESHOLD}" ]; then BOUNCESEVERETY="[WARNING]"; else BOUNCESEVERETY="[INFO]"; fi
fi

# E-Mail notification function
(
echo "From: ${LOGMAILFROM}"
echo "To: ${LOGMAILTO}"
echo "Subject: ${BOUNCESEVERETY}${LOGMAILSUBJECT}"
echo "Subject: ${BOUNCESEVERETY} ${LOGMAILSUBJECT} for ${HOSTNAME}"
echo "Mime-Version: 1.0"
echo "Content-Type: text/html"
echo ${MAILINFO}
Expand Down
3 changes: 1 addition & 2 deletions postfix-build-submission-recipients.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ NEW=$(grep sasl_username= $MAILLOG | cut -d " " -f 6 | perl -pe 's/://g' | xargs
echo "$NEW" > submission_recipient_new.txt
cat $RECIPIENTS_LIST > submission_recipient_old.txt
sort submission_recipient_new.txt submission_recipient_old.txt | uniq > $RECIPIENTS_LIST

rm submission_recipient_new.txt submission_recipient_old.txt -f
rm submission_recipient_new.txt submission_recipient_old.txt -f

0 comments on commit fc8be3b

Please sign in to comment.