- 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 = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
- } else {
- adios (NULL, "usage: %s [+folder] [switches]", invo_name);
- }
- }
-
- /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
- * not DROPGROUPPRIVS().
- */
-#ifdef POP
- if (host && !*host)
- host = NULL;
- if (from || !host || rpop <= 0)
- DROPUSERPRIVS();
-#endif /* POP */
-
- /* guarantee dropping group priveleges; we might not have done so earlier */
- DROPGROUPPRIVS();
-
- /*
- * Where are we getting the new mail?
- */
- if (from)
- inc_type = INC_FILE;
-#ifdef POP
- else if (host)
- inc_type = INC_POP;