]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Escape literal leading full stop in man/new.man.
[nmh] / uip / mhparse.c
index d729768abd04fa265dffe58cc6801261d419f233..a2dcb88c2e49503f78da26a6e4a72bce5fd02a8c 100644 (file)
@@ -209,6 +209,7 @@ parse_mime (char *file)
     FILE *fp;
     CT ct;
     size_t n;
+    struct stat statbuf;
 
     bogus_mp_content = 0;
 
@@ -222,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) {
@@ -244,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;
@@ -317,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) {
@@ -654,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) {
@@ -662,7 +670,7 @@ get_ctinfo (char *cp, CT ct, int magic)
                TYPE_FIELD, ct->c_file);
        return NOTOK;
     }
-    ToLower(ci->ci_type);
+    to_lower(ci->ci_type);
 
     while (isspace ((unsigned char) *cp))
        cp++;
@@ -673,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;
     }
 
@@ -688,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) {
@@ -697,7 +705,7 @@ get_ctinfo (char *cp, CT ct, int magic)
                TYPE_FIELD, ct->c_file, ci->ci_type);
        return NOTOK;
     }
-    ToLower(ci->ci_subtype);
+    to_lower(ci->ci_subtype);
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
@@ -836,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.
@@ -903,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)
@@ -960,7 +968,7 @@ invalid:
 
        case '(':
            i++;
-           /* and fall... */
+           /* FALLTHRU */
        default:
            *bp++ = c;
            continue;
@@ -980,7 +988,7 @@ invalid:
            *commentp = concat (dp, " ", buffer, NULL);
            free (dp);
        } else {
-           *commentp = add (buffer, NULL);
+           *commentp = mh_xstrdup(buffer);
        }
     }
 
@@ -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';
@@ -1257,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) {
@@ -1531,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)
@@ -1764,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;
     }
 
@@ -1786,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) {
@@ -1948,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;
     }
 
@@ -1970,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) {
@@ -2168,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;
     }
 
@@ -2190,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) {
@@ -2533,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) {
@@ -2731,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;
     }
 
@@ -2746,7 +2754,7 @@ openMail (CT ct, char **file)
     /* showproc is for mhshow and mhstore, though mhlist -debug
      * prints it, too. */
     mh_xfree(ct->c_showproc);
-    ct->c_showproc = add ("true", NULL);
+    ct->c_showproc = mh_xstrdup("true");
 
     fseek (ce->ce_fp, 0L, SEEK_SET);
     *file = ce->ce_file;
@@ -2813,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) {
@@ -3479,7 +3487,7 @@ bad_quote:
                    case '\\':
                        if (*++cp == '\0')
                            goto bad_quote;
-                       /* FALL THROUGH */
+                       /* FALLTHRU */
                    default:
                        len++;
                        continue;
@@ -3931,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--;
@@ -4039,6 +4047,7 @@ normal_param(PM pm, char *output, size_t len, size_t valuelen,
        case '"':
            *output++ = '\\';
            outlen++;
+           /* FALLTHRU */
        default:
            *output++ = *p++;
            outlen++;
@@ -4228,17 +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--) {
-        /* FIXME: !iscntrl should perhaps be isprint as that allows all
-         * classes bar cntrl, whereas the cntrl class can include those
-         * in space and blank.
-         * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html */
-       if (isascii((unsigned char) *p) && !iscntrl((unsigned char) *p))
+       if (isascii((unsigned char) *p) && isprint((unsigned char) *p))
            *q = *p;
        else
            *q = replace;