]> diplodocus.org Git - nmh/commitdiff
Added welcome message when nmh detects that its version changed.
authorDavid Levine <levinedl@acm.org>
Wed, 28 Sep 2016 19:01:43 +0000 (15:01 -0400)
committerDavid Levine <levinedl@acm.org>
Wed, 28 Sep 2016 19:02:25 +0000 (15:02 -0400)
Makefile.am
docs/pending-release-notes
h/utils.h
sbr/print_help.c
sbr/utils.c
test/common.sh.in
test/install-mh/test-version-check [new file with mode: 0755]
test/mhparam/test-mhparam
uip/install-mh.c

index 33c7e2ca529eecdbc5a085376df2d03b462b1031..91b53efe5b5712f716c1e3ea1374232118302d8a 100644 (file)
@@ -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/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 \
        test/locking/test-datalocking test/locking/test-spoollocking \
        test/manpages/test-manpages \
        test/mhbuild/test-attach \
index f44eb066dbcd17dfbb1d9757a61301388b53082c..74580e8925abc72d89b446f6fc0b52fad69fe5e0 100644 (file)
@@ -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.
 - 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
 
 -----------------
 OBSOLETE FEATURES
index cd696784f14365224750a4cc2c4cf3f2979d81f0..52d7d05b3bcf708a59021b6d0a5fec003a6641e6 100644 (file)
--- 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);
  * 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 ();
index 10bffc3d7cf339f6a9ce7c977a72387a0b7661ac..03274e080a0caa276b14048bcd5c885329b30289 100644 (file)
@@ -42,8 +42,8 @@ print_help (char *str, struct swit *swp, int print_context)
  */
 
 static const char nmh_intro1[] = \
  */
 
 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";
 "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";
index 6ab5f53461608e5a17759f26de79e1b180d492cc..dcdf24ad353c0daa5bf1ed05c050b245b6bd6084 100644 (file)
@@ -17,6 +17,7 @@ extern int setup_signal_handlers();
 /* sbr/m_mktemp.c */
 extern void remove_registered_files_atexit();
 
 /* sbr/m_mktemp.c */
 extern void remove_registered_files_atexit();
 
+extern char *mhdocdir;
 
 /*
  * We allocate space for messages (msgs array)
 
 /*
  * 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");
     }
 
         admonish("atexit", "unable to register atexit function");
     }
 
+    /* Read context, if supposed to. */
     if (read_context) {
         context_read();
     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);
         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 *
 /* Returns copy of argument str with all characters converted to upper
    case, and trimmed whitespace (see cpytrim()) . */
 char *
index 594d3dbe1287970e3bc83915b59b9922625a09ea..67b6074d3f3c96a07d163b850a28ee4c271f4dae 100644 (file)
@@ -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
 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
 
   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
   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
   # 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 (executable)
index 0000000..b8a91b6
--- /dev/null
@@ -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
index a7e76bf2afcd2bac8703d554cf2f41edbfa3d5ea..83b8407ead082c7d2c66ea16f2b6a2a6bb00618d 100755 (executable)
@@ -49,8 +49,9 @@ run_test 'mhparam -nonexistent' 'mhparam: -nonexistent unknown'
 
 # check -all
 cp "$MH" $expected
 
 # check -all
 cp "$MH" $expected
-# -all adds current folder
+# -all adds current folder and Version
 echo 'Current-Folder: '`folder -f` >>$expected
 echo 'Current-Folder: '`folder -f` >>$expected
+echo "Version: nmh-$MH_VERSION" >>$expected
 run_prog mhparam -all >$actual
 check $expected $actual 'keep first'
 
 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
 $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
 $MH_INST_DIR$bindir/whatnow
 $MH_INST_DIR$bindir/whom
 $nmhetcdirinst
index b32711596aac438d1ce4f267e65e60e74fc33ca5..93f52f5af075fde93b029b7f607d399c1583a42d 100644 (file)
@@ -223,6 +223,10 @@ query:
     puts ("\nPlease see the nmh(7) man page for an introduction to nmh.\n");
     print_intro (stdout, FALSE);
 
     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;
 }
     done (0);
     return 1;
 }