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