X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8c7b880eb8e42c3f51063aa3c3c2520b18777b53..fb6b8301237bcdd72bb86d34af68f378a07e4d70:/uip/mhparse.c?ds=sidebyside diff --git a/uip/mhparse.c b/uip/mhparse.c index 4cff8b9a..85c32924 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -34,13 +34,16 @@ int checksw = 0; /* check Content-MD5 field */ * in a multipart. * 2) Suppress the warning about bogus multipart content, and report it. * 3) Suppress the warning about extraneous trailing ';' in header parameter - * lists, and report it. + * lists. */ int skip_mp_cte_check; int suppress_bogus_mp_content_warning; int bogus_mp_content; int suppress_extraneous_trailing_semicolon_warning; -int extraneous_trailing_semicolon; + +/* + * By default, suppress warning about multiple MIME-Version header fields. + */ int suppress_multiple_mime_version_warning = 1; /* list of preferred type/subtype pairs, for -prefer */ @@ -207,6 +210,8 @@ parse_mime (char *file) CT ct; size_t n; + bogus_mp_content = 0; + /* * Check if file is actually standard input */ @@ -217,7 +222,7 @@ parse_mime (char *file) get_temp_dir()); return NULL; } - file = add (tfile, NULL); + file = mh_xstrdup(tfile); while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) { if (fwrite(buffer, 1, n, fp) != n) { @@ -312,8 +317,8 @@ get_content (FILE *in, char *file, int toplevel) compnum++; /* get copies of the buffers */ - np = add (name, NULL); - vp = add (buf, NULL); + np = mh_xstrdup(name); + vp = mh_xstrdup(buf); /* if necessary, get rest of field */ while (state == FLDPLUS) { @@ -649,7 +654,7 @@ get_ctinfo (char *cp, CT ct, int magic) for (dp = cp; istoken (*dp); dp++) continue; c = *dp, *dp = '\0'; - ci->ci_type = add (cp, NULL); /* store content type */ + ci->ci_type = mh_xstrdup(cp); /* store content type */ *dp = c, cp = dp; if (!*ci->ci_type) { @@ -657,10 +662,7 @@ get_ctinfo (char *cp, CT ct, int magic) TYPE_FIELD, ct->c_file); return NOTOK; } - - /* down case the content type string */ - for (dp = ci->ci_type; *dp; dp++) - *dp = tolower ((unsigned char) *dp); + to_lower(ci->ci_type); while (isspace ((unsigned char) *cp)) cp++; @@ -671,7 +673,7 @@ get_ctinfo (char *cp, CT ct, int magic) if (*cp != '/') { if (!magic) - ci->ci_subtype = add ("", NULL); + ci->ci_subtype = mh_xstrdup(""); goto magic_skip; } @@ -686,7 +688,7 @@ get_ctinfo (char *cp, CT ct, int magic) for (dp = cp; istoken (*dp); dp++) continue; c = *dp, *dp = '\0'; - ci->ci_subtype = add (cp, NULL); /* store the content subtype */ + ci->ci_subtype = mh_xstrdup(cp); /* store the content subtype */ *dp = c, cp = dp; if (!*ci->ci_subtype) { @@ -695,10 +697,7 @@ get_ctinfo (char *cp, CT ct, int magic) TYPE_FIELD, ct->c_file, ci->ci_type); return NOTOK; } - - /* down case the content subtype string */ - for (dp = ci->ci_subtype; *dp; dp++) - *dp = tolower ((unsigned char) *dp); + to_lower(ci->ci_subtype); magic_skip: while (isspace ((unsigned char) *cp)) @@ -718,10 +717,8 @@ magic_skip: * Get any given in buffer */ if (magic && *cp == '<') { - if (ct->c_id) { - free (ct->c_id); - ct->c_id = NULL; - } + mh_xfree(ct->c_id); + ct->c_id = NULL; if (!(dp = strchr(ct->c_id = ++cp, '>'))) { advise (NULL, "invalid ID in message %s", ct->c_file); return NOTOK; @@ -839,7 +836,7 @@ magic_skip: */ if (*cp) { if (magic) { - ci->ci_magic = add (cp, NULL); + ci->ci_magic = mh_xstrdup(cp); /* If there is a Content-Disposition header and it doesn't have a *filename=, extract it from the magic contents. @@ -906,7 +903,7 @@ get_dispo (char *cp, CT ct, int buildflag) for (dp = cp; istoken (*dp); dp++) continue; c = *dp, *dp = '\0'; - ct->c_dispo_type = add (cp, NULL); /* store disposition type */ + ct->c_dispo_type = mh_xstrdup(cp); /* store disposition type */ *dp = c, cp = dp; if (*cp == '(' && get_comment (ct->c_file, DISPO_FIELD, &cp, NULL) == NOTOK) @@ -983,7 +980,7 @@ invalid: *commentp = concat (dp, " ", buffer, NULL); free (dp); } else { - *commentp = add (buffer, NULL); + *commentp = mh_xstrdup(buffer); } } @@ -1095,7 +1092,7 @@ InitMultiPart (CT ct) ct->c_encoding != CE_8BIT && ct->c_encoding != CE_BINARY) { /* Copy the Content-Transfer-Encoding header field body so we can remove any trailing whitespace and leading blanks from it. */ - char *cte = add (ct->c_celine ? ct->c_celine : "(null)", NULL); + char *cte = mh_xstrdup(ct->c_celine ? ct->c_celine : "(null)"); bp = cte + strlen (cte) - 1; while (bp >= cte && isspace ((unsigned char) *bp)) *bp-- = '\0'; @@ -1228,7 +1225,7 @@ end_part: continue; *next = NULL; free_content (p); - free ((char *) part); + free(part); } } @@ -1260,7 +1257,7 @@ last_part: p = part->mp_part; sprintf (pp, "%d", partnum); - p->c_partno = add (partnam, NULL); + p->c_partno = mh_xstrdup(partnam); /* initialize the content of the subparts */ if (p->c_ctinitfnx && (*p->c_ctinitfnx) (p) == NOTOK) { @@ -1767,7 +1764,7 @@ openBase64 (CT ct, char **file) if (*file == NULL) { ce->ce_unlink = 1; } else { - ce->ce_file = add (*file, NULL); + ce->ce_file = mh_xstrdup(*file); ce->ce_unlink = 0; } @@ -1789,7 +1786,7 @@ openBase64 (CT ct, char **file) adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } - ce->ce_file = add (tempfile, NULL); + ce->ce_file = mh_xstrdup(tempfile); } if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { @@ -1840,7 +1837,7 @@ openBase64 (CT ct, char **file) for (i = 0; i < decoded_len; ++i) { putc (*decoded_p++, ce->ce_fp); } - free ((char *) decoded); + free(decoded); if (ferror (ce->ce_fp)) { content_error (ce->ce_file, ct, "error writing to"); goto clean_up; @@ -1951,7 +1948,7 @@ openQuoted (CT ct, char **file) if (*file == NULL) { ce->ce_unlink = 1; } else { - ce->ce_file = add (*file, NULL); + ce->ce_file = mh_xstrdup(*file); ce->ce_unlink = 0; } @@ -1973,7 +1970,7 @@ openQuoted (CT ct, char **file) adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } - ce->ce_file = add (tempfile, NULL); + ce->ce_file = mh_xstrdup(tempfile); } if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { @@ -2171,7 +2168,7 @@ open7Bit (CT ct, char **file) if (*file == NULL) { ce->ce_unlink = 1; } else { - ce->ce_file = add (*file, NULL); + ce->ce_file = mh_xstrdup(*file); ce->ce_unlink = 0; } @@ -2193,7 +2190,7 @@ open7Bit (CT ct, char **file) adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } - ce->ce_file = add (tempfile, NULL); + ce->ce_file = mh_xstrdup(tempfile); } if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { @@ -2536,16 +2533,16 @@ openFTP (CT ct, char **file) } if (*file) - ce->ce_file = add (*file, NULL); + ce->ce_file = mh_xstrdup(*file); else if (caching) - ce->ce_file = add (cachefile, NULL); + ce->ce_file = mh_xstrdup(cachefile); else { 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_file = mh_xstrdup(tempfile); } if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { @@ -2734,10 +2731,10 @@ openMail (CT ct, char **file) adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } - ce->ce_file = add (tempfile, NULL); + ce->ce_file = mh_xstrdup(tempfile); ce->ce_unlink = 1; } else { - ce->ce_file = add (*file, NULL); + ce->ce_file = mh_xstrdup(*file); ce->ce_unlink = 0; } @@ -2748,9 +2745,8 @@ openMail (CT ct, char **file) /* showproc is for mhshow and mhstore, though mhlist -debug * prints it, too. */ - if (ct->c_showproc) - free (ct->c_showproc); - ct->c_showproc = add ("true", NULL); + mh_xfree(ct->c_showproc); + ct->c_showproc = mh_xstrdup("true"); fseek (ce->ce_fp, 0L, SEEK_SET); *file = ce->ce_file; @@ -2817,16 +2813,16 @@ openURL (CT ct, char **file) } if (*file) - ce->ce_file = add(*file, NULL); + ce->ce_file = mh_xstrdup(*file); else if (caching) - ce->ce_file = add(cachefile, NULL); + ce->ce_file = mh_xstrdup(cachefile); else { 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_file = mh_xstrdup(tempfile); } if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) { @@ -3291,7 +3287,6 @@ parse_header_attrs (const char *filename, const char *fieldname, "parameter list", filename, fieldname); } - extraneous_trailing_semicolon = 1; return DONE; } @@ -3406,8 +3401,7 @@ parse_header_attrs (const char *filename, const char *fieldname, "field\n%*s(parameter %s)", filename, fieldname, strlen(invo_name) + 2, "", nameptr); free(nameptr); - if (charset) - free(charset); + mh_xfree(charset); return NOTOK; } @@ -3432,10 +3426,8 @@ parse_header_attrs (const char *filename, const char *fieldname, filename, fieldname, strlen(invo_name) + 2, "", nameptr); free(nameptr); - if (charset) - free(charset); - if (lang) - free(lang); + mh_xfree(charset); + mh_xfree(lang); return NOTOK; } vp += 2; @@ -3478,10 +3470,8 @@ bad_quote: filename, fieldname, strlen(invo_name) + 2, "", nameptr); free(nameptr); - if (charset) - free(charset); - if (lang) - free(lang); + mh_xfree(charset); + mh_xfree(lang); return NOTOK; case '"': break; @@ -3533,8 +3523,11 @@ bad_quote: if (partial) { for (pp = phead; pp != NULL; pp = pp->next) { - if (strcasecmp(nameptr, pp->name) == 0) + if (strcasecmp(nameptr, pp->name) == 0) { + free (nameptr); + nameptr = pp->name; break; + } } if (pp == NULL) { @@ -3563,7 +3556,6 @@ bad_quote: "%s's %s: field\n%*s(parameter %s)", sp->index, filename, fieldname, strlen(invo_name) + 2, "", nameptr); - free (nameptr); return NOTOK; } if (sp2->index < sp->index && @@ -3579,7 +3571,6 @@ bad_quote: "param in message %s's %s: field\n%*s(parameter %s)", filename, fieldname, strlen(invo_name) + 2, "", nameptr); - free (nameptr); return NOTOK; } } @@ -3589,11 +3580,9 @@ bad_quote: */ if (index == 0 && encoded) { - if (pp->charset) - free(pp->charset); + mh_xfree(pp->charset); pp->charset = charset; - if (pp->lang) - free(pp->lang); + mh_xfree(pp->lang); pp->lang = lang; } } else { @@ -3693,8 +3682,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external) if (strlen(params->pm_name) > CPERLIN) { advise(NULL, "Parameter name \"%s\" is too long", params->pm_name); - if (paramout) - free(paramout); + mh_xfree(paramout); return NULL; } @@ -3731,8 +3719,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external) numchars, valoff); if (i == 0) { - if (paramout) - free(paramout); + mh_xfree(paramout); return NULL; } @@ -3795,8 +3782,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external) strlen(params->pm_value + valoff), valoff); if (i == 0) { - if (paramout) - free(paramout); + mh_xfree(paramout); return NULL; } @@ -4242,13 +4228,13 @@ noiconv: #endif /* HAVE_ICONV */ /* - * Take everything non-ASCII and substituite the replacement character + * Take everything non-ASCII and substitute the replacement character */ q = buffer; bufsize = sizeof(buffer); for (p = pm->pm_value; *p != '\0' && bufsize > 1; p++, q++, bufsize--) { - if (isascii((unsigned char) *p) && !iscntrl((unsigned char) *p)) + if (isascii((unsigned char) *p) && isprint((unsigned char) *p)) *q = *p; else *q = replace;