]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Try using -man instead of -mandoc in test-manpages on OpenBSD
[nmh] / uip / mhparse.c
index 4a70610e0f9c4ae0dda2299c59c99b9144919c2e..5e35cbbf5c77e49881765681d17453a38e766914 100644 (file)
@@ -11,8 +11,6 @@
 #include <fcntl.h>
 #include <h/signals.h>
 #include <h/md5.h>
-#include <errno.h>
-#include <signal.h>
 #include <h/mts.h>
 #include <h/tws.h>
 #include <h/mime.h>
@@ -104,7 +102,7 @@ void free_encoding (CT, int);
  * static prototypes
  */
 static CT get_content (FILE *, char *, int);
-static int get_comment (CT, char **, int);
+static int get_comment (const char *, CI, char **, int);
 
 static int InitGeneric (CT);
 static int InitText (CT);
@@ -346,7 +344,7 @@ get_content (FILE *in, char *file, int toplevel)
     hp = ct->c_first_hf;       /* start at first header field */
     while (hp) {
        /* Get MIME-Version field */
-       if (!mh_strcasecmp (hp->name, VRSN_FIELD)) {
+       if (!strcasecmp (hp->name, VRSN_FIELD)) {
            int ucmp;
            char c, *cp, *dp;
 
@@ -371,21 +369,22 @@ get_content (FILE *in, char *file, int toplevel)
            if (debugsw)
                fprintf (stderr, "%s: %s\n", VRSN_FIELD, cp);
 
-           if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK)
+           if (*cp == '('  &&
+                get_comment (ct->c_file, &ct->c_ctinfo, &cp, 0) == NOTOK)
                goto out;
 
            for (dp = cp; istoken (*dp); dp++)
                continue;
            c = *dp;
            *dp = '\0';
-           ucmp = !mh_strcasecmp (cp, VRSN_VALUE);
+           ucmp = !strcasecmp (cp, VRSN_VALUE);
            *dp = c;
            if (!ucmp) {
                admonish (NULL, "message %s has unknown value for %s: field (%s)",
                ct->c_file, VRSN_FIELD, cp);
            }
        }
-       else if (!mh_strcasecmp (hp->name, TYPE_FIELD)) {
+       else if (!strcasecmp (hp->name, TYPE_FIELD)) {
        /* Get Content-Type field */
            struct str2init *s2i;
            CI ci = &ct->c_ctinfo;
@@ -406,14 +405,14 @@ get_content (FILE *in, char *file, int toplevel)
             * flag for this content type.
             */
            for (s2i = str2cts; s2i->si_key; s2i++)
-               if (!mh_strcasecmp (ci->ci_type, s2i->si_key))
+               if (!strcasecmp (ci->ci_type, s2i->si_key))
                    break;
            if (!s2i->si_key && !uprf (ci->ci_type, "X-"))
                s2i++;
            ct->c_type = s2i->si_val;
            ct->c_ctinitfnx = s2i->si_init;
        }
-       else if (!mh_strcasecmp (hp->name, ENCODING_FIELD)) {
+       else if (!strcasecmp (hp->name, ENCODING_FIELD)) {
        /* Get Content-Transfer-Encoding field */
            char c, *cp, *dp;
            struct str2init *s2i;
@@ -443,7 +442,7 @@ get_content (FILE *in, char *file, int toplevel)
             * for this transfer encoding.
             */
            for (s2i = str2ces; s2i->si_key; s2i++)
-               if (!mh_strcasecmp (cp, s2i->si_key))
+               if (!strcasecmp (cp, s2i->si_key))
                    break;
            if (!s2i->si_key && !uprf (cp, "X-"))
                s2i++;
@@ -454,7 +453,7 @@ get_content (FILE *in, char *file, int toplevel)
            if (s2i->si_init && (*s2i->si_init) (ct) == NOTOK)
                goto out;
        }
-       else if (!mh_strcasecmp (hp->name, MD5_FIELD)) {
+       else if (!strcasecmp (hp->name, MD5_FIELD)) {
        /* Get Content-MD5 field */
            char *cp, *dp, *ep;
 
@@ -480,7 +479,8 @@ get_content (FILE *in, char *file, int toplevel)
            if (debugsw)
                fprintf (stderr, "%s: %s\n", MD5_FIELD, cp);
 
-           if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) {
+           if (*cp == '('  &&
+                get_comment (ct->c_file, &ct->c_ctinfo, &cp, 0) == NOTOK) {
                free (ep);
                goto out;
            }
@@ -493,15 +493,15 @@ get_content (FILE *in, char *file, int toplevel)
            free (ep);
            ct->c_digested++;
        }
-       else if (!mh_strcasecmp (hp->name, ID_FIELD)) {
+       else if (!strcasecmp (hp->name, ID_FIELD)) {
        /* Get Content-ID field */
            ct->c_id = add (hp->value, ct->c_id);
        }
-       else if (!mh_strcasecmp (hp->name, DESCR_FIELD)) {
+       else if (!strcasecmp (hp->name, DESCR_FIELD)) {
        /* Get Content-Description field */
            ct->c_descr = add (hp->value, ct->c_descr);
        }
-       else if (!mh_strcasecmp (hp->name, DISPO_FIELD)) {
+       else if (!strcasecmp (hp->name, DISPO_FIELD)) {
        /* Get Content-Disposition field */
            ct->c_dispo = add (hp->value, ct->c_dispo);
        }
@@ -670,9 +670,10 @@ int
 get_ctinfo (char *cp, CT ct, int magic)
 {
     int        i;
-    char *dp, **ap, **ep;
+    char *dp;
     char c;
     CI ci;
+    int status;
 
     ci = &ct->c_ctinfo;
     i = strlen (invo_name) + 2;
@@ -696,7 +697,7 @@ get_ctinfo (char *cp, CT ct, int magic)
     if (debugsw)
        fprintf (stderr, "%s: %s\n", TYPE_FIELD, cp);
 
-    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+    if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
        return NOTOK;
 
     for (dp = cp; istoken (*dp); dp++)
@@ -719,7 +720,7 @@ get_ctinfo (char *cp, CT ct, int magic)
     while (isspace ((unsigned char) *cp))
        cp++;
 
-    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+    if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
        return NOTOK;
 
     if (*cp != '/') {
@@ -732,7 +733,7 @@ get_ctinfo (char *cp, CT ct, int magic)
     while (isspace ((unsigned char) *cp))
        cp++;
 
-    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+    if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
        return NOTOK;
 
     for (dp = cp; istoken (*dp); dp++)
@@ -757,103 +758,11 @@ magic_skip:
     while (isspace ((unsigned char) *cp))
        cp++;
 
-    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+    if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
        return NOTOK;
 
-    /*
-     * Parse attribute/value pairs given with Content-Type
-     */
-    ep = (ap = ci->ci_attrs) + NPARMS;
-    while (*cp == ';') {
-       char *vp, *up;
-
-       if (ap >= ep) {
-           advise (NULL,
-                   "too many parameters in message %s's %s: field (%d max)",
-                   ct->c_file, TYPE_FIELD, NPARMS);
-           return NOTOK;
-       }
-
-       cp++;
-       while (isspace ((unsigned char) *cp))
-           cp++;
-
-       if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
-           return NOTOK;
-
-       if (*cp == 0) {
-           advise (NULL,
-                   "extraneous trailing ';' in message %s's %s: parameter list",
-                   ct->c_file, TYPE_FIELD);
-           return OK;
-       }
-
-       /* 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);
-
-       for (up = dp; isspace ((unsigned char) *dp);)
-           dp++;
-       if (dp == cp || *dp != '=') {
-           advise (NULL,
-                   "invalid parameter in message %s's %s: field\n%*.*sparameter %s (error detected at offset %d)",
-                   ct->c_file, TYPE_FIELD, i, i, "", cp, dp - cp);
-           return NOTOK;
-       }
-
-       vp = (*ap = add (cp, NULL)) + (up - cp);
-       *vp = '\0';
-       for (dp++; isspace ((unsigned char) *dp);)
-           dp++;
-
-       /* now add the attribute value */
-       ci->ci_values[ap - ci->ci_attrs] = vp = *ap + (dp - cp);
-
-       if (*dp == '"') {
-           for (cp = ++dp, dp = vp;;) {
-               switch (c = *cp++) {
-                   case '\0':
-bad_quote:
-                       advise (NULL,
-                               "invalid quoted-string in message %s's %s: field\n%*.*s(parameter %s)",
-                               ct->c_file, TYPE_FIELD, i, i, "", *ap);
-                       return NOTOK;
-
-                   case '\\':
-                       *dp++ = c;
-                       if ((c = *cp++) == '\0')
-                           goto bad_quote;
-                       /* else fall... */
-
-                   default:
-                       *dp++ = c;
-                       continue;
-
-                   case '"':
-                       *dp = '\0';
-                       break;
-               }
-               break;
-           }
-       } else {
-           for (cp = dp, dp = vp; istoken (*cp); cp++, dp++)
-               continue;
-           *dp = '\0';
-       }
-       if (!*vp) {
-           advise (NULL,
-                   "invalid parameter in message %s's %s: field\n%*.*s(parameter %s)",
-                   ct->c_file, TYPE_FIELD, i, i, "", *ap);
-           return NOTOK;
-       }
-       ap++;
-
-       while (isspace ((unsigned char) *cp))
-           cp++;
-
-       if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
-           return NOTOK;
+    if (parse_header_attrs (ct->c_file, i, &cp, ci, &status) == NOTOK) {
+       return status;
     }
 
     /*
@@ -966,14 +875,12 @@ bad_quote:
 
 
 static int
-get_comment (CT ct, char **ap, int istype)
+get_comment (const char *filename, CI ci, char **ap, int istype)
 {
     int i;
     char *bp, *cp;
     char c, buffer[BUFSIZ], *dp;
-    CI ci;
 
-    ci = &ct->c_ctinfo;
     cp = *ap;
     bp = buffer;
     cp++;
@@ -983,7 +890,7 @@ get_comment (CT ct, char **ap, int istype)
        case '\0':
 invalid:
        advise (NULL, "invalid comment in message %s's %s: field",
-               ct->c_file, istype ? TYPE_FIELD : VRSN_FIELD);
+               filename, istype ? TYPE_FIELD : VRSN_FIELD);
        return NOTOK;
 
        case '\\':
@@ -1063,7 +970,7 @@ InitText (CT ct)
 
     /* match subtype */
     for (kv = SubText; kv->kv_key; kv++)
-       if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+       if (!strcasecmp (ci->ci_subtype, kv->kv_key))
            break;
     ct->c_subtype = kv->kv_value;
 
@@ -1074,7 +981,7 @@ InitText (CT ct)
 
     /* scan for charset parameter */
     for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
-       if (!mh_strcasecmp (*ap, "charset"))
+       if (!strcasecmp (*ap, "charset"))
            break;
 
     /* check if content specified a character set */
@@ -1147,7 +1054,7 @@ InitMultiPart (CT ct)
 
     /* match subtype */
     for (kv = SubMultiPart; kv->kv_key; kv++)
-       if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+       if (!strcasecmp (ci->ci_subtype, kv->kv_key))
            break;
     ct->c_subtype = kv->kv_value;
 
@@ -1157,7 +1064,7 @@ InitMultiPart (CT ct)
      */
     bp = 0;
     for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
-       if (!mh_strcasecmp (*ap, "boundary")) {
+       if (!strcasecmp (*ap, "boundary")) {
            bp = *ep;
            break;
        }
@@ -1359,7 +1266,7 @@ InitMessage (CT ct)
 
     /* match subtype */
     for (kv = SubMessage; kv->kv_key; kv++)
-       if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+       if (!strcasecmp (ci->ci_subtype, kv->kv_key))
            break;
     ct->c_subtype = kv->kv_value;
 
@@ -1378,11 +1285,11 @@ InitMessage (CT ct)
 
                /* scan for parameters "id", "number", and "total" */
                for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
-                   if (!mh_strcasecmp (*ap, "id")) {
+                   if (!strcasecmp (*ap, "id")) {
                        p->pm_partid = add (*ep, NULL);
                        continue;
                    }
-                   if (!mh_strcasecmp (*ap, "number")) {
+                   if (!strcasecmp (*ap, "number")) {
                        if (sscanf (*ep, "%d", &p->pm_partno) != 1
                                || p->pm_partno < 1) {
 invalid_param:
@@ -1394,7 +1301,7 @@ invalid_param:
                        }
                        continue;
                    }
-                   if (!mh_strcasecmp (*ap, "total")) {
+                   if (!strcasecmp (*ap, "total")) {
                        if (sscanf (*ep, "%d", &p->pm_maxno) != 1
                                || p->pm_maxno < 1)
                            goto invalid_param;
@@ -1516,12 +1423,12 @@ params_external (CT ct, int composing)
 
     ct->c_ceopenfnx = NULL;
     for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
-       if (!mh_strcasecmp (*ap, "access-type")) {
+       if (!strcasecmp (*ap, "access-type")) {
            struct str2init *s2i;
            CT p = e->eb_content;
 
            for (s2i = str2methods; s2i->si_key; s2i++)
-               if (!mh_strcasecmp (*ep, s2i->si_key))
+               if (!strcasecmp (*ep, s2i->si_key))
                    break;
            if (!s2i->si_key) {
                e->eb_access = *ep;
@@ -1538,39 +1445,39 @@ params_external (CT ct, int composing)
                return NOTOK;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "name")) {
+       if (!strcasecmp (*ap, "name")) {
            e->eb_name = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "permission")) {
+       if (!strcasecmp (*ap, "permission")) {
            e->eb_permission = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "site")) {
+       if (!strcasecmp (*ap, "site")) {
            e->eb_site = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "directory")) {
+       if (!strcasecmp (*ap, "directory")) {
            e->eb_dir = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "mode")) {
+       if (!strcasecmp (*ap, "mode")) {
            e->eb_mode = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "size")) {
+       if (!strcasecmp (*ap, "size")) {
            sscanf (*ep, "%lu", &e->eb_size);
            continue;
        }
-       if (!mh_strcasecmp (*ap, "server")) {
+       if (!strcasecmp (*ap, "server")) {
            e->eb_server = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "subject")) {
+       if (!strcasecmp (*ap, "subject")) {
            e->eb_subject = *ep;
            continue;
        }
-       if (!mh_strcasecmp (*ap, "url")) {
+       if (!strcasecmp (*ap, "url")) {
            /*
             * According to RFC 2017, we have to remove all whitespace from
             * the URL
@@ -1587,7 +1494,7 @@ params_external (CT ct, int composing)
            *u = '\0';
            continue;
        }
-       if (composing && !mh_strcasecmp (*ap, "body")) {
+       if (composing && !strcasecmp (*ap, "body")) {
            e->eb_body = getcpy (*ep);
            continue;
        }
@@ -1616,7 +1523,7 @@ InitApplication (CT ct)
 
     /* match subtype */
     for (kv = SubApplication; kv->kv_key; kv++)
-       if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+       if (!strcasecmp (ci->ci_subtype, kv->kv_key))
            break;
     ct->c_subtype = kv->kv_value;
 
@@ -1631,12 +1538,6 @@ InitApplication (CT ct)
 static int
 init_encoding (CT ct, OpenCEFunc openfnx)
 {
-    CE ce;
-
-    if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL)
-       adios (NULL, "out of memory");
-
-    ct->c_cefile     = ce;
     ct->c_ceopenfnx  = openfnx;
     ct->c_ceclosefnx = close_encoding;
     ct->c_cesizefnx  = size_encoding;
@@ -1648,10 +1549,7 @@ init_encoding (CT ct, OpenCEFunc openfnx)
 void
 close_encoding (CT ct)
 {
-    CE ce;
-
-    if (!(ce = ct->c_cefile))
-       return;
+    CE ce = &ct->c_cefile;
 
     if (ce->ce_fp) {
        fclose (ce->ce_fp);
@@ -1666,12 +1564,9 @@ size_encoding (CT ct)
     int        fd;
     unsigned long size;
     char *file;
-    CE ce;
+    CE ce = &ct->c_cefile;
     struct stat st;
 
-    if (!(ce = ct->c_cefile))
-       return (ct->c_end - ct->c_begin);
-
     if (ce->ce_fp && fstat (fileno (ce->ce_fp), &st) != NOTOK)
        return (long) st.st_size;
 
@@ -1740,10 +1635,9 @@ openBase64 (CT ct, char **file)
     char *cp, *ep, buffer[BUFSIZ];
     /* sbeck -- handle suffixes */
     CI ci;
-    CE ce;
+    CE ce = &ct->c_cefile;
     MD5_CTX mdContext;
 
-    ce = ct->c_cefile;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
@@ -1973,12 +1867,11 @@ openQuoted (CT ct, char **file)
     char *cp, *ep;
     char buffer[BUFSIZ];
     unsigned char mask;
-    CE ce;
+    CE ce = &ct->c_cefile;
     /* sbeck -- handle suffixes */
     CI ci;
     MD5_CTX mdContext;
 
-    ce = ct->c_cefile;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
@@ -2201,9 +2094,8 @@ open7Bit (CT ct, char **file)
     /* sbeck -- handle suffixes */
     char *cp;
     CI ci;
-    CE ce;
+    CE ce = &ct->c_cefile;
 
-    ce = ct->c_cefile;
     if (ce->ce_fp) {
        fseek (ce->ce_fp, 0L, SEEK_SET);
        goto ready_to_go;
@@ -2422,7 +2314,7 @@ openFile (CT ct, char **file)
     int        fd, cachetype;
     char cachefile[BUFSIZ];
     struct exbody *e = ct->c_ctexbody;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) {
        case NOTOK:
@@ -2448,7 +2340,7 @@ openFile (CT ct, char **file)
        return NOTOK;
     }
 
-    if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write"))
+    if ((!e->eb_permission || strcasecmp (e->eb_permission, "read-write"))
            && find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id,
                cachefile, sizeof(cachefile)) != NOTOK) {
        int mask;
@@ -2505,12 +2397,11 @@ openFTP (CT ct, char **file)
     char *bp, *ftp, *user, *pass;
     char buffer[BUFSIZ], cachefile[BUFSIZ];
     struct exbody *e;
-    CE ce;
+    CE ce = &ct->c_cefile;
     static char *username = NULL;
     static char *password = NULL;
 
     e  = ct->c_ctexbody;
-    ce = ct->c_cefile;
 
     if ((ftp = context_find (nmhaccessftp)) && !*ftp)
        ftp = NULL;
@@ -2595,7 +2486,7 @@ openFTP (CT ct, char **file)
     ce->ce_unlink = (*file == NULL);
     caching = 0;
     cachefile[0] = '\0';
-    if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write"))
+    if ((!e->eb_permission || strcasecmp (e->eb_permission, "read-write"))
            && find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id,
                cachefile, sizeof(cachefile)) != NOTOK) {
        if (*file == NULL) {
@@ -2628,7 +2519,7 @@ openFTP (CT ct, char **file)
        vec[vecp++] = e->eb_dir;
        vec[vecp++] = e->eb_name;
        vec[vecp++] = ce->ce_file,
-       vec[vecp++] = e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii")
+       vec[vecp++] = e->eb_mode && !strcasecmp (e->eb_mode, "ascii")
                        ? "ascii" : "binary";
        vec[vecp] = NULL;
 
@@ -2717,7 +2608,7 @@ openMail (CT ct, char **file)
     int len, buflen;
     char *bp, buffer[BUFSIZ], *vec[7];
     struct exbody *e = ct->c_ctexbody;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
 
     switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) {
        case NOTOK:
@@ -2836,7 +2727,7 @@ static int
 openURL (CT ct, char **file)
 {
     struct exbody *e = ct->c_ctexbody;
-    CE ce = ct->c_cefile;
+    CE ce = &ct->c_cefile;
     char *urlprog, *program;
     char buffer[BUFSIZ], cachefile[BUFSIZ];
     int fd, caching, cachetype;
@@ -3236,7 +3127,7 @@ ce_str (int encoding) {
     case CE_BASE64:
         return "base64";
     case CE_QUOTED:
-        return "quoted";
+        return "quoted-printable";
     case CE_8BIT:
         return "8bit";
     case CE_7BIT:
@@ -3265,3 +3156,124 @@ get_ce_method (const char *method) {
 
     return NULL;
 }
+
+int
+parse_header_attrs (const char *filename, int len, char **header_attrp, CI ci,
+                    int *status) {
+    char **attr = ci->ci_attrs;
+    char *cp = *header_attrp;
+
+    while (*cp == ';') {
+       char *dp, *vp, *up, c;
+
+        /* Relies on knowledge of this declaration:
+         *   char *ci_attrs[NPARMS + 2];
+         */
+       if (attr >= ci->ci_attrs + sizeof ci->ci_attrs/sizeof (char *) - 2) {
+           advise (NULL,
+                   "too many parameters in message %s's %s: field (%d max)",
+                   filename, TYPE_FIELD, NPARMS);
+           *status = NOTOK;
+           return NOTOK;
+       }
+
+       cp++;
+       while (isspace ((unsigned char) *cp))
+           cp++;
+
+       if (*cp == '('  &&
+            get_comment (filename, ci, &cp, 1) == NOTOK) {
+           *status = NOTOK;
+           return NOTOK;
+        }
+
+       if (*cp == 0) {
+           advise (NULL,
+                   "extraneous trailing ';' in message %s's %s: "
+                    "parameter list",
+                   filename, TYPE_FIELD);
+           *status = OK;
+           return NOTOK;
+       }
+
+       /* 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);
+
+       for (up = dp; isspace ((unsigned char) *dp);)
+           dp++;
+       if (dp == cp || *dp != '=') {
+           advise (NULL,
+                   "invalid parameter in message %s's %s: "
+                    "field\n%*.*sparameter %s (error detected at offset %d)",
+                   filename, TYPE_FIELD, len, len, "", cp, dp - cp);
+           *status = NOTOK;
+           return NOTOK;
+       }
+
+       vp = (*attr = add (cp, NULL)) + (up - cp);
+       *vp = '\0';
+       for (dp++; isspace ((unsigned char) *dp);)
+           dp++;
+
+       /* Now store the attribute value. */
+       ci->ci_values[attr - ci->ci_attrs] = vp = *attr + (dp - cp);
+
+       if (*dp == '"') {
+           for (cp = ++dp, dp = vp;;) {
+               switch (c = *cp++) {
+                   case '\0':
+bad_quote:
+                       advise (NULL,
+                               "invalid quoted-string in message %s's %s: "
+                                "field\n%*.*s(parameter %s)",
+                               filename, TYPE_FIELD, len, len, "", *attr);
+                       *status = NOTOK;
+                       return NOTOK;
+
+                   case '\\':
+                       *dp++ = c;
+                       if ((c = *cp++) == '\0')
+                           goto bad_quote;
+                       /* else fall... */
+
+                   default:
+                       *dp++ = c;
+                       continue;
+
+                   case '"':
+                       *dp = '\0';
+                       break;
+               }
+               break;
+           }
+       } else {
+           for (cp = dp, dp = vp; istoken (*cp); cp++, dp++)
+               continue;
+           *dp = '\0';
+       }
+       if (!*vp) {
+           advise (NULL,
+                   "invalid parameter in message %s's %s: "
+                    "field\n%*.*s(parameter %s)",
+                   filename, TYPE_FIELD, len, len, "", *attr);
+           *status = NOTOK;
+           return NOTOK;
+       }
+
+       while (isspace ((unsigned char) *cp))
+           cp++;
+
+       if (*cp == '('  &&
+            get_comment (filename, ci, &cp, 1) == NOTOK) {
+           *status = NOTOK;
+           return NOTOK;
+        }
+
+        ++attr;
+    }
+
+    *header_attrp = cp;
+    return OK;
+}