2 * options.c -- command-line option processing
4 * For license terms, see the file COPYING in this directory.
12 #include "fetchmail.h"
24 #define LA_PROTOCOL 11
26 #define LA_AUTHENTICATE 13
28 #define LA_USERNAME 15
33 #define LA_NOREWRITE 20
34 #define LA_REMOTEFILE 21
35 #define LA_SMTPHOST 22
39 static char *shortoptions = "?Vcsvd:qL:f:i:p:P:A:t:u:akKFnr:S:m:y";
40 static struct option longoptions[] = {
41 {"help", no_argument, (int *) 0, LA_HELP },
42 {"version", no_argument, (int *) 0, LA_VERSION },
43 {"check", no_argument, (int *) 0, LA_CHECK },
44 {"silent", no_argument, (int *) 0, LA_SILENT },
45 {"verbose", no_argument, (int *) 0, LA_VERBOSE },
46 {"daemon", required_argument, (int *) 0, LA_DAEMON },
47 {"quit", no_argument, (int *) 0, LA_QUIT },
48 {"logfile", required_argument, (int *) 0, LA_LOGFILE },
49 {"fetchmailrc",required_argument,(int *) 0, LA_RCFILE },
50 {"idfile", required_argument, (int *) 0, LA_IDFILE },
52 {"protocol", required_argument, (int *) 0, LA_PROTOCOL },
53 {"proto", required_argument, (int *) 0, LA_PROTOCOL },
54 {"port", required_argument, (int *) 0, LA_PORT },
55 {"auth", required_argument, (int *) 0, LA_AUTHENTICATE},
56 {"timeout", required_argument, (int *) 0, LA_TIMEOUT },
58 {"user", required_argument, (int *) 0, LA_USERNAME },
59 {"username", required_argument, (int *) 0, LA_USERNAME },
61 {"all", no_argument, (int *) 0, LA_ALL },
62 {"kill", no_argument, (int *) 0, LA_KILL },
63 {"keep", no_argument, (int *) 0, LA_KEEP },
64 {"flush", no_argument, (int *) 0, LA_FLUSH },
65 {"norewrite", no_argument, (int *) 0, LA_NOREWRITE },
67 {"remote", required_argument, (int *) 0, LA_REMOTEFILE },
68 {"smtphost", required_argument, (int *) 0, LA_SMTPHOST },
69 {"mda", required_argument, (int *) 0, LA_MDA },
71 {"yydebug", no_argument, (int *) 0, LA_YYDEBUG },
73 {(char *) 0, no_argument, (int *) 0, 0 }
76 int parsecmdline (argc,argv,queryctl)
77 /* parse and validate the command line options */
78 int argc; /* argument count */
79 char **argv; /* argument strings */
80 struct hostrec *queryctl; /* option record to be initialized */
83 * return value: if positive, argv index of last parsed option + 1
84 * (presumes one or more server names follows). if zero, the
85 * command line switches are such that no server names are
86 * required (e.g. --version). if negative, the command line is
87 * has one or more syntax errors.
91 int ocount = 0; /* count of destinations specified */
92 int errflag = 0; /* TRUE when a syntax error is detected */
95 memset(queryctl, '\0', sizeof(struct hostrec)); /* start clean */
98 (c = getopt_long(argc,argv,shortoptions,
99 longoptions,&option_index)) != -1) {
116 outlevel = O_VERBOSE;
120 poll_interval = atoi(optarg);
132 rcfile = (char *) xmalloc(strlen(optarg)+1);
133 strcpy(rcfile,optarg);
137 idfile = (char *) xmalloc(strlen(optarg)+1);
138 strcpy(idfile,optarg);
142 /* XXX -- should probably use a table lookup here */
143 if (strcasecmp(optarg,"pop2") == 0)
144 queryctl->protocol = P_POP2;
145 else if (strcasecmp(optarg,"pop3") == 0)
146 queryctl->protocol = P_POP3;
147 else if (strcasecmp(optarg,"imap") == 0)
148 queryctl->protocol = P_IMAP;
149 else if (strcasecmp(optarg,"apop") == 0)
150 queryctl->protocol = P_APOP;
151 else if (strcasecmp(optarg,"kpop") == 0)
153 queryctl->protocol = P_POP3;
154 queryctl->port = KPOP_PORT;
155 queryctl->authenticate = A_KERBEROS;
158 fprintf(stderr,"Invalid protocol `%s' specified.\n", optarg);
164 queryctl->port = atoi(optarg);
167 case LA_AUTHENTICATE:
168 if (strcmp(optarg, "password") == 0)
169 queryctl->authenticate = A_PASSWORD;
170 else if (strcmp(optarg, "kerberos") == 0)
171 queryctl->authenticate = A_KERBEROS;
173 fprintf(stderr,"Invalid authentication `%s' specified.\n", optarg);
178 queryctl->timeout = atoi(optarg);
182 strncpy(queryctl->remotename,optarg,sizeof(queryctl->remotename)-1);
187 queryctl->fetchall = TRUE;
191 queryctl->keep = FALSE;
195 queryctl->keep = TRUE;
199 queryctl->flush = TRUE;
203 queryctl->norewrite = TRUE;
207 strncpy(queryctl->mailbox,optarg,sizeof(queryctl->mailbox)-1);
211 strncpy(queryctl->smtphost,optarg,sizeof(queryctl->smtphost)-1);
216 strncpy(queryctl->mda,optarg,sizeof(queryctl->mda));
231 if (check_only && poll_interval)
233 fputs("The --check and --daemon options aren't compatible.\n", stderr);
237 if (errflag || ocount > 1) {
238 /* squawk if syntax errors were detected */
239 fputs("usage: fetchmail [options] [server ...]\n", stderr);
240 fputs(" Options are as follows:\n",stderr);
241 fputs(" -?, --help display this option help\n", stderr);
242 fputs(" -V, --version display version info\n", stderr);
244 fputs(" -c, --check check for messages without fetching\n", stderr);
245 fputs(" -s, --silent work silently\n", stderr);
246 fputs(" -v, --verbose work noisily (diagnostic output)\n", stderr);
247 fputs(" -d, --daemon run as a daemon once per n seconds\n", stderr);
248 fputs(" -q, --quit kill daemon process\n", stderr);
249 fputs(" -L, --logfile specify logfile name\n", stderr);
250 fputs(" -f, --fetchmailrc specify alternate run control file\n", stderr);
251 fputs(" -i, --idfile specify alternate UIDs file\n", stderr);
253 fputs(" -p, --protocol specify pop2, pop3, imap, apop, rpop, kpop\n", stderr);
254 fputs(" -P, --port TCP/IP service port to connect to\n",stderr);
255 fputs(" -A, --auth authentication type (password or kerberos)\n",stderr);
256 fputs(" -t, --timeout server nonresponse timeout\n",stderr);
258 fputs(" -u, --username specify users's login on server\n", stderr);
259 fputs(" -a, --all retrieve old and new messages\n", stderr);
260 fputs(" -K, --kill delete new messages after retrieval\n", stderr);
261 fputs(" -k, --keep save new messages after retrieval\n", stderr);
262 fputs(" -F, --flush delete old messages from server\n", stderr);
263 fputs(" -n, --norewrite don't rewrite header addresses\n", stderr);
265 fputs(" -S, --smtphost set SMTP forwarding host\n", stderr);
266 fputs(" -r, --remote specify remote folder name\n", stderr);
273 /* options.c ends here */