2 * fetchmail.c -- main driver module for fetchmail
4 * For license terms, see the file COPYING in this directory.
11 #if defined(STDC_HEADERS)
14 #if defined(HAVE_UNISTD_H)
17 #if defined(HAVE_ALLOCA_H)
22 #if defined(HAVE_SYSLOG)
28 #include <sys/types.h>
32 #ifdef HAVE_GETHOSTBYNAME
34 #endif /* HAVE_GETHOSTBYNAME */
40 #include "fetchmail.h"
46 #define DROPDEAD 6 /* maximum bad socket opens */
48 /* prototypes for internal functions */
49 static int load_params(int, char **, int);
50 static void dump_params (struct query *);
51 static int query_host(struct query *);
52 static char *visbuf(const char *);
54 /* controls the detail level of status/progress messages written to stderr */
55 int outlevel; /* see the O_.* constants above */
56 int yydebug; /* enable parse debugging */
58 /* daemon mode control */
59 int poll_interval; /* poll interval in seconds */
60 bool nodetach; /* if TRUE, don't detach daemon process */
61 char *logfile; /* log file for daemon mode */
62 bool use_syslog; /* if --syslog was set */
63 bool quitmode; /* if --quit was set */
64 bool check_only; /* if --probe was set */
65 char *cmd_logfile; /* if --logfile was set */
66 int cmd_daemon; /* if --daemon was set */
68 /* miscellaneous global controls */
69 char *rcfile; /* path name of rc file */
70 char *idfile; /* UID list file */
71 bool versioninfo; /* emit only version info */
72 char *user; /* the name of the invoking user */
73 char *fetchmailhost; /* the name of the host running fetchmail */
74 char *program_name; /* the name to prefix error messages with */
76 static char *lockfile; /* name of lockfile */
77 static int querystatus; /* status of query */
78 static int lastsig; /* last signal received */
80 static void termhook(); /* forward declaration of exit hook */
82 RETSIGTYPE donothing(sig) int sig; {signal(sig, donothing); lastsig = sig;}
85 static void unlockit(void)
86 #else /* use on_exit(), e.g. on SunOS */
87 static void unlockit(int n, void *p)
89 /* must-do actions for exit (but we can't count on being able to do malloc) */
94 int main (int argc, char **argv)
97 int parsestatus, implicitmode = FALSE;
98 char *home, *tmpdir, tmpbuf[BUFSIZ];
102 netrc_entry *netrc_list;
106 if ((program_name = strrchr(argv[0], '/')) != NULL)
109 program_name = argv[0];
111 if ((user = getenv("USER")) == (char *)NULL)
112 user = getenv("LOGNAME");
114 if ((user == (char *)NULL) || (home = getenv("HOME")) == (char *)NULL)
116 if ((pw = getpwuid(getuid())) != NULL)
123 fprintf(stderr,"fetchmail: can't find your name and home directory!\n");
128 /* we'll need this for the SMTP forwarding target and error messages */
129 if (gethostname(tmpbuf, sizeof(tmpbuf)))
131 fprintf(stderr, "fetchmail: can't determine fetchmail's host!");
134 fetchmailhost = xstrdup(tmpbuf);
137 * Backward-compatibility hack. If we're called by the name of the
138 * ancestral popclient, look for .poprc. This will actually work
139 * for popclient files that don't use the removed keywords.
141 if (strcmp("popclient", argv[0]) == 0)
144 tmpdir = ".fetchmailrc";
146 rcfile = (char *) xmalloc(strlen(home)+strlen(tmpdir)+2);
147 strcpy(rcfile, home);
149 strcat(rcfile, tmpdir);
151 #define IDFILE_NAME ".fetchids"
152 idfile = (char *) xmalloc(strlen(home)+strlen(IDFILE_NAME)+2);
153 strcpy(idfile, home);
155 strcat(idfile, IDFILE_NAME);
159 if ((parsestatus = parsecmdline(argc,argv,&cmd_opts)) < 0)
162 /* this hint to stdio should help messages come out in the right order */
163 setvbuf(stdout, NULL, _IOLBF, POPBUFSIZE);
166 printf("This is fetchmail release %s\n", RELEASE_ID);
168 /* avoid parsing the config file if all we're doing is killing a daemon */
170 implicitmode = load_params(argc, argv, optind);
172 /* set up to do lock protocol */
174 strcpy(tmpbuf, "/var/run/fetchmail.pid");
176 strcpy(tmpbuf, home);
177 strcat(tmpbuf, "/.fetchmail");
180 /* perhaps we just want to check options? */
182 printf("Taking options from command line");
183 if (access(rcfile, 0))
186 printf(" and %s\n", rcfile);
187 if (outlevel == O_VERBOSE)
188 printf("Lockfile at %s\n", tmpbuf);
189 for (ctl = querylist; ctl; ctl = ctl->next) {
190 if (ctl->active && !(implicitmode && ctl->server.skip))
193 if (querylist == NULL)
194 (void) fprintf(stderr,
195 "No mailservers set up -- perhaps %s is missing?\n", rcfile);
198 else if (!quitmode && querylist == NULL) {
199 (void) fputs("fetchmail: no mailservers have been specified.\n", stderr);
203 /* check for another fetchmail running concurrently */
205 if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
207 fprintf(stderr,"fetchmail: cannot allocate memory for lock name.\n");
211 (void) strcpy(lockfile, tmpbuf);
212 if ((lockfp = fopen(lockfile, "r")) != NULL )
214 bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
216 if (kill(pid, 0) == -1) {
217 fprintf(stderr,"fetchmail: removing stale lockfile\n");
225 /* perhaps user asked us to kill the other fetchmail */
230 fprintf(stderr,"fetchmail: no other fetchmail is running\n");
233 else if (kill(pid, SIGTERM) < 0)
235 fprintf(stderr,"fetchmail: error killing %s fetchmail at %d.\n",
236 bkgd ? "background" : "foreground", pid);
241 fprintf(stderr,"fetchmail: %s fetchmail at %d killed.\n",
242 bkgd ? "background" : "foreground", pid);
248 /* another fetchmail is running -- wake it up or die */
254 "fetchmail: can't check mail while another fetchmail to same host is running.\n");
257 else if (!implicitmode)
260 "fetchmail: can't poll specified hosts with another fetchmail running at %d.\n",
267 "fetchmail: another foreground fetchmail is running at %d.\n",
274 "fetchmail: can't accept options while a background fetchmail is running.\n");
277 else if (kill(pid, SIGUSR1) == 0)
280 "fetchmail: background fetchmail at %d awakened.\n",
287 * Should never happen -- possible only if a background fetchmail
288 * croaks after the first kill probe above but before the SIGUSR1/SIGHUP
292 "fetchmail: elder sibling at %d died mysteriously.\n",
294 return(PS_UNDEFINED);
298 /* parse the ~/.netrc file (if present) for future password lookups. */
299 netrc_file = (char *) xmalloc (strlen (home) + 8);
300 strcpy (netrc_file, home);
301 strcat (netrc_file, "/.netrc");
302 netrc_list = parse_netrc(netrc_file);
304 /* pick up interactively any passwords we need but don't have */
305 for (ctl = querylist; ctl; ctl = ctl->next)
306 if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
308 if (ctl->server.preauthenticate == A_KERBEROS_V4 || ctl->server.protocol == P_IMAP_K4)
309 /* Server won't care what the password is, but there
310 must be some non-null string here. */
311 ctl->password = ctl->remotename;
314 /* look up the host and account in the .netrc file. */
315 netrc_entry *p = search_netrc(netrc_list,ctl->server.names->id);
316 while (p && strcmp(p->account, ctl->remotename))
317 p = search_netrc(p->next, ctl->remotename);
319 /* if we find a matching entry with a password, use it */
320 if (p && p->password)
321 ctl->password = xstrdup(p->password);
324 if (ctl->server.protocol != P_ETRN && ctl->server.protocol != P_IMAP_K4 && !ctl->password)
326 (void) sprintf(tmpbuf, "Enter password for %s@%s: ",
327 ctl->remotename, ctl->server.names->id);
328 ctl->password = xstrdup((char *)getpassword(tmpbuf));
333 * Maybe time to go to demon mode...
335 #if defined(HAVE_SYSLOG)
337 openlog(program_name, LOG_PID, LOG_MAIL);
343 daemonize(logfile, termhook);
344 error( 0, 0, "starting fetchmail %s daemon ", RELEASE_ID);
347 /* beyond here we don't want more than one fetchmail running per user */
349 signal(SIGABRT, termhook);
350 signal(SIGINT, termhook);
351 signal(SIGTERM, termhook);
352 signal(SIGALRM, termhook);
353 signal(SIGPIPE, termhook);
354 signal(SIGQUIT, termhook);
357 * With this simple hack, we make it possible for a foreground
358 * fetchmail to wake up one in daemon mode. What we want is the
359 * side effect of interrupting any sleep that may be going on,
360 * forcing fetchmail to re-poll its hosts.
362 signal(SIGUSR1, donothing);
364 /* pacify people who think all system daemons wake up on SIGHUP */
365 if (poll_interval && !getuid())
366 signal(SIGHUP, donothing);
368 /* here's the exclusion lock */
369 if ( (lockfp = fopen(lockfile,"w")) != NULL ) {
370 fprintf(lockfp,"%d",getpid());
372 fprintf(lockfp," %d", poll_interval);
378 on_exit(unlockit, (char *)NULL);
383 * Query all hosts. If there's only one, the error return will
384 * reflect the status of that transaction.
387 #ifdef HAVE_RES_SEARCH
388 sethostent(TRUE); /* use TCP/IP for mailserver queries */
389 #endif /* HAVE_RES_SEARCH */
392 for (ctl = querylist; ctl; ctl = ctl->next)
394 if (ctl->active && !(implicitmode && ctl->server.skip))
397 /* interface_approve() does its own error logging */
398 if (!interface_approve(&ctl->server))
402 #ifdef HAVE_GETHOSTBYNAME
404 * This functions partly as an optimization and partly
405 * as a probe to make sure our nameserver is still up.
406 * The multidrop case (especially) needs it.
408 if (ctl->server.preauthenticate==A_KERBEROS_V4 || MULTIDROP(ctl))
410 struct hostent *namerec;
412 /* compute the canonical name of the host */
414 namerec = gethostbyname(ctl->server.names->id);
415 if (namerec == (struct hostent *)NULL)
418 "skipping %s poll, ",
419 ctl->server.names->id);
422 if (errno == ENETUNREACH)
423 break; /* go to sleep */
425 #ifdef HAVE_HERROR /* NEXTSTEP doesn't */
428 #endif /* HAVE_HERROR */
433 free(ctl->server.canonical_name);
434 ctl->server.canonical_name = xstrdup((char *)namerec->h_name);
437 #endif /* HAVE_GETHOSTBYNAME */
439 querystatus = query_host(ctl);
441 update_str_lists(ctl);
443 if (ctl->server.monitor)
445 /* Allow some time for the link to quiesce. One
446 * second is usually sufficient, three is safe.
447 * Note: this delay is important - don't remove!
450 interface_note_activity(&ctl->server);
456 #ifdef HAVE_RES_SEARCH
457 endhostent(); /* release TCP/IP connection to nameserver */
458 #endif /* HAVE_RES_SEARCH */
461 * Close all SMTP delivery sockets. For optimum performance
462 * we'd like to hold them open til end of run, but (1) this
463 * loses if our poll interval is longer than the MTA's inactivity
464 * timeout, and (2) some MTAs (like smail) don't deliver after
465 * each message, but rather queue up mail and wait to actually
466 * deliver it until the input socket is closed.
468 for (ctl = querylist; ctl; ctl = ctl->next)
469 if (ctl->smtp_socket != -1)
471 SMTP_quit(ctl->smtp_socket);
472 close(ctl->smtp_socket);
473 ctl->smtp_socket = -1;
477 * OK, we've polled. Now sleep.
481 if (outlevel == O_VERBOSE)
486 fprintf(stderr, "fetchmail: sleeping at %s", ctime(&now));
490 * We can't use sleep(3) here because we need an alarm(3)
491 * equivalent in order to implement server nonresponse timeout.
492 * We'll just assume setitimer(2) is available since fetchmail
493 * has to have a BSDoid socket layer to work at all.
496 struct itimerval ntimeout;
498 ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0;
499 ntimeout.it_value.tv_sec = poll_interval;
500 ntimeout.it_value.tv_usec = 0;
502 setitimer(ITIMER_REAL,&ntimeout,NULL);
503 signal(SIGALRM, donothing);
505 signal(SIGALRM, SIG_IGN);
506 if (lastsig == SIGUSR1
507 || ((poll_interval && !getuid()) && lastsig == SIGHUP))
509 #ifdef SYS_SIGLIST_DECLARED
510 error(0, 0, "awakened by %s", sys_siglist[lastsig]);
512 error(0, 0, "awakened by signal %d", lastsig);
517 if (outlevel == O_VERBOSE)
522 fprintf(stderr, "fetchmail: awakened at %s", ctime(&now));
528 if (outlevel == O_VERBOSE)
529 fprintf(stderr,"fetchmail: normal termination, status %d\n",querystatus);
535 static int load_params(int argc, char **argv, int optind)
537 int implicitmode, st;
539 struct query def_opts, *ctl, *mp;
541 memset(&def_opts, '\0', sizeof(struct query));
542 def_opts.smtp_socket = -1;
544 def_opts.server.protocol = P_AUTO;
545 def_opts.server.timeout = CLIENT_TIMEOUT;
546 def_opts.remotename = user;
547 save_str(&def_opts.smtphunt, -1, fetchmailhost);
549 /* this builds the host list */
550 if (prc_parse_file(rcfile) != 0)
553 if ((implicitmode = (optind >= argc)))
555 for (ctl = querylist; ctl; ctl = ctl->next)
559 for (; optind < argc; optind++)
562 * If hostname corresponds to a host known from the rc file,
563 * simply declare it active. Otherwise synthesize a host
564 * record from command line and defaults
566 for (ctl = querylist; ctl; ctl = ctl->next)
567 if (str_in_list(&ctl->server.names, argv[optind]))
570 ctl = hostalloc(&cmd_opts);
571 save_str(&ctl->server.names, -1, argv[optind]);
577 /* if there's a defaults record, merge it and lose it */
578 if (querylist && strcmp(querylist->server.names->id, "defaults") == 0)
580 for (ctl = querylist->next; ctl; ctl = ctl->next)
581 optmerge(ctl, querylist);
582 querylist = querylist->next;
585 /* don't allow a defaults record after the first */
586 for (ctl = querylist; ctl; ctl = ctl->next)
587 if (ctl != querylist && strcmp(ctl->server.names->id, "defaults") == 0)
590 /* merge in wired defaults, do sanity checks and prepare internal fields */
591 for (ctl = querylist; ctl; ctl = ctl->next)
593 if (ctl->active && !(implicitmode && ctl->server.skip))
595 /* merge in defaults */
596 optmerge(ctl, &def_opts);
598 /* keep lusers from shooting themselves in the foot :-) */
599 if (poll_interval && ctl->limit)
601 fprintf(stderr,"fetchmail: you'd never see large messages!\n");
605 /* make sure delivery will default to a real local user */
606 if ((pw = getpwnam(user)) == (struct passwd *)NULL)
609 "fetchmail: can't set up default delivery to %s\n", user);
610 exit(PS_SYNTAX); /* has to be from bad rc file */
614 ctl->uid = pw->pw_uid; /* for local delivery via MDA */
615 if (!ctl->localnames) /* for local delivery via SMTP */
616 save_str_pair(&ctl->localnames, user, NULL);
619 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
620 /* can't handle multidrop mailboxes unless we can do DNS lookups */
621 if (ctl->localnames && ctl->localnames->next)
623 fputs("fetchmail: can't handle multidrop mailboxes without DNS\n",
627 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
629 /* compute server leaders for queries */
630 for (mp = querylist; mp && mp != ctl; mp = mp->next)
631 if (strcmp(mp->server.names->id, ctl->server.names->id) == 0)
633 ctl->server.lead_server = mp->server.lead_server;
636 ctl->server.lead_server = &(ctl->server);
639 /* this code enables flags to be turned off */
640 #define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
642 else if (flag == FLAG_FALSE)\
646 DEFAULT(ctl->keep, FALSE);
647 DEFAULT(ctl->flush, FALSE);
648 DEFAULT(ctl->fetchall, FALSE);
649 DEFAULT(ctl->rewrite, TRUE);
650 DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
651 DEFAULT(ctl->forcecr, FALSE);
652 DEFAULT(ctl->server.dns, TRUE);
653 DEFAULT(ctl->server.uidl, FALSE);
656 /* plug in the semi-standard way of indicating a mail address */
657 if (ctl->server.envelope == (char *)NULL)
658 ctl->server.envelope = "X-Envelope-To:";
660 /* if no folders were specified, set up the null one as default */
662 save_str(&ctl->mailboxes, -1, (char *)NULL);
665 if (ctl->server.port < 0)
667 (void) fprintf(stderr,
668 "%s configuration invalid, port number cannot be negative",
669 ctl->server.names->id);
672 if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
674 (void) fprintf(stderr,
675 "%s configuration invalid, RPOP requires a privileged port",
676 ctl->server.names->id);
682 /* initialize UID handling */
683 if ((st = prc_filecheck(idfile)) != 0)
686 initialize_saved_lists(querylist, idfile);
688 /* if cmd_logfile was explicitly set, use it to override logfile */
690 logfile = cmd_logfile;
692 /* likewise for poll_interval */
694 poll_interval = cmd_daemon;
696 /* check and daemon options are not compatible */
697 if (check_only && poll_interval)
700 return(implicitmode);
703 void termhook(int sig)
704 /* to be executed on normal or signal-induced termination */
709 * Sending SMTP QUIT on signal is theoretically nice, but led to a
710 * subtle bug. If fetchmail was terminated by signal while it was
711 * shipping message text, it would hang forever waiting for a
712 * command acknowledge. In theory we could disable the QUIT
713 * only outside of the message send. In practice, we don't
714 * care. All mailservers hang up on a dropped TCP/IP connection
719 error(0, 0, "terminated with signal %d", sig);
721 /* terminate all SMTP connections cleanly */
722 for (ctl = querylist; ctl; ctl = ctl->next)
723 if (ctl->smtp_socket != -1)
724 SMTP_quit(ctl->smtp_socket);
727 write_saved_lists(querylist, idfile);
732 static char *showproto(int proto)
733 /* protocol index to protocol name mapping */
737 case P_AUTO: return("auto"); break;
739 case P_POP2: return("POP2"); break;
740 #endif /* POP2_ENABLE */
741 case P_POP3: return("POP3"); break;
742 case P_IMAP: return("IMAP"); break;
743 case P_IMAP_K4: return("IMAP-K4"); break;
744 case P_APOP: return("APOP"); break;
745 case P_RPOP: return("RPOP"); break;
746 case P_ETRN: return("ETRN"); break;
747 default: return("unknown?!?"); break;
752 * Sequence of protocols to try when autoprobing, most capable to least.
755 static const int autoprobe[] = {P_IMAP, P_POP3, P_POP2};
757 static const int autoprobe[] = {P_IMAP, P_POP3};
758 #endif /* POP2_ENABLE */
760 static int query_host(struct query *ctl)
761 /* perform fetch transaction with single host */
765 if (poll_interval && ctl->server.interval)
767 if (ctl->server.poll_count++ % ctl->server.interval)
769 if (outlevel == O_VERBOSE)
771 "fetchmail: interval not reached, not querying %s\n",
772 ctl->server.names->id);
777 if (outlevel == O_VERBOSE)
782 fprintf(stderr, "fetchmail: %s querying %s (protocol %s) at %s",
784 ctl->server.names->id, showproto(ctl->server.protocol), ctime(&now));
786 switch (ctl->server.protocol) {
788 for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
790 ctl->server.protocol = autoprobe[i];
791 if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL)
794 ctl->server.protocol = P_AUTO;
801 fprintf(stderr, "POP2 support is not configured.\n");
803 #endif /* POP2_ENABLE */
817 error(0, 0, "unsupported protocol selected.");
822 void dump_params (struct query *ctl)
823 /* display query parameters in English */
825 printf("Options for retrieving from %s@%s:\n",
826 ctl->remotename, visbuf(ctl->server.names->id));
829 printf(" Logfile is %s\n", logfile);
831 printf(" Poll interval is %d seconds\n", poll_interval);
832 if (ctl->server.interval)
833 printf(" Poll of this server will occur every %d intervals.\n",
834 ctl->server.interval);
835 #ifdef HAVE_GETHOSTBYNAME
836 if (ctl->server.canonical_name)
837 printf(" Canonical DNS name of server is %s.\n", ctl->server.canonical_name);
838 #endif /* HAVE_GETHOSTBYNAME */
839 if (ctl->server.names->next)
843 printf(" Predeclared mailserver aliases:");
844 for (idp = ctl->server.names->next; idp; idp = idp->next)
845 printf(" %s", idp->id);
848 if (ctl->server.skip || outlevel == O_VERBOSE)
849 printf(" This host will%s be queried when no host is specified.\n",
850 ctl->server.skip ? " not" : "");
852 printf(" Password will be prompted for.\n");
853 else if (outlevel == O_VERBOSE)
854 if (ctl->server.protocol == P_APOP)
855 printf(" APOP secret = '%s'.\n", visbuf(ctl->password));
856 else if (ctl->server.protocol == P_RPOP)
857 printf(" RPOP id = '%s'.\n", visbuf(ctl->password));
859 printf(" Password = '%s'.\n", visbuf(ctl->password));
860 if (ctl->server.protocol == P_POP3
861 && ctl->server.port == KPOP_PORT
862 && ctl->server.preauthenticate == A_KERBEROS_V4)
863 printf(" Protocol is KPOP");
865 printf(" Protocol is %s", showproto(ctl->server.protocol));
866 if (ctl->server.port)
867 printf(" (using port %d)", ctl->server.port);
868 else if (outlevel == O_VERBOSE)
869 printf(" (using default port)");
870 if (ctl->server.uidl)
871 printf(" (forcing UIDL use)");
874 if (ctl->server.preauthenticate == A_KERBEROS_V4)
875 printf(" Kerberos V4 preauthentication enabled.\n");
876 printf(" Server nonresponse timeout is %d seconds", ctl->server.timeout);
877 if (ctl->server.timeout == CLIENT_TIMEOUT)
878 printf(" (default).\n");
881 if (ctl->server.localdomains)
885 printf(" Local domains:");
886 for (idp = ctl->server.localdomains; idp; idp = idp->next)
887 printf(" %s", idp->id);
891 if (!ctl->mailboxes->id)
892 printf(" Default mailbox selected.\n");
897 printf(" Selected mailboxes are:");
898 for (idp = ctl->mailboxes; idp; idp = idp->next)
899 printf(" %s", idp->id);
902 printf(" %s messages will be retrieved (--all %s).\n",
903 ctl->fetchall ? "All" : "Only new",
904 ctl->fetchall ? "on" : "off");
905 printf(" Fetched messages will%s be kept on the server (--keep %s).\n",
906 ctl->keep ? "" : " not",
907 ctl->keep ? "on" : "off");
908 printf(" Old messages will%s be flushed before message retrieval (--flush %s).\n",
909 ctl->flush ? "" : " not",
910 ctl->flush ? "on" : "off");
911 printf(" Rewrite of server-local addresses is %sabled (--norewrite %s).\n",
912 ctl->rewrite ? "en" : "dis",
913 ctl->rewrite ? "off" : "on");
914 printf(" Carriage-return stripping is %sabled (--stripcr %s).\n",
915 ctl->stripcr ? "en" : "dis",
916 ctl->stripcr ? "on" : "off");
917 printf(" Carriage-return forcing is %sabled (--forcecr %s).\n",
918 ctl->forcecr ? "en" : "dis",
919 ctl->forcecr ? "on" : "off");
921 printf(" Message size limit is %d bytes (--limit %d).\n",
922 ctl->limit, ctl->limit);
923 else if (outlevel == O_VERBOSE)
924 printf(" No message size limit (--limit 0).\n");
925 if (ctl->fetchlimit > 0)
926 printf(" Received-message limit is %d (--fetchlimit %d).\n",
927 ctl->fetchlimit, ctl->fetchlimit);
928 else if (outlevel == O_VERBOSE)
929 printf(" No received-message limit (--fetchlimit 0).\n");
930 if (ctl->batchlimit > 0)
931 printf(" SMTP message batch limit is %d.\n", ctl->batchlimit);
932 else if (outlevel == O_VERBOSE)
933 printf(" No SMTP message batch limit.\n");
935 printf(" Messages will be delivered with '%s.'\n", visbuf(ctl->mda));
940 printf(" Messages will be SMTP-forwarded to:");
941 for (idp = ctl->smtphunt; idp; idp = idp->next)
942 printf(" %s", idp->id);
946 printf(" Server connection will be preinitialized with '%s.'\n", visbuf(ctl->preconnect));
947 else if (outlevel == O_VERBOSE)
948 printf(" No preinitialization command.\n");
949 if (!ctl->localnames)
950 printf(" No localnames declared for this host.\n");
956 for (idp = ctl->localnames; idp; idp = idp->next)
959 printf(" %d local name(s) recognized.\n", count);
960 if (outlevel == O_VERBOSE)
962 for (idp = ctl->localnames; idp; idp = idp->next)
964 printf("\t%s -> %s\n", idp->id, idp->val.id2);
966 printf("\t%s\n", idp->id);
968 fputs("*\n", stdout);
971 printf(" DNS lookup for multidrop addresses is %sabled.\n",
972 ctl->server.dns ? "en" : "dis");
975 if (ctl->server.envelope == STRING_DISABLED)
976 printf(" Envelope-address routing is disabled\n");
978 printf(" Envelope header is assumed to be: %s\n", ctl->server.envelope);
981 if (ctl->server.interface)
982 printf(" Connection must be through interface %s.\n", ctl->server.interface);
983 else if (outlevel == O_VERBOSE)
984 printf(" No interface requirement specified.\n");
985 if (ctl->server.monitor)
986 printf(" Polling loop will monitor %s.\n", ctl->server.monitor);
987 else if (outlevel == O_VERBOSE)
988 printf(" No monitor interface specified.\n");
991 if (ctl->server.protocol > P_POP2)
993 printf(" No UIDs saved from this host.\n");
999 for (idp = ctl->oldsaved; idp; idp = idp->next)
1002 printf(" %d UIDs saved.\n", count);
1003 if (outlevel == O_VERBOSE)
1004 for (idp = ctl->oldsaved; idp; idp = idp->next)
1005 fprintf(stderr, "\t%s\n", idp->id);
1009 /* helper functions for string interpretation and display */
1011 void escapes(cp, tp)
1012 /* process standard C-style escape sequences in a string */
1013 const char *cp; /* source string with escapes */
1014 char *tp; /* target buffer for digested string */
1020 if (*cp == '\\' && strchr("0123456789xX", cp[1]))
1022 char *dp, *hex = "00112233445566778899aAbBcCdDeEfF";
1025 if (*++cp == 'x' || *cp == 'X')
1026 for (++cp; (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
1027 cval = (cval * 16) + (dp - hex) / 2;
1028 else if (*cp == '0')
1029 while (strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
1030 cval = (cval * 8) + (*cp++ - '0');
1032 while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
1033 cval = (cval * 10) + (*cp++ - '0');
1035 else if (*cp == '\\') /* C-style character escapes */
1039 case '\\': cval = '\\'; break;
1040 case 'n': cval = '\n'; break;
1041 case 't': cval = '\t'; break;
1042 case 'b': cval = '\b'; break;
1043 case 'r': cval = '\r'; break;
1044 default: cval = *cp;
1055 static char *visbuf(const char *buf)
1056 /* visibilize a given string */
1058 static char vbuf[BUFSIZ];
1063 if (isprint(*buf) || *buf == ' ')
1065 else if (*buf == '\n')
1067 *tp++ = '\\'; *tp++ = 'n';
1070 else if (*buf == '\r')
1072 *tp++ = '\\'; *tp++ = 'r';
1075 else if (*buf == '\b')
1077 *tp++ = '\\'; *tp++ = 'b';
1080 else if (*buf < ' ')
1082 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
1087 (void) sprintf(tp, "\\0x%02x", *buf++);
1095 /* fetchmail.c ends here */