From: David Levine Date: Wed, 28 Sep 2016 19:01:43 +0000 (-0400) Subject: Added welcome message when nmh detects that its version changed. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/49b128f0607611e485a06c21dcb48e4144b63d5e?ds=sidebyside;hp=2e9c6b8b2c97bafa9416690d562a9425c5bd238f Added welcome message when nmh detects that its version changed. --- diff --git a/Makefile.am b/Makefile.am index 33c7e2ca..91b53efe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -69,7 +69,7 @@ TESTS = test/ali/test-ali test/anno/test-anno \ test/inc/test-deb359167 test/inc/test-eom-align \ test/inc/test-inc-scanout test/inc/test-msgchk \ test/inc/test-pop \ - test/install-mh/test-install-mh \ + test/install-mh/test-install-mh test/install-mh/test-version-check \ test/locking/test-datalocking test/locking/test-spoollocking \ test/manpages/test-manpages \ test/mhbuild/test-attach \ diff --git a/docs/pending-release-notes b/docs/pending-release-notes index f44eb066..74580e89 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -52,6 +52,7 @@ NEW FEATURES - Support for SMTPUTF8 (RFC 6531) has been added. mhshow(1) already supported RFC 6532, assuming all 8-bit message header field bodies are UTF-8 and use of a UTF-8 locale. +- Added welcome message when nmh detects that its version changed. ----------------- OBSOLETE FEATURES diff --git a/h/utils.h b/h/utils.h index cd696784..52d7d05b 100644 --- a/h/utils.h +++ b/h/utils.h @@ -57,3 +57,11 @@ char *nmh_strcasestr (const char *, const char *); * Returns 1 if the string contains an 8-bit character, 0 if it does not. */ int contains8bit(const char *start, const char *end); + +/* + * Check to see if the user is running a different version of nmh + * than they had last run, and notify them if so. But only if + * they seem to be running an interactive program. + * Returns 1 if they are, 0 if they are not. + */ +int nmh_version_changed (); diff --git a/sbr/print_help.c b/sbr/print_help.c index 10bffc3d..03274e08 100644 --- a/sbr/print_help.c +++ b/sbr/print_help.c @@ -42,8 +42,8 @@ print_help (char *str, struct swit *swp, int print_context) */ static const char nmh_intro1[] = \ -"Send bug reports, questions, suggestions, and patches to nmh-\n" -"workers@nongnu.org. That mailing list is relatively quiet, so user\n" +"Send bug reports, questions, suggestions, and patches to\n" +"nmh-workers@nongnu.org. That mailing list is relatively quiet, so user\n" "questions are encouraged. Users are also encouraged to subscribe, and\n" "view the archives, at https://lists.gnu.org/mailman/listinfo/nmh-\n" "workers .\n"; diff --git a/sbr/utils.c b/sbr/utils.c index 6ab5f534..dcdf24ad 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -17,6 +17,7 @@ extern int setup_signal_handlers(); /* sbr/m_mktemp.c */ extern void remove_registered_files_atexit(); +extern char *mhdocdir; /* * We allocate space for messages (msgs array) @@ -364,8 +365,46 @@ nmh_init(const char *argv0, int read_context) { admonish("atexit", "unable to register atexit function"); } + /* Read context, if supposed to. */ if (read_context) { context_read(); + + /* Check to see if the user is running a different version of nmh + than they had last run, and notify them if so. But only if + they seem to be running an interactive program. */ + if (isatty (fileno (stdin)) && isatty (fileno (stdout)) && + strcmp (invo_name, "ap") && + strcmp (invo_name, "dp") && + strcmp (invo_name, "fmtdump") && + strcmp (invo_name, "install-mh") && + strcmp (invo_name, "mhbuild") && + strcmp (invo_name, "mhfixmsg") && + strcmp (invo_name, "mhl") && + strcmp (invo_name, "mhparam") && + strcmp (invo_name, "mhpath") && + strcmp (invo_name, "mkstemp") && + strcmp (invo_name, "post") && + strcmp (invo_name, "prompter") && + strncmp (invo_name, "rcv", 3) && + strcmp (invo_name, "slocal") && + strcmp (invo_name, "viamail") && + strcmp (invo_name, "whatnow") && + strcmp (invo_name, "whom")) { + + if (nmh_version_changed ()) { + fprintf (stderr, "===========================================" + "============================\n"); + fprintf (stderr, "Welcome to nmh version %s\n\n", VERSION); + fprintf (stderr, "See the release notes in %s/NEWS .\n\n", + mhdocdir); + print_intro (stderr, 1); + fprintf (stderr, "\nThis message will not be repeated until " + "nmh is next updated.\n"); + fprintf (stderr, "===========================================" + "============================\n\n\n"); + } + } + return OK; } else { int status = context_foil(NULL); @@ -377,6 +416,25 @@ nmh_init(const char *argv0, int read_context) { } +/* + * Check stored version, and if out-of-date or non-existent, notify the user + * and update. + */ +int +nmh_version_changed () { + const char *const old_version = context_find("Version"); + + /* mhparam version includes the nmh- prefix, so be consistent with that. */ + if (old_version == NULL || strcmp(old_version, "nmh-" VERSION) != 0) { + context_replace ("Version", "nmh-" VERSION); + + return 1; + } else { + return 0; + } +} + + /* Returns copy of argument str with all characters converted to upper case, and trimmed whitespace (see cpytrim()) . */ char * diff --git a/test/common.sh.in b/test/common.sh.in index 594d3dbe..67b6074d 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -383,8 +383,6 @@ whatnowproc: ${MH_INST_DIR}${bindir}/whatnow whomproc: ${MH_INST_DIR}${bindir}/whom #: incproc and packproc are defined in config.c but not used by any code. EOF - #### Suppress warnings about a new version. - printf '%s\n' ${MH_VERSION} > ${MH_TEST_DIR}/Mail/VERSION if test -z '@nmhetcdirinst@'; then #### This isn't used with make distcheck, so that we can use it to @@ -396,6 +394,10 @@ EOF fi folder -create +inbox > /dev/null + #### Suppress warnings about a new version. + #### mhparam version includes the nmh- prefix, so be consistent with that. + printf 'Version: nmh-%s\n' "${MH_VERSION}" >> "${MH_TEST_DIR}"/Mail/context + # create 10 basic messages for i in 1 2 3 4 5 6 7 8 9 10; do diff --git a/test/install-mh/test-version-check b/test/install-mh/test-version-check new file mode 100755 index 00000000..b8a91b68 --- /dev/null +++ b/test/install-mh/test-version-check @@ -0,0 +1,45 @@ +#!/bin/sh +###################################################### +# +# Test display of new version welcome message. This +# doesn't really belong in install-mh. +# +###################################################### + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "${MH_OBJ_DIR}/test/common.sh" + +setup_test + +require_prog script + +actual="$MH_TEST_DIR/test-version-check$$.actual" +context="${MH_TEST_DIR}"/Mail/context + + +start_test 'with welcome message' +# Removing Version will trigger the welcome message. +grep -v Version "$context" > "$context.NEW" +mv -f "$context.NEW" "$context" +script -c 'pick last' -q "$actual" >/dev/null +grep 'Welcome to nmh version ' "$actual" >/dev/null +rm "$actual" +finish_test + + +start_test 'without welcome message' +# After running the previous test, this one should not have +# the welcome message. +script -c 'pick last' -q "$actual" >/dev/null +grep 'Welcome to nmh version ' "$actual" >/dev/null && false +rm "$actual" +finish_test + + +exit $failed diff --git a/test/mhparam/test-mhparam b/test/mhparam/test-mhparam index a7e76bf2..83b8407e 100755 --- a/test/mhparam/test-mhparam +++ b/test/mhparam/test-mhparam @@ -49,8 +49,9 @@ run_test 'mhparam -nonexistent' 'mhparam: -nonexistent unknown' # check -all cp "$MH" $expected -# -all adds current folder +# -all adds current folder and Version echo 'Current-Folder: '`folder -f` >>$expected +echo "Version: nmh-$MH_VERSION" >>$expected run_prog mhparam -all >$actual check $expected $actual 'keep first' @@ -94,7 +95,7 @@ $MH_INST_DIR$nmhlibexecdir/post $MH_INST_DIR$bindir/send $MH_INST_DIR$bindir/mhshow $MH_INST_DIR$nmhlibexecdir/mhl -nmh-`cat ${srcdir}/VERSION` +nmh-$MH_VERSION $MH_INST_DIR$bindir/whatnow $MH_INST_DIR$bindir/whom $nmhetcdirinst diff --git a/uip/install-mh.c b/uip/install-mh.c index b3271159..93f52f5a 100644 --- a/uip/install-mh.c +++ b/uip/install-mh.c @@ -223,6 +223,10 @@ query: puts ("\nPlease see the nmh(7) man page for an introduction to nmh.\n"); print_intro (stdout, FALSE); + /* Initialize the saved nmh version. The Path profile entry was added + above, that's all this needs. */ + (void) nmh_version_changed (); + done (0); return 1; }