]> diplodocus.org Git - nmh/commitdiff
Added -attach switch to mhmail.
authorDavid Levine <levinedl@acm.org>
Tue, 19 Jun 2012 15:13:28 +0000 (10:13 -0500)
committerDavid Levine <levinedl@acm.org>
Tue, 19 Jun 2012 15:13:28 +0000 (10:13 -0500)
Makefile.am
man/mhmail.man
test/common.sh.in
test/mhmail/test-mhmail
test/mhparam/test-mhparam
uip/mhmail

index 970eb60a54468f7795bc09d7fa2553b87479cab8..3f56a7049079e1650f0d134129ed8f9caa82d622 100644 (file)
@@ -226,7 +226,8 @@ EXTRA_DIST = config/version.sh sbr/sigmsg.awk etc/mts.conf.in etc/sendfiles.in \
             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 \
             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
 
 ##
             SPECS/nmh.spec SPECS/build-nmh-cygwin
 
 ##
index 3abd6d3b049be279b34c6e3d7cf26cb5f40581ff..3b382af276f1bfdb290990fb87d0edbd0830f4f2 100644 (file)
@@ -10,6 +10,8 @@ mhmail \- send or read mail
 .B mhmail
 .RI [ addrs
 \&...]
 .B mhmail
 .RI [ addrs
 \&...]
+.RB [ \-attach
+.IR file ]
 .RB [ \-body
 .IR text ]
 .RB [ \-cc
 .RB [ \-body
 .IR text ]
 .RB [ \-cc
@@ -143,6 +145,14 @@ recipient@example.com
 .fi
 .RE
 .PP
 .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
 The
 .B \-profile
 switch instructs
@@ -154,6 +164,22 @@ instead of
 to send the message.  This allows use of the user's context and aliases.
 .PP
 The
 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.
 .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.
@@ -186,7 +212,12 @@ is used.
 dist(1), inc(1), post(8), send(1)
 
 .SH DEFAULTS
 dist(1), inc(1), post(8), send(1)
 
 .SH DEFAULTS
+.nf
 .RB ` \-send '
 .RB ` \-send '
+.fi
+.RB ` \-profile' ,
+enabled by default only with
+.B \-attach
 
 .SH CONTEXT
 If
 
 .SH CONTEXT
 If
index e5da52c04e77fa31623388a5bf3f7d0bb8ddea87..aa34927091e0d928cdaca9095427f6f50ce55833 100644 (file)
@@ -161,6 +161,7 @@ setup_test ()
   mkdir $MH_TEST_DIR/Mail || exit 1
   cat > $MH <<EOF || exit 1
 Path: ${MH_TEST_DIR}/Mail
   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
 libdir: ${MH_LIB_DIR}
 mhlproc: ${MH_LIB_DIR}/mhl
 moreproc: cat
index 422c647dc959b6669bc3db4caf61f2a46c39ed29..e8fbac8ae3018bb1f335182617757eda7c234435 100755 (executable)
@@ -57,7 +57,8 @@ test_mhmail ()
 
     sed -e 's/^Date:.*/Date:/' \
         -e 's/^Resent-Date:.*/Resent-Date:/' \
 
     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"
     rm -f "$actual"
 
     check "$actual".nodate "$1"
@@ -74,6 +75,7 @@ actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
 cat >$expected <<EOF
 Usage: mhmail [addrs ... [switches]]
   switches are:
 cat >$expected <<EOF
 Usage: mhmail [addrs ... [switches]]
   switches are:
+  -at(tach) file [-at(tach) file] ...
   -b(ody) text
   -c(c) addrs ...
   -f(rom) addr
   -b(ody) text
   -c(c) addrs ...
   -f(rom) addr
@@ -740,4 +742,45 @@ test_mhmail "$expected" \
 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
 
 
 [ ${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}
 exit ${failed:-0}
index cde481c27df03427783dad9391c54929af88822e..a56945ca9ac0bb1af064fa0190a2012a5d247735 100755 (executable)
@@ -79,7 +79,7 @@ AliasFile: aliases"
 cat >$expected <<EOF
 context
 .mh_sequences
 cat >$expected <<EOF
 context
 .mh_sequences
-$bindir/mhbuild
+$MH_INST_DIR$bindir/mhbuild
 $MH_INST_DIR$bindir/refile
 700
 $bindir/inc
 $MH_INST_DIR$bindir/refile
 700
 $bindir/inc
index 235eebac3d49c99fcff0d6df06059f21a9dfaaf7..bcb9bd3caf50d26d410f9ba6589f7cca4ef0d58b 100755 (executable)
@@ -7,21 +7,19 @@
 # complete copyright information.
 #
 # Emulation of compiled mhmail(1), with these differences:
 # 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.
 # * 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.
 # * Drops support for undocumented -queue option.
-#
-# To do:
-# * add -attach file ... switch
 
 usage='Usage: mhmail [addrs ... [switches]]
   switches are:
 
 usage='Usage: mhmail [addrs ... [switches]]
   switches are:
+  -at(tach) file [-at(tach) file] ...
   -b(ody) text
   -c(c) addrs ...
   -f(rom) addr
   -b(ody) text
   -c(c) addrs ...
   -f(rom) addr
@@ -44,6 +42,8 @@ if [ $# -eq 0 ]; then
 else
   #### Go through all the switches so we can build the draft.
   tolist=
 else
   #### Go through all the switches so we can build the draft.
   tolist=
+  attacharg=0
+  attach_send_switch_added=0
   body=
   bodyarg=0
   cclist=
   body=
   bodyarg=0
   cclist=
@@ -69,7 +69,18 @@ else
       #### 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
       #### 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 ;;
       -b|-bo|-bod|-body) bodyarg=1 ;;
       -c|-cc) ccarg=1 ;;
       -f|-fr|-fro|-from) fromarg=1 ;;
@@ -99,6 +110,11 @@ else
          elif [ ${subjectarg} -eq 1 ]; then
            subject="${arg}"
            subjectarg=0
          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
          elif [ ${headerfieldarg} -eq 1 ]; then
            #### It's not strictly necessary to have one space after
            #### the : that separates the header field name from the