# HG changeset patch # User Franz Glasner # Date 1727865794 -7200 # Node ID 599fddb2370d3bd5e3907a30fe0fb07d93ff6a17 # Parent 7126823e4d70023367669e46be015af40ff2bcde bsmtp2dma: Some modernizations: use "read -r" and enhance some quoting diff -r 7126823e4d70 -r 599fddb2370d sbin/bsmtp2dma --- a/sbin/bsmtp2dma Tue Oct 01 20:18:12 2024 +0200 +++ b/sbin/bsmtp2dma Wed Oct 02 12:43:14 2024 +0200 @@ -54,9 +54,9 @@ # # Configuration directory # -: ${CONFIGDIR:=@@ETCDIR@@} +: ${CONFIGDIR:="@@ETCDIR@@"} -test -r "${CONFIGDIR}/bsmtp2dma.conf" && . "${CONFIGDIR}/bsmtp2dma.conf" +[ -r "${CONFIGDIR}/bsmtp2dma.conf" ] && . "${CONFIGDIR}/bsmtp2dma.conf" # @@ -176,7 +176,7 @@ # Start the mailer **before** opening the pipe; otherwise a # deadlock occurs # - "$MAILER" -f "${_sender_addr}" "${_recipient_addr}" <${MAILFIFO_STDIN} >${MAILFIFO_STDOUT} & + "$MAILER" -f "${_sender_addr}" "${_recipient_addr}" <"${MAILFIFO_STDIN}" >"${MAILFIFO_STDOUT}" & _pid_mailer=$! exec 3>"${MAILFIFO_STDIN}" @@ -208,12 +208,10 @@ # preserve leading white space when reading with `read` _oifs="$IFS" - IFS=" -" - cat "${MAILCONTENT}" | - while read _text; do - printf "%s\n" "$_text" >&3 - done + IFS=$'\n' + while read -r _text; do + printf "%s\n" "$_text" >&3 + done <"${MAILCONTENT}" # not all mailer recognize this # printf ".\n" >&3 IFS="$_oifs" @@ -221,7 +219,7 @@ # close the fd to the pipe: coproc should get EOF and terminate exec 3>&- # read eventually remaining stuff from the mailer until EOF - IFS='' read _dummy <&4 + IFS='' read -r _dummy <&4 exec 4<&- wait $_pid_mailer @@ -311,9 +309,8 @@ exec 3>"${MAILCONTENT}" # preserve leading white space when reading with `read` _oifs="$IFS" -IFS=" -" -while read _text; do +IFS=$'\n' +while read -r _text; do if [ "${_text}" = "." ]; then break else