Hi all

After I have looked at the ali bug, I have looked at the other tests
which are skipped. I have noticed the mhl with space feature is not this
hard to port from nmh. So I have done this. A patch for this is attached.

Philipp

Ps: the RFC 2231 support is on the todo list but not on top
From b9d4b0dd7841c1b038beca6d47216b20b9d82ba0 Mon Sep 17 00:00:00 2001
From: Philipp Takacs <phil...@bureaucracy.de>
Date: Mon, 19 Nov 2018 03:04:12 +0100
Subject: [PATCH] Trailing withspace handling in mhl

If a component has trailing whitespace, e.g., body:component="> ", mhl
now trims that whitespace off when filtering blank text lines. Also add
a rtrim flag to mhl. This flag removes trailing whitespace in filtert text.

The implementation was done by David Levine <levin...@acm.org> for nmh
commit ea0a6d8112a918809bd03d8126411040d22f2bb8
commit 1aa8f3e11e6d83ee4806abaa132ab9466f02ca5f
---
 h/prototypes.h                |  1 +
 man/mhl.man1                  |  2 ++
 sbr/trim.c                    | 10 ++++++++++
 test/tests/mhl/test-mhl-flags |  3 +--
 uip/mhl.c                     | 33 +++++++++++++++++++++++++--------
 5 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/h/prototypes.h b/h/prototypes.h
index 69556f94..65265822 100644
--- a/h/prototypes.h
+++ b/h/prototypes.h
@@ -107,6 +107,7 @@ char *snprintb(char *, size_t, unsigned, char *);
 int stringdex(char *, char *);
 char *toabsdir(char *);
 char *trim(unsigned char *);
+char *rtrim(char *);
 char *trimcpy(unsigned char *);
 int unputenv(char *);
 void unquote_string(const char *input, char *output);
diff --git a/man/mhl.man1 b/man/mhl.man1
index a80d6bf0..9785fe27 100644
--- a/man/mhl.man1
+++ b/man/mhl.man1
@@ -136,6 +136,8 @@ leftadjust	flag	strip off leading whitespace on each
 noleftadjust	flag	don't leftadjust
 compress	flag	change newlines in text to spaces
 nocompress	flag	don't compress
+rtrim	flag	trim whitespace at end of text lines
+nortrim	flag	retain whitespace at end of text lines (default)
 split	flag	don't combine multiple fields into
 		a single field
 nosplit	flag	combine multiple fields into
diff --git a/sbr/trim.c b/sbr/trim.c
index 249faf9c..ec41c70c 100644
--- a/sbr/trim.c
+++ b/sbr/trim.c
@@ -31,3 +31,13 @@ trim(unsigned char *cp)
 
 	return cp;
 }
+
+char *
+rtrim(char *cp)
+{
+	char *sp = cp + strlen(cp) - 1;
+
+	for (; sp >= cp && isspace(*sp); sp--) {}
+	*++sp = '\0';
+	return cp;
+}
diff --git a/test/tests/mhl/test-mhl-flags b/test/tests/mhl/test-mhl-flags
index 7220e6cb..e4f31bf6 100755
--- a/test/tests/mhl/test-mhl-flags
+++ b/test/tests/mhl/test-mhl-flags
@@ -4,7 +4,6 @@
 
 . "$MH_TEST_COMMON"
 
-test_skip "not implemented yet"
 
 
 cat >`mhpath b` <<EOF
@@ -51,5 +50,5 @@ runandcheck "mhl -form $MH_TEST_DIR/test.format `mhpath l`" <<!
 !
 
 
-rm -f "$MH_TEST_DIR/test.format"
+#rm -f "$MH_TEST_DIR/test.format"
 
diff --git a/uip/mhl.c b/uip/mhl.c
index a84703b8..b0ba02ed 100644
--- a/uip/mhl.c
+++ b/uip/mhl.c
@@ -77,7 +77,8 @@ char *version=VERSION;
 #define INIT        0x000800  /* initialize component        */
 #define SPLIT       0x001000  /* split headers (don't concatenate) */
 #define NONEWLINE   0x002000  /* don't write trailing newline */
-#define LBITS       "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE"
+#define RTRIM       0x004000  /* trim trailing whitespace    */
+#define LBITS       "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE\017RTRIM"
 #define GFLAGS      (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT)
 
 struct mcomp {
@@ -148,6 +149,8 @@ static struct triple triples[] = {
 	{ "nocompress", 0, COMPRESS },
 	{ "split", SPLIT, 0 },
 	{ "nosplit", 0, SPLIT },
+	{ "rtrim", RTRIM, 0 },
+	{ "nortrim", 0, RTRIM },
 	{ "addrfield", ADDRFMT, DATEFMT },
 	{ "datefield", DATEFMT, ADDRFMT },
 	{ "newline", 0, NONEWLINE },
@@ -884,7 +887,10 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
 {
 	int count, cchdr;
 	unsigned char *cp;
+	char trimmed_prefix[BUFSIZ];
 
+	strncpy(trimmed_prefix, c1->c_text ? c1->c_text : c1->c_name, sizeof(trimmed_prefix) - 1);
+	rtrim(trimmed_prefix);
 	cchdr = 0;
 	lm = 0;
 	wid = c1->c_width ? c1->c_width : global.c_width;
@@ -897,7 +903,7 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
 	onelp = NULL;
 
 	if (c1->c_flags & CLEARTEXT) {
-		putstr(c1->c_text);
+		putstr(c1->c_flags & RTRIM ? rtrim(c1->c_text) : c1->c_text);
 		putstr("\n");
 		return;
 	}
@@ -922,7 +928,11 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
 			for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
 				if (islower(*cp))
 					*cp = toupper(*cp);
-		putstr(c1->c_text ? c1->c_text : c1->c_name);
+		if (*c2->c_text && *c2->c_text != '\n' && *c2->c_text != '\t') {
+			putstr(c1->c_text ? c1->c_text : c1->c_name);
+		} else {
+			putstr(trimmed_prefix);
+		}
 		if (flag != BODYCOMP) {
 			putstr(": ");
 			if (!(c1->c_flags & SPLIT))
@@ -970,16 +980,23 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
 	}
 	count += c1->c_offset;
 
-	if ((cp = oneline(c2->c_text, c1->c_flags)))
-	   putstr(cp);
+	if ((cp = oneline(c2->c_text, c1->c_flags))) {
+	   putstr(c1->c_flags & RTRIM ? rtrim(cp) : cp);
+	}
 	if (term == '\n')
 		putstr("\n");
 	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);
+		if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT)) {
+			if (*cp) {
+				putstr(c1->c_text ? c1->c_text : c1->c_name);
+			} else {
+				putstr(trimmed_prefix);
+			}
+		}
 		if (*cp)
-			putstr(cp);
+			putstr(c1->c_flags & RTRIM ? rtrim(cp) : cp);
+
 		if (term == '\n')
 			putstr("\n");
 	}
-- 
2.19.1

Reply via email to