2 * fetchmail.c -- main driver module for fetchmail
4 * For license terms, see the file COPYING in this directory.
10 #if defined(STDC_HEADERS)
13 #if defined(HAVE_UNISTD_H)
20 #if defined(HAVE_SYSLOG)
29 #include <sys/types.h>
32 #include <sys/resource.h>
33 #endif /* HAVE_SETRLIMIT */
34 #ifdef HAVE_SYS_WAIT_H
36 #endif /* HAVE_SYS_WAIT_H */
37 #include <sys/utsname.h>
39 #ifdef HAVE_GETHOSTBYNAME
41 #endif /* HAVE_GETHOSTBYNAME */
47 #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 *program_name; /* the name to prefix error messages with */
74 flag configdump; /* dump control blocks for configurator */
75 const char *fetchmailhost; /* either `localhost' or the host's FQDN */
76 volatile int lastsig; /* last signal received */
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);
93 #ifdef SLEEP_WITH_ALARM
95 * The function of this variable is to remove the window during which a
96 * SIGALRM can hose the code (ALARM is triggered *before* pause() is called).
97 * This is a bit of a kluge; the real right thing would use sigprocmask(),
98 * sigsuspend(). This workaround lets the interval timer trigger the first
99 * alarm after the required interval and will then generate alarms all 5
100 * seconds, until it is certain, that the critical section (ie., the window)
103 #if defined(STDC_HEADERS)
104 static sig_atomic_t alarm_latch = FALSE;
106 /* assume int can be written in one atomic operation on non ANSI-C systems */
107 static int alarm_latch = FALSE;
110 RETSIGTYPE gotsigalrm(sig)
113 signal(sig, gotsigalrm);
117 #endif /* SLEEP_WITH_ALARM */
119 RETSIGTYPE donothing(int sig) {signal(sig, donothing); lastsig = sig;}
122 static void unlockit(int n, void *p)
124 static void unlockit(void)
126 /* must-do actions for exit (but we can't count on being able to do malloc) */
128 if (lockfile && lock_acquired)
133 /* Various EMX-specific definitions */
135 void itimerthread(void* dummy) {
136 if (outlevel >= O_VERBOSE)
137 report(stderr, _("fetchmail: thread sleeping for %d sec.\n"), poll_interval);
139 _sleep2(poll_interval*1000);
140 kill((getpid()), SIGALRM);
146 /* drop SGID kmem privileage until we need it */
147 static void dropprivs(void)
157 if (gr && !strcmp(gr->gr_name, "kmem"))
159 extern void interface_set_gids(gid_t egid, gid_t rgid);
160 interface_set_gids(egid, rgid);
166 int main(int argc, char **argv)
168 int st, bkgd = FALSE;
169 int parsestatus, implicitmode = FALSE;
172 netrc_entry *netrc_list;
173 char *netrc_file, *tmpbuf;
180 envquery(argc, argv);
182 bindtextdomain(PACKAGE, LOCALEDIR);
187 * Note: because we can't initialize reporting before we know whether
188 * syslog is supposed to be on, this message will go to stdout and
189 * be lost when running in background.
191 if (outlevel >= O_VERBOSE)
195 report(stdout, "fetchmail: invoked with");
196 for (i = 0; i < argc; i++)
197 report(stdout, " %s", argv[i]);
198 report(stdout, "\n");
201 #define IDFILE_NAME ".fetchids"
202 run.idfile = (char *) xmalloc(strlen(home)+sizeof(IDFILE_NAME)+1);
203 strcpy(run.idfile, home);
204 strcat(run.idfile, "/");
205 strcat(run.idfile, IDFILE_NAME);
210 * We used to arrange for the lockfile to be removed on exit close
211 * to where the lock was asserted. Now we need to do it here, because
212 * we might have re-executed in background with an existing lockfile
213 * as the result of a changed rcfile (see the code near the execvp(3)
214 * call near the beginning of the polling loop for details). We want
215 * to be sure the lockfile gets nuked on any error exit, basically.
221 on_exit(unlockit, (char *)NULL);
224 if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
229 printf(_("This is fetchmail release %s"), VERSION);
232 #endif /* POP2_ENABLE */
235 #endif /* POP3_ENABLE */
238 #endif /* IMAP_ENABLE */
244 #endif /* RPA_ENABLE */
247 #endif /* NTLM_ENABLE */
250 #endif /* SDPS_ENABLE */
253 #endif /* ETRN_ENABLE */
259 #endif /* OPIE_ENABLE */
262 #endif /* INET6_ENABLE */
265 #endif /* NET_SECURITY */
268 #endif /* HAVE_SOCKS */
271 #endif /* ENABLE_NLS */
275 /* this is an attempt to help remote debugging */
279 /* avoid parsing the config file if all we're doing is killing a daemon */
280 if (!(quitmode && argc == 2))
281 implicitmode = load_params(argc, argv, optind);
283 #if defined(HAVE_SYSLOG)
284 /* logging should be set up early in case we were restarted from exec */
287 openlog(program_name, LOG_PID, LOG_MAIL);
292 report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
294 /* set up to do lock protocol */
295 #define FETCHMAIL_PIDFILE "fetchmail.pid"
297 xalloca(tmpbuf, char *,
298 sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
299 sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
301 xalloca(tmpbuf, char *, strlen(home) + sizeof(FETCHMAIL_PIDFILE) + 2);
302 strcpy(tmpbuf, home);
303 strcat(tmpbuf, "/.");
304 strcat(tmpbuf, FETCHMAIL_PIDFILE);
306 #undef FETCHMAIL_PIDFILE
308 #ifdef HAVE_SETRLIMIT
310 * Before getting passwords, disable core dumps unless -v -d0 mode is on.
311 * Core dumps could otherwise contain passwords to be scavenged by a
314 if (outlevel < O_VERBOSE || run.poll_interval > 0)
316 struct rlimit corelimit;
317 corelimit.rlim_cur = 0;
318 corelimit.rlim_max = 0;
319 setrlimit(RLIMIT_CORE, &corelimit);
321 #endif /* HAVE_SETRLIMIT */
323 #define NETRC_FILE ".netrc"
324 /* parse the ~/.netrc file (if present) for future password lookups. */
325 xalloca(netrc_file, char *, strlen (home) + sizeof(NETRC_FILE) + 1);
326 strcpy (netrc_file, home);
327 strcat (netrc_file, "/");
328 strcat (netrc_file, NETRC_FILE);
329 netrc_list = parse_netrc(netrc_file);
332 /* pick up passwords where we can */
333 for (ctl = querylist; ctl; ctl = ctl->next)
335 if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
337 if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
338 ctl->server.preauthenticate == A_KERBEROS_V5 ||
339 ctl->server.preauthenticate == A_SSH ||
341 ctl->server.protocol == P_IMAP_GSS ||
343 ctl->server.protocol == P_IMAP_K4)
344 /* Server won't care what the password is, but there
345 must be some non-null string here. */
346 ctl->password = ctl->remotename;
351 /* look up the pollname and account in the .netrc file. */
352 p = search_netrc(netrc_list,
353 ctl->server.pollname, ctl->remotename);
354 /* if we find a matching entry with a password, use it */
355 if (p && p->password)
356 ctl->password = xstrdup(p->password);
358 /* otherwise try with "via" name if there is one */
359 else if (ctl->server.via)
361 p = search_netrc(netrc_list,
362 ctl->server.via, ctl->remotename);
363 if (p && p->password)
364 ctl->password = xstrdup(p->password);
370 /* perhaps we just want to check options? */
373 int havercfile = access(rcfile, 0);
375 printf(_("Taking options from command line%s%s\n"),
376 havercfile ? "" : _(" and "),
377 havercfile ? "" : rcfile);
379 if (outlevel >= O_VERBOSE)
380 printf(_("Lockfile at %s\n"), tmpbuf);
382 if (querylist == NULL)
384 _("No mailservers set up -- perhaps %s is missing?\n"),
387 dump_params(&run, querylist, implicitmode);
391 /* dump options as a Python dictionary, for configurator use */
394 dump_config(&run, querylist);
398 /* check for another fetchmail running concurrently */
400 if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
402 report(stderr,_("fetchmail: cannot allocate memory for lock name.\n"));
406 (void) strcpy(lockfile, tmpbuf);
407 if ((lockfp = fopen(lockfile, "r")) != NULL )
409 bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
411 if (kill(pid, 0) == -1) {
412 fprintf(stderr,_("fetchmail: removing stale lockfile\n"));
417 fclose(lockfp); /* not checking should be safe, file mode was "r" */
420 /* if no mail servers listed and nothing in background, we're done */
421 if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
422 (void)fputs(_("fetchmail: no mailservers have been specified.\n"),stderr);
426 /* perhaps user asked us to kill the other fetchmail */
431 fprintf(stderr,_("fetchmail: no other fetchmail is running\n"));
435 else if (kill(pid, SIGTERM) < 0)
437 fprintf(stderr,_("fetchmail: error killing %s fetchmail at %d; bailing out.\n"),
438 bkgd ? _("background") : _("foreground"), pid);
443 fprintf(stderr,_("fetchmail: %s fetchmail at %d killed.\n"),
444 bkgd ? _("background") : _("foreground"), pid);
453 /* another fetchmail is running -- wake it up or die */
459 _("fetchmail: can't check mail while another fetchmail to same host is running.\n"));
462 else if (!implicitmode)
465 _("fetchmail: can't poll specified hosts with another fetchmail running at %d.\n"),
472 _("fetchmail: another foreground fetchmail is running at %d.\n"),
478 /* this test enables re-execing on a changed rcfile */
480 lock_acquired = TRUE;
484 _("fetchmail: can't accept options while a background fetchmail is running.\n"));
488 else if (kill(pid, SIGUSR1) == 0)
491 _("fetchmail: background fetchmail at %d awakened.\n"),
498 * Should never happen -- possible only if a background fetchmail
499 * croaks after the first kill probe above but before the
500 * SIGUSR1/SIGHUP transmission.
503 _("fetchmail: elder sibling at %d died mysteriously.\n"),
505 return(PS_UNDEFINED);
509 /* pick up interactively any passwords we need but don't have */
510 for (ctl = querylist; ctl; ctl = ctl->next)
512 if (ctl->active && !(implicitmode && ctl->server.skip)
513 && ctl->server.protocol != P_ETRN
514 && ctl->server.protocol != P_IMAP_K4
516 && ctl->server.protocol != P_IMAP_GSS
520 char* password_prompt = _("Enter password for %s@%s: ");
522 xalloca(tmpbuf, char *, strlen(password_prompt) +
523 strlen(ctl->remotename) +
524 strlen(ctl->server.pollname) + 1);
525 (void) sprintf(tmpbuf, password_prompt,
526 ctl->remotename, ctl->server.pollname);
527 ctl->password = xstrdup((char *)getpassword(tmpbuf));
532 * Time to initiate the SOCKS library (this is not mandatory: it just
533 * registers the correct application name for logging purpose. If you
534 * have some problem, comment out these lines).
537 SOCKSinit("fetchmail");
538 #endif /* HAVE_SOCKS */
541 * Maybe time to go to demon mode...
543 if (run.poll_interval)
546 daemonize(run.logfile, terminate_run);
547 report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
550 * We'll set up a handler for these when we're sleeping,
551 * but ignore them otherwise so as not to interrupt a poll.
553 signal(SIGUSR1, SIG_IGN);
554 if (run.poll_interval && !getuid())
555 signal(SIGHUP, SIG_IGN);
557 else if (run.logfile && access(run.logfile, F_OK) == 0)
559 freopen(run.logfile, "a", stdout);
560 freopen(run.logfile, "a", stderr);
568 /* beyond here we don't want more than one fetchmail running per user */
570 signal(SIGABRT, terminate_run);
571 signal(SIGINT, terminate_run);
572 signal(SIGTERM, terminate_run);
573 signal(SIGALRM, terminate_run);
574 signal(SIGPIPE, terminate_run);
575 signal(SIGQUIT, terminate_run);
577 /* here's the exclusion lock */
579 #define O_SYNC 0 /* use it if we have it */
581 if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
583 sprintf(tmpbuf,"%d", getpid());
584 write(st, tmpbuf, strlen(tmpbuf));
585 if (run.poll_interval)
587 sprintf(tmpbuf," %d", run.poll_interval);
588 write(st, tmpbuf, strlen(tmpbuf));
590 close(st); /* should be safe, fd was opened with O_SYNC */
591 lock_acquired = TRUE;
595 * Query all hosts. If there's only one, the error return will
596 * reflect the status of that transaction.
600 * Check to see if the rcfile has been touched. If so,
601 * re-exec so the file will be reread. Doing it this way
602 * avoids all the complications of trying to deallocate the
603 * in-core control structures -- and the potential memory
608 if (stat(rcfile, &rcstat) == -1)
612 _("couldn't time-check %s (error %d)\n"),
615 else if (rcstat.st_mtime > parsetime)
617 report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
618 execvp("fetchmail", argv);
619 report(stderr, _("attempt to re-exec fetchmail failed\n"));
622 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
624 * This was an efficiency hack that backfired. The theory
625 * was that using TCP/IP for DNS queries would get us better
626 * reliability and shave off some per-UDP-packet costs.
627 * Unfortunately it interacted badly with diald, which effectively
628 * filters out DNS queries over TCP/IP for reasons having to do
629 * with some obscure kernel problem involving bootstrapping of
630 * dynamically-addressed links. I don't understand this mess
631 * and don't want to, so it's "See ya!" to this hack.
633 sethostent(TRUE); /* use TCP/IP for mailserver queries */
634 #endif /* HAVE_RES_SEARCH */
637 for (ctl = querylist; ctl; ctl = ctl->next)
639 if (ctl->active && !(implicitmode && ctl->server.skip))
644 _("poll of %s skipped (failed authentication or too many timeouts)\n"),
645 ctl->server.pollname);
649 /* check skip interval first so that it counts all polls */
650 if (run.poll_interval && ctl->server.interval)
652 if (ctl->server.poll_count++ % ctl->server.interval)
654 if (outlevel >= O_VERBOSE)
656 _("interval not reached, not querying %s\n"),
657 ctl->server.pollname);
662 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
663 /* interface_approve() does its own error logging */
664 if (!interface_approve(&ctl->server))
666 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
668 querystatus = query_host(ctl);
673 #endif /* POP3_ENABLE */
675 if (querystatus == PS_SUCCESS)
677 else if (!check_only &&
678 ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
682 report(stdout, "Query status=SUCCESS\n"); break ;
684 report(stdout, "Query status=NOMAIL\n"); break ;
686 report(stdout, "Query status=SOCKET\n"); break ;
688 report(stdout, "Query status=AUTHFAIL\n"); break ;
690 report(stdout, "Query status=PROTOCOL\n"); break ;
692 report(stdout, "Query status=SYNTAX\n"); break ;
694 report(stdout, "Query status=IOERR\n"); break ;
696 report(stdout, "Query status=ERROR\n"); break ;
698 report(stdout, "Query status=EXCLUDE\n"); break ;
700 report(stdout, "Query status=LOCKBUSY\n"); break ;
702 report(stdout, "Query status=SMTP\n"); break ;
704 report(stdout, "Query status=DNS\n"); break ;
706 report(stdout, "Query status=BSMTP\n"); break ;
708 report(stdout, "Query status=MAXFETCH\n"); break ;
710 report(stdout, "Query status=UNDEFINED\n"); break ;
712 report(stdout, "Query status=TRANSIENT\n"); break ;
714 report(stdout, "Query status=REFUSED\n"); break ;
716 report(stdout, "Query status=RETAINED\n"); break ;
718 report(stdout, "Query status=TRUNCATED\n"); break ;
720 report(stdout, _("Query status=%d\n"), querystatus); break;
723 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
724 if (ctl->server.monitor)
727 * Allow some time for the link to quiesce. One
728 * second is usually sufficient, three is safe.
729 * Note: this delay is important - don't remove!
732 interface_note_activity(&ctl->server);
734 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
738 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
739 endhostent(); /* release TCP/IP connection to nameserver */
740 #endif /* HAVE_RES_SEARCH */
742 /* close connections cleanly */
746 * OK, we've polled. Now sleep.
748 if (run.poll_interval)
751 * Because passwords can expire, it may happen that *all*
752 * hosts are now out of the loop due to authfail
753 * conditions. If this happens daemon-mode fetchmail
754 * should softly and silently vanish away, rather than
755 * spinning uselessly.
759 for (ctl = querylist; ctl; ctl = ctl->next)
760 if (ctl->active && !(implicitmode && ctl->server.skip))
765 report(stderr, _("All connections are wedged. Exiting.\n"));
766 /* FIXME: someday, send notification mail */
770 if (outlevel >= O_VERBOSE)
772 _("fetchmail: sleeping at %s\n"), rfc822timestamp());
775 * With this simple hack, we make it possible for a foreground
776 * fetchmail to wake up one in daemon mode. What we want is the
777 * side effect of interrupting any sleep that may be going on,
778 * forcing fetchmail to re-poll its hosts. The second line is
779 * for people who think all system daemons wake up on SIGHUP.
781 signal(SIGUSR1, donothing);
783 signal(SIGHUP, donothing);
785 /* time for a pause in the action... */
788 #ifdef SLEEP_WITH_ALARM /* not normally on */
790 * We can't use sleep(3) here because we need an alarm(3)
791 * equivalent in order to implement server nonresponse timeout.
792 * We'll just assume setitimer(2) is available since fetchmail
793 * has to have a BSDoid socket layer to work at all.
796 * This code stopped working under glibc-2, apparently due
797 * to the change in signal(2) semantics. (The siginterrupt
798 * line, added later, should fix this problem.) John Stracke
799 * <francis@netscape.com> wrote:
801 * The problem seems to be that, after hitting the interval
802 * timer while talking to the server, the process no longer
803 * responds to SIGALRM. I put in printf()s to see when it
804 * reached the pause() for the poll interval, and I checked
805 * the return from setitimer(), and everything seemed to be
806 * working fine, except that the pause() just ignored SIGALRM.
807 * I thought maybe the itimer wasn't being fired, so I hit
808 * it with a SIGALRM from the command line, and it ignored
809 * that, too. SIGUSR1 woke it up just fine, and it proceeded
810 * to repoll--but, when the dummy server didn't respond, it
811 * never timed out, and SIGALRM wouldn't make it.
813 * (continued below...)
815 struct itimerval ntimeout;
817 ntimeout.it_interval.tv_sec = 5; /* repeat alarm every 5 secs */
818 ntimeout.it_interval.tv_usec = 0;
819 ntimeout.it_value.tv_sec = run.poll_interval;
820 ntimeout.it_value.tv_usec = 0;
822 siginterrupt(SIGALRM, 1);
824 signal(SIGALRM, gotsigalrm); /* first trap signals */
825 setitimer(ITIMER_REAL,&ntimeout,NULL); /* then start timer */
826 /* there is a very small window between the next two lines */
827 /* which could result in a deadlock. But this will now be */
828 /* caught by periodical alarms (see it_interval) */
832 ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0;
833 ntimeout.it_value.tv_sec = ntimeout.it_value.tv_usec = 0;
834 setitimer(ITIMER_REAL,&ntimeout,NULL); /* now stop timer */
835 signal(SIGALRM, SIG_IGN);
838 * So the workaround I used is to make it sleep by using
839 * select() instead of setitimer()/pause(). select() is
840 * perfectly happy being called with a timeout and
841 * no file descriptors; it just sleeps until it hits the
842 * timeout. The only concern I had was that it might
843 * implement its timeout with SIGALRM--there are some
844 * Unices where this is done, because select() is a library
845 * function--but apparently not.
847 struct timeval timeout;
849 timeout.tv_sec = run.poll_interval;
853 select(0,0,0,0, &timeout);
854 } while (lastsig == SIGCHLD);
858 signal(SIGALRM, gotsigalrm);
859 _beginthread(itimerthread, NULL, 32768, NULL);
860 /* see similar code above */
863 signal(SIGALRM, SIG_IGN);
865 if (lastsig == SIGUSR1
866 || ((run.poll_interval && !getuid()) && lastsig == SIGHUP))
868 #ifdef SYS_SIGLIST_DECLARED
870 _("awakened by %s\n"), sys_siglist[lastsig]);
873 _("awakened by signal %d\n"), lastsig);
875 /* received a wakeup - unwedge all servers in case */
876 /* the problem has been manually repaired */
877 for (ctl = querylist; ctl; ctl = ctl->next)
882 /* now lock out interrupts again */
883 signal(SIGUSR1, SIG_IGN);
885 signal(SIGHUP, SIG_IGN);
887 if (outlevel >= O_VERBOSE)
888 report(stdout, _("awakened at %s\n"), rfc822timestamp());
893 if (outlevel >= O_VERBOSE)
894 report(stdout, _("normal termination, status %d\n"),
895 successes ? PS_SUCCESS : querystatus);
898 exit(successes ? PS_SUCCESS : querystatus);
901 static void optmerge(struct query *h2, struct query *h1, int force)
902 /* merge two options records */
905 * If force is off, modify h2 fields only when they're empty (treat h1
906 * as defaults). If force is on, modify each h2 field whenever h1
907 * is nonempty (treat h1 as an override).
909 #define LIST_MERGE(dstl, srcl) if (force ? !!srcl : !dstl) \
910 free_str_list(&dstl), \
911 append_str_list(&dstl, &srcl)
912 LIST_MERGE(h2->server.localdomains, h1->server.localdomains);
913 LIST_MERGE(h2->localnames, h1->localnames);
914 LIST_MERGE(h2->mailboxes, h1->mailboxes);
915 LIST_MERGE(h2->smtphunt, h1->smtphunt);
916 LIST_MERGE(h2->antispam, h1->antispam);
919 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
920 FLAG_MERGE(server.via);
921 FLAG_MERGE(server.protocol);
923 FLAG_MERGE(server.service);
924 FLAG_MERGE(server.netsec);
925 #else /* INET6_ENABLE */
926 FLAG_MERGE(server.port);
927 #endif /* INET6_ENABLE */
928 FLAG_MERGE(server.interval);
929 FLAG_MERGE(server.preauthenticate);
930 FLAG_MERGE(server.timeout);
931 FLAG_MERGE(server.envelope);
932 FLAG_MERGE(server.envskip);
933 FLAG_MERGE(server.qvirtual);
934 FLAG_MERGE(server.skip);
935 FLAG_MERGE(server.dns);
936 FLAG_MERGE(server.checkalias);
937 FLAG_MERGE(server.uidl);
939 #if defined(linux) || defined(__FreeBSD__)
940 FLAG_MERGE(server.interface);
941 FLAG_MERGE(server.monitor);
942 FLAG_MERGE(server.interface_pair);
943 #endif /* linux || defined(__FreeBSD__) */
945 FLAG_MERGE(server.plugin);
946 FLAG_MERGE(server.plugout);
948 FLAG_MERGE(wildcard);
949 FLAG_MERGE(remotename);
950 FLAG_MERGE(password);
953 FLAG_MERGE(listener);
954 FLAG_MERGE(smtpaddress);
955 FLAG_MERGE(preconnect);
956 FLAG_MERGE(postconnect);
960 FLAG_MERGE(fetchall);
964 FLAG_MERGE(pass8bits);
965 FLAG_MERGE(dropstatus);
966 FLAG_MERGE(mimedecode);
968 FLAG_MERGE(warnings);
969 FLAG_MERGE(fetchlimit);
970 FLAG_MERGE(batchlimit);
978 FLAG_MERGE(properties);
982 static int load_params(int argc, char **argv, int optind)
984 int implicitmode, st;
986 struct query def_opts, *ctl;
989 run.bouncemail = TRUE;
991 memset(&def_opts, '\0', sizeof(struct query));
992 def_opts.smtp_socket = -1;
993 def_opts.smtpaddress = (char *)0;
994 #define ANTISPAM(n) save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
995 ANTISPAM(571); /* sendmail */
996 ANTISPAM(550); /* old exim */
997 ANTISPAM(501); /* new exim */
998 ANTISPAM(554); /* Postfix */
1001 def_opts.server.protocol = P_AUTO;
1002 def_opts.server.timeout = CLIENT_TIMEOUT;
1003 def_opts.warnings = WARNING_INTERVAL;
1004 def_opts.remotename = user;
1005 def_opts.listener = SMTP_MODE;
1007 /* note the parse time, so we can pick up on modifications */
1008 parsetime = 0; /* foil compiler warnings */
1009 if (stat(rcfile, &rcstat) != -1)
1010 parsetime = rcstat.st_mtime;
1011 else if (errno != ENOENT)
1012 report(stderr, _("couldn't time-check the run-control file\n"));
1014 /* this builds the host list */
1015 if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
1017 * FIXME: someday, send notification mail here if backgrounded.
1018 * Right now, that can happen if the user changes the rcfile
1019 * while the fetchmail is running in background. Do similarly
1020 * for the other exit() calls in this function.
1024 if ((implicitmode = (optind >= argc)))
1026 for (ctl = querylist; ctl; ctl = ctl->next)
1030 for (; optind < argc; optind++)
1032 flag predeclared = FALSE;
1035 * If hostname corresponds to a host known from the rc file,
1036 * simply declare it active. Otherwise synthesize a host
1037 * record from command line and defaults
1039 for (ctl = querylist; ctl; ctl = ctl->next)
1040 if (!strcmp(ctl->server.pollname, argv[optind])
1041 || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
1043 /* Is this correct? */
1045 fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
1053 * Allocate and link record without copying in
1054 * command-line args; we'll do that with the optmerge
1057 ctl = hostalloc((struct query *)NULL);
1059 ctl->server.pollname = xstrdup(argv[optind]);
1061 ctl->server.lead_server = (struct hostdata *)NULL;
1066 * If there's a defaults record, merge it and lose it.
1068 if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
1070 for (ctl = querylist->next; ctl; ctl = ctl->next)
1071 optmerge(ctl, querylist, FALSE);
1072 querylist = querylist->next;
1075 /* don't allow a defaults record after the first */
1076 for (ctl = querylist; ctl; ctl = ctl->next)
1077 if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
1080 /* use localhost if we never fetch the FQDN of this host */
1081 fetchmailhost = "localhost";
1083 /* here's where we override globals */
1084 if (cmd_run.logfile)
1085 run.logfile = cmd_run.logfile;
1087 run.idfile = cmd_run.idfile;
1088 /* do this before the keep/fetchall test below, otherwise -d0 may fail */
1089 if (cmd_run.poll_interval >= 0)
1090 run.poll_interval = cmd_run.poll_interval;
1091 if (cmd_run.invisible)
1092 run.invisible = cmd_run.invisible;
1093 if (cmd_run.use_syslog)
1094 run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
1095 if (cmd_run.postmaster)
1096 run.postmaster = cmd_run.postmaster;
1097 if (cmd_run.bouncemail)
1098 run.bouncemail = cmd_run.bouncemail;
1100 /* check and daemon options are not compatible */
1101 if (check_only && run.poll_interval)
1102 run.poll_interval = 0;
1104 /* merge in wired defaults, do sanity checks and prepare internal fields */
1105 for (ctl = querylist; ctl; ctl = ctl->next)
1107 ctl->wedged = FALSE;
1109 if (configdump || (ctl->active && !(implicitmode && ctl->server.skip)))
1111 /* merge in defaults */
1112 optmerge(ctl, &def_opts, FALSE);
1114 /* force command-line options */
1115 optmerge(ctl, &cmd_opts, TRUE);
1117 /* this code enables flags to be turned off */
1118 #define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
1120 else if (flag == FLAG_FALSE)\
1124 DEFAULT(ctl->keep, FALSE);
1125 DEFAULT(ctl->fetchall, FALSE);
1126 DEFAULT(ctl->flush, FALSE);
1127 DEFAULT(ctl->rewrite, TRUE);
1128 DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
1129 DEFAULT(ctl->forcecr, FALSE);
1130 DEFAULT(ctl->pass8bits, FALSE);
1131 DEFAULT(ctl->dropstatus, FALSE);
1132 DEFAULT(ctl->mimedecode, FALSE);
1133 DEFAULT(ctl->server.dns, TRUE);
1134 DEFAULT(ctl->server.uidl, FALSE);
1136 DEFAULT(ctl->use_ssl, FALSE);
1138 DEFAULT(ctl->server.checkalias, FALSE);
1142 * DNS support is required for some protocols. We used to
1143 * do this unconditionally, but it made fetchmail excessively
1144 * vulnerable to misconfigured DNS setups.
1146 * If we're using ETRN, the smtp hunt list is the list of
1147 * systems we're polling on behalf of; these have to be
1148 * fully-qualified domain names. The default for this list
1149 * should be the FQDN of localhost.
1151 * If we're using Kerberos for authentication, we need
1152 * the FQDN in order to generate capability keys.
1154 if (ctl->server.protocol == P_ETRN
1155 || ctl->server.preauthenticate == A_KERBEROS_V4
1156 || ctl->server.preauthenticate == A_KERBEROS_V5)
1157 if (strcmp(fetchmailhost, "localhost") == 0)
1158 fetchmailhost = host_fqdn();
1161 * Make sure we have a nonempty host list to forward to.
1164 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1166 /* if `user' doesn't name a real local user, try to run as root */
1167 if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1170 ctl->uid = pw->pw_uid; /* for local delivery via MDA */
1171 if (!ctl->localnames) /* for local delivery via SMTP */
1172 save_str_pair(&ctl->localnames, user, NULL);
1174 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1175 /* can't handle multidrop mailboxes unless we can do DNS lookups */
1176 if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1178 ctl->server.dns = FALSE;
1179 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1181 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1185 * Compute the true name of the mailserver host.
1186 * There are two clashing cases here:
1188 * (1) The poll name is a label, possibly on one of several
1189 * poll configurations for the same host. In this case
1190 * the `via' option will be present and give the true name.
1192 * (2) The poll name is the true one, the via name is
1193 * localhost. This is going to be typical for ssh-using
1196 * We're going to assume the via name is true unless it's
1199 if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1200 ctl->server.queryname = xstrdup(ctl->server.via);
1202 ctl->server.queryname = xstrdup(ctl->server.pollname);
1205 /* If either the pollname or vianame are "hesiod" we want to
1206 lookup the user's hesiod pobox host */
1208 if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1209 struct hes_postoffice *hes_p;
1210 hes_p = hes_getmailhost(ctl->remotename);
1211 if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1212 free(ctl->server.queryname);
1213 ctl->server.queryname = xstrdup(hes_p->po_host);
1214 if (ctl->server.via)
1215 free(ctl->server.via);
1216 ctl->server.via = xstrdup(hes_p->po_host);
1219 _("couldn't find HESIOD pobox for %s\n"),
1226 * We may have to canonicalize the server truename for later use.
1227 * Do this just once for each lead server, if necessary, in order
1228 * to minimize DNS round trips.
1230 if (ctl->server.lead_server)
1232 char *leadname = ctl->server.lead_server->truename;
1234 /* prevent core dump from ill-formed or duplicate entry */
1238 _("Lead server has no name.\n"));
1242 ctl->server.truename = xstrdup(leadname);
1244 #ifdef HAVE_GETHOSTBYNAME
1245 else if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1246 ctl->server.preauthenticate==A_KERBEROS_V5 ||
1247 (ctl->server.dns && MULTIDROP(ctl)))
1249 struct hostent *namerec;
1251 /* compute the canonical name of the host */
1253 namerec = gethostbyname(ctl->server.queryname);
1254 if (namerec == (struct hostent *)NULL)
1257 _("couldn't find canonical DNS name of %s\n"),
1258 ctl->server.pollname);
1262 ctl->server.truename=xstrdup((char *)namerec->h_name);
1264 #endif /* HAVE_GETHOSTBYNAME */
1266 ctl->server.truename = xstrdup(ctl->server.queryname);
1268 /* if no folders were specified, set up the null one as default */
1269 if (!ctl->mailboxes)
1270 save_str(&ctl->mailboxes, (char *)NULL, 0);
1272 /* maybe user overrode timeout on command line? */
1273 if (ctl->server.timeout == -1)
1274 ctl->server.timeout = CLIENT_TIMEOUT;
1278 if (ctl->server.port < 0)
1280 (void) fprintf(stderr,
1281 _("%s configuration invalid, port number cannot be negative\n"),
1282 ctl->server.pollname);
1285 if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1287 (void) fprintf(stderr,
1288 _("%s configuration invalid, RPOP requires a privileged port\n"),
1289 ctl->server.pollname);
1292 if (ctl->listener == LMTP_MODE)
1296 for (idp = ctl->smtphunt; idp; idp = idp->next)
1300 if (!(cp = strrchr(idp->id, '/')) ||
1301 (atoi(++cp) == SMTP_PORT))
1303 (void) fprintf(stderr,
1304 _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1305 ctl->server.pollname);
1310 #endif /* !INET6_ENABLE */
1313 * "I beg to you, have mercy on the week minds like myself."
1314 * wrote Pehr Anderson. Your petition is granted.
1316 if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1318 (void) fprintf(stderr,
1319 _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1326 /* initialize UID handling */
1327 if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1330 initialize_saved_lists(querylist, run.idfile);
1331 #endif /* POP3_ENABLE */
1334 * If the user didn't set a last-resort user to get misaddressed
1335 * multidrop mail, set an appropriate default here.
1337 if (!run.postmaster)
1339 if (getuid()) /* ordinary user */
1340 run.postmaster = user;
1342 run.postmaster = "postmaster";
1345 return(implicitmode);
1348 static void terminate_poll(int sig)
1349 /* to be executed at the end of a poll cycle */
1352 * Close all SMTP delivery sockets. For optimum performance
1353 * we'd like to hold them open til end of run, but (1) this
1354 * loses if our poll interval is longer than the MTA's inactivity
1355 * timeout, and (2) some MTAs (like smail) don't deliver after
1356 * each message, but rather queue up mail and wait to actually
1357 * deliver it until the input socket is closed.
1359 * Sending SMTP QUIT on signal is theoretically nice, but led to a
1360 * subtle bug. If fetchmail was terminated by signal while it was
1361 * shipping message text, it would hang forever waiting for a
1362 * command acknowledge. In theory we could enable the QUIT
1363 * only outside of the message send. In practice, we don't
1364 * care. All mailservers hang up on a dropped TCP/IP connection
1369 report(stdout, _("terminated with signal %d\n"), sig);
1374 /* terminate all SMTP connections cleanly */
1375 for (ctl = querylist; ctl; ctl = ctl->next)
1376 if (ctl->smtp_socket != -1)
1378 SMTP_quit(ctl->smtp_socket);
1379 SockClose(ctl->smtp_socket);
1380 ctl->smtp_socket = -1;
1386 * Update UID information at end of each poll, rather than at end
1387 * of run, because that way we don't lose all UIDL information since
1388 * the beginning of time if fetchmail crashes.
1391 write_saved_lists(querylist, run.idfile);
1392 #endif /* POP3_ENABLE */
1395 static void terminate_run(int sig)
1396 /* to be executed on normal or signal-induced termination */
1400 terminate_poll(sig);
1403 * Craig Metz, the RFC1938 one-time-password guy, points out:
1404 * "Remember that most kernels don't zero pages before handing them to the
1405 * next process and many kernels share pages between user and kernel space.
1406 * You'd be very surprised what you can find from a short program to do a
1407 * malloc() and then dump the contents of the pages you got. By zeroing
1408 * the secrets at end of run (earlier if you can), you make sure the next
1409 * guy can't get the password/pass phrase."
1411 * Right you are, Craig!
1413 for (ctl = querylist; ctl; ctl = ctl->next)
1415 memset(ctl->password, '\0', strlen(ctl->password));
1417 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1421 exit(successes ? PS_SUCCESS : querystatus);
1425 * Sequence of protocols to try when autoprobing, most capable to least.
1427 static const int autoprobe[] =
1431 #endif /* IMAP_ENABLE */
1434 #endif /* POP3_ENABLE */
1437 #endif /* POP2_ENABLE */
1440 static int query_host(struct query *ctl)
1441 /* perform fetch transaction with single host */
1446 * If we're syslogging the progress messages are automatically timestamped.
1447 * Force timestamping if we're going to a logfile.
1449 if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1451 report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1453 ctl->server.pollname,
1454 showproto(ctl->server.protocol),
1457 switch (ctl->server.protocol) {
1459 for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1461 ctl->server.protocol = autoprobe[i];
1462 if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1465 ctl->server.protocol = P_AUTO;
1469 return(doPOP2(ctl));
1471 report(stderr, _("POP2 support is not configured.\n"));
1472 return(PS_PROTOCOL);
1473 #endif /* POP2_ENABLE */
1479 return(doPOP3(ctl));
1481 report(stderr, _("POP3 support is not configured.\n"));
1482 return(PS_PROTOCOL);
1483 #endif /* POP3_ENABLE */
1487 case P_IMAP_CRAM_MD5:
1493 return(doIMAP(ctl));
1495 report(stderr, _("IMAP support is not configured.\n"));
1496 return(PS_PROTOCOL);
1497 #endif /* IMAP_ENABLE */
1500 report(stderr, _("ETRN support is not configured.\n"));
1501 return(PS_PROTOCOL);
1503 #ifdef HAVE_GETHOSTBYNAME
1504 return(doETRN(ctl));
1506 report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1507 return(PS_PROTOCOL);
1508 #endif /* HAVE_GETHOSTBYNAME */
1509 #endif /* ETRN_ENABLE */
1511 report(stderr, _("unsupported protocol selected.\n"));
1512 return(PS_PROTOCOL);
1516 static void dump_params (struct runctl *runp,
1517 struct query *querylist, flag implicit)
1518 /* display query parameters in English */
1522 if (runp->poll_interval)
1523 printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1525 printf(_("Logfile is %s\n"), runp->logfile);
1526 if (strcmp(runp->idfile, IDFILE_NAME))
1527 printf(_("Idfile is %s\n"), runp->idfile);
1528 #if defined(HAVE_SYSLOG)
1529 if (runp->use_syslog)
1530 printf(_("Progress messages will be logged via syslog\n"));
1532 if (runp->invisible)
1533 printf(_("Fetchmail will masquerade and will not generate Received\n"));
1534 if (runp->postmaster)
1535 printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1538 if (!runp->bouncemail)
1539 printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1540 else if (outlevel >= O_VERBOSE)
1541 printf(_("Fetchmail will direct error mail to the sender.\n"));
1543 for (ctl = querylist; ctl; ctl = ctl->next)
1545 if (!ctl->active || (implicit && ctl->server.skip))
1548 printf(_("Options for retrieving from %s@%s:\n"),
1549 ctl->remotename, visbuf(ctl->server.pollname));
1551 if (ctl->server.via && (ctl->server.protocol != P_ETRN))
1552 printf(_(" Mail will be retrieved via %s\n"), ctl->server.via);
1554 if (ctl->server.interval)
1555 printf(_(" Poll of this server will occur every %d intervals.\n"),
1556 ctl->server.interval);
1557 if (ctl->server.truename)
1558 printf(_(" True name of server is %s.\n"), ctl->server.truename);
1559 if (ctl->server.skip || outlevel >= O_VERBOSE)
1560 printf(_(" This host %s be queried when no host is specified.\n"),
1561 ctl->server.skip ? _("will not") : _("will"));
1563 * Don't poll for password when there is one or when using the ETRN
1564 * or IMAP-GSS protocol
1566 /* ETRN, IMAP_GSS, and IMAP_K4 do not need a password, so skip this */
1567 if ( (ctl->server.protocol != P_ETRN)
1569 && (ctl->server.protocol != P_IMAP_GSS)
1571 && (ctl->server.protocol != P_IMAP_K4) ) {
1573 printf(_(" Password will be prompted for.\n"));
1574 else if (outlevel >= O_VERBOSE)
1576 if (ctl->server.protocol == P_APOP)
1577 printf(_(" APOP secret = \"%s\".\n"),
1578 visbuf(ctl->password));
1579 else if (ctl->server.protocol == P_RPOP)
1580 printf(_(" RPOP id = \"%s\".\n"),
1581 visbuf(ctl->password));
1583 printf(_(" Password = \"%s\".\n"),
1584 visbuf(ctl->password));
1588 if (ctl->server.protocol == P_POP3
1590 && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1591 #else /* INET6_ENABLE */
1592 && ctl->server.port == KPOP_PORT
1593 #endif /* INET6_ENABLE */
1594 && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1595 ctl->server.preauthenticate == A_KERBEROS_V5))
1596 printf(_(" Protocol is KPOP with Kerberos %s authentication"),
1597 ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1599 printf(_(" Protocol is %s"), showproto(ctl->server.protocol));
1601 if (ctl->server.service)
1602 printf(_(" (using service %s)"), ctl->server.service);
1603 if (ctl->server.netsec)
1604 printf(_(" (using network security options %s)"), ctl->server.netsec);
1605 #else /* INET6_ENABLE */
1606 if (ctl->server.port)
1607 printf(_(" (using port %d)"), ctl->server.port);
1608 #endif /* INET6_ENABLE */
1609 else if (outlevel >= O_VERBOSE)
1610 printf(_(" (using default port)"));
1611 if (ctl->server.uidl && (ctl->server.protocol != P_ETRN))
1612 printf(_(" (forcing UIDL use)"));
1615 if (ctl->server.preauthenticate == A_KERBEROS_V4)
1616 printf(_(" Kerberos V4 preauthentication enabled.\n"));
1617 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
1618 printf(_(" Kerberos V5 preauthentication enabled.\n"));
1619 else if (ctl->server.preauthenticate == A_SSH)
1620 printf(_(" End-to-end encryption assumed.\n"));
1623 printf(" SSL encrypted sessions enabled.\n");
1625 if (ctl->server.timeout > 0)
1626 printf(_(" Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1627 if (ctl->server.timeout == CLIENT_TIMEOUT)
1628 printf(_(" (default).\n"));
1632 if (ctl->server.protocol != P_ETRN) {
1633 if (!ctl->mailboxes->id)
1634 printf(_(" Default mailbox selected.\n"));
1639 printf(_(" Selected mailboxes are:"));
1640 for (idp = ctl->mailboxes; idp; idp = idp->next)
1641 printf(" %s", idp->id);
1644 printf(_(" %s messages will be retrieved (--all %s).\n"),
1645 ctl->fetchall ? _("All") : _("Only new"),
1646 ctl->fetchall ? "on" : "off");
1647 printf(_(" Fetched messages %s be kept on the server (--keep %s).\n"),
1648 ctl->keep ? _("will") : _("will not"),
1649 ctl->keep ? "on" : "off");
1650 printf(_(" Old messages %s be flushed before message retrieval (--flush %s).\n"),
1651 ctl->flush ? _("will") : _("will not"),
1652 ctl->flush ? "on" : "off");
1653 printf(_(" Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1654 ctl->rewrite ? _("enabled") : _("disabled"),
1655 ctl->rewrite ? "off" : "on");
1656 printf(_(" Carriage-return stripping is %s (stripcr %s).\n"),
1657 ctl->stripcr ? _("enabled") : _("disabled"),
1658 ctl->stripcr ? "on" : "off");
1659 printf(_(" Carriage-return forcing is %s (forcecr %s).\n"),
1660 ctl->forcecr ? _("enabled") : _("disabled"),
1661 ctl->forcecr ? "on" : "off");
1662 printf(_(" Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1663 ctl->pass8bits ? _("disabled") : _("enabled"),
1664 ctl->pass8bits ? "on" : "off");
1665 printf(_(" MIME decoding is %s (mimedecode %s).\n"),
1666 ctl->mimedecode ? _("enabled") : _("disabled"),
1667 ctl->mimedecode ? "on" : "off");
1668 printf(_(" Nonempty Status lines will be %s (dropstatus %s)\n"),
1669 ctl->dropstatus ? _("discarded") : _("kept"),
1670 ctl->dropstatus ? "on" : "off");
1671 if (NUM_NONZERO(ctl->limit))
1673 if (NUM_NONZERO(ctl->limit))
1674 printf(_(" Message size limit is %d octets (--limit %d).\n"),
1675 ctl->limit, ctl->limit);
1676 else if (outlevel >= O_VERBOSE)
1677 printf(_(" No message size limit (--limit 0).\n"));
1678 if (run.poll_interval > 0)
1679 printf(_(" Message size warning interval is %d seconds (--warnings %d).\n"),
1680 ctl->warnings, ctl->warnings);
1681 else if (outlevel >= O_VERBOSE)
1682 printf(_(" Size warnings on every poll (--warnings 0).\n"));
1684 if (NUM_NONZERO(ctl->fetchlimit))
1685 printf(_(" Received-message limit is %d (--fetchlimit %d).\n"),
1686 ctl->fetchlimit, ctl->fetchlimit);
1687 else if (outlevel >= O_VERBOSE)
1688 printf(_(" No received-message limit (--fetchlimit 0).\n"));
1689 if (NUM_NONZERO(ctl->batchlimit))
1690 printf(_(" SMTP message batch limit is %d.\n"), ctl->batchlimit);
1691 else if (outlevel >= O_VERBOSE)
1692 printf(_(" No SMTP message batch limit (--batchlimit 0).\n"));
1693 if (ctl->server.protocol == P_IMAP)
1695 if (NUM_NONZERO(ctl->expunge))
1696 printf(_(" Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1697 else if (outlevel >= O_VERBOSE)
1698 printf(_(" No forced expunges (--expunge 0).\n"));
1702 printf(_(" Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1703 else if (ctl->mda && (ctl->server.protocol != P_ETRN))
1704 printf(_(" Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1709 printf(_(" Messages will be %cMTP-forwarded to:"), ctl->listener);
1710 for (idp = ctl->smtphunt; idp; idp = idp->next)
1712 printf(" %s", idp->id);
1713 if (!idp->val.status.mark)
1714 printf(_(" (default)"));
1717 if (ctl->smtpaddress)
1718 printf(_(" Host part of MAIL FROM line will be %s\n"),
1721 if (ctl->server.protocol != P_ETRN)
1723 if (ctl->antispam != (struct idlist *)NULL)
1727 printf(_(" Recognized listener spam block responses are:"));
1728 for (idp = ctl->antispam; idp; idp = idp->next)
1729 printf(" %d", idp->val.status.num);
1732 else if (outlevel >= O_VERBOSE)
1733 printf(_(" Spam-blocking disabled\n"));
1735 if (ctl->preconnect)
1736 printf(_(" Server connection will be brought up with \"%s\".\n"),
1737 visbuf(ctl->preconnect));
1738 else if (outlevel >= O_VERBOSE)
1739 printf(_(" No pre-connection command.\n"));
1740 if (ctl->postconnect)
1741 printf(_(" Server connection will be taken down with \"%s\".\n"),
1742 visbuf(ctl->postconnect));
1743 else if (outlevel >= O_VERBOSE)
1744 printf(_(" No post-connection command.\n"));
1745 if (ctl->server.protocol != P_ETRN) {
1746 if (!ctl->localnames)
1747 printf(_(" No localnames declared for this host.\n"));
1753 for (idp = ctl->localnames; idp; idp = idp->next)
1756 if (count > 1 || ctl->wildcard)
1757 printf(_(" Multi-drop mode: "));
1759 printf(_(" Single-drop mode: "));
1761 printf(_("%d local name(s) recognized.\n"), count);
1762 if (outlevel >= O_VERBOSE)
1764 for (idp = ctl->localnames; idp; idp = idp->next)
1766 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1768 printf("\t%s\n", idp->id);
1770 fputs("\t*\n", stdout);
1773 if (count > 1 || ctl->wildcard)
1775 printf(_(" DNS lookup for multidrop addresses is %s.\n"),
1776 ctl->server.dns ? _("enabled") : _("disabled"));
1777 if (ctl->server.dns)
1779 printf(_(" Server aliases will be compared with multidrop addresses by "));
1780 if (ctl->server.checkalias)
1781 printf(_("IP address.\n"));
1783 printf(_("name.\n"));
1785 if (ctl->server.envelope == STRING_DISABLED)
1786 printf(_(" Envelope-address routing is disabled\n"));
1789 printf(_(" Envelope header is assumed to be: %s\n"),
1790 ctl->server.envelope ? ctl->server.envelope:_("Received"));
1791 if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1792 printf(_(" Number of envelope header to be parsed: %d\n"),
1793 ctl->server.envskip);
1794 if (ctl->server.qvirtual)
1795 printf(_(" Prefix %s will be removed from user id\n"),
1796 ctl->server.qvirtual);
1797 else if (outlevel >= O_VERBOSE)
1798 printf(_(" No prefix stripping\n"));
1801 if (ctl->server.akalist)
1805 printf(_(" Predeclared mailserver aliases:"));
1806 for (idp = ctl->server.akalist; idp; idp = idp->next)
1807 printf(" %s", idp->id);
1810 if (ctl->server.localdomains)
1814 printf(_(" Local domains:"));
1815 for (idp = ctl->server.localdomains; idp; idp = idp->next)
1816 printf(" %s", idp->id);
1822 #if defined(linux) || defined(__FreeBSD__)
1823 if (ctl->server.interface)
1824 printf(_(" Connection must be through interface %s.\n"), ctl->server.interface);
1825 else if (outlevel >= O_VERBOSE)
1826 printf(_(" No interface requirement specified.\n"));
1827 if (ctl->server.monitor)
1828 printf(_(" Polling loop will monitor %s.\n"), ctl->server.monitor);
1829 else if (outlevel >= O_VERBOSE)
1830 printf(_(" No monitor interface specified.\n"));
1833 if (ctl->server.plugin)
1834 printf(_(" Server connections will be mode via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1835 else if (outlevel >= O_VERBOSE)
1836 printf(_(" No plugin command specified.\n"));
1837 if (ctl->server.plugout)
1838 printf(_(" Listener connections will be mode via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1839 else if (outlevel >= O_VERBOSE)
1840 printf(_(" No plugout command specified.\n"));
1842 if (ctl->server.protocol > P_POP2 && (ctl->server.protocol != P_ETRN))
1845 printf(_(" No UIDs saved from this host.\n"));
1851 for (idp = ctl->oldsaved; idp; idp = idp->next)
1854 printf(_(" %d UIDs saved.\n"), count);
1855 if (outlevel >= O_VERBOSE)
1856 for (idp = ctl->oldsaved; idp; idp = idp->next)
1857 printf("\t%s\n", idp->id);
1861 if (ctl->properties)
1862 printf(_(" Pass-through properties \"%s\".\n"),
1863 visbuf(ctl->properties));
1867 /* fetchmail.c ends here */