]> diplodocus.org Git - nmh/commitdiff
If a component has trailing whitespace, e.g., body:component="> ",
authorDavid Levine <levinedl@acm.org>
Mon, 15 Sep 2014 00:04:21 +0000 (19:04 -0500)
committerDavid Levine <levinedl@acm.org>
Mon, 15 Sep 2014 00:04:21 +0000 (19:04 -0500)
mhl now trims that whitespace off when filtering blank text lines.

Makefile.am
docs/pending-release-notes
h/prototypes.h
sbr/trimcpy.c
test/mhl/test-mhl-flags [new file with mode: 0755]
uip/mhlsbr.c

index 30e02a275d8e911dc322cbba8bb4c628af77652d..e4209a58901719fc6cfcc08c4d91285e0580f3ba 100644 (file)
@@ -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/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 \
        test/mhlist/test-mhlist test/mhlist/test-ext-params \
        test/mhmail/test-mhmail \
        test/mhparam/test-mhparam test/mhpath/test-mhpath \
index 6ceb7bd646c174d1fd9acc591516de8fdde6efda..1ae76473c9917f28ea1c7d39e512807d4f4c3b2e 100644 (file)
@@ -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.
   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
 
 -----------------
 OBSOLETE FEATURES
index 4c5c3bb12cd61b7b4f9dbf66da511e476b4f23dd..a338fd52765b6ec5277f33509ecbbdf4adfef603 100644 (file)
@@ -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 *);
 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 *);
 int decode_rfc2047 (char *, char *, size_t);
 void discard (FILE *);
 char *upcase (const char *);
index 6bcf3aec693d3002bd934ee2513f56277bb50d86..7a2ac03abecf05f4553a7511cb39393b7287b300 100644 (file)
@@ -72,3 +72,25 @@ cpytrim (const char *sp) {
 
     return dp;
 }
 
     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 (executable)
index 0000000..36a7323
--- /dev/null
@@ -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` <<EOF
+MIME-Version: 1.0
+From: sender@example.com
+To: recipient@example.com
+Subject: message with blank lines
+Date: Mon, 29 Apr 2013 11:51:45 -0400
+
+There are two blank lines below.  And there is a trailing space: 
+And another trailing space: 
+
+
+EOF
+
+
+# check that blank lines don't end with whitepace
+cat >"$expected" <<EOF
+> There are two blank lines below.  And there is a trailing space: 
+> And another trailing space: 
+>
+>
+EOF
+
+cat >"$MH_TEST_DIR/test.format" <<EOF
+body:component="> ",overflowtext=,overflowoffset=0
+EOF
+
+"$mhl" -nomoreproc -form "$MH_TEST_DIR/test.format" `mhpath last` >"$actual"
+check "$expected" "$actual"
+
+
+rm -f "$MH_TEST_DIR/test.format"
+exit $failed
index 12add6ccca2a793b7fbe5cbb77317a8639684e2d..8d5202b5eb683c749272324a079c852e6a473abf 100644 (file)
@@ -1293,6 +1293,12 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
 {
     int count, cchdr;
     char *cp;
 {
     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;
 
     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
     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);
            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 */
        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);
 }
 
 
 }