X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/29911a92cfff89a79410b861308658a5eb50d41a..9cc2510:/uip/mhbuildsbr.c diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index a05b4cbf..2a230385 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -145,7 +145,7 @@ build_mime (char *infile, int autobuild, int dist, int directives, /* * Allocate space for primary (outside) content */ - if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) + if ((ct = (CT) mh_xcalloc (1, sizeof(*ct))) == NULL) adios (NULL, "out of memory"); /* @@ -173,6 +173,7 @@ build_mime (char *infile, int autobuild, int dist, int directives, strcasecmp (name, ENCODING_FIELD) == 0) { if (autobuild) { fclose(in); + free (ct); return NULL; } else { adios (NULL, "draft shouldn't contain %s: field", name); @@ -294,7 +295,7 @@ finish_field: ct->c_type = CT_MULTIPART; ct->c_subtype = MULTI_MIXED; - if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) + if ((m = (struct multipart *) mh_xcalloc (1, sizeof(*m))) == NULL) adios (NULL, "out of memory"); ct->c_ctparams = (void *) m; pp = &m->mp_parts; @@ -314,7 +315,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 (NULL, "out of memory"); *pp = part; pp = &part->mp_next; @@ -335,7 +336,7 @@ finish_field: adios("reading", "Unable to open %s for", at_entry->filename); } - if ((p = (CT) calloc (1, sizeof(*p))) == NULL) + if ((p = (CT) mh_xcalloc (1, sizeof(*p))) == NULL) adios(NULL, "out of memory"); init_decoded_content(p, infile); @@ -348,7 +349,7 @@ finish_field: setup_attach_content(p, at_entry->filename); - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL) adios (NULL, "out of memory"); *pp = part; pp = &part->mp_next; @@ -369,7 +370,7 @@ finish_field: struct part *part; struct text *t; - if ((p = (CT) calloc (1, sizeof(*p))) == NULL) + if ((p = (CT) mh_xcalloc (1, sizeof(*p))) == NULL) adios(NULL, "out of memory"); init_decoded_content(p, infile); @@ -389,16 +390,15 @@ finish_field: p->c_begin = ftell(in); p->c_end = ftell(in); - if ((t = (struct text *) calloc (1, sizeof (*t))) == NULL) + if ((t = (struct text *) mh_xcalloc (1, sizeof (*t))) == NULL) adios (NULL, "out of memory"); t->tx_charset = CHARSET_SPECIFIED; p->c_ctparams = t; - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL) adios (NULL, "out of memory"); *pp = part; - pp = &part->mp_next; part->mp_part = p; } @@ -544,7 +544,7 @@ user_content (FILE *in, char *buf, CT *ctp, const char *infilename) } /* allocate basic Content structure */ - if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) + if ((ct = (CT) mh_xcalloc (1, sizeof(*ct))) == NULL) adios (NULL, "out of memory"); *ctp = ct; @@ -776,17 +776,16 @@ use_forw: * reference, we need to create another Content structure * for the message/external-body to wrap it in. */ - if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) + if ((ct = (CT) mh_xcalloc (1, sizeof(*ct))) == NULL) adios (NULL, "out of memory"); init_decoded_content(ct, infilename); *ctp = ct; - ci = &ct->c_ctinfo; if (get_ctinfo (buffer, ct, 0) == NOTOK) done (1); ct->c_type = CT_MESSAGE; ct->c_subtype = MESSAGE_EXTERNAL; - if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL) + if ((e = (struct exbody *) mh_xcalloc (1, sizeof(*e))) == NULL) adios (NULL, "out of memory"); ct->c_ctparams = (void *) e; @@ -827,14 +826,10 @@ use_forw: * No [file] argument, so check profile for * method to compose content. */ - snprintf (buffer, sizeof(buffer), "%s-compose-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) == NULL || *cp == '\0') { - snprintf (buffer, sizeof(buffer), "%s-compose-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) == NULL || *cp == '\0') { - content_error (NULL, ct, "don't know how to compose content"); - done (1); - } + cp = context_find_by_type ("compose", ci->ci_type, ci->ci_subtype); + if (cp == NULL) { + content_error (NULL, ct, "don't know how to compose content"); + done (1); } ci->ci_magic = add (cp, NULL); return OK; @@ -900,7 +895,7 @@ use_forw: ct->c_type = CT_MULTIPART; ct->c_subtype = MULTI_DIGEST; - if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) + if ((m = (struct multipart *) mh_xcalloc (1, sizeof(*m))) == NULL) adios (NULL, "out of memory"); ct->c_ctparams = (void *) m; pp = &m->mp_parts; @@ -911,7 +906,7 @@ use_forw: CT p; CE pe; - if ((p = (CT) calloc (1, sizeof(*p))) == NULL) + if ((p = (CT) mh_xcalloc (1, sizeof(*p))) == NULL) adios (NULL, "out of memory"); init_decoded_content (p, infilename); pe = &p->c_cefile; @@ -925,7 +920,7 @@ use_forw: if (listsw && stat (pe->ce_file, &st) != NOTOK) p->c_end = (long) st.st_size; - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL) adios (NULL, "out of memory"); *pp = part; pp = &part->mp_next; @@ -986,7 +981,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 (NULL, "out of memory"); ct->c_ctparams = (void *) m; @@ -1003,7 +998,7 @@ use_forw: if (!p) continue; - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL) adios (NULL, "out of memory"); *pp = part; pp = &part->mp_next; @@ -1480,9 +1475,16 @@ scan_content (CT ct, size_t maxunencoded) t = (struct text *) ct->c_ctparams; if (t->tx_charset == CHARSET_UNSPECIFIED) { CI ci = &ct->c_ctinfo; + char *eightbitcharset = write_charset_8bit(); + + if (contains8bit && strcasecmp(eightbitcharset, "US-ASCII") == 0) { + adios(NULL, "Text content contains 8 bit characters, but " + "character set is US-ASCII"); + } add_param(&ci->ci_first_pm, &ci->ci_last_pm, "charset", - contains8bit ? write_charset_8bit() : "us-ascii", 0); + contains8bit ? eightbitcharset : "us-ascii", 0); + t->tx_charset = CHARSET_SPECIFIED; } } @@ -1511,7 +1513,7 @@ scan_content (CT ct, size_t maxunencoded) /* For application type, use base64, except when postscript */ if (wants_q_p || contains8bit) { if (ct->c_subtype == APPLICATION_POSTSCRIPT) - ct->c_encoding = CE_QUOTED; // historical + ct->c_encoding = CE_QUOTED; /* historical */ else ct->c_encoding = CE_BASE64; } else { @@ -1863,8 +1865,7 @@ setup_attach_content(CT ct, char *filename) char *type, *simplename = r1bindex(filename, '/'); struct str2init *s2i; PM pm; - char buffer[BUFSIZ], *cp; - int no_subtype = 0; + char *cp; if (! (type = mime_type(filename))) { adios(NULL, "Unable to determine MIME type of \"%s\"", filename); @@ -1944,24 +1945,16 @@ setup_attach_content(CT ct, char *filename) * 'attachment'. */ - snprintf (buffer, sizeof(buffer), "%s-disposition-%s/%s", - invo_name, ct->c_ctinfo.ci_type, ct->c_ctinfo.ci_subtype); - cp = context_find (buffer); - if (cp == NULL || *cp == '\0') { - no_subtype = 1; - snprintf (buffer, sizeof(buffer), "%s-disposition-%s", invo_name, - ct->c_ctinfo.ci_type); - cp = context_find (buffer); - } - if (cp != NULL && *cp != '\0') { - if (strcasecmp (cp, "attachment") && - strcasecmp (cp, "inline")) { + cp = context_find_by_type ("disposition", ct->c_ctinfo.ci_type, + ct->c_ctinfo.ci_subtype); + if (cp != NULL) { + if (strcasecmp (cp, "attachment") && strcasecmp (cp, "inline")) { admonish (NULL, "configuration problem: %s-disposition-%s%s%s " "specifies '%s' but only 'attachment' and 'inline' are " "allowed", invo_name, ct->c_ctinfo.ci_type, - no_subtype ? "" : "/", - no_subtype ? "" : ct->c_ctinfo.ci_subtype, + ct->c_ctinfo.ci_subtype ? "/" : "", + ct->c_ctinfo.ci_subtype ? ct->c_ctinfo.ci_subtype : "", cp); } }