]> Pileus Git - ~andy/fetchmail/blob - options.c
c51e9d7257a45dab86901cb7e186a29d5d74e8b4
[~andy/fetchmail] / options.c
1 /*
2  * options.c -- command-line option processing
3  *
4  * Copyright 1998 by Eric S. Raymond.
5  * For license terms, see the file COPYING in this directory.
6  */
7
8 #include "config.h"
9
10 #include <stdio.h>
11 #include <pwd.h>
12 #include <string.h>
13 #include <errno.h>
14 #if defined(STDC_HEADERS)
15 #include  <stdlib.h>
16 #include  <limits.h>
17 #else
18 #include  <ctype.h>
19 #endif
20
21 #include "getopt.h"
22 #include "fetchmail.h"
23 #include "i18n.h"
24
25 #define LA_HELP         1
26 #define LA_VERSION      2 
27 #define LA_CHECK        3
28 #define LA_SILENT       4 
29 #define LA_VERBOSE      5 
30 #define LA_DAEMON       6
31 #define LA_NODETACH     7
32 #define LA_QUIT         8
33 #define LA_LOGFILE      9
34 #define LA_INVISIBLE    10
35 #define LA_SYSLOG       11
36 #define LA_NOSYSLOG     12
37 #define LA_RCFILE       13
38 #define LA_IDFILE       14
39 #define LA_POSTMASTER   15
40 #define LA_NOBOUNCE     16
41 #define LA_PROTOCOL     17
42 #define LA_UIDL         18
43 #define LA_PORT         19
44 #define LA_AUTH         20
45 #define LA_TIMEOUT      21
46 #define LA_ENVELOPE     22
47 #define LA_QVIRTUAL     23
48 #define LA_USERNAME     24
49 #define LA_ALL          25
50 #define LA_NOKEEP       26
51 #define LA_KEEP         27
52 #define LA_FLUSH        28
53 #define LA_NOREWRITE    29
54 #define LA_LIMIT        30
55 #define LA_WARNINGS     31
56 #define LA_FOLDER       32
57 #define LA_SMTPHOST     33
58 #define LA_FETCHDOMAINS 34
59 #define LA_SMTPADDR     35
60 #define LA_ANTISPAM     36
61 #define LA_BATCHLIMIT   37
62 #define LA_FETCHLIMIT   38
63 #define LA_EXPUNGE      39
64 #define LA_MDA          40
65 #define LA_BSMTP        41
66 #define LA_LMTP         42
67 #define LA_PLUGIN       43
68 #define LA_PLUGOUT      44
69 #define LA_NETSEC       45
70 #define LA_INTERFACE    46
71 #define LA_MONITOR      47
72 #define LA_CONFIGDUMP   48
73 #define LA_YYDEBUG      49
74 #define LA_SMTPNAME     50
75 #define LA_SHOWDOTS     51
76 #define LA_PRINCIPAL    52
77 #define LA_TRACEPOLLS   53
78
79 #ifdef SSL_ENABLE
80 #define LA_SSL          54
81 #define LA_SSLKEY       55
82 #define LA_SSLCERT      56
83 #define LA_SSLPROTO     57
84 #define LA_SSLCERTCK    58
85 #define LA_SSLCERTPATH  59
86 #define LA_SSLFINGERPRINT       60
87 #endif
88
89
90 /* options still left: CDgGhHjJoORwWxXYz */
91 static const char *shortoptions = 
92         "?Vcsvd:NqL:f:i:p:UP:A:t:E:Q:u:akKFnl:r:S:Z:b:B:e:m:T:I:M:yw:D:";
93
94 static const struct option longoptions[] = {
95 /* this can be const because all flag fields are 0 and will never get set */
96   {"help",      no_argument,       (int *) 0, LA_HELP        },
97   {"version",   no_argument,       (int *) 0, LA_VERSION     },
98   {"check",     no_argument,       (int *) 0, LA_CHECK       },
99   {"silent",    no_argument,       (int *) 0, LA_SILENT      },
100   {"verbose",   no_argument,       (int *) 0, LA_VERBOSE     },
101   {"daemon",    required_argument, (int *) 0, LA_DAEMON      },
102   {"nodetach",  no_argument,       (int *) 0, LA_NODETACH    },
103   {"quit",      no_argument,       (int *) 0, LA_QUIT        },
104   {"logfile",   required_argument, (int *) 0, LA_LOGFILE     },
105   {"invisible", no_argument,       (int *) 0, LA_INVISIBLE   },
106   {"showdots",  no_argument,       (int *) 0, LA_SHOWDOTS    },
107   {"syslog",    no_argument,       (int *) 0, LA_SYSLOG      },
108   {"nosyslog",  no_argument,       (int *) 0, LA_NOSYSLOG    },
109   {"fetchmailrc",required_argument,(int *) 0, LA_RCFILE      },
110   {"idfile",    required_argument, (int *) 0, LA_IDFILE      },
111   {"postmaster",required_argument, (int *) 0, LA_POSTMASTER  },
112   {"nobounce",  no_argument,       (int *) 0, LA_NOBOUNCE    },
113
114   {"protocol",  required_argument, (int *) 0, LA_PROTOCOL    },
115   {"proto",     required_argument, (int *) 0, LA_PROTOCOL    },
116   {"uidl",      no_argument,       (int *) 0, LA_UIDL        },
117   {"port",      required_argument, (int *) 0, LA_PORT        },
118   {"auth",      required_argument, (int *) 0, LA_AUTH},
119   {"timeout",   required_argument, (int *) 0, LA_TIMEOUT     },
120   {"envelope",  required_argument, (int *) 0, LA_ENVELOPE    },
121   {"qvirtual",  required_argument, (int *) 0, LA_QVIRTUAL    },
122
123   {"user",      required_argument, (int *) 0, LA_USERNAME    },
124   {"username",  required_argument, (int *) 0, LA_USERNAME    },
125
126   {"all",       no_argument,       (int *) 0, LA_ALL         },
127   {"nokeep",    no_argument,       (int *) 0, LA_NOKEEP      },
128   {"keep",      no_argument,       (int *) 0, LA_KEEP        },
129   {"flush",     no_argument,       (int *) 0, LA_FLUSH       },
130   {"norewrite", no_argument,       (int *) 0, LA_NOREWRITE   },
131   {"limit",     required_argument, (int *) 0, LA_LIMIT       },
132   {"warnings",  required_argument, (int *) 0, LA_WARNINGS    },
133
134   {"folder",    required_argument, (int *) 0, LA_FOLDER      },
135   {"smtphost",  required_argument, (int *) 0, LA_SMTPHOST    },
136   {"fetchdomains",      required_argument, (int *) 0, LA_FETCHDOMAINS    },
137   {"smtpaddress", required_argument, (int *) 0, LA_SMTPADDR  },
138   {"smtpname",  required_argument, (int *) 0, LA_SMTPNAME    },
139   {"antispam",  required_argument, (int *) 0, LA_ANTISPAM    },
140   
141   {"batchlimit",required_argument, (int *) 0, LA_BATCHLIMIT  },
142   {"fetchlimit",required_argument, (int *) 0, LA_FETCHLIMIT  },
143   {"expunge",   required_argument, (int *) 0, LA_EXPUNGE     },
144   {"mda",       required_argument, (int *) 0, LA_MDA         },
145   {"bsmtp",     required_argument, (int *) 0, LA_BSMTP       },
146   {"lmtp",      no_argument,       (int *) 0, LA_LMTP        },
147
148 #ifdef INET6_ENABLE
149   {"netsec",    required_argument, (int *) 0, LA_NETSEC      },
150 #endif /* INET6_ENABLE */
151
152 #ifdef SSL_ENABLE
153   {"ssl",       no_argument,       (int *) 0, LA_SSL        },
154   {"sslkey",    required_argument, (int *) 0, LA_SSLKEY     },
155   {"sslcert",   required_argument, (int *) 0, LA_SSLCERT    },
156   {"sslproto",   required_argument, (int *) 0, LA_SSLPROTO    },
157   {"sslcertck", no_argument,       (int *) 0, LA_SSLCERTCK  },
158   {"sslcertpath",   required_argument, (int *) 0, LA_SSLCERTPATH },
159   {"sslfingerprint",   required_argument, (int *) 0, LA_SSLFINGERPRINT },
160 #endif
161
162   {"principal", required_argument, (int *) 0, LA_PRINCIPAL },
163
164 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
165   {"interface", required_argument, (int *) 0, LA_INTERFACE   },
166   {"monitor",   required_argument, (int *) 0, LA_MONITOR     },
167 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
168   {"plugin",    required_argument, (int *) 0, LA_PLUGIN      },
169   {"plugout",   required_argument, (int *) 0, LA_PLUGOUT     },
170
171   {"configdump",no_argument,       (int *) 0, LA_CONFIGDUMP  },
172
173   {"yydebug",   no_argument,       (int *) 0, LA_YYDEBUG     },
174
175   {"tracepolls",no_argument,       (int *) 0, LA_TRACEPOLLS  },
176
177   {(char *) 0,  no_argument,       (int *) 0, 0              }
178 };
179
180 static int xatoi(char *s, int *errflagptr)
181 /* do safe conversion from string to number */
182 {
183 #if defined (STDC_HEADERS) && defined (LONG_MAX) && defined (INT_MAX)
184     /* parse and convert numbers, but also check for invalid characters in
185      * numbers
186      */
187
188     char *endptr;
189     long value;
190
191     errno = 0;
192
193     value = strtol(s, &endptr, 0);
194
195     /* any invalid chars in string? */
196     if ( (endptr == s) || (*endptr != '\0') ) {
197         (void) fprintf(stderr, GT_("String '%s' is not a valid number string.\n"), s);
198         (*errflagptr)++;
199         return 0;
200     }
201
202     /* is the range valid? */
203     if ( (((value == LONG_MAX) || (value == LONG_MIN)) && (errno == ERANGE)) ||
204                                 (value > INT_MAX) || (value < INT_MIN)) {
205
206         (void) fprintf(stderr, GT_("Value of string '%s' is %s than %d.\n"), s,
207                                         (value < 0) ? GT_("smaller"): GT_("larger"),
208                                         (value < 0) ? INT_MIN : INT_MAX);
209         (*errflagptr)++;
210         return 0;
211     }
212
213     return (int) value;  /* shut up, I know what I'm doing */
214 #else
215     int i;
216     char *dp;
217 # if defined (STDC_HEADERS)
218     size_t      len;
219 # else
220     int         len;
221 # endif
222
223     /* We do only base 10 conversions here (atoi)! */
224
225     len = strlen(s);
226     /* check for leading white spaces */
227     for (i = 0; (i < len) && isspace(s[i]); i++)
228         ;
229
230     dp = &s[i];
231
232     /* check for +/- */
233     if (i < len && (s[i] == '+' || s[i] == '-'))        i++;
234
235     /* skip over digits */
236     for ( /* no init */ ; (i < len) && isdigit(s[i]); i++)
237         ;
238
239     /* check for trailing garbage */
240     if (i != len) {
241         (void) fprintf(stderr, GT_("String '%s' is not a valid number string.\n"), s);
242         (*errflagptr)++;
243         return 0;
244     }
245
246     /* atoi should be safe by now, except for number range over/underflow */
247     return atoi(dp);
248 #endif
249 }
250
251 int parsecmdline (argc, argv, rctl, ctl)
252 /* parse and validate the command line options */
253 int argc;               /* argument count */
254 char **argv;            /* argument strings */
255 struct runctl *rctl;    /* global run controls to modify */
256 struct query *ctl;      /* option record to be initialized */
257 {
258     /*
259      * return value: if positive, argv index of last parsed option + 1
260      * (presumes one or more server names follows).  if zero, the
261      * command line switches are such that no server names are
262      * required (e.g. --version).  if negative, the command line is
263      * has one or more syntax errors.
264      */
265
266     int c;
267     int ocount = 0;     /* count of destinations specified */
268     int errflag = 0;    /* TRUE when a syntax error is detected */
269     int helpflag = 0;   /* TRUE when option help was explicitly requested */
270     int option_index;
271     char *buf, *cp;
272
273     rctl->poll_interval = -1;
274
275     memset(ctl, '\0', sizeof(struct query));    /* start clean */
276     ctl->smtp_socket = -1;
277
278     while (!errflag && 
279 #ifdef HAVE_GETOPTLONG
280            (c = getopt_long(argc,argv,shortoptions,
281                             longoptions, &option_index)) != -1)
282 #else
283            (c = getopt(argc, argv, shortoptions)) != -1)
284 #endif
285     {
286         switch (c) {
287         case 'V':
288         case LA_VERSION:
289             versioninfo = TRUE;
290             break;
291         case 'c':
292         case LA_CHECK:
293             check_only = TRUE;
294             break;
295         case 's':
296         case LA_SILENT:
297             outlevel = O_SILENT;
298             break;
299         case 'v':
300         case LA_VERBOSE:
301             if (outlevel == O_VERBOSE)
302                 outlevel = O_DEBUG;
303             else
304                 outlevel = O_VERBOSE;
305             break;
306         case 'd':
307         case LA_DAEMON:
308             rctl->poll_interval = xatoi(optarg, &errflag);
309             break;
310         case 'N':
311         case LA_NODETACH:
312             nodetach = TRUE;
313             break;
314         case 'q':
315         case LA_QUIT:
316             quitmode = TRUE;
317             break;
318         case 'L':
319         case LA_LOGFILE:
320             rctl->logfile = optarg;
321             break;
322         case LA_INVISIBLE:
323             rctl->invisible = TRUE;
324             break;
325         case LA_SHOWDOTS:
326             rctl->showdots = TRUE;
327             break;
328         case 'f':
329         case LA_RCFILE:
330             rcfile = (char *) xstrdup(optarg);
331             break;
332         case 'i':
333         case LA_IDFILE:
334             rctl->idfile = (char *) xstrdup(optarg);
335             break;
336         case LA_POSTMASTER:
337             rctl->postmaster = (char *) xstrdup(optarg);
338             break;
339         case LA_NOBOUNCE:
340             run.bouncemail = FALSE;
341             break;
342         case 'p':
343         case LA_PROTOCOL:
344             /* XXX -- should probably use a table lookup here */
345             if (strcasecmp(optarg,"auto") == 0)
346                 ctl->server.protocol = P_AUTO;
347             else if (strcasecmp(optarg,"pop2") == 0)
348                 ctl->server.protocol = P_POP2;
349 #ifdef SDPS_ENABLE
350             else if (strcasecmp(optarg,"sdps") == 0)
351             {
352                 ctl->server.protocol = P_POP3; 
353                 ctl->server.sdps = TRUE;
354             }
355 #endif /* SDPS_ENABLE */
356             else if (strcasecmp(optarg,"pop3") == 0)
357                 ctl->server.protocol = P_POP3;
358             else if (strcasecmp(optarg,"apop") == 0)
359                 ctl->server.protocol = P_APOP;
360             else if (strcasecmp(optarg,"rpop") == 0)
361                 ctl->server.protocol = P_RPOP;
362             else if (strcasecmp(optarg,"kpop") == 0)
363             {
364                 ctl->server.protocol = P_POP3;
365 #if INET6_ENABLE
366                 ctl->server.service = KPOP_PORT;
367 #else /* INET6_ENABLE */
368                 ctl->server.port = KPOP_PORT;
369 #endif /* INET6_ENABLE */
370 #ifdef KERBEROS_V5
371                 ctl->server.authenticate =  A_KERBEROS_V5;
372 #else
373                 ctl->server.authenticate =  A_KERBEROS_V4;
374 #endif /* KERBEROS_V5 */
375             }
376             else if (strcasecmp(optarg,"imap") == 0)
377                 ctl->server.protocol = P_IMAP;
378             else if (strcasecmp(optarg,"etrn") == 0)
379                 ctl->server.protocol = P_ETRN;
380             else if (strcasecmp(optarg,"odmr") == 0)
381                 ctl->server.protocol = P_ODMR;
382             else {
383                 fprintf(stderr,GT_("Invalid protocol `%s' specified.\n"), optarg);
384                 errflag++;
385             }
386             break;
387         case 'U':
388         case LA_UIDL:
389             ctl->server.uidl = FLAG_TRUE;
390             break;
391         case 'P':
392         case LA_PORT:
393 #if INET6_ENABLE
394             ctl->server.service = optarg;
395 #else /* INET6_ENABLE */
396             ctl->server.port = xatoi(optarg, &errflag);
397 #endif /* INET6_ENABLE */
398             break;
399         case LA_AUTH:
400             if (strcmp(optarg, "password") == 0)
401                 ctl->server.authenticate = A_PASSWORD;
402             else if (strcmp(optarg, "kerberos") == 0)
403 #ifdef KERBEROS_V5
404                 ctl->server.authenticate = A_KERBEROS_V5;
405 #else
406                 ctl->server.authenticate = A_KERBEROS_V4;
407 #endif /* KERBEROS_V5 */
408             else if (strcmp(optarg, "kerberos_v5") == 0)
409                 ctl->server.authenticate = A_KERBEROS_V5;
410             else if (strcmp(optarg, "kerberos_v4") == 0)
411                 ctl->server.authenticate = A_KERBEROS_V4;
412             else if (strcmp(optarg, "ssh") == 0)
413                 ctl->server.authenticate = A_SSH;
414             else if (strcmp(optarg, "otp") == 0)
415                 ctl->server.authenticate = A_OTP;
416             else if (strcmp(optarg, "ntlm") == 0)
417                 ctl->server.authenticate = A_NTLM;
418             else if (strcmp(optarg, "cram") == 0)
419                 ctl->server.authenticate = A_CRAM_MD5;
420             else if (strcmp(optarg, "cram-md5") == 0)
421                 ctl->server.authenticate = A_CRAM_MD5;
422             else if (strcmp(optarg, "gssapi") == 0)
423                 ctl->server.authenticate = A_GSSAPI;
424             else if (strcmp(optarg, "any") == 0)
425                 ctl->server.authenticate = A_ANY;
426             else {
427                 fprintf(stderr,GT_("Invalid authentication `%s' specified.\n"), optarg);
428                 errflag++;
429             }
430             break;
431         case 't':
432         case LA_TIMEOUT:
433             ctl->server.timeout = xatoi(optarg, &errflag);
434             if (ctl->server.timeout == 0)
435                 ctl->server.timeout = -1;
436             break;
437         case 'E':
438         case LA_ENVELOPE:
439             ctl->server.envelope = xstrdup(optarg);
440             break;
441         case 'Q':    
442         case LA_QVIRTUAL:
443             ctl->server.qvirtual = xstrdup(optarg);
444             break;
445
446         case 'u':
447         case LA_USERNAME:
448             ctl->remotename = xstrdup(optarg);
449             break;
450         case 'a':
451         case LA_ALL:
452             ctl->fetchall = FLAG_TRUE;
453             break;
454         case 'K':
455         case LA_NOKEEP:
456             ctl->keep = FLAG_FALSE;
457             break;
458         case 'k':
459         case LA_KEEP:
460             ctl->keep = FLAG_TRUE;
461             break;
462         case 'F':
463         case LA_FLUSH:
464             ctl->flush = FLAG_TRUE;
465             break;
466         case 'n':
467         case LA_NOREWRITE:
468             ctl->rewrite = FLAG_FALSE;
469             break;
470         case 'l':
471         case LA_LIMIT:
472             c = xatoi(optarg, &errflag);
473             ctl->limit = NUM_VALUE_IN(c);
474             break;
475         case 'r':
476         case LA_FOLDER:
477             xalloca(buf, char *, strlen(optarg) + 1);
478             strcpy(buf, optarg);
479             cp = strtok(buf, ",");
480             do {
481                 save_str(&ctl->mailboxes, cp, 0);
482             } while
483                 ((cp = strtok((char *)NULL, ",")));
484             break;
485         case 'S':
486         case LA_SMTPHOST:
487             xalloca(buf, char *, strlen(optarg) + 1);
488             strcpy(buf, optarg);
489             cp = strtok(buf, ",");
490             do {
491                 save_str(&ctl->smtphunt, cp, TRUE);
492             } while
493                 ((cp = strtok((char *)NULL, ",")));
494             ocount++;
495             break;
496         case LA_FETCHDOMAINS:
497             xalloca(buf, char *, strlen(optarg) + 1);
498             strcpy(buf, optarg);
499             cp = strtok(buf, ",");
500             do {
501                 save_str(&ctl->domainlist, cp, TRUE);
502             } while
503                 ((cp = strtok((char *)NULL, ",")));
504             break;
505         case 'D':
506         case LA_SMTPADDR:
507             ctl->smtpaddress = xstrdup(optarg);
508             break;
509         case LA_SMTPNAME:
510           ctl->smtpname = xstrdup(optarg);
511           break;
512         case 'Z':
513         case LA_ANTISPAM:
514             xalloca(buf, char *, strlen(optarg) + 1);
515             strcpy(buf, optarg);
516             cp = strtok(buf, ",");
517             do {
518                 struct idlist   *idp = save_str(&ctl->antispam, NULL, 0);;
519
520                 idp->val.status.num = xatoi(cp, &errflag);
521             } while
522                 ((cp = strtok((char *)NULL, ",")));
523             break;
524         case 'b':
525         case LA_BATCHLIMIT:
526             c = xatoi(optarg, &errflag);
527             ctl->batchlimit = NUM_VALUE_IN(c);
528             break;
529         case 'B':
530         case LA_FETCHLIMIT:
531             c = xatoi(optarg, &errflag);
532             ctl->fetchlimit = NUM_VALUE_IN(c);
533             break;
534         case 'e':
535         case LA_EXPUNGE:
536             c = xatoi(optarg, &errflag);
537             ctl->expunge = NUM_VALUE_IN(c);
538             break;
539         case 'm':
540         case LA_MDA:
541             ctl->mda = xstrdup(optarg);
542             ocount++;
543             break;
544         case LA_BSMTP:
545             ctl->bsmtp = xstrdup(optarg);
546             ocount++;
547             break;
548         case LA_LMTP:
549             ctl->listener = LMTP_MODE;
550             break;
551
552         case 'T':
553         case LA_NETSEC:
554 #if NET_SECURITY
555             ctl->server.netsec = (void *)optarg;
556 #else
557             fprintf(stderr, GT_("fetchmail: network security support is disabled\n"));
558             errflag++;
559 #endif /* NET_SECURITY */
560             break;
561
562 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
563         case 'I':
564         case LA_INTERFACE:
565             interface_parse(optarg, &ctl->server);
566             break;
567         case 'M':
568         case LA_MONITOR:
569             ctl->server.monitor = xstrdup(optarg);
570             break;
571 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
572         case LA_PLUGIN:
573             ctl->server.plugin = xstrdup(optarg);
574             break;
575         case LA_PLUGOUT:
576             ctl->server.plugout = xstrdup(optarg);
577             break;
578
579 #ifdef SSL_ENABLE
580         case LA_SSL:
581             ctl->use_ssl = FLAG_TRUE;
582             break;
583
584         case LA_SSLKEY:
585             ctl->sslkey = xstrdup(optarg);
586             break;
587
588         case LA_SSLCERT:
589             ctl->sslcert = xstrdup(optarg);
590             break;
591
592         case LA_SSLPROTO:
593             ctl->sslproto = xstrdup(optarg);
594             break;
595
596         case LA_SSLCERTCK:
597             ctl->sslcertck = FLAG_TRUE;
598             break;
599
600         case LA_SSLCERTPATH:
601             ctl->sslcertpath = xstrdup(optarg);
602             break;
603
604         case LA_SSLFINGERPRINT:
605             ctl->sslfingerprint = xstrdup(optarg);
606             break;
607 #endif
608
609         case LA_PRINCIPAL:
610             ctl->server.principal = xstrdup(optarg);
611             break;
612
613         case 'y':
614         case LA_YYDEBUG:
615             yydebug = TRUE;
616             break;
617
618         case 'w':
619         case LA_WARNINGS:
620             c = xatoi(optarg, &errflag);
621             ctl->warnings = NUM_VALUE_IN(c);
622             break;
623
624         case LA_CONFIGDUMP:
625             configdump = TRUE;
626             break;
627
628         case LA_SYSLOG:
629             rctl->use_syslog = FLAG_TRUE;
630             break;
631
632         case LA_NOSYSLOG:
633             rctl->use_syslog = FLAG_FALSE;
634             break;
635
636         case LA_TRACEPOLLS:
637             ctl->tracepolls = FLAG_TRUE;
638             break;
639
640         case '?':
641         case LA_HELP:
642         default:
643             helpflag++;
644         }
645     }
646
647     if (errflag || ocount > 1 || helpflag) {
648         /* squawk if syntax errors were detected */
649 #define P(s)    fputs(s, helpflag ? stdout : stderr)
650         P(GT_("usage:  fetchmail [options] [server ...]\n"));
651         P(GT_("  Options are as follows:\n"));
652         P(GT_("  -?, --help        display this option help\n"));
653         P(GT_("  -V, --version     display version info\n"));
654
655         P(GT_("  -c, --check       check for messages without fetching\n"));
656         P(GT_("  -s, --silent      work silently\n"));
657         P(GT_("  -v, --verbose     work noisily (diagnostic output)\n"));
658         P(GT_("  -d, --daemon      run as a daemon once per n seconds\n"));
659         P(GT_("  -N, --nodetach    don't detach daemon process\n"));
660         P(GT_("  -q, --quit        kill daemon process\n"));
661         P(GT_("  -L, --logfile     specify logfile name\n"));
662         P(GT_("      --syslog      use syslog(3) for most messages when running as a daemon\n"));
663         P(GT_("      --invisible   don't write Received & enable host spoofing\n"));
664         P(GT_("  -f, --fetchmailrc specify alternate run control file\n"));
665         P(GT_("  -i, --idfile      specify alternate UIDs file\n"));
666         P(GT_("      --postmaster  specify recipient of last resort\n"));
667         P(GT_("      --nobounce    redirect bounces from user to postmaster.\n"));
668 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
669         P(GT_("  -I, --interface   interface required specification\n"));
670         P(GT_("  -M, --monitor     monitor interface for activity\n"));
671 #endif
672 #if defined( SSL_ENABLE )
673         P(GT_("      --ssl         enable ssl encrypted session\n"));
674         P(GT_("      --sslkey      ssl private key file\n"));
675         P(GT_("      --sslcert     ssl client certificate\n"));
676         P(GT_("      --sslproto    force ssl protocol (ssl2/ssl3/tls1)\n"));
677 #endif
678         P(GT_("      --plugin      specify external command to open connection\n"));
679         P(GT_("      --plugout     specify external command to open smtp connection\n"));
680
681         P(GT_("  -p, --protocol    specify retrieval protocol (see man page)\n"));
682         P(GT_("  -U, --uidl        force the use of UIDLs (pop3 only)\n"));
683         P(GT_("  -P, --port        TCP/IP service port to connect to\n"));
684         P(GT_("      --auth        authentication type (password/kerberos/ssh)\n"));
685         P(GT_("  -t, --timeout     server nonresponse timeout\n"));
686         P(GT_("  -E, --envelope    envelope address header\n"));
687         P(GT_("  -Q, --qvirtual    prefix to remove from local user id\n"));
688         P(GT_("      --principal   mail service principal\n"));
689         P(GT_("      --tracepolls  add poll-tracing information to Received header\n"));
690
691         P(GT_("  -u, --username    specify users's login on server\n"));
692         P(GT_("  -a, --all         retrieve old and new messages\n"));
693         P(GT_("  -K, --nokeep      delete new messages after retrieval\n"));
694         P(GT_("  -k, --keep        save new messages after retrieval\n"));
695         P(GT_("  -F, --flush       delete old messages from server\n"));
696         P(GT_("  -n, --norewrite   don't rewrite header addresses\n"));
697         P(GT_("  -l, --limit       don't fetch messages over given size\n"));
698         P(GT_("  -w, --warnings    interval between warning mail notification\n"));
699
700 #if NET_SECURITY
701         P(GT_("  -T, --netsec      set IP security request\n"));
702 #endif /* NET_SECURITY */
703         P(GT_("  -S, --smtphost    set SMTP forwarding host\n"));
704         P(GT_("      --fetchdomains fetch mail for specified domains\n"));
705         P(GT_("  -D, --smtpaddress set SMTP delivery domain to use\n"));
706         P(GT_("      --smtpname    set SMTP full name username@domain\n"));
707         P(GT_("  -Z, --antispam,   set antispam response values\n"));
708         P(GT_("  -b, --batchlimit  set batch limit for SMTP connections\n"));
709         P(GT_("  -B, --fetchlimit  set fetch limit for server connections\n"));
710         P(GT_("  -e, --expunge     set max deletions between expunges\n"));
711         P(GT_("  -m, --mda         set MDA to use for forwarding\n"));
712         P(GT_("      --bsmtp       set output BSMTP file\n"));
713         P(GT_("      --lmtp        use LMTP (RFC2033) for delivery\n"));
714         P(GT_("  -r, --folder      specify remote folder name\n"));
715         P(GT_("      --showdots    show progress dots even in logfiles\n"));
716 #undef P
717
718         if (helpflag)
719             exit(PS_SUCCESS);
720         else
721             exit(PS_SYNTAX);
722     }
723
724     return(optind);
725 }
726
727 /* options.c ends here */