]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Escape literal leading full stop in man/new.man.
[nmh] / uip / mhparse.c
index 40fe61d5f8fe69c95438cd145abc481a6b576044..a2dcb88c2e49503f78da26a6e4a72bce5fd02a8c 100644 (file)
@@ -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 */
@@ -206,6 +209,9 @@ parse_mime (char *file)
     FILE *fp;
     CT ct;
     size_t n;
+    struct stat statbuf;
+
+    bogus_mp_content = 0;
 
     /*
      * Check if file is actually standard input
@@ -217,7 +223,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) {
@@ -239,6 +245,13 @@ parse_mime (char *file)
            return NULL;
        }
        fseek (fp, 0L, SEEK_SET);
+    } else if (lstat (file, &statbuf) == NOTOK) {
+       advise (file, "unable to lstat");
+       return NULL;
+    } else if (S_ISDIR(statbuf.st_mode)) {
+       /* Don't try to parse a directory. */
+       advise (NULL, "%s is a directory", file);
+       return NULL;
     } else if ((fp = fopen (file, "r")) == NULL) {
        advise (file, "unable to read");
        return NULL;
@@ -294,9 +307,7 @@ get_content (FILE *in, char *file, int toplevel)
     m_getfld_state_t gstate = 0;
 
     /* allocate the content structure */
-    if (!(ct = (CT) mh_xcalloc (1, sizeof(*ct))))
-       adios (NULL, "out of memory");
-
+    NEW0(ct);
     ct->c_fp = in;
     ct->c_file = add (file, NULL);
     ct->c_begin = ftell (ct->c_fp) + 1;
@@ -314,8 +325,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) {
@@ -332,7 +343,15 @@ get_content (FILE *in, char *file, int toplevel)
            continue;
 
        case BODY:
-           ct->c_begin = ftell (in) - strlen (buf);
+           if (name[0] == ':') {
+               /* Special case:  no blank line between header and body.  The
+                  file position indicator is on the newline at the end of the
+                  line, but it needs to be one prior to the beginning of the
+                  line.  So subtract the length of the line, bufsz, plus 1. */
+               ct->c_begin = ftell (in) - (bufsz + 1);
+           } else {
+               ct->c_begin = ftell (in) - (bufsz - 1);
+           }
            break;
 
        case FILEEOF:
@@ -583,7 +602,7 @@ add_header (CT ct, char *name, char *value)
     HF hp;
 
     /* allocate header field structure */
-    hp = mh_xmalloc (sizeof(*hp));
+    NEW(hp);
 
     /* link data into header structure */
     hp->name = name;
@@ -643,7 +662,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) {
@@ -651,11 +670,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++)
-       if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
-           *dp = tolower ((unsigned char) *dp);
+    to_lower(ci->ci_type);
 
     while (isspace ((unsigned char) *cp))
        cp++;
@@ -666,7 +681,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;
     }
 
@@ -681,7 +696,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) {
@@ -690,11 +705,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++)
-       if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
-           *dp = tolower ((unsigned char) *dp);
+    to_lower(ci->ci_subtype);
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
@@ -714,10 +725,8 @@ magic_skip:
      * Get any <Content-Id> 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;
@@ -835,7 +844,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.
@@ -902,7 +911,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)
@@ -959,7 +968,7 @@ invalid:
 
        case '(':
            i++;
-           /* and fall... */
+           /* FALLTHRU */
        default:
            *bp++ = c;
            continue;
@@ -979,7 +988,7 @@ invalid:
            *commentp = concat (dp, " ", buffer, NULL);
            free (dp);
        } else {
-           *commentp = add (buffer, NULL);
+           *commentp = mh_xstrdup(buffer);
        }
     }
 
@@ -1029,8 +1038,7 @@ InitText (CT ct)
     ct->c_subtype = ct_str_subtype (CT_TEXT, ci->ci_subtype);
 
     /* allocate text character set structure */
-    if ((t = (struct text *) mh_xcalloc (1, sizeof(*t))) == NULL)
-       adios (NULL, "out of memory");
+    NEW0(t);
     ct->c_ctparams = (void *) t;
 
     /* scan for charset parameter */
@@ -1056,7 +1064,7 @@ InitText (CT ct)
     if (chset != NULL && !check_charset (chset, strlen (chset))) {
        snprintf (buffer, sizeof(buffer), "%s-charset-%s", invo_name, chset);
        if ((cp = context_find (buffer)))
-           ct->c_termproc = getcpy (cp);
+           ct->c_termproc = mh_xstrdup(cp);
     }
 
     return OK;
@@ -1092,7 +1100,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';
@@ -1134,8 +1142,7 @@ InitMultiPart (CT ct)
     }
 
     /* allocate primary structure for multipart info */
