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 struct runctl cmd_run; /* global options set from command line */
88 static time_t parsetime; /* time of last parse */
90 static void terminate_run(int);
91 static void terminate_poll(int);
94 static void unlockit(int n, void *p)
96 static void unlockit(void)
98 /* must-do actions for exit (but we can't count on being able to do malloc) */
100 if (lockfile && lock_acquired)
105 /* drop SGID kmem privileage until we need it */
106 static void dropprivs(void)
116 if (gr && !strcmp(gr->gr_name, "kmem"))
118 extern void interface_set_gids(gid_t egid, gid_t rgid);
119 interface_set_gids(egid, rgid);
125 int main(int argc, char **argv)
127 int st, bkgd = FALSE;
128 int parsestatus, implicitmode = FALSE;
131 netrc_entry *netrc_list;
132 char *netrc_file, *tmpbuf;
140 envquery(argc, argv);
142 bindtextdomain(PACKAGE, LOCALEDIR);
147 * Note: because we can't initialize reporting before we know whether
148 * syslog is supposed to be on, this message will go to stdout and
149 * be lost when running in background.
151 if (outlevel >= O_VERBOSE)
155 report(stdout, "fetchmail: invoked with");
156 for (i = 0; i < argc; i++)
157 report(stdout, " %s", argv[i]);
158 report(stdout, "\n");
161 #define IDFILE_NAME ".fetchids"
162 run.idfile = (char *) xmalloc(strlen(fmhome)+sizeof(IDFILE_NAME)+2);
163 strcpy(run.idfile, fmhome);
164 strcat(run.idfile, "/");
165 strcat(run.idfile, IDFILE_NAME);
170 * We used to arrange for the lockfile to be removed on exit close
171 * to where the lock was asserted. Now we need to do it here, because
172 * we might have re-executed in background with an existing lockfile
173 * as the result of a changed rcfile (see the code near the execvp(3)
174 * call near the beginning of the polling loop for details). We want
175 * to be sure the lockfile gets nuked on any error exit, basically.
181 on_exit(unlockit, (char *)NULL);
184 if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
189 printf(_("This is fetchmail release %s"), VERSION);
192 #endif /* POP2_ENABLE */
195 #endif /* POP3_ENABLE */
198 #endif /* IMAP_ENABLE */
204 #endif /* RPA_ENABLE */
207 #endif /* NTLM_ENABLE */
210 #endif /* SDPS_ENABLE */
213 #endif /* ETRN_ENABLE */
219 #endif /* OPIE_ENABLE */
222 #endif /* INET6_ENABLE */
225 #endif /* NET_SECURITY */
228 #endif /* HAVE_SOCKS */
231 #endif /* ENABLE_NLS */
235 /* this is an attempt to help remote debugging */
239 /* avoid parsing the config file if all we're doing is killing a daemon */
240 if (!(quitmode && argc == 2))
241 implicitmode = load_params(argc, argv, optind);
243 #if defined(HAVE_SYSLOG)
244 /* logging should be set up early in case we were restarted from exec */
247 #if defined(LOG_MAIL)
248 openlog(program_name, LOG_PID, LOG_MAIL);
250 /* Assume BSD4.2 openlog with two arguments */
251 openlog(program_name, LOG_PID);
257 report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
259 /* set up to do lock protocol */
260 #define FETCHMAIL_PIDFILE "fetchmail.pid"
262 xalloca(tmpbuf, char *,
263 sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
264 sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
266 xalloca(tmpbuf, char *, strlen(fmhome) + sizeof(FETCHMAIL_PIDFILE) + 2);
267 strcpy(tmpbuf, fmhome);
271 strcat(tmpbuf, FETCHMAIL_PIDFILE);
273 #undef FETCHMAIL_PIDFILE
275 #ifdef HAVE_SETRLIMIT
277 * Before getting passwords, disable core dumps unless -v -d0 mode is on.
278 * Core dumps could otherwise contain passwords to be scavenged by a
281 if (outlevel < O_VERBOSE || run.poll_interval > 0)
283 struct rlimit corelimit;
284 corelimit.rlim_cur = 0;
285 corelimit.rlim_max = 0;
286 setrlimit(RLIMIT_CORE, &corelimit);
288 #endif /* HAVE_SETRLIMIT */
290 #define NETRC_FILE ".netrc"
291 /* parse the ~/.netrc file (if present) for future password lookups. */
292 xalloca(netrc_file, char *, strlen(home) + sizeof(NETRC_FILE) + 2);
293 strcpy (netrc_file, home);
294 strcat (netrc_file, "/");
295 strcat (netrc_file, NETRC_FILE);
296 netrc_list = parse_netrc(netrc_file);
299 /* pick up passwords where we can */
300 for (ctl = querylist; ctl; ctl = ctl->next)
302 if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
304 if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
305 ctl->server.preauthenticate == A_KERBEROS_V5 ||
306 ctl->server.preauthenticate == A_SSH ||
308 ctl->server.protocol == P_IMAP_GSS ||
310 ctl->server.protocol == P_IMAP_K4)
311 /* Server won't care what the password is, but there
312 must be some non-null string here. */
313 ctl->password = ctl->remotename;
318 /* look up the pollname and account in the .netrc file. */
319 p = search_netrc(netrc_list,
320 ctl->server.pollname, ctl->remotename);
321 /* if we find a matching entry with a password, use it */
322 if (p && p->password)
323 ctl->password = xstrdup(p->password);
325 /* otherwise try with "via" name if there is one */
326 else if (ctl->server.via)
328 p = search_netrc(netrc_list,
329 ctl->server.via, ctl->remotename);
330 if (p && p->password)
331 ctl->password = xstrdup(p->password);
337 /* perhaps we just want to check options? */
340 int havercfile = access(rcfile, 0);
342 printf(_("Taking options from command line%s%s\n"),
343 havercfile ? "" : _(" and "),
344 havercfile ? "" : rcfile);
346 if (outlevel >= O_VERBOSE)
347 printf(_("Lockfile at %s\n"), tmpbuf);
349 if (querylist == NULL)
351 _("No mailservers set up -- perhaps %s is missing?\n"),
354 dump_params(&run, querylist, implicitmode);
358 /* dump options as a Python dictionary, for configurator use */
361 dump_config(&run, querylist);
365 /* check for another fetchmail running concurrently */
367 if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
369 report(stderr,_("fetchmail: cannot allocate memory for lock name.\n"));
373 (void) strcpy(lockfile, tmpbuf);
374 if ((lockfp = fopen(lockfile, "r")) != NULL )
376 bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
378 if (kill(pid, 0) == -1) {
379 fprintf(stderr,_("fetchmail: removing stale lockfile\n"));
384 fclose(lockfp); /* not checking should be safe, file mode was "r" */
387 /* if no mail servers listed and nothing in background, we're done */
388 if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
389 (void)fputs(_("fetchmail: no mailservers have been specified.\n"),stderr);
393 /* perhaps user asked us to kill the other fetchmail */
398 fprintf(stderr,_("fetchmail: no other fetchmail is running\n"));
402 else if (kill(pid, SIGTERM) < 0)
404 fprintf(stderr,_("fetchmail: error killing %s fetchmail at %d; bailing out.\n"),
405 bkgd ? _("background") : _("foreground"), pid);
410 fprintf(stderr,_("fetchmail: %s fetchmail at %d killed.\n"),
411 bkgd ? _("background") : _("foreground"), pid);
420 /* another fetchmail is running -- wake it up or die */
426 _("fetchmail: can't check mail while another fetchmail to same host is running.\n"));
429 else if (!implicitmode)
432 _("fetchmail: can't poll specified hosts with another fetchmail running at %d.\n"),
439 _("fetchmail: another foreground fetchmail is running at %d.\n"),
445 /* this test enables re-execing on a changed rcfile */
447 lock_acquired = TRUE;
451 _("fetchmail: can't accept options while a background fetchmail is running.\n"));
455 else if (kill(pid, SIGUSR1) == 0)
458 _("fetchmail: background fetchmail at %d awakened.\n"),
465 * Should never happen -- possible only if a background fetchmail
466 * croaks after the first kill probe above but before the
467 * SIGUSR1/SIGHUP transmission.
470 _("fetchmail: elder sibling at %d died mysteriously.\n"),
472 return(PS_UNDEFINED);
476 /* pick up interactively any passwords we need but don't have */
477 for (ctl = querylist; ctl; ctl = ctl->next)
479 if (ctl->active && !(implicitmode && ctl->server.skip)
480 && ctl->server.protocol != P_ETRN
481 && ctl->server.protocol != P_IMAP_K4
483 && ctl->server.protocol != P_IMAP_GSS
490 _("fetchmail: can't find a password for %s@%s.\n"),
491 ctl->remotename, ctl->server.pollname);
496 char* password_prompt = _("Enter password for %s@%s: ");
498 xalloca(tmpbuf, char *, strlen(password_prompt) +
499 strlen(ctl->remotename) +
500 strlen(ctl->server.pollname) + 1);
501 (void) sprintf(tmpbuf, password_prompt,
502 ctl->remotename, ctl->server.pollname);
503 ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
509 * Time to initiate the SOCKS library (this is not mandatory: it just
510 * registers the correct application name for logging purpose. If you
511 * have some problem, comment out these lines).
514 SOCKSinit("fetchmail");
515 #endif /* HAVE_SOCKS */
518 * Maybe time to go to demon mode...
520 if (run.poll_interval)
523 daemonize(run.logfile, terminate_run);
524 report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
527 * We'll set up a handler for these when we're sleeping,
528 * but ignore them otherwise so as not to interrupt a poll.
530 signal(SIGUSR1, SIG_IGN);
531 if (run.poll_interval && !getuid())
532 signal(SIGHUP, SIG_IGN);
534 else if (run.logfile && access(run.logfile, F_OK) == 0)
536 freopen(run.logfile, "a", stdout);
537 freopen(run.logfile, "a", stderr);
545 /* beyond here we don't want more than one fetchmail running per user */
547 signal(SIGABRT, terminate_run);
548 signal(SIGINT, terminate_run);
549 signal(SIGTERM, terminate_run);
550 signal(SIGALRM, terminate_run);
551 signal(SIGPIPE, terminate_run);
552 signal(SIGQUIT, terminate_run);
554 /* here's the exclusion lock */
556 #define O_SYNC 0 /* use it if we have it */
558 if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
560 sprintf(tmpbuf,"%d", getpid());
561 write(st, tmpbuf, strlen(tmpbuf));
562 if (run.poll_interval)
564 sprintf(tmpbuf," %d", run.poll_interval);
565 write(st, tmpbuf, strlen(tmpbuf));
567 close(st); /* should be safe, fd was opened with O_SYNC */
568 lock_acquired = TRUE;
572 * Query all hosts. If there's only one, the error return will
573 * reflect the status of that transaction.
577 * Check to see if the rcfile has been touched. If so,
578 * re-exec so the file will be reread. Doing it this way
579 * avoids all the complications of trying to deallocate the
580 * in-core control structures -- and the potential memory
585 if (stat(rcfile, &rcstat) == -1)
589 _("couldn't time-check %s (error %d)\n"),
592 else if (rcstat.st_mtime > parsetime)
594 report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
595 execvp("fetchmail", argv);
596 report(stderr, _("attempt to re-exec fetchmail failed\n"));
599 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
601 * This was an efficiency hack that backfired. The theory
602 * was that using TCP/IP for DNS queries would get us better
603 * reliability and shave off some per-UDP-packet costs.
604 * Unfortunately it interacted badly with diald, which effectively
605 * filters out DNS queries over TCP/IP for reasons having to do
606 * with some obscure kernel problem involving bootstrapping of
607 * dynamically-addressed links. I don't understand this mess
608 * and don't want to, so it's "See ya!" to this hack.
610 sethostent(TRUE); /* use TCP/IP for mailserver queries */
611 #endif /* HAVE_RES_SEARCH */
614 for (ctl = querylist; ctl; ctl = ctl->next)
616 if (ctl->active && !(implicitmode && ctl->server.skip))
621 _("poll of %s skipped (failed authentication or too many timeouts)\n"),
622 ctl->server.pollname);
626 /* check skip interval first so that it counts all polls */
627 if (run.poll_interval && ctl->server.interval)
629 if (ctl->server.poll_count++ % ctl->server.interval)
631 if (outlevel >= O_VERBOSE)
633 _("interval not reached, not querying %s\n"),
634 ctl->server.pollname);
639 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
641 * Don't do monitoring if we were woken by a signal.
642 * Note that interface_approve() does its own error logging.
644 if (!interface_approve(&ctl->server, !lastsig))
646 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
648 querystatus = query_host(ctl);
653 #endif /* POP3_ENABLE */
655 if (querystatus == PS_SUCCESS)
657 else if (!check_only &&
658 ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
662 report(stdout, "Query status=0 (SUCCESS)\n"); break ;
664 report(stdout, "Query status=1 (NOMAIL)\n"); break ;
666 report(stdout, "Query status=2 (SOCKET)\n"); break ;
668 report(stdout, "Query status=3 (AUTHFAIL)\n"); break ;
670 report(stdout, "Query status=4 (PROTOCOL)\n"); break ;
672 report(stdout, "Query status=5 (SYNTAX)\n"); break ;
674 report(stdout, "Query status=6 (IOERR)\n"); break ;
676 report(stdout, "Query status=7 (ERROR)\n"); break ;
678 report(stdout, "Query status=8 (EXCLUDE)\n"); break ;
680 report(stdout, "Query status=9 (LOCKBUSY)\n"); break ;
682 report(stdout, "Query status=10 (SMTP)\n"); break ;
684 report(stdout, "Query status=11 (DNS)\n"); break ;
686 report(stdout, "Query status=12 (BSMTP)\n"); break ;
688 report(stdout, "Query status=13 (MAXFETCH)\n"); break ;
690 report(stdout, _("Query status=%d\n"), querystatus); break;
693 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
694 if (ctl->server.monitor)
697 * Allow some time for the link to quiesce. One
698 * second is usually sufficient, three is safe.
699 * Note: this delay is important - don't remove!
702 interface_note_activity(&ctl->server);
704 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
708 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
709 endhostent(); /* release TCP/IP connection to nameserver */
710 #endif /* HAVE_RES_SEARCH */
712 /* close connections cleanly */
716 * OK, we've polled. Now sleep.
718 if (run.poll_interval)
721 * Because passwords can expire, it may happen that *all*
722 * hosts are now out of the loop due to authfail
723 * conditions. If this happens daemon-mode fetchmail
724 * should softly and silently vanish away, rather than
725 * spinning uselessly.
729 for (ctl = querylist; ctl; ctl = ctl->next)
730 if (ctl->active && !(implicitmode && ctl->server.skip))
735 report(stderr, _("All connections are wedged. Exiting.\n"));
736 /* FIXME: someday, send notification mail */
740 if (outlevel >= O_VERBOSE)
742 _("fetchmail: sleeping at %s\n"), rfc822timestamp());
745 * OK, now pause util it's time for the next poll cycle.
746 * A nonzero return indicates we received a wakeup signal;
747 * unwedge all servers in case the problem has been
750 if ((lastsig = interruptible_idle(run.poll_interval)))
752 #ifdef SYS_SIGLIST_DECLARED
754 _("awakened by %s\n"), sys_siglist[lastsig]);
757 _("awakened by signal %d\n"), lastsig);
759 for (ctl = querylist; ctl; ctl = ctl->next)
763 if (outlevel >= O_VERBOSE)
764 report(stdout, _("awakened at %s\n"), rfc822timestamp());
769 if (outlevel >= O_VERBOSE)
770 report(stdout, _("normal termination, status %d\n"),
771 successes ? PS_SUCCESS : querystatus);
774 exit(successes ? PS_SUCCESS : querystatus);
777 static void list_merge(struct idlist **dstl, struct idlist **srcl, int force)
780 * If force is off, modify dstl fields only when they're empty (treat srcl
781 * as defaults). If force is on, modify each dstl field whenever scrcl
782 * is nonempty (treat srcl as an override).
784 if (force ? !!*srcl : !*dstl)
786 struct idlist *cpl = copy_str_list(*srcl);
788 append_str_list(dstl, &cpl);
792 static void optmerge(struct query *h2, struct query *h1, int force)
793 /* merge two options records */
795 list_merge(&h2->server.localdomains, &h1->server.localdomains, force);
796 list_merge(&h2->localnames, &h1->localnames, force);
797 list_merge(&h2->mailboxes, &h1->mailboxes, force);
798 list_merge(&h2->smtphunt, &h1->smtphunt, force);
799 list_merge(&h2->antispam, &h1->antispam, force);
801 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
802 FLAG_MERGE(server.via);
803 FLAG_MERGE(server.protocol);
805 FLAG_MERGE(server.service);
806 FLAG_MERGE(server.netsec);
807 #else /* INET6_ENABLE */
808 FLAG_MERGE(server.port);
809 #endif /* INET6_ENABLE */
810 FLAG_MERGE(server.interval);
811 FLAG_MERGE(server.preauthenticate);
812 FLAG_MERGE(server.timeout);
813 FLAG_MERGE(server.envelope);
814 FLAG_MERGE(server.envskip);
815 FLAG_MERGE(server.qvirtual);
816 FLAG_MERGE(server.skip);
817 FLAG_MERGE(server.dns);
818 FLAG_MERGE(server.checkalias);
819 FLAG_MERGE(server.uidl);
821 #if defined(linux) || defined(__FreeBSD__)
822 FLAG_MERGE(server.interface);
823 FLAG_MERGE(server.monitor);
824 FLAG_MERGE(server.interface_pair);
825 #endif /* linux || defined(__FreeBSD__) */
827 FLAG_MERGE(server.plugin);
828 FLAG_MERGE(server.plugout);
830 FLAG_MERGE(wildcard);
831 FLAG_MERGE(remotename);
832 FLAG_MERGE(password);
835 FLAG_MERGE(listener);
836 FLAG_MERGE(smtpaddress);
837 FLAG_MERGE(smtpname);
838 FLAG_MERGE(preconnect);
839 FLAG_MERGE(postconnect);
843 FLAG_MERGE(fetchall);
847 FLAG_MERGE(pass8bits);
848 FLAG_MERGE(dropstatus);
849 FLAG_MERGE(mimedecode);
852 FLAG_MERGE(warnings);
853 FLAG_MERGE(fetchlimit);
854 FLAG_MERGE(batchlimit);
862 FLAG_MERGE(properties);
866 static int load_params(int argc, char **argv, int optind)
868 int implicitmode, st;
870 struct query def_opts, *ctl;
873 run.bouncemail = TRUE;
875 memset(&def_opts, '\0', sizeof(struct query));
876 def_opts.smtp_socket = -1;
877 def_opts.smtpaddress = (char *)0;
878 #define ANTISPAM(n) save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
879 ANTISPAM(571); /* sendmail */
880 ANTISPAM(550); /* old exim */
881 ANTISPAM(501); /* new exim */
882 ANTISPAM(554); /* Postfix */
885 def_opts.server.protocol = P_AUTO;
886 def_opts.server.timeout = CLIENT_TIMEOUT;
887 def_opts.warnings = WARNING_INTERVAL;
888 def_opts.remotename = user;
889 def_opts.listener = SMTP_MODE;
891 /* note the parse time, so we can pick up on modifications */
892 parsetime = 0; /* foil compiler warnings */
893 if (stat(rcfile, &rcstat) != -1)
894 parsetime = rcstat.st_mtime;
895 else if (errno != ENOENT)
896 report(stderr, _("couldn't time-check the run-control file\n"));
898 /* this builds the host list */
899 if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
901 * FIXME: someday, send notification mail here if backgrounded.
902 * Right now, that can happen if the user changes the rcfile
903 * while the fetchmail is running in background. Do similarly
904 * for the other exit() calls in this function.
908 if ((implicitmode = (optind >= argc)))
910 for (ctl = querylist; ctl; ctl = ctl->next)
914 for (; optind < argc; optind++)
916 flag predeclared = FALSE;
919 * If hostname corresponds to a host known from the rc file,
920 * simply declare it active. Otherwise synthesize a host
921 * record from command line and defaults
923 for (ctl = querylist; ctl; ctl = ctl->next)
924 if (!strcmp(ctl->server.pollname, argv[optind])
925 || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
927 /* Is this correct? */
928 if (predeclared && outlevel == O_VERBOSE)
929 fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
937 * Allocate and link record without copying in
938 * command-line args; we'll do that with the optmerge
941 ctl = hostalloc((struct query *)NULL);
943 ctl->server.pollname = xstrdup(argv[optind]);
945 ctl->server.lead_server = (struct hostdata *)NULL;
950 * If there's a defaults record, merge it and lose it.
952 if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
954 for (ctl = querylist->next; ctl; ctl = ctl->next)
955 optmerge(ctl, querylist, FALSE);
956 querylist = querylist->next;
959 /* don't allow a defaults record after the first */
960 for (ctl = querylist; ctl; ctl = ctl->next)
961 if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
964 /* use localhost if we never fetch the FQDN of this host */
965 fetchmailhost = "localhost";
967 /* here's where we override globals */
969 run.logfile = cmd_run.logfile;
971 run.idfile = cmd_run.idfile;
972 /* do this before the keep/fetchall test below, otherwise -d0 may fail */
973 if (cmd_run.poll_interval >= 0)
974 run.poll_interval = cmd_run.poll_interval;
975 if (cmd_run.invisible)
976 run.invisible = cmd_run.invisible;
977 if (cmd_run.use_syslog)
978 run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
979 if (cmd_run.postmaster)
980 run.postmaster = cmd_run.postmaster;
981 if (cmd_run.bouncemail)
982 run.bouncemail = cmd_run.bouncemail;
984 /* check and daemon options are not compatible */
985 if (check_only && run.poll_interval)
986 run.poll_interval = 0;
988 /* merge in wired defaults, do sanity checks and prepare internal fields */
989 for (ctl = querylist; ctl; ctl = ctl->next)
993 if (configdump || (ctl->active && !(implicitmode && ctl->server.skip)))
995 /* merge in defaults */
996 optmerge(ctl, &def_opts, FALSE);
998 /* force command-line options */
999 optmerge(ctl, &cmd_opts, TRUE);
1001 /* this code enables flags to be turned off */
1002 #define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
1004 else if (flag == FLAG_FALSE)\
1008 DEFAULT(ctl->keep, FALSE);
1009 DEFAULT(ctl->fetchall, FALSE);
1010 DEFAULT(ctl->flush, FALSE);
1011 DEFAULT(ctl->rewrite, TRUE);
1012 DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
1013 DEFAULT(ctl->forcecr, FALSE);
1014 DEFAULT(ctl->pass8bits, FALSE);
1015 DEFAULT(ctl->dropstatus, FALSE);
1016 DEFAULT(ctl->mimedecode, FALSE);
1017 DEFAULT(ctl->idle, FALSE);
1018 DEFAULT(ctl->server.dns, TRUE);
1019 DEFAULT(ctl->server.uidl, FALSE);
1021 DEFAULT(ctl->use_ssl, FALSE);
1023 DEFAULT(ctl->server.checkalias, FALSE);
1027 * DNS support is required for some protocols. We used to
1028 * do this unconditionally, but it made fetchmail excessively
1029 * vulnerable to misconfigured DNS setups.
1031 * If we're using ETRN, the smtp hunt list is the list of
1032 * systems we're polling on behalf of; these have to be
1033 * fully-qualified domain names. The default for this list
1034 * should be the FQDN of localhost.
1036 * If we're using Kerberos for authentication, we need
1037 * the FQDN in order to generate capability keys.
1039 if (ctl->server.protocol == P_ETRN
1040 || ctl->server.preauthenticate == A_KERBEROS_V4
1041 || ctl->server.preauthenticate == A_KERBEROS_V5)
1042 if (strcmp(fetchmailhost, "localhost") == 0)
1043 fetchmailhost = host_fqdn();
1046 * Make sure we have a nonempty host list to forward to.
1049 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1051 /* if `user' doesn't name a real local user, try to run as root */
1052 if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1055 ctl->uid = pw->pw_uid; /* for local delivery via MDA */
1056 if (!ctl->localnames) /* for local delivery via SMTP */
1057 save_str_pair(&ctl->localnames, user, NULL);
1059 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1060 /* can't handle multidrop mailboxes unless we can do DNS lookups */
1061 if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1063 ctl->server.dns = FALSE;
1064 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1066 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1070 * Compute the true name of the mailserver host.
1071 * There are two clashing cases here:
1073 * (1) The poll name is a label, possibly on one of several
1074 * poll configurations for the same host. In this case
1075 * the `via' option will be present and give the true name.
1077 * (2) The poll name is the true one, the via name is
1078 * localhost. This is going to be typical for ssh-using
1081 * We're going to assume the via name is true unless it's
1084 if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1085 ctl->server.queryname = xstrdup(ctl->server.via);
1087 ctl->server.queryname = xstrdup(ctl->server.pollname);
1090 /* If either the pollname or vianame are "hesiod" we want to
1091 lookup the user's hesiod pobox host */
1093 if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1094 struct hes_postoffice *hes_p;
1095 hes_p = hes_getmailhost(ctl->remotename);
1096 if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1097 free(ctl->server.queryname);
1098 ctl->server.queryname = xstrdup(hes_p->po_host);
1099 if (ctl->server.via)
1100 free(ctl->server.via);
1101 ctl->server.via = xstrdup(hes_p->po_host);
1104 _("couldn't find HESIOD pobox for %s\n"),
1111 * We may have to canonicalize the server truename for later use.
1112 * Do this just once for each lead server, if necessary, in order
1113 * to minimize DNS round trips.
1115 if (ctl->server.lead_server)
1117 char *leadname = ctl->server.lead_server->truename;
1119 /* prevent core dump from ill-formed or duplicate entry */
1123 _("Lead server has no name.\n"));
1127 ctl->server.truename = xstrdup(leadname);
1129 #ifdef HAVE_GETHOSTBYNAME
1130 else if (!configdump && (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1131 ctl->server.preauthenticate==A_KERBEROS_V5 ||
1132 (ctl->server.dns && MULTIDROP(ctl))))
1134 struct hostent *namerec;
1136 /* compute the canonical name of the host */
1138 namerec = gethostbyname(ctl->server.queryname);
1139 if (namerec == (struct hostent *)NULL)
1142 _("couldn't find canonical DNS name of %s\n"),
1143 ctl->server.pollname);
1147 ctl->server.truename=xstrdup((char *)namerec->h_name);
1149 #endif /* HAVE_GETHOSTBYNAME */
1151 #ifdef HAVE_GETHOSTBYNAME
1152 struct hostent *namerec;
1154 /* <fetchmail@mail.julianhaight.com>
1155 Get the host's IP, so we can report it like this:
1157 Received: from hostname [10.0.0.1]
1159 do we actually need to gethostbyname to find the IP?
1160 it seems like it would be faster to do this later, when
1161 we are actually resolving the hostname for a connection,
1162 but I ain't that smart, so I don't know where to make
1166 namerec = gethostbyname(ctl->server.queryname);
1167 if (namerec == (struct hostent *)NULL)
1170 _("couldn't find canonical DNS name of %s\n"),
1171 ctl->server.pollname);
1175 ctl->server.truename=xstrdup((char *)namerec->h_name);
1176 ctl->server.trueaddr=xmalloc(namerec->h_length);
1177 memcpy(ctl->server.trueaddr,
1178 namerec->h_addr_list[0],
1182 ctl->server.truename = xstrdup(ctl->server.queryname);
1183 #endif /* HAVE_GETHOSTBYNAME */
1186 /* if no folders were specified, set up the null one as default */
1187 if (!ctl->mailboxes)
1188 save_str(&ctl->mailboxes, (char *)NULL, 0);
1190 /* maybe user overrode timeout on command line? */
1191 if (ctl->server.timeout == -1)
1192 ctl->server.timeout = CLIENT_TIMEOUT;
1196 if (ctl->server.port < 0)
1198 (void) fprintf(stderr,
1199 _("%s configuration invalid, port number cannot be negative\n"),
1200 ctl->server.pollname);
1203 if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1205 (void) fprintf(stderr,
1206 _("%s configuration invalid, RPOP requires a privileged port\n"),
1207 ctl->server.pollname);
1210 if (ctl->listener == LMTP_MODE)
1214 for (idp = ctl->smtphunt; idp; idp = idp->next)
1218 if (!(cp = strrchr(idp->id, '/')) ||
1219 (atoi(++cp) == SMTP_PORT))
1221 (void) fprintf(stderr,
1222 _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1223 ctl->server.pollname);
1228 #endif /* !INET6_ENABLE */
1231 * "I beg to you, have mercy on the week minds like myself."
1232 * wrote Pehr Anderson. Your petition is granted.
1234 if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1236 (void) fprintf(stderr,
1237 _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1244 /* initialize UID handling */
1245 if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1248 initialize_saved_lists(querylist, run.idfile);
1249 #endif /* POP3_ENABLE */
1252 * If the user didn't set a last-resort user to get misaddressed
1253 * multidrop mail, set an appropriate default here.
1255 if (!run.postmaster)
1257 if (getuid()) /* ordinary user */
1258 run.postmaster = user;
1260 run.postmaster = "postmaster";
1263 return(implicitmode);
1266 static void terminate_poll(int sig)
1267 /* to be executed at the end of a poll cycle */
1270 * Close all SMTP delivery sockets. For optimum performance
1271 * we'd like to hold them open til end of run, but (1) this
1272 * loses if our poll interval is longer than the MTA's inactivity
1273 * timeout, and (2) some MTAs (like smail) don't deliver after
1274 * each message, but rather queue up mail and wait to actually
1275 * deliver it until the input socket is closed.
1277 * Sending SMTP QUIT on signal is theoretically nice, but led to a
1278 * subtle bug. If fetchmail was terminated by signal while it was
1279 * shipping message text, it would hang forever waiting for a
1280 * command acknowledge. In theory we could enable the QUIT
1281 * only outside of the message send. In practice, we don't
1282 * care. All mailservers hang up on a dropped TCP/IP connection
1287 report(stdout, _("terminated with signal %d\n"), sig);
1292 /* terminate all SMTP connections cleanly */
1293 for (ctl = querylist; ctl; ctl = ctl->next)
1294 if (ctl->smtp_socket != -1)
1296 SMTP_quit(ctl->smtp_socket);
1297 SockClose(ctl->smtp_socket);
1298 ctl->smtp_socket = -1;
1304 * Update UID information at end of each poll, rather than at end
1305 * of run, because that way we don't lose all UIDL information since
1306 * the beginning of time if fetchmail crashes.
1309 write_saved_lists(querylist, run.idfile);
1310 #endif /* POP3_ENABLE */
1313 static void terminate_run(int sig)
1314 /* to be executed on normal or signal-induced termination */
1318 terminate_poll(sig);
1321 * Craig Metz, the RFC1938 one-time-password guy, points out:
1322 * "Remember that most kernels don't zero pages before handing them to the
1323 * next process and many kernels share pages between user and kernel space.
1324 * You'd be very surprised what you can find from a short program to do a
1325 * malloc() and then dump the contents of the pages you got. By zeroing
1326 * the secrets at end of run (earlier if you can), you make sure the next
1327 * guy can't get the password/pass phrase."
1329 * Right you are, Craig!
1331 for (ctl = querylist; ctl; ctl = ctl->next)
1333 memset(ctl->password, '\0', strlen(ctl->password));
1335 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1339 exit(successes ? PS_SUCCESS : querystatus);
1343 * Sequence of protocols to try when autoprobing, most capable to least.
1345 static const int autoprobe[] =
1349 #endif /* IMAP_ENABLE */
1352 #endif /* POP3_ENABLE */
1355 #endif /* POP2_ENABLE */
1358 static int query_host(struct query *ctl)
1359 /* perform fetch transaction with single host */
1364 * If we're syslogging the progress messages are automatically timestamped.
1365 * Force timestamping if we're going to a logfile.
1367 if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1369 report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1371 ctl->server.pollname,
1372 showproto(ctl->server.protocol),
1375 switch (ctl->server.protocol) {
1377 for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1379 ctl->server.protocol = autoprobe[i];
1380 if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1383 ctl->server.protocol = P_AUTO;
1387 return(doPOP2(ctl));
1389 report(stderr, _("POP2 support is not configured.\n"));
1390 return(PS_PROTOCOL);
1391 #endif /* POP2_ENABLE */
1397 return(doPOP3(ctl));
1399 report(stderr, _("POP3 support is not configured.\n"));
1400 return(PS_PROTOCOL);
1401 #endif /* POP3_ENABLE */
1405 case P_IMAP_CRAM_MD5:
1411 return(doIMAP(ctl));
1413 report(stderr, _("IMAP support is not configured.\n"));
1414 return(PS_PROTOCOL);
1415 #endif /* IMAP_ENABLE */
1418 report(stderr, _("ETRN support is not configured.\n"));
1419 return(PS_PROTOCOL);
1421 #ifdef HAVE_GETHOSTBYNAME
1422 return(doETRN(ctl));
1424 report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1425 return(PS_PROTOCOL);
1426 #endif /* HAVE_GETHOSTBYNAME */
1427 #endif /* ETRN_ENABLE */
1429 report(stderr, _("unsupported protocol selected.\n"));
1430 return(PS_PROTOCOL);
1434 static void dump_params (struct runctl *runp,
1435 struct query *querylist, flag implicit)
1436 /* display query parameters in English */
1440 if (runp->poll_interval)
1441 printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1443 printf(_("Logfile is %s\n"), runp->logfile);
1444 if (strcmp(runp->idfile, IDFILE_NAME))
1445 printf(_("Idfile is %s\n"), runp->idfile);
1446 #if defined(HAVE_SYSLOG)
1447 if (runp->use_syslog)
1448 printf(_("Progress messages will be logged via syslog\n"));
1450 if (runp->invisible)
1451 printf(_("Fetchmail will masquerade and will not generate Received\n"));
1452 if (runp->postmaster)
1453 printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1456 if (!runp->bouncemail)
1457 printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1458 else if (outlevel >= O_VERBOSE)
1459 printf(_("Fetchmail will direct error mail to the sender.\n"));
1461 for (ctl = querylist; ctl; ctl = ctl->next)
1463 if (!ctl->active || (implicit && ctl->server.skip))
1466 printf(_("Options for retrieving from %s@%s:\n"),
1467 ctl->remotename, visbuf(ctl->server.pollname));
1469 if (ctl->server.via && (ctl->server.protocol != P_ETRN))
1470 printf(_(" Mail will be retrieved via %s\n"), ctl->server.via);
1472 if (ctl->server.interval)
1473 printf(_(" Poll of this server will occur every %d intervals.\n"),
1474 ctl->server.interval);
1475 if (ctl->server.truename)
1476 printf(_(" True name of server is %s.\n"), ctl->server.truename);
1477 if (ctl->server.skip || outlevel >= O_VERBOSE)
1478 printf(_(" This host %s be queried when no host is specified.\n"),
1479 ctl->server.skip ? _("will not") : _("will"));
1481 * Don't poll for password when there is one or when using the ETRN
1482 * or IMAP-GSS protocol
1484 /* ETRN, IMAP_GSS, and IMAP_K4 do not need a password, so skip this */
1485 if ( (ctl->server.protocol != P_ETRN)
1487 && (ctl->server.protocol != P_IMAP_GSS)
1489 && (ctl->server.protocol != P_IMAP_K4) ) {
1491 printf(_(" Password will be prompted for.\n"));
1492 else if (outlevel >= O_VERBOSE)
1494 if (ctl->server.protocol == P_APOP)
1495 printf(_(" APOP secret = \"%s\".\n"),
1496 visbuf(ctl->password));
1497 else if (ctl->server.protocol == P_RPOP)
1498 printf(_(" RPOP id = \"%s\".\n"),
1499 visbuf(ctl->password));
1501 printf(_(" Password = \"%s\".\n"),
1502 visbuf(ctl->password));
1506 if (ctl->server.protocol == P_POP3
1508 && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1509 #else /* INET6_ENABLE */
1510 && ctl->server.port == KPOP_PORT
1511 #endif /* INET6_ENABLE */
1512 && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1513 ctl->server.preauthenticate == A_KERBEROS_V5))
1514 printf(_(" Protocol is KPOP with Kerberos %s authentication"),
1515 ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1517 printf(_(" Protocol is %s"), showproto(ctl->server.protocol));
1519 if (ctl->server.service)
1520 printf(_(" (using service %s)"), ctl->server.service);
1521 if (ctl->server.netsec)
1522 printf(_(" (using network security options %s)"), ctl->server.netsec);
1523 #else /* INET6_ENABLE */
1524 if (ctl->server.port)
1525 printf(_(" (using port %d)"), ctl->server.port);
1526 #endif /* INET6_ENABLE */
1527 else if (outlevel >= O_VERBOSE)
1528 printf(_(" (using default port)"));
1529 if (ctl->server.uidl && (ctl->server.protocol != P_ETRN))
1530 printf(_(" (forcing UIDL use)"));
1533 if (ctl->server.preauthenticate == A_KERBEROS_V4)
1534 printf(_(" Kerberos V4 preauthentication enabled.\n"));
1535 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
1536 printf(_(" Kerberos V5 preauthentication enabled.\n"));
1537 else if (ctl->server.preauthenticate == A_SSH)
1538 printf(_(" End-to-end encryption assumed.\n"));
1541 printf(" SSL encrypted sessions enabled.\n");
1543 if (ctl->server.timeout > 0)
1544 printf(_(" Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1545 if (ctl->server.timeout == CLIENT_TIMEOUT)
1546 printf(_(" (default).\n"));
1550 if (ctl->server.protocol != P_ETRN) {
1551 if (!ctl->mailboxes->id)
1552 printf(_(" Default mailbox selected.\n"));
1557 printf(_(" Selected mailboxes are:"));
1558 for (idp = ctl->mailboxes; idp; idp = idp->next)
1559 printf(" %s", idp->id);
1562 printf(_(" %s messages will be retrieved (--all %s).\n"),
1563 ctl->fetchall ? _("All") : _("Only new"),
1564 ctl->fetchall ? "on" : "off");
1565 printf(_(" Fetched messages %s be kept on the server (--keep %s).\n"),
1566 ctl->keep ? _("will") : _("will not"),
1567 ctl->keep ? "on" : "off");
1568 printf(_(" Old messages %s be flushed before message retrieval (--flush %s).\n"),
1569 ctl->flush ? _("will") : _("will not"),
1570 ctl->flush ? "on" : "off");
1571 printf(_(" Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1572 ctl->rewrite ? _("enabled") : _("disabled"),
1573 ctl->rewrite ? "off" : "on");
1574 printf(_(" Carriage-return stripping is %s (stripcr %s).\n"),
1575 ctl->stripcr ? _("enabled") : _("disabled"),
1576 ctl->stripcr ? "on" : "off");
1577 printf(_(" Carriage-return forcing is %s (forcecr %s).\n"),
1578 ctl->forcecr ? _("enabled") : _("disabled"),
1579 ctl->forcecr ? "on" : "off");
1580 printf(_(" Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1581 ctl->pass8bits ? _("disabled") : _("enabled"),
1582 ctl->pass8bits ? "on" : "off");
1583 printf(_(" MIME decoding is %s (mimedecode %s).\n"),
1584 ctl->mimedecode ? _("enabled") : _("disabled"),
1585 ctl->mimedecode ? "on" : "off");
1586 printf(_(" Idle after poll is %s (idle %s).\n"),
1587 ctl->idle ? _("enabled") : _("disabled"),
1588 ctl->idle ? "on" : "off");
1589 printf(_(" Nonempty Status lines will be %s (dropstatus %s)\n"),
1590 ctl->dropstatus ? _("discarded") : _("kept"),
1591 ctl->dropstatus ? "on" : "off");
1592 if (NUM_NONZERO(ctl->limit))
1594 if (NUM_NONZERO(ctl->limit))
1595 printf(_(" Message size limit is %d octets (--limit %d).\n"),
1596 ctl->limit, ctl->limit);
1597 else if (outlevel >= O_VERBOSE)
1598 printf(_(" No message size limit (--limit 0).\n"));
1599 if (run.poll_interval > 0)
1600 printf(_(" Message size warning interval is %d seconds (--warnings %d).\n"),
1601 ctl->warnings, ctl->warnings);
1602 else if (outlevel >= O_VERBOSE)
1603 printf(_(" Size warnings on every poll (--warnings 0).\n"));
1605 if (NUM_NONZERO(ctl->fetchlimit))
1606 printf(_(" Received-message limit is %d (--fetchlimit %d).\n"),
1607 ctl->fetchlimit, ctl->fetchlimit);
1608 else if (outlevel >= O_VERBOSE)
1609 printf(_(" No received-message limit (--fetchlimit 0).\n"));
1610 if (NUM_NONZERO(ctl->batchlimit))
1611 printf(_(" SMTP message batch limit is %d.\n"), ctl->batchlimit);
1612 else if (outlevel >= O_VERBOSE)
1613 printf(_(" No SMTP message batch limit (--batchlimit 0).\n"));
1614 if (ctl->server.protocol == P_IMAP)
1616 if (NUM_NONZERO(ctl->expunge))
1617 printf(_(" Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1618 else if (outlevel >= O_VERBOSE)
1619 printf(_(" No forced expunges (--expunge 0).\n"));
1623 printf(_(" Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1624 else if (ctl->mda && (ctl->server.protocol != P_ETRN))
1625 printf(_(" Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1630 printf(_(" Messages will be %cMTP-forwarded to:"), ctl->listener);
1631 for (idp = ctl->smtphunt; idp; idp = idp->next)
1633 printf(" %s", idp->id);
1634 if (!idp->val.status.mark)
1635 printf(_(" (default)"));
1638 if (ctl->smtpaddress)
1639 printf(_(" Host part of MAIL FROM line will be %s\n"),
1642 if (ctl->server.protocol != P_ETRN)
1644 if (ctl->antispam != (struct idlist *)NULL)
1648 printf(_(" Recognized listener spam block responses are:"));
1649 for (idp = ctl->antispam; idp; idp = idp->next)
1650 printf(" %d", idp->val.status.num);
1653 else if (outlevel >= O_VERBOSE)
1654 printf(_(" Spam-blocking disabled\n"));
1656 if (ctl->preconnect)
1657 printf(_(" Server connection will be brought up with \"%s\".\n"),
1658 visbuf(ctl->preconnect));
1659 else if (outlevel >= O_VERBOSE)
1660 printf(_(" No pre-connection command.\n"));
1661 if (ctl->postconnect)
1662 printf(_(" Server connection will be taken down with \"%s\".\n"),
1663 visbuf(ctl->postconnect));
1664 else if (outlevel >= O_VERBOSE)
1665 printf(_(" No post-connection command.\n"));
1666 if (ctl->server.protocol != P_ETRN) {
1667 if (!ctl->localnames)
1668 printf(_(" No localnames declared for this host.\n"));
1674 for (idp = ctl->localnames; idp; idp = idp->next)
1677 if (count > 1 || ctl->wildcard)
1678 printf(_(" Multi-drop mode: "));
1680 printf(_(" Single-drop mode: "));
1682 printf(_("%d local name(s) recognized.\n"), count);
1683 if (outlevel >= O_VERBOSE)
1685 for (idp = ctl->localnames; idp; idp = idp->next)
1687 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1689 printf("\t%s\n", idp->id);
1691 fputs("\t*\n", stdout);
1694 if (count > 1 || ctl->wildcard)
1696 printf(_(" DNS lookup for multidrop addresses is %s.\n"),
1697 ctl->server.dns ? _("enabled") : _("disabled"));
1698 if (ctl->server.dns)
1700 printf(_(" Server aliases will be compared with multidrop addresses by "));
1701 if (ctl->server.checkalias)
1702 printf(_("IP address.\n"));
1704 printf(_("name.\n"));
1706 if (ctl->server.envelope == STRING_DISABLED)
1707 printf(_(" Envelope-address routing is disabled\n"));
1710 printf(_(" Envelope header is assumed to be: %s\n"),
1711 ctl->server.envelope ? ctl->server.envelope:_("Received"));
1712 if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1713 printf(_(" Number of envelope header to be parsed: %d\n"),
1714 ctl->server.envskip);
1715 if (ctl->server.qvirtual)
1716 printf(_(" Prefix %s will be removed from user id\n"),
1717 ctl->server.qvirtual);
1718 else if (outlevel >= O_VERBOSE)
1719 printf(_(" No prefix stripping\n"));
1722 if (ctl->server.akalist)
1726 printf(_(" Predeclared mailserver aliases:"));
1727 for (idp = ctl->server.akalist; idp; idp = idp->next)
1728 printf(" %s", idp->id);
1731 if (ctl->server.localdomains)
1735 printf(_(" Local domains:"));
1736 for (idp = ctl->server.localdomains; idp; idp = idp->next)
1737 printf(" %s", idp->id);
1743 #if defined(linux) || defined(__FreeBSD__)
1744 if (ctl->server.interface)
1745 printf(_(" Connection must be through interface %s.\n"), ctl->server.interface);
1746 else if (outlevel >= O_VERBOSE)
1747 printf(_(" No interface requirement specified.\n"));
1748 if (ctl->server.monitor)
1749 printf(_(" Polling loop will monitor %s.\n"), ctl->server.monitor);
1750 else if (outlevel >= O_VERBOSE)
1751 printf(_(" No monitor interface specified.\n"));
1754 if (ctl->server.plugin)
1755 printf(_(" Server connections will be made via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1756 else if (outlevel >= O_VERBOSE)
1757 printf(_(" No plugin command specified.\n"));
1758 if (ctl->server.plugout)
1759 printf(_(" Listener connections will be made via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1760 else if (outlevel >= O_VERBOSE)
1761 printf(_(" No plugout command specified.\n"));
1763 if (ctl->server.protocol > P_POP2 && (ctl->server.protocol != P_ETRN))
1766 printf(_(" No UIDs saved from this host.\n"));
1772 for (idp = ctl->oldsaved; idp; idp = idp->next)
1775 printf(_(" %d UIDs saved.\n"), count);
1776 if (outlevel >= O_VERBOSE)
1777 for (idp = ctl->oldsaved; idp; idp = idp->next)
1778 printf("\t%s\n", idp->id);
1782 if (ctl->properties)
1783 printf(_(" Pass-through properties \"%s\".\n"),
1784 visbuf(ctl->properties));
1788 /* fetchmail.c ends here */