]> diplodocus.org Git - nmh/commitdiff
Output a newline if the last character in a text/plain part is
authorKen Hornstein <kenh@pobox.com>
Fri, 16 May 2014 16:14:21 +0000 (12:14 -0400)
committerKen Hornstein <kenh@pobox.com>
Fri, 16 May 2014 16:14:21 +0000 (12:14 -0400)
not a newline (but only for mhshow).

uip/mhshowsbr.c

index 33d1c09d615e18712aabe1425927639c11f74262..36b414050755ff03595cbce20e84aa7212c7c598 100644 (file)
@@ -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;
     }