* Bug #15213, #18635: The use of the insecure m_scratch() and
[mmh] / uip / mhoutsbr.c
index 6d2914a..9235253 100644 (file)
@@ -4,6 +4,10 @@
  *            -- given a Content structure
  *
  * $Id$
+ *
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 #include <h/mh.h>
@@ -12,8 +16,8 @@
 #include <h/md5.h>
 #include <errno.h>
 #include <signal.h>
-#include <zotnet/mts/mts.h>
-#include <zotnet/tws/tws.h>
+#include <h/mts.h>
+#include <h/tws.h>
 #include <h/mime.h>
 #include <h/mhparse.h>
 
@@ -22,7 +26,6 @@
 #endif
 
 
-extern int errno;
 extern int ebcdicsw;
 
 static char ebcdicsafe[0x100] = {
@@ -67,13 +70,14 @@ static char nib2b64[0x40+1] =
  * prototypes
  */
 int output_message (CT, char *);
+int output_message_fp (CT, FILE *, char *);
 int writeBase64aux (FILE *, FILE *);
 
 /*
  * static prototypes
  */
 static int output_content (CT, FILE *);
-static int output_headers (CT, FILE *);
+static void output_headers (CT, FILE *);
 static int writeExternalBody (CT, FILE *);
 static int write8Bit (CT, FILE *);
 static int writeQuoted (CT, FILE *);
@@ -87,27 +91,33 @@ static int writeBase64 (CT, FILE *);
  */
 
 int
-output_message (CT ct, char *file)
+output_message_fp (CT ct, FILE *fp, char *file)
 {
-    FILE *fp;
-
-    if ((fp = fopen (file, "w")) == NULL) {
-       advise (file, "unable to open for writing");
-       return NOTOK;
-    }
-
     if (output_content (ct, fp) == NOTOK)
        return NOTOK;
 
     if (fflush (fp)) {
-       advise (file, "error writing to");
+       advise ((file?file:"<FILE*>"), "error writing to");
        return NOTOK;
     }
-    fclose (fp);
-
     return OK;
 }
 
+int
+output_message (CT ct, char *file)
+{
+    FILE *fp;
+    int status;
+
+    if ((fp = fopen (file, "w")) == NULL) {
+       advise (file, "unable to open for writing");
+       return NOTOK;
+    }
+    status = output_message_fp(ct, fp, file);
+    fclose(fp);
+    return status;
+}
+
 
 /*
  * Output a Content structure to a file.
@@ -219,7 +229,7 @@ output_content (CT ct, FILE *out)
  * Output all the header fields for a content
  */
 
-static int
+static void
 output_headers (CT ct, FILE *out)
 {
     HF hp;
@@ -260,7 +270,7 @@ writeExternalBody (CT ct, FILE *out)
 
            case 'N':
                for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++)
-                   if (!strcasecmp (*ap, "name")) {
+                   if (!mh_strcasecmp (*ap, "name")) {
                        fprintf (out, "%s", *ep);
                        break;
                    }