X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/f5a9aef6b97b9f07c8af62b2eb4d67fcbb995fb7..4dff00a2d1a9e0b1e301c3015d8f7bdf87e2e37a:/uip/mhoutsbr.c?ds=sidebyside diff --git a/uip/mhoutsbr.c b/uip/mhoutsbr.c index 57a5df93..4845f7e1 100644 --- a/uip/mhoutsbr.c +++ b/uip/mhoutsbr.c @@ -62,12 +62,14 @@ output_message (CT ct, char *file) FILE *fp; int status; - if ((fp = fopen (file, "w")) == NULL) { + if (! strcmp (file, "-")) { + fp = stdout; + } else if ((fp = fopen (file, "w")) == NULL) { advise (file, "unable to open for writing"); return NOTOK; } status = output_message_fp(ct, fp, file); - fclose(fp); + if (strcmp (file, "-")) fclose(fp); return status; } @@ -81,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 @@ -108,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; @@ -142,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; @@ -272,17 +298,18 @@ static int write8Bit (CT ct, FILE *out) { int fd; + size_t inbytes; char c, *file, buffer[BUFSIZ]; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; file = NULL; if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) 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); @@ -302,7 +329,7 @@ writeQuoted (CT ct, FILE *out) int fd; char *cp, *file; char c, buffer[BUFSIZ]; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; file = NULL; if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) @@ -373,7 +400,7 @@ writeBase64ct (CT ct, FILE *out) { int fd, result; char *file; - CE ce = ct->c_cefile; + CE ce = &ct->c_cefile; file = NULL; if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)