From 8ba186801a31551de4f12ffd26b617a02b289d32 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 17 Jun 2012 14:35:14 -0500 Subject: [PATCH] Added -resent support to mhmail. It doesn't work with -profile, though. --- man/mhmail.man | 32 +++++++++++++++++++++----------- test/post/test-mhmail | 33 +++++++++++++++++++++++++++++++++ uip/mhmail | 45 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 88 insertions(+), 22 deletions(-) diff --git a/man/mhmail.man b/man/mhmail.man index c1c8149..cf8e73a 100644 --- a/man/mhmail.man +++ b/man/mhmail.man @@ -19,6 +19,7 @@ mhmail \- send or read mail .IR addr ] .RB [ \-subject .IR subject ] +.RB [ \-resent ] [switches\ for .I post \&... | @@ -67,21 +68,20 @@ name of the temporary file as its argument to deliver the message to the specified user. .PP The -.B \-profile -switch instructs -.B mhmail -to use -.B send -instead of -.B post -to send the message. This allows use of the user's context and aliases. -.PP -The .B \-subject .I subject switch can be used to specify the \*(lqSubject:\*(rq field of the message. .PP +The +.B \-resent +switch indicates that the message body is a fully formed message that +will be resent, as +.B dist +would do. For example: +.PP + mhmail u2@example.com -resent < `mhpath cur` +.PP By default, .B mhmail will read the message to be sent from the @@ -117,6 +117,16 @@ will fill\-in the \*(lqSender:\*(rq header correctly. .PP The +.B \-profile +switch instructs +.B mhmail +to use +.B send +instead of +.B post +to send the message. This allows use of the user's context and aliases. +.PP +The .B \-debug option shows the draft file that would be posted/sent and the command that would be used to post/send the draft, but does not post or send @@ -142,7 +152,7 @@ is used. .fi .SH "SEE ALSO" -inc(1), post(8), send(1) +dist(1), inc(1), post(8), send(1) .SH DEFAULTS None diff --git a/test/post/test-mhmail b/test/post/test-mhmail index 08df557..17c9505 100755 --- a/test/post/test-mhmail +++ b/test/post/test-mhmail @@ -56,6 +56,7 @@ test_mhmail () # sed -e 's/^Date:.*/Date:/' \ + -e 's/^Resent-Date:.*/Resent-Date:/' \ -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate rm -f "$actual" @@ -77,6 +78,7 @@ Usage: mhmail [addrs ... [switches]] -c(c) addrs ... -f(rom) addr -s(ubject) text + -r(esent) -pr(ofile) -v(ersion) -h(elp) @@ -578,4 +580,35 @@ test_mhmail "$expected" "-from sender@localhost" -b "here's some text [ ${failed:-0} -eq 0 ] || exit ${failed:-0} +# check -resent +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +Resent-To: recipient@example.com +Resent-From: recipient@example.com +To: recipient@example.com +From: sender@localhost +Date: +Resent-Date: + +please resend this message + +. +QUIT +EOF + +test_mhmail "$expected" "-from recipient@example.com -resent" \ + -b "To: recipient@example.com +From: sender@localhost +Date: Sat Jun 16 18:35:15 -0500 + +please resend this message +" + +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + exit ${failed:-0} diff --git a/uip/mhmail b/uip/mhmail index de2fe4d..30fbbb7 100755 --- a/uip/mhmail +++ b/uip/mhmail @@ -18,7 +18,8 @@ # * Drops support for undocumented -queue option. # # To do: -# * add support for undocumented -resent compiled mhmail switch +# * fix -resent with -profile +# * rename -debug to -nosend and add -send (and note in doc that last one takes) # * add -attach file ... switch usage='Usage: mhmail [addrs ... [switches]] @@ -27,6 +28,7 @@ usage='Usage: mhmail [addrs ... [switches]] -c(c) addrs ... -f(rom) addr -s(ubject) text + -r(esent) -pr(ofile) -v(ersion) -h(elp) @@ -50,6 +52,7 @@ else fromarg=0 subject= subjectarg=0 + resent=0 postsendargs= switcharg=0 use_send=0 @@ -62,15 +65,18 @@ else case "${arg}" in #### Post and send won't accept -f -or -s because they'd be #### ambiguous, so no conflicts with them. And they don't have - #### -b or -c. For the new switches that compiled mhmail didn't - #### have: let -p indicate mhmail -profile, not send -port, and - #### let -d indicate mhmail -debug, not send -draft. + #### -b, -c, or -r. For the new switches that compiled mhmail + #### didn't have: let -p indicate mhmail -profile, not send + #### -port, and let -d indicate mhmail -debug, not send -draft. -b|-bo|-bod|-body) bodyarg=1 ;; -c|-cc) ccarg=1 ;; -d|-de|-deb|-debu|-debug) debug=echo ;; -f|-fr|-fro|-from) fromarg=1 ;; -h|-he|-hel|-help) printf "%s\n" "${usage}"; exit ;; -p|-pr|-pro|-prof|-profi|-profil|-profile) use_send=1 ;; + -resend) printf "mhmail: did you mean -resent instead of -resend?\n" 1>&2 + exit 1 ;; + -r|-re|-res|-rese|-resen|-resent) resent=1 ;; -s|-su|-sub|-subj|-subje|-subjec|-subject) subjectarg=1 ;; -v|-ve|-ver|-vers|-versi|-versio|-version) #### Cheat instead of using autoconf and make to fill in the version. @@ -111,16 +117,15 @@ else fi #### Build header. - header="To: ${tolist} + [ ${resent} -eq 0 ] && prefix= || prefix='Resent-' + header="${prefix}To: ${tolist} " - [ "${cclist}"x = x ] || header="${header}Cc: ${cclist} + [ "${cclist}"x = x ] || header="${header}${prefix}Cc: ${cclist} " - [ "${subject}"x = x ] || header="${header}Subject: ${subject} + [ "${subject}"x = x ] || header="${header}${prefix}Subject: ${subject} "; - [ "${from}"x = x ] || header="${header}From: ${from} + [ "${from}"x = x ] || header="${header}${prefix}From: ${from} "; - header="${header} -" #### Set up a file to supply as a draft to send/post. And set a #### trap to remove it. send moves the file to a backup, so it will @@ -131,6 +136,22 @@ else tmpfilbackup="${tmpdir}/[,#]mhmail$$" trap 'rm -f '"${tmpfil}"' '"${tmpfilbackup}" EXIT + if [ ${resent} -eq 0 ]; then + #### Add blank line after header if not resending. + header="${header} +" + else + if [ "$use_send" -eq 0 ]; then + postsendargs="${postsendargs:+${postsendargs} }-dist" + else + mhdist=1; export mhdist + mhaltmsg=${tmpfil}; export mhaltmsg + #### This doesn't work, I'm not sure about mhaltmsg. + printf "mhmail: -resent not currently supported with -profile\n" + exit 1 + fi + fi + if [ "${body}"x = x ]; then #### First put message header in the file. cat >> handles blank #### lines better than body=`cat`. @@ -167,8 +188,10 @@ else post_or_send="${nmhbindir}/send" fi + status=$? + if $debug "${post_or_send}" "${tmpfil}" ${postsendargs}; then - : + exit ${status} else printf "Letter saved in dead.letter\n" #### exec skips the trap set above. -- 1.7.10.4