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 int nodetach; /* if TRUE, don't detach daemon process */
61 char *logfile; /* log file for daemon mode */
62 int use_syslog; /* if --syslog was set */
63 int quitmode; /* if --quit was set */
64 int 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 int 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;
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",
278 else if (kill(pid, SIGUSR1) == 0)
281 "fetchmail: background fetchmail at %d awakened.\n",
288 * Should never happen -- possible only if a background fetchmail
289 * croaks after the first kill probe above but before the SIGUSR1/SIGHUP
293 "fetchmail: elder sibling at %d died mysteriously.\n",
295 return(PS_UNDEFINED);
299 /* parse the ~/.netrc file (if present) for future password lookups. */
300 netrc_file = (char *) xmalloc (strlen (home) + 8);
301 strcpy (netrc_file, home);
302 strcat (netrc_file, "/.netrc");
303 netrc_list = parse_netrc(netrc_file);
305 /* pick up interactively any passwords we need but don't have */
306 for (ctl = querylist; ctl; ctl = ctl->next)
307 if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
309 if (ctl->server.authenticate == A_KERBEROS_V4 || ctl->server.protocol == P_IMAP_K4)
310 /* Server won't care what the password is, but there
311 must be some non-null string here. */
312 ctl->password = ctl->remotename;
315 /* look up the host and account in the .netrc file. */
316 netrc_entry *p = search_netrc(netrc_list,ctl->server.names->id);
317 while (p && strcmp(p->account, ctl->remotename))
318 p = search_netrc(p->next, ctl->remotename);
320 /* if we find a matching entry with a password, use it */
321 if (p && p->password)
322 ctl->password = xstrdup(p->password);
325 if (ctl->server.protocol != P_ETRN && ctl->server.protocol != P_IMAP_K4 && !ctl->password)
327 (void) sprintf(tmpbuf, "Enter password for %s@%s: ",
328 ctl->remotename, ctl->server.names->id);
329 ctl->password = xstrdup((char *)getpassword(tmpbuf));
334 * Maybe time to go to demon mode...
336 #if defined(HAVE_SYSLOG)
338 openlog(program_name, LOG_PID, LOG_MAIL);
344 daemonize(logfile, termhook);
345 error( 0, 0, "starting fetchmail %s daemon ", RELEASE_ID);
348 /* beyond here we don't want more than one fetchmail running per user */
350 signal(SIGABRT, termhook);
351 signal(SIGINT, termhook);
352 signal(SIGTERM, termhook);
353 signal(SIGALRM, termhook);
354 signal(SIGPIPE, termhook);
355 signal(SIGQUIT, termhook);
358 * With this simple hack, we make it possible for a foreground
359 * fetchmail to wake up one in daemon mode. What we want is the
360 * side effect of interrupting any sleep that may be going on,
361 * forcing fetchmail to re-poll its hosts.
363 signal(SIGUSR1, donothing);
365 /* pacify people who think all system daemons wake up on SIGHUP */
366 if (poll_interval && !getuid())
367 signal(SIGHUP, donothing);
369 /* here's the exclusion lock */
370 if ( (lockfp = fopen(lockfile,"w")) != NULL ) {
371 fprintf(lockfp,"%d",getpid());
373 fprintf(lockfp," %d", poll_interval);
379 on_exit(unlockit, (char *)NULL);
384 * Query all hosts. If there's only one, the error return will
385 * reflect the status of that transaction.
388 #ifdef HAVE_RES_SEARCH
389 sethostent(TRUE); /* use TCP/IP for mailserver queries */
390 #endif /* HAVE_RES_SEARCH */
393 for (ctl = querylist; ctl; ctl = ctl->next)
395 if (ctl->active && !(implicitmode && ctl->server.skip))
398 /* interface_approve() does its own error logging */
399 if (!interface_approve(&ctl->server))
403 #ifdef HAVE_GETHOSTBYNAME
405 * This functions partly as an optimization and partly
406 * as a probe to make sure our nameserver is still up.
407 * The multidrop case (especially) needs it.
409 if (ctl->server.authenticate==A_KERBEROS_V4 || MULTIDROP(ctl))
411 struct hostent *namerec;
413 /* compute the canonical name of the host */
415 namerec = gethostbyname(ctl->server.names->id);
416 if (namerec == (struct hostent *)NULL)
419 "skipping %s poll, ",
420 ctl->server.names->id);
423 if (errno == ENETUNREACH)
424 break; /* go to sleep */
426 #ifdef HAVE_HERROR /* NEXTSTEP doesn't */
429 #endif /* HAVE_HERROR */
434 free(ctl->server.canonical_name);
435 ctl->server.canonical_name = xstrdup((char *)namerec->h_name);
438 #endif /* HAVE_GETHOSTBYNAME */
440 querystatus = query_host(ctl);
442 update_str_lists(ctl);
444 if (ctl->server.monitor)
446 /* Allow some time for the link to quiesce. One
447 * second is usually sufficient, three is safe.
448 * Note: this delay is important - don't remove!
451 interface_note_activity(&ctl->server);
457 #ifdef HAVE_RES_SEARCH
458 endhostent(); /* release TCP/IP connection to nameserver */
459 #endif /* HAVE_RES_SEARCH */
462 * Close all SMTP delivery sockets. For optimum performance
463 * we'd like to hold them open til end of run, but (1) this
464 * loses if our poll interval is longer than the MTA's inactivity
465 * timeout, and (2) some MTAs (like smail) don't deliver after
466 * each message, but rather queue up mail and wait to actually
467 * deliver it until the input socket is closed.
469 for (ctl = querylist; ctl; ctl = ctl->next)
470 if (ctl->smtp_socket != -1)
472 SMTP_quit(ctl->smtp_socket);
473 close(ctl->smtp_socket);
474 ctl->smtp_socket = -1;
478 * OK, we've polled. Now sleep.
482 if (outlevel == O_VERBOSE)
487 fprintf(stderr, "fetchmail: sleeping at %s", ctime(&now));
491 * We can't use sleep(3) here because we need an alarm(3)
492 * equivalent in order to implement server nonresponse timeout.
493 * We'll just assume setitimer(2) is available since fetchmail
494 * has to have a BSDoid socket layer to work at all.
497 struct itimerval ntimeout;
499 ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0;
500 ntimeout.it_value.tv_sec = poll_interval;
501 ntimeout.it_value.tv_usec = 0;
503 setitimer(ITIMER_REAL,&ntimeout,NULL);
504 signal(SIGALRM, donothing);
506 signal(SIGALRM, SIG_IGN);
507 if (lastsig == SIGUSR1
508 || ((poll_interval && !getuid()) && lastsig == SIGHUP))
510 #ifdef SYS_SIGLIST_DECLARED
511 error(0, 0, "awakened by %s", sys_siglist[lastsig]);
513 error(0, 0, "awakened by signal %d", lastsig);
518 if (outlevel == O_VERBOSE)
523 fprintf(stderr, "fetchmail: awakened at %s", ctime(&now));
529 if (outlevel == O_VERBOSE)
530 fprintf(stderr,"fetchmail: normal termination, status %d\n",querystatus);
536 static int load_params(int argc, char **argv, int optind)
538 int implicitmode, st;
540 struct query def_opts, *ctl, *mp;
542 memset(&def_opts, '\0', sizeof(struct query));
543 def_opts.smtp_socket = -1;
545 def_opts.server.protocol = P_AUTO;
546 def_opts.server.timeout = CLIENT_TIMEOUT;
547 def_opts.remotename = user;
548 save_str(&def_opts.smtphunt, -1, fetchmailhost);
550 /* this builds the host list */
551 if (prc_parse_file(rcfile) != 0)
554 if ((implicitmode = (optind >= argc)))
556 for (ctl = querylist; ctl; ctl = ctl->next)
560 for (; optind < argc; optind++)
563 * If hostname corresponds to a host known from the rc file,
564 * simply declare it active. Otherwise synthesize a host
565 * record from command line and defaults
567 for (ctl = querylist; ctl; ctl = ctl->next)
568 if (str_in_list(&ctl->server.names, argv[optind]))
571 ctl = hostalloc(&cmd_opts);
572 save_str(&ctl->server.names, -1, argv[optind]);
578 /* if there's a defaults record, merge it and lose it */
579 if (querylist && strcmp(querylist->server.names->id, "defaults") == 0)
581 for (ctl = querylist->next; ctl; ctl = ctl->next)
582 optmerge(ctl, querylist);
583 querylist = querylist->next;
586 /* don't allow a defaults record after the first */
587 for (ctl = querylist; ctl; ctl = ctl->next)
588 if (ctl != querylist && strcmp(ctl->server.names->id, "defaults") == 0)
591 /* merge in wired defaults, do sanity checks and prepare internal fields */
592 for (ctl = querylist; ctl; ctl = ctl->next)
594 if (ctl->active && !(implicitmode && ctl->server.skip))
596 /* merge in defaults */
597 optmerge(ctl, &def_opts);
599 /* keep lusers from shooting themselves in the foot :-) */
600 if (poll_interval && ctl->limit)
602 fprintf(stderr,"fetchmail: you'd never see large messages!\n");
606 /* make sure delivery will default to a real local user */
607 if ((pw = getpwnam(user)) == (struct passwd *)NULL)
610 "fetchmail: can't set up default delivery to %s\n", user);
611 exit(PS_SYNTAX); /* has to be from bad rc file */
615 ctl->uid = pw->pw_uid; /* for local delivery via MDA */
616 if (!ctl->localnames) /* for local delivery via SMTP */
617 save_str_pair(&ctl->localnames, user, NULL);
620 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
621 /* can't handle multidrop mailboxes unless we can do DNS lookups */
622 if (ctl->localnames && ctl->localnames->next)
624 fputs("fetchmail: can't handle multidrop mailboxes without DNS\n",
628 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
630 /* compute server leaders for queries */
631 for (mp = querylist; mp && mp != ctl; mp = mp->next)
632 if (strcmp(mp->server.names->id, ctl->server.names->id) == 0)
634 ctl->server.lead_server = mp->server.lead_server;
637 ctl->server.lead_server = &(ctl->server);
640 /* this code enables flags to be turned off */
641 #define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
643 else if (flag == FLAG_FALSE)\
647 DEFAULT(ctl->keep, FALSE);
648 DEFAULT(ctl->flush, FALSE);
649 DEFAULT(ctl->fetchall, FALSE);
650 DEFAULT(ctl->rewrite, TRUE);
651 DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
652 DEFAULT(ctl->forcecr, FALSE);
653 DEFAULT(ctl->server.dns, TRUE);
654 DEFAULT(ctl->server.uidl, FALSE);
657 /* plug in the semi-standard way of indicating a mail address */
658 if (ctl->server.envelope == (char *)NULL)
659 ctl->server.envelope = "X-Envelope-To:";
661 /* if no folders were specified, set up the null one as default */
663 save_str(&ctl->mailboxes, -1, (char *)NULL);
666 if (ctl->server.port < 0)
668 (void) fprintf(stderr,
669 "%s configuration invalid, port number cannot be negative",
670 ctl->server.names->id);
673 if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
675 (void) fprintf(stderr,
676 "%s configuration invalid, RPOP requires a privileged port",
677 ctl->server.names->id);
683 /* initialize UID handling */
684 if ((st = prc_filecheck(idfile)) != 0)
687 initialize_saved_lists(querylist, idfile);
689 /* if cmd_logfile was explicitly set, use it to override logfile */
691 logfile = cmd_logfile;
693 /* likewise for poll_interval */
695 poll_interval = cmd_daemon;
697 /* check and daemon options are not compatible */
698 if (check_only && poll_interval)
701 return(implicitmode);
704 void termhook(int sig)
705 /* to be executed on normal or signal-induced termination */
710 * Sending SMTP QUIT on signal is theoretically nice, but led to a
711 * subtle bug. If fetchmail was terminated by signal while it was
712 * shipping message text, it would hang forever waiting for a
713 * command acknowledge. In theory we could disable the QUIT
714 * only outside of the message send. In practice, we don't
715 * care. All mailservers hang up on a dropped TCP/IP connection
720 error(0, 0, "terminated with signal %d", sig);
722 /* terminate all SMTP connections cleanly */
723 for (ctl = querylist; ctl; ctl = ctl->next)
724 if (ctl->smtp_socket != -1)
725 SMTP_quit(ctl->smtp_socket);
728 write_saved_lists(querylist, idfile);
733 static char *showproto(int proto)
734 /* protocol index to protocol name mapping */
738 case P_AUTO: return("auto"); break;
740 case P_POP2: return("POP2"); break;
741 #endif /* POP2_ENABLE */
742 case P_POP3: return("POP3"); break;
743 case P_IMAP: return("IMAP"); break;
744 case P_IMAP_K4: return("IMAP-K4"); break;
745 case P_APOP: return("APOP"); break;
746 case P_RPOP: return("RPOP"); break;
747 case P_ETRN: return("ETRN"); break;
748 default: return("unknown?!?"); break;
753 * Sequence of protocols to try when autoprobing, most capable to least.
756 static const int autoprobe[] = {P_IMAP, P_POP3, P_POP2};
758 static const int autoprobe[] = {P_IMAP, P_POP3};
759 #endif /* POP2_ENABLE */
761 static int query_host(struct query *ctl)
762 /* perform fetch transaction with single host */
766 if (poll_interval && ctl->server.interval)
768 if (ctl->server.poll_count++ % ctl->server.interval)
770 if (outlevel == O_VERBOSE)
772 "fetchmail: interval not reached, not querying %s\n",
773 ctl->server.names->id);
778 if (outlevel == O_VERBOSE)
783 fprintf(stderr, "fetchmail: %s querying %s (protocol %s) at %s",
785 ctl->server.names->id, showproto(ctl->server.protocol), ctime(&now));
787 switch (ctl->server.protocol) {
789 for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
791 ctl->server.protocol = autoprobe[i];
792 if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL)
795 ctl->server.protocol = P_AUTO;
802 fprintf(stderr, "POP2 support is not configured.\n");
804 #endif /* POP2_ENABLE */
818 error(0, 0, "unsupported protocol selected.");
823 void dump_params (struct query *ctl)
824 /* display query parameters in English */
826 printf("Options for retrieving from %s@%s:\n",
827 ctl->remotename, visbuf(ctl->server.names->id));
830 printf(" Logfile is %s\n", logfile);
832 printf(" Poll interval is %d seconds\n", poll_interval);
833 if (ctl->server.interval)
834 printf(" Poll of this server will occur every %d intervals.\n",
835 ctl->server.interval);
836 #ifdef HAVE_GETHOSTBYNAME
837 if (ctl->server.canonical_name)
838 printf(" Canonical DNS name of server is %s.\n", ctl->server.canonical_name);
839 #endif /* HAVE_GETHOSTBYNAME */
840 if (ctl->server.names->next)
844 printf(" Predeclared mailserver aliases:");
845 for (idp = ctl->server.names->next; idp; idp = idp->next)
846 printf(" %s", idp->id);
849 if (ctl->server.skip || outlevel == O_VERBOSE)
850 printf(" This host will%s be queried when no host is specified.\n",
851 ctl->server.skip ? " not" : "");
853 printf(" Password will be prompted for.\n");
854 else if (outlevel == O_VERBOSE)
855 if (ctl->server.protocol == P_APOP)
856 printf(" APOP secret = '%s'.\n", visbuf(ctl->password));
857 else if (ctl->server.protocol == P_RPOP)
858 printf(" RPOP id = '%s'.\n", visbuf(ctl->password));
860 printf(" Password = '%s'.\n", visbuf(ctl->password));
861 if (ctl->server.protocol == P_POP3
862 && ctl->server.port == KPOP_PORT
863 && ctl->server.authenticate == A_KERBEROS_V4)
864 printf(" Protocol is KPOP");
866 printf(" Protocol is %s", showproto(ctl->server.protocol));
867 if (ctl->server.port)
868 printf(" (using port %d)", ctl->server.port);
869 else if (outlevel == O_VERBOSE)
870 printf(" (using default port)");
871 if (ctl->server.uidl)
872 printf(" (forcing UIDL use)");
875 if (ctl->server.authenticate == A_KERBEROS_V4)
876 printf(" Kerberos V4 preauthentication enabled.\n");
877 printf(" Server nonresponse timeout is %d seconds", ctl->server.timeout);
878 if (ctl->server.timeout == CLIENT_TIMEOUT)
879 printf(" (default).\n");
882 if (ctl->server.localdomains)
886 printf(" Local domains:");
887 for (idp = ctl->server.localdomains; idp; idp = idp->next)
888 printf(" %s", idp->id);
892 if (!ctl->mailboxes->id)
893 printf(" Default mailbox selected.\n");
898 printf(" Selected mailboxes are:");
899 for (idp = ctl->mailboxes; idp; idp = idp->next)
900 printf(" %s", idp->id);
903 printf(" %s messages will be retrieved (--all %s).\n",
904 ctl->fetchall ? "All" : "Only new",
905 ctl->fetchall ? "on" : "off");
906 printf(" Fetched messages will%s be kept on the server (--keep %s).\n",
907 ctl->keep ? "" : " not",
908 ctl->keep ? "on" : "off");
909 printf(" Old messages will%s be flushed before message retrieval (--flush %s).\n",
910 ctl->flush ? "" : " not",
911 ctl->flush ? "on" : "off");
912 printf(" Rewrite of server-local addresses is %sabled (--norewrite %s).\n",
913 ctl->rewrite ? "en" : "dis",
914 ctl->rewrite ? "off" : "on");
915 printf(" Carriage-return stripping is %sabled (--stripcr %s).\n",
916 ctl->stripcr ? "en" : "dis",
917 ctl->stripcr ? "on" : "off");
918 printf(" Carriage-return forcing is %sabled (--forcecr %s).\n",
919 ctl->forcecr ? "en" : "dis",
920 ctl->forcecr ? "on" : "off");
922 printf(" Message size limit is %d bytes (--limit %d).\n",
923 ctl->limit, ctl->limit);
924 else if (outlevel == O_VERBOSE)
925 printf(" No message size limit (--limit 0).\n");
927 printf(" Received-message limit is %d (--fetchlimit %d).\n",
928 ctl->fetchlimit, ctl->fetchlimit);
929 else if (outlevel == O_VERBOSE)
930 printf(" No received-message limit (--fetchlimit 0).\n");
932 printf(" SMTP message batch limit is %d.\n", ctl->batchlimit);
933 else if (outlevel == O_VERBOSE)
934 printf(" No SMTP message batch limit.\n");
936 printf(" Messages will be delivered with '%s.'\n", visbuf(ctl->mda));
941 printf(" Messages will be SMTP-forwarded to:");
942 for (idp = ctl->smtphunt; idp; idp = idp->next)
943 printf(" %s", idp->id);
947 printf(" Server connection will be preinitialized with '%s.'\n", visbuf(ctl->preconnect));
948 else if (outlevel == O_VERBOSE)
949 printf(" No preinitialization command.\n");
950 if (!ctl->localnames)
951 printf(" No localnames declared for this host.\n");
957 for (idp = ctl->localnames; idp; idp = idp->next)
960 printf(" %d local name(s) recognized.\n", count);
961 if (outlevel == O_VERBOSE)
963 for (idp = ctl->localnames; idp; idp = idp->next)
965 printf("\t%s -> %s\n", idp->id, idp->val.id2);
967 printf("\t%s\n", idp->id);
969 fputs("*\n", stdout);
972 printf(" DNS lookup for multidrop addresses is %sabled.\n",
973 ctl->server.dns ? "en" : "dis");
976 if (ctl->server.envelope == STRING_DISABLED)
977 printf(" Envelope-address routing is disabled\n");
979 printf(" Envelope header is assumed to be: %s\n", ctl->server.envelope);
982 if (ctl->server.interface)
983 printf(" Connection must be through interface %s.\n", ctl->server.interface);
984 else if (outlevel == O_VERBOSE)
985 printf(" No interface requirement specified.\n");
986 if (ctl->server.monitor)
987 printf(" Polling loop will monitor %s.\n", ctl->server.monitor);
988 else if (outlevel == O_VERBOSE)
989 printf(" No monitor interface specified.\n");
992 if (ctl->server.protocol > P_POP2)
994 printf(" No UIDs saved from this host.\n");
1000 for (idp = ctl->oldsaved; idp; idp = idp->next)
1003 printf(" %d UIDs saved.\n", count);
1004 if (outlevel == O_VERBOSE)
1005 for (idp = ctl->oldsaved; idp; idp = idp->next)
1006 fprintf(stderr, "\t%s\n", idp->id);
1010 /* helper functions for string interpretation and display */
1012 void escapes(cp, tp)
1013 /* process standard C-style escape sequences in a string */
1014 const char *cp; /* source string with escapes */
1015 char *tp; /* target buffer for digested string */
1021 if (*cp == '\\' && strchr("0123456789xX", cp[1]))
1023 char *dp, *hex = "00112233445566778899aAbBcCdDeEfF";
1026 if (*++cp == 'x' || *cp == 'X')
1027 for (++cp; (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
1028 cval = (cval * 16) + (dp - hex) / 2;
1029 else if (*cp == '0')
1030 while (strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
1031 cval = (cval * 8) + (*cp++ - '0');
1033 while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
1034 cval = (cval * 10) + (*cp++ - '0');
1036 else if (*cp == '\\') /* C-style character escapes */
1040 case '\\': cval = '\\'; break;
1041 case 'n': cval = '\n'; break;
1042 case 't': cval = '\t'; break;
1043 case 'b': cval = '\b'; break;
1044 case 'r': cval = '\r'; break;
1045 default: cval = *cp;
1056 static char *visbuf(const char *buf)
1057 /* visibilize a given string */
1059 static char vbuf[BUFSIZ];
1064 if (isprint(*buf) || *buf == ' ')
1066 else if (*buf == '\n')
1068 *tp++ = '\\'; *tp++ = 'n';
1071 else if (*buf == '\r')
1073 *tp++ = '\\'; *tp++ = 'r';
1076 else if (*buf == '\b')
1078 *tp++ = '\\'; *tp++ = 'b';
1081 else if (*buf < ' ')
1083 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
1088 (void) sprintf(tp, "\\0x%02x", *buf++);
1096 /* fetchmail.c ends here */