]> diplodocus.org Git - nmh/blobdiff - uip/mhoutsbr.c
Use a dynamically-allocated buffer for character set conversion, and
[nmh] / uip / mhoutsbr.c
index 7c3cbe99285a6cf3fa873ddecafb4c97a44fe87d..8f19702c5310889f72d845c84a01b2199721a0f8 100644 (file)
@@ -81,15 +81,10 @@ output_content (CT ct, FILE *out)
 {
     int result = 0;
     CI ci = &ct->c_ctinfo;
-    PM pm;
-    char *boundary = "";
+    char *boundary = "", *cp;
 
-    for (pm = ci->ci_first_pm; pm; pm = pm->pm_next) {
-        if (! strcasecmp ("boundary", pm->pm_name)) {
-            boundary = pm->pm_value;
-            break;
-        }
-    }
+    if ((cp = get_param(ci->ci_first_pm, "boundary", '-', 0)))
+       boundary = cp;
 
     /*
      * Output all header fields for this content
@@ -101,8 +96,11 @@ output_content (CT ct, FILE *out)
      * "message/external", then we are done with the
      * headers (since it has no body).
      */
-    if (ct->c_ctexbody)
+    if (ct->c_ctexbody) {
+       if (boundary && *boundary != '\0')
+           free(boundary);
        return OK;
+    }
 
     /*
      * Now output the content bodies.
@@ -126,8 +124,11 @@ output_content (CT ct, FILE *out)
            CT p = part->mp_part;
 
            fprintf (out, "\n--%s\n", boundary);
-           if (output_content (p, out) == NOTOK)
+           if (output_content (p, out) == NOTOK) {
+               if (boundary && *boundary != '\0')
+                   free(boundary);
                return NOTOK;
+           }
        }
        fprintf (out, "\n--%s--\n", boundary);
 
@@ -199,6 +200,9 @@ output_content (CT ct, FILE *out)
        break;
     }
 
+    if (boundary && *boundary != '\0')
+       free(boundary);
+
     return result;
 }
 
@@ -227,8 +231,7 @@ output_headers (CT ct, FILE *out)
 static int
 writeExternalBody (CT ct, FILE *out)
 {
-    char *cp;
-    PM pm;
+    char *cp, *dp;
     struct exbody *e = (struct exbody *) ct->c_ctparams;
                
     putc ('\n', out);
@@ -240,7 +243,7 @@ writeExternalBody (CT ct, FILE *out)
            switch (*++cp) {
            case 'I':
                if (ct2->c_id) {
-                   char *dp = trimcpy (ct2->c_id);
+                   dp = trimcpy (ct2->c_id);
 
                    fputs (dp, out);
                    free (dp);
@@ -248,17 +251,22 @@ writeExternalBody (CT ct, FILE *out)
                continue;
 
            case 'N':
-               for (pm = ci2->ci_first_pm; pm; pm = pm->pm_next)
-                   if (!strcasecmp (pm->pm_name, "name")) {
-                       fprintf (out, "%s", pm->pm_value);
-                       break;
-                   }
+               dp = get_param(ci2->ci_first_pm, "name", '_', 0);
+               if (dp) {
+                   fputs (dp, out);
+                   free (dp);
+               }
                continue;
 
            case 'T':
                fprintf (out, "%s/%s", ci2->ci_type, ci2->ci_subtype);
-               for (pm = ci2->ci_first_pm; pm; pm = pm->pm_next)
-                   fprintf (out, "; %s=\"%s\"", pm->pm_name, pm->pm_value);
+               dp = output_params(strlen(ci2->ci_type) +
+                                  strlen(ci2->ci_subtype) + 1,
+                                  ci2->ci_first_pm, NULL, 0);
+               if (dp) {
+                   fputs (dp, out);
+                   free (dp);
+               }
                continue;
 
            case 'n':