Fix uip/whom.c for C89 compatibility
[mmh] / uip / mhbuild.c
index 0f77f33..a233c68 100644 (file)
@@ -45,6 +45,7 @@ static struct swit switches[] = {
        { NULL, 0 }
 };
 
+char *version=VERSION;
 
 /*
 ** Directory to place tmp files.  This must
@@ -312,8 +313,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 +327,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 +348,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);
 
@@ -423,7 +415,7 @@ build_mime(char *infile)
        add_header(ct, np, vp);
 
        /*
-       ** We initally assume we will find multiple contents in the
+       ** We initially assume we will find multiple contents in the
        ** draft.  So create a multipart/mixed content to hold everything.
        ** We can remove this later, if it is not needed.
        */
@@ -434,7 +426,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;
 
@@ -1285,13 +1277,8 @@ scan_content(CT ct)
        case CT_TEXT:
                check8bit = 1;
                checkboundary = 1;
-               if (ct->c_subtype == TEXT_PLAIN) {
-                       checklinelen = 0;
-                       checklinespace = 0;
-               } else {
-                       checklinelen = 1;
-                       checklinespace = 1;
-               }
+               checklinelen = 1;
+               checklinespace = 1;
                break;
 
        case CT_MESSAGE: