]> diplodocus.org Git - nmh/commitdiff
Merge branch 'welcome'
authorDavid Levine <levinedl@acm.org>
Thu, 6 Oct 2016 13:39:27 +0000 (09:39 -0400)
committerDavid Levine <levinedl@acm.org>
Thu, 6 Oct 2016 13:39:27 +0000 (09:39 -0400)
29 files changed:
Makefile.am
docs/pending-release-notes
h/prototypes.h
h/utils.h
man/mh-profile.man
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/ap.c
uip/dp.c
uip/fmtdump.c
uip/install-mh.c
uip/mhbuild.c
uip/mhfixmsg.c
uip/mhical.c
uip/mhl.c
uip/mhparam.c
uip/mhpath.c
uip/mkstemp.c
uip/prompter.c
uip/rcvdist.c
uip/rcvpack.c
uip/rcvstore.c
uip/rcvtty.c
uip/viamail.c
uip/whatnow.c
uip/whom.c

index 33c7e2c..91b53ef 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/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 \
index bec2a5a..e5ae089 100644 (file)
@@ -58,6 +58,7 @@ NEW FEATURES
 - If a message body contains 8-bit bytes, post(8) uses SMTP 8BITMIME if the
   server supports it.  If not, post fails with a message to the user to
   encode the message for 7-bit transport.
+- Added welcome message when nmh detects that its version changed.
 
 -----------------
 OBSOLETE FEATURES
index a44ccbf..a6c412e 100644 (file)
@@ -479,14 +479,15 @@ int writeBase64 (const unsigned char *, size_t, unsigned char *);
 int writeBase64raw (const unsigned char *, size_t, unsigned char *);
 
 /*
- * first argument:  the string to be decoded
- * second argument:  the decoded bytes
- * third argument:  number of decoded bytes
- * fourth argument:   non-zero for text content, and for which CR's should be skipped
- * fifth argument:  for an MD5 digest, it can be null
+ * encoded      - the string to be decoded
+ * decoded      - the decoded bytes
+ * len          - number of decoded bytes
+ * skip-crs     - non-zero for text content, and for which CR's should be
+ *                skipped
+ * digest       - for an MD5 digest, it can be null
  */
-int decodeBase64 (const char *, unsigned char **, size_t *, int,
-                 unsigned char *);
+int decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
+                  int skip_crs, unsigned char *digest);
 
 void hexify (const unsigned char *, size_t, char **);
 
@@ -497,8 +498,18 @@ void init_credentials_file ();
 int nmh_get_credentials (char *, char *, int, nmh_creds_t);
 
 /*
- * temporary file management
+ * program initialization
+ *
+ * argv0        - argv[0], presumably the program name
+ * read_context - 0: don't read context
+ *              - 1: read context, check nmh version, and issue warning message
+ *                   if non-existent or old
+ *              - 2: read context, don't check nmh version
  */
 int nmh_init(const char *argv0, int read_context);
+
+/*
+ * temporary file management
+ */
 int m_unlink(const char *);
 void unregister_for_removal(int remove_files);
index cd69678..00249be 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);
+
+/*
+ * 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 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%
 .\"
@@ -478,6 +478,34 @@ exception that the permission checks done by
 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
index 10bffc3..03274e0 100644 (file)
@@ -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";
index 6ab5f53..1b1b473 100644 (file)
@@ -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,47 @@ nmh_init(const char *argv0, int read_context) {
         admonish("atexit", "unable to register atexit function");
     }
 
+    /* Read context, if supposed to. */
     if (read_context) {
+        int allow_version_check = 1;
+        int check_older_version = 0;
+        char *cp;
+
         context_read();
+
+        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))) {
+            if (nmh_version_changed (check_older_version)) {
+                printf ("==================================================="
+                        "====================\n");
+                printf ("Welcome to nmh version %s\n\n", VERSION);
+                printf ("See the release notes in %s/NEWS .\n\n",
+                         mhdocdir);
+                print_intro (stdout, 1);
+                printf ("\nThis message will not be repeated until "
+                        "nmh is next updated.\n");
+                printf ("==================================================="
+                        "====================\n\n");
+
+                fputs ("Press enter to continue: ", stdout);
+                (void) read_line ();
+                putchar ('\n');
+            }
+        }
+
         return OK;
     } else {
         int status = context_foil(NULL);
@@ -377,6 +417,41 @@ nmh_init(const char *argv0, int read_context) {
 }
 
 
+/*
+ * 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
+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 old_version < current_version  ?  1  :  0;
+    } else {
+        if (context_version == NULL  ||  strcmp(context_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 *
index 5f3ccd1..47df61e 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
-  #### 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 (executable)
index 0000000..591eb1e
--- /dev/null
@@ -0,0 +1,112 @@
+#!/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
+version="Version: nmh-${MH_VERSION}"
+
+# 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"
+
+
+start_test 'mhparam skips the welcome message'
+# The command will wait for the user to hit return.  script seems to do what
+# we want by not waiting when run in the background.
+script -c 'mhparam path 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
+
+
+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
+
+
+start_test 'with welcome message'
+script -c 'pick last' -f -q "$actual" >/dev/null &
+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
+
+
+start_test 'without welcome message'
+# After running the previous test, this one should not have
+# the welcome message.
+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 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
+
+
+exit $failed
index a7e76bf..83b8407 100755 (executable)
@@ -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
index 9250b08..0b57e65 100644 (file)
--- a/uip/ap.c
+++ b/uip/ap.c
@@ -53,7 +53,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp;
     char **arguments, *addrs[NADDRS];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     mts_init ();
     arguments = getarguments (invo_name, argc, argv, 1);
index cf8f9b1..097b961 100644 (file)
--- a/uip/dp.c
+++ b/uip/dp.c
@@ -50,7 +50,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp, **arguments;
     char *dates[NDATES];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index a45ea80..3cf18d3 100644 (file)
@@ -51,7 +51,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], *nfs, **argp, **arguments;
     struct format *fmt;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index b327115..6b8f444 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);
 
+    /* Initialize the saved nmh version.  The Path profile entry was added
+       above, that's all this needs. */
+    (void) nmh_version_changed (0);
+
     done (0);
     return 1;
 }
