Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/bsmtp2dma @ 704:599fddb2370d
bsmtp2dma: Some modernizations: use "read -r" and enhance some quoting
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 02 Oct 2024 12:43:14 +0200 |
| parents | 4f2257ea7d0a |
| children | e2f262ec2bf4 |
comparison
equal
deleted
inserted
replaced
| 703:7126823e4d70 | 704:599fddb2370d |
|---|---|
| 52 ' | 52 ' |
| 53 | 53 |
| 54 # | 54 # |
| 55 # Configuration directory | 55 # Configuration directory |
| 56 # | 56 # |
| 57 : ${CONFIGDIR:=@@ETCDIR@@} | 57 : ${CONFIGDIR:="@@ETCDIR@@"} |
| 58 | 58 |
| 59 test -r "${CONFIGDIR}/bsmtp2dma.conf" && . "${CONFIGDIR}/bsmtp2dma.conf" | 59 [ -r "${CONFIGDIR}/bsmtp2dma.conf" ] && . "${CONFIGDIR}/bsmtp2dma.conf" |
| 60 | 60 |
| 61 | 61 |
| 62 # | 62 # |
| 63 # Default configuration values | 63 # Default configuration values |
| 64 # | 64 # |
| 174 | 174 |
| 175 # | 175 # |
| 176 # Start the mailer **before** opening the pipe; otherwise a | 176 # Start the mailer **before** opening the pipe; otherwise a |
| 177 # deadlock occurs | 177 # deadlock occurs |
| 178 # | 178 # |
| 179 "$MAILER" -f "${_sender_addr}" "${_recipient_addr}" <${MAILFIFO_STDIN} >${MAILFIFO_STDOUT} & | 179 "$MAILER" -f "${_sender_addr}" "${_recipient_addr}" <"${MAILFIFO_STDIN}" >"${MAILFIFO_STDOUT}" & |
| 180 _pid_mailer=$! | 180 _pid_mailer=$! |
| 181 | 181 |
| 182 exec 3>"${MAILFIFO_STDIN}" | 182 exec 3>"${MAILFIFO_STDIN}" |
| 183 exec 4<"${MAILFIFO_STDOUT}" | 183 exec 4<"${MAILFIFO_STDOUT}" |
| 184 | 184 |
| 206 fi | 206 fi |
| 207 printf "\n" >&3 | 207 printf "\n" >&3 |
| 208 | 208 |
| 209 # preserve leading white space when reading with `read` | 209 # preserve leading white space when reading with `read` |
| 210 _oifs="$IFS" | 210 _oifs="$IFS" |
| 211 IFS=" | 211 IFS=$'\n' |
| 212 " | 212 while read -r _text; do |
| 213 cat "${MAILCONTENT}" | | 213 printf "%s\n" "$_text" >&3 |
| 214 while read _text; do | 214 done <"${MAILCONTENT}" |
| 215 printf "%s\n" "$_text" >&3 | |
| 216 done | |
| 217 # not all mailer recognize this | 215 # not all mailer recognize this |
| 218 # printf ".\n" >&3 | 216 # printf ".\n" >&3 |
| 219 IFS="$_oifs" | 217 IFS="$_oifs" |
| 220 | 218 |
| 221 # close the fd to the pipe: coproc should get EOF and terminate | 219 # close the fd to the pipe: coproc should get EOF and terminate |
| 222 exec 3>&- | 220 exec 3>&- |
| 223 # read eventually remaining stuff from the mailer until EOF | 221 # read eventually remaining stuff from the mailer until EOF |
| 224 IFS='' read _dummy <&4 | 222 IFS='' read -r _dummy <&4 |
| 225 exec 4<&- | 223 exec 4<&- |
| 226 | 224 |
| 227 wait $_pid_mailer | 225 wait $_pid_mailer |
| 228 _rc=$? | 226 _rc=$? |
| 229 | 227 |
| 309 # Collect the mail text from stdin into a temporary file | 307 # Collect the mail text from stdin into a temporary file |
| 310 # | 308 # |
| 311 exec 3>"${MAILCONTENT}" | 309 exec 3>"${MAILCONTENT}" |
| 312 # preserve leading white space when reading with `read` | 310 # preserve leading white space when reading with `read` |
| 313 _oifs="$IFS" | 311 _oifs="$IFS" |
| 314 IFS=" | 312 IFS=$'\n' |
| 315 " | 313 while read -r _text; do |
| 316 while read _text; do | |
| 317 if [ "${_text}" = "." ]; then | 314 if [ "${_text}" = "." ]; then |
| 318 break | 315 break |
| 319 else | 316 else |
| 320 printf "%s\n" "${_text}" >&3 | 317 printf "%s\n" "${_text}" >&3 |
| 321 fi | 318 fi |
