mcom: use printf instead of echo

Fixes #19.
pull/22/head
Leah Neukirchen 7 years ago
parent a27ba3370c
commit f771d062a5

57
mcom

@ -14,7 +14,7 @@ msgid() {
} }
msgdate() { msgdate() {
echo -n "Date: " printf 'Date: '
mdate mdate
} }
@ -35,59 +35,56 @@ if [ -z "$outbox" ]; then
else else
draft="$(true | mdeliver -v -c -XD "$outbox")" draft="$(true | mdeliver -v -c -XD "$outbox")"
if [ -z "$draft" ]; then if [ -z "$draft" ]; then
echo "$0: failed to create draft in outbox $outbox." 1>&2 printf '%s\n' "$0: failed to create draft in outbox $outbox." 1>&2
exit 1 exit 1
fi fi
draftmime="$(echo $draft | sed 's,\(.*\)/cur/,\1/tmp/mime-,')" draftmime="$(printf '%s\n' "$draft" | sed 's,\(.*\)/cur/,\1/tmp/mime-,')"
fi fi
{ {
case "$0" in case "$0" in
*mcom*) *mcom*)
echo -n "To: " printf 'To: '
printf '%s\n' "$@" | commajoin printf '%s\n' "$@" | commajoin
echo "Cc: " printf '%s: \n' Cc Bcc Subject
echo "Bcc: "
echo "Subject: "
from=$(mhdr -h local-mailbox "$MBLAZE/profile") from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ "$from" ] && echo "From: $from" [ "$from" ] && printf 'From: %s\n' "$from"
cat "$MBLAZE/headers" 2>/dev/null cat "$MBLAZE/headers" 2>/dev/null
msgid msgid
msgdate msgdate
echo printf '\n\n'
echo
;; ;;
*mrep*) *mrep*)
[ "$#" -eq 0 ] && set -- . [ "$#" -eq 0 ] && set -- .
ng=$(mhdr -h newsgroups "$1") ng=$(mhdr -h newsgroups "$1")
if [ "$ng" ]; then if [ "$ng" ]; then
echo "Newsgroups: $ng" printf 'Newsgroups: %s\n' "$ng"
else else
to=$(mhdr -h reply-to "$1") to=$(mhdr -h reply-to "$1")
[ -z "$to" ] && to=$(mhdr -h from "$1") [ -z "$to" ] && to=$(mhdr -h from "$1")
echo "To: $to" printf 'To: %s\n' "$to"
echo "Cc: $(mhdr -d -A -h to:cc: "$1" | commajoin)" printf 'Cc: %s\n' "$(mhdr -d -A -h to:cc: "$1" | commajoin)"
echo "Bcc: " printf 'Bcc: \n'
fi fi
echo "Subject: Re: $(mscan -f '%S' "$1")" printf 'Subject: Re: %s\n' "$(mscan -f '%S' "$1")"
from=$(mhdr -h local-mailbox "$MBLAZE/profile") from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ "$from" ] && echo "From: $from" [ "$from" ] && printf 'From: %s\n' "$from"
cat "$MBLAZE/headers" 2>/dev/null cat "$MBLAZE/headers" 2>/dev/null
mid=$(mhdr -h message-id "$1") mid=$(mhdr -h message-id "$1")
if [ "$mid" ]; then if [ "$mid" ]; then
echo -n "References:" printf 'References: '
{ {
mhdr -h references "$1" mhdr -h references "$1"
printf "%s\n" "$mid" printf '%s\n' "$mid"
} | reffmt } | reffmt
echo "In-Reply-To: $mid" printf 'In-Reply-To: %s\n' "$mid"
fi fi
msgid msgid
msgdate msgdate
echo printf '\n'
mquote "$1" mquote "$1"
echo printf '\n'
esac esac
if [ -f "$MBLAZE/signature" ]; then if [ -f "$MBLAZE/signature" ]; then
@ -122,11 +119,11 @@ while :; do
fi fi
exit 0 exit 0
else else
echo "mcom: $sendmail failed, kept draft $draft" printf '%s\n' "mcom: $sendmail failed, kept draft $draft"
exit 2 exit 2
fi fi
else else
echo "mcom: re-run mmime first." printf 'mcom: re-run mmime first.\n'
c= c=
fi fi
else else
@ -139,17 +136,17 @@ while :; do
fi fi
exit 0 exit 0
else else
echo "mcom: $sendmail failed, kept draft $draft" printf '%s\n' "mcom: $sendmail failed, kept draft $draft"
exit 2 exit 2
fi fi
else else
echo "mcom: message needs to be MIME-encoded first." printf '%s\n' "mcom: message needs to be MIME-encoded first."
c= c=
fi fi
fi fi
;; ;;
c|cancel) c|cancel)
echo "mcom: cancelled draft $draft" printf '%s\n' "mcom: cancelled draft $draft"
exit 1 exit 1
;; ;;
m|mime) m|mime)
@ -158,9 +155,9 @@ while :; do
' '
msed '/attach/d' $draft msed '/attach/d' $draft
for f in $(mhdr -M -h attach $draft); do for f in $(mhdr -M -h attach $draft); do
echo "#$(file -Lbi $f | sed 's/ //g') $f" printf '#%s %s\n' "$(file -Lbi $f | sed 's/ //g')" "$f"
done done
) | tee /tmp/v | mmime >$draftmime ) | mmime >$draftmime
mshow -t $draftmime mshow -t $draftmime
c= c=
;; ;;
@ -174,13 +171,13 @@ while :; do
rm -i $draft rm -i $draft
if ! [ -f $draft ]; then if ! [ -f $draft ]; then
rm -f $draftmime rm -f $draftmime
echo "mcom: deleted draft $draft" printf '%s\n' "mcom: deleted draft $draft"
exit 0 exit 0
fi fi
c= c=
;; ;;
*) *)
echo -n "What now? ([s]end, [c]ancel, [d]elete, [e]dit, [m]ime) " printf 'What now? ([s]end, [c]ancel, [d]elete, [e]dit, [m]ime) '
read -r c read -r c
;; ;;
esac esac

Loading…
Cancel
Save