.HP 5
.na
.B mhmail
-.RI [ addrs
-\&...]
+.RB [ \-to ]
+.RI addrs
+\&...
.RB [ \-attach
.IR file ]
.RB [ \-body
.RB [ \-send " | " \-nosend ]
.RB [ \-version ]
.RB [ \-help ]
+.PP
+.HP 5
+.B mhmail
+with no arguments is equivalent to
+.B inc
.ad
.SH DESCRIPTION
.B mhmail
.BR nmh .
This program is intended for the use of programs such as
.BR cron ,
-which expect to send mail automatically to various
-users. It is also used by various
+which expect to send mail automatically to various addresses. It is
+also used by various
.B nmh
commands to mail various
error notifications. Although
.PP
When invoked without arguments, it simply invokes
.B inc
-to incorporate new messages from the user's maildrop. When one or more users
-is specified, a message is read from the standard input and spooled to
-a temporary file.
+to incorporate new messages from the user's maildrop.
+.PP
+When one or more addresses are specified, a message is read from the
+standard input and spooled to a temporary file.
.B mhmail
then invokes
-.B post
-with the
-name of the temporary file as its argument to deliver the message to
-the specified user.
+.BR post ,
+by default, with the name of the temporary file as its argument to
+deliver the message to the specified address.
.PP
The
.B \-subject
i.e., if any other switches are supplied. If the
.B \-cc
switch is used, all addresses following it, even if there are
-intervening switches, are placed in the \*(lqcc:\*(rq field.
+intervening switches other than
+.BR \-to ,
+are placed in the \*(lqcc:\*(rq field. The optional
+.B \-to
+switch can appear in front of any addresses to signify their placement
+in the \*(lqTo:\*(rq field. The
+.B \-to
+and
+.B \-cc
+switches may be given multiple times.
.PP
By using
.B \-from
# check -help
# Verified behavior consistent with compiled sendmail.
cat >$expected <<EOF
-Usage: mhmail [addrs ... [switches]]
+Usage: mhmail [-t(o)] addrs ... [switches]
switches are:
-at(tach) file [-at(tach) file] ...
-b(ody) text
-v(ersion)
-hel(p)
and all post(8)/send(1) switches
+ mhmail with no arguments is equivalent to inc
EOF
mhmail -help >$actual 2>&1
esac
# check for missing argument to switches that require them
-for switch in attach body cc from headerfield subject; do
+for switch in attach body cc from headerfield subject to; do
run_test "mhmail recipient -$switch" \
"mhmail: missing argument to -$switch"
done
-for switch in attach body cc from headerfield subject; do
+for switch in attach body cc from headerfield subject to; do
run_test "mhmail recipient -$switch -nosend" \
"mhmail: missing argument to -$switch"
done
-for switch in attach body cc from headerfield subject; do
+for switch in attach body cc from headerfield subject to; do
run_test "mhmail recipient -$switch -server 127.0.0.1" \
"mhmail: missing argument to -$switch"
done
-# check with no arguments
+# check with no switches
# That will just run inc, which we don't want to do anything,
# so tell inc to just display its version.
# Verified same behavior as compiled mhmail.
[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
-# check repeated -from and -subject arguments
+# check repeated -from and -subject switches
# Verified same behavior as compiled mhmail.
cat > "$expected" <<EOF
EHLO nosuchhost.example.com
'-subject Subject1 -subject Subject2' -b message
[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
-# check repeated -body arguments
+# check repeated -body switches
# Verified same behavior as compiled mhmail.
cat > "$expected" <<EOF
EHLO nosuchhost.example.com
[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
-# check multiple -cc arguments
+# check multiple -cc switches
# Verified same behavior as compiled mhmail.
cat > "$expected" <<EOF
EHLO nosuchhost.example.com
[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
+# check -cc switch followed by -to switch
+# Verified same behavior as compiled mhmail.
+cat > "$expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<sender@localhost>
+RCPT TO:<recipient@example.com>
+RCPT TO:<recipient2@example.com>
+RCPT TO:<cc1@example.com>
+DATA
+To: recipient@example.com, recipient2@example.com
+Cc: cc1@example.com
+Subject: Test
+From: sender@localhost
+Date:
+
+message
+.
+QUIT
+EOF
+
+test_mhmail "$expected" \
+ "-from sender@localhost -cc cc1@example.com -subject Test \
+ -to recipient2@example.com" \
+ -b message
+[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
+
+
# check with no newline on stdin
# Shows different behavior than compiled mhmail, which was silent in this case.
cat > "$expected" <<EOF
#
# Emulation of compiled mhmail(1), with these differences:
# * Adds -send/-nosend, -headerfield, and -attach options.
+# * Adds optional -to switch for recipient addresses.
# * Supports all post(8) (by default, without -profile) or send(1)
# (with -profile) options.
# * Optionally (with -profile) obeys the users profile, including
# * The compiled mhmail dropped a trailing newline from the -body argument.
# * Drops support for undocumented -queue option.
-usage='Usage: mhmail [addrs ... [switches]]
+usage='Usage: mhmail [-t(o)] addrs ... [switches]
switches are:
-at(tach) file [-at(tach) file] ...
-b(ody) text
-nose(nd)
-v(ersion)
-hel(p)
- and all post(8)/send(1) switches'
+ and all post(8)/send(1) switches
+ mhmail with no arguments is equivalent to inc'
bindir=`dirname $0`
nmhbindir=`cd "${bindir}" && pwd`
printf "mhmail: missing argument to -headerfield\n"; exit 1
elif [ ${subjectarg} -eq 1 ]; then
printf "mhmail: missing argument to -subject\n"; exit 1
+ elif [ ${toarg} -eq 1 ]; then
+ printf "mhmail: missing argument to -to\n"; exit 1
fi
}
else
#### Go through all the switches so we can build the draft.
tolist= ## To: addresses
+ toarg=0 ## whether currently handling -to
attacharg=0 ## whether currently handling -attach
attach_send_switch_added=0 ## whether added "-attach Nmh-Attachment" switch
body= ## contents of the message body
-r|-re|-res|-rese|-resen|-resent) mhmailswitch=1; resent=1 ;;
-se|-sen|-send) mhmailswitch=1; sendsw=1 ;;
-su|-sub|-subj|-subje|-subjec|-subject) mhmailswitch=1; subjectarg=1 ;;
+ -t|-to) toarg=1; ccarg=0 ;;
-v|-ve|-ver|-vers|-versi|-versio|-version)
#### Cheat instead of using autoconf and make to fill in the version.
"${nmhbindir}"/mhpath -v | sed 's/mhpath/mhmail/'; exit ;;
elif [ ${post_send_switch_arg} -eq 1 ]; then
postsendargs="${postsendargs:+${postsendargs} }${arg}"
elif [ ${ccarg} -eq 1 ]; then
- #### Never reset ccarg to 0, for compatibilty with compiled mhmail.
+ #### ccarg can only be reset to 0 by -to.
cclist="${cclist:+${cclist}, }${arg}"
else
#### An address.
tolist="${tolist:+${tolist}, }${arg}"
+ toarg=0
fi ;;
esac
done