2 * options.c -- command-line option processing
4 * For license terms, see the file COPYING in this directory.
11 #if defined(STDC_HEADERS)
16 #include "fetchmail.h"
28 #define LA_PROTOCOL 11
30 #define LA_AUTHENTICATE 13
32 #define LA_USERNAME 15
37 #define LA_NOREWRITE 20
39 #define LA_REMOTEFILE 22
40 #define LA_SMTPHOST 23
44 static char *shortoptions = "?Vcsvd:qL:f:i:p:P:A:t:u:akKFnl:r:S:m:y";
45 static struct option longoptions[] = {
46 {"help", no_argument, (int *) 0, LA_HELP },
47 {"version", no_argument, (int *) 0, LA_VERSION },
48 {"check", no_argument, (int *) 0, LA_CHECK },
49 {"silent", no_argument, (int *) 0, LA_SILENT },
50 {"verbose", no_argument, (int *) 0, LA_VERBOSE },
51 {"daemon", required_argument, (int *) 0, LA_DAEMON },
52 {"quit", no_argument, (int *) 0, LA_QUIT },
53 {"logfile", required_argument, (int *) 0, LA_LOGFILE },
54 {"fetchmailrc",required_argument,(int *) 0, LA_RCFILE },
55 {"idfile", required_argument, (int *) 0, LA_IDFILE },
57 {"protocol", required_argument, (int *) 0, LA_PROTOCOL },
58 {"proto", required_argument, (int *) 0, LA_PROTOCOL },
59 {"port", required_argument, (int *) 0, LA_PORT },
60 {"auth", required_argument, (int *) 0, LA_AUTHENTICATE},
61 {"timeout", required_argument, (int *) 0, LA_TIMEOUT },
63 {"user", required_argument, (int *) 0, LA_USERNAME },
64 {"username", required_argument, (int *) 0, LA_USERNAME },
66 {"all", no_argument, (int *) 0, LA_ALL },
67 {"kill", no_argument, (int *) 0, LA_KILL },
68 {"keep", no_argument, (int *) 0, LA_KEEP },
69 {"flush", no_argument, (int *) 0, LA_FLUSH },
70 {"norewrite", no_argument, (int *) 0, LA_NOREWRITE },
71 {"limit", required_argument, (int *) 0, LA_LIMIT },
73 {"remote", required_argument, (int *) 0, LA_REMOTEFILE },
74 {"smtphost", required_argument, (int *) 0, LA_SMTPHOST },
75 {"mda", required_argument, (int *) 0, LA_MDA },
77 {"yydebug", no_argument, (int *) 0, LA_YYDEBUG },
79 {(char *) 0, no_argument, (int *) 0, 0 }
82 int parsecmdline (argc,argv,ctl)
83 /* parse and validate the command line options */
84 int argc; /* argument count */
85 char **argv; /* argument strings */
86 struct query *ctl; /* option record to be initialized */
89 * return value: if positive, argv index of last parsed option + 1
90 * (presumes one or more server names follows). if zero, the
91 * command line switches are such that no server names are
92 * required (e.g. --version). if negative, the command line is
93 * has one or more syntax errors.
97 int ocount = 0; /* count of destinations specified */
98 int errflag = 0; /* TRUE when a syntax error is detected */
101 memset(ctl, '\0', sizeof(struct query)); /* start clean */
104 (c = getopt_long(argc,argv,shortoptions,
105 longoptions,&option_index)) != -1) {
122 outlevel = O_VERBOSE;
126 poll_interval = atoi(optarg);
138 rcfile = (char *) xmalloc(strlen(optarg)+1);
139 strcpy(rcfile,optarg);
143 idfile = (char *) xmalloc(strlen(optarg)+1);
144 strcpy(idfile,optarg);
148 /* XXX -- should probably use a table lookup here */
149 if (strcasecmp(optarg,"pop2") == 0)
150 ctl->protocol = P_POP2;
151 else if (strcasecmp(optarg,"pop3") == 0)
152 ctl->protocol = P_POP3;
153 else if (strcasecmp(optarg,"imap") == 0)
154 ctl->protocol = P_IMAP;
155 else if (strcasecmp(optarg,"apop") == 0)
156 ctl->protocol = P_APOP;
157 else if (strcasecmp(optarg,"kpop") == 0)
159 ctl->protocol = P_POP3;
160 ctl->port = KPOP_PORT;
161 ctl->authenticate = A_KERBEROS;
164 fprintf(stderr,"Invalid protocol `%s' specified.\n", optarg);
170 ctl->port = atoi(optarg);
173 case LA_AUTHENTICATE:
174 if (strcmp(optarg, "password") == 0)
175 ctl->authenticate = A_PASSWORD;
176 else if (strcmp(optarg, "kerberos") == 0)
177 ctl->authenticate = A_KERBEROS;
179 fprintf(stderr,"Invalid authentication `%s' specified.\n", optarg);
184 ctl->timeout = atoi(optarg);
188 strncpy(ctl->remotename,optarg,sizeof(ctl->remotename)-1);
193 ctl->fetchall = TRUE;
209 ctl->norewrite = TRUE;
213 ctl->limit = atoi(optarg);
217 strncpy(ctl->mailbox,optarg,sizeof(ctl->mailbox)-1);
221 strncpy(ctl->smtphost,optarg,sizeof(ctl->smtphost)-1);
226 strncpy(ctl->mda,optarg,sizeof(ctl->mda));
241 if (check_only && poll_interval)
243 fputs("The --check and --daemon options aren't compatible.\n", stderr);
247 if (errflag || ocount > 1) {
248 /* squawk if syntax errors were detected */
249 fputs("usage: fetchmail [options] [server ...]\n", stderr);
250 fputs(" Options are as follows:\n",stderr);
251 fputs(" -?, --help display this option help\n", stderr);
252 fputs(" -V, --version display version info\n", stderr);
254 fputs(" -c, --check check for messages without fetching\n", stderr);
255 fputs(" -s, --silent work silently\n", stderr);
256 fputs(" -v, --verbose work noisily (diagnostic output)\n", stderr);
257 fputs(" -d, --daemon run as a daemon once per n seconds\n", stderr);
258 fputs(" -q, --quit kill daemon process\n", stderr);
259 fputs(" -L, --logfile specify logfile name\n", stderr);
260 fputs(" -f, --fetchmailrc specify alternate run control file\n", stderr);
261 fputs(" -i, --idfile specify alternate UIDs file\n", stderr);
263 fputs(" -p, --protocol specify pop2, pop3, imap, apop, rpop, kpop\n", stderr);
264 fputs(" -P, --port TCP/IP service port to connect to\n",stderr);
265 fputs(" -A, --auth authentication type (password or kerberos)\n",stderr);
266 fputs(" -t, --timeout server nonresponse timeout\n",stderr);
268 fputs(" -u, --username specify users's login on server\n", stderr);
269 fputs(" -a, --all retrieve old and new messages\n", stderr);
270 fputs(" -K, --kill delete new messages after retrieval\n", stderr);
271 fputs(" -k, --keep save new messages after retrieval\n", stderr);
272 fputs(" -F, --flush delete old messages from server\n", stderr);
273 fputs(" -n, --norewrite don't rewrite header addresses\n", stderr);
274 fputs(" -l, --limit don't fetch messages over given size\n", stderr);
276 fputs(" -S, --smtphost set SMTP forwarding host\n", stderr);
277 fputs(" -r, --remote specify remote folder name\n", stderr);
284 /* options.c ends here */