/*
* inc.c -- incorporate messages from a maildrop into a folder
*
- * $Id$
- *
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
# include <h/popsbr.h>
#endif
-#ifdef HESIOD
-# include <hesiod.h>
-#endif
-
#include <h/fmt_scan.h>
#include <h/scansbr.h>
#include <h/signals.h>
# define POPminc(a) 0
#endif
-#ifndef RPOP
-# define RPOPminc(a) (a)
-#else
-# define RPOPminc(a) 0
-#endif
-
-#ifndef APOP
-# define APOPminc(a) (a)
-#else
-# define APOPminc(a) 0
-#endif
-
-#ifndef KPOP
-# define KPOPminc(a) (a)
-#else
-# define KPOPminc(a) 0
-#endif
-
#ifndef CYRUS_SASL
# define SASLminc(a) (a)
#else
{ "pack file", POPminc (-4) },
#define NPACKSW 10
{ "nopack", POPminc (-6) },
-#define APOPSW 11
- { "apop", APOPminc (-4) },
-#define NAPOPSW 12
- { "noapop", APOPminc (-6) },
-#define RPOPSW 13
- { "rpop", RPOPminc (-4) },
-#define NRPOPSW 14
- { "norpop", RPOPminc (-6) },
-#define SILSW 15
+#define PORTSW 11
+ { "port name/number", POPminc (-4) },
+#define SILSW 12
{ "silent", 0 },
-#define NSILSW 16
+#define NSILSW 13
{ "nosilent", 0 },
-#define TRNCSW 17
+#define TRNCSW 14
{ "truncate", 0 },
-#define NTRNCSW 18
+#define NTRNCSW 15
{ "notruncate", 0 },
-#define WIDTHSW 19
+#define WIDTHSW 16
{ "width columns", 0 },
-#define VERSIONSW 20
+#define VERSIONSW 17
{ "version", 0 },
-#define HELPSW 21
+#define HELPSW 18
{ "help", 0 },
-#define SNOOPSW 22
+#define SNOOPSW 19
{ "snoop", -5 },
-#define KPOPSW 23
- { "kpop", KPOPminc (-4) },
-#define SASLSW 24
+#define SASLSW 20
{ "sasl", SASLminc(-4) },
-#define SASLMECHSW 25
+#define SASLMECHSW 21
{ "saslmech", SASLminc(-8) },
-#define PROXYSW 26
+#define PROXYSW 22
{ "proxy command", POPminc(-5) },
{ NULL, 0 }
};
#define SAVEGROUPPRIVS()
#endif /* not MAILGROUP */
-#ifdef POP
-#define DROPUSERPRIVS() setuid(getuid())
-#else
-#define DROPUSERPRIVS()
-#endif
-
/* these variables have to be globals so that done() can correctly clean up the lockfile */
static int locked = 0;
static char *newmail;
{
int chgflag = 1, trnflag = 1;
int noisy = 1, width = 0;
- int rpop, i, hghnum, msgnum;
- int kpop = 0, sasl = 0;
- char *cp, *maildir, *folder = NULL;
+ int hghnum = 0, msgnum = 0;
+ int sasl = 0;
+ int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */
+ char *cp, *maildir = NULL, *folder = NULL;
char *format = NULL, *form = NULL;
- char *host = NULL, *user = NULL, *proxy = NULL;
+ char *host = NULL, *port = NULL, *user = NULL, *proxy = NULL;
char *audfile = NULL, *from = NULL, *saslmech = NULL;
char buf[BUFSIZ], **argp, *nfs, **arguments;
- struct msgs *mp;
+ struct msgs *mp = NULL;
struct stat st, s1;
FILE *aud = NULL;
- char b[MAXPATHLEN + 1];
- char *maildir_copy; /* copy of mail directory because the static gets overwritten */
+ char b[MAXPATHLEN + 1];
+ char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */
#ifdef POP
- int nmsgs, nbytes, p = 0;
+ int nmsgs, nbytes;
char *pass = NULL;
char *MAILHOST_env_variable;
#endif
FILE *mhe = NULL;
#endif
-#ifdef HESIOD
- struct hes_postoffice *po;
-#endif
-
done=inc_done;
/* absolutely the first thing we do is save our privileges,
*/
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.
snoop++;
#endif /* POP */
- rpop = 0;
-
while ((cp = *argp++)) {
if (*cp == '-') {
switch (smatch (++cp, switches)) {
if (!(host = *argp++) || *host == '-')
adios (NULL, "missing argument to %s", argp[-2]);
continue;
+
+ case PORTSW:
+ if (!(host = *argp++) || *port == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ continue;
+
case USERSW:
if (!(user = *argp++) || *user == '-')
adios (NULL, "missing argument to %s", argp[-2]);
#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;
#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 */
if (inc_type == INC_POP) {
if (user == NULL)
user = getusername ();
- if ( strcmp( POPSERVICE, "kpop" ) == 0 ) {
- kpop = 1;
- }
- if (kpop || sasl || ( rpop > 0))
+ if (sasl)
pass = getusername ();
else
ruserpass (host, &user, &pass);
/*
* initialize POP connection
*/
- if (pop_init (host, user, pass, proxy, snoop, kpop ? 1 : rpop, kpop,
- sasl, saslmech) == NOTOK)
+ if (pop_init (host, port, user, pass, proxy, snoop, sasl,
+ saslmech) == NOTOK)
adios (NULL, "%s", response);
/* Check if there are any messages */
if (pop_stat (&nmsgs, &nbytes) == NOTOK)
adios (NULL, "%s", response);
- if (rpop > 0)
- DROPUSERPRIVS();
if (nmsgs == 0) {
pop_quit();
adios (NULL, "no mail to incorporate");
adios (NULL, "no mail to incorporate");
if ((cp = strdup(newmail)) == (char *)0)
- adios (maildir, "error allocating memory to copy newmail");
+ adios (NULL, "error allocating memory to copy newmail");
newmail = cp;
}
DROPGROUPPRIVS();
if (audfile) {
+ int i;
if ((i = stat (audfile, &st)) == NOTOK)
advise (NULL, "Creating Receive-Audit: %s", audfile);
if ((aud = fopen (audfile, "a")) == NULL)
#ifdef POP
fprintf (aud, from ? "<<inc>> %s -ms %s\n"
- : host ? "<<inc>> %s -host %s -user %s%s\n"
+ : host ? "<<inc>> %s -host %s -user %s\n"
: "<<inc>> %s\n",
- dtimenow (0), from ? from : host, user,
- rpop < 0 ? " -apop" : rpop > 0 ? " -rpop" : "");
+ dtimenow (0), from ? from : host, user);
#else /* POP */
fprintf (aud, from ? "<<inc>> %s -ms %s\n" : "<<inc>> %s\n",
dtimenow (0), from);
#ifdef MHE
if (context_find ("mhe")) {
+ int i;
cp = concat (maildir, "/++", NULL);
i = stat (cp, &st);
if ((mhe = fopen (cp, "a")) == NULL)
* Get the mail from a POP server
*/
if (inc_type == INC_POP) {
+ int i;
if (packfile) {
packfile = path (packfile, TFILE);
if (stat (packfile, &st) == NOTOK) {
adios (cp, "write error on");
fseek (pf, 0L, SEEK_SET);
}
- switch (p = scan (pf, msgnum, 0, nfs, width,
+ switch (incerr = scan (pf, msgnum, 0, nfs, width,
packfile ? 0 : msgnum == mp->hghmsg + 1 && chgflag,
1, NULL, stop - start, noisy)) {
case SCNEOF:
if (inc_type == INC_FILE) {
m_unknown (in); /* the MAGIC invocation... */
hghnum = msgnum = mp->hghmsg;
- for (i = 0;;) {
+ for (;;) {
/*
* Check if we need to allocate more space for message status.
* If so, then add space for an additional 100 messages.
if (msgnum >= mp->hghoff
&& !(mp = folder_realloc (mp, mp->lowoff, mp->hghoff + 100))) {
advise (NULL, "unable to allocate folder storage");
- i = NOTOK;
+ incerr = NOTOK;
break;
}
newmsg = folder_addmsg(mp, tmpfilenam);
#endif
/* create scanline for new message */
- switch (i = scan (in, msgnum + 1, msgnum + 1, nfs, width,
+ switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width,
msgnum == hghnum && chgflag, 1, NULL, 0L, noisy)) {
case SCNFAT:
case SCNEOF:
break;
default:
- advise (NULL, "BUG in %s, scan() botch (%d)", invo_name, i);
+ advise (NULL, "BUG in %s, scan() botch (%d)", invo_name, incerr);
break;
case SCNMSG:
mp->msgflags |= SEQMOD;
continue;
}
+ /* If we get here there was some sort of error from scan(),
+ * so stop processing anything more from the spool.
+ */
break;
}
}
-#ifdef POP
- if (p < 0) { /* error */
-#else
- if (i < 0) { /* error */
-#endif
+ if (incerr < 0) { /* error */
if (locked) {
GETGROUPPRIVS(); /* Be sure we can unlock mail file */
(void) lkfclose (in, newmail); in = NULL;
if (stat (newmail, &st) != NOTOK && s1.st_mtime != st.st_mtime)
advise (NULL, "new messages have arrived!\007");
else {
- if ((i = creat (newmail, 0600)) != NOTOK)
- close (i);
+ int newfd;
+ if ((newfd = creat (newmail, 0600)) != NOTOK)
+ close (newfd);
else
admonish (newmail, "error zero'ing");
unlink(map_name(newmail));