]> diplodocus.org Git - nmh/commitdiff
Welcome message enhancements:
authorDavid Levine <levinedl@acm.org>
Thu, 29 Sep 2016 19:13:05 +0000 (15:13 -0400)
committerDavid Levine <levinedl@acm.org>
Thu, 29 Sep 2016 19:13:05 +0000 (15:13 -0400)
1) Disable if Welcome: disable component is in profile.
2) If MHCONTEXT is set, only print the message if the context file
   already has a Version: reference where the version is old.

h/utils.h
man/mh-profile.man
sbr/utils.c
test/install-mh/test-version-check
uip/install-mh.c

index 52d7d05..00249be 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -59,9 +59,9 @@ char *nmh_strcasestr (const char *, const char *);
 int contains8bit(const char *start, const char *end);
 
 /*
 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.
+ * Compares prior version of nmh with current version.  Returns 1
+ * if they compare the be the same, 0 if not.
+ *
+ * older        - 0 for difference comparison, 1 for only if older
  */
  */
-int nmh_version_changed ();
+int nmh_version_changed (int older);
index 9a873a0..d3a8bf1 100644 (file)
@@ -1,4 +1,4 @@
-.TH MH-PROFILE %manext5% "December 21, 2014" "%nmhversion%"
+.TH MH-PROFILE %manext5% "September 29, 2016" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
 .\"
 .\" %nmhwarning%
 .\"
@@ -478,6 +478,34 @@ exception that the permission checks done by
 caution and only when absolutely necessary.
 (profile, default: legacy)
 .RE
 caution and only when absolutely necessary.
 (profile, default: legacy)
 .RE
