Merge branch 'm_getfld2-meillo' into master
[mmh] / uip / mhbuild.c
index 0f77f33..fe3e946 100644 (file)
@@ -312,8 +312,10 @@ unlink_done()
 static CT
 build_mime(char *infile)
 {
-       int compnum, state;
-       char buf[BUFSIZ], name[NAMESZ];
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
+       char buf[BUFSIZ];
        char *cp, *np, *vp;
        struct multipart *m;
        struct part **pp;
@@ -324,8 +326,9 @@ build_mime(char *infile)
        umask(~m_gmprot());
 
        /* open the composition draft */
-       if ((in = fopen(infile, "r")) == NULL)
+       if ((in = fopen(infile, "r")) == NULL) {
                adios(EX_IOERR, infile, "unable to open for reading");
+       }
 
        /*
        ** Allocate space for primary (outside) content
@@ -344,57 +347,45 @@ build_mime(char *infile)
        ** draft into the linked list of header fields for
        ** the new MIME message.
        */
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
+       for (compnum = 1, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        compnum++;
 
                        /* abort if draft has Mime-Version header field */
-                       if (!mh_strcasecmp(name, VRSN_FIELD))
+                       if (!mh_strcasecmp(f.name, VRSN_FIELD)) {
                                adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
+                       }
 
                        /*
                        ** abort if draft has Content-Transfer-Encoding
                        ** header field
                        */
-                       if (!mh_strcasecmp(name, ENCODING_FIELD))
+                       if (!mh_strcasecmp(f.name, ENCODING_FIELD)) {
                                adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
+                       }
 
                        /* ignore any Content-Type fields in the header */
-                       if (!mh_strcasecmp(name, TYPE_FIELD)) {
-                               while (state == FLDPLUS)
-                                       state = m_getfld(state, name, buf,
-                                                       sizeof(buf), in);
+                       if (!mh_strcasecmp(f.name, TYPE_FIELD)) {
                                continue;
                        }
 
-                       /* get copies of the buffers */
-                       np = mh_xstrdup(name);
-                       vp = mh_xstrdup(buf);
-
-                       /* if necessary, get rest of field */
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               vp = add(buf, vp);  /* add to prev value */
-                       }
-
-                       /* Now add the header data to the list */
-                       add_header(ct, np, vp);
+                       /* add the header data to the list */
+                       add_header(ct, mh_xstrdup(f.name), mh_xstrdup(f.value));
 
                        continue;
 
-               case FILEEOF:
+               case BODY2:
+                       fseek(in, (long) (-strlen(f.value)), SEEK_CUR);
+                       break;
+
+               case FILEEOF2:
                        adios(EX_CONFIG, NULL, "draft has empty body -- no directives!");
                        /* NOTREACHED */
 
-               case BODY:
-                       fseek(in, (long) (-strlen(buf)), SEEK_CUR);
-                       break;
-
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case IOERR2:
                        adios(EX_CONFIG, NULL, "message format error in component #%d",
                                        compnum);
 
@@ -434,7 +425,7 @@ build_mime(char *infile)
        ct->c_subtype = MULTI_MIXED;
        ct->c_file = mh_xstrdup(infile);
 
-       m = mh_xcalloc(1, sizeof(*m));
+       m = (struct multipart *) mh_xcalloc(1, sizeof(*m));
        ct->c_ctparams = (void *) m;
        pp = &m->mp_parts;