[Logcheck-devel] Bug#860052: [PATCH] Let mime-construct pick an encoding (closes: #860052)

Anthony DeRobertis aderobertis at metrics.net
Fri Nov 17 19:00:27 UTC 2017


tags 860052 + patch
thanks

Note that this uses arrays, which are of course a bashism, but the top 
of the script explicitly calls for bash, so I presume bashisms are OK. 
Unfortunately, because of the "eval", it doesn't fully protect from 
weirdness in the config file. Of course, it looks like that eval could 
fairly easily be removed...


 From 86c8dc10a6452c011b993569ea0994bf280fb40f Mon Sep 17 00:00:00 2001
From: Anthony DeRobertis
Date: Fri, 17 Nov 2017 12:43:01 -0500
Subject: [PATCH] Let mime-construct pick an encoding (closes: #860052)

Forcing 7bit is nice for MUAs and other tools that don't fully support
MIME encoding messages, but has the downside of sometimes generating
non-compliant messages. In particular, overly long lines get the
logcheck message rejected by Debian's default Exim configuration.

Add a configuration option to allow this to be overridden if required to
work with some MIME-unaware tool.
---
  etc/logcheck.conf | 11 +++++++++++
  src/logcheck      | 16 ++++++++++++----
  2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/etc/logcheck.conf b/etc/logcheck.conf
index 4653c11..1699fae 100644
--- a/etc/logcheck.conf
+++ b/etc/logcheck.conf
@@ -71,6 +71,17 @@ FQDN=1
  
  #ADDTAG="no"
  
+# Previous versions of logcheck always sent messages in 7bit encoding,
+# even if that resulted in RFC-violating messages. For example, really
+# long syslog lines would generate too-long SMTP lines, which are
+# rejected at least by Debian's default exim configuration. The new
+# default is to let mime-construct pick an appropriate encoding, but you
+# can override it by setting the below (to any of the encodings
+# supported by mime-construct). You may need to do this if you have
+# tools handling logcheck emails that don't understand MIME encoding.
+
+#MIMEENCODING="7bit"
+
  # Set a different location for temporary files than /tmp
  # this is useful if your /tmp is small and you are getting
  # errors such as:
diff --git a/src/logcheck b/src/logcheck
index a8c58ea..48082f3 100755
--- a/src/logcheck
+++ b/src/logcheck
@@ -84,6 +84,7 @@ INTRO=1
  LOGCHECKDEBUG=0
  MAILOUT=0
  MAILASATTACH=0
+MIMEENCODING=
  NOCLEANUP=0
  REBOOT=0
  FQDN=0
@@ -176,7 +177,7 @@ Also verify that the logcheck user can read all files referenced in
  $(export)
  EOF
  	} | eval mime-construct $MIMECONSTRUCTARGS \
-	    --subject "'Logcheck: $HOSTNAME $DATE exiting due to errors'" --encoding "7bit" \
+	    --subject "'Logcheck: $HOSTNAME $DATE exiting due to errors'" "${ENCODING[@]}" \
          --file - --to "$SENDMAILTO"
  
      elif [ "$MAILOUT" -eq 1 ]; then
@@ -306,14 +307,14 @@ sendreport() {
  	debug "Sending report: '$subject' to $SENDMAILTO"
          if [ "$MAILASATTACH" -eq 1 ]; then
            debug "Sending report as attachment"
-          eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --encoding "7bit" --string "'Report attached'" --to "$SENDMAILTO" --attachment "logcheck_report" --encoding "7bit" --file "$TMPDIR/report"
+          eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" "${ENCODING[@]}" --string "'Report attached'" --to "$SENDMAILTO" --attachment "logcheck_report" "${ENCODING[@]}" --file "$TMPDIR/report"
            return $?
          elif [ "$MAILASATTACH" -eq 2 ]; then
            debug "Sending report as gzip attachment"
-          eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --encoding "7bit" --string "'Report attached'" --to "$SENDMAILTO" --type "application/x-gzip" --attachment "logcheck_report.gz" --file "'gzip -c $TMPDIR/report |'"
+          eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" "${ENCODING[@]}" --string "'Report attached'" --to "$SENDMAILTO" --type "application/x-gzip" --attachment "logcheck_report.gz" --file "'gzip -c $TMPDIR/report |'"
            return $?
          fi
-        eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --to "$SENDMAILTO" --encoding "7bit" --file "$TMPDIR/report"
+        eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --to "$SENDMAILTO" "${ENCODING[@]}" --file "$TMPDIR/report"
      fi
  }
  
@@ -536,6 +537,13 @@ else
      SORT="sort -k 1,3 -s"
  fi
  
+# Set the forced mime encoding if not left blank (auto)
+if [ -n "$MIMEENCODING" ]; then
+	ENCODING=(--encoding "$MIMEENCODING")
+else
+	ENCODING=()
+fi
+
  # Hostname either fully qualified or not.
  if [ "$FQDN" -eq 1 ]; then
          HOSTNAME="$(hostname --fqdn 2>/dev/null)"
-- 
2.15.0



More information about the Logcheck-devel mailing list