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