[bug #4302] errno is not always an extern int
[mmh] / uip / mhparse.c
index 86a08b7..0bb56da 100644 (file)
@@ -3,6 +3,10 @@
  * mhparse.c -- routines to parse the contents of MIME messages
  *
  * $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 <errno.h>
 #include <setjmp.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 debugsw;
 
 extern int endian;     /* mhmisc.c     */
@@ -177,7 +180,7 @@ static struct str2init str2ces[] = {
     { "quoted-printable", CE_QUOTED,   InitQuoted },
     { "8bit",            CE_8BIT,      Init7Bit },
     { "7bit",            CE_7BIT,      Init7Bit },
-    { "binary",                  CE_BINARY,    NULL },
+    { "binary",                  CE_BINARY,    Init7Bit },
     { NULL,              CE_EXTENSION, NULL },  /* these two must be last! */
     { NULL,              CE_UNKNOWN,   NULL },
 };
@@ -984,6 +987,7 @@ InitMultiPart (CT ct)
      * Check for "boundary" parameter, which is
      * required for multipart messages.
      */
+    bp = 0;
     for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
        if (!strcasecmp (*ap, "boundary")) {
            bp = *ep;
@@ -1568,6 +1572,8 @@ openBase64 (CT ct, char **file)
     unsigned long bits;
     unsigned char value, *b, *b1, *b2, *b3;
     char *cp, *ep, buffer[BUFSIZ];
+    /* sbeck -- handle prefixes */
+    CI ci;
     CE ce;
     MD5_CTX mdContext;
 
@@ -1598,6 +1604,19 @@ openBase64 (CT ct, char **file)
        ce->ce_unlink = 0;
     }
 
+    /* sbeck@cise.ufl.edu -- handle suffixes */
+    ci = &ct->c_ctinfo;
+    snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s",
+              invo_name, ci->ci_type, ci->ci_subtype);
+    cp = context_find (buffer);
+    if (cp == NULL || *cp == '\0') {
+        snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name,
+                  ci->ci_type);
+        cp = context_find (buffer);
+    }
+    if (cp != NULL && *cp != '\0')
+        ce->ce_file = add (cp, ce->ce_file);
+
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
        return NOTOK;
@@ -1767,6 +1786,8 @@ openQuoted (CT ct, char **file)
     char buffer[BUFSIZ];
     unsigned char mask;
     CE ce;
+    /* sbeck -- handle prefixes */
+    CI ci;
     MD5_CTX mdContext;
 
     ce = ct->c_cefile;
@@ -1791,6 +1812,24 @@ openQuoted (CT ct, char **file)
        ce->ce_unlink = 0;
     }
 
+    /* sbeck@cise.ufl.edu -- handle suffixes */
+    ci = &ct->c_ctinfo;
+    snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s",
+              invo_name, ci->ci_type, ci->ci_subtype);
+    cp = context_find (buffer);
+    if (cp == NULL || *cp == '\0') {
+        snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name,
+                  ci->ci_type);
+        cp = context_find (buffer);
+    }
+    if (cp != NULL && *cp != '\0')
+        ce->ce_file = add (cp, ce->ce_file);
+
+    if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
+       content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
+       return NOTOK;
+    }
+
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
        return NOTOK;
@@ -1965,6 +2004,9 @@ open7Bit (CT ct, char **file)
 {
     int        cc, fd, len;
     char buffer[BUFSIZ];
+    /* sbeck -- handle prefixes */
+    char *cp;
+    CI ci;
     CE ce;
 
     ce = ct->c_cefile;
@@ -1989,6 +2031,19 @@ open7Bit (CT ct, char **file)
        ce->ce_unlink = 0;
     }
 
+    /* sbeck@cise.ufl.edu -- handle suffixes */
+    ci = &ct->c_ctinfo;
+    snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s",
+              invo_name, ci->ci_type, ci->ci_subtype);
+    cp = context_find (buffer);
+    if (cp == NULL || *cp == '\0') {
+        snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name,
+                  ci->ci_type);
+        cp = context_find (buffer);
+    }
+    if (cp != NULL && *cp != '\0')
+        ce->ce_file = add (cp, ce->ce_file);
+
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
        return NOTOK;