index 87252a7..b111df0 100644 (file)
@@ -114,7 +114,7 @@ main (int argc, char **argv)
     int header_encoding = CE_UNKNOWN;
     size_t n;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     done=unlink_done;
 
index 61b3b8b..6195b31 100644 (file)
@@ -152,7 +152,7 @@ main (int argc, char **argv) {
     fx.lf_line_endings = 0;
     fx.textcharset = NULL;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     done = freects_done;
 
index 324d4b6..70f96dd 100644 (file)
@@ -76,7 +76,7 @@ main (int argc, char *argv[]) {
 
     icaldebug = 0;  /* Global provided by bison (with name-prefix "ical"). */
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 652fb11..e945f32 100644 (file)
--- a/uip/mhl.c
+++ b/uip/mhl.c
@@ -13,7 +13,7 @@
 int
 main (int argc, char **argv)
 {
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     done (mhl (argc, argv));
     return 1;
index 3b259e7..a2a7489 100644 (file)
@@ -145,7 +145,7 @@ main(int argc, char **argv)
     char *cp, buf[BUFSIZ], **argp;
     char **arguments, *comps[MAXARGS];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index b9506d7..9ab9439 100644 (file)
@@ -32,7 +32,7 @@ main(int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 8139fec..259c3ed 100644 (file)
@@ -150,7 +150,7 @@ process_args(int argc, char **argv, const char **directory,
     NMH_UNUSED(suffix);
 #   endif /* ! HAVE_MKSTEMPS */
 
-    if (nmh_init(argv[0], 1)) { done(NOTOK); }
+    if (nmh_init(argv[0], 2)) { done(NOTOK); }
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
index 58347d4..f5332e4 100644 (file)
@@ -78,7 +78,7 @@ main (int argc, char **argv)
     char *tmpfil;
     m_getfld_state_t gstate = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 7e9ae01..29b341c 100644 (file)
@@ -48,7 +48,7 @@ main (int argc, char **argv)
     FILE *fp;
     char *tfile = NULL;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     done=unlink_done;
 
index 2553e82..df504a8 100644 (file)
@@ -40,7 +40,7 @@ main (int argc, char **argv)
     char *cp, *file = NULL, buf[BUFSIZ];
     char **argp, **arguments;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     mts_init ();
     arguments = getarguments (invo_name, argc, argv, 1);
index a7d3a9e..8d11e00 100644 (file)
@@ -54,7 +54,7 @@ main (int argc, char **argv)
     struct msgs *mp;
     struct stat st;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     done=unlink_done;
 
index ab674f0..d32a1ba 100644 (file)
@@ -82,7 +82,7 @@ main (int argc, char **argv)
     char **argp, **arguments, *vec[MAXARGS];
     struct utmpx *utp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     mts_init ();
     arguments = getarguments (invo_name, argc, argv, 1);
index f80980d..1514ef8 100644 (file)
@@ -56,7 +56,7 @@ main (int argc, char **argv)
     char *cp, buf[BUFSIZ];
     char **argp, **arguments;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
index 031ff3c..9f30590 100644 (file)
@@ -13,7 +13,7 @@
 int
 main (int argc, char **argv)
 {
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     return WhatNow (argc, argv);
 }
index b1e8b1e..688950c 100644 (file)
@@ -63,7 +63,7 @@ main (int argc, char **argv)
     char *msg = NULL, **ap, **argp, backup[BUFSIZ];
     char buf[BUFSIZ], **arguments, *vec[MAXARGS];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;