]> diplodocus.org Git - nmh/blobdiff - uip/mhoutsbr.c
Ignore the sign mismatch warning when sbr/dtimep.c is built with
[nmh] / uip / mhoutsbr.c
index 59bf7a429e36bafde130923128e730cf723afbef..db64c4b87d1e2af79e4e448d4ed3a5bf86ea6b6a 100644 (file)
@@ -83,6 +83,14 @@ output_content (CT ct, FILE *out)
 {
     int result = 0;
     CI ci = &ct->c_ctinfo;
+    char *boundary = ci->ci_values[0], **ap, **vp;
+
+    for (ap = ci->ci_attrs, vp = ci->ci_values; *ap; ++ap, ++vp) {
+        if (! mh_strcasecmp ("boundary", *ap)) {
+            boundary = *vp;
+            break;
+        }
+    }
 
     /*
      * Output all header fields for this content
@@ -110,14 +118,23 @@ output_content (CT ct, FILE *out)
            putc ('\n', out);
 
        m = (struct multipart *) ct->c_ctparams;
+
+        if (m->mp_content_before) {
+           fprintf (out, "%s", m->mp_content_before);
+        }
+
        for (part = m->mp_parts; part; part = part->mp_next) {
            CT p = part->mp_part;
 
-           fprintf (out, "\n--%s\n", ci->ci_values[0]);
+           fprintf (out, "\n--%s\n", boundary);
            if (output_content (p, out) == NOTOK)
                return NOTOK;
        }
-       fprintf (out, "\n--%s--\n", ci->ci_values[0]);
+       fprintf (out, "\n--%s--\n", boundary);
+
+        if (m->mp_content_after) {
+           fprintf (out, "%s", m->mp_content_after);
+        }
     }
     break;
 
@@ -144,7 +161,14 @@ output_content (CT ct, FILE *out)
     default:
        switch (ct->c_encoding) {
        case CE_7BIT:
-           putc ('\n', out);
+           /* Special case:  if this is a non-MIME message with no
+              body, don't emit the newline that would appear between
+              the headers and body.  In that case, the call to
+              write8Bit() shouldn't be needed, but is harmless. */
+           if (ct->c_ctinfo.ci_attrs[0] != NULL  ||
+               ct->c_begin != ct->c_end) {
+               putc ('\n', out);
+           }
            result = write8Bit (ct, out);
            break;
 
@@ -274,6 +298,7 @@ static int
 write8Bit (CT ct, FILE *out)
 {
     int fd;
+    size_t inbytes;
     char c, *file, buffer[BUFSIZ];
     CE ce = ct->c_cefile;
 
@@ -282,9 +307,9 @@ write8Bit (CT ct, FILE *out)
        return NOTOK;
 
     c = '\n';
-    while (fgets (buffer, sizeof(buffer) - 1, ce->ce_fp)) {
-       c = buffer[strlen (buffer) - 1];
-       fputs (buffer, out);
+    while ((inbytes = fread (buffer, 1, sizeof buffer, ce->ce_fp)) > 0) {
+        c = buffer[inbytes - 1];
+        fwrite (buffer, 1, inbytes, out);
     }
     if (c != '\n')
        putc ('\n', out);