2 * fetchmail.c -- main driver module for fetchmail
4 * For license terms, see the file COPYING in this directory.
9 #if defined(STDC_HEADERS)
12 #if defined(HAVE_UNISTD_H)
18 #if defined(HAVE_SYSLOG)
26 #include <sys/types.h>
28 #include <sys/time.h> /* needed for Sun 4.1.2 */
30 #include <sys/resource.h>
31 #endif /* HAVE_SETRLIMIT */
32 #include <sys/utsname.h>
34 #ifdef HAVE_NET_SOCKET_H
35 #include <net/socket.h>
37 #ifdef HAVE_GETHOSTBYNAME
39 #endif /* HAVE_GETHOSTBYNAME */
46 #include "fetchmail.h"
54 #define ENETUNREACH 128 /* Interactive doesn't know this */
55 #endif /* ENETUNREACH */
57 /* prototypes for internal functions */
58 static int load_params(int, char **, int);
59 static void dump_params (struct runctl *runp, struct query *, flag implicit);
60 static int query_host(struct query *);
62 /* controls the detail level of status/progress messages written to stderr */
63 int outlevel; /* see the O_.* constants above */
65 /* miscellaneous global controls */
66 struct runctl run; /* global controls for this run */
67 flag nodetach; /* if TRUE, don't detach daemon process */
68 flag quitmode; /* if --quit was set */
69 flag check_only; /* if --probe was set */
70 flag versioninfo; /* emit only version info */
71 char *user; /* the name of the invoking user */
72 char *home; /* invoking user's home directory */
73 char *fmhome; /* fetchmail's home directory */
74 char *program_name; /* the name to prefix error messages with */
75 flag configdump; /* dump control blocks for configurator */
76 const char *fetchmailhost; /* either `localhost' or the host's FQDN */
81 #endif /* NET_SECURITY */
83 static char *lockfile; /* name of lockfile */
84 static int lock_acquired; /* have we acquired a lock */
85 static int querystatus; /* status of query */
86 static int successes; /* count number of successful polls */
87 static int activecount; /* count number of active entries */
88 static struct runctl cmd_run; /* global options set from command line */
89 static time_t parsetime; /* time of last parse */
91 static void terminate_run(int);
92 static void terminate_poll(int);
95 static void unlockit(int n, void *p)
97 static void unlockit(void)
99 /* must-do actions for exit (but we can't count on being able to do malloc) */
101 if (lockfile && lock_acquired)
105 #if defined(__FreeBSD__) && defined(__FreeBSD_USE_KVM)
106 /* drop SGID kmem privileage until we need it */
107 static void dropprivs(void)
117 if (gr && !strcmp(gr->gr_name, "kmem"))
119 extern void interface_set_gids(gid_t egid, gid_t rgid);
120 interface_set_gids(egid, rgid);
126 #if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
129 static char *timestamp (void)
135 setlocale (LC_TIME, "");
136 strftime (buf, sizeof (buf), "%c", localtime(&now));
137 setlocale (LC_TIME, "C");
141 #define timestamp rfc822timestamp
144 int main(int argc, char **argv)
146 int st, bkgd = FALSE;
147 int parsestatus, implicitmode = FALSE;
150 netrc_entry *netrc_list;
151 char *netrc_file, *tmpbuf;
155 #if defined(__FreeBSD__) && defined(__FreeBSD_USE_KVM)
159 envquery(argc, argv);
161 setlocale (LC_ALL, "");
162 bindtextdomain(PACKAGE, LOCALEDIR);
167 * Note: because we can't initialize reporting before we know whether
168 * syslog is supposed to be on, this message will go to stdout and
169 * be lost when running in background.
171 if (outlevel >= O_VERBOSE)
175 report(stdout, _("fetchmail: invoked with"));
176 for (i = 0; i < argc; i++)
177 report(stdout, " %s", argv[i]);
178 report(stdout, "\n");
181 #define IDFILE_NAME ".fetchids"
182 run.idfile = (char *) xmalloc(strlen(fmhome)+sizeof(IDFILE_NAME)+2);
183 strcpy(run.idfile, fmhome);
184 strcat(run.idfile, "/");
185 strcat(run.idfile, IDFILE_NAME);
190 * We used to arrange for the lockfile to be removed on exit close
191 * to where the lock was asserted. Now we need to do it here, because
192 * we might have re-executed in background with an existing lockfile
193 * as the result of a changed rcfile (see the code near the execvp(3)
194 * call near the beginning of the polling loop for details). We want
195 * to be sure the lockfile gets nuked on any error exit, basically.
201 on_exit(unlockit, (char *)NULL);
204 if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
209 printf(_("This is fetchmail release %s"), VERSION);
212 #endif /* POP2_ENABLE */
215 #endif /* POP3_ENABLE */
218 #endif /* IMAP_ENABLE */
224 #endif /* RPA_ENABLE */
227 #endif /* NTLM_ENABLE */
230 #endif /* SDPS_ENABLE */
233 #endif /* ETRN_ENABLE */
236 #endif /* ODMR_ENABLE */
242 #endif /* OPIE_ENABLE */
245 #endif /* INET6_ENABLE */
248 #endif /* NET_SECURITY */
251 #endif /* HAVE_SOCKS */
254 #endif /* ENABLE_NLS */
258 /* this is an attempt to help remote debugging */
262 /* avoid parsing the config file if all we're doing is killing a daemon */
263 if (!(quitmode && argc == 2))
264 implicitmode = load_params(argc, argv, optind);
266 #if defined(HAVE_SYSLOG)
267 /* logging should be set up early in case we were restarted from exec */
270 #if defined(LOG_MAIL)
271 openlog(program_name, LOG_PID, LOG_MAIL);
273 /* Assume BSD4.2 openlog with two arguments */
274 openlog(program_name, LOG_PID);
280 report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
282 /* set up to do lock protocol */
283 #define FETCHMAIL_PIDFILE "fetchmail.pid"
285 xalloca(tmpbuf, char *,
286 sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
287 sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
289 xalloca(tmpbuf, char *, strlen(fmhome) + sizeof(FETCHMAIL_PIDFILE) + 2);
290 strcpy(tmpbuf, fmhome);
294 strcat(tmpbuf, FETCHMAIL_PIDFILE);
296 #undef FETCHMAIL_PIDFILE
298 #ifdef HAVE_SETRLIMIT
300 * Before getting passwords, disable core dumps unless -v -d0 mode is on.
301 * Core dumps could otherwise contain passwords to be scavenged by a
304 if (outlevel < O_VERBOSE || run.poll_interval > 0)
306 struct rlimit corelimit;
307 corelimit.rlim_cur = 0;
308 corelimit.rlim_max = 0;
309 setrlimit(RLIMIT_CORE, &corelimit);
311 #endif /* HAVE_SETRLIMIT */
313 #define NETRC_FILE ".netrc"
314 /* parse the ~/.netrc file (if present) for future password lookups. */
315 xalloca(netrc_file, char *, strlen(home) + sizeof(NETRC_FILE) + 2);
316 strcpy (netrc_file, home);
317 strcat (netrc_file, "/");
318 strcat (netrc_file, NETRC_FILE);
319 netrc_list = parse_netrc(netrc_file);
322 /* pick up passwords where we can */
323 for (ctl = querylist; ctl; ctl = ctl->next)
325 if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
327 if (ctl->server.preauthenticate > A_PASSWORD || ctl->server.protocol >= P_ETRN)
328 /* Server won't care what the password is, but there
329 must be some non-null string here. */
330 ctl->password = ctl->remotename;
335 /* look up the pollname and account in the .netrc file. */
336 p = search_netrc(netrc_list,
337 ctl->server.pollname, ctl->remotename);
338 /* if we find a matching entry with a password, use it */
339 if (p && p->password)
340 ctl->password = xstrdup(p->password);
342 /* otherwise try with "via" name if there is one */
343 else if (ctl->server.via)
345 p = search_netrc(netrc_list,
346 ctl->server.via, ctl->remotename);
347 if (p && p->password)
348 ctl->password = xstrdup(p->password);
354 /* perhaps we just want to check options? */
357 int havercfile = access(rcfile, 0);
359 printf(_("Taking options from command line%s%s\n"),
360 havercfile ? "" : _(" and "),
361 havercfile ? "" : rcfile);
363 if (outlevel >= O_VERBOSE)
364 printf(_("Lockfile at %s\n"), tmpbuf);
366 if (querylist == NULL)
368 _("No mailservers set up -- perhaps %s is missing?\n"),
371 dump_params(&run, querylist, implicitmode);
375 /* dump options as a Python dictionary, for configurator use */
378 dump_config(&run, querylist);
382 /* check for another fetchmail running concurrently */
384 if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
386 report(stderr,_("fetchmail: cannot allocate memory for lock name.\n"));
390 (void) strcpy(lockfile, tmpbuf);
391 if ((lockfp = fopen(lockfile, "r")) != NULL )
393 bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
395 if (kill(pid, 0) == -1) {
396 fprintf(stderr,_("fetchmail: removing stale lockfile\n"));
401 fclose(lockfp); /* not checking should be safe, file mode was "r" */
404 /* if no mail servers listed and nothing in background, we're done */
405 if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
406 (void)fputs(_("fetchmail: no mailservers have been specified.\n"),stderr);
410 /* perhaps user asked us to kill the other fetchmail */
415 fprintf(stderr,_("fetchmail: no other fetchmail is running\n"));
419 else if (kill(pid, SIGTERM) < 0)
421 fprintf(stderr,_("fetchmail: error killing %s fetchmail at %d; bailing out.\n"),
422 bkgd ? _("background") : _("foreground"), pid);
427 fprintf(stderr,_("fetchmail: %s fetchmail at %d killed.\n"),
428 bkgd ? _("background") : _("foreground"), pid);
437 /* another fetchmail is running -- wake it up or die */
443 _("fetchmail: can't check mail while another fetchmail to same host is running.\n"));
446 else if (!implicitmode)
449 _("fetchmail: can't poll specified hosts with another fetchmail running at %d.\n"),
456 _("fetchmail: another foreground fetchmail is running at %d.\n"),
462 /* this test enables re-execing on a changed rcfile */
464 lock_acquired = TRUE;
468 _("fetchmail: can't accept options while a background fetchmail is running.\n"));
472 else if (kill(pid, SIGUSR1) == 0)
475 _("fetchmail: background fetchmail at %d awakened.\n"),
482 * Should never happen -- possible only if a background fetchmail
483 * croaks after the first kill probe above but before the
484 * SIGUSR1/SIGHUP transmission.
487 _("fetchmail: elder sibling at %d died mysteriously.\n"),
489 return(PS_UNDEFINED);
493 /* pick up interactively any passwords we need but don't have */
494 for (ctl = querylist; ctl; ctl = ctl->next)
496 if (ctl->active && !(implicitmode && ctl->server.skip)
497 && ctl->server.preauthenticate <= A_PASSWORD
498 && ctl->server.protocol < P_ETRN
504 _("fetchmail: can't find a password for %s@%s.\n"),
505 ctl->remotename, ctl->server.pollname);
510 char* password_prompt = _("Enter password for %s@%s: ");
512 xalloca(tmpbuf, char *, strlen(password_prompt) +
513 strlen(ctl->remotename) +
514 strlen(ctl->server.pollname) + 1);
515 (void) sprintf(tmpbuf, password_prompt,
516 ctl->remotename, ctl->server.pollname);
517 ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
523 * Time to initiate the SOCKS library (this is not mandatory: it just
524 * registers the correct application name for logging purpose. If you
525 * have some problem, comment out these lines).
528 SOCKSinit("fetchmail");
529 #endif /* HAVE_SOCKS */
532 * Maybe time to go to demon mode...
534 if (run.poll_interval)
539 daemonize(run.logfile, terminate_run);
540 report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
543 * We'll set up a handler for these when we're sleeping,
544 * but ignore them otherwise so as not to interrupt a poll.
546 signal(SIGUSR1, SIG_IGN);
547 if (run.poll_interval && !getuid())
548 signal(SIGHUP, SIG_IGN);
550 else if (run.logfile && access(run.logfile, F_OK) == 0)
552 freopen(run.logfile, "a", stdout);
553 freopen(run.logfile, "a", stderr);
561 /* beyond here we don't want more than one fetchmail running per user */
563 signal(SIGABRT, terminate_run);
564 signal(SIGINT, terminate_run);
565 signal(SIGTERM, terminate_run);
566 signal(SIGALRM, terminate_run);
567 signal(SIGPIPE, terminate_run);
568 signal(SIGQUIT, terminate_run);
570 /* here's the exclusion lock */
572 #define O_SYNC 0 /* use it if we have it */
576 if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
578 sprintf(tmpbuf,"%d", getpid());
579 write(st, tmpbuf, strlen(tmpbuf));
580 if (run.poll_interval)
582 sprintf(tmpbuf," %d", run.poll_interval);
583 write(st, tmpbuf, strlen(tmpbuf));
585 close(st); /* should be safe, fd was opened with O_SYNC */
586 lock_acquired = TRUE;
590 fprintf(stderr, _("fetchmail: lock creation failed.\n"));
596 * Query all hosts. If there's only one, the error return will
597 * reflect the status of that transaction.
601 * Check to see if the rcfile has been touched. If so,
602 * re-exec so the file will be reread. Doing it this way
603 * avoids all the complications of trying to deallocate the
604 * in-core control structures -- and the potential memory
609 if (stat(rcfile, &rcstat) == -1)
613 _("couldn't time-check %s (error %d)\n"),
616 else if (rcstat.st_mtime > parsetime)
618 report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
620 * Matthias Andree: Isn't this prone to introduction of
621 * "false" programs by interfering with PATH? Those
622 * path-searching execs might not be the best ideas for
625 * Rob Funk: But is there any way for someone to modify
626 * the PATH variable of a running fetchmail? I don't know
629 * Dave's change makes fetchmail restart itself in exactly
630 * the way it was started from the shell (or shell script)
631 * in the first place. If you're concerned about PATH
632 * contamination, call fetchmail initially with a full
633 * path, and use Dave's patch.
635 * Not using a -p variant of exec means that the restart
636 * will break if both (a) the user depended on PATH to
637 * call fetchmail in the first place, and (b) the system
638 * doesn't save the whole path in argv[0] if the whole
639 * path wasn't used in the initial call. (If I recall
640 * correctly, Linux saves it but many other Unices don't.)
642 execvp(argv[0], argv);
643 report(stderr, _("attempt to re-exec fetchmail failed\n"));
646 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
648 * This was an efficiency hack that backfired. The theory
649 * was that using TCP/IP for DNS queries would get us better
650 * reliability and shave off some per-UDP-packet costs.
651 * Unfortunately it interacted badly with diald, which effectively
652 * filters out DNS queries over TCP/IP for reasons having to do
653 * with some obscure Linux kernel problem involving bootstrapping of
654 * dynamically-addressed links. I don't understand this mess
655 * and don't want to, so it's "See ya!" to this hack.
657 sethostent(TRUE); /* use TCP/IP for mailserver queries */
658 #endif /* HAVE_RES_SEARCH */
662 for (ctl = querylist; ctl; ctl = ctl->next)
666 if (!(implicitmode && ctl->server.skip))
671 _("poll of %s skipped (failed authentication or too many timeouts)\n"),
672 ctl->server.pollname);
676 /* check skip interval first so that it counts all polls */
677 if (run.poll_interval && ctl->server.interval)
679 if (ctl->server.poll_count++ % ctl->server.interval)
681 if (outlevel >= O_VERBOSE)
683 _("interval not reached, not querying %s\n"),
684 ctl->server.pollname);
689 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
691 * Don't do monitoring if we were woken by a signal.
692 * Note that interface_approve() does its own error logging.
694 if (!interface_approve(&ctl->server, !lastsig))
696 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
698 querystatus = query_host(ctl);
701 /* leave the UIDL state alone if there have been any errors */
703 ((querystatus==PS_SUCCESS) || (querystatus==PS_NOMAIL) || (querystatus==PS_MAXFETCH)))
705 #endif /* POP3_ENABLE */
707 if (querystatus == PS_SUCCESS)
709 else if (!check_only &&
710 ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
714 report(stdout,_("Query status=0 (SUCCESS)\n"));break;
716 report(stdout,_("Query status=1 (NOMAIL)\n")); break;
718 report(stdout,_("Query status=2 (SOCKET)\n")); break;
720 report(stdout,_("Query status=3 (AUTHFAIL)\n"));break;
722 report(stdout,_("Query status=4 (PROTOCOL)\n"));break;
724 report(stdout,_("Query status=5 (SYNTAX)\n")); break;
726 report(stdout,_("Query status=6 (IOERR)\n")); break;
728 report(stdout,_("Query status=7 (ERROR)\n")); break;
730 report(stdout,_("Query status=8 (EXCLUDE)\n")); break;
732 report(stdout,_("Query status=9 (LOCKBUSY)\n"));break;
734 report(stdout,_("Query status=10 (SMTP)\n")); break;
736 report(stdout,_("Query status=11 (DNS)\n")); break;
738 report(stdout,_("Query status=12 (BSMTP)\n")); break;
740 report(stdout,_("Query status=13 (MAXFETCH)\n"));break;
742 report(stdout,_("Query status=%d\n"),querystatus);
746 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
747 if (ctl->server.monitor)
750 * Allow some time for the link to quiesce. One
751 * second is usually sufficient, three is safe.
752 * Note: this delay is important - don't remove!
755 interface_note_activity(&ctl->server);
757 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
761 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
762 endhostent(); /* release TCP/IP connection to nameserver */
763 #endif /* HAVE_RES_SEARCH */
765 /* close connections cleanly */
769 * OK, we've polled. Now sleep.
771 if (run.poll_interval)
774 * Because passwords can expire, it may happen that *all*
775 * hosts are now out of the loop due to authfail
776 * conditions. If this happens daemon-mode fetchmail
777 * should softly and silently vanish away, rather than
778 * spinning uselessly.
782 for (ctl = querylist; ctl; ctl = ctl->next)
783 if (ctl->active && !(implicitmode && ctl->server.skip))
788 report(stderr, _("All connections are wedged. Exiting.\n"));
789 /* FIXME: someday, send notification mail */
793 if (outlevel >= O_VERBOSE)
795 _("fetchmail: sleeping at %s\n"), timestamp());
798 * OK, now pause util it's time for the next poll cycle.
799 * A nonzero return indicates we received a wakeup signal;
800 * unwedge all servers in case the problem has been
803 if ((lastsig = interruptible_idle(run.poll_interval)))
805 #ifdef SYS_SIGLIST_DECLARED
807 _("awakened by %s\n"), sys_siglist[lastsig]);
810 _("awakened by signal %d\n"), lastsig);
812 for (ctl = querylist; ctl; ctl = ctl->next)
816 if (outlevel >= O_VERBOSE)
817 report(stdout, _("awakened at %s\n"), timestamp());
822 if (outlevel >= O_VERBOSE)
823 report(stdout, _("normal termination, status %d\n"),
824 successes ? PS_SUCCESS : querystatus);
830 else if (querystatus)
833 /* in case we interrupted before a successful fetch */
837 static void list_merge(struct idlist **dstl, struct idlist **srcl, int force)
840 * If force is off, modify dstl fields only when they're empty (treat srcl
841 * as defaults). If force is on, modify each dstl field whenever scrcl
842 * is nonempty (treat srcl as an override).
844 if (force ? !!*srcl : !*dstl)
846 struct idlist *cpl = copy_str_list(*srcl);
848 append_str_list(dstl, &cpl);
852 static void optmerge(struct query *h2, struct query *h1, int force)
853 /* merge two options records */
855 list_merge(&h2->server.localdomains, &h1->server.localdomains, force);
856 list_merge(&h2->localnames, &h1->localnames, force);
857 list_merge(&h2->mailboxes, &h1->mailboxes, force);
858 list_merge(&h2->smtphunt, &h1->smtphunt, force);
859 list_merge(&h2->antispam, &h1->antispam, force);
861 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
862 FLAG_MERGE(server.via);
863 FLAG_MERGE(server.protocol);
865 FLAG_MERGE(server.service);
866 FLAG_MERGE(server.netsec);
867 #else /* INET6_ENABLE */
868 FLAG_MERGE(server.port);
869 #endif /* INET6_ENABLE */
870 FLAG_MERGE(server.interval);
871 FLAG_MERGE(server.preauthenticate);
872 FLAG_MERGE(server.timeout);
873 FLAG_MERGE(server.envelope);
874 FLAG_MERGE(server.envskip);
875 FLAG_MERGE(server.qvirtual);
876 FLAG_MERGE(server.skip);
877 FLAG_MERGE(server.dns);
878 FLAG_MERGE(server.checkalias);
879 FLAG_MERGE(server.uidl);
880 FLAG_MERGE(server.principal);
882 #if defined(linux) || defined(__FreeBSD__)
883 FLAG_MERGE(server.interface);
884 FLAG_MERGE(server.monitor);
885 FLAG_MERGE(server.interface_pair);
886 #endif /* linux || defined(__FreeBSD__) */
888 FLAG_MERGE(server.plugin);
889 FLAG_MERGE(server.plugout);
891 FLAG_MERGE(wildcard);
892 FLAG_MERGE(remotename);
893 FLAG_MERGE(password);
896 FLAG_MERGE(listener);
897 FLAG_MERGE(smtpaddress);
898 FLAG_MERGE(smtpname);
899 FLAG_MERGE(preconnect);
900 FLAG_MERGE(postconnect);
904 FLAG_MERGE(fetchall);
908 FLAG_MERGE(pass8bits);
909 FLAG_MERGE(dropstatus);
910 FLAG_MERGE(dropdelivered);
911 FLAG_MERGE(mimedecode);
914 FLAG_MERGE(warnings);
915 FLAG_MERGE(fetchlimit);
916 FLAG_MERGE(batchlimit);
924 FLAG_MERGE(properties);
928 static int load_params(int argc, char **argv, int optind)
930 int implicitmode, st;
932 struct query def_opts, *ctl;
935 run.bouncemail = TRUE;
936 run.spambounce = FALSE; /* don't bounce back to innocent bystanders */
938 memset(&def_opts, '\0', sizeof(struct query));
939 def_opts.smtp_socket = -1;
940 def_opts.smtpaddress = (char *)0;
941 def_opts.smtpname = (char *)0;
942 #define ANTISPAM(n) save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
943 ANTISPAM(571); /* sendmail */
944 ANTISPAM(550); /* old exim */
945 ANTISPAM(501); /* new exim */
946 ANTISPAM(554); /* Postfix */
949 def_opts.server.protocol = P_AUTO;
950 def_opts.server.timeout = CLIENT_TIMEOUT;
951 def_opts.warnings = WARNING_INTERVAL;
952 def_opts.remotename = user;
953 def_opts.listener = SMTP_MODE;
955 /* note the parse time, so we can pick up on modifications */
956 parsetime = 0; /* foil compiler warnings */
957 if (stat(rcfile, &rcstat) != -1)
958 parsetime = rcstat.st_mtime;
959 else if (errno != ENOENT)
960 report(stderr, _("couldn't time-check the run-control file\n"));
962 /* this builds the host list */
963 if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
965 * FIXME: someday, send notification mail here if backgrounded.
966 * Right now, that can happen if the user changes the rcfile
967 * while the fetchmail is running in background. Do similarly
968 * for the other exit() calls in this function.
972 if ((implicitmode = (optind >= argc)))
974 for (ctl = querylist; ctl; ctl = ctl->next)
978 for (; optind < argc; optind++)
980 flag predeclared = FALSE;
983 * If hostname corresponds to a host known from the rc file,
984 * simply declare it active. Otherwise synthesize a host
985 * record from command line and defaults
987 for (ctl = querylist; ctl; ctl = ctl->next)
988 if (!strcmp(ctl->server.pollname, argv[optind])
989 || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
991 /* Is this correct? */
992 if (predeclared && outlevel == O_VERBOSE)
993 fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
1001 * Allocate and link record without copying in
1002 * command-line args; we'll do that with the optmerge
1005 ctl = hostalloc((struct query *)NULL);
1007 ctl->server.pollname = xstrdup(argv[optind]);
1009 ctl->server.lead_server = (struct hostdata *)NULL;
1014 * If there's a defaults record, merge it and lose it.
1016 if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
1018 for (ctl = querylist->next; ctl; ctl = ctl->next)
1019 optmerge(ctl, querylist, FALSE);
1020 querylist = querylist->next;
1023 /* don't allow a defaults record after the first */
1024 for (ctl = querylist; ctl; ctl = ctl->next)
1025 if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
1028 /* use localhost if we never fetch the FQDN of this host */
1029 fetchmailhost = "localhost";
1031 /* here's where we override globals */
1032 if (cmd_run.logfile)
1033 run.logfile = cmd_run.logfile;
1035 run.idfile = cmd_run.idfile;
1036 /* do this before the keep/fetchall test below, otherwise -d0 may fail */
1037 if (cmd_run.poll_interval >= 0)
1038 run.poll_interval = cmd_run.poll_interval;
1039 if (cmd_run.invisible)
1040 run.invisible = cmd_run.invisible;
1041 if (cmd_run.showdots)
1042 run.showdots = cmd_run.showdots;
1043 if (cmd_run.use_syslog)
1044 run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
1045 if (cmd_run.postmaster)
1046 run.postmaster = cmd_run.postmaster;
1047 if (cmd_run.bouncemail)
1048 run.bouncemail = cmd_run.bouncemail;
1050 /* check and daemon options are not compatible */
1051 if (check_only && run.poll_interval)
1052 run.poll_interval = 0;
1054 /* merge in wired defaults, do sanity checks and prepare internal fields */
1055 for (ctl = querylist; ctl; ctl = ctl->next)
1057 ctl->wedged = FALSE;
1059 if (configdump || ctl->active )
1061 /* merge in defaults */
1062 optmerge(ctl, &def_opts, FALSE);
1064 /* force command-line options */
1065 optmerge(ctl, &cmd_opts, TRUE);
1067 /* this code enables flags to be turned off */
1068 #define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
1070 else if (flag == FLAG_FALSE)\
1074 DEFAULT(ctl->keep, FALSE);
1075 DEFAULT(ctl->fetchall, FALSE);
1076 DEFAULT(ctl->flush, FALSE);
1077 DEFAULT(ctl->rewrite, TRUE);
1078 DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
1079 DEFAULT(ctl->forcecr, FALSE);
1080 DEFAULT(ctl->pass8bits, FALSE);
1081 DEFAULT(ctl->dropstatus, FALSE);
1082 DEFAULT(ctl->dropdelivered, FALSE);
1083 DEFAULT(ctl->mimedecode, FALSE);
1084 DEFAULT(ctl->idle, FALSE);
1085 DEFAULT(ctl->server.dns, TRUE);
1086 DEFAULT(ctl->server.uidl, FALSE);
1088 DEFAULT(ctl->use_ssl, FALSE);
1090 DEFAULT(ctl->server.checkalias, FALSE);
1094 * DNS support is required for some protocols. We used to
1095 * do this unconditionally, but it made fetchmail excessively
1096 * vulnerable to misconfigured DNS setups.
1098 * If we're using ETRN or ODMR, the smtp hunt list is the
1099 * list of systems we're polling on behalf of; these have
1100 * to be fully-qualified domain names. The default for
1101 * this list should be the FQDN of localhost.
1103 * If we're using Kerberos for authentication, we need
1104 * the FQDN in order to generate capability keys. */
1105 if (ctl->server.protocol==P_ETRN || ctl->server.protocol==P_ODMR
1106 || ctl->server.preauthenticate == A_KERBEROS_V4
1107 || ctl->server.preauthenticate == A_KERBEROS_V5)
1108 if (strcmp(fetchmailhost, "localhost") == 0)
1109 fetchmailhost = host_fqdn();
1112 * Make sure we have a nonempty host list to forward to.
1115 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1117 /* if `user' doesn't name a real local user, try to run as root */
1118 if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1121 ctl->uid = pw->pw_uid; /* for local delivery via MDA */
1122 if (!ctl->localnames) /* for local delivery via SMTP */
1123 save_str_pair(&ctl->localnames, user, NULL);
1125 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1126 /* can't handle multidrop mailboxes unless we can do DNS lookups */
1127 if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1129 ctl->server.dns = FALSE;
1130 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1132 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1136 * Compute the true name of the mailserver host.
1137 * There are two clashing cases here:
1139 * (1) The poll name is a label, possibly on one of several
1140 * poll configurations for the same host. In this case
1141 * the `via' option will be present and give the true name.
1143 * (2) The poll name is the true one, the via name is
1144 * localhost. This is going to be typical for ssh-using
1147 * We're going to assume the via name is true unless it's
1150 if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1151 ctl->server.queryname = xstrdup(ctl->server.via);
1153 ctl->server.queryname = xstrdup(ctl->server.pollname);
1156 /* If either the pollname or vianame are "hesiod" we want to
1157 lookup the user's hesiod pobox host */
1159 if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1160 struct hes_postoffice *hes_p;
1161 hes_p = hes_getmailhost(ctl->remotename);
1162 if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1163 free(ctl->server.queryname);
1164 ctl->server.queryname = xstrdup(hes_p->po_host);
1165 if (ctl->server.via)
1166 free(ctl->server.via);
1167 ctl->server.via = xstrdup(hes_p->po_host);
1170 _("couldn't find HESIOD pobox for %s\n"),
1177 * We may have to canonicalize the server truename for later use.
1178 * Do this just once for each lead server, if necessary, in order
1179 * to minimize DNS round trips.
1181 if (ctl->server.lead_server)
1183 char *leadname = ctl->server.lead_server->truename;
1185 /* prevent core dump from ill-formed or duplicate entry */
1188 report(stderr, _("Lead server has no name.\n"));
1192 ctl->server.truename = xstrdup(leadname);
1194 #ifdef HAVE_GETHOSTBYNAME
1195 else if (!configdump)
1197 if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1198 ctl->server.preauthenticate==A_KERBEROS_V5 ||
1199 (ctl->server.dns && MULTIDROP(ctl)))
1201 struct hostent *namerec;
1203 /* compute the canonical name of the host */
1205 namerec = gethostbyname(ctl->server.queryname);
1206 if (namerec == (struct hostent *)NULL)
1209 _("couldn't find canonical DNS name of %s\n"),
1210 ctl->server.pollname);
1211 ctl->server.truename = xstrdup(ctl->server.queryname);
1212 ctl->server.trueaddr = NULL;
1215 ctl->server.truename=xstrdup((char *)namerec->h_name);
1217 #endif /* HAVE_GETHOSTBYNAME */
1219 #ifdef HAVE_GETHOSTBYNAME
1220 struct hostent *namerec;
1222 /* <fetchmail@mail.julianhaight.com>
1223 Get the host's IP, so we can report it like this:
1225 Received: from hostname [10.0.0.1]
1227 do we actually need to gethostbyname to find the IP?
1228 it seems like it would be faster to do this later, when
1229 we are actually resolving the hostname for a connection,
1230 but I ain't that smart, so I don't know where to make
1234 namerec = gethostbyname(ctl->server.queryname);
1235 if (namerec == (struct hostent *)NULL)
1238 _("couldn't find canonical DNS name of %s\n"),
1239 ctl->server.pollname);
1243 ctl->server.truename=xstrdup((char *)namerec->h_name);
1244 ctl->server.trueaddr=xmalloc(namerec->h_length);
1245 memcpy(ctl->server.trueaddr,
1246 namerec->h_addr_list[0],
1250 ctl->server.truename = xstrdup(ctl->server.queryname);
1251 #endif /* HAVE_GETHOSTBYNAME */
1255 /* if no folders were specified, set up the null one as default */
1256 if (!ctl->mailboxes)
1257 save_str(&ctl->mailboxes, (char *)NULL, 0);
1259 /* maybe user overrode timeout on command line? */
1260 if (ctl->server.timeout == -1)
1261 ctl->server.timeout = CLIENT_TIMEOUT;
1265 if (ctl->server.port < 0)
1267 (void) fprintf(stderr,
1268 _("%s configuration invalid, port number cannot be negative\n"),
1269 ctl->server.pollname);
1272 if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1274 (void) fprintf(stderr,
1275 _("%s configuration invalid, RPOP requires a privileged port\n"),
1276 ctl->server.pollname);
1279 if (ctl->listener == LMTP_MODE)
1283 for (idp = ctl->smtphunt; idp; idp = idp->next)
1287 if (!(cp = strrchr(idp->id, '/')) ||
1288 (atoi(++cp) == SMTP_PORT))
1290 (void) fprintf(stderr,
1291 _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1292 ctl->server.pollname);
1297 #endif /* !INET6_ENABLE */
1300 * "I beg to you, have mercy on the week minds like myself."
1301 * wrote Pehr Anderson. Your petition is granted.
1303 if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1305 (void) fprintf(stderr,
1306 _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1313 /* initialize UID handling */
1314 if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1317 initialize_saved_lists(querylist, run.idfile);
1318 #endif /* POP3_ENABLE */
1321 * If the user didn't set a last-resort user to get misaddressed
1322 * multidrop mail, set an appropriate default here.
1324 if (!run.postmaster)
1326 if (getuid()) /* ordinary user */
1327 run.postmaster = user;
1329 run.postmaster = "postmaster";
1332 return(implicitmode);
1335 static void terminate_poll(int sig)
1336 /* to be executed at the end of a poll cycle */
1339 * Close all SMTP delivery sockets. For optimum performance
1340 * we'd like to hold them open til end of run, but (1) this
1341 * loses if our poll interval is longer than the MTA's inactivity
1342 * timeout, and (2) some MTAs (like smail) don't deliver after
1343 * each message, but rather queue up mail and wait to actually
1344 * deliver it until the input socket is closed.
1346 * Sending SMTP QUIT on signal is theoretically nice, but led to a
1347 * subtle bug. If fetchmail was terminated by signal while it was
1348 * shipping message text, it would hang forever waiting for a
1349 * command acknowledge. In theory we could enable the QUIT
1350 * only outside of the message send. In practice, we don't
1351 * care. All mailservers hang up on a dropped TCP/IP connection
1356 report(stdout, _("terminated with signal %d\n"), sig);
1361 /* terminate all SMTP connections cleanly */
1362 for (ctl = querylist; ctl; ctl = ctl->next)
1363 if (ctl->smtp_socket != -1)
1365 SMTP_quit(ctl->smtp_socket);
1366 SockClose(ctl->smtp_socket);
1367 ctl->smtp_socket = -1;
1373 * Update UID information at end of each poll, rather than at end
1374 * of run, because that way we don't lose all UIDL information since
1375 * the beginning of time if fetchmail crashes.
1378 write_saved_lists(querylist, run.idfile);
1379 #endif /* POP3_ENABLE */
1382 static void terminate_run(int sig)
1383 /* to be executed on normal or signal-induced termination */
1387 terminate_poll(sig);
1390 * Craig Metz, the RFC1938 one-time-password guy, points out:
1391 * "Remember that most kernels don't zero pages before handing them to the
1392 * next process and many kernels share pages between user and kernel space.
1393 * You'd be very surprised what you can find from a short program to do a
1394 * malloc() and then dump the contents of the pages you got. By zeroing
1395 * the secrets at end of run (earlier if you can), you make sure the next
1396 * guy can't get the password/pass phrase."
1398 * Right you are, Craig!
1400 for (ctl = querylist; ctl; ctl = ctl->next)
1402 memset(ctl->password, '\0', strlen(ctl->password));
1404 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1408 if (activecount == 0)
1411 exit(successes ? PS_SUCCESS : querystatus);
1415 * Sequence of protocols to try when autoprobing, most capable to least.
1417 static const int autoprobe[] =
1421 #endif /* IMAP_ENABLE */
1424 #endif /* POP3_ENABLE */
1427 #endif /* POP2_ENABLE */
1430 static int query_host(struct query *ctl)
1431 /* perform fetch transaction with single host */
1436 * If we're syslogging the progress messages are automatically timestamped.
1437 * Force timestamping if we're going to a logfile.
1439 if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1441 report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1443 ctl->server.pollname,
1444 showproto(ctl->server.protocol),
1447 switch (ctl->server.protocol) {
1449 for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1451 ctl->server.protocol = autoprobe[i];
1452 if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1455 ctl->server.protocol = P_AUTO;
1459 return(doPOP2(ctl));
1461 report(stderr, _("POP2 support is not configured.\n"));
1462 return(PS_PROTOCOL);
1463 #endif /* POP2_ENABLE */
1469 return(doPOP3(ctl));
1471 report(stderr, _("POP3 support is not configured.\n"));
1472 return(PS_PROTOCOL);
1473 #endif /* POP3_ENABLE */
1480 return(doIMAP(ctl));
1482 report(stderr, _("IMAP support is not configured.\n"));
1483 return(PS_PROTOCOL);
1484 #endif /* IMAP_ENABLE */
1487 report(stderr, _("ETRN support is not configured.\n"));
1488 return(PS_PROTOCOL);
1490 #ifdef HAVE_GETHOSTBYNAME
1491 return(doETRN(ctl));
1493 report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1494 return(PS_PROTOCOL);
1495 #endif /* HAVE_GETHOSTBYNAME */
1496 #endif /* ETRN_ENABLE */
1499 report(stderr, _("ODMR support is not configured.\n"));
1500 return(PS_PROTOCOL);
1502 #ifdef HAVE_GETHOSTBYNAME
1503 return(doODMR(ctl));
1505 report(stderr, _("Cannot support ODMR without gethostbyname(2).\n"));
1506 return(PS_PROTOCOL);
1507 #endif /* HAVE_GETHOSTBYNAME */
1508 #endif /* ODMR_ENABLE */
1510 report(stderr, _("unsupported protocol selected.\n"));
1511 return(PS_PROTOCOL);
1515 static void dump_params (struct runctl *runp,
1516 struct query *querylist, flag implicit)
1517 /* display query parameters in English */
1521 if (runp->poll_interval)
1522 printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1524 printf(_("Logfile is %s\n"), runp->logfile);
1525 if (strcmp(runp->idfile, IDFILE_NAME))
1526 printf(_("Idfile is %s\n"), runp->idfile);
1527 #if defined(HAVE_SYSLOG)
1528 if (runp->use_syslog)
1529 printf(_("Progress messages will be logged via syslog\n"));
1531 if (runp->invisible)
1532 printf(_("Fetchmail will masquerade and will not generate Received\n"));
1534 printf(_("Fetchmail will show progress dots even in logfiles.\n"));
1535 if (runp->postmaster)
1536 printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1539 if (!runp->bouncemail)
1540 printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1541 else if (outlevel >= O_VERBOSE)
1542 printf(_("Fetchmail will direct error mail to the sender.\n"));
1544 for (ctl = querylist; ctl; ctl = ctl->next)
1546 if (!ctl->active || (implicit && ctl->server.skip))
1549 printf(_("Options for retrieving from %s@%s:\n"),
1550 ctl->remotename, visbuf(ctl->server.pollname));
1552 if (ctl->server.via && (ctl->server.protocol < P_ETRN))
1553 printf(_(" Mail will be retrieved via %s\n"), ctl->server.via);
1555 if (ctl->server.interval)
1556 printf(_(" Poll of this server will occur every %d intervals.\n"),
1557 ctl->server.interval);
1558 if (ctl->server.truename)
1559 printf(_(" True name of server is %s.\n"), ctl->server.truename);
1560 if (ctl->server.skip || outlevel >= O_VERBOSE)
1561 printf(_(" This host %s be queried when no host is specified.\n"),
1562 ctl->server.skip ? _("will not") : _("will"));
1563 if (ctl->server.preauthenticate <= A_PASSWORD && ctl->server.protocol < P_ETRN)
1566 printf(_(" Password will be prompted for.\n"));
1567 else if (outlevel >= O_VERBOSE)
1569 if (ctl->server.protocol == P_APOP)
1570 printf(_(" APOP secret = \"%s\".\n"),
1571 visbuf(ctl->password));
1572 else if (ctl->server.protocol == P_RPOP)
1573 printf(_(" RPOP id = \"%s\".\n"),
1574 visbuf(ctl->password));
1576 printf(_(" Password = \"%s\".\n"),
1577 visbuf(ctl->password));
1581 if (ctl->server.protocol == P_POP3
1583 && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1584 #else /* INET6_ENABLE */
1585 && ctl->server.port == KPOP_PORT
1586 #endif /* INET6_ENABLE */
1587 && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1588 ctl->server.preauthenticate == A_KERBEROS_V5))
1589 printf(_(" Protocol is KPOP with Kerberos %s authentication"),
1590 ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1592 printf(_(" Protocol is %s"), showproto(ctl->server.protocol));
1594 if (ctl->server.service)
1595 printf(_(" (using service %s)"), ctl->server.service);
1596 if (ctl->server.netsec)
1597 printf(_(" (using network security options %s)"), ctl->server.netsec);
1598 #else /* INET6_ENABLE */
1599 if (ctl->server.port)
1600 printf(_(" (using port %d)"), ctl->server.port);
1601 #endif /* INET6_ENABLE */
1602 else if (outlevel >= O_VERBOSE)
1603 printf(_(" (using default port)"));
1604 if (ctl->server.uidl && (ctl->server.protocol < P_ETRN))
1605 printf(_(" (forcing UIDL use)"));
1608 switch (ctl->server.preauthenticate)
1611 printf(_(" All authentication methods will be described.\n"));
1614 printf(_(" Password authentication will be forced.\n"));
1617 printf(_(" GSSAPI preauthentication will be forced.\n"));
1620 printf(_(" Kerberos V4 preauthentication will be forced.\n"));
1623 printf(_(" Kerberos V5 preauthentication will be forced.\n"));
1626 printf(_(" End-to-end encryption assumed.\n"));
1629 if (ctl->server.principal != (char *) NULL)
1630 printf(_(" Mail service principal is: %s\n"), ctl->server.principal);
1633 printf(" SSL encrypted sessions enabled.\n");
1635 if (ctl->server.timeout > 0)
1636 printf(_(" Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1637 if (ctl->server.timeout == CLIENT_TIMEOUT)
1638 printf(_(" (default).\n"));
1642 if (ctl->server.protocol < P_ETRN) {
1643 if (!ctl->mailboxes->id)
1644 printf(_(" Default mailbox selected.\n"));
1649 printf(_(" Selected mailboxes are:"));
1650 for (idp = ctl->mailboxes; idp; idp = idp->next)
1651 printf(" %s", idp->id);
1654 printf(_(" %s messages will be retrieved (--all %s).\n"),
1655 ctl->fetchall ? _("All") : _("Only new"),
1656 ctl->fetchall ? "on" : "off");
1657 printf(_(" Fetched messages %s be kept on the server (--keep %s).\n"),
1658 ctl->keep ? _("will") : _("will not"),
1659 ctl->keep ? "on" : "off");
1660 printf(_(" Old messages %s be flushed before message retrieval (--flush %s).\n"),
1661 ctl->flush ? _("will") : _("will not"),
1662 ctl->flush ? "on" : "off");
1663 printf(_(" Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1664 ctl->rewrite ? _("enabled") : _("disabled"),
1665 ctl->rewrite ? "off" : "on");
1666 printf(_(" Carriage-return stripping is %s (stripcr %s).\n"),
1667 ctl->stripcr ? _("enabled") : _("disabled"),
1668 ctl->stripcr ? "on" : "off");
1669 printf(_(" Carriage-return forcing is %s (forcecr %s).\n"),
1670 ctl->forcecr ? _("enabled") : _("disabled"),
1671 ctl->forcecr ? "on" : "off");
1672 printf(_(" Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1673 ctl->pass8bits ? _("disabled") : _("enabled"),
1674 ctl->pass8bits ? "on" : "off");
1675 printf(_(" MIME decoding is %s (mimedecode %s).\n"),
1676 ctl->mimedecode ? _("enabled") : _("disabled"),
1677 ctl->mimedecode ? "on" : "off");
1678 printf(_(" Idle after poll is %s (idle %s).\n"),
1679 ctl->idle ? _("enabled") : _("disabled"),
1680 ctl->idle ? "on" : "off");
1681 printf(_(" Nonempty Status lines will be %s (dropstatus %s)\n"),
1682 ctl->dropstatus ? _("discarded") : _("kept"),
1683 ctl->dropstatus ? "on" : "off");
1684 printf(_(" Delivered-To lines will be %s (dropdelivered %s)\n"),
1685 ctl->dropdelivered ? _("discarded") : _("kept"),
1686 ctl->dropdelivered ? "on" : "off");
1687 if (NUM_NONZERO(ctl->limit))
1689 if (NUM_NONZERO(ctl->limit))
1690 printf(_(" Message size limit is %d octets (--limit %d).\n"),
1691 ctl->limit, ctl->limit);
1692 else if (outlevel >= O_VERBOSE)
1693 printf(_(" No message size limit (--limit 0).\n"));
1694 if (run.poll_interval > 0)
1695 printf(_(" Message size warning interval is %d seconds (--warnings %d).\n"),
1696 ctl->warnings, ctl->warnings);
1697 else if (outlevel >= O_VERBOSE)
1698 printf(_(" Size warnings on every poll (--warnings 0).\n"));
1700 if (NUM_NONZERO(ctl->fetchlimit))
1701 printf(_(" Received-message limit is %d (--fetchlimit %d).\n"),
1702 ctl->fetchlimit, ctl->fetchlimit);
1703 else if (outlevel >= O_VERBOSE)
1704 printf(_(" No received-message limit (--fetchlimit 0).\n"));
1705 if (NUM_NONZERO(ctl->batchlimit))
1706 printf(_(" SMTP message batch limit is %d.\n"), ctl->batchlimit);
1707 else if (outlevel >= O_VERBOSE)
1708 printf(_(" No SMTP message batch limit (--batchlimit 0).\n"));
1709 if (ctl->server.protocol < P_ETRN)
1711 if (NUM_NONZERO(ctl->expunge))
1712 printf(_(" Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1713 else if (outlevel >= O_VERBOSE)
1714 printf(_(" No forced expunges (--expunge 0).\n"));
1718 printf(_(" Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1719 else if (ctl->mda && (ctl->server.protocol < P_ETRN))
1720 printf(_(" Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1725 printf(_(" Messages will be %cMTP-forwarded to:"), ctl->listener);
1726 for (idp = ctl->smtphunt; idp; idp = idp->next)
1728 printf(" %s", idp->id);
1729 if (!idp->val.status.mark)
1730 printf(_(" (default)"));
1733 if (ctl->smtpaddress)
1734 printf(_(" Host part of MAIL FROM line will be %s\n"),
1737 printf(_(" Address to be put in RCPT TO lines shipped to SMTP will be %s\n"),
1740 if (ctl->server.protocol < P_ETRN)
1742 if (ctl->antispam != (struct idlist *)NULL)
1746 printf(_(" Recognized listener spam block responses are:"));
1747 for (idp = ctl->antispam; idp; idp = idp->next)
1748 printf(" %d", idp->val.status.num);
1751 else if (outlevel >= O_VERBOSE)
1752 printf(_(" Spam-blocking disabled\n"));
1754 if (ctl->preconnect)
1755 printf(_(" Server connection will be brought up with \"%s\".\n"),
1756 visbuf(ctl->preconnect));
1757 else if (outlevel >= O_VERBOSE)
1758 printf(_(" No pre-connection command.\n"));
1759 if (ctl->postconnect)
1760 printf(_(" Server connection will be taken down with \"%s\".\n"),
1761 visbuf(ctl->postconnect));
1762 else if (outlevel >= O_VERBOSE)
1763 printf(_(" No post-connection command.\n"));
1764 if (ctl->server.protocol < P_ETRN) {
1765 if (!ctl->localnames)
1766 printf(_(" No localnames declared for this host.\n"));
1772 for (idp = ctl->localnames; idp; idp = idp->next)
1775 if (count > 1 || ctl->wildcard)
1776 printf(_(" Multi-drop mode: "));
1778 printf(_(" Single-drop mode: "));
1780 printf(_("%d local name(s) recognized.\n"), count);
1781 if (outlevel >= O_VERBOSE)
1783 for (idp = ctl->localnames; idp; idp = idp->next)
1785 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1787 printf("\t%s\n", idp->id);
1789 fputs("\t*\n", stdout);
1792 if (count > 1 || ctl->wildcard)
1794 printf(_(" DNS lookup for multidrop addresses is %s.\n"),
1795 ctl->server.dns ? _("enabled") : _("disabled"));
1796 if (ctl->server.dns)
1798 printf(_(" Server aliases will be compared with multidrop addresses by "));
1799 if (ctl->server.checkalias)
1800 printf(_("IP address.\n"));
1802 printf(_("name.\n"));
1804 if (ctl->server.envelope == STRING_DISABLED)
1805 printf(_(" Envelope-address routing is disabled\n"));
1808 printf(_(" Envelope header is assumed to be: %s\n"),
1809 ctl->server.envelope ? ctl->server.envelope:_("Received"));
1810 if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1811 printf(_(" Number of envelope header to be parsed: %d\n"),
1812 ctl->server.envskip);
1813 if (ctl->server.qvirtual)
1814 printf(_(" Prefix %s will be removed from user id\n"),
1815 ctl->server.qvirtual);
1816 else if (outlevel >= O_VERBOSE)
1817 printf(_(" No prefix stripping\n"));
1820 if (ctl->server.akalist)
1824 printf(_(" Predeclared mailserver aliases:"));
1825 for (idp = ctl->server.akalist; idp; idp = idp->next)
1826 printf(" %s", idp->id);
1829 if (ctl->server.localdomains)
1833 printf(_(" Local domains:"));
1834 for (idp = ctl->server.localdomains; idp; idp = idp->next)
1835 printf(" %s", idp->id);
1841 #if defined(linux) || defined(__FreeBSD__)
1842 if (ctl->server.interface)
1843 printf(_(" Connection must be through interface %s.\n"), ctl->server.interface);
1844 else if (outlevel >= O_VERBOSE)
1845 printf(_(" No interface requirement specified.\n"));
1846 if (ctl->server.monitor)
1847 printf(_(" Polling loop will monitor %s.\n"), ctl->server.monitor);
1848 else if (outlevel >= O_VERBOSE)
1849 printf(_(" No monitor interface specified.\n"));
1852 if (ctl->server.plugin)
1853 printf(_(" Server connections will be made via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1854 else if (outlevel >= O_VERBOSE)
1855 printf(_(" No plugin command specified.\n"));
1856 if (ctl->server.plugout)
1857 printf(_(" Listener connections will be made via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1858 else if (outlevel >= O_VERBOSE)
1859 printf(_(" No plugout command specified.\n"));
1861 if (ctl->server.protocol > P_POP2 && (ctl->server.protocol < P_ETRN))
1864 printf(_(" No UIDs saved from this host.\n"));
1870 for (idp = ctl->oldsaved; idp; idp = idp->next)
1873 printf(_(" %d UIDs saved.\n"), count);
1874 if (outlevel >= O_VERBOSE)
1875 for (idp = ctl->oldsaved; idp; idp = idp->next)
1876 printf("\t%s\n", idp->id);
1880 if (ctl->properties)
1881 printf(_(" Pass-through properties \"%s\".\n"),
1882 visbuf(ctl->properties));
1886 /* fetchmail.c ends here */