- int chgflag = 1, trnflag = 1;
- int noisy = 1, width = 0;
- int rpop, i, hghnum = 0, msgnum = 0;
- int kpop = 0, sasl = 0;
- char *cp, *maildir = NULL, *folder = NULL;
- char *format = NULL, *form = NULL;
- char *host = NULL, *user = NULL, *proxy = NULL;
- char *audfile = NULL, *from = NULL, *saslmech = NULL;
- char buf[BUFSIZ], **argp, *nfs, **arguments;
- struct msgs *mp = NULL;
- struct stat st, s1;
- FILE *aud = NULL;
- char b[MAXPATHLEN + 1];
- char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */
-
-#ifdef POP
- int nmsgs, nbytes, p = 0;
- char *pass = NULL;
- char *MAILHOST_env_variable;
-#endif
-
-#ifdef MHE
- FILE *mhe = NULL;
-#endif
-
-#ifdef HESIOD
- struct hes_postoffice *po;
-#endif
-
- done=inc_done;
-
-/* absolutely the first thing we do is save our privileges,
- * and drop them if we can.
- */
- SAVEGROUPPRIVS();
- TRYDROPGROUPPRIVS();
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
-
- mts_init (invo_name);
- arguments = getarguments (invo_name, argc, argv, 1);
- argp = arguments;
-
-#ifdef POP
- /*
- * Scheme is:
- * use MAILHOST environment variable if present,
- * else try Hesiod.
- * If that fails, use the default (if any)
- * provided by mts.conf in mts_init()
- */
- if ((MAILHOST_env_variable = getenv("MAILHOST")) != NULL)
- pophost = MAILHOST_env_variable;
-# ifdef HESIOD
- else if ((po = hes_getmailhost(getusername())) != NULL &&
- strcmp(po->po_type, "POP") == 0)
- pophost = po->po_host;
-# endif /* HESIOD */
- /*
- * If there is a valid "pophost" entry in mts.conf,
- * then use it as the default host.
- */
- if (pophost && *pophost)
- host = pophost;
-
- if ((cp = getenv ("MHPOPDEBUG")) && *cp)
- snoop++;
-#endif /* POP */
-
- rpop = 0;
-
- while ((cp = *argp++)) {
- if (*cp == '-') {
- switch (smatch (++cp, switches)) {
- case AMBIGSW:
- ambigsw (cp, switches);
- done (1);
- case UNKWNSW:
- adios (NULL, "-%s unknown", cp);
-
- case HELPSW:
- snprintf (buf, sizeof(buf), "%s [+folder] [switches]", invo_name);
- print_help (buf, switches, 1);
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- done (1);
-
- case AUDSW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- audfile = getcpy (m_maildir (cp));
- continue;
- case NAUDSW:
- audfile = NULL;
- continue;
-
- case CHGSW:
- chgflag++;
- continue;
- case NCHGSW:
- chgflag = 0;
- continue;
-
- /*
- * The flag `trnflag' has the value:
- *
- * 2 if -truncate is given
- * 1 by default (truncating is default)
- * 0 if -notruncate is given
- */
- case TRNCSW:
- trnflag = 2;
- continue;
- case NTRNCSW:
- trnflag = 0;
- continue;
-
- case FILESW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- from = path (cp, TFILE);
-
- /*
- * If the truncate file is in default state,
- * change to not truncate.
- */
- if (trnflag == 1)
- trnflag = 0;
- continue;
-
- case SILSW:
- noisy = 0;
- continue;
- case NSILSW:
- noisy++;
- continue;
-
- case FORMSW:
- if (!(form = *argp++) || *form == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- format = NULL;
- continue;
- case FMTSW:
- if (!(format = *argp++) || *format == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- form = NULL;
- continue;
-
- case WIDTHSW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- width = atoi (cp);
- continue;
-
- case HOSTSW:
- if (!(host = *argp++) || *host == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- case USERSW:
- if (!(user = *argp++) || *user == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
-
- case PACKSW:
-#ifndef POP
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
-#else /* POP */
- if (!(packfile = *argp++) || *packfile == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
-#endif /* POP */
- continue;
- case NPACKSW:
-#ifdef POP
- packfile = NULL;
-#endif /* POP */
- continue;
-
- case APOPSW:
- rpop = -1;
- continue;
- case NAPOPSW:
- rpop = 0;
- continue;
-
- case RPOPSW:
- rpop = 1;
- continue;
- case NRPOPSW:
- rpop = 0;
- continue;
-
- case KPOPSW:
- kpop = 1;
- continue;
-
- case SNOOPSW:
- snoop++;
- continue;
-
- case SASLSW:
- sasl++;
- continue;
-
- case SASLMECHSW:
- if (!(saslmech = *argp++) || *saslmech == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- case PROXYSW:
- if (!(proxy = *argp++) || *proxy == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- }
- }
- if (*cp == '+' || *cp == '@') {
- if (folder)
- adios (NULL, "only one folder at a time!");
- else
- folder = pluspath (cp);
- } else {
- adios (NULL, "usage: %s [+folder] [switches]", invo_name);
+ int chgflag = 1, trnflag = 1;
+ int noisy = 1, width = 0;
+ int hghnum = 0, msgnum = 0;
+ int incerr = 0; /*
+ ** <0 if inc hits an error which means it should
+ ** not truncate mailspool
+ */
+ char *cp, *maildir = NULL, *folder = NULL;
+ char *form = NULL;
+ char *audfile = NULL, *from = NULL;
+ char buf[BUFSIZ], **argp, *fmtstr, **arguments;
+ struct msgs *mp = NULL;
+ struct stat st, s1;
+ FILE *aud = NULL;
+ char b[MAXPATHLEN + 1];
+ /* copy of mail directory because the static gets overwritten */
+ char *maildir_copy = NULL;
+
+ if (atexit(inc_done) != 0) {
+ adios(EX_OSERR, NULL, "atexit failed");