]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
sbr/m_getfld.c: Fix and improve `delim' comment.
[nmh] / uip / mhparse.c
index 2be9760359526cd446863c4bc0eb3cee9dc33cbf..69660a91d3e416525e790f23e363a6b02a1d9587 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * mhparse.c -- routines to parse the contents of MIME messages
+/* mhparse.c -- routines to parse the contents of MIME messages
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -15,6 +13,9 @@
 #include <h/mime.h>
 #include <h/mhparse.h>
 #include <h/utils.h>
+#include <h/mhcachesbr.h>
+#include "../sbr/m_mktemp.h"
+#include "mhfree.h"
 #ifdef HAVE_ICONV
 # include <iconv.h>
 #endif /* HAVE_ICONV */
 
 extern int debugsw;
 
-/* cache policies */
-extern int rcachesw;   /* mhcachesbr.c */
-extern int wcachesw;   /* mhcachesbr.c */
-
 int checksw = 0;       /* check Content-MD5 field */
 
 /*
@@ -57,8 +54,8 @@ int npreferred;
  */
 struct k2v SubText[] = {
     { "plain",    TEXT_PLAIN },
-    { "richtext", TEXT_RICHTEXT },  /* defined in RFC-1341    */
-    { "enriched", TEXT_ENRICHED },  /* defined in RFC-1896    */
+    { "richtext", TEXT_RICHTEXT },  /* defined in RFC 1341    */
+    { "enriched", TEXT_ENRICHED },  /* defined in RFC 1896    */
     { NULL,       TEXT_UNKNOWN }    /* this one must be last! */
 };
 
@@ -109,17 +106,11 @@ static struct k2v EncodingType[] = {
 };
 
 
-/* mhcachesbr.c */
-int find_cache (CT, int, int *, char *, char *, int);
-
 /* mhmisc.c */
 int part_ok (CT);
 int type_ok (CT, int);
 void content_error (char *, CT, char *, ...);
 
-/* mhfree.c */
-void free_encoding (CT, int);
-
 /*
  * static prototypes
  */
@@ -245,8 +236,8 @@ parse_mime (char *file)
            return NULL;
        }
        fseek (fp, 0L, SEEK_SET);
-    } else if (lstat (file, &statbuf) == NOTOK) {
-       advise (file, "unable to lstat");
+    } else if (stat (file, &statbuf) == NOTOK) {
+       advise (file, "unable to stat");
        return NULL;
     } else if (S_ISDIR(statbuf.st_mode)) {
        /* Don't try to parse a directory. */
@@ -300,7 +291,7 @@ static CT
 get_content (FILE *in, char *file, int toplevel)
 {
     int compnum, state;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     char *np, *vp;
     CT ct;
     HF hp;
@@ -413,7 +404,7 @@ get_content (FILE *in, char *file, int toplevel)
            ucmp = !strcasecmp (cp, VRSN_VALUE);
            *dp = c;
            if (!ucmp) {
-               admonish (NULL, "message %s has unknown value for %s: field (%s)",
+               inform("message %s has unknown value for %s: field (%s), continuing...",
                ct->c_file, VRSN_FIELD, cp);
            }
            if (!ct->c_vrsn) {
@@ -661,9 +652,11 @@ get_ctinfo (char *cp, CT ct, int magic)
 
     for (dp = cp; istoken (*dp); dp++)
        continue;
-    c = *dp, *dp = '\0';
+    c = *dp;
+    *dp = '\0';
     ci->ci_type = mh_xstrdup(cp);      /* store content type */
-    *dp = c, cp = dp;
+    *dp = c;
+    cp = dp;
 
     if (!*ci->ci_type) {
        inform("invalid %s: field in message %s (empty type)",
@@ -695,9 +688,11 @@ get_ctinfo (char *cp, CT ct, int magic)
 
     for (dp = cp; istoken (*dp); dp++)
        continue;
-    c = *dp, *dp = '\0';
+    c = *dp;
+    *dp = '\0';
     ci->ci_subtype = mh_xstrdup(cp);   /* store the content subtype */
-    *dp = c, cp = dp;
+    *dp = c;
+    cp = dp;
 
     if (!*ci->ci_subtype) {
        inform("invalid %s: field in message %s (empty subtype for \"%s\")",
@@ -908,9 +903,11 @@ get_dispo (char *cp, CT ct, int buildflag)
 
     for (dp = cp; istoken (*dp); dp++)
        continue;
-    c = *dp, *dp = '\0';
+    c = *dp;
+    *dp = '\0';
     ct->c_dispo_type = mh_xstrdup(cp); /* store disposition type */
-    *dp = c, cp = dp;
+    *dp = c;
+    cp = dp;
 
     if (*cp == '(' && get_comment (ct->c_file, DISPO_FIELD, &cp, NULL) == NOTOK)
        return NOTOK;
@@ -1091,7 +1088,7 @@ InitMultiPart (CT ct)
 
     /*
      * The encoding for multipart messages must be either
-     * 7bit, 8bit, or binary (per RFC2045).
+     * 7bit, 8bit, or binary (per RFC 2045).
      */
     if (! skip_mp_cte_check  &&  ct->c_encoding != CE_7BIT  &&
         ct->c_encoding != CE_8BIT  &&  ct->c_encoding != CE_BINARY) {
@@ -1103,13 +1100,12 @@ InitMultiPart (CT ct)
        while (bp >= cte && isspace ((unsigned char) *bp)) *bp-- = '\0';
        for (bp = cte; *bp && isblank ((unsigned char) *bp); ++bp) continue;
 
-       admonish (NULL,
-                 "\"%s/%s\" type in message %s must be encoded in\n"
-                 "7bit, 8bit, or binary, per RFC 2045 (6.4).  "
-                  "mhfixmsg -fixcte can fix it, or\n"
-                  "manually edit the file and change the \"%s\"\n"
-                 "Content-Transfer-Encoding to one of those.  For now",
-                 ci->ci_type, ci->ci_subtype, ct->c_file, bp);
+       inform("\"%s/%s\" type in message %s must be encoded in\n"
+           "7bit, 8bit, or binary, per RFC 2045 (6.4).  "
+           "mhfixmsg -fixcte can fix it, or\n"
+           "manually edit the file and change the \"%s\"\n"
+           "Content-Transfer-Encoding to one of those.  For now, continuing...",
+           ci->ci_type, ci->ci_subtype, ct->c_file, bp);
        free (cte);
 
        return NOTOK;
@@ -1289,7 +1285,7 @@ last_part:
  * ease of choosing/displaying it later on.  from a mail message on
  * nmh-workers, from kenh:
  *  "Stock" MH 6.8.5 did not have a reverse_parts() function, but I
- *  see code in mhn that did the same thing...  Acccording to the RCS
+ *  see code in mhn that did the same thing...  According to the RCS
  *  logs, that code was around from the initial checkin of mhn.c by
  *  John Romine in 1992, which is as far back as we have."
  */
@@ -1398,9 +1394,9 @@ InitMessage (CT ct)
     CI ci = &ct->c_ctinfo;
 
     if ((ct->c_encoding != CE_7BIT) && (ct->c_encoding != CE_8BIT)) {
-       admonish (NULL,
-                 "\"%s/%s\" type in message %s should be encoded in 7bit or 8bit",
-                 ci->ci_type, ci->ci_subtype, ct->c_file);
+       inform("\"%s/%s\" type in message %s should be encoded in "
+           "7bit or 8bit, continuing...", ci->ci_type, ci->ci_subtype,
+           ct->c_file);
        return NOTOK;
     }
 
@@ -2011,7 +2007,8 @@ openQuoted (CT ct, char **file)
        for (ep = (cp = bufp) + cc - 1; cp <= ep; ep--)
            if (!isspace ((unsigned char) *ep))
                break;
-       *++ep = '\n', ep++;
+        *++ep = '\n';
+        ep++;
 
        for (; cp < ep; cp++) {
            if (quoted > 0) {
@@ -2057,11 +2054,10 @@ openQuoted (CT ct, char **file)
                     * sequence; let's decode it (above). */
                    quoted = 1;
                    continue;
-               } else {
-                   /* One or both of the next 2 is out of range, making this
-                    * an invalid escape sequence; just show the raw bytes
-                    * (below). */
                }
+                /* One or both of the next 2 is out of range, making this
+                 * an invalid escape sequence; just show the raw bytes
+                 * (below). */
            }
 
            /* Just show the raw byte. */
@@ -3321,7 +3317,8 @@ parse_header_attrs (const char *filename, const char *fieldname,
            if (*vp == '*' && vp < up - 1) {
                partial = 1;
                continue;
-           } else if (*vp == '*' && vp == up - 1) {
+           }
+            if (*vp == '*' && vp == up - 1) {
                encoded = 1;
            } else if (partial) {
                if (isdigit((unsigned char) *vp))
@@ -3757,7 +3754,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
        }
 
        /*
-        * At this point, we're either finishing a contined parameter, or
+        * At this point, we're either finishing a continued parameter, or
         * we're working on a new one.
         */