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 bindtextdomain(PACKAGE, LOCALEDIR);
166 * Note: because we can't initialize reporting before we know whether
167 * syslog is supposed to be on, this message will go to stdout and
168 * be lost when running in background.
170 if (outlevel >= O_VERBOSE)
174 report(stdout, _("fetchmail: invoked with"));
175 for (i = 0; i < argc; i++)
176 report(stdout, " %s", argv[i]);
177 report(stdout, "\n");
180 #define IDFILE_NAME ".fetchids"
181 run.idfile = (char *) xmalloc(strlen(fmhome)+sizeof(IDFILE_NAME)+2);
182 strcpy(run.idfile, fmhome);
183 strcat(run.idfile, "/");
184 strcat(run.idfile, IDFILE_NAME);
189 * We used to arrange for the lockfile to be removed on exit close
190 * to where the lock was asserted. Now we need to do it here, because
191 * we might have re-executed in background with an existing lockfile
192 * as the result of a changed rcfile (see the code near the execvp(3)
193 * call near the beginning of the polling loop for details). We want
194 * to be sure the lockfile gets nuked on any error exit, basically.
200 on_exit(unlockit, (char *)NULL);
203 if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
208 printf(_("This is fetchmail release %s"), VERSION);
211 #endif /* POP2_ENABLE */
214 #endif /* POP3_ENABLE */
217 #endif /* IMAP_ENABLE */
223 #endif /* RPA_ENABLE */
226 #endif /* NTLM_ENABLE */
229 #endif /* SDPS_ENABLE */
232 #endif /* ETRN_ENABLE */
238 #endif /* OPIE_ENABLE */
241 #endif /* INET6_ENABLE */
244 #endif /* NET_SECURITY */
247 #endif /* HAVE_SOCKS */
250 #endif /* ENABLE_NLS */
254 /* this is an attempt to help remote debugging */
258 /* avoid parsing the config file if all we're doing is killing a daemon */
259 if (!(quitmode && argc == 2))
260 implicitmode = load_params(argc, argv, optind);
262 #if defined(HAVE_SYSLOG)
263 /* logging should be set up early in case we were restarted from exec */
266 #if defined(LOG_MAIL)
267 openlog(program_name, LOG_PID, LOG_MAIL);
269 /* Assume BSD4.2 openlog with two arguments */
270 openlog(program_name, LOG_PID);
276 report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
278 /* set up to do lock protocol */
279 #define FETCHMAIL_PIDFILE "fetchmail.pid"
281 xalloca(tmpbuf, char *,
282 sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
283 sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
285 xalloca(tmpbuf, char *, strlen(fmhome) + sizeof(FETCHMAIL_PIDFILE) + 2);
286 strcpy(tmpbuf, fmhome);
290 strcat(tmpbuf, FETCHMAIL_PIDFILE);
292 #undef FETCHMAIL_PIDFILE
294 #ifdef HAVE_SETRLIMIT
296 * Before getting passwords, disable core dumps unless -v -d0 mode is on.
297 * Core dumps could otherwise contain passwords to be scavenged by a
300 if (outlevel < O_VERBOSE || run.poll_interval > 0)
302 struct rlimit corelimit;
303 corelimit.rlim_cur = 0;
304 corelimit.rlim_max = 0;
305 setrlimit(RLIMIT_CORE, &corelimit);
307 #endif /* HAVE_SETRLIMIT */
309 #define NETRC_FILE ".netrc"
310 /* parse the ~/.netrc file (if present) for future password lookups. */
311 xalloca(netrc_file, char *, strlen(home) + sizeof(NETRC_FILE) + 2);
312 strcpy (netrc_file, home);
313 strcat (netrc_file, "/");
314 strcat (netrc_file, NETRC_FILE);
315 netrc_list = parse_netrc(netrc_file);
318 /* pick up passwords where we can */
319 for (ctl = querylist; ctl; ctl = ctl->next)
321 if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
323 if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
324 ctl->server.preauthenticate == A_KERBEROS_V5 ||
325 ctl->server.preauthenticate == A_SSH ||
327 ctl->server.protocol == P_IMAP_GSS ||
329 ctl->server.protocol == P_IMAP_K4)
330 /* Server won't care what the password is, but there
331 must be some non-null string here. */
332 ctl->password = ctl->remotename;
337 /* look up the pollname and account in the .netrc file. */
338 p = search_netrc(netrc_list,
339 ctl->server.pollname, ctl->remotename);
340 /* if we find a matching entry with a password, use it */
341 if (p && p->password)
342 ctl->password = xstrdup(p->password);
344 /* otherwise try with "via" name if there is one */
345 else if (ctl->server.via)
347 p = search_netrc(netrc_list,
348 ctl->server.via, ctl->remotename);
349 if (p && p->password)
350 ctl->password = xstrdup(p->password);
356 /* perhaps we just want to check options? */
359 int havercfile = access(rcfile, 0);
361 printf(_("Taking options from command line%s%s\n"),
362 havercfile ? "" : _(" and "),
363 havercfile ? "" : rcfile);
365 if (outlevel >= O_VERBOSE)
366 printf(_("Lockfile at %s\n"), tmpbuf);
368 if (querylist == NULL)
370 _("No mailservers set up -- perhaps %s is missing?\n"),
373 dump_params(&run, querylist, implicitmode);
377 /* dump options as a Python dictionary, for configurator use */
380 dump_config(&run, querylist);
384 /* check for another fetchmail running concurrently */
386 if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
388 report(stderr,_("fetchmail: cannot allocate memory for lock name.\n"));
392 (void) strcpy(lockfile, tmpbuf);
393 if ((lockfp = fopen(lockfile, "r")) != NULL )
395 bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
397 if (kill(pid, 0) == -1) {
398 fprintf(stderr,_("fetchmail: removing stale lockfile\n"));
403 fclose(lockfp); /* not checking should be safe, file mode was "r" */
406 /* if no mail servers listed and nothing in background, we're done */
407 if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
408 (void)fputs(_("fetchmail: no mailservers have been specified.\n"),stderr);
412 /* perhaps user asked us to kill the other fetchmail */
417 fprintf(stderr,_("fetchmail: no other fetchmail is running\n"));
421 else if (kill(pid, SIGTERM) < 0)
423 fprintf(stderr,_("fetchmail: error killing %s fetchmail at %d; bailing out.\n"),
424 bkgd ? _("background") : _("foreground"), pid);
429 fprintf(stderr,_("fetchmail: %s fetchmail at %d killed.\n"),
430 bkgd ? _("background") : _("foreground"), pid);
439 /* another fetchmail is running -- wake it up or die */
445 _("fetchmail: can't check mail while another fetchmail to same host is running.\n"));
448 else if (!implicitmode)
451 _("fetchmail: can't poll specified hosts with another fetchmail running at %d.\n"),
458 _("fetchmail: another foreground fetchmail is running at %d.\n"),
464 /* this test enables re-execing on a changed rcfile */
466 lock_acquired = TRUE;
470 _("fetchmail: can't accept options while a background fetchmail is running.\n"));
474 else if (kill(pid, SIGUSR1) == 0)
477 _("fetchmail: background fetchmail at %d awakened.\n"),
484 * Should never happen -- possible only if a background fetchmail
485 * croaks after the first kill probe above but before the
486 * SIGUSR1/SIGHUP transmission.
489 _("fetchmail: elder sibling at %d died mysteriously.\n"),
491 return(PS_UNDEFINED);
495 /* pick up interactively any passwords we need but don't have */
496 for (ctl = querylist; ctl; ctl = ctl->next)
498 if (ctl->active && !(implicitmode && ctl->server.skip)
499 && ctl->server.protocol != P_ETRN
500 && ctl->server.protocol != P_IMAP_K4
502 && ctl->server.protocol != P_IMAP_GSS
509 _("fetchmail: can't find a password for %s@%s.\n"),
510 ctl->remotename, ctl->server.pollname);
515 char* password_prompt = _("Enter password for %s@%s: ");
517 xalloca(tmpbuf, char *, strlen(password_prompt) +
518 strlen(ctl->remotename) +
519 strlen(ctl->server.pollname) + 1);
520 (void) sprintf(tmpbuf, password_prompt,
521 ctl->remotename, ctl->server.pollname);
522 ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
528 * Time to initiate the SOCKS library (this is not mandatory: it just
529 * registers the correct application name for logging purpose. If you
530 * have some problem, comment out these lines).
533 SOCKSinit("fetchmail");
534 #endif /* HAVE_SOCKS */
537 * Maybe time to go to demon mode...
539 if (run.poll_interval)
542 daemonize(run.logfile, terminate_run);
543 report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
546 * We'll set up a handler for these when we're sleeping,
547 * but ignore them otherwise so as not to interrupt a poll.
549 signal(SIGUSR1, SIG_IGN);
550 if (run.poll_interval && !getuid())
551 signal(SIGHUP, SIG_IGN);
553 else if (run.logfile && access(run.logfile, F_OK) == 0)
555 freopen(run.logfile, "a", stdout);
556 freopen(run.logfile, "a", stderr);
564 /* beyond here we don't want more than one fetchmail running per user */
566 signal(SIGABRT, terminate_run);
567 signal(SIGINT, terminate_run);
568 signal(SIGTERM, terminate_run);
569 signal(SIGALRM, terminate_run);
570 signal(SIGPIPE, terminate_run);
571 signal(SIGQUIT, terminate_run);
573 /* here's the exclusion lock */
575 #define O_SYNC 0 /* use it if we have it */
577 if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
579 sprintf(tmpbuf,"%d", getpid());
580 write(st, tmpbuf, strlen(tmpbuf));
581 if (run.poll_interval)
583 sprintf(tmpbuf," %d", run.poll_interval);
584 write(st, tmpbuf, strlen(tmpbuf));
586 close(st); /* should be safe, fd was opened with O_SYNC */
587 lock_acquired = TRUE;
591 * Query all hosts. If there's only one, the error return will
592 * reflect the status of that transaction.
596 * Check to see if the rcfile has been touched. If so,
597 * re-exec so the file will be reread. Doing it this way
598 * avoids all the complications of trying to deallocate the
599 * in-core control structures -- and the potential memory
604 if (stat(rcfile, &rcstat) == -1)
608 _("couldn't time-check %s (error %d)\n"),
611 else if (rcstat.st_mtime > parsetime)
613 report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
614 execvp("fetchmail", argv);
615 report(stderr, _("attempt to re-exec fetchmail failed\n"));
618 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
620 * This was an efficiency hack that backfired. The theory
621 * was that using TCP/IP for DNS queries would get us better
622 * reliability and shave off some per-UDP-packet costs.
623 * Unfortunately it interacted badly with diald, which effectively
624 * filters out DNS queries over TCP/IP for reasons having to do
625 * with some obscure kernel problem involving bootstrapping of
626 * dynamically-addressed links. I don't understand this mess
627 * and don't want to, so it's "See ya!" to this hack.
629 sethostent(TRUE); /* use TCP/IP for mailserver queries */
630 #endif /* HAVE_RES_SEARCH */
634 for (ctl = querylist; ctl; ctl = ctl->next)
638 if (!(implicitmode && ctl->server.skip))
643 _("poll of %s skipped (failed authentication or too many timeouts)\n"),
644 ctl->server.pollname);
648 /* check skip interval first so that it counts all polls */
649 if (run.poll_interval && ctl->server.interval)
651 if (ctl->server.poll_count++ % ctl->server.interval)
653 if (outlevel >= O_VERBOSE)
655 _("interval not reached, not querying %s\n"),
656 ctl->server.pollname);
661 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
663 * Don't do monitoring if we were woken by a signal.
664 * Note that interface_approve() does its own error logging.
666 if (!interface_approve(&ctl->server, !lastsig))
668 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
670 querystatus = query_host(ctl);
673 /* leave the UIDL state alone if there have been any errors */
675 ((querystatus==PS_SUCCESS) || (querystatus==PS_NOMAIL)))
677 #endif /* POP3_ENABLE */
679 if (querystatus == PS_SUCCESS)
681 else if (!check_only &&
682 ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
686 report(stdout,_("Query status=0 (SUCCESS)\n"));break;
688 report(stdout,_("Query status=1 (NOMAIL)\n")); break;
690 report(stdout,_("Query status=2 (SOCKET)\n")); break;
692 report(stdout,_("Query status=3 (AUTHFAIL)\n"));break;
694 report(stdout,_("Query status=4 (PROTOCOL)\n"));break;
696 report(stdout,_("Query status=5 (SYNTAX)\n")); break;
698 report(stdout,_("Query status=6 (IOERR)\n")); break;
700 report(stdout,_("Query status=7 (ERROR)\n")); break;
702 report(stdout,_("Query status=8 (EXCLUDE)\n")); break;
704 report(stdout,_("Query status=9 (LOCKBUSY)\n"));break;
706 report(stdout,_("Query status=10 (SMTP)\n")); break;
708 report(stdout,_("Query status=11 (DNS)\n")); break;
710 report(stdout,_("Query status=12 (BSMTP)\n")); break;
712 report(stdout,_("Query status=13 (MAXFETCH)\n"));break;
714 report(stdout,_("Query status=%d\n"),querystatus);
718 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
719 if (ctl->server.monitor)
722 * Allow some time for the link to quiesce. One
723 * second is usually sufficient, three is safe.
724 * Note: this delay is important - don't remove!
727 interface_note_activity(&ctl->server);
729 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
733 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
734 endhostent(); /* release TCP/IP connection to nameserver */
735 #endif /* HAVE_RES_SEARCH */
737 /* close connections cleanly */
741 * OK, we've polled. Now sleep.
743 if (run.poll_interval)
746 * Because passwords can expire, it may happen that *all*
747 * hosts are now out of the loop due to authfail
748 * conditions. If this happens daemon-mode fetchmail
749 * should softly and silently vanish away, rather than
750 * spinning uselessly.
754 for (ctl = querylist; ctl; ctl = ctl->next)
755 if (ctl->active && !(implicitmode && ctl->server.skip))
760 report(stderr, _("All connections are wedged. Exiting.\n"));
761 /* FIXME: someday, send notification mail */
765 if (outlevel >= O_VERBOSE)
767 _("fetchmail: sleeping at %s\n"), timestamp());
770 * OK, now pause util it's time for the next poll cycle.
771 * A nonzero return indicates we received a wakeup signal;
772 * unwedge all servers in case the problem has been
775 if ((lastsig = interruptible_idle(run.poll_interval)))
777 #ifdef SYS_SIGLIST_DECLARED
779 _("awakened by %s\n"), sys_siglist[lastsig]);
782 _("awakened by signal %d\n"), lastsig);
784 for (ctl = querylist; ctl; ctl = ctl->next)
788 if (outlevel >= O_VERBOSE)
789 report(stdout, _("awakened at %s\n"), timestamp());
794 if (outlevel >= O_VERBOSE)
795 report(stdout, _("normal termination, status %d\n"),
796 successes ? PS_SUCCESS : querystatus);
799 exit(successes ? PS_SUCCESS : querystatus);
802 static void list_merge(struct idlist **dstl, struct idlist **srcl, int force)
805 * If force is off, modify dstl fields only when they're empty (treat srcl
806 * as defaults). If force is on, modify each dstl field whenever scrcl
807 * is nonempty (treat srcl as an override).
809 if (force ? !!*srcl : !*dstl)
811 struct idlist *cpl = copy_str_list(*srcl);
813 append_str_list(dstl, &cpl);
817 static void optmerge(struct query *h2, struct query *h1, int force)
818 /* merge two options records */
820 list_merge(&h2->server.localdomains, &h1->server.localdomains, force);
821 list_merge(&h2->localnames, &h1->localnames, force);
822 list_merge(&h2->mailboxes, &h1->mailboxes, force);
823 list_merge(&h2->smtphunt, &h1->smtphunt, force);
824 list_merge(&h2->antispam, &h1->antispam, force);
826 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
827 FLAG_MERGE(server.via);
828 FLAG_MERGE(server.protocol);
830 FLAG_MERGE(server.service);
831 FLAG_MERGE(server.netsec);
832 #else /* INET6_ENABLE */
833 FLAG_MERGE(server.port);
834 #endif /* INET6_ENABLE */
835 FLAG_MERGE(server.interval);
836 FLAG_MERGE(server.preauthenticate);
837 FLAG_MERGE(server.timeout);
838 FLAG_MERGE(server.envelope);
839 FLAG_MERGE(server.envskip);
840 FLAG_MERGE(server.qvirtual);
841 FLAG_MERGE(server.skip);
842 FLAG_MERGE(server.dns);
843 FLAG_MERGE(server.checkalias);
844 FLAG_MERGE(server.uidl);
845 FLAG_MERGE(server.principal);
847 #if defined(linux) || defined(__FreeBSD__)
848 FLAG_MERGE(server.interface);
849 FLAG_MERGE(server.monitor);
850 FLAG_MERGE(server.interface_pair);
851 #endif /* linux || defined(__FreeBSD__) */
853 FLAG_MERGE(server.plugin);
854 FLAG_MERGE(server.plugout);
856 FLAG_MERGE(wildcard);
857 FLAG_MERGE(remotename);
858 FLAG_MERGE(password);
861 FLAG_MERGE(listener);
862 FLAG_MERGE(smtpaddress);
863 FLAG_MERGE(smtpname);
864 FLAG_MERGE(preconnect);
865 FLAG_MERGE(postconnect);
869 FLAG_MERGE(fetchall);
873 FLAG_MERGE(pass8bits);
874 FLAG_MERGE(dropstatus);
875 FLAG_MERGE(dropdelivered);
876 FLAG_MERGE(mimedecode);
879 FLAG_MERGE(warnings);
880 FLAG_MERGE(fetchlimit);
881 FLAG_MERGE(batchlimit);
889 FLAG_MERGE(properties);
893 static int load_params(int argc, char **argv, int optind)
895 int implicitmode, st;
897 struct query def_opts, *ctl;
900 run.bouncemail = TRUE;
902 memset(&def_opts, '\0', sizeof(struct query));
903 def_opts.smtp_socket = -1;
904 def_opts.smtpaddress = (char *)0;
905 #define ANTISPAM(n) save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
906 ANTISPAM(571); /* sendmail */
907 ANTISPAM(550); /* old exim */
908 ANTISPAM(501); /* new exim */
909 ANTISPAM(554); /* Postfix */
912 def_opts.server.protocol = P_AUTO;
913 def_opts.server.timeout = CLIENT_TIMEOUT;
914 def_opts.warnings = WARNING_INTERVAL;
915 def_opts.remotename = user;
916 def_opts.listener = SMTP_MODE;
918 /* note the parse time, so we can pick up on modifications */
919 parsetime = 0; /* foil compiler warnings */
920 if (stat(rcfile, &rcstat) != -1)
921 parsetime = rcstat.st_mtime;
922 else if (errno != ENOENT)
923 report(stderr, _("couldn't time-check the run-control file\n"));
925 /* this builds the host list */
926 if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
928 * FIXME: someday, send notification mail here if backgrounded.
929 * Right now, that can happen if the user changes the rcfile
930 * while the fetchmail is running in background. Do similarly
931 * for the other exit() calls in this function.
935 if ((implicitmode = (optind >= argc)))
937 for (ctl = querylist; ctl; ctl = ctl->next)
941 for (; optind < argc; optind++)
943 flag predeclared = FALSE;
946 * If hostname corresponds to a host known from the rc file,
947 * simply declare it active. Otherwise synthesize a host
948 * record from command line and defaults
950 for (ctl = querylist; ctl; ctl = ctl->next)
951 if (!strcmp(ctl->server.pollname, argv[optind])
952 || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
954 /* Is this correct? */
955 if (predeclared && outlevel == O_VERBOSE)
956 fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
964 * Allocate and link record without copying in
965 * command-line args; we'll do that with the optmerge
968 ctl = hostalloc((struct query *)NULL);
970 ctl->server.pollname = xstrdup(argv[optind]);
972 ctl->server.lead_server = (struct hostdata *)NULL;
977 * If there's a defaults record, merge it and lose it.
979 if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
981 for (ctl = querylist->next; ctl; ctl = ctl->next)
982 optmerge(ctl, querylist, FALSE);
983 querylist = querylist->next;
986 /* don't allow a defaults record after the first */
987 for (ctl = querylist; ctl; ctl = ctl->next)
988 if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
991 /* use localhost if we never fetch the FQDN of this host */
992 fetchmailhost = "localhost";
994 /* here's where we override globals */
996 run.logfile = cmd_run.logfile;
998 run.idfile = cmd_run.idfile;
999 /* do this before the keep/fetchall test below, otherwise -d0 may fail */
1000 if (cmd_run.poll_interval >= 0)
1001 run.poll_interval = cmd_run.poll_interval;
1002 if (cmd_run.invisible)
1003 run.invisible = cmd_run.invisible;
1004 if (cmd_run.use_syslog)
1005 run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
1006 if (cmd_run.postmaster)
1007 run.postmaster = cmd_run.postmaster;
1008 if (cmd_run.bouncemail)
1009 run.bouncemail = cmd_run.bouncemail;
1011 /* check and daemon options are not compatible */
1012 if (check_only && run.poll_interval)
1013 run.poll_interval = 0;
1015 /* merge in wired defaults, do sanity checks and prepare internal fields */
1016 for (ctl = querylist; ctl; ctl = ctl->next)
1018 ctl->wedged = FALSE;
1020 if (configdump || (ctl->active && !(implicitmode && ctl->server.skip)))
1022 /* merge in defaults */
1023 optmerge(ctl, &def_opts, FALSE);
1025 /* force command-line options */
1026 optmerge(ctl, &cmd_opts, TRUE);
1028 /* this code enables flags to be turned off */
1029 #define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
1031 else if (flag == FLAG_FALSE)\
1035 DEFAULT(ctl->keep, FALSE);
1036 DEFAULT(ctl->fetchall, FALSE);
1037 DEFAULT(ctl->flush, FALSE);
1038 DEFAULT(ctl->rewrite, TRUE);
1039 DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
1040 DEFAULT(ctl->forcecr, FALSE);
1041 DEFAULT(ctl->pass8bits, FALSE);
1042 DEFAULT(ctl->dropstatus, FALSE);
1043 DEFAULT(ctl->dropdelivered, FALSE);
1044 DEFAULT(ctl->mimedecode, FALSE);
1045 DEFAULT(ctl->idle, FALSE);
1046 DEFAULT(ctl->server.dns, TRUE);
1047 DEFAULT(ctl->server.uidl, FALSE);
1049 DEFAULT(ctl->use_ssl, FALSE);
1051 DEFAULT(ctl->server.checkalias, FALSE);
1055 * DNS support is required for some protocols. We used to
1056 * do this unconditionally, but it made fetchmail excessively
1057 * vulnerable to misconfigured DNS setups.
1059 * If we're using ETRN, the smtp hunt list is the list of
1060 * systems we're polling on behalf of; these have to be
1061 * fully-qualified domain names. The default for this list
1062 * should be the FQDN of localhost.
1064 * If we're using Kerberos for authentication, we need
1065 * the FQDN in order to generate capability keys.
1067 if (ctl->server.protocol == P_ETRN
1068 || ctl->server.preauthenticate == A_KERBEROS_V4
1069 || ctl->server.preauthenticate == A_KERBEROS_V5)
1070 if (strcmp(fetchmailhost, "localhost") == 0)
1071 fetchmailhost = host_fqdn();
1074 * Make sure we have a nonempty host list to forward to.
1077 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1079 /* if `user' doesn't name a real local user, try to run as root */
1080 if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1083 ctl->uid = pw->pw_uid; /* for local delivery via MDA */
1084 if (!ctl->localnames) /* for local delivery via SMTP */
1085 save_str_pair(&ctl->localnames, user, NULL);
1087 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1088 /* can't handle multidrop mailboxes unless we can do DNS lookups */
1089 if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1091 ctl->server.dns = FALSE;
1092 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1094 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1098 * Compute the true name of the mailserver host.
1099 * There are two clashing cases here:
1101 * (1) The poll name is a label, possibly on one of several
1102 * poll configurations for the same host. In this case
1103 * the `via' option will be present and give the true name.
1105 * (2) The poll name is the true one, the via name is
1106 * localhost. This is going to be typical for ssh-using
1109 * We're going to assume the via name is true unless it's
1112 if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1113 ctl->server.queryname = xstrdup(ctl->server.via);
1115 ctl->server.queryname = xstrdup(ctl->server.pollname);
1118 /* If either the pollname or vianame are "hesiod" we want to
1119 lookup the user's hesiod pobox host */
1121 if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1122 struct hes_postoffice *hes_p;
1123 hes_p = hes_getmailhost(ctl->remotename);
1124 if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1125 free(ctl->server.queryname);
1126 ctl->server.queryname = xstrdup(hes_p->po_host);
1127 if (ctl->server.via)
1128 free(ctl->server.via);
1129 ctl->server.via = xstrdup(hes_p->po_host);
1132 _("couldn't find HESIOD pobox for %s\n"),
1139 * We may have to canonicalize the server truename for later use.
1140 * Do this just once for each lead server, if necessary, in order
1141 * to minimize DNS round trips.
1143 if (ctl->server.lead_server)
1145 char *leadname = ctl->server.lead_server->truename;
1147 /* prevent core dump from ill-formed or duplicate entry */
1150 report(stderr, _("Lead server has no name.\n"));
1154 ctl->server.truename = xstrdup(leadname);
1156 #ifdef HAVE_GETHOSTBYNAME
1157 else if (!configdump)
1159 if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1160 ctl->server.preauthenticate==A_KERBEROS_V5 ||
1161 (ctl->server.dns && MULTIDROP(ctl)))
1163 struct hostent *namerec;
1165 /* compute the canonical name of the host */
1167 namerec = gethostbyname(ctl->server.queryname);
1168 if (namerec == (struct hostent *)NULL)
1171 _("couldn't find canonical DNS name of %s\n"),
1172 ctl->server.pollname);
1173 ctl->server.truename = xstrdup(ctl->server.queryname);
1174 ctl->server.trueaddr = NULL;
1177 ctl->server.truename=xstrdup((char *)namerec->h_name);
1179 #endif /* HAVE_GETHOSTBYNAME */
1181 #ifdef HAVE_GETHOSTBYNAME
1182 struct hostent *namerec;
1184 /* <fetchmail@mail.julianhaight.com>
1185 Get the host's IP, so we can report it like this:
1187 Received: from hostname [10.0.0.1]
1189 do we actually need to gethostbyname to find the IP?
1190 it seems like it would be faster to do this later, when
1191 we are actually resolving the hostname for a connection,
1192 but I ain't that smart, so I don't know where to make
1196 namerec = gethostbyname(ctl->server.queryname);
1197 if (namerec == (struct hostent *)NULL)
1200 _("couldn't find canonical DNS name of %s\n"),
1201 ctl->server.pollname);
1205 ctl->server.truename=xstrdup((char *)namerec->h_name);
1206 ctl->server.trueaddr=xmalloc(namerec->h_length);
1207 memcpy(ctl->server.trueaddr,
1208 namerec->h_addr_list[0],
1212 ctl->server.truename = xstrdup(ctl->server.queryname);
1213 #endif /* HAVE_GETHOSTBYNAME */
1217 /* if no folders were specified, set up the null one as default */
1218 if (!ctl->mailboxes)
1219 save_str(&ctl->mailboxes, (char *)NULL, 0);
1221 /* maybe user overrode timeout on command line? */
1222 if (ctl->server.timeout == -1)
1223 ctl->server.timeout = CLIENT_TIMEOUT;
1227 if (ctl->server.port < 0)
1229 (void) fprintf(stderr,
1230 _("%s configuration invalid, port number cannot be negative\n"),
1231 ctl->server.pollname);
1234 if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1236 (void) fprintf(stderr,
1237 _("%s configuration invalid, RPOP requires a privileged port\n"),
1238 ctl->server.pollname);
1241 if (ctl->listener == LMTP_MODE)
1245 for (idp = ctl->smtphunt; idp; idp = idp->next)
1249 if (!(cp = strrchr(idp->id, '/')) ||
1250 (atoi(++cp) == SMTP_PORT))
1252 (void) fprintf(stderr,
1253 _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1254 ctl->server.pollname);
1259 #endif /* !INET6_ENABLE */
1262 * "I beg to you, have mercy on the week minds like myself."
1263 * wrote Pehr Anderson. Your petition is granted.
1265 if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1267 (void) fprintf(stderr,
1268 _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1275 /* initialize UID handling */
1276 if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1279 initialize_saved_lists(querylist, run.idfile);
1280 #endif /* POP3_ENABLE */
1283 * If the user didn't set a last-resort user to get misaddressed
1284 * multidrop mail, set an appropriate default here.
1286 if (!run.postmaster)
1288 if (getuid()) /* ordinary user */
1289 run.postmaster = user;
1291 run.postmaster = "postmaster";
1294 return(implicitmode);
1297 static void terminate_poll(int sig)
1298 /* to be executed at the end of a poll cycle */
1301 * Close all SMTP delivery sockets. For optimum performance
1302 * we'd like to hold them open til end of run, but (1) this
1303 * loses if our poll interval is longer than the MTA's inactivity
1304 * timeout, and (2) some MTAs (like smail) don't deliver after
1305 * each message, but rather queue up mail and wait to actually
1306 * deliver it until the input socket is closed.
1308 * Sending SMTP QUIT on signal is theoretically nice, but led to a
1309 * subtle bug. If fetchmail was terminated by signal while it was
1310 * shipping message text, it would hang forever waiting for a
1311 * command acknowledge. In theory we could enable the QUIT
1312 * only outside of the message send. In practice, we don't
1313 * care. All mailservers hang up on a dropped TCP/IP connection
1318 report(stdout, _("terminated with signal %d\n"), sig);
1323 /* terminate all SMTP connections cleanly */
1324 for (ctl = querylist; ctl; ctl = ctl->next)
1325 if (ctl->smtp_socket != -1)
1327 SMTP_quit(ctl->smtp_socket);
1328 SockClose(ctl->smtp_socket);
1329 ctl->smtp_socket = -1;
1335 * Update UID information at end of each poll, rather than at end
1336 * of run, because that way we don't lose all UIDL information since
1337 * the beginning of time if fetchmail crashes.
1340 write_saved_lists(querylist, run.idfile);
1341 #endif /* POP3_ENABLE */
1344 static void terminate_run(int sig)
1345 /* to be executed on normal or signal-induced termination */
1349 terminate_poll(sig);
1352 * Craig Metz, the RFC1938 one-time-password guy, points out:
1353 * "Remember that most kernels don't zero pages before handing them to the
1354 * next process and many kernels share pages between user and kernel space.
1355 * You'd be very surprised what you can find from a short program to do a
1356 * malloc() and then dump the contents of the pages you got. By zeroing
1357 * the secrets at end of run (earlier if you can), you make sure the next
1358 * guy can't get the password/pass phrase."
1360 * Right you are, Craig!
1362 for (ctl = querylist; ctl; ctl = ctl->next)
1364 memset(ctl->password, '\0', strlen(ctl->password));
1366 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1370 if (activecount == 0)
1373 exit(successes ? PS_SUCCESS : querystatus);
1377 * Sequence of protocols to try when autoprobing, most capable to least.
1379 static const int autoprobe[] =
1383 #endif /* IMAP_ENABLE */
1386 #endif /* POP3_ENABLE */
1389 #endif /* POP2_ENABLE */
1392 static int query_host(struct query *ctl)
1393 /* perform fetch transaction with single host */
1398 * If we're syslogging the progress messages are automatically timestamped.
1399 * Force timestamping if we're going to a logfile.
1401 if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1403 report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1405 ctl->server.pollname,
1406 showproto(ctl->server.protocol),
1409 switch (ctl->server.protocol) {
1411 for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1413 ctl->server.protocol = autoprobe[i];
1414 if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1417 ctl->server.protocol = P_AUTO;
1421 return(doPOP2(ctl));
1423 report(stderr, _("POP2 support is not configured.\n"));
1424 return(PS_PROTOCOL);
1425 #endif /* POP2_ENABLE */
1431 return(doPOP3(ctl));
1433 report(stderr, _("POP3 support is not configured.\n"));
1434 return(PS_PROTOCOL);
1435 #endif /* POP3_ENABLE */
1439 case P_IMAP_CRAM_MD5:
1445 return(doIMAP(ctl));
1447 report(stderr, _("IMAP support is not configured.\n"));
1448 return(PS_PROTOCOL);
1449 #endif /* IMAP_ENABLE */
1452 report(stderr, _("ETRN support is not configured.\n"));
1453 return(PS_PROTOCOL);
1455 #ifdef HAVE_GETHOSTBYNAME
1456 return(doETRN(ctl));
1458 report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1459 return(PS_PROTOCOL);
1460 #endif /* HAVE_GETHOSTBYNAME */
1461 #endif /* ETRN_ENABLE */
1463 report(stderr, _("unsupported protocol selected.\n"));
1464 return(PS_PROTOCOL);
1468 static void dump_params (struct runctl *runp,
1469 struct query *querylist, flag implicit)
1470 /* display query parameters in English */
1474 if (runp->poll_interval)
1475 printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1477 printf(_("Logfile is %s\n"), runp->logfile);
1478 if (strcmp(runp->idfile, IDFILE_NAME))
1479 printf(_("Idfile is %s\n"), runp->idfile);
1480 #if defined(HAVE_SYSLOG)
1481 if (runp->use_syslog)
1482 printf(_("Progress messages will be logged via syslog\n"));
1484 if (runp->invisible)
1485 printf(_("Fetchmail will masquerade and will not generate Received\n"));
1487 printf(_("Fetchmail will show progress dots even in logfiles\n"));
1488 if (runp->postmaster)
1489 printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1492 if (!runp->bouncemail)
1493 printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1494 else if (outlevel >= O_VERBOSE)
1495 printf(_("Fetchmail will direct error mail to the sender.\n"));
1497 for (ctl = querylist; ctl; ctl = ctl->next)
1499 if (!ctl->active || (implicit && ctl->server.skip))
1502 printf(_("Options for retrieving from %s@%s:\n"),
1503 ctl->remotename, visbuf(ctl->server.pollname));
1505 if (ctl->server.via && (ctl->server.protocol != P_ETRN))
1506 printf(_(" Mail will be retrieved via %s\n"), ctl->server.via);
1508 if (ctl->server.interval)
1509 printf(_(" Poll of this server will occur every %d intervals.\n"),
1510 ctl->server.interval);
1511 if (ctl->server.truename)
1512 printf(_(" True name of server is %s.\n"), ctl->server.truename);
1513 if (ctl->server.skip || outlevel >= O_VERBOSE)
1514 printf(_(" This host %s be queried when no host is specified.\n"),
1515 ctl->server.skip ? _("will not") : _("will"));
1517 * Don't poll for password when there is one or when using the ETRN
1518 * or IMAP-GSS protocol
1520 /* ETRN, IMAP_GSS, and IMAP_K4 do not need a password, so skip this */
1521 if ( (ctl->server.protocol != P_ETRN)
1523 && (ctl->server.protocol != P_IMAP_GSS)
1525 && (ctl->server.protocol != P_IMAP_K4) ) {
1527 printf(_(" Password will be prompted for.\n"));
1528 else if (outlevel >= O_VERBOSE)
1530 if (ctl->server.protocol == P_APOP)
1531 printf(_(" APOP secret = \"%s\".\n"),
1532 visbuf(ctl->password));
1533 else if (ctl->server.protocol == P_RPOP)
1534 printf(_(" RPOP id = \"%s\".\n"),
1535 visbuf(ctl->password));
1537 printf(_(" Password = \"%s\".\n"),
1538 visbuf(ctl->password));
1542 if (ctl->server.protocol == P_POP3
1544 && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1545 #else /* INET6_ENABLE */
1546 && ctl->server.port == KPOP_PORT
1547 #endif /* INET6_ENABLE */
1548 && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1549 ctl->server.preauthenticate == A_KERBEROS_V5))
1550 printf(_(" Protocol is KPOP with Kerberos %s authentication"),
1551 ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1553 printf(_(" Protocol is %s"), showproto(ctl->server.protocol));
1555 if (ctl->server.service)
1556 printf(_(" (using service %s)"), ctl->server.service);
1557 if (ctl->server.netsec)
1558 printf(_(" (using network security options %s)"), ctl->server.netsec);
1559 #else /* INET6_ENABLE */
1560 if (ctl->server.port)
1561 printf(_(" (using port %d)"), ctl->server.port);
1562 #endif /* INET6_ENABLE */
1563 else if (outlevel >= O_VERBOSE)
1564 printf(_(" (using default port)"));
1565 if (ctl->server.uidl && (ctl->server.protocol != P_ETRN))
1566 printf(_(" (forcing UIDL use)"));
1569 if (ctl->server.preauthenticate == A_KERBEROS_V4)
1570 printf(_(" Kerberos V4 preauthentication enabled.\n"));
1571 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
1572 printf(_(" Kerberos V5 preauthentication enabled.\n"));
1573 else if (ctl->server.preauthenticate == A_SSH)
1574 printf(_(" End-to-end encryption assumed.\n"));
1575 if (ctl->server.principal != (char *) NULL) {
1576 printf(_(" Mail service principal is: %s\n"), ctl->server.principal);
1580 printf(" SSL encrypted sessions enabled.\n");
1582 if (ctl->server.timeout > 0)
1583 printf(_(" Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1584 if (ctl->server.timeout == CLIENT_TIMEOUT)
1585 printf(_(" (default).\n"));
1589 if (ctl->server.protocol != P_ETRN) {
1590 if (!ctl->mailboxes->id)
1591 printf(_(" Default mailbox selected.\n"));
1596 printf(_(" Selected mailboxes are:"));
1597 for (idp = ctl->mailboxes; idp; idp = idp->next)
1598 printf(" %s", idp->id);
1601 printf(_(" %s messages will be retrieved (--all %s).\n"),
1602 ctl->fetchall ? _("All") : _("Only new"),
1603 ctl->fetchall ? "on" : "off");
1604 printf(_(" Fetched messages %s be kept on the server (--keep %s).\n"),
1605 ctl->keep ? _("will") : _("will not"),
1606 ctl->keep ? "on" : "off");
1607 printf(_(" Old messages %s be flushed before message retrieval (--flush %s).\n"),
1608 ctl->flush ? _("will") : _("will not"),
1609 ctl->flush ? "on" : "off");
1610 printf(_(" Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1611 ctl->rewrite ? _("enabled") : _("disabled"),
1612 ctl->rewrite ? "off" : "on");
1613 printf(_(" Carriage-return stripping is %s (stripcr %s).\n"),
1614 ctl->stripcr ? _("enabled") : _("disabled"),
1615 ctl->stripcr ? "on" : "off");
1616 printf(_(" Carriage-return forcing is %s (forcecr %s).\n"),
1617 ctl->forcecr ? _("enabled") : _("disabled"),
1618 ctl->forcecr ? "on" : "off");
1619 printf(_(" Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1620 ctl->pass8bits ? _("disabled") : _("enabled"),
1621 ctl->pass8bits ? "on" : "off");
1622 printf(_(" MIME decoding is %s (mimedecode %s).\n"),
1623 ctl->mimedecode ? _("enabled") : _("disabled"),
1624 ctl->mimedecode ? "on" : "off");
1625 printf(_(" Idle after poll is %s (idle %s).\n"),
1626 ctl->idle ? _("enabled") : _("disabled"),
1627 ctl->idle ? "on" : "off");
1628 printf(_(" Nonempty Status lines will be %s (dropstatus %s)\n"),
1629 ctl->dropstatus ? _("discarded") : _("kept"),
1630 ctl->dropstatus ? "on" : "off");
1631 printf(_(" Delivered-To lines will be %s (dropdelivered %s)\n"),
1632 ctl->dropdelivered ? _("discarded") : _("kept"),
1633 ctl->dropdelivered ? "on" : "off");
1634 if (NUM_NONZERO(ctl->limit))
1636 if (NUM_NONZERO(ctl->limit))
1637 printf(_(" Message size limit is %d octets (--limit %d).\n"),
1638 ctl->limit, ctl->limit);
1639 else if (outlevel >= O_VERBOSE)
1640 printf(_(" No message size limit (--limit 0).\n"));
1641 if (run.poll_interval > 0)
1642 printf(_(" Message size warning interval is %d seconds (--warnings %d).\n"),
1643 ctl->warnings, ctl->warnings);
1644 else if (outlevel >= O_VERBOSE)
1645 printf(_(" Size warnings on every poll (--warnings 0).\n"));
1647 if (NUM_NONZERO(ctl->fetchlimit))
1648 printf(_(" Received-message limit is %d (--fetchlimit %d).\n"),
1649 ctl->fetchlimit, ctl->fetchlimit);
1650 else if (outlevel >= O_VERBOSE)
1651 printf(_(" No received-message limit (--fetchlimit 0).\n"));
1652 if (NUM_NONZERO(ctl->batchlimit))
1653 printf(_(" SMTP message batch limit is %d.\n"), ctl->batchlimit);
1654 else if (outlevel >= O_VERBOSE)
1655 printf(_(" No SMTP message batch limit (--batchlimit 0).\n"));
1656 if (ctl->server.protocol != P_ETRN)
1658 if (NUM_NONZERO(ctl->expunge))
1659 printf(_(" Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1660 else if (outlevel >= O_VERBOSE)
1661 printf(_(" No forced expunges (--expunge 0).\n"));
1665 printf(_(" Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1666 else if (ctl->mda && (ctl->server.protocol != P_ETRN))
1667 printf(_(" Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1672 printf(_(" Messages will be %cMTP-forwarded to:"), ctl->listener);
1673 for (idp = ctl->smtphunt; idp; idp = idp->next)
1675 printf(" %s", idp->id);
1676 if (!idp->val.status.mark)
1677 printf(_(" (default)"));
1680 if (ctl->smtpaddress)
1681 printf(_(" Host part of MAIL FROM line will be %s\n"),
1684 if (ctl->server.protocol != P_ETRN)
1686 if (ctl->antispam != (struct idlist *)NULL)
1690 printf(_(" Recognized listener spam block responses are:"));
1691 for (idp = ctl->antispam; idp; idp = idp->next)
1692 printf(" %d", idp->val.status.num);
1695 else if (outlevel >= O_VERBOSE)
1696 printf(_(" Spam-blocking disabled\n"));
1698 if (ctl->preconnect)
1699 printf(_(" Server connection will be brought up with \"%s\".\n"),
1700 visbuf(ctl->preconnect));
1701 else if (outlevel >= O_VERBOSE)
1702 printf(_(" No pre-connection command.\n"));
1703 if (ctl->postconnect)
1704 printf(_(" Server connection will be taken down with \"%s\".\n"),
1705 visbuf(ctl->postconnect));
1706 else if (outlevel >= O_VERBOSE)
1707 printf(_(" No post-connection command.\n"));
1708 if (ctl->server.protocol != P_ETRN) {
1709 if (!ctl->localnames)
1710 printf(_(" No localnames declared for this host.\n"));
1716 for (idp = ctl->localnames; idp; idp = idp->next)
1719 if (count > 1 || ctl->wildcard)
1720 printf(_(" Multi-drop mode: "));
1722 printf(_(" Single-drop mode: "));
1724 printf(_("%d local name(s) recognized.\n"), count);
1725 if (outlevel >= O_VERBOSE)
1727 for (idp = ctl->localnames; idp; idp = idp->next)
1729 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1731 printf("\t%s\n", idp->id);
1733 fputs("\t*\n", stdout);
1736 if (count > 1 || ctl->wildcard)
1738 printf(_(" DNS lookup for multidrop addresses is %s.\n"),
1739 ctl->server.dns ? _("enabled") : _("disabled"));
1740 if (ctl->server.dns)
1742 printf(_(" Server aliases will be compared with multidrop addresses by "));
1743 if (ctl->server.checkalias)
1744 printf(_("IP address.\n"));
1746 printf(_("name.\n"));
1748 if (ctl->server.envelope == STRING_DISABLED)
1749 printf(_(" Envelope-address routing is disabled\n"));
1752 printf(_(" Envelope header is assumed to be: %s\n"),
1753 ctl->server.envelope ? ctl->server.envelope:_("Received"));
1754 if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1755 printf(_(" Number of envelope header to be parsed: %d\n"),
1756 ctl->server.envskip);
1757 if (ctl->server.qvirtual)
1758 printf(_(" Prefix %s will be removed from user id\n"),
1759 ctl->server.qvirtual);
1760 else if (outlevel >= O_VERBOSE)
1761 printf(_(" No prefix stripping\n"));
1764 if (ctl->server.akalist)
1768 printf(_(" Predeclared mailserver aliases:"));
1769 for (idp = ctl->server.akalist; idp; idp = idp->next)
1770 printf(" %s", idp->id);
1773 if (ctl->server.localdomains)
1777 printf(_(" Local domains:"));
1778 for (idp = ctl->server.localdomains; idp; idp = idp->next)
1779 printf(" %s", idp->id);
1785 #if defined(linux) || defined(__FreeBSD__)
1786 if (ctl->server.interface)
1787 printf(_(" Connection must be through interface %s.\n"), ctl->server.interface);
1788 else if (outlevel >= O_VERBOSE)
1789 printf(_(" No interface requirement specified.\n"));
1790 if (ctl->server.monitor)
1791 printf(_(" Polling loop will monitor %s.\n"), ctl->server.monitor);
1792 else if (outlevel >= O_VERBOSE)
1793 printf(_(" No monitor interface specified.\n"));
1796 if (ctl->server.plugin)
1797 printf(_(" Server connections will be made via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1798 else if (outlevel >= O_VERBOSE)
1799 printf(_(" No plugin command specified.\n"));
1800 if (ctl->server.plugout)
1801 printf(_(" Listener connections will be made via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1802 else if (outlevel >= O_VERBOSE)
1803 printf(_(" No plugout command specified.\n"));
1805 if (ctl->server.protocol > P_POP2 && (ctl->server.protocol != P_ETRN))
1808 printf(_(" No UIDs saved from this host.\n"));
1814 for (idp = ctl->oldsaved; idp; idp = idp->next)
1817 printf(_(" %d UIDs saved.\n"), count);
1818 if (outlevel >= O_VERBOSE)
1819 for (idp = ctl->oldsaved; idp; idp = idp->next)
1820 printf("\t%s\n", idp->id);
1824 if (ctl->properties)
1825 printf(_(" Pass-through properties \"%s\".\n"),
1826 visbuf(ctl->properties));
1830 /* fetchmail.c ends here */