#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h> /* needed for Sun 4.1.2 */
#ifdef HAVE_SETRLIMIT
#include <sys/resource.h>
#endif /* HAVE_SETRLIMIT */
#include <sys/utsname.h>
+#ifdef HAVE_NET_SOCKET_H
+#include <net/socket.h>
+#endif
#ifdef HAVE_GETHOSTBYNAME
#include <netdb.h>
#endif /* HAVE_GETHOSTBYNAME */
#include "getopt.h"
#include "fetchmail.h"
+#include "socket.h"
#include "tunable.h"
#include "smtp.h"
#include "netrc.h"
flag versioninfo; /* emit only version info */
char *user; /* the name of the invoking user */
char *home; /* invoking user's home directory */
+char *fmhome; /* fetchmail's home directory */
char *program_name; /* the name to prefix error messages with */
flag configdump; /* dump control blocks for configurator */
const char *fetchmailhost; /* either `localhost' or the host's FQDN */
static int lock_acquired; /* have we acquired a lock */
static int querystatus; /* status of query */
static int successes; /* count number of successful polls */
+static int activecount; /* count number of active entries */
static struct runctl cmd_run; /* global options set from command line */
static time_t parsetime; /* time of last parse */
unlink(lockfile);
}
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) && defined(__FreeBSD_USE_KVM)
/* drop SGID kmem privileage until we need it */
static void dropprivs(void)
{
}
#endif
+#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
+#include <time.h>
+#include <locale.h>
+static char *timestamp (void)
+{
+ time_t now;
+ static char buf[60];
+
+ time (&now);
+ setlocale (LC_TIME, "");
+ strftime (buf, sizeof (buf), "%c", localtime(&now));
+ setlocale (LC_TIME, "C");
+ return (buf);
+}
+#else
+#define timestamp rfc822timestamp
+#endif
+
int main(int argc, char **argv)
{
int st, bkgd = FALSE;
pid_t pid;
int lastsig = 0;
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) && defined(__FreeBSD_USE_KVM)
dropprivs();
#endif
{
int i;
- report(stdout, "fetchmail: invoked with");
+ report(stdout, _("fetchmail: invoked with"));
for (i = 0; i < argc; i++)
report(stdout, " %s", argv[i]);
report(stdout, "\n");
}
#define IDFILE_NAME ".fetchids"
- run.idfile = (char *) xmalloc(strlen(home)+sizeof(IDFILE_NAME)+1);
- strcpy(run.idfile, home);
+ run.idfile = (char *) xmalloc(strlen(fmhome)+sizeof(IDFILE_NAME)+2);
+ strcpy(run.idfile, fmhome);
strcat(run.idfile, "/");
strcat(run.idfile, IDFILE_NAME);
sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
} else {
- xalloca(tmpbuf, char *, strlen(home) + sizeof(FETCHMAIL_PIDFILE) + 2);
- strcpy(tmpbuf, home);
- strcat(tmpbuf, "/.");
+ xalloca(tmpbuf, char *, strlen(fmhome) + sizeof(FETCHMAIL_PIDFILE) + 2);
+ strcpy(tmpbuf, fmhome);
+ strcat(tmpbuf, "/");
+ if (fmhome == home)
+ strcat(tmpbuf, ".");
strcat(tmpbuf, FETCHMAIL_PIDFILE);
}
#undef FETCHMAIL_PIDFILE
#define NETRC_FILE ".netrc"
/* parse the ~/.netrc file (if present) for future password lookups. */
- xalloca(netrc_file, char *, strlen (home) + sizeof(NETRC_FILE) + 1);
+ xalloca(netrc_file, char *, strlen(home) + sizeof(NETRC_FILE) + 2);
strcpy (netrc_file, home);
strcat (netrc_file, "/");
strcat (netrc_file, NETRC_FILE);
&& ctl->server.protocol != P_IMAP_GSS
#endif /* GSSAPI */
&& !ctl->password)
+ {
if (!isatty(0))
{
fprintf(stderr,
- _("fetchmail: can't find a password for %s@s.\n"),
+ _("fetchmail: can't find a password for %s@%s.\n"),
ctl->remotename, ctl->server.pollname);
return(PS_AUTHFAIL);
}
strlen(ctl->server.pollname) + 1);
(void) sprintf(tmpbuf, password_prompt,
ctl->remotename, ctl->server.pollname);
- ctl->password = xstrdup((char *)getpassword(tmpbuf));
+ ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
}
+ }
}
/*
sethostent(TRUE); /* use TCP/IP for mailserver queries */
#endif /* HAVE_RES_SEARCH */
+ activecount = 0;
batchcount = 0;
for (ctl = querylist; ctl; ctl = ctl->next)
- {
- if (ctl->active && !(implicitmode && ctl->server.skip))
+ if (ctl->active)
{
- if (ctl->wedged)
+ activecount++;
+ if (!(implicitmode && ctl->server.skip))
{
- report(stderr,
- _("poll of %s skipped (failed authentication or too many timeouts)\n"),
- ctl->server.pollname);
- continue;
- }
-
- /* check skip interval first so that it counts all polls */
- if (run.poll_interval && ctl->server.interval)
- {
- if (ctl->server.poll_count++ % ctl->server.interval)
+ if (ctl->wedged)
{
- if (outlevel >= O_VERBOSE)
- report(stdout,
- _("interval not reached, not querying %s\n"),
- ctl->server.pollname);
+ report(stderr,
+ _("poll of %s skipped (failed authentication or too many timeouts)\n"),
+ ctl->server.pollname);
continue;
}
- }
+
+ /* check skip interval first so that it counts all polls */
+ if (run.poll_interval && ctl->server.interval)
+ {
+ if (ctl->server.poll_count++ % ctl->server.interval)
+ {
+ if (outlevel >= O_VERBOSE)
+ report(stdout,
+ _("interval not reached, not querying %s\n"),
+ ctl->server.pollname);
+ continue;
+ }
+ }
#if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
- /*
- * Don't do monitoring if we were woken by a signal.
- * Note that interface_approve() does its own error logging.
- */
- if (!interface_approve(&ctl->server, !lastsig))
- continue;
+ /*
+ * Don't do monitoring if we were woken by a signal.
+ * Note that interface_approve() does its own error logging.
+ */
+ if (!interface_approve(&ctl->server, !lastsig))
+ continue;
#endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
- querystatus = query_host(ctl);
+ querystatus = query_host(ctl);
#ifdef POP3_ENABLE
- if (!check_only)
- uid_end_query(ctl);
+ /* leave the UIDL state alone if there have been any errors */
+ if (!check_only &&
+ ((querystatus==PS_SUCCESS) || (querystatus==PS_NOMAIL)))
+ uid_swap_lists(ctl);
#endif /* POP3_ENABLE */
- if (querystatus == PS_SUCCESS)
- successes++;
- else if (!check_only &&
- ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
- switch(querystatus)
- {
- case PS_SUCCESS:
- report(stdout, "Query status=0 (SUCCESS)\n"); break ;
- case PS_NOMAIL:
- report(stdout, "Query status=1 (NOMAIL)\n"); break ;
- case PS_SOCKET:
- report(stdout, "Query status=2 (SOCKET)\n"); break ;
- case PS_AUTHFAIL:
- report(stdout, "Query status=3 (AUTHFAIL)\n"); break ;
- case PS_PROTOCOL:
- report(stdout, "Query status=4 (PROTOCOL)\n"); break ;
- case PS_SYNTAX:
- report(stdout, "Query status=5 (SYNTAX)\n"); break ;
- case PS_IOERR:
- report(stdout, "Query status=6 (IOERR)\n"); break ;
- case PS_ERROR:
- report(stdout, "Query status=7 (ERROR)\n"); break ;
- case PS_EXCLUDE:
- report(stdout, "Query status=8 (EXCLUDE)\n"); break ;
- case PS_LOCKBUSY:
- report(stdout, "Query status=9 (LOCKBUSY)\n"); break ;
- case PS_SMTP:
- report(stdout, "Query status=10 (SMTP)\n"); break ;
- case PS_DNS:
- report(stdout, "Query status=11 (DNS)\n"); break ;
- case PS_BSMTP:
- report(stdout, "Query status=12 (BSMTP)\n"); break ;
- case PS_MAXFETCH:
- report(stdout, "Query status=13 (MAXFETCH)\n"); break ;
- default:
- report(stdout, _("Query status=%d\n"), querystatus); break;
- }
+ if (querystatus == PS_SUCCESS)
+ successes++;
+ else if (!check_only &&
+ ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
+ switch(querystatus)
+ {
+ case PS_SUCCESS:
+ report(stdout,_("Query status=0 (SUCCESS)\n"));break;
+ case PS_NOMAIL:
+ report(stdout,_("Query status=1 (NOMAIL)\n")); break;
+ case PS_SOCKET:
+ report(stdout,_("Query status=2 (SOCKET)\n")); break;
+ case PS_AUTHFAIL:
+ report(stdout,_("Query status=3 (AUTHFAIL)\n"));break;
+ case PS_PROTOCOL:
+ report(stdout,_("Query status=4 (PROTOCOL)\n"));break;
+ case PS_SYNTAX:
+ report(stdout,_("Query status=5 (SYNTAX)\n")); break;
+ case PS_IOERR:
+ report(stdout,_("Query status=6 (IOERR)\n")); break;
+ case PS_ERROR:
+ report(stdout,_("Query status=7 (ERROR)\n")); break;
+ case PS_EXCLUDE:
+ report(stdout,_("Query status=8 (EXCLUDE)\n")); break;
+ case PS_LOCKBUSY:
+ report(stdout,_("Query status=9 (LOCKBUSY)\n"));break;
+ case PS_SMTP:
+ report(stdout,_("Query status=10 (SMTP)\n")); break;
+ case PS_DNS:
+ report(stdout,_("Query status=11 (DNS)\n")); break;
+ case PS_BSMTP:
+ report(stdout,_("Query status=12 (BSMTP)\n")); break;
+ case PS_MAXFETCH:
+ report(stdout,_("Query status=13 (MAXFETCH)\n"));break;
+ default:
+ report(stdout,_("Query status=%d\n"),querystatus);
+ break;
+ }
#if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
- if (ctl->server.monitor)
- {
- /*
- * Allow some time for the link to quiesce. One
- * second is usually sufficient, three is safe.
- * Note: this delay is important - don't remove!
- */
- sleep(3);
- interface_note_activity(&ctl->server);
- }
+ if (ctl->server.monitor)
+ {
+ /*
+ * Allow some time for the link to quiesce. One
+ * second is usually sufficient, three is safe.
+ * Note: this delay is important - don't remove!
+ */
+ sleep(3);
+ interface_note_activity(&ctl->server);
+ }
#endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
+ }
}
- }
#if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
endhostent(); /* release TCP/IP connection to nameserver */
if (outlevel >= O_VERBOSE)
report(stdout,
- _("fetchmail: sleeping at %s\n"), rfc822timestamp());
+ _("fetchmail: sleeping at %s\n"), timestamp());
/*
* OK, now pause util it's time for the next poll cycle.
}
if (outlevel >= O_VERBOSE)
- report(stdout, _("awakened at %s\n"), rfc822timestamp());
+ report(stdout, _("awakened at %s\n"), timestamp());
}
} while
(run.poll_interval);
FLAG_MERGE(bsmtp);
FLAG_MERGE(listener);
FLAG_MERGE(smtpaddress);
+ FLAG_MERGE(smtpname);
FLAG_MERGE(preconnect);
FLAG_MERGE(postconnect);
FLAG_MERGE(stripcr);
FLAG_MERGE(pass8bits);
FLAG_MERGE(dropstatus);
+ FLAG_MERGE(dropdelivered);
FLAG_MERGE(mimedecode);
FLAG_MERGE(idle);
FLAG_MERGE(limit);
|| str_in_list(&ctl->server.akalist, argv[optind], TRUE))
{
/* Is this correct? */
- if(predeclared)
+ if (predeclared && outlevel == O_VERBOSE)
fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
ctl->active = TRUE;
predeclared = TRUE;
DEFAULT(ctl->forcecr, FALSE);
DEFAULT(ctl->pass8bits, FALSE);
DEFAULT(ctl->dropstatus, FALSE);
+ DEFAULT(ctl->dropdelivered, FALSE);
DEFAULT(ctl->mimedecode, FALSE);
DEFAULT(ctl->idle, FALSE);
DEFAULT(ctl->server.dns, TRUE);
/* prevent core dump from ill-formed or duplicate entry */
if (!leadname)
{
- report(stderr,
- _("Lead server has no name.\n"));
+ report(stderr, _("Lead server has no name.\n"));
exit(PS_SYNTAX);
}
ctl->server.truename = xstrdup(leadname);
}
#ifdef HAVE_GETHOSTBYNAME
- else if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
+ else if (!configdump && (ctl->server.preauthenticate==A_KERBEROS_V4 ||
ctl->server.preauthenticate==A_KERBEROS_V5 ||
- (ctl->server.dns && MULTIDROP(ctl)))
+ (ctl->server.dns && MULTIDROP(ctl))))
{
struct hostent *namerec;
report(stderr,
_("couldn't find canonical DNS name of %s\n"),
ctl->server.pollname);
- exit(PS_DNS);
+ ctl->server.truename = xstrdup(ctl->server.queryname);
+ ctl->server.trueaddr = NULL;
}
else
ctl->server.truename=xstrdup((char *)namerec->h_name);
}
#endif /* HAVE_GETHOSTBYNAME */
- else
- ctl->server.truename = xstrdup(ctl->server.queryname);
+ else {
+#ifdef HAVE_GETHOSTBYNAME
+ struct hostent *namerec;
+
+ /* <fetchmail@mail.julianhaight.com>
+ Get the host's IP, so we can report it like this:
+
+ Received: from hostname [10.0.0.1]
+
+ do we actually need to gethostbyname to find the IP?
+ it seems like it would be faster to do this later, when
+ we are actually resolving the hostname for a connection,
+ but I ain't that smart, so I don't know where to make
+ the change later..
+ */
+ errno = 0;
+ namerec = gethostbyname(ctl->server.queryname);
+ if (namerec == (struct hostent *)NULL)
+ {
+ report(stderr,
+ _("couldn't find canonical DNS name of %s\n"),
+ ctl->server.pollname);
+ exit(PS_DNS);
+ }
+ else {
+ ctl->server.truename=xstrdup((char *)namerec->h_name);
+ ctl->server.trueaddr=xmalloc(namerec->h_length);
+ memcpy(ctl->server.trueaddr,
+ namerec->h_addr_list[0],
+ namerec->h_length);
+ }
+#else
+ ctl->server.truename = xstrdup(ctl->server.queryname);
+#endif /* HAVE_GETHOSTBYNAME */
+ }
/* if no folders were specified, set up the null one as default */
if (!ctl->mailboxes)
unlockit();
#endif
- exit(successes ? PS_SUCCESS : querystatus);
+ if (activecount == 0)
+ exit(PS_NOMAIL);
+ else
+ exit(successes ? PS_SUCCESS : querystatus);
}
/*
VERSION,
ctl->server.pollname,
showproto(ctl->server.protocol),
- rfc822timestamp());
+ timestamp());
}
switch (ctl->server.protocol) {
case P_AUTO:
printf(_(" Nonempty Status lines will be %s (dropstatus %s)\n"),
ctl->dropstatus ? _("discarded") : _("kept"),
ctl->dropstatus ? "on" : "off");
+ printf(_(" Delivered-To lines will be %s (dropdelivered %s)\n"),
+ ctl->dropdelivered ? _("discarded") : _("kept"),
+ ctl->dropdelivered ? "on" : "off");
if (NUM_NONZERO(ctl->limit))
{
if (NUM_NONZERO(ctl->limit))
printf(_(" SMTP message batch limit is %d.\n"), ctl->batchlimit);
else if (outlevel >= O_VERBOSE)
printf(_(" No SMTP message batch limit (--batchlimit 0).\n"));
- if (ctl->server.protocol == P_IMAP)
+ if (ctl->server.protocol != P_ETRN)
{
if (NUM_NONZERO(ctl->expunge))
printf(_(" Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
#endif
if (ctl->server.plugin)
- printf(_(" Server connections will be mode via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
+ printf(_(" Server connections will be made via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
else if (outlevel >= O_VERBOSE)
printf(_(" No plugin command specified.\n"));
if (ctl->server.plugout)
- printf(_(" Listener connections will be mode via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
+ printf(_(" Listener connections will be made via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
else if (outlevel >= O_VERBOSE)
printf(_(" No plugout command specified.\n"));