alarm-notify.sh: allow sender names with spaces; fixes #3843
Costa Tsaousis (ktsaou) committed
Jun 21, 2018 at 22:31 UTC
bab702804062a6825bcf454fc64aa754a09e8c79
1 file changed
+17
-14
plugins.d/alarm-notify.sh
+17
-14
@@ -924,39 +924,42 @@ duration4human() {
924
# email sender
925
926
send_email() {
927
- local ret= opts=
927
+ local ret= opts=() sender_email="${EMAIL_SENDER}" sender_name=
928
if [ "${SEND_EMAIL}" = "YES" ]
929
then
930
931
if [ ! -z "${EMAIL_SENDER}" ]
932
then
933
- if [[ "${EMAIL_SENDER}" =~ \".*\"\ \<.*\> ]]
934
- then
935
- # the name includes single quotes
936
- opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
937
- elif [[ "${EMAIL_SENDER}" =~ \'.*\'\ \<.*\> ]]
933
+ if [[ "${EMAIL_SENDER}" =~ ^\".*\"\ \<.*\>$ ]]
934
then
935
# the name includes double quotes
940
- opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
941
- elif [[ "${EMAIL_SENDER}" =~ .*\ \<.*\> ]]
936
+ sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
937
+ sender_name="$(echo "${EMAIL_SENDER}" | cut -d '"' -f 2)"
938
+ elif [[ "${EMAIL_SENDER}" =~ ^\'.*\'\ \<.*\>$ ]]
939
+ then
940
+ # the name includes single quotes
941
+ sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
942
+ sender_name="$(echo "${EMAIL_SENDER}" | cut -d "'" -f 2)"
943
+ elif [[ "${EMAIL_SENDER}" =~ ^.*\ \<.*\>$ ]]
944
then
945
# the name does not have any quotes
944
- opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)'"
945
- else
946
- # no name at all
947
- opts=" -f ${EMAIL_SENDER}"
946
+ sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
947
+ sender_name="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
948
fi
949
fi
950
951
+ [ ! -z "${sender_email}" ] && opts+=(-f "${sender_email}")
952
+ [ ! -z "${sender_name}" ] && opts+=(-F "${sender_name}")
953
+
954
if [ "${debug}" = "1" ]
955
then
956
echo >&2 "--- BEGIN sendmail command ---"
954
- printf >&2 "%q " "${sendmail}" -t ${opts}
957
+ printf >&2 "%q " "${sendmail}" -t "${opts[@]}"
958
echo >&2
959
echo >&2 "--- END sendmail command ---"
960
fi
961
959
- "${sendmail}" -t ${opts}
962
+ "${sendmail}" -t "${opts[@]}"
963
ret=$?
964
965
if [ ${ret} -eq 0 ]