+.PP
+.BR Welcome :
+disable
+.RS 5
+If the Welcome component is not present, or its value is not
+.RI \*(lq disable \*(rq,
+a welcome message will be displayed the first time that an interactive
+.B nmh
+program is run after updating the
+.B nmh
+installation.
+The user must press the Enter key to continue.
+.PP
+If the MHCONTEXT environment variable is set and non-empty (and
+the Welcome component is not
+.RI \*(lq disable \*(rq),
+the welcome message is only displayed if the context file contains a version
+reference, and that reference is older than the installed
+.B nmh
+version.  The version reference is of the form:
+.PP
+.RS 5
+.nf
+Version: %nmhversion%
+.fi
+.RE
+.PP
+.RE
 .SS "Process Profile Entries"
 The following profile elements are used whenever an
 .B nmh
 .SS "Process Profile Entries"
 The following profile elements are used whenever an
 .B nmh
index f103167..1b1b473 100644 (file)
@@ -367,14 +367,28 @@ nmh_init(const char *argv0, int read_context) {
 
     /* Read context, if supposed to. */
     if (read_context) {
 
     /* Read context, if supposed to. */
     if (read_context) {
+        int allow_version_check = 1;
+        int check_older_version = 0;
+        char *cp;
+
         context_read();
 
         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
-           read_context was set to a value to enable this. */
-        if (read_context == 1  &&  isatty (fileno (stdin))  &&
+        if (read_context != 1  ||
+            ((cp = context_find ("Welcome")) && strcasecmp (cp, "disable") == 0)) {
+            allow_version_check = 0;
+        } else if ((cp = getenv ("MHCONTEXT")) != NULL && *cp != '\0') {
+            /* Context file comes from $MHCONTEXT, so only print the message
+               if the context file has an older version.  If it does, or if it
+               doesn't have a version at all, update the version. */
+            check_older_version = 1;
+        }
+
+        /* Check to see if the user is running a different (or older, if
+           specified) version of nmh than they had run bfore, and notify them
+           if so.  But only if read_context was set to a value to enable. */
+        if (allow_version_check  &&  isatty (fileno (stdin))  &&
             isatty (fileno (stdout))  &&  isatty (fileno (stderr))) {
             isatty (fileno (stdout))  &&  isatty (fileno (stderr))) {
-            if (nmh_version_changed ()) {
+            if (nmh_version_changed (check_older_version)) {
                 printf ("==================================================="
                         "====================\n");
                 printf ("Welcome to nmh version %s\n\n", VERSION);
                 printf ("==================================================="
                         "====================\n");
                 printf ("Welcome to nmh version %s\n\n", VERSION);
@@ -404,20 +418,36 @@ nmh_init(const char *argv0, int read_context) {
 
 
 /*
 
 
 /*
- * Check stored version, and if out-of-date or non-existent, notify the user
- * and update.
+ * Check stored version, and return 1 if out-of-date or non-existent.
+ * Because the output of "mhparam version" is prefixed with "nmh-",
+ * use that prefix here.
  */
 int
  */
 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);
+nmh_version_changed (int older) {
+    const char *const context_version = context_find("Version");
+
+    if (older) {
+        /* Convert the version strings to floats and compare them.  This will
+           break for versions with multiple decimal points, etc. */
+        const float current_version = strtod (VERSION, NULL);
+        const float old_version =
+            context_version  &&  strncmp (context_version, "nmh-", 4) == 0
+            ?  strtof (context_version + 4, NULL)
+            :  99999999;
+
+        if (context_version == NULL  ||  old_version < current_version) {
+            context_replace ("Version", "nmh-" VERSION);
+        }
 
 
-        return 1;
+        return old_version < current_version  ?  1  :  0;
     } else {
     } else {
-        return 0;
+        if (context_version == NULL  ||  strcmp(context_version, "nmh-" VERSION) != 0) {
+            context_replace ("Version", "nmh-" VERSION);
+
+            return 1;
+        } else {
+            return 0;
+        }
     }
 }
 
     }
 }
 
index 3dfef04..591eb1e 100755 (executable)
@@ -21,8 +21,10 @@ require_prog script
 
 actual="$MH_TEST_DIR/test-version-check$$.actual"
 context="${MH_TEST_DIR}"/Mail/context
 
 actual="$MH_TEST_DIR/test-version-check$$.actual"
 context="${MH_TEST_DIR}"/Mail/context
+version="Version: nmh-${MH_VERSION}"
 
 
-# Removing Version will trigger the welcome message.
+# Removing Version will trigger the welcome message.  (setup_test
+# inserted it so that other tests wouldn't show it.)
 grep -v Version "$context" > "$context.NEW"
 mv -f "$context.NEW" "$context"
 
 grep -v Version "$context" > "$context.NEW"
 mv -f "$context.NEW" "$context"
 
@@ -34,6 +36,20 @@ script -c 'mhparam path last' -f -q "$actual" >/dev/null &
 wait $!
 grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
 rm "$actual"
 wait $!
 grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
 rm "$actual"
+# Make sure that version wasn't added to context.
+grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null  &&  false
+finish_test
+
+
+start_test 'Welcome: disable in profile skips the welcome message'
+cp "${MH}" "${MH}-welcome"
+printf 'Welcome: disable\n' >> "${MH}-welcome"
+MH="${MH}-welcome" script -c 'pick last' -f -q "$actual" >/dev/null &
+wait $!
+grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
+rm "$actual"
+# Make sure that version wasn't added to context.
+grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null  &&  false
 finish_test
 
 
 finish_test
 
 
@@ -42,6 +58,8 @@ script -c 'pick last' -f -q "$actual" >/dev/null &
 wait $!
 grep 'Welcome to nmh version ' "$actual" >/dev/null
 rm "$actual"
 wait $!
 grep 'Welcome to nmh version ' "$actual" >/dev/null
 rm "$actual"
+# Make sure that version was added to context.
+grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
 finish_test
 
 
 finish_test
 
 
@@ -52,6 +70,42 @@ script -c 'pick last' -f -q "$actual" >/dev/null &
 wait $!
 grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
 rm "$actual"
 wait $!
 grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
 rm "$actual"
+# Make sure that version is still in context.
+grep "^${version}$" "${MH_TEST_DIR}/Mail/context" >/dev/null
+finish_test
+
+
+start_test 'with MHCONTEXT, welcome only if older'
+MHCONTEXT="${MH_TEST_DIR}/Mail/context2"; export MHCONTEXT
+printf 'Version: nmh-1.5\n' >"${MHCONTEXT}"
+script -c 'pick last' -f -q "$actual" >/dev/null &
+wait $!
+grep 'Welcome to nmh version ' "$actual" >/dev/null
+# And make sure that version did get updated in context.
+grep "^${version}$" "${MHCONTEXT}" >/dev/null
+rm "$actual"
+finish_test
+
+
+start_test "with MHCONTEXT doesn't welcome if newer"
+printf 'Version: nmh-10000.0\n' >"${MHCONTEXT}"
+script -c 'pick last' -f -q "$actual" >/dev/null &
+wait $!
+grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
+rm "$actual"
+# And make sure that version didn't get updated in context.
+grep '^Version: nmh-10000.0$' "${MHCONTEXT}" >/dev/null
+finish_test
+
+
+start_test 'with MHCONTEXT but no version, no welcome and update'
+printf '' >"${MHCONTEXT}"
+script -c 'pick last' -f -q "$actual" >/dev/null &
+wait $!
+grep 'Welcome to nmh version ' "$actual" >/dev/null  &&  false
+# And make sure that version did get updated in context.
+grep "^${version}$" "${MHCONTEXT}" >/dev/null
+rm "$actual"
 finish_test
 
 
 finish_test
 
 
index 93f52f5..6b8f444 100644 (file)
@@ -225,7 +225,7 @@ query:
 
     /* Initialize the saved nmh version.  The Path profile entry was added
        above, that's all this needs. */
 
     /* Initialize the saved nmh version.  The Path profile entry was added
        above, that's all this needs. */
-    (void) nmh_version_changed ();
+    (void) nmh_version_changed (0);
 
     done (0);
     return 1;
 
     done (0);
     return 1;