]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
In test-mhfixmsg, look at configuration to see if iconv is enabled
[nmh] / uip / mhparse.c
index d12fbb30f5e394413ef052c55d4f677edfcaa87c..9873e0b184d679f420283f28d1b924939d2b5684 100644 (file)
@@ -1700,12 +1700,6 @@ openBase64 (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1723,9 +1717,22 @@ openBase64 (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (! ce->ce_unlink) {
-            ce->ce_file = add (cp, ce->ce_file);
-        }
+       if (ce->ce_unlink) {
+           /* Create temporary file with filename extension. */
+           if ((ce->ce_file = m_mktemps(invo_name, cp, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
+       } else {
+           ce->ce_file = add (cp, ce->ce_file);
+       }
+    } else if (*file == NULL) {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -1932,12 +1939,6 @@ openQuoted (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1955,9 +1956,22 @@ openQuoted (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (! ce->ce_unlink) {
-            ce->ce_file = add (cp, ce->ce_file);
-        }
+       if (ce->ce_unlink) {
+           /* Create temporary file with filename extension. */
+           if ((ce->ce_file = m_mktemps(invo_name, cp, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
+       } else {
+           ce->ce_file = add (cp, ce->ce_file);
+       }
+    } else if (*file == NULL) {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -2151,12 +2165,6 @@ open7Bit (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2174,9 +2182,22 @@ open7Bit (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (! ce->ce_unlink) {
-            ce->ce_file = add (cp, ce->ce_file);
-        }
+       if (ce->ce_unlink) {
+           /* Create temporary file with filename extension. */
+           if ((ce->ce_file = m_mktemps(invo_name, cp, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
+       } else {
+           ce->ce_file = add (cp, ce->ce_file);
+       }
+    } else if (*file == NULL) {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -3330,3 +3351,64 @@ bad_quote:
     *header_attrp = cp;
     return OK;
 }
+
+
+char *
+content_charset (CT ct) {
+    const char *const charset = "charset";
+    char *default_charset = NULL;
+    CI ctinfo = &ct->c_ctinfo;
+    char **ap, **vp;
+    char **src_charset = NULL;
+
+    for (ap = ctinfo->ci_attrs, vp = ctinfo->ci_values; *ap; ++ap, ++vp) {
+        if (! strcasecmp (*ap, charset)) {
+            src_charset = vp;
+            break;
+        }
+    }
+
+    /* RFC 2045, Sec. 5.2:  default to us-ascii. */
+    if (src_charset == NULL) src_charset = &default_charset;
+    if (*src_charset == NULL) *src_charset = "US-ASCII";
+
+    return *src_charset;
+}
+
+
+/* Change the value of a name=value pair in a header field body.
+   If the name isn't there, append them.  In any case, a new
+   string will be allocated and must be free'd by the caller.
+   Trims any trailing newlines. */
+char *
+update_attr (char *body, const char *name, const char *value) {
+    char *bp = nmh_strcasestr (body, name);
+    char *new_body;
+
+    if (bp) {
+        char *other_attrs = strchr (bp, ';');
+
+        *(bp + strlen (name)) = '\0';
+        new_body = concat (body, "\"", value, "\"", NULL);
+
+        if (other_attrs) {
+            char *cp;
+
+            /* Trim any trailing newlines. */
+            for (cp = &other_attrs[strlen (other_attrs) - 1];
+                 cp > other_attrs  &&  *cp == '\n';
+                 *cp-- = '\0') continue;
+            new_body = add (other_attrs, new_body);
+        }
+    } else {
+        char *cp;
+
+        /* Append name/value pair, after first removing a final newline
+           and (extraneous) semicolon. */
+        if (*(cp = &body[strlen (body) - 1]) == '\n') *cp = '\0';
+        if (*(cp = &body[strlen (body) - 1]) == ';') *cp = '\0';
+        new_body = concat (body, "; ", name, "\"", value, "\"", NULL);
+    }
+
+    return new_body;
+}