@cryptotaxi247 / netdata-1 / commits / 8b8ba4849

Further reduce spam score by adding encoding info.

A lot of spam filters are more likely to flag email without an encoding in the Content-Type headers as spam. Netdata is technically not locale aware, but the email message is sent from a bash script, and bash is locale aware, so the message will be encoded in whatever the environment dictated character encoding is (which is usually UTF-8) these days. It turns out that my assessment in the previous commit was incorrect, and it actually is trivial to get a MIME compatible encoding name from a shell script, so lets try to make sure the encoding is set automatically. When not explicitly set by the user, we first try to determine the system encoding using the `locale` command. If this fails and the user has not explicitly set an encoding, then it defaults to UTF-8, which is the de-facto standard on all modern Linux distributions and thus should be correct most of the time. Users can override the detection by setting EMAIL_CHARSET in health_alarm_notify.conf. For English speaking users, this should result in no change. For non-English speaking users, this may fix display of non-punycode encoded hostnames.

Austin S. Hemmelgarn committed Aug 15, 2017 at 08:43 UTC 8b8ba4849d27615e2f7fc4b3c5a8ff44e8958a30
2 files changed +18 -2
conf.d/health_alarm_notify.conf
+7
@@ -105,6 +105,13 @@ SEND_EMAIL="YES"
105 DEFAULT_RECIPIENT_EMAIL="root"
106 # to receive only critical alarms, set it to "root|critical"
107
108 +# Optionally specify the encoding to list in the Content-Type header.
109 +# This doesn't change what encoding the e-mail is sent with, just what
110 +# the headers say it was encoded as.
111 +# This shouldn't need to be changed as it will almost always be
112 +# autodetected from the environment.
113 +#EMAIL_CHARSET="UTF-8"
114 +
115
116 #------------------------------------------------------------------------------
117 # pushover (pushover.net) global notification options
plugins.d/alarm-notify.sh
+11 -2
@@ -290,6 +290,7 @@ declare -A role_recipients_custom=()
290 # email configs
291 EMAIL_SENDER=""
292 DEFAULT_RECIPIENT_EMAIL="root"
293 +EMAIL_CHARSET=$(locale charmap 2>/dev/null)
294 declare -A role_recipients_email=()
295
296 # load the user configuration
@@ -301,6 +302,14 @@ else
302 error "Cannot find file ${NETDATA_CONFIG_DIR}/health_alarm_notify.conf. Using internal defaults."
303 fi
304
305 +# If we didn't autodetect the character set for e-mail and it wasn't
306 +# set by the user, we need to set it to a reasonable default. UTF-8
307 +# should be correct for almost all modern UNIX systems.
308 +if [ -z ${EMAIL_CHARSET} ]
309 + then
310 + EMAIL_CHARSET="UTF-8"
311 +fi
312 +
313 # -----------------------------------------------------------------------------
314 # filter a recipient based on alarm event severity
315
@@ -1401,7 +1410,7 @@ Content-Type: multipart/alternative; boundary="multipart-boundary"
1410 This is a MIME-encoded multipart message
1411
1412 --multipart-boundary
1404 -Content-Type: text/plain
1413 +Content-Type: text/plain; encoding=${EMAIL_CHARSET}
1414 Content-Disposition: inline
1415 Content-Transfer-Encoding: 8bit
1416
@@ -1419,7 +1428,7 @@ Date : ${date}
1428 Notification generated on ${this_host}
1429
1430 --multipart-boundary
1422 -Content-Type: text/html
1431 +Content-Type: text/html; encoding=${EMAIL_CHARSET}
1432 Content-Disposition: inline
1433 Content-Transfer-Encoding: 8bit
1434