- [ "${body}"x = x ] && body=`cat`
- #### Don't allow an empty body (from stdin).
- [ "${body}"x = x ] && exit 1
+ if [ "${body}"x = x ]; then
+ #### This will lose any trailing newline(s), so we can't
+ #### send the message when stdin contains only newlines.
+ body=`cat`
+
+ #### Don't allow an empty body (from stdin).
+ if [ "${body}"x = x ]; then
+ printf "empty body, message not sent\n"
+ exit 1
+ fi
+
+ #### Add trailing newline to body if it doesn't have one.
+ [ `printf "${body}" | tail -n 1 | wc -l` -ne 1 ] && body="${body}
+"
+ fi