]> Pileus Git - ~andy/fetchmail/blob - fetchmail.c
Dave Zarzycki's fixes.
[~andy/fetchmail] / fetchmail.c
1 /*
2  * fetchmail.c -- main driver module for fetchmail
3  *
4  * For license terms, see the file COPYING in this directory.
5  */
6 #include "config.h"
7
8 #include <stdio.h>
9 #if defined(STDC_HEADERS)
10 #include <stdlib.h>
11 #endif
12 #if defined(HAVE_UNISTD_H)
13 #include <unistd.h>
14 #endif
15 #include <fcntl.h>
16 #include <string.h>
17 #include <signal.h>
18 #if defined(HAVE_SYSLOG)
19 #include <syslog.h>
20 #endif
21 #include <pwd.h>
22 #ifdef __FreeBSD__
23 #include <grp.h>
24 #endif
25 #include <errno.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <sys/time.h>   /* needed for Sun 4.1.2 */
29 #ifdef HAVE_SETRLIMIT
30 #include <sys/resource.h>
31 #endif /* HAVE_SETRLIMIT */
32 #include <sys/utsname.h>
33
34 #ifdef HAVE_NET_SOCKET_H
35 #include <net/socket.h>
36 #endif
37 #ifdef HAVE_GETHOSTBYNAME
38 #include <netdb.h>
39 #endif /* HAVE_GETHOSTBYNAME */
40
41 #ifdef HESIOD
42 #include <hesiod.h>
43 #endif
44
45 #include "getopt.h"
46 #include "fetchmail.h"
47 #include "socket.h"
48 #include "tunable.h"
49 #include "smtp.h"
50 #include "netrc.h"
51 #include "i18n.h"
52
53 #ifndef ENETUNREACH
54 #define ENETUNREACH   128       /* Interactive doesn't know this */
55 #endif /* ENETUNREACH */
56
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 *);
61
62 /* controls the detail level of status/progress messages written to stderr */
63 int outlevel;               /* see the O_.* constants above */
64
65 /* miscellaneous global controls */
66 struct runctl run;          /* global controls for this run */
67 flag nodetach;              /* if TRUE, don't detach daemon process */
68 flag quitmode;              /* if --quit was set */
69 flag check_only;            /* if --probe was set */
70 flag versioninfo;           /* emit only version info */
71 char *user;                 /* the name of the invoking user */
72 char *home;                 /* invoking user's home directory */
73 char *fmhome;               /* fetchmail's home directory */
74 char *program_name;         /* the name to prefix error messages with */
75 flag configdump;            /* dump control blocks for configurator */
76 const char *fetchmailhost;  /* either `localhost' or the host's FQDN */
77
78 #if NET_SECURITY
79 void *request = NULL;
80 int requestlen = 0;
81 #endif /* NET_SECURITY */
82
83 static char *lockfile;          /* name of lockfile */
84 static int lock_acquired;       /* have we acquired a lock */
85 static int querystatus;         /* status of query */
86 static int successes;           /* count number of successful polls */
87 static int activecount;         /* count number of active entries */
88 static struct runctl cmd_run;   /* global options set from command line */
89 static time_t parsetime;        /* time of last parse */
90
91 static void terminate_run(int);
92 static void terminate_poll(int);
93
94 #ifdef HAVE_ON_EXIT
95 static void unlockit(int n, void *p)
96 #else
97 static void unlockit(void)
98 #endif
99 /* must-do actions for exit (but we can't count on being able to do malloc) */
100 {
101     if (lockfile && lock_acquired)
102         unlink(lockfile);
103 }
104
105 #if defined(__FreeBSD__) && defined(__FreeBSD_USE_KVM)
106 /* drop SGID kmem privileage until we need it */
107 static void dropprivs(void)
108 {
109     struct group *gr;
110     gid_t        egid;
111     gid_t        rgid;
112     
113     egid = getegid();
114     rgid = getgid();
115     gr = getgrgid(egid);
116     
117     if (gr && !strcmp(gr->gr_name, "kmem"))
118     {
119         extern void interface_set_gids(gid_t egid, gid_t rgid);
120         interface_set_gids(egid, rgid);
121         setegid(rgid);
122     }
123 }
124 #endif
125
126 #if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
127 #include <time.h>
128 #include <locale.h>
129 static char *timestamp (void)
130 {
131     time_t      now;
132     static char buf[60];
133
134     time (&now);
135     setlocale (LC_TIME, "");
136     strftime (buf, sizeof (buf), "%c", localtime(&now));
137     setlocale (LC_TIME, "C");
138     return (buf);
139 }
140 #else
141 #define timestamp rfc822timestamp
142 #endif
143
144 int main(int argc, char **argv)
145 {
146     int st, bkgd = FALSE;
147     int parsestatus, implicitmode = FALSE;
148     FILE        *lockfp;
149     struct query *ctl;
150     netrc_entry *netrc_list;
151     char *netrc_file, *tmpbuf;
152     pid_t pid;
153     int lastsig = 0;
154
155 #if defined(__FreeBSD__) && defined(__FreeBSD_USE_KVM)
156     dropprivs();
157 #endif
158
159     envquery(argc, argv);
160 #ifdef ENABLE_NLS
161     bindtextdomain(PACKAGE, LOCALEDIR);
162     textdomain(PACKAGE);
163 #endif
164
165     /*
166      * Note: because we can't initialize reporting before we  know whether
167      * syslog is supposed to be on, this message will go to stdout and
168      * be lost when running in background.
169      */
170     if (outlevel >= O_VERBOSE)
171     {
172         int i;
173
174         report(stdout, _("fetchmail: invoked with"));
175         for (i = 0; i < argc; i++)
176             report(stdout, " %s", argv[i]);
177         report(stdout, "\n");
178     }
179
180 #define IDFILE_NAME     ".fetchids"
181     run.idfile = (char *) xmalloc(strlen(fmhome)+sizeof(IDFILE_NAME)+2);
182     strcpy(run.idfile, fmhome);
183     strcat(run.idfile, "/");
184     strcat(run.idfile, IDFILE_NAME);
185   
186     outlevel = O_NORMAL;
187
188     /*
189      * We used to arrange for the lockfile to be removed on exit close
190      * to where the lock was asserted.  Now we need to do it here, because
191      * we might have re-executed in background with an existing lockfile
192      * as the result of a changed rcfile (see the code near the execvp(3)
193      * call near the beginning of the polling loop for details).  We want
194      * to be sure the lockfile gets nuked on any error exit, basically.
195      */
196 #ifdef HAVE_ATEXIT
197     atexit(unlockit);
198 #endif
199 #ifdef HAVE_ON_EXIT
200     on_exit(unlockit, (char *)NULL);
201 #endif
202
203     if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
204         exit(PS_SYNTAX);
205
206     if (versioninfo)
207     {
208         printf(_("This is fetchmail release %s"), VERSION);
209 #ifdef POP2_ENABLE
210         printf("+POP2");
211 #endif /* POP2_ENABLE */
212 #ifndef POP3_ENABLE
213         printf("-POP3");
214 #endif /* POP3_ENABLE */
215 #ifndef IMAP_ENABLE
216         printf("-IMAP");
217 #endif /* IMAP_ENABLE */
218 #ifdef GSSAPI
219         printf("+IMAP-GSS");
220 #endif /* GSSAPI */
221 #ifdef RPA_ENABLE
222         printf("+RPA");
223 #endif /* RPA_ENABLE */
224 #ifdef NTLM_ENABLE
225         printf("+NTLM");
226 #endif /* NTLM_ENABLE */
227 #ifdef SDPS_ENABLE
228         printf("+SDPS");
229 #endif /* SDPS_ENABLE */
230 #ifndef ETRN_ENABLE
231         printf("-ETRN");
232 #endif /* ETRN_ENABLE */
233 #ifndef ODMR_ENABLE
234         printf("-ODMR");
235 #endif /* ODMR_ENABLE */
236 #ifdef SSL_ENABLE
237         printf("+SSL");
238 #endif
239 #if OPIE_ENABLE
240         printf("+OPIE");
241 #endif /* OPIE_ENABLE */
242 #if INET6_ENABLE
243         printf("+INET6");
244 #endif /* INET6_ENABLE */
245 #if NET_SECURITY
246         printf("+NETSEC");
247 #endif /* NET_SECURITY */
248 #ifdef HAVE_SOCKS
249         printf("+SOCKS");
250 #endif /* HAVE_SOCKS */
251 #if ENABLE_NLS
252         printf("+NLS");
253 #endif /* ENABLE_NLS */
254         putchar('\n');
255         fflush(stdout);
256
257         /* this is an attempt to help remote debugging */
258         system("uname -a");
259     }
260
261     /* avoid parsing the config file if all we're doing is killing a daemon */ 
262     if (!(quitmode && argc == 2))
263         implicitmode = load_params(argc, argv, optind);
264
265 #if defined(HAVE_SYSLOG)
266     /* logging should be set up early in case we were restarted from exec */
267     if (run.use_syslog)
268     {
269 #if defined(LOG_MAIL)
270         openlog(program_name, LOG_PID, LOG_MAIL);
271 #else
272         /* Assume BSD4.2 openlog with two arguments */
273         openlog(program_name, LOG_PID);
274 #endif
275         report_init(-1);
276     }
277     else
278 #endif
279         report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
280
281     /* set up to do lock protocol */
282 #define FETCHMAIL_PIDFILE       "fetchmail.pid"
283     if (!getuid()) {
284         xalloca(tmpbuf, char *,
285                 sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
286         sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
287     } else {
288         xalloca(tmpbuf, char *, strlen(fmhome) + sizeof(FETCHMAIL_PIDFILE) + 2);
289         strcpy(tmpbuf, fmhome);
290         strcat(tmpbuf, "/");
291         if (fmhome == home)
292            strcat(tmpbuf, ".");
293         strcat(tmpbuf, FETCHMAIL_PIDFILE);
294     }
295 #undef FETCHMAIL_PIDFILE
296
297 #ifdef HAVE_SETRLIMIT
298     /*
299      * Before getting passwords, disable core dumps unless -v -d0 mode is on.
300      * Core dumps could otherwise contain passwords to be scavenged by a
301      * cracker.
302      */
303     if (outlevel < O_VERBOSE || run.poll_interval > 0)
304     {
305         struct rlimit corelimit;
306         corelimit.rlim_cur = 0;
307         corelimit.rlim_max = 0;
308         setrlimit(RLIMIT_CORE, &corelimit);
309     }
310 #endif /* HAVE_SETRLIMIT */
311
312 #define NETRC_FILE      ".netrc"
313     /* parse the ~/.netrc file (if present) for future password lookups. */
314     xalloca(netrc_file, char *, strlen(home) + sizeof(NETRC_FILE) + 2);
315     strcpy (netrc_file, home);
316     strcat (netrc_file, "/");
317     strcat (netrc_file, NETRC_FILE);
318     netrc_list = parse_netrc(netrc_file);
319 #undef NETRC_FILE
320
321     /* pick up passwords where we can */ 
322     for (ctl = querylist; ctl; ctl = ctl->next)
323     {
324         if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
325         {
326             if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
327                         ctl->server.preauthenticate == A_KERBEROS_V5 ||
328                         ctl->server.preauthenticate == A_SSH ||
329 #ifdef GSSAPI
330                         ctl->server.protocol == P_IMAP_GSS ||
331 #endif /* GSSAPI */
332                         ctl->server.protocol == P_IMAP_K4)
333                 /* Server won't care what the password is, but there
334                    must be some non-null string here.  */
335                 ctl->password = ctl->remotename;
336             else
337             {
338                 netrc_entry *p;
339
340                 /* look up the pollname and account in the .netrc file. */
341                 p = search_netrc(netrc_list,
342                                  ctl->server.pollname, ctl->remotename);
343                 /* if we find a matching entry with a password, use it */
344                 if (p && p->password)
345                     ctl->password = xstrdup(p->password);
346
347                 /* otherwise try with "via" name if there is one */
348                 else if (ctl->server.via)
349                 {
350                     p = search_netrc(netrc_list, 
351                                      ctl->server.via, ctl->remotename);
352                     if (p && p->password)
353                         ctl->password = xstrdup(p->password);
354                 }
355             }
356         }
357     }
358
359     /* perhaps we just want to check options? */
360     if (versioninfo)
361     {
362         int havercfile = access(rcfile, 0);
363
364         printf(_("Taking options from command line%s%s\n"),
365                                 havercfile ? "" :  _(" and "),
366                                 havercfile ? "" : rcfile);
367
368         if (outlevel >= O_VERBOSE)
369             printf(_("Lockfile at %s\n"), tmpbuf);
370
371         if (querylist == NULL)
372             fprintf(stderr,
373                     _("No mailservers set up -- perhaps %s is missing?\n"),
374                     rcfile);
375         else
376             dump_params(&run, querylist, implicitmode);
377         exit(0);
378     }
379
380     /* dump options as a Python dictionary, for configurator use */
381     if (configdump)
382     {
383         dump_config(&run, querylist);
384         exit(0);
385     }
386
387     /* check for another fetchmail running concurrently */
388     pid = -1;
389     if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
390     {
391         report(stderr,_("fetchmail: cannot allocate memory for lock name.\n"));
392         exit(PS_EXCLUDE);
393     }
394     else
395         (void) strcpy(lockfile, tmpbuf);
396     if ((lockfp = fopen(lockfile, "r")) != NULL )
397     {
398         bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
399
400         if (kill(pid, 0) == -1) {
401             fprintf(stderr,_("fetchmail: removing stale lockfile\n"));
402             pid = -1;
403             bkgd = FALSE;
404             unlink(lockfile);
405         }
406         fclose(lockfp); /* not checking should be safe, file mode was "r" */
407     }
408
409     /* if no mail servers listed and nothing in background, we're done */
410     if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
411         (void)fputs(_("fetchmail: no mailservers have been specified.\n"),stderr);
412         exit(PS_SYNTAX);
413     }
414
415     /* perhaps user asked us to kill the other fetchmail */
416     if (quitmode)
417     {
418         if (pid == -1) 
419         {
420             fprintf(stderr,_("fetchmail: no other fetchmail is running\n"));
421             if (argc == 2)
422                 exit(PS_EXCLUDE);
423         }
424         else if (kill(pid, SIGTERM) < 0)
425         {
426             fprintf(stderr,_("fetchmail: error killing %s fetchmail at %d; bailing out.\n"),
427                     bkgd ? _("background") : _("foreground"), pid);
428             exit(PS_EXCLUDE);
429         }
430         else
431         {
432             fprintf(stderr,_("fetchmail: %s fetchmail at %d killed.\n"),
433                     bkgd ? _("background") : _("foreground"), pid);
434             unlink(lockfile);
435             if (argc == 2)
436                 exit(0);
437             else
438                 pid = -1; 
439         }
440     }
441
442     /* another fetchmail is running -- wake it up or die */
443     if (pid != -1)
444     {
445         if (check_only)
446         {
447             fprintf(stderr,
448                  _("fetchmail: can't check mail while another fetchmail to same host is running.\n"));
449             return(PS_EXCLUDE);
450         }
451         else if (!implicitmode)
452         {
453             fprintf(stderr,
454                  _("fetchmail: can't poll specified hosts with another fetchmail running at %d.\n"),
455                  pid);
456                 return(PS_EXCLUDE);
457         }
458         else if (!bkgd)
459         {
460             fprintf(stderr,
461                  _("fetchmail: another foreground fetchmail is running at %d.\n"),
462                  pid);
463                 return(PS_EXCLUDE);
464         }
465         else if (argc > 1)
466         {
467             /* this test enables re-execing on a changed rcfile */
468             if (getpid() == pid)
469                 lock_acquired = TRUE;
470             else
471             {
472                 fprintf(stderr,
473                         _("fetchmail: can't accept options while a background fetchmail is running.\n"));
474                 return(PS_EXCLUDE);
475             }
476         }
477         else if (kill(pid, SIGUSR1) == 0)
478         {
479             fprintf(stderr,
480                     _("fetchmail: background fetchmail at %d awakened.\n"),
481                     pid);
482             return(0);
483         }
484         else
485         {
486             /*
487              * Should never happen -- possible only if a background fetchmail
488              * croaks after the first kill probe above but before the
489              * SIGUSR1/SIGHUP transmission.
490              */
491             fprintf(stderr,
492                     _("fetchmail: elder sibling at %d died mysteriously.\n"),
493                     pid);
494             return(PS_UNDEFINED);
495         }
496     }
497
498     /* pick up interactively any passwords we need but don't have */ 
499     for (ctl = querylist; ctl; ctl = ctl->next)
500     {
501         if (ctl->active && !(implicitmode && ctl->server.skip)
502                 && ctl->server.protocol != P_ETRN
503                 && ctl->server.protocol != P_IMAP_K4
504 #ifdef GSSAPI
505                 && ctl->server.protocol != P_IMAP_GSS
506 #endif /* GSSAPI */
507                 && !ctl->password)
508         {
509             if (!isatty(0))
510             {
511                 fprintf(stderr,
512                         _("fetchmail: can't find a password for %s@%s.\n"),
513                         ctl->remotename, ctl->server.pollname);
514                 return(PS_AUTHFAIL);
515             }
516             else
517             {
518                 char* password_prompt = _("Enter password for %s@%s: ");
519
520                 xalloca(tmpbuf, char *, strlen(password_prompt) +
521                         strlen(ctl->remotename) +
522                         strlen(ctl->server.pollname) + 1);
523                 (void) sprintf(tmpbuf, password_prompt,
524                                ctl->remotename, ctl->server.pollname);
525                 ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
526             }
527         }
528     }
529
530     /*
531      * Time to initiate the SOCKS library (this is not mandatory: it just
532      * registers the correct application name for logging purpose. If you
533      * have some problem, comment out these lines).
534      */
535 #ifdef HAVE_SOCKS
536     SOCKSinit("fetchmail");
537 #endif /* HAVE_SOCKS */
538
539     /*
540      * Maybe time to go to demon mode...
541      */
542     if (run.poll_interval)
543     {
544         deal_with_sigchld();
545         if (nodetach)
546             deal_with_sigchld();
547         else
548             daemonize(run.logfile, terminate_run);
549         report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
550
551         /*
552          * We'll set up a handler for these when we're sleeping,
553          * but ignore them otherwise so as not to interrupt a poll.
554          */
555         signal(SIGUSR1, SIG_IGN);
556         if (run.poll_interval && !getuid())
557             signal(SIGHUP, SIG_IGN);
558     }
559     else if (run.logfile && access(run.logfile, F_OK) == 0)
560     {
561         freopen(run.logfile, "a", stdout);
562         freopen(run.logfile, "a", stderr);
563     }
564
565
566 #ifdef linux
567     interface_init();
568 #endif /* linux */
569
570     /* beyond here we don't want more than one fetchmail running per user */
571     umask(0077);
572     signal(SIGABRT, terminate_run);
573     signal(SIGINT, terminate_run);
574     signal(SIGTERM, terminate_run);
575     signal(SIGALRM, terminate_run);
576     signal(SIGPIPE, terminate_run);
577     signal(SIGQUIT, terminate_run);
578
579     /* here's the exclusion lock */
580 #ifndef O_SYNC
581 #define O_SYNC  0       /* use it if we have it */
582 #endif
583     if (!lock_acquired)
584     {
585       if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
586       {
587           sprintf(tmpbuf,"%d", getpid());
588           write(st, tmpbuf, strlen(tmpbuf));
589           if (run.poll_interval)
590           {
591               sprintf(tmpbuf," %d", run.poll_interval);
592               write(st, tmpbuf, strlen(tmpbuf));
593           }
594           close(st);    /* should be safe, fd was opened with O_SYNC */
595           lock_acquired = TRUE;
596       }
597       else
598       {
599           fprintf(stderr,       _("fetchmail: lock creation failed.\n"));
600           return(PS_EXCLUDE);
601       }
602     }
603
604     /*
605      * Query all hosts. If there's only one, the error return will
606      * reflect the status of that transaction.
607      */
608     do {
609         /* 
610          * Check to see if the rcfile has been touched.  If so,
611          * re-exec so the file will be reread.  Doing it this way
612          * avoids all the complications of trying to deallocate the
613          * in-core control structures -- and the potential memory
614          * leaks...
615          */
616         struct stat     rcstat;
617
618         if (stat(rcfile, &rcstat) == -1)
619         {
620             if (errno != ENOENT)
621                 report(stderr, 
622                        _("couldn't time-check %s (error %d)\n"),
623                        rcfile, errno);
624         }
625         else if (rcstat.st_mtime > parsetime)
626         {
627             report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
628             /*
629              * Matthias Andree: Isn't this prone to introduction of
630              * "false" programs by interfering with PATH? Those
631              * path-searching execs might not be the best ideas for
632              * this reason.
633              *
634              * Rob Funk: But is there any way for someone to modify
635              * the PATH variable of a running fetchmail?  I don't know
636              * of a way.
637              *
638              * Dave's change makes fetchmail restart itself in exactly
639              * the way it was started from the shell (or shell script)
640              * in the first place.  If you're concerned about PATH
641              * contamination, call fetchmail initially with a full
642              * path, and use Dave's patch.
643              *
644              * Not using a -p variant of exec means that the restart
645              * will break if both (a) the user depended on PATH to
646              * call fetchmail in the first place, and (b) the system
647              * doesn't save the whole path in argv[0] if the whole
648              * path wasn't used in the initial call.  (If I recall
649              * correctly, Linux saves it but many other Unices don't.)
650              */
651             execvp(argv[0], argv);
652             report(stderr, _("attempt to re-exec fetchmail failed\n"));
653         }
654
655 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
656         /*
657          * This was an efficiency hack that backfired.  The theory
658          * was that using TCP/IP for DNS queries would get us better
659          * reliability and shave off some per-UDP-packet costs.
660          * Unfortunately it interacted badly with diald, which effectively 
661          * filters out DNS queries over TCP/IP for reasons having to do
662          * with some obscure Linux kernel problem involving bootstrapping of
663          * dynamically-addressed links.  I don't understand this mess
664          * and don't want to, so it's "See ya!" to this hack.
665          */
666         sethostent(TRUE);       /* use TCP/IP for mailserver queries */
667 #endif /* HAVE_RES_SEARCH */
668
669         activecount = 0;
670         batchcount = 0;
671         for (ctl = querylist; ctl; ctl = ctl->next)
672             if (ctl->active)
673             {
674                 activecount++;
675                 if (!(implicitmode && ctl->server.skip))
676                 {
677                     if (ctl->wedged)
678                     {
679                         report(stderr, 
680                                _("poll of %s skipped (failed authentication or too many timeouts)\n"),
681                                ctl->server.pollname);
682                         continue;
683                     }
684
685                     /* check skip interval first so that it counts all polls */
686                     if (run.poll_interval && ctl->server.interval) 
687                     {
688                         if (ctl->server.poll_count++ % ctl->server.interval) 
689                         {
690                             if (outlevel >= O_VERBOSE)
691                                 report(stdout,
692                                        _("interval not reached, not querying %s\n"),
693                                        ctl->server.pollname);
694                             continue;
695                         }
696                     }
697
698 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
699                     /*
700                      * Don't do monitoring if we were woken by a signal.
701                      * Note that interface_approve() does its own error logging.
702                      */
703                     if (!interface_approve(&ctl->server, !lastsig))
704                         continue;
705 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
706
707                     querystatus = query_host(ctl);
708
709 #ifdef POP3_ENABLE
710                     /* leave the UIDL state alone if there have been any errors */
711                     if (!check_only &&
712                                 ((querystatus==PS_SUCCESS) || (querystatus==PS_NOMAIL) || (querystatus==PS_MAXFETCH)))
713                         uid_swap_lists(ctl);
714 #endif  /* POP3_ENABLE */
715
716                     if (querystatus == PS_SUCCESS)
717                         successes++;
718                     else if (!check_only && 
719                              ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
720                         switch(querystatus)
721                         {
722                         case PS_SUCCESS:
723                             report(stdout,_("Query status=0 (SUCCESS)\n"));break;
724                         case PS_NOMAIL: 
725                             report(stdout,_("Query status=1 (NOMAIL)\n")); break;
726                         case PS_SOCKET:
727                             report(stdout,_("Query status=2 (SOCKET)\n")); break;
728                         case PS_AUTHFAIL:
729                             report(stdout,_("Query status=3 (AUTHFAIL)\n"));break;
730                         case PS_PROTOCOL:
731                             report(stdout,_("Query status=4 (PROTOCOL)\n"));break;
732                         case PS_SYNTAX:
733                             report(stdout,_("Query status=5 (SYNTAX)\n")); break;
734                         case PS_IOERR:
735                             report(stdout,_("Query status=6 (IOERR)\n"));  break;
736                         case PS_ERROR:
737                             report(stdout,_("Query status=7 (ERROR)\n"));  break;
738                         case PS_EXCLUDE:
739                             report(stdout,_("Query status=8 (EXCLUDE)\n")); break;
740                         case PS_LOCKBUSY:
741                             report(stdout,_("Query status=9 (LOCKBUSY)\n"));break;
742                         case PS_SMTP:
743                             report(stdout,_("Query status=10 (SMTP)\n")); break;
744                         case PS_DNS:
745                             report(stdout,_("Query status=11 (DNS)\n")); break;
746                         case PS_BSMTP:
747                             report(stdout,_("Query status=12 (BSMTP)\n")); break;
748                         case PS_MAXFETCH:
749                             report(stdout,_("Query status=13 (MAXFETCH)\n"));break;
750                         default:
751                             report(stdout,_("Query status=%d\n"),querystatus);
752                             break;
753                         }
754
755 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
756                     if (ctl->server.monitor)
757                     {
758                         /*
759                          * Allow some time for the link to quiesce.  One
760                          * second is usually sufficient, three is safe.
761                          * Note:  this delay is important - don't remove!
762                          */
763                         sleep(3);
764                         interface_note_activity(&ctl->server);
765                     }
766 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
767                 }
768             }
769
770 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
771         endhostent();           /* release TCP/IP connection to nameserver */
772 #endif /* HAVE_RES_SEARCH */
773
774         /* close connections cleanly */
775         terminate_poll(0);
776
777         /*
778          * OK, we've polled.  Now sleep.
779          */
780         if (run.poll_interval)
781         {
782             /* 
783              * Because passwords can expire, it may happen that *all*
784              * hosts are now out of the loop due to authfail
785              * conditions.  If this happens daemon-mode fetchmail
786              * should softly and silently vanish away, rather than
787              * spinning uselessly.
788              */
789             int unwedged = 0;
790
791             for (ctl = querylist; ctl; ctl = ctl->next)
792                 if (ctl->active && !(implicitmode && ctl->server.skip))
793                     if (!ctl->wedged)
794                         unwedged++;
795             if (!unwedged)
796             {
797                 report(stderr, _("All connections are wedged.  Exiting.\n"));
798                 /* FIXME: someday, send notification mail */
799                 exit(PS_AUTHFAIL);
800             }
801
802             if (outlevel >= O_VERBOSE)
803                 report(stdout, 
804                        _("fetchmail: sleeping at %s\n"), timestamp());
805
806             /*
807              * OK, now pause util it's time for the next poll cycle.
808              * A nonzero return indicates we received a wakeup signal;
809              * unwedge all servers in case the problem has been
810              * manually repaired.
811              */
812             if ((lastsig = interruptible_idle(run.poll_interval)))
813             {
814 #ifdef SYS_SIGLIST_DECLARED
815                 report(stdout, 
816                        _("awakened by %s\n"), sys_siglist[lastsig]);
817 #else
818                 report(stdout, 
819                        _("awakened by signal %d\n"), lastsig);
820 #endif
821                 for (ctl = querylist; ctl; ctl = ctl->next)
822                     ctl->wedged = FALSE;
823             }
824
825             if (outlevel >= O_VERBOSE)
826                 report(stdout, _("awakened at %s\n"), timestamp());
827         }
828     } while
829         (run.poll_interval);
830
831     if (outlevel >= O_VERBOSE)
832         report(stdout, _("normal termination, status %d\n"),
833                 successes ? PS_SUCCESS : querystatus);
834
835     terminate_run(0);
836     exit(successes ? PS_SUCCESS : querystatus);
837 }
838
839 static void list_merge(struct idlist **dstl, struct idlist **srcl, int force)
840 {
841     /*
842      * If force is off, modify dstl fields only when they're empty (treat srcl
843      * as defaults).  If force is on, modify each dstl field whenever scrcl
844      * is nonempty (treat srcl as an override).  
845      */
846     if (force ? !!*srcl : !*dstl)
847     {
848         struct idlist *cpl = copy_str_list(*srcl);
849
850         append_str_list(dstl, &cpl);
851     }
852 }
853
854 static void optmerge(struct query *h2, struct query *h1, int force)
855 /* merge two options records */
856 {
857     list_merge(&h2->server.localdomains, &h1->server.localdomains, force);
858     list_merge(&h2->localnames, &h1->localnames, force);
859     list_merge(&h2->mailboxes, &h1->mailboxes, force);
860     list_merge(&h2->smtphunt, &h1->smtphunt, force);
861     list_merge(&h2->antispam, &h1->antispam, force);
862
863 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
864     FLAG_MERGE(server.via);
865     FLAG_MERGE(server.protocol);
866 #if INET6_ENABLE
867     FLAG_MERGE(server.service);
868     FLAG_MERGE(server.netsec);
869 #else /* INET6_ENABLE */
870     FLAG_MERGE(server.port);
871 #endif /* INET6_ENABLE */
872     FLAG_MERGE(server.interval);
873     FLAG_MERGE(server.preauthenticate);
874     FLAG_MERGE(server.timeout);
875     FLAG_MERGE(server.envelope);
876     FLAG_MERGE(server.envskip);
877     FLAG_MERGE(server.qvirtual);
878     FLAG_MERGE(server.skip);
879     FLAG_MERGE(server.dns);
880     FLAG_MERGE(server.checkalias);
881     FLAG_MERGE(server.uidl);
882     FLAG_MERGE(server.principal);
883
884 #if defined(linux) || defined(__FreeBSD__)
885     FLAG_MERGE(server.interface);
886     FLAG_MERGE(server.monitor);
887     FLAG_MERGE(server.interface_pair);
888 #endif /* linux || defined(__FreeBSD__) */
889
890     FLAG_MERGE(server.plugin);
891     FLAG_MERGE(server.plugout);
892
893     FLAG_MERGE(wildcard);
894     FLAG_MERGE(remotename);
895     FLAG_MERGE(password);
896     FLAG_MERGE(mda);
897     FLAG_MERGE(bsmtp);
898     FLAG_MERGE(listener);
899     FLAG_MERGE(smtpaddress);
900     FLAG_MERGE(smtpname);
901     FLAG_MERGE(preconnect);
902     FLAG_MERGE(postconnect);
903
904     FLAG_MERGE(keep);
905     FLAG_MERGE(flush);
906     FLAG_MERGE(fetchall);
907     FLAG_MERGE(rewrite);
908     FLAG_MERGE(forcecr);
909     FLAG_MERGE(stripcr);
910     FLAG_MERGE(pass8bits);
911     FLAG_MERGE(dropstatus);
912     FLAG_MERGE(dropdelivered);
913     FLAG_MERGE(mimedecode);
914     FLAG_MERGE(idle);
915     FLAG_MERGE(limit);
916     FLAG_MERGE(warnings);
917     FLAG_MERGE(fetchlimit);
918     FLAG_MERGE(batchlimit);
919 #ifdef  SSL_ENABLE
920     FLAG_MERGE(use_ssl);
921     FLAG_MERGE(sslkey);
922     FLAG_MERGE(sslcert);
923 #endif
924     FLAG_MERGE(expunge);
925
926     FLAG_MERGE(properties);
927 #undef FLAG_MERGE
928 }
929
930 static int load_params(int argc, char **argv, int optind)
931 {
932     int implicitmode, st;
933     struct passwd *pw;
934     struct query def_opts, *ctl;
935     struct stat rcstat;
936
937     run.bouncemail = TRUE;
938     run.spambounce = FALSE;     /* don't bounce back to innocent bystanders */
939
940     memset(&def_opts, '\0', sizeof(struct query));
941     def_opts.smtp_socket = -1;
942     def_opts.smtpaddress = (char *)0;
943     def_opts.smtpname = (char *)0;
944 #define ANTISPAM(n)     save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
945     ANTISPAM(571);      /* sendmail */
946     ANTISPAM(550);      /* old exim */
947     ANTISPAM(501);      /* new exim */
948     ANTISPAM(554);      /* Postfix */
949 #undef ANTISPAM
950
951     def_opts.server.protocol = P_AUTO;
952     def_opts.server.timeout = CLIENT_TIMEOUT;
953     def_opts.warnings = WARNING_INTERVAL;
954     def_opts.remotename = user;
955     def_opts.listener = SMTP_MODE;
956
957     /* note the parse time, so we can pick up on modifications */
958     parsetime = 0;      /* foil compiler warnings */
959     if (stat(rcfile, &rcstat) != -1)
960         parsetime = rcstat.st_mtime;
961     else if (errno != ENOENT)
962         report(stderr, _("couldn't time-check the run-control file\n"));
963
964     /* this builds the host list */
965     if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
966         /*
967          * FIXME: someday, send notification mail here if backgrounded.
968          * Right now, that can happen if the user changes the rcfile
969          * while the fetchmail is running in background.  Do similarly
970          * for the other exit() calls in this function.
971          */
972         exit(st);
973
974     if ((implicitmode = (optind >= argc)))
975     {
976         for (ctl = querylist; ctl; ctl = ctl->next)
977             ctl->active = TRUE;
978     }
979     else
980         for (; optind < argc; optind++) 
981         {
982             flag        predeclared =  FALSE;
983
984             /*
985              * If hostname corresponds to a host known from the rc file,
986              * simply declare it active.  Otherwise synthesize a host
987              * record from command line and defaults
988              */
989             for (ctl = querylist; ctl; ctl = ctl->next)
990                 if (!strcmp(ctl->server.pollname, argv[optind])
991                         || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
992                 {
993                     /* Is this correct? */
994                     if (predeclared && outlevel == O_VERBOSE)
995                         fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
996                     ctl->active = TRUE;
997                     predeclared = TRUE;
998                 }
999
1000             if (!predeclared)
1001             {
1002                 /*
1003                  * Allocate and link record without copying in
1004                  * command-line args; we'll do that with the optmerge
1005                  * call later on.
1006                  */
1007                 ctl = hostalloc((struct query *)NULL);
1008                 ctl->server.via =
1009                     ctl->server.pollname = xstrdup(argv[optind]);
1010                 ctl->active = TRUE;
1011                 ctl->server.lead_server = (struct hostdata *)NULL;
1012             }
1013         }
1014
1015     /*
1016      * If there's a defaults record, merge it and lose it.
1017      */ 
1018     if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
1019     {
1020         for (ctl = querylist->next; ctl; ctl = ctl->next)
1021             optmerge(ctl, querylist, FALSE);
1022         querylist = querylist->next;
1023     }
1024
1025     /* don't allow a defaults record after the first */
1026     for (ctl = querylist; ctl; ctl = ctl->next)
1027         if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
1028             exit(PS_SYNTAX);
1029
1030     /* use localhost if we never fetch the FQDN of this host */
1031     fetchmailhost = "localhost";
1032
1033     /* here's where we override globals */
1034     if (cmd_run.logfile)
1035         run.logfile = cmd_run.logfile;
1036     if (cmd_run.idfile)
1037         run.idfile = cmd_run.idfile;
1038     /* do this before the keep/fetchall test below, otherwise -d0 may fail */
1039     if (cmd_run.poll_interval >= 0)
1040         run.poll_interval = cmd_run.poll_interval;
1041     if (cmd_run.invisible)
1042         run.invisible = cmd_run.invisible;
1043     if (cmd_run.showdots)
1044         run.showdots = cmd_run.showdots;
1045     if (cmd_run.use_syslog)
1046         run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
1047     if (cmd_run.postmaster)
1048         run.postmaster = cmd_run.postmaster;
1049     if (cmd_run.bouncemail)
1050         run.bouncemail = cmd_run.bouncemail;
1051
1052     /* check and daemon options are not compatible */
1053     if (check_only && run.poll_interval)
1054         run.poll_interval = 0;
1055
1056     /* merge in wired defaults, do sanity checks and prepare internal fields */
1057     for (ctl = querylist; ctl; ctl = ctl->next)
1058     {
1059         ctl->wedged = FALSE;
1060
1061         if (configdump || ctl->active )
1062         {
1063             /* merge in defaults */
1064             optmerge(ctl, &def_opts, FALSE);
1065
1066             /* force command-line options */
1067             optmerge(ctl, &cmd_opts, TRUE);
1068
1069             /* this code enables flags to be turned off */
1070 #define DEFAULT(flag, dflt)     if (flag == FLAG_TRUE)\
1071                                         flag = TRUE;\
1072                                 else if (flag == FLAG_FALSE)\
1073                                         flag = FALSE;\
1074                                 else\
1075                                         flag = (dflt)
1076             DEFAULT(ctl->keep, FALSE);
1077             DEFAULT(ctl->fetchall, FALSE);
1078             DEFAULT(ctl->flush, FALSE);
1079             DEFAULT(ctl->rewrite, TRUE);
1080             DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL)); 
1081             DEFAULT(ctl->forcecr, FALSE);
1082             DEFAULT(ctl->pass8bits, FALSE);
1083             DEFAULT(ctl->dropstatus, FALSE);
1084             DEFAULT(ctl->dropdelivered, FALSE);
1085             DEFAULT(ctl->mimedecode, FALSE);
1086             DEFAULT(ctl->idle, FALSE);
1087             DEFAULT(ctl->server.dns, TRUE);
1088             DEFAULT(ctl->server.uidl, FALSE);
1089 #ifdef  SSL_ENABLE
1090             DEFAULT(ctl->use_ssl, FALSE);
1091 #endif
1092             DEFAULT(ctl->server.checkalias, FALSE);
1093 #undef DEFAULT
1094
1095             /*
1096              * DNS support is required for some protocols.  We used to
1097              * do this unconditionally, but it made fetchmail excessively
1098              * vulnerable to misconfigured DNS setups.
1099              *
1100              * If we're using ETRN or ODMR, the smtp hunt list is the
1101              * list of systems we're polling on behalf of; these have
1102              * to be fully-qualified domain names.  The default for
1103              * this list should be the FQDN of localhost.
1104              *
1105              * If we're using Kerberos for authentication, we need 
1106              * the FQDN in order to generate capability keys.  */
1107             if (ctl->server.protocol == P_ETRN
1108 #ifdef ODMR_ENABLE 
1109                          || ctl->server.protocol == P_ODMR
1110 #endif /* ODMR_ENABLE */
1111                          || ctl->server.preauthenticate == A_KERBEROS_V4
1112                          || ctl->server.preauthenticate == A_KERBEROS_V5)
1113                 if (strcmp(fetchmailhost, "localhost") == 0)
1114                         fetchmailhost = host_fqdn();
1115
1116             /*
1117              * Make sure we have a nonempty host list to forward to.
1118              */
1119             if (!ctl->smtphunt)
1120                 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1121
1122             /* if `user' doesn't name a real local user, try to run as root */
1123             if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1124                 ctl->uid = 0;
1125             else
1126                 ctl->uid = pw->pw_uid;  /* for local delivery via MDA */
1127             if (!ctl->localnames)       /* for local delivery via SMTP */
1128                 save_str_pair(&ctl->localnames, user, NULL);
1129
1130 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1131             /* can't handle multidrop mailboxes unless we can do DNS lookups */
1132             if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1133             {
1134                 ctl->server.dns = FALSE;
1135                 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1136             }
1137 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1138
1139             /*
1140              *
1141              * Compute the true name of the mailserver host.  
1142              * There are two clashing cases here:
1143              *
1144              * (1) The poll name is a label, possibly on one of several
1145              *     poll configurations for the same host.  In this case 
1146              *     the `via' option will be present and give the true name.
1147              *
1148              * (2) The poll name is the true one, the via name is 
1149              *     localhost.   This is going to be typical for ssh-using
1150              *     configurations.
1151              *
1152              * We're going to assume the via name is true unless it's
1153              * localhost.
1154              */
1155             if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1156                 ctl->server.queryname = xstrdup(ctl->server.via);
1157             else
1158                 ctl->server.queryname = xstrdup(ctl->server.pollname);
1159
1160 #ifdef HESIOD
1161         /* If either the pollname or vianame are "hesiod" we want to
1162            lookup the user's hesiod pobox host */
1163
1164         if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1165             struct hes_postoffice *hes_p;
1166             hes_p = hes_getmailhost(ctl->remotename);
1167             if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1168                  free(ctl->server.queryname);
1169                  ctl->server.queryname = xstrdup(hes_p->po_host);
1170                  if (ctl->server.via)
1171                      free(ctl->server.via);
1172                  ctl->server.via = xstrdup(hes_p->po_host);
1173             } else {
1174                  report(stderr,
1175                         _("couldn't find HESIOD pobox for %s\n"),
1176                         ctl->remotename);
1177             }
1178         }
1179 #endif /* HESIOD */
1180
1181             /*
1182              * We may have to canonicalize the server truename for later use.
1183              * Do this just once for each lead server, if necessary, in order
1184              * to minimize DNS round trips.
1185              */
1186             if (ctl->server.lead_server)
1187             {
1188                 char    *leadname = ctl->server.lead_server->truename;
1189
1190                 /* prevent core dump from ill-formed or duplicate entry */
1191                 if (!leadname)
1192                 {
1193                     report(stderr, _("Lead server has no name.\n"));
1194                     exit(PS_SYNTAX);
1195                 }
1196
1197                 ctl->server.truename = xstrdup(leadname);
1198             }
1199 #ifdef HAVE_GETHOSTBYNAME
1200             else if (!configdump)
1201             {
1202                 if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1203                       ctl->server.preauthenticate==A_KERBEROS_V5 ||
1204                     (ctl->server.dns && MULTIDROP(ctl)))
1205                 {
1206                     struct hostent      *namerec;
1207
1208                     /* compute the canonical name of the host */
1209                     errno = 0;
1210                     namerec = gethostbyname(ctl->server.queryname);
1211                     if (namerec == (struct hostent *)NULL)
1212                     {
1213                         report(stderr,
1214                                _("couldn't find canonical DNS name of %s\n"),
1215                                ctl->server.pollname);
1216                         ctl->server.truename = xstrdup(ctl->server.queryname);
1217                         ctl->server.trueaddr = NULL;
1218                     }
1219                     else
1220                         ctl->server.truename=xstrdup((char *)namerec->h_name);
1221                 }
1222 #endif /* HAVE_GETHOSTBYNAME */
1223                 else {
1224 #ifdef HAVE_GETHOSTBYNAME
1225                     struct hostent      *namerec;
1226                     
1227                     /* <fetchmail@mail.julianhaight.com>
1228                        Get the host's IP, so we can report it like this:
1229
1230                        Received: from hostname [10.0.0.1]
1231
1232                        do we actually need to gethostbyname to find the IP?
1233                        it seems like it would be faster to do this later, when
1234                        we are actually resolving the hostname for a connection,
1235                        but I ain't that smart, so I don't know where to make
1236                        the change later..
1237                     */
1238                     errno = 0;
1239                     namerec = gethostbyname(ctl->server.queryname);
1240                     if (namerec == (struct hostent *)NULL)
1241                     {
1242                         report(stderr,
1243                                _("couldn't find canonical DNS name of %s\n"),
1244                                ctl->server.pollname);
1245                         exit(PS_DNS);
1246                     }
1247                     else {
1248                         ctl->server.truename=xstrdup((char *)namerec->h_name);
1249                         ctl->server.trueaddr=xmalloc(namerec->h_length);
1250                         memcpy(ctl->server.trueaddr, 
1251                                namerec->h_addr_list[0],
1252                                namerec->h_length);
1253                     }
1254 #else
1255                     ctl->server.truename = xstrdup(ctl->server.queryname);
1256 #endif /* HAVE_GETHOSTBYNAME */
1257                 }
1258             }
1259
1260             /* if no folders were specified, set up the null one as default */
1261             if (!ctl->mailboxes)
1262                 save_str(&ctl->mailboxes, (char *)NULL, 0);
1263
1264             /* maybe user overrode timeout on command line? */
1265             if (ctl->server.timeout == -1)      
1266                 ctl->server.timeout = CLIENT_TIMEOUT;
1267
1268 #if !INET6_ENABLE
1269             /* sanity checks */
1270             if (ctl->server.port < 0)
1271             {
1272                 (void) fprintf(stderr,
1273                                _("%s configuration invalid, port number cannot be negative\n"),
1274                                ctl->server.pollname);
1275                 exit(PS_SYNTAX);
1276             }
1277             if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1278             {
1279                 (void) fprintf(stderr,
1280                                _("%s configuration invalid, RPOP requires a privileged port\n"),
1281                                ctl->server.pollname);
1282                 exit(PS_SYNTAX);
1283             }
1284             if (ctl->listener == LMTP_MODE)
1285             {
1286                 struct idlist   *idp;
1287
1288                 for (idp = ctl->smtphunt; idp; idp = idp->next)
1289                 {
1290                     char        *cp;
1291
1292                     if (!(cp = strrchr(idp->id, '/')) ||
1293                                 (atoi(++cp) == SMTP_PORT))
1294                     {
1295                         (void) fprintf(stderr,
1296                                        _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1297                                        ctl->server.pollname);
1298                         exit(PS_SYNTAX);
1299                     }
1300                 }
1301             }
1302 #endif /* !INET6_ENABLE */
1303
1304             /*
1305              * "I beg to you, have mercy on the week minds like myself."
1306              * wrote Pehr Anderson.  Your petition is granted.
1307              */
1308             if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1309             {
1310                 (void) fprintf(stderr,
1311                                _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1312                 exit(PS_SYNTAX);
1313             }
1314         }
1315     }
1316
1317 #ifdef POP3_ENABLE
1318     /* initialize UID handling */
1319     if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1320         exit(st);
1321     else
1322         initialize_saved_lists(querylist, run.idfile);
1323 #endif /* POP3_ENABLE */
1324
1325     /*
1326      * If the user didn't set a last-resort user to get misaddressed
1327      * multidrop mail, set an appropriate default here.
1328      */
1329     if (!run.postmaster)
1330     {
1331         if (getuid())                           /* ordinary user */
1332             run.postmaster = user;
1333         else                                    /* root */
1334             run.postmaster = "postmaster";
1335     }
1336
1337     return(implicitmode);
1338 }
1339
1340 static void terminate_poll(int sig)
1341 /* to be executed at the end of a poll cycle */
1342 {
1343     /*
1344      * Close all SMTP delivery sockets.  For optimum performance
1345      * we'd like to hold them open til end of run, but (1) this
1346      * loses if our poll interval is longer than the MTA's inactivity
1347      * timeout, and (2) some MTAs (like smail) don't deliver after
1348      * each message, but rather queue up mail and wait to actually
1349      * deliver it until the input socket is closed. 
1350      *
1351      * Sending SMTP QUIT on signal is theoretically nice, but led to a 
1352      * subtle bug.  If fetchmail was terminated by signal while it was 
1353      * shipping message text, it would hang forever waiting for a
1354      * command acknowledge.  In theory we could enable the QUIT
1355      * only outside of the message send.  In practice, we don't
1356      * care.  All mailservers hang up on a dropped TCP/IP connection
1357      * anyway.
1358      */
1359
1360     if (sig != 0)
1361         report(stdout, _("terminated with signal %d\n"), sig);
1362     else
1363     {
1364         struct query *ctl;
1365
1366         /* terminate all SMTP connections cleanly */
1367         for (ctl = querylist; ctl; ctl = ctl->next)
1368             if (ctl->smtp_socket != -1)
1369             {
1370                 SMTP_quit(ctl->smtp_socket);
1371                 SockClose(ctl->smtp_socket);
1372                 ctl->smtp_socket = -1;
1373             }
1374     }
1375
1376 #ifdef POP3_ENABLE
1377     /*
1378      * Update UID information at end of each poll, rather than at end
1379      * of run, because that way we don't lose all UIDL information since
1380      * the beginning of time if fetchmail crashes.
1381      */
1382     if (!check_only)
1383         write_saved_lists(querylist, run.idfile);
1384 #endif /* POP3_ENABLE */
1385 }
1386
1387 static void terminate_run(int sig)
1388 /* to be executed on normal or signal-induced termination */
1389 {
1390     struct query        *ctl;
1391
1392     terminate_poll(sig);
1393
1394     /* 
1395      * Craig Metz, the RFC1938 one-time-password guy, points out:
1396      * "Remember that most kernels don't zero pages before handing them to the
1397      * next process and many kernels share pages between user and kernel space.
1398      * You'd be very surprised what you can find from a short program to do a
1399      * malloc() and then dump the contents of the pages you got. By zeroing
1400      * the secrets at end of run (earlier if you can), you make sure the next
1401      * guy can't get the password/pass phrase."
1402      *
1403      * Right you are, Craig!
1404      */
1405     for (ctl = querylist; ctl; ctl = ctl->next)
1406         if (ctl->password)
1407           memset(ctl->password, '\0', strlen(ctl->password));
1408
1409 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1410     unlockit();
1411 #endif
1412
1413     if (activecount == 0)
1414         exit(PS_NOMAIL);
1415     else
1416         exit(successes ? PS_SUCCESS : querystatus);
1417 }
1418
1419 /*
1420  * Sequence of protocols to try when autoprobing, most capable to least.
1421  */
1422 static const int autoprobe[] = 
1423 {
1424 #ifdef IMAP_ENABLE
1425     P_IMAP,
1426 #endif /* IMAP_ENABLE */
1427 #ifdef POP3_ENABLE
1428     P_POP3,
1429 #endif /* POP3_ENABLE */
1430 #ifdef POP2_ENABLE
1431     P_POP2
1432 #endif /* POP2_ENABLE */
1433 };
1434
1435 static int query_host(struct query *ctl)
1436 /* perform fetch transaction with single host */
1437 {
1438     int i, st;
1439
1440     /*
1441      * If we're syslogging the progress messages are automatically timestamped.
1442      * Force timestamping if we're going to a logfile.
1443      */
1444     if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1445     {
1446         report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1447                VERSION,
1448                ctl->server.pollname,
1449                showproto(ctl->server.protocol),
1450                timestamp());
1451     }
1452     switch (ctl->server.protocol) {
1453     case P_AUTO:
1454         for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1455         {
1456             ctl->server.protocol = autoprobe[i];
1457             if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1458                 break;
1459         }
1460         ctl->server.protocol = P_AUTO;
1461         return(st);
1462     case P_POP2:
1463 #ifdef POP2_ENABLE
1464         return(doPOP2(ctl));
1465 #else
1466         report(stderr, _("POP2 support is not configured.\n"));
1467         return(PS_PROTOCOL);
1468 #endif /* POP2_ENABLE */
1469         break;
1470     case P_POP3:
1471     case P_APOP:
1472     case P_RPOP:
1473 #ifdef POP3_ENABLE
1474         return(doPOP3(ctl));
1475 #else
1476         report(stderr, _("POP3 support is not configured.\n"));
1477         return(PS_PROTOCOL);
1478 #endif /* POP3_ENABLE */
1479         break;
1480     case P_IMAP:
1481     case P_IMAP_K4:
1482     case P_IMAP_CRAM_MD5:
1483     case P_IMAP_LOGIN:
1484 #ifdef GSSAPI
1485     case P_IMAP_GSS:
1486 #endif /* GSSAPI */
1487 #ifdef IMAP_ENABLE
1488         return(doIMAP(ctl));
1489 #else
1490         report(stderr, _("IMAP support is not configured.\n"));
1491         return(PS_PROTOCOL);
1492 #endif /* IMAP_ENABLE */
1493     case P_ETRN:
1494 #ifndef ETRN_ENABLE
1495         report(stderr, _("ETRN support is not configured.\n"));
1496         return(PS_PROTOCOL);
1497 #else
1498 #ifdef HAVE_GETHOSTBYNAME
1499         return(doETRN(ctl));
1500 #else
1501         report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1502         return(PS_PROTOCOL);
1503 #endif /* HAVE_GETHOSTBYNAME */
1504 #endif /* ETRN_ENABLE */
1505     case P_ODMR:
1506 #ifndef ODMR_ENABLE
1507         report(stderr, _("ODMR support is not configured.\n"));
1508         return(PS_PROTOCOL);
1509 #else
1510 #ifdef HAVE_GETHOSTBYNAME
1511         return(doODMR(ctl));
1512 #else
1513         report(stderr, _("Cannot support ODMR without gethostbyname(2).\n"));
1514         return(PS_PROTOCOL);
1515 #endif /* HAVE_GETHOSTBYNAME */
1516 #endif /* ODMR_ENABLE */
1517     default:
1518         report(stderr, _("unsupported protocol selected.\n"));
1519         return(PS_PROTOCOL);
1520     }
1521 }
1522
1523 static void dump_params (struct runctl *runp,
1524                          struct query *querylist, flag implicit)
1525 /* display query parameters in English */
1526 {
1527     struct query *ctl;
1528
1529     if (runp->poll_interval)
1530         printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1531     if (runp->logfile)
1532         printf(_("Logfile is %s\n"), runp->logfile);
1533     if (strcmp(runp->idfile, IDFILE_NAME))
1534         printf(_("Idfile is %s\n"), runp->idfile);
1535 #if defined(HAVE_SYSLOG)
1536     if (runp->use_syslog)
1537         printf(_("Progress messages will be logged via syslog\n"));
1538 #endif
1539     if (runp->invisible)
1540         printf(_("Fetchmail will masquerade and will not generate Received\n"));
1541     if (runp->showdots)
1542         printf(_("Fetchmail will show progress dots even in logfiles.\n"));
1543     if (runp->postmaster)
1544         printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1545                runp->postmaster);
1546
1547     if (!runp->bouncemail)
1548         printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1549     else if (outlevel >= O_VERBOSE)
1550         printf(_("Fetchmail will direct error mail to the sender.\n"));
1551
1552     for (ctl = querylist; ctl; ctl = ctl->next)
1553     {
1554         if (!ctl->active || (implicit && ctl->server.skip))
1555             continue;
1556
1557         printf(_("Options for retrieving from %s@%s:\n"),
1558                ctl->remotename, visbuf(ctl->server.pollname));
1559
1560         if (ctl->server.via && (ctl->server.protocol < P_ETRN))
1561             printf(_("  Mail will be retrieved via %s\n"), ctl->server.via);
1562
1563         if (ctl->server.interval)
1564             printf(_("  Poll of this server will occur every %d intervals.\n"),
1565                    ctl->server.interval);
1566         if (ctl->server.truename)
1567             printf(_("  True name of server is %s.\n"), ctl->server.truename);
1568         if (ctl->server.skip || outlevel >= O_VERBOSE)
1569             printf(_("  This host %s be queried when no host is specified.\n"),
1570                    ctl->server.skip ? _("will not") : _("will"));
1571         /*
1572          * Don't poll for password when there is one or when using the ETRN
1573          * or IMAP-GSS protocol
1574          */
1575         /* ETRN, IMAP_GSS, and IMAP_K4 do not need a password, so skip this */
1576         if ( (ctl->server.protocol != P_ETRN)
1577 #ifdef GSSAPI
1578                                 && (ctl->server.protocol != P_IMAP_GSS)
1579 #endif /* GSSAPI */
1580                                 && (ctl->server.protocol != P_IMAP_K4) ) {
1581                 if (!ctl->password)
1582                         printf(_("  Password will be prompted for.\n"));
1583                 else if (outlevel >= O_VERBOSE)
1584                 {
1585                         if (ctl->server.protocol == P_APOP)
1586                                 printf(_("  APOP secret = \"%s\".\n"),
1587                                                         visbuf(ctl->password));
1588                         else if (ctl->server.protocol == P_RPOP)
1589                                 printf(_("  RPOP id = \"%s\".\n"),
1590                                                         visbuf(ctl->password));
1591                         else
1592                                 printf(_("  Password = \"%s\".\n"),
1593                                                         visbuf(ctl->password));
1594                 }
1595         }
1596
1597         if (ctl->server.protocol == P_POP3 
1598 #if INET6_ENABLE
1599             && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1600 #else /* INET6_ENABLE */
1601             && ctl->server.port == KPOP_PORT
1602 #endif /* INET6_ENABLE */
1603             && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1604                 ctl->server.preauthenticate == A_KERBEROS_V5))
1605             printf(_("  Protocol is KPOP with Kerberos %s authentication"),
1606                    ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1607         else
1608             printf(_("  Protocol is %s"), showproto(ctl->server.protocol));
1609 #if INET6_ENABLE
1610         if (ctl->server.service)
1611             printf(_(" (using service %s)"), ctl->server.service);
1612         if (ctl->server.netsec)
1613             printf(_(" (using network security options %s)"), ctl->server.netsec);
1614 #else /* INET6_ENABLE */
1615         if (ctl->server.port)
1616             printf(_(" (using port %d)"), ctl->server.port);
1617 #endif /* INET6_ENABLE */
1618         else if (outlevel >= O_VERBOSE)
1619             printf(_(" (using default port)"));
1620         if (ctl->server.uidl && (ctl->server.protocol < P_ETRN))
1621             printf(_(" (forcing UIDL use)"));
1622         putchar('.');
1623         putchar('\n');
1624         if (ctl->server.preauthenticate == A_KERBEROS_V4)
1625             printf(_("  Kerberos V4 preauthentication enabled.\n"));
1626         else if (ctl->server.preauthenticate == A_KERBEROS_V5)
1627             printf(_("  Kerberos V5 preauthentication enabled.\n"));
1628         else if (ctl->server.preauthenticate == A_SSH)
1629             printf(_("  End-to-end encryption assumed.\n"));
1630         if (ctl->server.principal != (char *) NULL) {
1631             printf(_("  Mail service principal is: %s\n"), ctl->server.principal);
1632         }
1633 #ifdef  SSL_ENABLE
1634         if (ctl->use_ssl)
1635             printf("  SSL encrypted sessions enabled.\n");
1636 #endif
1637         if (ctl->server.timeout > 0)
1638             printf(_("  Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1639         if (ctl->server.timeout ==  CLIENT_TIMEOUT)
1640             printf(_(" (default).\n"));
1641         else
1642             printf(".\n");
1643
1644         if (ctl->server.protocol < P_ETRN) {
1645                 if (!ctl->mailboxes->id)
1646                     printf(_("  Default mailbox selected.\n"));
1647                 else
1648                 {
1649                     struct idlist *idp;
1650
1651                     printf(_("  Selected mailboxes are:"));
1652                     for (idp = ctl->mailboxes; idp; idp = idp->next)
1653                         printf(" %s", idp->id);
1654                     printf("\n");
1655                 }
1656                 printf(_("  %s messages will be retrieved (--all %s).\n"),
1657                        ctl->fetchall ? _("All") : _("Only new"),
1658                        ctl->fetchall ? "on" : "off");
1659                 printf(_("  Fetched messages %s be kept on the server (--keep %s).\n"),
1660                        ctl->keep ? _("will") : _("will not"),
1661                        ctl->keep ? "on" : "off");
1662                 printf(_("  Old messages %s be flushed before message retrieval (--flush %s).\n"),
1663                        ctl->flush ? _("will") : _("will not"),
1664                        ctl->flush ? "on" : "off");
1665                 printf(_("  Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1666                        ctl->rewrite ? _("enabled") : _("disabled"),
1667                        ctl->rewrite ? "off" : "on");
1668                 printf(_("  Carriage-return stripping is %s (stripcr %s).\n"),
1669                        ctl->stripcr ? _("enabled") : _("disabled"),
1670                        ctl->stripcr ? "on" : "off");
1671                 printf(_("  Carriage-return forcing is %s (forcecr %s).\n"),
1672                        ctl->forcecr ? _("enabled") : _("disabled"),
1673                        ctl->forcecr ? "on" : "off");
1674                 printf(_("  Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1675                        ctl->pass8bits ? _("disabled") : _("enabled"),
1676                        ctl->pass8bits ? "on" : "off");
1677                 printf(_("  MIME decoding is %s (mimedecode %s).\n"),
1678                        ctl->mimedecode ? _("enabled") : _("disabled"),
1679                        ctl->mimedecode ? "on" : "off");
1680                 printf(_("  Idle after poll is %s (idle %s).\n"),
1681                        ctl->idle ? _("enabled") : _("disabled"),
1682                        ctl->idle ? "on" : "off");
1683                 printf(_("  Nonempty Status lines will be %s (dropstatus %s)\n"),
1684                        ctl->dropstatus ? _("discarded") : _("kept"),
1685                        ctl->dropstatus ? "on" : "off");
1686                 printf(_("  Delivered-To lines will be %s (dropdelivered %s)\n"),
1687                        ctl->dropdelivered ? _("discarded") : _("kept"),
1688                        ctl->dropdelivered ? "on" : "off");
1689                 if (NUM_NONZERO(ctl->limit))
1690                 {
1691                     if (NUM_NONZERO(ctl->limit))
1692                         printf(_("  Message size limit is %d octets (--limit %d).\n"), 
1693                                ctl->limit, ctl->limit);
1694                     else if (outlevel >= O_VERBOSE)
1695                         printf(_("  No message size limit (--limit 0).\n"));
1696                     if (run.poll_interval > 0)
1697                         printf(_("  Message size warning interval is %d seconds (--warnings %d).\n"), 
1698                                ctl->warnings, ctl->warnings);
1699                     else if (outlevel >= O_VERBOSE)
1700                         printf(_("  Size warnings on every poll (--warnings 0).\n"));
1701                 }
1702                 if (NUM_NONZERO(ctl->fetchlimit))
1703                     printf(_("  Received-message limit is %d (--fetchlimit %d).\n"),
1704                            ctl->fetchlimit, ctl->fetchlimit);
1705                 else if (outlevel >= O_VERBOSE)
1706                     printf(_("  No received-message limit (--fetchlimit 0).\n"));
1707                 if (NUM_NONZERO(ctl->batchlimit))
1708                     printf(_("  SMTP message batch limit is %d.\n"), ctl->batchlimit);
1709                 else if (outlevel >= O_VERBOSE)
1710                     printf(_("  No SMTP message batch limit (--batchlimit 0).\n"));
1711                 if (ctl->server.protocol < P_ETRN)
1712                 {
1713                     if (NUM_NONZERO(ctl->expunge))
1714                         printf(_("  Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1715                     else if (outlevel >= O_VERBOSE)
1716                         printf(_("  No forced expunges (--expunge 0).\n"));
1717                 }
1718         }
1719         if (ctl->bsmtp)
1720             printf(_("  Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1721         else if (ctl->mda && (ctl->server.protocol < P_ETRN))
1722             printf(_("  Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1723         else
1724         {
1725             struct idlist *idp;
1726
1727             printf(_("  Messages will be %cMTP-forwarded to:"), ctl->listener);
1728             for (idp = ctl->smtphunt; idp; idp = idp->next)
1729             {
1730                 printf(" %s", idp->id);
1731                 if (!idp->val.status.mark)
1732                     printf(_(" (default)"));
1733             }
1734             printf("\n");
1735             if (ctl->smtpaddress)
1736                 printf(_("  Host part of MAIL FROM line will be %s\n"),
1737                        ctl->smtpaddress);
1738             if (ctl->smtpname)
1739                 printf(_("  Address to be put in RCPT TO lines shipped to SMTP will be %s\n"),
1740                        ctl->smtpname);
1741         }
1742         if (ctl->server.protocol < P_ETRN)
1743         {
1744                 if (ctl->antispam != (struct idlist *)NULL)
1745                 {
1746                     struct idlist *idp;
1747
1748                     printf(_("  Recognized listener spam block responses are:"));
1749                     for (idp = ctl->antispam; idp; idp = idp->next)
1750                         printf(" %d", idp->val.status.num);
1751                     printf("\n");
1752                 }
1753                 else if (outlevel >= O_VERBOSE)
1754                     printf(_("  Spam-blocking disabled\n"));
1755         }
1756         if (ctl->preconnect)
1757             printf(_("  Server connection will be brought up with \"%s\".\n"),
1758                    visbuf(ctl->preconnect));
1759         else if (outlevel >= O_VERBOSE)
1760             printf(_("  No pre-connection command.\n"));
1761         if (ctl->postconnect)
1762             printf(_("  Server connection will be taken down with \"%s\".\n"),
1763                    visbuf(ctl->postconnect));
1764         else if (outlevel >= O_VERBOSE)
1765             printf(_("  No post-connection command.\n"));
1766         if (ctl->server.protocol < P_ETRN) {
1767                 if (!ctl->localnames)
1768                     printf(_("  No localnames declared for this host.\n"));
1769                 else
1770                 {
1771                     struct idlist *idp;
1772                     int count = 0;
1773
1774                     for (idp = ctl->localnames; idp; idp = idp->next)
1775                         ++count;
1776
1777                     if (count > 1 || ctl->wildcard)
1778                         printf(_("  Multi-drop mode: "));
1779                     else
1780                         printf(_("  Single-drop mode: "));
1781
1782                     printf(_("%d local name(s) recognized.\n"), count);
1783                     if (outlevel >= O_VERBOSE)
1784                     {
1785                         for (idp = ctl->localnames; idp; idp = idp->next)
1786                             if (idp->val.id2)
1787                                 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1788                             else
1789                                 printf("\t%s\n", idp->id);
1790                         if (ctl->wildcard)
1791                             fputs("\t*\n", stdout);
1792                     }
1793
1794                     if (count > 1 || ctl->wildcard)
1795                     {
1796                         printf(_("  DNS lookup for multidrop addresses is %s.\n"),
1797                                ctl->server.dns ? _("enabled") : _("disabled"));
1798                         if (ctl->server.dns)
1799                         {
1800                             printf(_("  Server aliases will be compared with multidrop addresses by "));
1801                             if (ctl->server.checkalias)
1802                                 printf(_("IP address.\n"));
1803                             else
1804                                 printf(_("name.\n"));
1805                         }
1806                         if (ctl->server.envelope == STRING_DISABLED)
1807                             printf(_("  Envelope-address routing is disabled\n"));
1808                         else
1809                         {
1810                             printf(_("  Envelope header is assumed to be: %s\n"),
1811                                    ctl->server.envelope ? ctl->server.envelope:_("Received"));
1812                             if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1813                                 printf(_("  Number of envelope header to be parsed: %d\n"),
1814                                        ctl->server.envskip);
1815                             if (ctl->server.qvirtual)
1816                                 printf(_("  Prefix %s will be removed from user id\n"),
1817                                        ctl->server.qvirtual);
1818                             else if (outlevel >= O_VERBOSE) 
1819                                 printf(_("  No prefix stripping\n"));
1820                         }
1821
1822                         if (ctl->server.akalist)
1823                         {
1824                             struct idlist *idp;
1825
1826                             printf(_("  Predeclared mailserver aliases:"));
1827                             for (idp = ctl->server.akalist; idp; idp = idp->next)
1828                                 printf(" %s", idp->id);
1829                             putchar('\n');
1830                         }
1831                         if (ctl->server.localdomains)
1832                         {
1833                             struct idlist *idp;
1834
1835                             printf(_("  Local domains:"));
1836                             for (idp = ctl->server.localdomains; idp; idp = idp->next)
1837                                 printf(" %s", idp->id);
1838                             putchar('\n');
1839                         }
1840                     }
1841                 }
1842         }
1843 #if defined(linux) || defined(__FreeBSD__)
1844         if (ctl->server.interface)
1845             printf(_("  Connection must be through interface %s.\n"), ctl->server.interface);
1846         else if (outlevel >= O_VERBOSE)
1847             printf(_("  No interface requirement specified.\n"));
1848         if (ctl->server.monitor)
1849             printf(_("  Polling loop will monitor %s.\n"), ctl->server.monitor);
1850         else if (outlevel >= O_VERBOSE)
1851             printf(_("  No monitor interface specified.\n"));
1852 #endif
1853
1854         if (ctl->server.plugin)
1855             printf(_("  Server connections will be made via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1856         else if (outlevel >= O_VERBOSE)
1857             printf(_("  No plugin command specified.\n"));
1858         if (ctl->server.plugout)
1859             printf(_("  Listener connections will be made via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1860         else if (outlevel >= O_VERBOSE)
1861             printf(_("  No plugout command specified.\n"));
1862
1863         if (ctl->server.protocol > P_POP2 && (ctl->server.protocol < P_ETRN))
1864         {
1865             if (!ctl->oldsaved)
1866                 printf(_("  No UIDs saved from this host.\n"));
1867             else
1868             {
1869                 struct idlist *idp;
1870                 int count = 0;
1871
1872                 for (idp = ctl->oldsaved; idp; idp = idp->next)
1873                     ++count;
1874
1875                 printf(_("  %d UIDs saved.\n"), count);
1876                 if (outlevel >= O_VERBOSE)
1877                     for (idp = ctl->oldsaved; idp; idp = idp->next)
1878                         printf("\t%s\n", idp->id);
1879             }
1880         }
1881
1882         if (ctl->properties)
1883             printf(_("  Pass-through properties \"%s\".\n"),
1884                    visbuf(ctl->properties));
1885     }
1886 }
1887
1888 /* fetchmail.c ends here */