Fix uip/whom.c for C89 compatibility
[mmh] / uip / spost.c
index aacb633..39d8ada 100644 (file)
@@ -39,6 +39,7 @@ static struct swit switches[] = {
        { NULL, 0 }
 };
 
+char *version=VERSION;
 
 /* flags for headers->flags */
 #define HNOP  0x0000  /* just used to keep .set around */
@@ -144,9 +145,11 @@ static size_t do_aliasing(struct mailname *, struct mailname **);
 int
 main(int argc, char **argv)
 {
-       int state, compnum;
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
        char *cp, *msg = NULL, **argp, **arguments;
-       char **sargv, buf[BUFSIZ], name[NAMESZ];
+       char **sargv, buf[BUFSIZ];
        FILE *in;
 
        setlocale(LC_ALL, "");
@@ -231,37 +234,31 @@ main(int argc, char **argv)
 
        hdrtab = (msgstate == normal) ? NHeaders : RHeaders;
 
-       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++;
-                       cp = mh_xstrdup(buf);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               cp = add(buf, cp);
-                       }
-                       putfmt(name, cp, out);
-                       mh_free0(&cp);
+                       putfmt(f.name, f.value, out);
                        continue;
 
-               case BODY:
+               case BODY2:
                        finish_headers(out);
-                       fprintf(out, "\n%s", buf);
-                       while (state == BODY) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               fputs(buf, out);
+                       fprintf(out, "\n%s", f.value);
+                       while ((state = m_getfld2(state, &f, in)) == BODY2) {
+                               if (f.valuelen >= NAMESZ) {
+                                       adios(EX_DATAERR, NULL, "Body contains a to long line");
+                               }
+                               fputs(f.value, out);
                        }
                        break;
 
-               case FILEEOF:
+               case FILEEOF2:
                        finish_headers(out);
                        break;
 
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case IOERR2:
                        adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);
 
@@ -272,6 +269,10 @@ main(int argc, char **argv)
        }
        fclose(in);
 
+       if (state != FILEEOF2) {
+               adios(EX_IOERR, "m_getfld2", "Error while reading body");
+       }
+
        if (debug) {
                struct mailname *i = recipients;
                /* stop here */
@@ -650,7 +651,7 @@ fcc(char *file, char *folders)
                fprintf(stderr, "Skipped %sFcc %s: unable to system().\n",
                                msgstate == resent ? "Resent-" : "", folders);
        } else if (status != 0) {
-               fprintf(stderr, "%sFcc %s: Problems occured.\n",
+               fprintf(stderr, "%sFcc %s: Problems occurred.\n",
                                msgstate == resent ? "Resent-" : "", folders);
        }
 }