-    if ((m = (struct multipart *) mh_xcalloc (1, sizeof(*m))) == NULL)
-       adios (NULL, "out of memory");
+    NEW0(m);
     ct->c_ctparams = (void *) m;
 
     /* check if boundary parameter contains only whitespace characters */
@@ -1179,8 +1186,7 @@ InitMultiPart (CT ct)
            if (strcmp (bufp + 2, m->mp_start))
                continue;
 next_part:
-           if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL)
-               adios (NULL, "out of memory");
+           NEW0(part);
            *next = part;
            next = &part->mp_next;
 
@@ -1206,10 +1212,9 @@ end_part:
                if (inout)
                    goto next_part;
                goto last_part;
-           } else {
-               if (strcmp (bufp + 2, m->mp_stop) == 0)
-                   goto end_part;
            }
+            if (strcmp (bufp + 2, m->mp_stop) == 0)
+                goto end_part;
        }
     }
 
@@ -1228,7 +1233,7 @@ end_part:
                continue;
            *next = NULL;
            free_content (p);
-           free ((char *) part);
+           free(part);
        }
     }
 
@@ -1260,7 +1265,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) {
@@ -1419,8 +1424,7 @@ InitMessage (CT ct)
                PM pm;
                struct partial *p;
 
-               if ((p = (struct partial *) mh_xcalloc (1, sizeof(*p))) == NULL)
-                   adios (NULL, "out of memory");
+               NEW0(p);
                ct->c_ctparams = (void *) p;
 
                /* scan for parameters "id", "number", and "total" */
@@ -1468,8 +1472,7 @@ invalid_param:
                CT p;
                FILE *fp;
 
-               if ((e = (struct exbody *) mh_xcalloc (1, sizeof(*e))) == NULL)
-                   adios (NULL, "out of memory");
+               NEW0(e);
                ct->c_ctparams = (void *) e;
 
                if (!ct->c_fp
@@ -1536,7 +1539,7 @@ no_body:
                    case CT_MESSAGE:
                        if (p->c_subtype != MESSAGE_RFC822)
                            break;
-                       /* else fall... */
+                       /* FALLTHRU */
                    default:
                        e->eb_partno = ct->c_partno;
                        if (p->c_ctinitfnx)
@@ -1709,8 +1712,7 @@ size_encoding (CT ct)
     if (ce->ce_file) {
        if (stat (ce->ce_file, &st) != NOTOK)
            return (long) st.st_size;
-       else
-           return 0L;
+        return 0L;
     }
 
     if (ct->c_encoding == CE_EXTERNAL)
@@ -1770,7 +1772,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;
     }
 
@@ -1792,7 +1794,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) {
@@ -1843,7 +1845,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;
@@ -1954,7 +1956,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;
     }
 
@@ -1976,7 +1978,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) {
@@ -2174,7 +2176,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;
     }
 
@@ -2196,7 +2198,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) {
@@ -2329,12 +2331,11 @@ openExternal (CT ct, CT cb, CE ce, char **file, int *fd)
     if (find_cache (ct, rcachesw, (int *) 0, cb->c_id,
                cachefile, sizeof(cachefile)) != NOTOK) {
        if ((ce->ce_fp = fopen (cachefile, "r"))) {
-           ce->ce_file = getcpy (cachefile);
+           ce->ce_file = mh_xstrdup(cachefile);
            ce->ce_unlink = 0;
            goto ready_already;
-       } else {
-           admonish (cachefile, "unable to fopen for reading");
        }
+        admonish (cachefile, "unable to fopen for reading");
     }
 
     *fd = fileno (ce->ce_fp);
@@ -2381,7 +2382,7 @@ openFile (CT ct, char **file)
        return NOTOK;
     }
 
-    ce->ce_file = getcpy (e->eb_name);
+    ce->ce_file = mh_xstrdup(e->eb_name);
     ce->ce_unlink = 0;
 
     if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) {
@@ -2522,7 +2523,7 @@ openFTP (CT ct, char **file)
                  LocalName (1));
        pass = buffer;
     } else {
-       ruserpass (e->eb_site, &username, &password);
+       ruserpass (e->eb_site, &username, &password, 0);
        user = username;
        pass = password;
     }
@@ -2540,16 +2541,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) {
@@ -2738,10 +2739,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;
     }
 
@@ -2752,9 +2753,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;
@@ -2821,16 +2821,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) {
@@ -2926,17 +2926,16 @@ readDigest (CT ct, char *cp)
             }
 
             return OK;
-        } else {
-            if (debugsw) {
-                fprintf (stderr, "invalid MD5 digest (got %d octets)\n",
-                         (int) strlen ((char *) digest));
-            }
-
-            return NOTOK;
         }
