From e49cacf800179ed9650c07f9fc13c5e8736cb9e7 Mon Sep 17 00:00:00 2001
From: Dan Harkless <dan@harkless.org>
Date: Thu, 13 May 1999 01:22:03 +0000
Subject: [PATCH] Don't add line breaks in the middle of long addresses when
 building a draft. Fixes a bug where repl would generate invalid headers. From
 Ruud de Rooij <r.c.m.derooij@twi.tudelft.nl>.

---
 sbr/fmt_scan.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c
index 2086a94c..630cfc5c 100644
--- a/sbr/fmt_scan.c
+++ b/sbr/fmt_scan.c
@@ -729,16 +729,22 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
 		*cp++ = c;
 	    while (len > wid) {
 		/* try to break at a comma; failing that, break at a
-		 * space, failing that, just split the line.
+		 * space.
 		 */
 		lastb = 0; sp = lp + wid;
 		while (sp > lp && (c = *--sp) != ',') {
 		    if (! lastb && isspace(c))
 			lastb = sp - 1;
 		}
-		if (sp == lp)
-		    if (! (sp = lastb))
+		if (sp == lp) {
+		    if (! (sp = lastb)) {
 			sp = lp + wid - 1;
+			while (*sp && *sp != ',' && !isspace(*sp))
+			    sp++;
+			if (*sp != ',')
+			    sp--;
+		    }
+		}
 		len -= sp - lp + 1;
 		while (cp < ep && lp <= sp)
 		    *cp++ = *lp++;
@@ -747,6 +753,12 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
 		    *cp++ = ' ';
 		while (isspace(*lp))
 		    lp++, len--;
+		if (*lp) {
+		    if (cp < ep)
+			*cp++ = '\n';
+		    for (i=indent; cp < ep && i > 0; i--)
+			*cp++ = ' ';
+		}
 	    }
 	    PUTS (cp, lp);
 	    }
-- 
2.39.5