fix 2fb1dd2271e5be9d0b0c9cbd4e7d6d5d51aaecb9
[mmh] / uip / inc.c
index f08fb4f..0cb2a5e 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -197,7 +197,7 @@ main(int argc, char **argv)
                        case AUDSW:
                                if (!(cp = *argp++) || *cp == '-')
                                        adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
-                               audfile = getcpy(expanddir(cp));
+                               audfile = mh_xstrdup(expanddir(cp));
                                continue;
                        case NAUDSW:
                                audfile = NULL;
@@ -228,7 +228,7 @@ main(int argc, char **argv)
                                if (!(cp = *argp++) || *cp == '-')
                                        adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
-                               from = getcpy(expanddir(cp));
+                               from = mh_xstrdup(expanddir(cp));
 
                                /*
                                ** If the truncate file is in default state,
@@ -263,7 +263,7 @@ main(int argc, char **argv)
                        if (folder)
                                adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
-                               folder = getcpy(expandfol(cp));
+                               folder = mh_xstrdup(expandfol(cp));
                } else {
                        adios(EX_USAGE, NULL, "usage: %s [+folder] [switches]",
                                        invo_name);
@@ -350,18 +350,33 @@ main(int argc, char **argv)
                         dtimenow(), from);
        }
 
-       /* Get new format string */
-       fmtstr = new_fs(form, FORMAT);
+       /* Set format string */
+       fmtstr = new_fs(form, scanformat);
 
        if (noisy) {
                printf("Incorporating new mail into %s...\n\n", folder);
                fflush(stdout);
        }
 
+       /* check if readable and nonempty */
+       if (!fgets(buf, sizeof(buf), in)) {
+               if (ferror(in)) {
+                       advise("read", "unable to");
+                       incerr = SCNFAT;
+               } else {
+                       incerr = SCNEOF;
+               }
+               goto giveup;
+       }
+       if (strncmp("From ", buf, 5)!=0) {
+               advise(NULL, "not in mbox format");
+               incerr = SCNFAT;
+               goto giveup;
+       }
+
        /*
        ** Get the mail from file (usually mail spool)
        */
-       thisisanmbox(in);
        hghnum = msgnum = mp->hghmsg;
        for (;;) {
                /*
@@ -429,7 +444,8 @@ main(int argc, char **argv)
                */
                break;
        }
-       free(maildir_copy);
+giveup:;
+       mh_free0(&maildir_copy);
 
        if (incerr < 0) {  /* error */
                if (locked) {