From b67c1d7c42331f0abd85439caa3d5b9a09e7a999 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Fri, 16 May 2014 12:14:21 -0400 Subject: [PATCH] Output a newline if the last character in a text/plain part is not a newline (but only for mhshow). --- uip/mhshowsbr.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 33d1c09d..36b41405 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -416,6 +416,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, if (buffer[0] == '\0') { char readbuf[BUFSIZ]; ssize_t cc; + char lastchar = '\n'; if (fd == NOTOK) { advise(NULL, "Cannot use NULL command to display content-type " @@ -425,6 +426,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, while ((cc = read(fd, readbuf, sizeof(readbuf))) > 0) { fwrite(readbuf, sizeof(char), cc, stdout); + lastchar = readbuf[cc - 1]; } if (cc < 0) { @@ -432,6 +434,20 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, return NOTOK; } + /* + * The MIME standards allow content to not have a trailing newline. + * But because we are (presumably) sending this to stdout, include + * a newline for text content if the final character was not a + * newline. Only do this for mhshow. + */ + + if (strcmp(invo_name, "mhshow") == 0 && ct->c_type == CT_TEXT && + ct->c_subtype == TEXT_PLAIN && lastchar != '\n') { + putc('\n', stdout); + } + + fflush(stdout); + return OK; } -- 2.56.0