From: David Levine Date: Mon, 15 Sep 2014 00:04:21 +0000 (-0500) Subject: If a component has trailing whitespace, e.g., body:component="> ", X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/ea0a6d8112a918809bd03d8126411040d22f2bb8?ds=sidebyside;hp=337b4e616e8f53ba06285b1645e1df9918ed5c16 If a component has trailing whitespace, e.g., body:component="> ", mhl now trims that whitespace off when filtering blank text lines. --- diff --git a/Makefile.am b/Makefile.am index 30e02a27..e4209a58 100644 --- a/Makefile.am +++ b/Makefile.am @@ -72,6 +72,7 @@ TESTS = test/ali/test-ali test/anno/test-anno \ test/mhbuild/test-forw test/mhbuild/test-header-encode \ test/mhbuild/test-utf8-body \ test/mhfixmsg/test-mhfixmsg \ + test/mhl/test-mhl-flags \ test/mhlist/test-mhlist test/mhlist/test-ext-params \ test/mhmail/test-mhmail \ test/mhparam/test-mhparam test/mhpath/test-mhpath \ diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 6ceb7bd6..1ae76473 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -10,6 +10,8 @@ NEW FEATURES fmttest(1), and mhl(1) now means as many characters as the format engine can produce [Bug #15274]. That amount is limited by internal buffers. +- If a component has trailing whitespace, e.g., body:component="> ", + mhl now trims that whitespace off when filtering blank text lines. ----------------- OBSOLETE FEATURES diff --git a/h/prototypes.h b/h/prototypes.h index 4c5c3bb1..a338fd52 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -57,6 +57,7 @@ char **copyip (char **, char **, int); void cpydata (int, int, char *, char *); void cpydgst (int, int, char *, char *); char *cpytrim (const char *); +char *rtrim (char *); int decode_rfc2047 (char *, char *, size_t); void discard (FILE *); char *upcase (const char *); diff --git a/sbr/trimcpy.c b/sbr/trimcpy.c index 6bcf3aec..7a2ac03a 100644 --- a/sbr/trimcpy.c +++ b/sbr/trimcpy.c @@ -72,3 +72,25 @@ cpytrim (const char *sp) { return dp; } + + +/* + * rtrim() -- modify the argument to: + * -- strip trailing whitespace + * + * This code is Copyright (c) 2014, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ +char * +rtrim (char *sp) { + char *cp; + + /* start at the end and zap trailing whitespace */ + for (cp = sp + strlen (sp) - 1; + cp >= sp && isspace ((unsigned char) *cp); + --cp) { continue; } + *++cp = '\0'; + + return sp; +} diff --git a/test/mhl/test-mhl-flags b/test/mhl/test-mhl-flags new file mode 100755 index 00000000..36a73236 --- /dev/null +++ b/test/mhl/test-mhl-flags @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Test of various (well, start with one) function escapes. + +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 +mhl="${MH_LIB_DIR}/mhl" +expected="$MH_TEST_DIR/$$.expected" +actual="$MH_TEST_DIR/$$.actual" + +cat >`mhpath new` <"$expected" < There are two blank lines below. And there is a trailing space: +> And another trailing space: +> +> +EOF + +cat >"$MH_TEST_DIR/test.format" <"$actual" +check "$expected" "$actual" + + +rm -f "$MH_TEST_DIR/test.format" +exit $failed diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 12add6cc..8d5202b5 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1293,6 +1293,12 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag) { int count, cchdr; char *cp; + /* + * Create a copy of c1->c_text with trailing whitespace + * trimmed, for use with blank lines. + */ + char *trimmed_prefix = + rtrim (add (c1->c_text ? c1->c_text : c1->c_name, NULL)); cchdr = 0; lm = 0; @@ -1388,15 +1394,25 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag) while ((cp = oneline (c2->c_text, c1->c_flags))) { lm = count; if (flag == BODYCOMP - && !(c1->c_flags & NOCOMPONENT)) - putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags); - if (*cp) + && !(c1->c_flags & NOCOMPONENT)) { + /* Output component, trimming trailing whitespace if there + is no text on the line. */ + if (*cp) { + putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags); + } else { + putstr (trimmed_prefix, c1->c_flags); + } + } + if (*cp) { putstr (cp, c1->c_flags); + } if (term == '\n') putstr ("\n", c1->c_flags); } if (flag == BODYCOMP && term == '\n') c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */ + + free (trimmed_prefix); }