From: David Levine Date: Thu, 6 Oct 2016 13:39:27 +0000 (-0400) Subject: Merge branch 'welcome' X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/6fc2909634fb431c65ecfa8b6db4f6519f99b389?hp=641e461b10b6fd320ed6a13ec4075754d29bbb0b Merge branch 'welcome' --- 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 bec2a5ae..e5ae0899 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -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 diff --git a/h/prototypes.h b/h/prototypes.h index a44ccbf5..a6c412e2 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -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); diff --git a/h/utils.h b/h/utils.h index cd696784..00249be4 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); + +/* + * 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); diff --git a/man/mh-profile.man b/man/mh-profile.man index 9a873a05..d3a8bf16 100644 --- a/man/mh-profile.man +++ b/man/mh-profile.man @@ -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 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..1b1b4738 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,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 * diff --git a/test/common.sh.in b/test/common.sh.in index 5f3ccd14..47df61eb 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..591eb1ee --- /dev/null +++ b/test/install-mh/test-version-check @@ -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 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/ap.c b/uip/ap.c index 9250b08a..0b57e652 100644 --- 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); diff --git a/uip/dp.c b/uip/dp.c index cf8f9b14..097b961d 100644 --- 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; diff --git a/uip/fmtdump.c b/uip/fmtdump.c index a45ea801..3cf18d35 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -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; diff --git a/uip/install-mh.c b/uip/install-mh.c index b3271159..6b8f4442 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 (0); + done (0); return 1; } diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 87252a7c..b111df0c 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -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; diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index 61b3b8b3..6195b316 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -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; diff --git a/uip/mhical.c b/uip/mhical.c index 324d4b63..70f96dd2 100644 --- a/uip/mhical.c +++ b/uip/mhical.c @@ -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; diff --git a/uip/mhl.c b/uip/mhl.c index 652fb11b..e945f322 100644 --- 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; diff --git a/uip/mhparam.c b/uip/mhparam.c index 3b259e7f..a2a7489a 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -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; diff --git a/uip/mhpath.c b/uip/mhpath.c index b9506d73..9ab94392 100644 --- a/uip/mhpath.c +++ b/uip/mhpath.c @@ -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; diff --git a/uip/mkstemp.c b/uip/mkstemp.c index 8139fec7..259c3edd 100644 --- a/uip/mkstemp.c +++ b/uip/mkstemp.c @@ -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; diff --git a/uip/prompter.c b/uip/prompter.c index 58347d47..f5332e46 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -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; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 7e9ae010..29b341ca 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -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; diff --git a/uip/rcvpack.c b/uip/rcvpack.c index 2553e823..df504a86 100644 --- a/uip/rcvpack.c +++ b/uip/rcvpack.c @@ -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); diff --git a/uip/rcvstore.c b/uip/rcvstore.c index a7d3a9e9..8d11e005 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -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; diff --git a/uip/rcvtty.c b/uip/rcvtty.c index ab674f0d..d32a1baa 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -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); diff --git a/uip/viamail.c b/uip/viamail.c index f80980d6..1514ef88 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -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; diff --git a/uip/whatnow.c b/uip/whatnow.c index 031ff3c8..9f305907 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.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; } return WhatNow (argc, argv); } diff --git a/uip/whom.c b/uip/whom.c index b1e8b1ed..688950c9 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -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;