From c00afe1f1f6d73712b705aa09e919e8e51503bcd Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 13 Jun 2012 22:16:46 -0500 Subject: [PATCH 01/16] Removed another faceproc relic. --- test/mhparam/test-mhparam | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/mhparam/test-mhparam b/test/mhparam/test-mhparam index 7c9bba23..b94b9de7 100755 --- a/test/mhparam/test-mhparam +++ b/test/mhparam/test-mhparam @@ -32,7 +32,6 @@ Usage: mhparam [profile-components] [switches] -help EOF -# check -help mhparam -help >$actual 2>&1 check $expected $actual @@ -132,7 +131,7 @@ libdir >$actual 2>&1 check $expected $actual #### This exits with non-zero status, so let run_test squash that: -run_test 'mhparam faceproc formatproc rmmproc' '' +run_test 'mhparam formatproc rmmproc' '' #### Test sbackup separately because it's only passed as a -D compile option. case `mhparam sbackup` in -- 2.48.1 From f087c81dc5221b9e9610462584ee6bfaaa18155d Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 13 Jun 2012 22:18:43 -0500 Subject: [PATCH 02/16] Removed unnecessary comment. --- test/mhpath/test-mhpath | 1 - 1 file changed, 1 deletion(-) diff --git a/test/mhpath/test-mhpath b/test/mhpath/test-mhpath index 9bb1207a..a9aeee1a 100755 --- a/test/mhpath/test-mhpath +++ b/test/mhpath/test-mhpath @@ -28,7 +28,6 @@ Usage: mhpath [+folder] [msgs] [switches] -help EOF -# check -help mhpath -help > $actual 2>&1 check $expected $actual -- 2.48.1 From 89a6090f08e6d28599f5b55e3249a48f7af81c67 Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 13 Jun 2012 22:19:19 -0500 Subject: [PATCH 03/16] Added mhmail.in. start of a replacement for compiled mhmail. --- uip/mhmail.in | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100755 uip/mhmail.in diff --git a/uip/mhmail.in b/uip/mhmail.in new file mode 100755 index 00000000..d2d9d267 --- /dev/null +++ b/uip/mhmail.in @@ -0,0 +1,137 @@ +#! /bin/sh +# +# mhmail.c -- simple mail program +# +# This code is Copyright (c) 2012, by the authors of nmh. See the +# COPYRIGHT file in the root directory of the nmh distribution for +# complete copyright information. +# +# Emulation of compiled mhmail(1) using nmh send(1) or post(8). +# Differences from compiled mhmail: +# * Supports all send(1) (with -profile) or post(8) (without -profile) options. +# * Optionally (with -profile) obeys the users profile, including +# AliasFile and send entries. +# * Adds -debug option for debugging (sending, not incorporating new mail). +# +# To do: +# * update mhmail man page +# * add mhmail test +# * integrate into autoconf +# * support undocumented mhmail options? + +usage='Usage: mhmail [addrs ... [switches]] + switches are: + -b(ody) text + -c(c) addrs ... + -f(rom) addr + -s(ubject) text + -pr(ofile) + -v(ersion) + -h(elp) + -d(ebug) + and all send(1)/post(8) switches' + +#### Use autoconf to fill in bindir. +nmhbindir=@bindir@ + +#### Or if configure hasn't been run yet, figure out nmhbindir at runtime. +case ${nmhbindir} in + @*@) nmhbindir=`dirname $0` ;; +esac + +if [ $# -eq 0 ]; then + #### Emulate mhmail for reading mail. + exec ${nmhbindir}/inc +else + #### Go through all the switches so we can build the draft. + tolist= + body= + bodyarg=0 + cclist= + ccarg=0 + havefrom=0 + header= + otherarg=0 + sendpostargs= + switcharg=0 + use_send=0 + debug= + for arg in "$@"; do + case ${arg} in + -*) switcharg=0 + esac + + case ${arg} in + #### Send and post wouldn'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|-bo|-bod|-body) bodyarg=1 ;; + -c|-cc) ccarg=1 ;; + -d|-de|-deb|-debu|-debug) debug=echo ;; + -f|-fr|-fro|-from) header="${header}From:"; otherarg=1; havefrom=1 ;; + -h|-he|-hel|-help) printf "%s\n" "${usage}"; exit ;; + -p|-pr|-pro|-prof|-profi|-profil|-profile) use_send=1 ;; + -s|-su|-sub|-subj|-subje|-subjec|-subject) + header="${header}Subject:"; otherarg=1 ;; + -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 ;; + -*) sendpostargs="${sendpostargs:+${sendpostargs} }${arg}"; switcharg=1 ;; + *) if [ ${ccarg} -eq 1 ]; then + cclist="${cclist:+${cclist}, }${arg}"; ccarg=0 + elif [ ${bodyarg} -eq 1 ]; then + body=${arg}; bodyarg=0 + elif [ ${otherarg} -eq 1 ]; then + #### Always end ${header} with a newline. + header="${header:+${header} }${arg} +"; otherarg=0 + elif [ ${switcharg} -eq 1 ]; then + sendpostargs="${sendpostargs:+${sendpostargs} }${arg}" + else + #### An address. + tolist="${tolist:+${tolist}, }${arg}" + fi + esac + done + + #### Check for at least one address and -from. + if [ "${tolist}"x = x ]; then + printf "mhmail: usage: mhmail addrs ... [switches]\n"; exit 1 + fi + if [ "${havefrom}" = 0 ]; then + nmhlibdir=`${nmhbindir}/mhparam libdir` + header="${header:+${header} +}From: "`${nmhlibdir}/ap -format '%(localmbox)' 0`" +" + fi + + #### Set up a tmpfil and trap to remove it. send moves the file to a backup. + tmpdir=${MHTMPDIR:-${TMPDIR:-${TMP:-`${nmhbindir}/mhpath +`}}} + tmpfil=${tmpdir}/mhmail$$ + tmpfilbackup=${tmpdir}/[,#]mhmail$$ + trap "rm -f ${tmpfil} ${tmpfilbackup}" EXIT + + #### Put message header and body in file to supply as draft to + #### send/post. ${header} always ends with a newline, so this adds + #### the blank that separates the body. + umask 077 + printf "%s\n" "To: ${tolist} +Cc: ${cclist} +${header} +${body}" > ${tmpfil} || exit 1 + + if [ "${debug}" ]; then + printf "%s:\n" `ls -1 ${tmpfil}` + cat ${tmpfil} + fi + + if [ "$use_send" -eq 1 ]; then + send_or_post="${nmhbindir}/send" + else + send_or_post="${nmhlibdir:=`${nmhbindir}/mhparam libdir`}/post" + fi + + $debug ${send_or_post} ${tmpfil} ${sendpostargs} +fi -- 2.48.1 From 68d4260ee4aa0a6aa5f8aada02183e9f8b97f48d Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 13 Jun 2012 22:32:46 -0500 Subject: [PATCH 04/16] Removed newline before generated From:. --- uip/mhmail.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uip/mhmail.in b/uip/mhmail.in index d2d9d267..809668aa 100755 --- a/uip/mhmail.in +++ b/uip/mhmail.in @@ -102,8 +102,8 @@ else fi if [ "${havefrom}" = 0 ]; then nmhlibdir=`${nmhbindir}/mhparam libdir` - header="${header:+${header} -}From: "`${nmhlibdir}/ap -format '%(localmbox)' 0`" + header="${header:+${header}}From: "\ +`${nmhlibdir}/ap -format '%(localmbox)' 0`" " fi -- 2.48.1 From 7bd4d02e13dbd5d649482a622be5734f395f3180 Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 13 Jun 2012 22:59:05 -0500 Subject: [PATCH 05/16] Added support to mhmail.in to read message from stdin. --- uip/mhmail.in | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uip/mhmail.in b/uip/mhmail.in index 809668aa..2caea10c 100755 --- a/uip/mhmail.in +++ b/uip/mhmail.in @@ -8,7 +8,8 @@ # # Emulation of compiled mhmail(1) using nmh send(1) or post(8). # Differences from compiled mhmail: -# * Supports all send(1) (with -profile) or post(8) (without -profile) 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 -debug option for debugging (sending, not incorporating new mail). @@ -107,6 +108,11 @@ else " fi + #### If no -body, read message from stdin the easy way. + if [ "${body}"x = x ]; then + body=`cat` + fi + #### Set up a tmpfil and trap to remove it. send moves the file to a backup. tmpdir=${MHTMPDIR:-${TMPDIR:-${TMP:-`${nmhbindir}/mhpath +`}}} tmpfil=${tmpdir}/mhmail$$ -- 2.48.1 From 1888a6885e0c4049755578814462cad4259e85df Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 13 Jun 2012 23:12:22 -0500 Subject: [PATCH 06/16] Support empty message body in mhmail.in the same way as in mhmail. --- uip/mhmail.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/uip/mhmail.in b/uip/mhmail.in index 2caea10c..56bcac00 100755 --- a/uip/mhmail.in +++ b/uip/mhmail.in @@ -84,6 +84,9 @@ else cclist="${cclist:+${cclist}, }${arg}"; ccarg=0 elif [ ${bodyarg} -eq 1 ]; then body=${arg}; bodyarg=0 + #### Allow -body "" by using just a newline for the body. + [ "${body}"x = x ] && body=" +" elif [ ${otherarg} -eq 1 ]; then #### Always end ${header} with a newline. header="${header:+${header} }${arg} @@ -109,9 +112,9 @@ else fi #### If no -body, read message from stdin the easy way. - if [ "${body}"x = x ]; then - body=`cat` - fi + [ "${body}"x = x ] && body=`cat` + #### Don't allow an empty body (from stdin). + [ "${body}"x = x ] && exit 1 #### Set up a tmpfil and trap to remove it. send moves the file to a backup. tmpdir=${MHTMPDIR:-${TMPDIR:-${TMP:-`${nmhbindir}/mhpath +`}}} -- 2.48.1 From 436e6b477fa6dabe40404c84334e148b49682708 Mon Sep 17 00:00:00 2001 From: Alexander Zangerl Date: Thu, 14 Jun 2012 07:31:40 -0500 Subject: [PATCH 07/16] The base64-decoder doesn't work on 64-bit big-endian architectures: mhstore and co. write files of the correct length but which consist only of \0s. The culprit is uip/mhparse.c, which contains a pretty ugly base64 decoder (in two places). that thing allocates a "long int" as a container for the 24 bits that you get from four base-64 chars. the container is then accessed both as a single entity and as a byte array, which naturally depends on how wide the long int is and in what order things end up in there. The code distinguishes between big- and little-endian systems but wrongly assumes that sizeof(long int) == 4, which isn't universally true (quel surprise...). The attached patch fixes the issue, but in the long run we should insist on posix and use a64l(). --- uip/mhparse.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/uip/mhparse.c b/uip/mhparse.c index 4c3a1946..91cc4116 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -1737,10 +1737,15 @@ openBase64 (CT ct, char **file) CE ce; MD5_CTX mdContext; + /* the decoder works on the least-significant three bytes of the bits integer, + but their position in memory depend on both endian-ness and size of + long int... for little-endian architectures the size is irrelevant, for + big-endian archs it's crucial... ideally we'd adopt posix and use a64l instead + of this mess. */ b = (unsigned char *) &bits; - b1 = &b[endian > 0 ? 1 : 2]; - b2 = &b[endian > 0 ? 2 : 1]; - b3 = &b[endian > 0 ? 3 : 0]; + b1 = &b[endian > 0 ? sizeof(bits)==8?5:1 : 2]; + b2 = &b[endian > 0 ? sizeof(bits)==8?6:2 : 1]; + b3 = &b[endian > 0 ? sizeof(bits)==8?7:3 : 0]; ce = ct->c_cefile; if (ce->ce_fp) { @@ -2825,10 +2830,16 @@ readDigest (CT ct, char *cp) unsigned char *dp, value, *ep; unsigned char *b, *b1, *b2, *b3; - b = (unsigned char *) &bits, - b1 = &b[endian > 0 ? 1 : 2], - b2 = &b[endian > 0 ? 2 : 1], - b3 = &b[endian > 0 ? 3 : 0]; + /* the decoder works on the least-significant three bytes of the bits integer, + but their position in memory depend on both endian-ness and size of + long int... for little-endian architectures the size is irrelevant, for + big-endian archs it's crucial... ideally we'd adopt posix and use a64l instead + of this mess. */ + b = (unsigned char *) &bits; + b1 = &b[endian > 0 ? sizeof(bits)==8?5:1 : 2]; + b2 = &b[endian > 0 ? sizeof(bits)==8?6:2 : 1]; + b3 = &b[endian > 0 ? sizeof(bits)==8?7:3 : 0]; + bitno = 18; bits = 0L; skip = 0; -- 2.48.1 From 5a2a69e9c6ce8d763584808c31ecf47d74a52b94 Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 14 Jun 2012 08:30:30 -0500 Subject: [PATCH 08/16] Added etcdir and libdir. And added mention that component name matching is case-insensitive. --- man/mhparam.man | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/man/mhparam.man b/man/mhparam.man index 93d9c902..82b343ce 100644 --- a/man/mhparam.man +++ b/man/mhparam.man @@ -16,9 +16,10 @@ mhparam \- print nmh profile and context components .ad .SH DESCRIPTION .B mhparam -writes the value of the specified profile component to the -standard output separated by newlines. If the profile component is not -present, the default value (or nothing if there is no default) is printed. +writes the value of the specified profile component to the standard +output separated by newlines. Component name matching is +case-insensitive. If the profile component is not present, the +default value (or nothing if there is no default) is printed. .PP If the switch .B \-component @@ -42,6 +43,13 @@ If is specified, then all components in the nmh profile are displayed and other arguments are ignored. .PP +The locations of two nmh install directories are also available +through +.BR mhparam : +.I etcdir +and +.IR libdir . +.PP Examples: .PP .RS 5 @@ -67,6 +75,12 @@ rmmproc % mhparam path nonexistent context Path: Mail context: context + +% mhparam etcdir +%etcdir% + +% mhparam libdir +%libdir% .fi .RE .PP -- 2.48.1 From ebbb13923f482d26c7910b0005f0d238c83b6b37 Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 14 Jun 2012 08:35:14 -0500 Subject: [PATCH 09/16] If post/send fail, save the draft in dead.letter, the same as compiled mhmail. --- uip/mhmail.in | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/uip/mhmail.in b/uip/mhmail.in index 56bcac00..0e5713c2 100755 --- a/uip/mhmail.in +++ b/uip/mhmail.in @@ -6,7 +6,7 @@ # COPYRIGHT file in the root directory of the nmh distribution for # complete copyright information. # -# Emulation of compiled mhmail(1) using nmh send(1) or post(8). +# Emulation of compiled mhmail(1) using nmh post(8) or send(1). # Differences from compiled mhmail: # * Supports all post(8) (by default, without -profile) or send(1) # (with -profile) options. @@ -30,7 +30,7 @@ usage='Usage: mhmail [addrs ... [switches]] -v(ersion) -h(elp) -d(ebug) - and all send(1)/post(8) switches' + and all post(8)/send(1) switches' #### Use autoconf to fill in bindir. nmhbindir=@bindir@ @@ -53,7 +53,7 @@ else havefrom=0 header= otherarg=0 - sendpostargs= + postsendargs= switcharg=0 use_send=0 debug= @@ -63,7 +63,7 @@ else esac case ${arg} in - #### Send and post wouldn't accept -f -or -s because they'd be + #### 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 @@ -79,7 +79,7 @@ else -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 ;; - -*) sendpostargs="${sendpostargs:+${sendpostargs} }${arg}"; switcharg=1 ;; + -*) postsendargs="${postsendargs:+${postsendargs} }${arg}"; switcharg=1 ;; *) if [ ${ccarg} -eq 1 ]; then cclist="${cclist:+${cclist}, }${arg}"; ccarg=0 elif [ ${bodyarg} -eq 1 ]; then @@ -92,7 +92,7 @@ else header="${header:+${header} }${arg} "; otherarg=0 elif [ ${switcharg} -eq 1 ]; then - sendpostargs="${sendpostargs:+${sendpostargs} }${arg}" + postsendargs="${postsendargs:+${postsendargs} }${arg}" else #### An address. tolist="${tolist:+${tolist}, }${arg}" @@ -126,21 +126,27 @@ else #### send/post. ${header} always ends with a newline, so this adds #### the blank that separates the body. umask 077 - printf "%s\n" "To: ${tolist} + printf "%s" "To: ${tolist} Cc: ${cclist} ${header} ${body}" > ${tmpfil} || exit 1 if [ "${debug}" ]; then printf "%s:\n" `ls -1 ${tmpfil}` - cat ${tmpfil} + cat "${tmpfil}" fi - if [ "$use_send" -eq 1 ]; then - send_or_post="${nmhbindir}/send" + if [ "$use_send" -eq 0 ]; then + post_or_send="${nmhlibdir:=`${nmhbindir}/mhparam libdir`}/post" else - send_or_post="${nmhlibdir:=`${nmhbindir}/mhparam libdir`}/post" + post_or_send="${nmhbindir}/send" fi - $debug ${send_or_post} ${tmpfil} ${sendpostargs} + if $debug ${post_or_send} ${tmpfil} ${postsendargs}; then + : + else + #### exec disables the trap set above. + printf "Letter saved in dead.letter\n" + exec mv ${tmpfil} dead.letter + fi fi -- 2.48.1 From 1a28128fdeeeeb9152c3a7289c638e465853d489 Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 14 Jun 2012 08:54:35 -0500 Subject: [PATCH 10/16] If heirloom shell is in /usr/lib/heirloom/5bin/sh, use it to run tests. --- docs/contrib/build_nmh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/contrib/build_nmh b/docs/contrib/build_nmh index e367da5b..335e0421 100755 --- a/docs/contrib/build_nmh +++ b/docs/contrib/build_nmh @@ -278,6 +278,15 @@ if [ $status -eq 0 ]; then status=$? if [ $status -eq 0 ]; then + if [ "${TESTS_SHELL}"x = x ]; then + #### Bonus: use heirloom shell to test, if available, and if + #### TESTS_SHELL hadn't already been set. + heirloom_shell=/usr/lib/heirloom/5bin/sh + if [ -x "${heirloom_shell}" ]; then + TESTS_SHELL="${heirloom_shell}"; export TESTS_SHELL + fi + fi + [ $verbose -ge 1 ] && echo testing . . . checkoutput=`make $check 2>>$logfile` status=$? -- 2.48.1 From 2af0f6c0e0f7f5ee65cd156a6e8af065618f902d Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 14 Jun 2012 09:10:23 -0500 Subject: [PATCH 11/16] Documented mhparam -debug option. --- man/mhparam.man | 15 +++++++++++---- test/mhparam/test-mhparam | 2 +- uip/mhparam.c | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/man/mhparam.man b/man/mhparam.man index 82b343ce..4326d13d 100644 --- a/man/mhparam.man +++ b/man/mhparam.man @@ -13,6 +13,7 @@ mhparam \- print nmh profile and context components .RB [ \-component " | " \-nocomponent ] .RB [ \-version ] .RB [ \-help ] +.RB [ \-debug ] .ad .SH DESCRIPTION .B mhparam @@ -43,12 +44,18 @@ If is specified, then all components in the nmh profile are displayed and other arguments are ignored. .PP -The locations of two nmh install directories are also available -through -.BR mhparam : +.BR mhparam +can provide other information, such as +the locations of the nmh .I etcdir and -.IR libdir . +.I libdir +install directories and all +.I proc +settings. The +.B \-debug +switch displays all such other information available from +.BR mhparam . .PP Examples: .PP diff --git a/test/mhparam/test-mhparam b/test/mhparam/test-mhparam index b94b9de7..087be8d4 100755 --- a/test/mhparam/test-mhparam +++ b/test/mhparam/test-mhparam @@ -161,7 +161,7 @@ mhparam path context nonexistent1 nonexistent2 nonexistent3 >/dev/null run_test "echo $?" 3 set -e -# mhparam -debug (undocumented) +# mhparam -debug # Some of its output depends on configure options, so don't bother to # check for correctness here. mhparam -debug >/dev/null diff --git a/uip/mhparam.c b/uip/mhparam.c index 53a25238..d2603522 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -29,7 +29,7 @@ static struct swit switches[] = { #define HELPSW 4 { "help", 0 }, #define DEBUGSW 5 - { "debug", -5 }, + { "debug", 5 }, { NULL, 0 } }; -- 2.48.1 From 3dccb685fb1b879e8910e8732e748b22e7ff8dc7 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Thu, 14 Jun 2012 10:33:21 -0400 Subject: [PATCH 12/16] Make the base64 encoder endian-agnostic, and remove the function set_endian() since it's no longer needed. --- h/prototypes.h | 1 - uip/mhbuild.c | 2 -- uip/mhbuildsbr.c | 2 -- uip/mhlist.c | 2 -- uip/mhmisc.c | 17 ---------------- uip/mhn.c | 2 -- uip/mhparse.c | 50 +++++++++++++++--------------------------------- uip/mhshow.c | 2 -- uip/mhstore.c | 2 -- uip/mhtest.c | 2 -- uip/viamail.c | 2 -- 11 files changed, 15 insertions(+), 69 deletions(-) diff --git a/h/prototypes.h b/h/prototypes.h index 914036c8..9c4b208c 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -155,7 +155,6 @@ int mhlsbr(int, char **, FILE *(*)(char *)); int distout (char *, char *, char *); void replout (FILE *, char *, char *, struct msgs *, int, int, char *, char *, char *, int); -void set_endian(void); int sc_hardcopy(void); int sc_length(void); int sc_width(void); diff --git a/uip/mhbuild.c b/uip/mhbuild.c index a4cce1c1..e8e74231 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -254,8 +254,6 @@ main (int argc, char **argv) compfile = cp; } - set_endian (); - /* * Check if we've specified an additional profile */ diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 4a2c70c7..00a94083 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -41,8 +41,6 @@ extern int listsw; extern int rfc934sw; extern int contentidsw; -extern int endian; /* mhmisc.c */ - /* cache policies */ extern int rcachesw; /* mhcachesbr.c */ extern int wcachesw; /* mhcachesbr.c */ diff --git a/uip/mhlist.c b/uip/mhlist.c index 72b91d1d..021a4b20 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -244,8 +244,6 @@ do_cache: parts[npart] = NULL; types[ntype] = NULL; - set_endian (); - /* Check for public cache location */ if ((cache_public = context_find (nmhcache)) && *cache_public != '/') cache_public = NULL; diff --git a/uip/mhmisc.c b/uip/mhmisc.c index e8a30ace..86b8ad80 100644 --- a/uip/mhmisc.c +++ b/uip/mhmisc.c @@ -23,7 +23,6 @@ int ntype = 0; char *parts[NPARTS + 1]; char *types[NTYPES + 1]; -int endian = 0; /* little or big endian */ int userrs = 0; static char *errs = NULL; @@ -77,22 +76,6 @@ type_ok (CT ct, int sP) } -void -set_endian (void) -{ - union { - long l; - char c[sizeof(long)]; - } un; - - un.l = 1; - endian = un.c[0] ? -1 : 1; - if (debugsw) - fprintf (stderr, "%s endian architecture\n", - endian > 0 ? "big" : "little"); -} - - int make_intermediates (char *file) { diff --git a/uip/mhn.c b/uip/mhn.c index 64a7fc41..65e78d31 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -429,8 +429,6 @@ do_cache: parts[npart] = NULL; types[ntype] = NULL; - set_endian (); - /* * Check if we've specified an additional profile */ diff --git a/uip/mhparse.c b/uip/mhparse.c index 91cc4116..25bbad75 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -22,8 +22,6 @@ extern int debugsw; -extern int endian; /* mhmisc.c */ - extern pid_t xpid; /* mhshowsbr.c */ /* cache policies */ @@ -1728,8 +1726,8 @@ openBase64 (CT ct, char **file) { int bitno, cc, digested; int fd, len, skip, own_ct_fp = 0; - unsigned long bits; - unsigned char value, *b, *b1, *b2, *b3; + uint32_t bits; + unsigned char value, b; unsigned char *cp, *ep; char buffer[BUFSIZ]; /* sbeck -- handle suffixes */ @@ -1737,16 +1735,6 @@ openBase64 (CT ct, char **file) CE ce; MD5_CTX mdContext; - /* the decoder works on the least-significant three bytes of the bits integer, - but their position in memory depend on both endian-ness and size of - long int... for little-endian architectures the size is irrelevant, for - big-endian archs it's crucial... ideally we'd adopt posix and use a64l instead - of this mess. */ - b = (unsigned char *) &bits; - b1 = &b[endian > 0 ? sizeof(bits)==8?5:1 : 2]; - b2 = &b[endian > 0 ? sizeof(bits)==8?6:2 : 1]; - b3 = &b[endian > 0 ? sizeof(bits)==8?7:3 : 0]; - ce = ct->c_cefile; if (ce->ce_fp) { fseek (ce->ce_fp, 0L, SEEK_SET); @@ -1855,17 +1843,20 @@ openBase64 (CT ct, char **file) bits |= value << bitno; test_end: if ((bitno -= 6) < 0) { - putc ((char) *b1, ce->ce_fp); + b = (bits >> 16) & 0xff; + putc ((char) b, ce->ce_fp); if (digested) - MD5Update (&mdContext, b1, 1); + MD5Update (&mdContext, &b, 1); if (skip < 2) { - putc ((char) *b2, ce->ce_fp); + b = (bits >> 8) & 0xff; + putc ((char) b, ce->ce_fp); if (digested) - MD5Update (&mdContext, b2, 1); + MD5Update (&mdContext, &b, 1); if (skip < 1) { - putc ((char) *b3, ce->ce_fp); + b = bits & 0xff; + putc ((char) b, ce->ce_fp); if (digested) - MD5Update (&mdContext, b3, 1); + MD5Update (&mdContext, &b, 1); } } @@ -2825,20 +2816,9 @@ static int readDigest (CT ct, char *cp) { int bitno, skip; - unsigned long bits; + uint32_t bits; char *bp = cp; unsigned char *dp, value, *ep; - unsigned char *b, *b1, *b2, *b3; - - /* the decoder works on the least-significant three bytes of the bits integer, - but their position in memory depend on both endian-ness and size of - long int... for little-endian architectures the size is irrelevant, for - big-endian archs it's crucial... ideally we'd adopt posix and use a64l instead - of this mess. */ - b = (unsigned char *) &bits; - b1 = &b[endian > 0 ? sizeof(bits)==8?5:1 : 2]; - b2 = &b[endian > 0 ? sizeof(bits)==8?6:2 : 1]; - b3 = &b[endian > 0 ? sizeof(bits)==8?7:3 : 0]; bitno = 18; bits = 0L; @@ -2861,11 +2841,11 @@ test_end: if ((bitno -= 6) < 0) { if (dp + (3 - skip) > ep) goto invalid_digest; - *dp++ = *b1; + *dp++ = (bits >> 16) & 0xff; if (skip < 2) { - *dp++ = *b2; + *dp++ = (bits >> 8) & 0xff; if (skip < 1) - *dp++ = *b3; + *dp++ = bits & 0xff; } bitno = 18; bits = 0L; diff --git a/uip/mhshow.c b/uip/mhshow.c index e4eba4ff..993477bb 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -285,8 +285,6 @@ do_cache: parts[npart] = NULL; types[ntype] = NULL; - set_endian (); - /* * Check if we've specified an additional profile */ diff --git a/uip/mhstore.c b/uip/mhstore.c index 41e62c7d..e491dd90 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -231,8 +231,6 @@ do_cache: parts[npart] = NULL; types[ntype] = NULL; - set_endian (); - /* * Check if we've specified an additional profile */ diff --git a/uip/mhtest.c b/uip/mhtest.c index caaf7af8..cbaefd33 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -232,8 +232,6 @@ do_cache: parts[npart] = NULL; types[ntype] = NULL; - set_endian (); - if (outfile == NULL) adios (NULL, "must specify output file"); diff --git a/uip/viamail.c b/uip/viamail.c index 6e47ea53..e9b26b76 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -146,8 +146,6 @@ main (int argc, char **argv) } } - set_endian (); - if (!f1) adios (NULL, "missing -viamail \"mailpath\" switch"); -- 2.48.1 From 97bc9119e91a9a6d084b6070c8aecbab91393e70 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Thu, 14 Jun 2012 10:36:09 -0400 Subject: [PATCH 13/16] Fix test for changes to mhparam. --- test/mhparam/test-mhparam | 1 + 1 file changed, 1 insertion(+) diff --git a/test/mhparam/test-mhparam b/test/mhparam/test-mhparam index 087be8d4..cc6089ed 100755 --- a/test/mhparam/test-mhparam +++ b/test/mhparam/test-mhparam @@ -30,6 +30,7 @@ Usage: mhparam [profile-components] [switches] -all -version -help + -(debug) EOF mhparam -help >$actual 2>&1 -- 2.48.1 From e1b283895cc1768f8821b980fa5fe56a2567a283 Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 14 Jun 2012 23:17:33 -0500 Subject: [PATCH 14/16] Add trailing newline to body, if needed. --- uip/mhmail.in | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/uip/mhmail.in b/uip/mhmail.in index 0e5713c2..5ad4c71f 100755 --- a/uip/mhmail.in +++ b/uip/mhmail.in @@ -15,9 +15,7 @@ # * Adds -debug option for debugging (sending, not incorporating new mail). # # To do: -# * update mhmail man page -# * add mhmail test -# * integrate into autoconf +# * set prefix properly so that it supports distcheck # * support undocumented mhmail options? usage='Usage: mhmail [addrs ... [switches]] @@ -33,9 +31,12 @@ usage='Usage: mhmail [addrs ... [switches]] and all post(8)/send(1) switches' #### Use autoconf to fill in bindir. -nmhbindir=@bindir@ +# This doesn't work with distcheck. +# prefix=@prefix@ +# exec_prefix=@exec_prefix@ +# nmhbindir=@bindir@ -#### Or if configure hasn't been run yet, figure out nmhbindir at runtime. +#### Or if configure/make haven't been run yet, figure out nmhbindir at runtime. case ${nmhbindir} in @*@) nmhbindir=`dirname $0` ;; esac @@ -83,10 +84,11 @@ else *) if [ ${ccarg} -eq 1 ]; then cclist="${cclist:+${cclist}, }${arg}"; ccarg=0 elif [ ${bodyarg} -eq 1 ]; then - body=${arg}; bodyarg=0 + body="${arg} +"; bodyarg=0 #### Allow -body "" by using just a newline for the body. - [ "${body}"x = x ] && body=" -" + [ "${body}"x = x ] && body=' +' elif [ ${otherarg} -eq 1 ]; then #### Always end ${header} with a newline. header="${header:+${header} }${arg} @@ -107,19 +109,31 @@ else if [ "${havefrom}" = 0 ]; then nmhlibdir=`${nmhbindir}/mhparam libdir` header="${header:+${header}}From: "\ -`${nmhlibdir}/ap -format '%(localmbox)' 0`" -" +`${nmhlibdir}/ap -format '%(localmbox)' 0`' +' fi #### If no -body, read message from stdin the easy way. - [ "${body}"x = x ] && body=`cat` - #### Don't allow an empty body (from stdin). - [ "${body}"x = x ] && exit 1 + if [ "${body}"x = x ]; then + #### This will lose any trailing newline(s), so we can't + #### send the message when stdin contains only newlines. + body=`cat` + + #### Don't allow an empty body (from stdin). + if [ "${body}"x = x ]; then + printf "empty body, message not sent\n" + exit 1 + fi + + #### Add trailing newline to body if it doesn't have one. + [ `printf "${body}" | tail -n 1 | wc -l` -ne 1 ] && body="${body} +" + fi #### Set up a tmpfil and trap to remove it. send moves the file to a backup. - tmpdir=${MHTMPDIR:-${TMPDIR:-${TMP:-`${nmhbindir}/mhpath +`}}} - tmpfil=${tmpdir}/mhmail$$ - tmpfilbackup=${tmpdir}/[,#]mhmail$$ + tmpdir="${MHTMPDIR:-${TMPDIR:-${TMP:-`${nmhbindir}/mhpath +`}}}" + tmpfil="${tmpdir}/mhmail$$" + tmpfilbackup="${tmpdir}/[,#]mhmail$$" trap "rm -f ${tmpfil} ${tmpfilbackup}" EXIT #### Put message header and body in file to supply as draft to @@ -145,8 +159,8 @@ ${body}" > ${tmpfil} || exit 1 if $debug ${post_or_send} ${tmpfil} ${postsendargs}; then : else - #### exec disables the trap set above. printf "Letter saved in dead.letter\n" + #### exec skips the trap set above. exec mv ${tmpfil} dead.letter fi fi -- 2.48.1 From 7b2c5a1bbb879321bc126c5b8df3cc1f38321496 Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 14 Jun 2012 23:28:05 -0500 Subject: [PATCH 15/16] Fixed temporary autoconf workaround by hard-coding nmhbindir. --- uip/mhmail.in | 1 + 1 file changed, 1 insertion(+) diff --git a/uip/mhmail.in b/uip/mhmail.in index 5ad4c71f..e899e99f 100755 --- a/uip/mhmail.in +++ b/uip/mhmail.in @@ -35,6 +35,7 @@ usage='Usage: mhmail [addrs ... [switches]] # prefix=@prefix@ # exec_prefix=@exec_prefix@ # nmhbindir=@bindir@ +nmhbindir=`dirname $0` #### Or if configure/make haven't been run yet, figure out nmhbindir at runtime. case ${nmhbindir} in -- 2.48.1 From e194fdf11df779597e19039a67454e9b42a77ef0 Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 15 Jun 2012 20:53:03 -0500 Subject: [PATCH 16/16] Added nmh lib directory to PATH in setup_test (). This is necessary with "make distcheck" for scripts to access the lib directory that it installs for testing. (The distcheck target does not configure them; they retain their build configuration.) If we ever add a test for etc/sendfiles, we'll have to deal with its configured %libdir%. --- test/common.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common.sh.in b/test/common.sh.in index 39abf676..54f3b8ee 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -135,7 +135,7 @@ setup_test () { MH=${MH_TEST_DIR}/Mail/.mh_profile MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf - PATH=${MH_INST_DIR}${bindir}:${PATH} + PATH=${MH_INST_DIR}${bindir}:${MH_INST_DIR}${auxexecdir}:${PATH} MH_LIB_DIR=${MH_INST_DIR}${auxexecdir} export MH MHMTSCONF MH_LIB_DIR PATH -- 2.48.1