man/unseen.man man/whatnow.man man/whom.man \
test/README $(TESTS) test/inc/deb359167.mbox \
test/inc/fromline.txt test/inc/msgheader.txt test/inc/filler.txt \
- test/inc/md5sums test/post/test-post-common.sh uip/mhmail \
+ test/inc/md5sums test/mhmail/attachment.txt \
+ test/post/test-post-common.sh uip/mhmail \
SPECS/nmh.spec SPECS/build-nmh-cygwin
##
.B mhmail
.RI [ addrs
\&...]
+.RB [ \-attach
+.IR file ]
.RB [ \-body
.IR text ]
.RB [ \-cc
.fi
.RE
.PP
+Note about this example: the
+.B \-attach
+switch causes
+.I MIME-Version
+and
+.I Content-Type
+headers to be added to the message.
+.PP
The
.B \-profile
switch instructs
to send the message. This allows use of the user's context and aliases.
.PP
The
+.B \-attach
+.I file
+switch attaches the specified file to the message. Use of
+.B \-attach
+enables
+.B \-profile
+because
+.B mhmail
+uses
+.B send
+to handle the attachment. It is usually best to enclose the argument
+in quotes to protect it from the shell. The
+.B \-attach
+switch may be given multiple times to add multiple attachments.
+.PP
+The
.B \-nosend
option shows the draft file that would be posted/sent on the command's
standard output but does not post or send it.
dist(1), inc(1), post(8), send(1)
.SH DEFAULTS
+.nf
.RB ` \-send '
+.fi
+.RB ` \-profile' ,
+enabled by default only with
+.B \-attach
.SH CONTEXT
If
mkdir $MH_TEST_DIR/Mail || exit 1
cat > $MH <<EOF || exit 1
Path: ${MH_TEST_DIR}/Mail
+buildmimeproc: ${MH_INST_DIR}${bindir}/mhbuild
libdir: ${MH_LIB_DIR}
mhlproc: ${MH_LIB_DIR}/mhl
moreproc: cat
sed -e 's/^Date:.*/Date:/' \
-e 's/^Resent-Date:.*/Resent-Date:/' \
- -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
+ -e 's/^Message-ID:.*/Message-ID:/' \
+ -e 's/^Content-ID:.*/Content-ID:/' "$actual" > "$actual".nodate
rm -f "$actual"
check "$actual".nodate "$1"
cat >$expected <<EOF
Usage: mhmail [addrs ... [switches]]
switches are:
+ -at(tach) file [-at(tach) file] ...
-b(ody) text
-c(c) addrs ...
-f(rom) addr
[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
+# check -attach
+# Not supported by compiled mhmail.
+cat > "$expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<sender@example.com>
+RCPT TO:<recipient@example.com>
+DATA
+To: recipient@example.com
+From: sender@example.com
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
+Content-ID:
+Date:
+Message-ID:
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="us-ascii"
+
+See how easy it is to add an attachment!
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
+Content-Description: attachment.txt
+Content-Disposition: attachment; filename="attachment.txt"
+
+The future disappears into memory, With only a moment between,
+Forever dwells in that moment, hope is what remains to be seen
+Forever dwells in that moment, hope is what remains to be seen.
+
+------- =_aaaaaaaaaa0--
+.
+QUIT
+EOF
+
+test_mhmail "$expected" \
+ "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
+ -b 'See how easy it is to add an attachment!'
+
+[ ${failed:-0} -eq 0 ] || exit ${failed:-0}
+
+
exit ${failed:-0}
cat >$expected <<EOF
context
.mh_sequences
-$bindir/mhbuild
+$MH_INST_DIR$bindir/mhbuild
$MH_INST_DIR$bindir/refile
700
$bindir/inc
# complete copyright information.
#
# Emulation of compiled mhmail(1), with these differences:
-# * Instead of silently not sending an empty message, notifies user
-# "mhmail: empty message not sent, use -body '' to force."
-# * The compiled mhmail dropped a trailing newline from the -body argument.
+# * Adds -send/-nosend, -header-field, and -attach options.
# * Supports all post(8) (by default, without -profile) or send(1)
# (with -profile) options.
# * Optionally (with -profile) obeys the users profile, including
# AliasFile and send entries.
-# * Adds -send/-nosend and -header-field options.
+# * Instead of silently not sending an empty message, notifies user
+# "mhmail: empty message not sent, use -body '' to force."
+# * The compiled mhmail dropped a trailing newline from the -body argument.
# * Drops support for undocumented -queue option.
-#
-# To do:
-# * add -attach file ... switch
usage='Usage: mhmail [addrs ... [switches]]
switches are:
+ -at(tach) file [-at(tach) file] ...
-b(ody) text
-c(c) addrs ...
-f(rom) addr
else
#### Go through all the switches so we can build the draft.
tolist=
+ attacharg=0
+ attach_send_switch_added=0
body=
bodyarg=0
cclist=
#### ambiguous, so no conflicts with them. And they don't have
#### -b, -c, or -r. For the new switches that compiled mhmail
#### didn't have: let -p indicate mhmail -profile, not send
- #### -port. -send masks the send(1) -send switch.
+ #### -port. -send masks the send(1) -send switch. -attach
+ #### masks the send(1) -attach switch.
+ -at|-att|-atta|-attac|-attach)
+ attacharg=1;
+ use_send=1
+ if [ ${attach_send_switch_added} -eq 0 ]; then
+ #### Override any send -attach switch in user's profile.
+ postsendargs=\
+"${postsendargs:+${postsendargs} }-attach Nmh-Attachment"
+ attach_send_switch_added=1
+ fi
+ ;;
-b|-bo|-bod|-body) bodyarg=1 ;;
-c|-cc) ccarg=1 ;;
-f|-fr|-fro|-from) fromarg=1 ;;
elif [ ${subjectarg} -eq 1 ]; then
subject="${arg}"
subjectarg=0
+ elif [ ${attacharg} -eq 1 ]; then
+ headerfieldlist="${headerfieldlist:+${headerfieldlist}}\
+Nmh-Attachment: ${arg}
+"
+ attacharg=0
elif [ ${headerfieldarg} -eq 1 ]; then
#### It's not strictly necessary to have one space after
#### the : that separates the header field name from the