common.c
13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <string.h>
#include <mailutils/syslog.h>
#include <mailutils/mailbox.h>
/* ************************************************************************* */
/* Common */
/* ************************************************************************* */
enum {
OPT_SHOW_OPTIONS=256,
OPT_NO_USER_RCFILE,
OPT_NO_SITE_RCFILE,
OPT_RCFILE,
OPT_RCFILE_LINT,
OPT_RCFILE_VERBOSE,
OPT_LOG_FACILITY,
OPT_LOCK_FLAGS,
OPT_LOCK_RETRY_COUNT,
OPT_LOCK_RETRY_TIMEOUT,
OPT_LOCK_EXPIRE_TIMEOUT,
OPT_LOCK_EXTERNAL_PROGRAM,
OPT_LICENSE,
OPT_MAILBOX_PATTERN,
OPT_MAILBOX_TYPE,
OPT_MAIL_FOLDER,
OPT_DEBUG_LEVEL,
OPT_LINE_INFO,
OPT_HELP_CONFIG
};
static struct argp_option mu_common_argp_options[] =
{
{ NULL, 0, NULL, 0, N_("Common options"), 0},
{ "show-config-options", OPT_SHOW_OPTIONS, NULL, 0,
N_("show compilation options"), 0 },
{ "config-help", OPT_HELP_CONFIG, NULL, 0,
N_("show configuration file summary"), 0 },
{ "no-user-config", OPT_NO_USER_RCFILE, NULL, 0,
N_("do not load user configuration file"), 0 },
{ "no-user-rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "no-site-config", OPT_NO_SITE_RCFILE, NULL, 0,
N_("do not load site configuration file"), 0 },
{ "no-site-rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "config-file", OPT_RCFILE, N_("FILE"), 0,
N_("load this configuration file"), 0, },
{ "rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "config-verbose", OPT_RCFILE_VERBOSE, NULL, 0,
N_("verbosely log parsing of the configuration files"), 0 },
{ "rcfile-verbose", 0, NULL, OPTION_ALIAS, NULL },
{ "config-lint", OPT_RCFILE_LINT, NULL, 0,
N_("check configuration file syntax and exit"), 0 },
{ "rcfile-lint", 0, NULL, OPTION_ALIAS, NULL },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_common_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_SHOW_OPTIONS:
mu_print_options ();
exit (0);
case OPT_NO_USER_RCFILE:
mu_load_user_rcfile = 0;
break;
case OPT_NO_SITE_RCFILE:
mu_load_site_rcfile = 0;
break;
case OPT_RCFILE:
mu_load_rcfile = arg;
break;
case OPT_RCFILE_LINT:
mu_cfg_parser_verbose++;
mu_rcfile_lint = 1;
break;
case OPT_RCFILE_VERBOSE:
mu_cfg_parser_verbose++;
break;
case OPT_HELP_CONFIG:
mu_help_config_mode = 1;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_common_argp = {
mu_common_argp_options,
mu_common_argp_parser,
};
struct argp_child mu_common_argp_child = {
&mu_common_argp,
0,
NULL,
0,
};
struct mu_cmdline_capa mu_common_cmdline = {
"common", &mu_common_argp_child
};
/* ************************************************************************* */
/* Logging */
/* ************************************************************************* */
static struct argp_option mu_logging_argp_option[] = {
{"log-facility", OPT_LOG_FACILITY, N_("FACILITY"), 0,
N_("output logs to syslog FACILITY"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_logging_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
/* log */
case OPT_LOG_FACILITY:
mu_argp_node_list_new (&lst, "facility", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "logging", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_logging_argp = {
mu_logging_argp_option,
mu_logging_argp_parser,
};
struct argp_child mu_logging_argp_child = {
&mu_logging_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_logging_cmdline = {
"logging", &mu_logging_argp_child
};
/* ************************************************************************* */
/* License */
/* ************************************************************************* */
/* Option to print the license. */
static struct argp_option mu_license_argp_option[] = {
{ "license", OPT_LICENSE, NULL, 0, N_("print license and exit"), -2 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_license_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_LICENSE:
printf (_("License for %s:\n\n"), argp_program_version);
printf ("%s", mu_license_text);
exit (0);
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_license_argp = {
mu_license_argp_option,
mu_license_argp_parser,
};
struct argp_child mu_license_argp_child = {
&mu_license_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_license_cmdline = {
"license", &mu_license_argp_child
};
/* ************************************************************************* */
/* Mailbox */
/* ************************************************************************* */
/* Options used by programs that access mailboxes. */
static struct argp_option mu_mailbox_argp_option[] = {
{ "mail-spool", 'm', N_("URL"), OPTION_HIDDEN,
N_("use specified URL as a mailspool directory"), 0 },
{ "mailbox-pattern", OPT_MAILBOX_PATTERN, N_("pat"), OPTION_HIDDEN,
"", 0 },
{ "mailbox-type", OPT_MAILBOX_TYPE, N_("PROTO"), OPTION_HIDDEN,
N_("default mailbox type to use"), 0 },
{ "mail-folder", OPT_MAIL_FOLDER, N_("DIR"), OPTION_HIDDEN,
N_("default user mail folder"), 0 },
{ NULL }
};
static error_t
mu_mailbox_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
/* mailbox */
case 'm':
mu_argp_node_list_new (&lst, "mail-spool", arg);
break;
case OPT_MAILBOX_PATTERN:
mu_argp_node_list_new (&lst, "mailbox-pattern", arg);
break;
case OPT_MAILBOX_TYPE:
mu_argp_node_list_new (&lst, "mailbox-type", arg);
break;
case OPT_MAIL_FOLDER:
mu_argp_node_list_new (&lst, "folder", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "mailbox", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_mailbox_argp = {
mu_mailbox_argp_option,
mu_mailbox_argp_parser,
};
struct argp_child mu_mailbox_argp_child = {
&mu_mailbox_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_mailbox_cmdline = {
"mailbox", &mu_mailbox_argp_child
};
/* ************************************************************************* */
/* Locking */
/* ************************************************************************* */
/* Options used by programs that access mailboxes. */
static struct argp_option mu_locking_argp_option[] = {
{"lock-flags", OPT_LOCK_FLAGS, N_("FLAGS"), OPTION_HIDDEN,
N_("default locker flags (E=external, R=retry, T=time, P=pid)"), 0},
{"lock-retry-timeout", OPT_LOCK_RETRY_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN,
N_("set timeout for acquiring the lockfile") },
{"lock-retry-count", OPT_LOCK_RETRY_COUNT, N_("NUMBER"), OPTION_HIDDEN,
N_("set the maximum number of times to retry acquiring the lockfile") },
{"lock-expire-timeout", OPT_LOCK_EXPIRE_TIMEOUT, N_("SECONDS"),
OPTION_HIDDEN,
N_("number of seconds after which the lock expires"), },
{"external-locker", OPT_LOCK_EXTERNAL_PROGRAM, N_("PATH"), OPTION_HIDDEN,
N_("set full path to the external locker program") },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_locking_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
case OPT_LOCK_FLAGS:
mu_argp_node_list_new (&lst, "flags", arg);
break;
case OPT_LOCK_RETRY_COUNT:
mu_argp_node_list_new (&lst, "retry-count", arg);
break;
case OPT_LOCK_RETRY_TIMEOUT:
mu_argp_node_list_new (&lst, "retry-timeout", arg);
break;
case OPT_LOCK_EXPIRE_TIMEOUT:
mu_argp_node_list_new (&lst, "expire-timeout", arg);
break;
case OPT_LOCK_EXTERNAL_PROGRAM:
mu_argp_node_list_new (&lst, "external-locker", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "locking", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_locking_argp = {
mu_locking_argp_option,
mu_locking_argp_parser,
};
struct argp_child mu_locking_argp_child = {
&mu_locking_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_locking_cmdline = {
"locking", &mu_locking_argp_child
};
/* ************************************************************************* */
/* Address */
/* ************************************************************************* */
/* Options used by programs that do address mapping. */
static struct argp_option mu_address_argp_option[] = {
{"email-addr", 'E', N_("EMAIL"), OPTION_HIDDEN,
N_("set current user's email address (default is loginname@defaultdomain)"), 0},
{"email-domain", 'D', N_("DOMAIN"), OPTION_HIDDEN,
N_("set domain for unqualified user names (default is this host)"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_address_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
case 'E':
mu_argp_node_list_new (&lst, "email-addr", arg);
break;
case 'D':
mu_argp_node_list_new (&lst, "email-domain", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "address", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_address_argp = {
mu_address_argp_option,
mu_address_argp_parser,
};
struct argp_child mu_address_argp_child = {
&mu_address_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_address_cmdline = {
"address", &mu_address_argp_child
};
/* ************************************************************************* */
/* Mailer */
/* ************************************************************************* */
/* Options used by programs that send mail. */
static struct argp_option mu_mailer_argp_option[] = {
{"mailer", 'M', N_("MAILER"), 0,
N_("use specified URL as the default mailer"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_mailer_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
/* mailer */
case 'M':
mu_argp_node_list_new (&lst, "url", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "mailer", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_mailer_argp = {
mu_mailer_argp_option,
mu_mailer_argp_parser,
};
struct argp_child mu_mailer_argp_child = {
&mu_mailer_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_mailer_cmdline = {
"mailer", &mu_mailer_argp_child
};
static struct argp_option mu_debug_argp_options[] =
{
{ "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
N_("set Mailutils debugging level"), 0 },
{ "debug-line-info", OPT_LINE_INFO, NULL, 0,
N_("show source info with debugging messages"), 0 },
{ NULL }
};
static error_t
mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
case OPT_DEBUG_LEVEL:
mu_global_debug_from_string (arg, "command line");
//mu_argp_node_list_new (&lst, "level", arg);
break;
case OPT_LINE_INFO:
mu_argp_node_list_new (&lst, "line-info", "yes");
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "debug", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_debug_argp = {
mu_debug_argp_options,
mu_debug_argp_parser,
};
struct argp_child mu_debug_argp_child = {
&mu_debug_argp,
0,
N_("Global debugging settings"),
0
};
struct mu_cmdline_capa mu_debug_cmdline = {
"debug", &mu_debug_argp_child
};