Coding style adjustments for nmh-imported code
[mmh] / uip / mhbuild.c
index de2cf45..1fdedb6 100644 (file)
@@ -319,6 +319,7 @@ build_mime(char *infile)
        struct part **pp;
        CT ct;
        FILE *in;
+       HF hp;
 
        umask(~m_gmprot());
 
@@ -329,7 +330,7 @@ build_mime(char *infile)
        /*
        ** Allocate space for primary (outside) content
        */
-       if ((ct = (CT) calloc(1, sizeof(*ct))) == NULL)
+       if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
                adios(EX_OSERR, NULL, "out of memory");
 
        /*
@@ -411,6 +412,16 @@ finish_field:
        }
 
        /*
+       ** Iterate through the list of headers and call the function to
+       ** MIME-ify them if required.
+       */
+       for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) {
+               if (encode_rfc2047(hp->name, &hp->value, NULL)) {
+                       adios(EX_DATAERR, NULL, "Unable to encode header \"%s\"", hp->name);
+               }
+       }
+
+       /*
        ** Now add the MIME-Version header field
        ** to the list of header fields.
        */
@@ -430,7 +441,7 @@ finish_field:
        ct->c_subtype = MULTI_MIXED;
        ct->c_file = getcpy(infile);
 
-       if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
+       if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
                adios(EX_OSERR, NULL, "out of memory");
        ct->c_ctparams = (void *) m;
        pp = &m->mp_parts;
@@ -450,7 +461,7 @@ finish_field:
                if (!p)
                        continue;
 
-               if ((part = (struct part *) calloc(1, sizeof(*part))) == NULL)
+               if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
                        adios(EX_OSERR, NULL, "out of memory");
                *pp = part;
                pp = &part->mp_next;
@@ -531,7 +542,7 @@ init_decoded_content(CT ct)
 {
        CE ce;
 
-       if ((ce = (CE) calloc(1, sizeof(*ce))) == NULL)
+       if ((ce = (CE) mh_xcalloc(1, sizeof(*ce))) == NULL)
                adios(EX_OSERR, NULL, "out of memory");
 
        ct->c_cefile     = ce;
@@ -592,7 +603,7 @@ user_content(FILE *in, char *file, char *buf, CT *ctp)
        }
 
        /* allocate basic Content structure */
-       if ((ct = (CT) calloc(1, sizeof(*ct))) == NULL)
+       if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
                adios(EX_OSERR, NULL, "out of memory");
        *ctp = ct;
 
@@ -902,7 +913,7 @@ use_forw:
                        ct->c_subtype = MULTI_DIGEST;
 
                        if ((m = (struct multipart *)
-                                       calloc(1, sizeof(*m))) == NULL)
+                                       mh_xcalloc(1, sizeof(*m))) == NULL)
                                adios(EX_OSERR, NULL, "out of memory");
                        ct->c_ctparams = (void *) m;
                        pp = &m->mp_parts;
@@ -913,7 +924,7 @@ use_forw:
                                        CT p;
                                        CE pe;
 
-                                       if ((p = (CT) calloc(1, sizeof(*p)))
+                                       if ((p = (CT) mh_xcalloc(1, sizeof(*p)))
                                                        == NULL)
                                                adios(EX_OSERR, NULL, "out of memory");
                                        init_decoded_content(p);
@@ -929,7 +940,7 @@ use_forw:
                                                        msgnum);
                                        pe->ce_file = getcpy(buffer);
 
-                                       if ((part = (struct part *) calloc(1, sizeof(*part))) == NULL)
+                                       if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
                                                adios(EX_OSERR, NULL, "out of memory");
                                        *pp = part;
                                        pp = &part->mp_next;
@@ -989,7 +1000,7 @@ use_forw:
                ct->c_type = CT_MULTIPART;
                ct->c_subtype = vrsn;
 
-               if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
+               if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
                        adios(EX_OSERR, NULL, "out of memory");
                ct->c_ctparams = (void *) m;
 
@@ -1007,7 +1018,7 @@ use_forw:
                                continue;
 
                        if ((part = (struct part *)
-                                       calloc(1, sizeof(*part))) == NULL)
+                                       mh_xcalloc(1, sizeof(*part))) == NULL)
                                adios(EX_OSERR, NULL, "out of memory");
                        *pp = part;
                        pp = &part->mp_next;
@@ -1529,6 +1540,9 @@ build_headers(CT ct)
        if (ct->c_descr) {
                np = getcpy(DESCR_FIELD);
                vp = concat(" ", ct->c_descr, NULL);
+               if (encode_rfc2047(DESCR_FIELD, &vp, NULL)) {
+                       adios(EX_DATAERR, NULL, "Unable to encode %s header", DESCR_FIELD);
+               }
                add_header(ct, np, vp);
        }