]> diplodocus.org Git - nmh/blobdiff - uip/mhoutsbr.c
Reworked attach to add charset to Content-Type string for
[nmh] / uip / mhoutsbr.c
index d3a0a85b656ae8da038bf66cd4723fe06ee0c6cd..df23047e6282bc613ca286235c5a7cfc75a01617 100644 (file)
@@ -12,8 +12,6 @@
 #include <fcntl.h>
 #include <h/signals.h>
 #include <h/md5.h>
-#include <errno.h>
-#include <signal.h>
 #include <h/mts.h>
 #include <h/tws.h>
 #include <h/mime.h>
@@ -86,7 +84,7 @@ output_content (CT ct, FILE *out)
     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)) {
+        if (! strcasecmp ("boundary", *ap)) {
             boundary = *vp;
             break;
         }
@@ -118,6 +116,11 @@ 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;
 
@@ -126,6 +129,10 @@ output_content (CT ct, FILE *out)
                return NOTOK;
        }
        fprintf (out, "\n--%s--\n", boundary);
+
+        if (m->mp_content_after) {
+           fprintf (out, "%s", m->mp_content_after);
+        }
     }
     break;
 
@@ -152,7 +159,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;
 
@@ -233,7 +247,7 @@ writeExternalBody (CT ct, FILE *out)
 
            case 'N':
                for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++)
-                   if (!mh_strcasecmp (*ap, "name")) {
+                   if (!strcasecmp (*ap, "name")) {
                        fprintf (out, "%s", *ep);
                        break;
                    }
@@ -282,17 +296,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);
@@ -312,7 +327,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)
@@ -383,7 +398,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)