aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorheeplr <[email protected]>2022-05-18 19:27:53 +0200
committerGitHub <[email protected]>2022-05-18 10:27:53 -0700
commit08b32c6fa9dd68d024447979e7c9b711b9e60c56 (patch)
tree648fef6cfba05e774f4a89443cf1fa427432adc3 /cmd
parent00ac77464ef15c56b2cffb049518b78545552a9d (diff)
zed: support subject as header in zed_notify_email()
Some minimal MUAs don't support passing the subjects as cmdline option. This commit checks if "@SUBJECT@" is missing in ZED_EMAIL_OPTS and then prepends a subject header to the notification message. Also set a default for ${subject}. Reviewed-by: Ahelenia Ziemia<C5><84>ska <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Daniel Hiepler <[email protected]> Closes #13440
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zed/zed.d/zed-functions.sh19
-rw-r--r--cmd/zed/zed.d/zed.rc1
2 files changed, 17 insertions, 3 deletions
diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh
index 70a7113c6..49b6b5402 100644
--- a/cmd/zed/zed.d/zed-functions.sh
+++ b/cmd/zed/zed.d/zed-functions.sh
@@ -223,6 +223,8 @@ zed_notify()
# ZED_EMAIL_OPTS. This undergoes the following keyword substitutions:
# - @ADDRESS@ is replaced with the space-delimited recipient email address(es)
# - @SUBJECT@ is replaced with the notification subject
+# If @SUBJECT@ was omited here, a "Subject: ..." header will be added to notification
+#
#
# Arguments
# subject: notification subject
@@ -240,7 +242,7 @@ zed_notify()
#
zed_notify_email()
{
- local subject="$1"
+ local subject="${1:-"ZED notification"}"
local pathname="${2:-"/dev/null"}"
: "${ZED_EMAIL_PROG:="mail"}"
@@ -261,12 +263,23 @@ zed_notify_email()
return 1
fi
- ZED_EMAIL_OPTS="$(echo "${ZED_EMAIL_OPTS}" \
+ # construct cmdline options
+ ZED_EMAIL_OPTS_PARSED="$(echo "${ZED_EMAIL_OPTS}" \
| sed -e "s/@ADDRESS@/${ZED_EMAIL_ADDR}/g" \
-e "s/@SUBJECT@/${subject}/g")"
+ # pipe message to email prog
# shellcheck disable=SC2086,SC2248
- eval ${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1
+ {
+ # no subject passed as option?
+ if [ "${ZED_EMAIL_OPTS%@SUBJECT@*}" = "${ZED_EMAIL_OPTS}" ] ; then
+ # inject subject header
+ printf "Subject: %s\n" "${subject}"
+ fi
+ # output message
+ cat "${pathname}"
+ } |
+ eval ${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS_PARSED} >/dev/null 2>&1
rv=$?
if [ "${rv}" -ne 0 ]; then
zed_log_err "${ZED_EMAIL_PROG##*/} exit=${rv}"
diff --git a/cmd/zed/zed.d/zed.rc b/cmd/zed/zed.d/zed.rc
index 3c58a2c28..c55a70c79 100644
--- a/cmd/zed/zed.d/zed.rc
+++ b/cmd/zed/zed.d/zed.rc
@@ -29,6 +29,7 @@ ZED_EMAIL_ADDR="root"
# The string @SUBJECT@ will be replaced with the notification subject;
# this should be protected with quotes to prevent word-splitting.
# Email will only be sent if ZED_EMAIL_ADDR is defined.
+# If @SUBJECT@ was omited here, a "Subject: ..." header will be added to notification
#
#ZED_EMAIL_OPTS="-s '@SUBJECT@' @ADDRESS@"