-    } else {
+        if (debugsw) {
+            fprintf (stderr, "invalid MD5 digest (got %d octets)\n",
+                     (int) strlen ((char *) digest));
+        }
+
         return NOTOK;
     }
+
+    return NOTOK;
 }
 
 
@@ -3296,14 +3295,12 @@ parse_header_attrs (const char *filename, const char *fieldname,
                        "parameter list",
                        filename, fieldname);
            }
-           extraneous_trailing_semicolon = 1;
            return DONE;
        }
 
        /* down case the attribute name */
        for (dp = cp; istoken ((unsigned char) *dp); dp++)
-           if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
-               *dp = tolower ((unsigned char) *dp);
+            *dp = tolower ((unsigned char) *dp);
 
        for (up = dp; isspace ((unsigned char) *dp);)
            dp++;
@@ -3412,8 +3409,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;
                }
 
@@ -3438,10 +3434,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;
@@ -3484,10 +3478,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;
@@ -3495,7 +3487,7 @@ bad_quote:
                    case '\\':
                        if (*++cp == '\0')
                            goto bad_quote;
-                       /* FALL THROUGH */
+                       /* FALLTHRU */
                    default:
                        len++;
                        continue;
@@ -3539,13 +3531,15 @@ 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) {
-               pp = mh_xmalloc(sizeof(*pp));
-               memset(pp, 0, sizeof(*pp));
+               NEW0(pp);
                pp->name = nameptr;
                pp->next = phead;
                phead = pp;
@@ -3555,8 +3549,7 @@ bad_quote:
             * Insert this into the section linked list
             */
 
-           sp = mh_xmalloc(sizeof(*sp));
-           memset(sp, 0, sizeof(*sp));
+           NEW0(sp);
            sp->value = valptr;
            sp->index = index;
            sp->len = len;
@@ -3571,7 +3564,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 &&
@@ -3587,7 +3579,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;
                }
            }
@@ -3597,11 +3588,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 {
@@ -3672,7 +3661,7 @@ content_charset (CT ct) {
 
     ret_charset = get_param(ct->c_ctinfo.ci_first_pm, "charset", '?', 0);
 
-    return ret_charset ? ret_charset : getcpy ("US-ASCII");
+    return ret_charset ? ret_charset : mh_xstrdup("US-ASCII");
 }
 
 
@@ -3701,8 +3690,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;
        }
 
@@ -3739,8 +3727,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;
            }
 
@@ -3803,8 +3790,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;
        }
 
@@ -3903,13 +3889,13 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont,
         */
 
        if (! pm->pm_charset) {
-           pm->pm_charset = getcpy(write_charset_8bit());
+           pm->pm_charset = mh_xstrdup(write_charset_8bit());
            if (strcasecmp(pm->pm_charset, "US-ASCII") == 0)
                adios(NULL, "8-bit characters in parameter \"%s\", but "
                      "local character set is US-ASCII", pm->pm_name);
        }
        if (! pm->pm_lang)
-           pm->pm_lang = getcpy(NULL); /* Default to a blank lang tag */
+           pm->pm_lang = mh_xstrdup("");       /* Default to a blank lang tag */
 
        len++;          /* For the encoding marker */
        maxfit--;
@@ -3953,7 +3939,7 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont,
            case '\\':
                len++;
                maxfit--;
-           /* FALL THROUGH */
+           /* FALLTHRU */
            default:
                len++;
                maxfit--;
@@ -4061,6 +4047,7 @@ normal_param(PM pm, char *output, size_t len, size_t valuelen,
        case '"':
            *output++ = '\\';
            outlen++;
+           /* FALLTHRU */
        default:
            *output++ = *p++;
            outlen++;
@@ -4089,10 +4076,9 @@ normal_param(PM pm, char *output, size_t len, size_t valuelen,
 PM
 add_param(PM *first, PM *last, char *name, char *value, int nocopy)
 {
-    PM pm = mh_xmalloc(sizeof(*pm));
-
-    memset(pm, 0, sizeof(*pm));
+    PM pm;
 
+    NEW0(pm);
     pm->pm_name = nocopy ? name : getcpy(name);
     pm->pm_value = nocopy ? value : getcpy(value);
 
@@ -4146,8 +4132,7 @@ get_param(PM first, const char *name, char replace, int fetchonly)
        if (strcasecmp(name, first->pm_name) == 0) {
            if (fetchonly)
                return first->pm_value;
-           else
-               return getcpy(get_param_value(first, replace));
+            return getcpy(get_param_value(first, replace));
        }
        first = first->pm_next;
     }
@@ -4252,13 +4237,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;