From: David Levine Date: Mon, 18 Jun 2012 03:51:51 +0000 (-0500) Subject: mhmail now supports -profile -resend. X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=ebee927145cb7593ea681b21024eff7e9583b062 mhmail now supports -profile -resend. --- diff --git a/man/mhmail.man b/man/mhmail.man index 6bbd8ae..fb271e1 100644 --- a/man/mhmail.man +++ b/man/mhmail.man @@ -171,8 +171,3 @@ context changes occur. With the switch, the context of .B send is used. - -.SH BUGS -.B \-resent -cannot be used with -.BR \-profile . diff --git a/test/post/test-mhmail b/test/post/test-mhmail index ce4d9c6..0d0943e 100755 --- a/test/post/test-mhmail +++ b/test/post/test-mhmail @@ -239,7 +239,8 @@ QUIT EOF test_mhmail "$expected" \ - "-from sender@localhost -cc recipient2@example.com recipient3@example.com recipient4@example.com" '|' message + '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\ +'recipient4@example.com' '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -260,8 +261,7 @@ message QUIT EOF -test_mhmail "$expected" \ - "-from sender@localhost -subject Test" '|' message +test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -287,8 +287,7 @@ message QUIT EOF -test_mhmail "$expected" \ - "-from sender@localhost -profile" '|' message +test_mhmail "$expected" '-from sender@localhost -profile' '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -309,8 +308,8 @@ message QUIT EOF -test_mhmail "$expected" "-from sender@localhost -from sender2@localhost \ --subject Subject1 -subject Subject2" -b message +test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\ +'-subject Subject1 -subject Subject2' -b message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check repeated -body arguments @@ -352,8 +351,8 @@ message QUIT EOF -test_mhmail "$expected" "-from sender@localhost \ --cc cc1@example.com -cc cc2@example.com" -b message +test_mhmail "$expected" \ + '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -377,8 +376,9 @@ message QUIT EOF -test_mhmail "$expected" "-from sender@localhost \ --cc cc1@example.com -subject Test cc2@example.com" -b message +test_mhmail "$expected" \ + '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \ + -b message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -417,7 +417,7 @@ Date: QUIT EOF -test_mhmail "$expected" "-from sender@localhost" '|' '\n' +test_mhmail "$expected" '-from sender@localhost' '|' '\n' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -439,7 +439,7 @@ Date: QUIT EOF -test_mhmail "$expected" "-from sender@localhost" '|' '\n\n\n' +test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -459,7 +459,7 @@ no newline in input QUIT EOF -test_mhmail "$expected" "-from sender@localhost" '|' 'no newline in input' +test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -481,7 +481,7 @@ here's some text QUIT EOF -test_mhmail "$expected" "-from sender@localhost" '|' "here's some text\n\n\n" +test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n" [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -501,7 +501,7 @@ Date: QUIT EOF -test_mhmail "$expected" "-from sender@localhost" -b '' +test_mhmail "$expected" '-from sender@localhost' -b '' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -522,7 +522,7 @@ Date: QUIT EOF -test_mhmail "$expected" "-from sender@localhost" -b ' +test_mhmail "$expected" '-from sender@localhost' -b ' ' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -547,7 +547,7 @@ Date: QUIT EOF -test_mhmail "$expected" "-from sender@localhost" -b ' +test_mhmail "$expected" '-from sender@localhost' -b ' ' @@ -570,7 +570,7 @@ no newline in input QUIT EOF -test_mhmail "$expected" "-from sender@localhost" -b 'no newline in input' +test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -593,7 +593,7 @@ here's some text QUIT EOF -test_mhmail "$expected" "-from sender@localhost" -b "here's some text +test_mhmail "$expected" '-from sender@localhost' -b "here's some text " [ ${failed:-0} -eq 0 ] || exit ${failed:-0} @@ -613,19 +613,76 @@ From: sender@localhost Date: Resent-Date: -please resend this message +please resend this message, #1 +. +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, #1' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + +# check -resent -profile, using stdin +# Not supported by compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: +Resent-To: recipient@example.com +Resent-From: recipient@example.com +Resent-Date: + +please resend this message, #2 . QUIT EOF -test_mhmail "$expected" "-from recipient@example.com -resent" \ - -b "To: recipient@example.com +test_mhmail "$expected" \ + '-from recipient@example.com -resent -profile -nomsgid' \ + '|' 'To: recipient@example.com From: sender@localhost Date: Sat Jun 16 18:35:15 -0500 -please resend this message -" +please resend this message, #2' + +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -resent -profile, using -b +# Not supported by compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: +Resent-To: recipient@example.com +Resent-From: recipient@example.com +Resent-Date: + +please resend this message, #3 +. +QUIT +EOF + +test_mhmail "$expected" \ + '-from recipient@example.com -resent -profile -nomsgid' \ + -b 'To: recipient@example.com +From: sender@localhost +Date: Sat Jun 16 18:35:15 -0500 + +please resend this message, #3' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} diff --git a/uip/mhmail b/uip/mhmail index 57d0f8a..31a21d4 100755 --- a/uip/mhmail +++ b/uip/mhmail @@ -18,7 +18,6 @@ # * Drops support for undocumented -queue option. # # To do: -# * fix -resent with -profile # * add -header-field name:body switch # * add -attach file ... switch @@ -132,35 +131,43 @@ else #### remove that, too. umask 077 tmpdir="${MHTMPDIR:-${TMPDIR:-${TMP:-`${nmhbindir}/mhpath +`}}}" - tmpfil="${tmpdir}/mhmail$$" - tmpfilbackup="${tmpdir}/[,#]mhmail$$" - trap 'rm -f '"${tmpfil}"' '"${tmpfilbackup}" EXIT + tmpfile="${tmpdir}/mhmail$$" + tmpfilebackup="${tmpdir}/[,#]mhmail$$" + tmpfileresent= + message_file= if [ ${resent} -eq 0 ]; then #### Add blank line after header if not resending. header="${header} " + message_file="${tmpfile}" else if [ ${use_send} -eq 0 ]; then postsendargs="${postsendargs:+${postsendargs} }-dist" + message_file="${tmpfile}" else + #### When resending with send, tmpfile will just contain the + #### Resent- header fields. "${tmpfileresent}" will contain + #### the message that is being resent. + tmpfileresent="${tmpdir}/mhmail-resent$$" 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 + mhaltmsg=${tmpfileresent}; export mhaltmsg + message_file="${tmpfileresent}" + printf "" >"${message_file}" || exit 2 fi fi + trap 'rm -f '"${tmpfile}"' '"${tmpfilebackup}"' '"${tmpfileresent}" EXIT + if [ "${body}"x = x ]; then - #### First put message header in the file. cat >> handles blank - #### lines better than body=`cat`. - printf "%s" "${header}" > "${tmpfil}" || exit 1 + #### First put message header in the file. + printf "%s" "${header}" >"${tmpfile}" || exit 2 - tmpfile_size_before=`wc -c "${tmpfil}"` - #### Now grab the body from stdin. - cat >>"${tmpfil}" - tmpfile_size_after=`wc -c "${tmpfil}"` + tmpfile_size_before=`wc -c "${message_file}"` + #### Now grab the body from stdin. cat >> handles blank lines + #### better than body=`cat`. + cat >>"${message_file}" || exit 2 + tmpfile_size_after=`wc -c "${message_file}"` #### Don't allow an empty body (from stdin). Use string #### comparison so we don't have to strip the filename, etc. @@ -170,15 +177,27 @@ else fi #### Add trailing newline to body if it doesn't have one. + if [ `tail -n 1 "${message_file}" | wc -l` -ne 1 ]; then + printf "\n" >>"${message_file}" || exit 2 + fi + else + #### Add trailing newline to body if it doesn't have one. [ `printf "${body}" | tail -n 1 | wc -l` -ne 1 ] && body="${body} " - else - #### Put message header and body in the file. - printf "%s" "${header}${body}" > "${tmpfil}" || exit 1 + + if [ "${tmpfileresent}" ]; then + #### Put just the new message header in the file. + printf "%s" "${header}" >"${tmpfile}" || exit 2 + #### and the body in the file to resend. + printf "${body}" >"${tmpfileresent}" || exit 2 + else + #### Put message header and body in the file. + printf "%s" "${header}${body}" >"${tmpfile}" || exit 2 + fi fi if [ ${sendsw} -eq 0 ]; then - cat "${tmpfil}" + cat "${tmpfile}" else if [ ${use_send} -eq 0 ]; then post_or_send=`${nmhbindir}/mhparam postproc` @@ -186,12 +205,12 @@ else post_or_send="${nmhbindir}/send" fi - if "${post_or_send}" "${tmpfil}" ${postsendargs}; then + if "${post_or_send}" "${tmpfile}" ${postsendargs}; then exit else printf "Letter saved in dead.letter\n" #### exec skips the trap set above. - exec mv "${tmpfil}" dead.letter + exec mv "${tmpfile}" dead.letter fi fi fi