Commit d56b8243 d56b82437f909ff323d9cd87f2ed9f04322f9966 by Sergey Poznyakoff

Convert to mu_cli: frm, from, messages, mimeview, movemail, readmsg, sieve

* configure.ac (MU_APP_NEW_LIBRARIES): New temp variable.

* include/mailutils/sieve.h (mu_cli_capa_sieve): New extern.
* include/mailutils/tls.h (mu_cli_capa_tls): New extern.

* libmailutils/cli/cli.c: Minor change.
* libmailutils/cli/stdcapa.c: Add "auth" capability.

* libmu_auth/tls.c: provide mu_cli_capa_tls

* dotlock/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* dotlock/dotlock.c

* frm/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* frm/frm.h: Fix includes.
* frm/frm.c: Use mu_cli for optionr&config parsing.
* frm/from.c: Likewise.

* messages/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* messages/messages.c: Use mu_cli for optionr&config parsing.

* mimeview/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* mimeview/mimeview.c: Use mu_cli for optionr&config parsing.

* movemail/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* movemail/movemail.c: Use mu_cli for optionr&config parsing.

* readmsg/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* readmsg/readmsg.c: Use mu_cli for optionr&config parsing.

* sieve/Makefile.am: Link with MU_APP_NEW_LIBRARIES
* sieve/sieve.c: Use mu_cli for optionr&config parsing.
1 parent 260b113a
...@@ -58,6 +58,7 @@ AC_SUBST(MU_SIEVE_MODDIR,'$(libdir)/$(PACKAGE)') ...@@ -58,6 +58,7 @@ AC_SUBST(MU_SIEVE_MODDIR,'$(libdir)/$(PACKAGE)')
58 58
59 AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)') 59 AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)')
60 AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/libmu_argp/libmu_argp.la ${top_builddir}/libmu_cfg/libmu_cfg.la ${top_builddir}/lib/libmuaux.la') 60 AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/libmu_argp/libmu_argp.la ${top_builddir}/libmu_cfg/libmu_cfg.la ${top_builddir}/lib/libmuaux.la')
61 AC_SUBST(MU_APP_NEW_LIBRARIES,'${top_builddir}/lib/libmuaux.la')
61 62
62 # There are two sets of include directories: MU_LIB_COMMON_INCLUDES, used 63 # There are two sets of include directories: MU_LIB_COMMON_INCLUDES, used
63 # by the libraries, and MU_APP_COMMON_INCLUDES, which is used by applications. 64 # by the libraries, and MU_APP_COMMON_INCLUDES, which is used by applications.
......
...@@ -20,7 +20,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ ...@@ -20,7 +20,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
20 bin_PROGRAMS = dotlock 20 bin_PROGRAMS = dotlock
21 21
22 dotlock_LDADD = \ 22 dotlock_LDADD = \
23 ${MU_APP_LIBRARIES}\ 23 ${MU_APP_NEW_LIBRARIES}\
24 ${MU_LIB_MAILUTILS}\ 24 ${MU_LIB_MAILUTILS}\
25 @MU_COMMON_LIBRARIES@ 25 @MU_COMMON_LIBRARIES@
26 26
......
...@@ -20,49 +20,12 @@ ...@@ -20,49 +20,12 @@
20 #endif 20 #endif
21 21
22 #include <stdlib.h> 22 #include <stdlib.h>
23 #ifdef __EXT_QNX
24 # undef __EXT_QNX
25 #endif
26 #include <unistd.h> 23 #include <unistd.h>
27 24
28 #include <mailutils/errno.h> 25 #include <mailutils/errno.h>
29 #include <mailutils/locker.h> 26 #include <mailutils/locker.h>
30 #include <mailutils/nls.h> 27 #include <mailutils/nls.h>
31 28 #include "mailutils/cli.h"
32 #include "mailutils/libargp.h"
33
34 static char doc[] =
35 N_("GNU dotlock -- lock mail spool files.")
36 "\v"
37 N_("Returns 0 on success, 3 if locking the file fails because\
38 it's already locked, and 1 if some other kind of error occurred.");
39
40 static char args_doc[] = N_("FILE");
41
42 static struct argp_option options[] = {
43 {"unlock", 'u', NULL, 0,
44 N_("unlock"), 0},
45
46 {"force", 'f', N_("MINUTES"), OPTION_ARG_OPTIONAL,
47 N_("forcibly break an existing lock older than a certain time"), 0},
48
49 {"retry", 'r', N_("RETRIES"), OPTION_ARG_OPTIONAL,
50 N_("retry the lock a few times"), 0},
51
52 {"debug", 'd', NULL, 0,
53 N_("print details of failure reasons to stderr"), 0},
54
55 {NULL, 0, NULL, 0, NULL, 0}
56 };
57
58 static error_t parse_opt (int key, char *arg, struct argp_state *state);
59
60 static struct argp argp = {
61 options,
62 parse_opt,
63 args_doc,
64 doc,
65 };
66 29
67 static const char *file; 30 static const char *file;
68 static int unlock; 31 static int unlock;
...@@ -71,55 +34,25 @@ static int retries; ...@@ -71,55 +34,25 @@ static int retries;
71 static time_t force; 34 static time_t force;
72 static int debug; 35 static int debug;
73 36
74 static error_t 37 static struct mu_option dotlock_options[] = {
75 parse_opt (int key, char *arg, struct argp_state *state) 38 { "unlock", 'u', NULL, MU_OPTION_DEFAULT,
76 { 39 N_("unlock"),
77 static mu_list_t lst; 40 mu_c_bool, &unlock },
78 41
79 switch (key) 42 { "force", 'f', N_("MINUTES"), MU_OPTION_ARG_OPTIONAL,
80 { 43 N_("forcibly break an existing lock older than a certain time"),
81 case 'd': 44 mu_c_time, &force },//FIXME: Default value
82 mu_argp_node_list_new (lst, "debug", "yes"); 45
83 break; 46 { "retry", 'r', N_("RETRIES"), MU_OPTION_ARG_OPTIONAL,
84 47 N_("retry the lock a few times"),
85 case 'u': 48 mu_c_int, &retries },
86 unlock = 1; 49
87 break; 50 { "debug", 'd', NULL, MU_OPTION_DEFAULT,
88 51 N_("print details of failure reasons to stderr"),
89 case 'r': 52 mu_c_bool, &debug },
90 if (arg) 53
91 mu_argp_node_list_new (lst, "retry", arg); 54 MU_OPTION_END
92 break; 55 }, *options[] = { dotlock_options, NULL };
93
94 case 'f':
95 mu_argp_node_list_new (lst, "force", arg ? arg : "0");
96 break;
97
98 case ARGP_KEY_ARG:
99 if (file)
100 argp_error (state, _("only one FILE can be specified"));
101 file = arg;
102 break;
103
104 case ARGP_KEY_NO_ARGS:
105 if (!mu_help_config_mode)
106 argp_error (state, _("FILE must be specified"));
107 return ARGP_ERR_UNKNOWN;
108
109 case ARGP_KEY_INIT:
110 mu_argp_node_list_init (&lst);
111 break;
112
113 case ARGP_KEY_FINI:
114 mu_argp_node_list_finish (lst, NULL, NULL);
115 break;
116
117 default:
118 return ARGP_ERR_UNKNOWN;
119 }
120 return 0;
121 }
122
123 56
124 struct mu_cfg_param dotlock_cfg_param[] = { 57 struct mu_cfg_param dotlock_cfg_param[] = {
125 { "force", mu_c_time, &force, 0, NULL, 58 { "force", mu_c_time, &force, 0, NULL,
...@@ -130,12 +63,22 @@ struct mu_cfg_param dotlock_cfg_param[] = { ...@@ -130,12 +63,22 @@ struct mu_cfg_param dotlock_cfg_param[] = {
130 N_("Print details of failure reasons to stderr.") }, 63 N_("Print details of failure reasons to stderr.") },
131 { NULL } 64 { NULL }
132 }; 65 };
66
67 static struct mu_cli_setup cli = {
68 options,
69 dotlock_cfg_param,
70 N_("GNU dotlock -- lock mail spool files."),
71 //FIXME:
72 /*
73 N_("Returns 0 on success, 3 if locking the file fails because\
74 it's already locked, and 1 if some other kind of error occurred.");
75 */
76 N_("FILE")
77 };
133 78
134 79
135 80
136 const char *dotlock_capa[] = { 81 char *capa[] = {
137 "mailutils",
138 "common",
139 "debug", 82 "debug",
140 NULL 83 NULL
141 }; 84 };
...@@ -156,13 +99,24 @@ main (int argc, char *argv[]) ...@@ -156,13 +99,24 @@ main (int argc, char *argv[])
156 if (setegid (usergid) < 0) 99 if (setegid (usergid) < 0)
157 return MU_DL_EX_ERROR; 100 return MU_DL_EX_ERROR;
158 101
159 argp_err_exit_status = MU_DL_EX_ERROR; 102 /* FIXME: Force mu_cli to exit with MU_DL_EX_ERROR on errors? */
160 103
161 mu_argp_init (NULL, NULL); 104 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
162 if (mu_app_init (&argp, dotlock_capa, dotlock_cfg_param, 105
163 argc, argv, 0, NULL, NULL)) 106 switch (argc)
164 exit (1); 107 {
108 case 0:
109 mu_error (_("FILE must be specified"));
110 exit (MU_DL_EX_ERROR);
111
112 case 1:
113 file = argv[0];
114 break;
165 115
116 default:
117 mu_error (_("only one FILE can be specified"));
118 }
119
166 if (force) 120 if (force)
167 { 121 {
168 force *= 60; 122 force *= 60;
......
...@@ -27,7 +27,7 @@ frm_LDADD = $(common_ldadd) ...@@ -27,7 +27,7 @@ frm_LDADD = $(common_ldadd)
27 from_LDADD = $(common_ldadd) 27 from_LDADD = $(common_ldadd)
28 28
29 common_ldadd = \ 29 common_ldadd = \
30 ${MU_APP_LIBRARIES}\ 30 ${MU_APP_NEW_LIBRARIES}\
31 ${MU_LIB_MBOX}\ 31 ${MU_LIB_MBOX}\
32 ${MU_LIB_IMAP}\ 32 ${MU_LIB_IMAP}\
33 ${MU_LIB_POP}\ 33 ${MU_LIB_POP}\
......
...@@ -29,8 +29,6 @@ static int align = 0; /* Tidy mode. -t option. */ ...@@ -29,8 +29,6 @@ static int align = 0; /* Tidy mode. -t option. */
29 #define IS_NEW 0x100 29 #define IS_NEW 0x100
30 static int select_attribute; 30 static int select_attribute;
31 31
32 static char doc[] = N_("GNU frm -- display From: lines.");
33
34 static struct attr_tab { 32 static struct attr_tab {
35 char *name; /* Attribute name */ 33 char *name; /* Attribute name */
36 int code; /* Corresponding IS_.* flag */ 34 int code; /* Corresponding IS_.* flag */
...@@ -84,7 +82,7 @@ prepare_attrs (void) ...@@ -84,7 +82,7 @@ prepare_attrs (void)
84 /* Translates the textual status representation to the corresponding 82 /* Translates the textual status representation to the corresponding
85 IS_.* flag */ 83 IS_.* flag */
86 static int 84 static int
87 decode_attr (char *arg) 85 decode_attr (char const *arg)
88 { 86 {
89 struct attr_tab *p; 87 struct attr_tab *p;
90 int len = strlen (arg); 88 int len = strlen (arg);
...@@ -111,105 +109,82 @@ decode_attr (char *arg) ...@@ -111,105 +109,82 @@ decode_attr (char *arg)
111 } 109 }
112 110
113 111
112 static void
113 cli_show_field (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
114 {
115 show_field = mu_strdup (arg);
116 align = 0;
117 }
114 118
115 static struct argp_option options[] = { 119 static void
116 {"debug", 'd', NULL, 0, N_("enable debugging output"), 0}, 120 cli_Quiet (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
117 {"field", 'f', N_("NAME"), 0, N_("header field to display"), 0}, 121 {
118 {"to", 'l', NULL, 0, N_("include the To: information"), 0}, 122 be_quiet += 2;
119 {"number", 'n', NULL, 0, N_("display message numbers"), 0}, 123 }
120 {"Quiet", 'Q', NULL, 0, N_("do not display headers"), 0},
121 {"query", 'q', NULL, 0, N_("print a message if the mailbox contains some unread mail"), 0},
122 {"summary",'S', NULL, 0, N_("print a summary of messages"), 0},
123 {"status", 's', N_("STATUS"), 0,
124 /* TRANSLATORS: Please do *not* translate the words "new", "unread",
125 "old" and "read". They are keywords. */
126 N_("select messages with the specific attribute:"
127 " new, unread, old (same as unread) or read (or any unambiguous"
128 " abbreviation of these)"),
129 0},
130 {"align", 't', NULL, 0, N_("tidy mode: align subject lines"), 0},
131 {0, 0, 0, 0}
132 };
133 124
134 static error_t 125 static void
135 parse_opt (int key, char *arg, struct argp_state *state) 126 cli_query (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
136 { 127 {
137 switch (key) 128 be_quiet++;
138 { 129 show_query = 1;
139 case 'd': 130 }
140 frm_debug++; 131
141 break; 132 static void
142 133 cli_status (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
143 case 'f': 134 {
144 show_field = arg; 135 select_attribute = decode_attr (arg);
145 align = 0;
146 break;
147
148 case 'l':
149 show_to = 1;
150 break;
151
152 case 'n':
153 show_number = 1;
154 break;
155
156 case 'Q':
157 /* Very silent. */
158 be_quiet += 2;
159 break;
160
161 case 'q':
162 be_quiet++;
163 show_query = 1;
164 break;
165
166 case 'S':
167 show_summary = 1;
168 break;
169
170 case 's':
171 select_attribute = decode_attr (arg);
172 break;
173
174 case 't':
175 align = 1;
176 break;
177
178 case ARGP_KEY_FINI:
179 {
180 size_t s;
181 if (align && (s = util_getcols ()))
182 init_output (s);
183 else
184 init_output (0);
185 }
186 break;
187
188 default:
189 return ARGP_ERR_UNKNOWN;
190 }
191 return 0;
192 } 136 }
193 137
194 static struct argp argp = { 138 static struct mu_option frm_options[] = {
139 { "debug", 'd', NULL, MU_OPTION_DEFAULT,
140 N_("enable debugging output"),
141 mu_c_incr, &frm_debug },
142 { "field", 'f', N_("NAME"), MU_OPTION_DEFAULT,
143 N_("header field to display"),
144 mu_c_string, &show_field, cli_show_field },
145 { "to", 'l', NULL, MU_OPTION_DEFAULT,
146 N_("include the To: information"),
147 mu_c_bool, &show_to },
148 { "number", 'n', NULL, MU_OPTION_DEFAULT,
149 N_("display message numbers"),
150 mu_c_bool, &show_number },
151 { "Quiet", 'Q', NULL, MU_OPTION_DEFAULT,
152 N_("do not display headers"),
153 mu_c_int, &be_quiet, cli_Quiet },
154 { "query", 'q', NULL, MU_OPTION_DEFAULT,
155 N_("print a message if the mailbox contains some unread mail"),
156 mu_c_int, &be_quiet, cli_query },
157 { "summary",'S', NULL, MU_OPTION_DEFAULT,
158 N_("print a summary of messages"),
159 mu_c_bool, &show_summary },
160 { "status", 's', N_("STATUS"), 0,
161 /* TRANSLATORS: Please do *not* translate the words "new", "unread",
162 "old" and "read". They are keywords. */
163 N_("select messages with the specific attribute:"
164 " new, unread, old (same as unread) or read (or any unambiguous"
165 " abbreviation of these)"),
166 mu_c_string, NULL, cli_status},
167 { "align", 't', NULL, MU_OPTION_DEFAULT,
168 N_("tidy mode: align subject lines"),
169 mu_c_bool, &align },
170 MU_OPTION_END
171 }, *options[] = { frm_options, NULL };
172
173 static struct mu_cli_setup cli = {
195 options, 174 options,
196 parse_opt,
197 N_("[URL ...]"),
198 doc,
199 NULL, 175 NULL,
200 NULL, NULL 176 N_("GNU frm -- display From: lines."),
177 N_("[URL ...]"),
201 }; 178 };
202 179
203 static const char *frm_argp_capa[] = { 180 static char *frm_argp_capa[] = {
204 "mailutils",
205 "common",
206 "debug", 181 "debug",
207 "mailbox", 182 "mailbox",
208 "locking", 183 "locking",
184 "tls",
209 NULL 185 NULL
210 }; 186 };
211 187
212
213 static struct 188 static struct
214 { 189 {
215 size_t new; 190 size_t new;
...@@ -342,8 +317,8 @@ frm (char *mailbox_name) ...@@ -342,8 +317,8 @@ frm (char *mailbox_name)
342 int 317 int
343 main (int argc, char **argv) 318 main (int argc, char **argv)
344 { 319 {
345 int c;
346 int status = 0; 320 int status = 0;
321 size_t s;
347 322
348 /* Native Language Support */ 323 /* Native Language Support */
349 MU_APP_INIT_NLS (); 324 MU_APP_INIT_NLS ();
...@@ -352,25 +327,30 @@ main (int argc, char **argv) ...@@ -352,25 +327,30 @@ main (int argc, char **argv)
352 327
353 /* register the formats. */ 328 /* register the formats. */
354 mu_register_all_mbox_formats (); 329 mu_register_all_mbox_formats ();
355 #ifdef WITH_TLS
356 mu_gocs_register ("tls", mu_tls_module_init);
357 #endif
358
359 mu_argp_init (NULL, NULL);
360 if (mu_app_init (&argp, frm_argp_capa, NULL, argc, argv, 0, &c, NULL))
361 exit (1);
362 330
331 mu_cli_capa_register (&mu_cli_capa_tls);
332 mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
333
334 if (align && (s = util_getcols ()))
335 init_output (s);
336 else
337 init_output (0);
338
363 /* have an argument */ 339 /* have an argument */
364 if (c == argc) 340 if (argc == 0)
365 status = frm (NULL); 341 status = frm (NULL);
366 else if (c + 1 == argc) 342 else if (argc == 1)
367 status = frm (argv[c]); 343 status = frm (argv[0]);
368 else 344 else
369 for (; c < argc; c++) 345 {
370 { 346 int i;
371 mu_printf ("%s:\n", argv[c]); 347
372 status = frm (argv[c]); 348 for (i = 0; i < argc; i++)
373 } 349 {
374 350 mu_printf ("%s:\n", argv[i]);
351 status = frm (argv[i]);
352 }
353 }
354
375 return status; 355 return status;
376 } 356 }
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
64 #include <mailutils/util.h> 64 #include <mailutils/util.h>
65 #include <mailutils/mime.h> 65 #include <mailutils/mime.h>
66 66
67 #include "mailutils/libargp.h" 67 #include "mailutils/cli.h"
68 68
69 typedef int (*frm_select_t) (size_t index, mu_message_t msg); 69 typedef int (*frm_select_t) (size_t index, mu_message_t msg);
70 70
......
...@@ -21,58 +21,34 @@ int count_only; ...@@ -21,58 +21,34 @@ int count_only;
21 char *sender_option; 21 char *sender_option;
22 char *mailbox_name; 22 char *mailbox_name;
23 23
24 static char doc[] = N_("GNU from -- display from and subject."); 24 static struct mu_option from_options[] = {
25 25 { "count", 'c', NULL, MU_OPTION_DEFAULT,
26 static struct argp_option options[] = { 26 N_("just print a count of messages and exit"),
27 {"count", 'c', NULL, 0, N_("just print a count of messages and exit")}, 27 mu_c_bool, &count_only },
28 {"sender", 's', N_("ADDRESS"), 0, 28 { "sender", 's', N_("ADDRESS"), MU_OPTION_DEFAULT,
29 N_("print only mail from addresses containing the supplied string") }, 29 N_("print only mail from addresses containing the supplied string"),
30 {"file", 'f', N_("FILE"), 0, 30 mu_c_string, &sender_option },
31 N_("read mail from FILE") }, 31 { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
32 {"debug", 'd', NULL, 0, N_("enable debugging output"), 0}, 32 N_("read mail from FILE"),
33 {0, 0, 0, 0} 33 mu_c_string, &mailbox_name },
34 }; 34 { "debug", 'd', NULL, MU_OPTION_DEFAULT,
35 35 N_("enable debugging output"),
36 static error_t 36 mu_c_incr, &frm_debug },
37 parse_opt (int key, char *arg, struct argp_state *state) 37 MU_OPTION_END
38 { 38 }, *options[] = { from_options, NULL };
39 switch (key) 39
40 { 40 static struct mu_cli_setup cli = {
41 case 'c':
42 count_only = 1;
43 break;
44
45 case 's':
46 sender_option = arg;
47 break;
48
49 case 'f':
50 mailbox_name = arg;
51 break;
52
53 case 'd':
54 frm_debug++;
55 break;
56
57 default:
58 return ARGP_ERR_UNKNOWN;
59 }
60 return 0;
61 }
62
63 static struct argp argp = {
64 options, 41 options,
65 parse_opt, 42 NULL,
43 N_("GNU from -- display from and subject."),
66 N_("[OPTIONS] [USER]"), 44 N_("[OPTIONS] [USER]"),
67 doc,
68 }; 45 };
69 46
70 static const char *capa[] = { 47 static char *capa[] = {
71 "mailutils",
72 "common",
73 "debug", 48 "debug",
74 "mailbox", 49 "mailbox",
75 "locking", 50 "locking",
51 "tls",
76 NULL 52 NULL
77 }; 53 };
78 54
...@@ -105,7 +81,6 @@ from_select (size_t index, mu_message_t msg) ...@@ -105,7 +81,6 @@ from_select (size_t index, mu_message_t msg)
105 int 81 int
106 main (int argc, char **argv) 82 main (int argc, char **argv)
107 { 83 {
108 int c;
109 size_t total; 84 size_t total;
110 85
111 /* Native Language Support */ 86 /* Native Language Support */
...@@ -113,20 +88,16 @@ main (int argc, char **argv) ...@@ -113,20 +88,16 @@ main (int argc, char **argv)
113 88
114 /* register the formats. */ 89 /* register the formats. */
115 mu_register_all_mbox_formats (); 90 mu_register_all_mbox_formats ();
116 #ifdef WITH_TLS
117 mu_gocs_register ("tls", mu_tls_module_init);
118 #endif
119 91
120 mu_argp_init (NULL, NULL); 92 mu_cli_capa_register (&mu_cli_capa_tls);
121 if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &c, NULL)) 93 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
122 exit (1);
123 94
124 if (argc - c > 1) 95 if (argc > 1)
125 { 96 {
126 mu_error (_("too many arguments")); 97 mu_error (_("too many arguments"));
127 exit (1); 98 exit (1);
128 } 99 }
129 else if (argc - c > 0) 100 else if (argc > 0)
130 { 101 {
131 if (mailbox_name) 102 if (mailbox_name)
132 { 103 {
...@@ -134,9 +105,9 @@ main (int argc, char **argv) ...@@ -134,9 +105,9 @@ main (int argc, char **argv)
134 exit (1); 105 exit (1);
135 } 106 }
136 107
137 mailbox_name = mu_alloc (strlen (argv[c]) + 2); 108 mailbox_name = mu_alloc (strlen (argv[0]) + 2);
138 mailbox_name[0] = '%'; 109 mailbox_name[0] = '%';
139 strcpy (mailbox_name + 1, argv[c]); 110 strcpy (mailbox_name + 1, argv[0]);
140 } 111 }
141 112
142 init_output (0); 113 init_output (0);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
22 #include <sys/types.h> 22 #include <sys/types.h>
23 #include <stdarg.h> 23 #include <stdarg.h>
24 #include <mailutils/mailutils.h> 24 #include <mailutils/mailutils.h>
25 #include <mailutils/cli.h>
25 26
26 #ifdef __cplusplus 27 #ifdef __cplusplus
27 extern "C" { 28 extern "C" {
...@@ -282,6 +283,8 @@ struct mu_gocs_sieve ...@@ -282,6 +283,8 @@ struct mu_gocs_sieve
282 283
283 int mu_sieve_module_init (enum mu_gocs_op, void *); 284 int mu_sieve_module_init (enum mu_gocs_op, void *);
284 285
286 extern struct mu_cli_capa mu_cli_capa_sieve;
287
285 #ifdef __cplusplus 288 #ifdef __cplusplus
286 } 289 }
287 #endif 290 #endif
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
20 #define _MAILUTILS_TLS_H 20 #define _MAILUTILS_TLS_H
21 21
22 #include <mailutils/types.h> 22 #include <mailutils/types.h>
23 #include <mailutils/cli.h>
23 24
24 #ifdef __cplusplus 25 #ifdef __cplusplus
25 extern "C" { 26 extern "C" {
...@@ -55,6 +56,8 @@ extern int mu_init_tls_libs (int x509); ...@@ -55,6 +56,8 @@ extern int mu_init_tls_libs (int x509);
55 extern void mu_deinit_tls_libs (void); 56 extern void mu_deinit_tls_libs (void);
56 57
57 extern int mu_tls_enable; 58 extern int mu_tls_enable;
59
60 extern struct mu_cli_capa mu_cli_capa_tls;
58 61
59 #ifdef __cplusplus 62 #ifdef __cplusplus
60 } 63 }
......
...@@ -384,7 +384,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -384,7 +384,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
384 optv = init_options (capa, setup, &com_list); 384 optv = init_options (capa, setup, &com_list);
385 385
386 if (mu_parseopt (&po, argc, argv, optv, flags)) 386 if (mu_parseopt (&po, argc, argv, optv, flags))
387 exit (EX_USAGE); 387 exit (po.po_exit_error);
388 388
389 argc -= po.po_arg_start; 389 argc -= po.po_arg_start;
390 argv += po.po_arg_start; 390 argv += po.po_arg_start;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
28 #include <mailutils/mailbox.h> 28 #include <mailutils/mailbox.h>
29 #include <mailutils/registrar.h> 29 #include <mailutils/registrar.h>
30 #include <mailutils/locker.h> 30 #include <mailutils/locker.h>
31 #include <mailutils/mu_auth.h>
31 32
32 /* ************************************************************************* 33 /* *************************************************************************
33 * Logging section 34 * Logging section
...@@ -440,7 +441,106 @@ static struct mu_cfg_param address_cfg[] = { ...@@ -440,7 +441,106 @@ static struct mu_cfg_param address_cfg[] = {
440 N_("domain: string") }, 441 N_("domain: string") },
441 { NULL } 442 { NULL }
442 }; 443 };
444
445 /* ************************************************************************* *
446 * Authentication & Authorization *
447 * ************************************************************************* */
448 static int
449 cb_authentication (void *data, mu_config_value_t *val)
450 {
451 if (val->type == MU_CFG_STRING)
452 {
453 if (strcmp (val->v.string, "clear") == 0)
454 mu_authentication_clear_list ();
455 else
456 /*FIXME: use err for error reporting*/
457 mu_authentication_add_module_list (val->v.string);
458 }
459 else if (val->type == MU_CFG_LIST)
460 {
461 int i;
462 for (i = 0; i < val->v.arg.c; i++)
463 {
464 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
465 return 1;
466 if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
467 mu_authentication_clear_list ();
468 else
469 mu_authentication_add_module (val->v.arg.v[i].v.string);
470 }
471 }
472 else
473 {
474 mu_error (_("expected string value"));
475 return 1;
476 }
477 return 0;
478 }
479
480 static int
481 cb_authorization (void *data, mu_config_value_t *val)
482 {
483 if (val->type == MU_CFG_STRING)
484 {
485 if (strcmp (val->v.string, "clear") == 0)
486 mu_authorization_clear_list ();
487 else
488 /*FIXME: use err for error reporting*/
489 mu_authorization_add_module_list (val->v.string);
490 }
491 else if (val->type == MU_CFG_LIST)
492 {
493 int i;
494 for (i = 0; i < val->v.arg.c; i++)
495 {
496 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
497 return 1;
498 if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
499 mu_authorization_clear_list ();
500 else
501 mu_authorization_add_module (val->v.arg.v[i].v.string);
502 }
503 }
504 else
505 {
506 mu_error (_("expected string value"));
507 return 1;
508 }
509 return 0;
510 }
443 511
512 static struct mu_cfg_param mu_auth_param[] = {
513 { "authentication", mu_cfg_callback, NULL, 0, cb_authentication,
514 /* FIXME: The description is incomplete. MU-list is also allowed as
515 argument */
516 N_("Set a list of modules for authentication. Modlist is a "
517 "colon-separated list of module names or a word `clear' to "
518 "clear the previously set up values."),
519 N_("modlist") },
520 { "authorization", mu_cfg_callback, NULL, 0, cb_authorization,
521 N_("Set a list of modules for authorization. Modlist is a "
522 "colon-separated list of module names or a word `clear' to "
523 "clear the previously set up values."),
524 N_("modlist") },
525 { NULL }
526 };
527
528 int
529 mu_auth_section_parser
530 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
531 const char *section_label, void **section_data, void *call_data,
532 mu_cfg_tree_t *tree)
533 {
534 switch (stage)
535 {
536 case mu_cfg_section_start:
537 break;
538
539 case mu_cfg_section_end:
540 mu_auth_finish_setup ();
541 }
542 return 0;
543 }
444 544
445 /* ************************************************************************* * 545 /* ************************************************************************* *
446 * Registry of standard mailutils' capabilities * 546 * Registry of standard mailutils' capabilities *
...@@ -453,6 +553,8 @@ struct mu_cli_capa mu_cli_std_capa[] = { ...@@ -453,6 +553,8 @@ struct mu_cli_capa mu_cli_std_capa[] = {
453 { "mailbox", NULL, mailbox_cfg, NULL, NULL }, 553 { "mailbox", NULL, mailbox_cfg, NULL, NULL },
454 { "locking", NULL, locking_cfg, NULL, NULL }, 554 { "locking", NULL, locking_cfg, NULL, NULL },
455 { "address", NULL, address_cfg, NULL, NULL }, 555 { "address", NULL, address_cfg, NULL, NULL },
556 { "auth", NULL, mu_auth_param, mu_auth_section_parser },
557
456 { NULL } 558 { NULL }
457 }; 559 };
458 560
......
...@@ -35,15 +35,36 @@ ...@@ -35,15 +35,36 @@
35 #include <mailutils/errno.h> 35 #include <mailutils/errno.h>
36 #include <mailutils/util.h> 36 #include <mailutils/util.h>
37 #include <mailutils/property.h> 37 #include <mailutils/property.h>
38 #include <mailutils/cli.h>
39
40 #define SSL_CERT_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
41 MU_FILE_SAFETY_GROUP_WRITABLE | \
42 MU_FILE_SAFETY_LINKED_WRDIR)
43
44 #define SSL_KEY_FILE_CHECKS (MU_FILE_SAFETY_ALL & \
45 ~MU_FILE_SAFETY_OWNER_MISMATCH)
46
47 #define SSL_CA_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
48 MU_FILE_SAFETY_GROUP_WRITABLE | \
49 MU_FILE_SAFETY_LINKED_WRDIR)
38 50
39 struct mu_tls_module_config mu_tls_module_config = { 51 struct mu_tls_module_config mu_tls_module_config = {
40 #ifdef WITH_TLS 52 #ifdef WITH_TLS
41 1 /* enable by default */ 53 1, /* enable by default */
54
55 NULL, /* Certificate file */
56 SSL_CERT_FILE_CHECKS,
57
58 NULL, /* Key file */
59 SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
60
61 NULL, /* CA file */
62 SSL_CA_FILE_CHECKS
42 #else 63 #else
43 0 64 0
44 #endif 65 #endif
45 }; 66 };
46 67 //FIXME: REMOVE
47 int 68 int
48 mu_tls_module_init (enum mu_gocs_op op, void *data) 69 mu_tls_module_init (enum mu_gocs_op op, void *data)
49 { 70 {
...@@ -774,8 +795,92 @@ mu_tls_client_stream_create (mu_stream_t *pstream, ...@@ -774,8 +795,92 @@ mu_tls_client_stream_create (mu_stream_t *pstream,
774 _tls_client_open, 795 _tls_client_open,
775 strin, strout, flags); 796 strin, strout, flags);
776 } 797 }
798
799 static int
800 cb2_safety_checks (const char *name, void *data)
801 {
802 int defval;
803
804 if (data == &mu_tls_module_config.ssl_key_safety_checks)
805 defval = SSL_KEY_FILE_CHECKS;
806 else if (data == &mu_tls_module_config.ssl_cert_safety_checks)
807 defval = SSL_CERT_FILE_CHECKS;
808 else if (data == &mu_tls_module_config.ssl_cafile_safety_checks)
809 defval = SSL_CA_FILE_CHECKS;
810 else
811 {
812 mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
813 __FILE__, __LINE__);
814 defval = MU_FILE_SAFETY_ALL;
815 }
816 if (mu_file_safety_compose (data, name, defval))
817 mu_error (_("unknown keyword: %s"), name);
818 return 0;
819 }
777 820
778 821 static int
822 cb_safety_checks (void *data, mu_config_value_t *arg)
823 {
824 return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
825 }
826
827 static struct mu_cfg_param mu_tls_param[] = {
828 { "enable", mu_c_bool, &mu_tls_module_config.enable, 0, NULL,
829 N_("Enable TLS encryption.") },
830 { "ssl-cert", mu_c_string, &mu_tls_module_config.ssl_cert, 0, NULL,
831 N_("Specify SSL certificate file."),
832 N_("file") },
833 { "ssl-key", mu_c_string, &mu_tls_module_config.ssl_key, 0, NULL,
834 N_("Specify SSL certificate key file."),
835 N_("file") },
836 { "ssl-cafile", mu_c_string, &mu_tls_module_config.ssl_cafile, 0, NULL,
837 N_("Specify trusted CAs file."),
838 N_("file") },
839 { "ssl-priorities", mu_c_string, &mu_tls_module_config.priorities, 0, NULL,
840 N_("Set the priorities to use on the ciphers, key exchange methods, "
841 "macs and compression methods."),
842 NULL },
843 { "key-file-safety-checks", mu_cfg_callback,
844 &mu_tls_module_config.ssl_key_safety_checks, 0,
845 cb_safety_checks,
846 N_("Configure safety checks for SSL key file. Argument is a list or "
847 "sequence of check names optionally prefixed with '+' to enable or "
848 "'-' to disable the corresponding check. Valid check names are:\n"
849 "\n"
850 " none disable all checks\n"
851 " all enable all checks\n"
852 " gwrfil forbid group writable files\n"
853 " awrfil forbid world writable files\n"
854 " grdfil forbid group readable files\n"
855 " ardfil forbid world writable files\n"
856 " linkwrdir forbid symbolic links in group or world writable directories\n"
857 " gwrdir forbid files in group writable directories\n"
858 " awrdir forbid files in world writable directories\n"),
859 N_("arg: list") },
860 { "cert-file-safety-checks", mu_cfg_callback,
861 &mu_tls_module_config.ssl_cert_safety_checks, 0,
862 cb_safety_checks,
863 N_("Configure safety checks for SSL certificate. See above for a description of <arg>."),
864 N_("arg: list") },
865 { "ca-file-safety-checks", mu_cfg_callback,
866 &mu_tls_module_config.ssl_cafile_safety_checks, 0,
867 cb_safety_checks,
868 N_("Configure safety checks for SSL certificate authority file. See above for a description of <arg>."),
869 N_("arg: list") },
870 { NULL }
871 };
872
873 struct mu_cli_capa mu_cli_capa_tls = {
874 "tls",
875 NULL,
876 mu_tls_param,
877 NULL, NULL
878 };
879 #else
880 struct mu_cli_capa mu_cli_capa_tls = {
881 "tls",
882 NULL
883 };
779 #endif /* WITH_TLS */ 884 #endif /* WITH_TLS */
780 885
781 /* EOF */ 886 /* EOF */
......
...@@ -22,7 +22,7 @@ SUBDIRS = . tests ...@@ -22,7 +22,7 @@ SUBDIRS = . tests
22 bin_PROGRAMS = messages 22 bin_PROGRAMS = messages
23 messages_SOURCES = messages.c 23 messages_SOURCES = messages.c
24 messages_LDADD =\ 24 messages_LDADD =\
25 ${MU_APP_LIBRARIES}\ 25 ${MU_APP_NEW_LIBRARIES}\
26 ${MU_LIB_MBOX}\ 26 ${MU_LIB_MBOX}\
27 ${MU_LIB_IMAP}\ 27 ${MU_LIB_IMAP}\
28 ${MU_LIB_POP}\ 28 ${MU_LIB_POP}\
......
...@@ -20,85 +20,44 @@ ...@@ -20,85 +20,44 @@
20 #endif 20 #endif
21 21
22 #include <stdio.h> 22 #include <stdio.h>
23 #ifdef HAVE_MALLOC_H
24 # include <malloc.h>
25 #endif
26 23
27 #include <mailutils/mailutils.h> 24 #include <mailutils/mailutils.h>
28 #include "mailutils/libargp.h" 25 #include <mailutils/cli.h>
29 26
30 static int messages_count (const char *); 27 static int messages_count (const char *);
31 28
32 static char doc[] = N_("GNU messages -- count the number of messages in a mailbox"); 29 /* are we loud or quiet? */
33 static char args_doc[] = N_("[mailbox...]"); 30 static int silent = 0;
34 31
35 static struct argp_option options[] = { 32 static struct mu_option messages_options[] = {
36 { NULL, 0, NULL, 0, 33 { "quiet", 'q', NULL, MU_OPTION_DEFAULT,
37 /* TRANSLATORS: 'messages' is a program name. Do not translate it! */ 34 N_("only display number of messages"),
38 N_("messages specific switches:"), 0}, 35 mu_c_bool, &silent },
39 {"quiet", 'q', NULL, 0, N_("only display number of messages")}, 36 {"silent", 's', NULL, MU_OPTION_ALIAS },
40 {"silent", 's', NULL, OPTION_ALIAS, NULL }, 37 MU_OPTION_END
41 { 0 }
42 }; 38 };
43 39
44 static const char *argp_capa[] = { 40 static char *capa[] = {
45 "mailutils",
46 "common",
47 "debug", 41 "debug",
48 "mailbox", 42 "mailbox",
49 "locking", 43 "locking",
44 "tls",
50 NULL 45 NULL
51 }; 46 };
52 47
53 struct arguments 48 static struct mu_option *options[] = { messages_options, NULL };
54 {
55 int argc;
56 char **argv;
57 };
58 49
59 /* are we loud or quiet? */ 50 struct mu_cli_setup cli = {
60 static int silent = 0;
61
62 static error_t
63 parse_opt (int key, char *arg, struct argp_state *state)
64 {
65 struct arguments *args = state->input;
66 switch (key)
67 {
68 case 'q':
69 case 's':
70 silent = 1;
71 break;
72
73 case ARGP_KEY_ARG:
74 args->argv = realloc (args->argv,
75 sizeof (char *) * (state->arg_num + 2));
76 args->argv[state->arg_num] = arg;
77 args->argv[state->arg_num + 1] = NULL;
78 args->argc++;
79 break;
80
81 default:
82 return ARGP_ERR_UNKNOWN;
83 }
84 return 0;
85 }
86
87 static struct argp argp = {
88 options, 51 options,
89 parse_opt,
90 args_doc,
91 doc,
92 NULL, 52 NULL,
93 NULL, NULL 53 N_("GNU messages -- count the number of messages in a mailbox"),
54 N_("[mailbox...]")
94 }; 55 };
95 56
96 int 57 int
97 main (int argc, char **argv) 58 main (int argc, char **argv)
98 { 59 {
99 int i = 1;
100 int err = 0; 60 int err = 0;
101 struct arguments args = {0, NULL};
102 61
103 /* Native Language Support */ 62 /* Native Language Support */
104 MU_APP_INIT_NLS (); 63 MU_APP_INIT_NLS ();
...@@ -106,20 +65,18 @@ main (int argc, char **argv) ...@@ -106,20 +65,18 @@ main (int argc, char **argv)
106 /* register the formats. */ 65 /* register the formats. */
107 mu_register_all_mbox_formats (); 66 mu_register_all_mbox_formats ();
108 67
109 #ifdef WITH_TLS 68 mu_cli_capa_register (&mu_cli_capa_tls);
110 mu_gocs_register ("tls", mu_tls_module_init); 69 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
111 #endif
112 mu_argp_init (NULL, NULL);
113 if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, NULL, &args))
114 exit (1);
115 70
116 if (args.argc < 1 && messages_count (NULL) < 0) 71 if (argc == 0 && messages_count (NULL) < 0)
117 err = 1; 72 err = 1;
118 else if (args.argc >= 1) 73 else if (argc >= 1)
119 { 74 {
120 for (i = 0; i < args.argc; i++) 75 size_t i;
76
77 for (i = 0; i < argc; i++)
121 { 78 {
122 if (messages_count (args.argv[i]) < 0) 79 if (messages_count (argv[i]) < 0)
123 err = 1; 80 err = 1;
124 } 81 }
125 } 82 }
......
...@@ -47,7 +47,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h ...@@ -47,7 +47,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h
47 BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h 47 BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h
48 48
49 mimeview_LDADD = \ 49 mimeview_LDADD = \
50 ${MU_APP_LIBRARIES}\ 50 ${MU_APP_NEW_LIBRARIES}\
51 ${MU_LIB_MAILUTILS}\ 51 ${MU_LIB_MAILUTILS}\
52 @LTLIBINTL@ 52 @LTLIBINTL@
53 53
......
...@@ -26,38 +26,11 @@ ...@@ -26,38 +26,11 @@
26 #include <unistd.h> 26 #include <unistd.h>
27 #include <fcntl.h> 27 #include <fcntl.h>
28 28
29 #include "mailutils/libargp.h" 29 #include "mailutils/cli.h"
30 #include "mailutils/argcv.h" 30 #include "mailutils/argcv.h"
31 31
32 #include "mailcap.h" 32 #include "mailcap.h"
33 33
34 static char doc[] = N_("GNU mimeview -- display files, using mailcap mechanism.")
35 "\v"
36 N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
37 N_("\n\nDebug flags are:\n\
38 g - Mime.types parser traces\n\
39 l - Mime.types lexical analyzer traces\n\
40 0-9 - Set debugging level\n");
41
42 #define OPT_METAMAIL 256
43
44 static struct argp_option options[] = {
45 {"no-ask", 'a', N_("TYPE-LIST"), OPTION_ARG_OPTIONAL,
46 N_("do not ask for confirmation before displaying files, or, if TYPE-LIST is given, do not ask for confirmation before displaying such files whose MIME type matches one of the patterns from TYPE-LIST"), 0},
47 {"no-interactive", 'h', NULL, 0,
48 N_("disable interactive mode"), 0 },
49 {"print", 0, NULL, OPTION_ALIAS, NULL, 0 },
50 {"debug", 'd', N_("FLAGS"), OPTION_ARG_OPTIONAL,
51 N_("enable debugging output"), 0},
52 {"mimetypes", 't', N_("FILE"), 0,
53 N_("use this mime.types file"), 0},
54 {"dry-run", 'n', NULL, 0,
55 N_("do nothing, just print what would have been done"), 0},
56 {"metamail", OPT_METAMAIL, N_("FILE"), OPTION_ARG_OPTIONAL,
57 N_("use metamail to display files"), 0},
58 {0, 0, 0, 0}
59 };
60
61 int debug_level; /* Debugging level set by --debug option */ 34 int debug_level; /* Debugging level set by --debug option */
62 static int dry_run; /* Dry run mode */ 35 static int dry_run; /* Dry run mode */
63 static char *metamail; /* Name of metamail program, if requested */ 36 static char *metamail; /* Name of metamail program, if requested */
...@@ -88,68 +61,62 @@ set_debug_flags (const char *arg) ...@@ -88,68 +61,62 @@ set_debug_flags (const char *arg)
88 } 61 }
89 } 62 }
90 } 63 }
91 64
92 static error_t 65 static void
93 parse_opt (int key, char *arg, struct argp_state *state) 66 cli_no_ask (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
94 { 67 {
95 static mu_list_t lst; 68 no_ask_types = mu_strdup (arg ? arg : "*");
96 69 setenv ("MM_NOASK", arg, 1); /* In case we are given --metamail option */
97 switch (key) 70 }
98 {
99 case ARGP_KEY_INIT:
100 mimetypes_lex_debug (0);
101 mimetypes_gram_debug (0);
102 if (interactive == -1)
103 interactive = isatty (fileno (stdin));
104 mu_argp_node_list_init (&lst);
105 break;
106
107 case ARGP_KEY_FINI:
108 if (dry_run && !debug_level)
109 debug_level = 1;
110 mu_argp_node_list_finish (lst, NULL, NULL);
111 break;
112 71
113 case 'a': 72 static void
114 no_ask_types = arg ? arg : "*"; 73 cli_no_interactive (struct mu_parseopt *po, struct mu_option *opt,
115 setenv ("MM_NOASK", arg, 1); /* In case we are given --metamail option */ 74 char const *arg)
116 break; 75 {
117 76 interactive = 0;
118 case 'd': 77 }
119 mu_argp_node_list_new (lst, "debug", arg ? arg : "9");
120 break;
121 78
122 case 'h': 79 static void
123 interactive = 0; 80 cli_debug (struct mu_parseopt *po, struct mu_option *opt,
124 break; 81 char const *arg)
125 82 {
126 case 'n': 83 set_debug_flags (arg);
127 dry_run = 1; 84 }
128 break;
129
130 case 't':
131 mu_argp_node_list_new (lst, "mimetypes", arg);
132 break;
133 85
134 case OPT_METAMAIL: 86 static void
135 mu_argp_node_list_new (lst, "metamail", arg ? arg : "metamail"); 87 cli_metamail (struct mu_parseopt *po, struct mu_option *opt,
136 break; 88 char const *arg)
137 89 {
138 default: 90 if (!arg)
139 return ARGP_ERR_UNKNOWN; 91 arg = "metamail";
140 } 92 metamail = mu_strdup (arg);
141 return 0;
142 } 93 }
143 94
144 static struct argp argp = { 95 static struct mu_option mimeview_options[] = {
145 options, 96 { "no-ask", 'a', N_("TYPE-LIST"), MU_OPTION_ARG_OPTIONAL,
146 parse_opt, 97 N_("do not ask for confirmation before displaying files, or, if TYPE-LIST is given, do not ask for confirmation before displaying such files whose MIME type matches one of the patterns from TYPE-LIST"),
147 N_("FILE [FILE ...]"), 98 mu_c_string, NULL, cli_no_ask },
148 doc, 99 { "no-interactive", 'h', NULL, MU_OPTION_DEFAULT,
149 NULL, 100 N_("disable interactive mode"),
150 NULL, NULL 101 mu_c_string, NULL, cli_no_interactive },
151 }; 102 { "print", 0, NULL, MU_OPTION_ALIAS },
103 { "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL,
104 N_("enable debugging output"),
105 mu_c_string, NULL, cli_debug },
106 { "mimetypes", 't', N_("FILE"), MU_OPTION_DEFAULT,
107 N_("use this mime.types file"),
108 mu_c_string, &mimetypes_config },
109
110 { "dry-run", 'n', NULL, MU_OPTION_DEFAULT,
111 N_("do nothing, just print what would have been done"),
112 mu_c_bool, &dry_run },
113
114 { "metamail", 0, N_("FILE"), MU_OPTION_ARG_OPTIONAL,
115 N_("use metamail to display files"),
116 mu_c_string, NULL, cli_metamail },
152 117
118 MU_OPTION_END
119 }, *options[] = { mimeview_options, NULL };
153 120
154 static int 121 static int
155 cb_debug (void *data, mu_config_value_t *val) 122 cb_debug (void *data, mu_config_value_t *val)
...@@ -172,12 +139,23 @@ struct mu_cfg_param mimeview_cfg_param[] = { ...@@ -172,12 +139,23 @@ struct mu_cfg_param mimeview_cfg_param[] = {
172 N_("prog") }, 139 N_("prog") },
173 { NULL } 140 { NULL }
174 }; 141 };
175
176 142
177 143 struct mu_cli_setup cli = {
178 static const char *capa[] = { 144 options,
179 "mailutils", 145 mimeview_cfg_param,
180 "common", 146 N_("GNU mimeview -- display files, using mailcap mechanism."),
147 //FIXME:
148 /*
149 N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
150 N_("\n\nDebug flags are:\n\
151 g - Mime.types parser traces\n\
152 l - Mime.types lexical analyzer traces\n\
153 0-9 - Set debugging level\n");
154 */
155 N_("FILE [FILE ...]")
156 };
157
158 static char *capa[] = {
181 "debug", 159 "debug",
182 NULL 160 NULL
183 }; 161 };
...@@ -267,16 +245,15 @@ display_file (const char *type) ...@@ -267,16 +245,15 @@ display_file (const char *type)
267 int 245 int
268 main (int argc, char **argv) 246 main (int argc, char **argv)
269 { 247 {
270 int index;
271
272 MU_APP_INIT_NLS (); 248 MU_APP_INIT_NLS ();
273 mu_argp_init (NULL, NULL);
274 if (mu_app_init (&argp, capa, mimeview_cfg_param,
275 argc, argv, 0, &index, NULL))
276 exit (1);
277 249
278 argc -= index; 250 mimetypes_lex_debug (0);
279 argv += index; 251 mimetypes_gram_debug (0);
252 interactive = isatty (fileno (stdin));
253
254 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
255 if (dry_run && !debug_level)
256 debug_level = 1;
280 257
281 if (argc == 0) 258 if (argc == 0)
282 { 259 {
......
...@@ -19,7 +19,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@ ...@@ -19,7 +19,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@
19 bin_PROGRAMS = movemail 19 bin_PROGRAMS = movemail
20 20
21 movemail_LDADD = \ 21 movemail_LDADD = \
22 ${MU_APP_LIBRARIES}\ 22 ${MU_APP_NEW_LIBRARIES}\
23 ${MU_LIB_MBOX}\ 23 ${MU_LIB_MBOX}\
24 ${MU_LIB_IMAP}\ 24 ${MU_LIB_IMAP}\
25 ${MU_LIB_POP}\ 25 ${MU_LIB_POP}\
......
...@@ -27,46 +27,9 @@ ...@@ -27,46 +27,9 @@
27 #include <unistd.h> 27 #include <unistd.h>
28 #include <mailutils/mailutils.h> 28 #include <mailutils/mailutils.h>
29 #include <mailutils/tls.h> 29 #include <mailutils/tls.h>
30 #include "mailutils/libargp.h" 30 #include "mailutils/cli.h"
31 #include <muaux.h> 31 #include <muaux.h>
32 32
33 static char doc[] = N_("GNU movemail -- move messages across mailboxes.");
34 static char args_doc[] = N_("inbox-url destfile [POP-password]");
35
36 enum {
37 EMACS_OPTION=256,
38 IGNORE_ERRORS_OPTION,
39 PROGRAM_ID_OPTION,
40 MAX_MESSAGES_OPTION,
41 ONERROR_OPTION,
42 NOTIFY_OPTION
43 };
44
45 static struct argp_option options[] = {
46 { "preserve", 'p', NULL, 0, N_("preserve the source mailbox") },
47 { "keep-messages", 0, NULL, OPTION_ALIAS, NULL },
48 { "reverse", 'r', NULL, 0, N_("reverse the sorting order") },
49 { "emacs", EMACS_OPTION, NULL, 0,
50 N_("output information used by Emacs rmail interface") },
51 { "uidl", 'u', NULL, 0,
52 N_("use UIDLs to avoid downloading the same message twice") },
53 { "verbose", 'v', NULL, 0,
54 N_("increase verbosity level") },
55 { "owner", 'P', N_("MODELIST"), 0,
56 N_("control mailbox ownership") },
57 { "ignore-errors", IGNORE_ERRORS_OPTION, NULL, 0,
58 N_("try to continue after errors") },
59 { "onerror", ONERROR_OPTION, N_("KW[,KW...]"), 0,
60 N_("what to do on errors") },
61 { "program-id", PROGRAM_ID_OPTION, N_("FMT"), 0,
62 N_("set program identifier for diagnostics (default: program name)") },
63 { "max-messages", MAX_MESSAGES_OPTION, N_("NUMBER"), 0,
64 N_("process at most NUMBER messages") },
65 { "notify", NOTIFY_OPTION, NULL, 0,
66 N_("enable biff notification") },
67 { NULL, 0, NULL, 0, NULL, 0 }
68 };
69
70 static int reverse_order; 33 static int reverse_order;
71 static int preserve_mail; 34 static int preserve_mail;
72 static int emacs_mode; 35 static int emacs_mode;
...@@ -135,84 +98,9 @@ mu_kwd_t method_kwd[] = { ...@@ -135,84 +98,9 @@ mu_kwd_t method_kwd[] = {
135 { "set-id", set_owner_id }, 98 { "set-id", set_owner_id },
136 { NULL } 99 { NULL }
137 }; 100 };
138
139 static error_t
140 parse_opt (int key, char *arg, struct argp_state *state)
141 {
142 static mu_list_t lst;
143
144 switch (key)
145 {
146 case 'r':
147 mu_argp_node_list_new (lst, "reverse", "yes");
148 break;
149
150 case 'p':
151 mu_argp_node_list_new (lst, "preserve", "yes");
152 break;
153
154 case 'P':
155 mu_argp_node_list_new (lst, "mailbox-ownership", arg);
156 break;
157
158 case 'u':
159 mu_argp_node_list_new (lst, "uidl", "yes");
160 break;
161
162 case 'v':
163 verbose_option++;
164 break;
165
166 case EMACS_OPTION:
167 mu_argp_node_list_new (lst, "emacs", "yes");
168 break;
169
170 case IGNORE_ERRORS_OPTION:
171 mu_argp_node_list_new (lst, "ignore-errors", "yes");
172 break;
173
174 case NOTIFY_OPTION:
175 notify = 1;
176 break;
177
178 case ONERROR_OPTION:
179 mu_argp_node_list_new (lst, "onerror", arg);
180 break;
181
182 case MAX_MESSAGES_OPTION:
183 mu_argp_node_list_new (lst, "max-messages", arg);
184 break;
185
186 case PROGRAM_ID_OPTION:
187 mu_argp_node_list_new (lst, "program-id", arg);
188 break;
189
190 case ARGP_KEY_INIT:
191 mu_argp_node_list_init (&lst);
192 break;
193
194 case ARGP_KEY_FINI:
195 mu_argp_node_list_finish (lst, NULL, NULL);
196 break;
197
198 default:
199 return ARGP_ERR_UNKNOWN;
200 }
201 return 0;
202 }
203
204 static struct argp argp = {
205 options,
206 parse_opt,
207 args_doc,
208 doc,
209 NULL,
210 NULL, NULL
211 };
212
213 101
214 static int 102 static int
215 _cb_mailbox_ownership (const char *str) 103 set_mailbox_ownership (const char *str)
216 { 104 {
217 if (strcmp (str, "clear") == 0) 105 if (strcmp (str, "clear") == 0)
218 so_method_num = 0; 106 so_method_num = 0;
...@@ -280,50 +168,33 @@ _cb_mailbox_ownership (const char *str) ...@@ -280,50 +168,33 @@ _cb_mailbox_ownership (const char *str)
280 } 168 }
281 169
282 static int 170 static int
283 cb_mailbox_ownership (void *data, mu_config_value_t *val) 171 set_mailbox_ownership_list (char const *str)
284 { 172 {
285 int i; 173 if (!strchr (str, ','))
286 174 return set_mailbox_ownership (str);
287 if (val->type == MU_CFG_STRING) 175 else
288 { 176 {
289 const char *str = val->v.string; 177 struct mu_wordsplit ws;
290 if (!strchr (str, ',')) 178 size_t i;
291 return _cb_mailbox_ownership (str); 179
292 else 180 ws.ws_delim = ",";
181 if (mu_wordsplit (str, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM))
293 { 182 {
294 struct mu_wordsplit ws; 183 mu_error (_("cannot parse %s: %s"),
295 184 str, mu_wordsplit_strerror (&ws));
296 ws.ws_delim = ","; 185 return 1;
297 if (mu_wordsplit (str, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM))
298 {
299 mu_error (_("cannot parse %s: %s"),
300 str, mu_wordsplit_strerror (&ws));
301 return 1;
302 }
303
304 for (i = 0; i < ws.ws_wordc; i++)
305 if (_cb_mailbox_ownership (ws.ws_wordv[i]))
306 return 1;
307 mu_wordsplit_free (&ws);
308 return 0;
309 } 186 }
310 }
311
312 if (mu_cfg_assert_value_type (val, MU_CFG_LIST))
313 return 1;
314 187
315 for (i = 0; i < val->v.arg.c; i++) 188 for (i = 0; i < ws.ws_wordc; i++)
316 { 189 if (set_mailbox_ownership (ws.ws_wordv[i]))
317 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING)) 190 return 1;
318 return 1; 191 mu_wordsplit_free (&ws);
319 if (_cb_mailbox_ownership (val->v.arg.v[i].v.string)) 192 return 0;
320 return 1;
321 } 193 }
322 return 0;
323 } 194 }
324 195
325 static int 196 static int
326 cb_onerror (void *data, mu_config_value_t *val) 197 set_onerror_action (char const *str)
327 { 198 {
328 struct mu_wordsplit ws; 199 struct mu_wordsplit ws;
329 static struct mu_kwd onerror_kw[] = { 200 static struct mu_kwd onerror_kw[] = {
...@@ -334,15 +205,13 @@ cb_onerror (void *data, mu_config_value_t *val) ...@@ -334,15 +205,13 @@ cb_onerror (void *data, mu_config_value_t *val)
334 }; 205 };
335 int i, flag; 206 int i, flag;
336 207
337 if (mu_cfg_assert_value_type (val, MU_CFG_STRING)) 208 if (strcmp (str, "abort") == 0)
338 return 1;
339 if (strcmp (val->v.string, "abort") == 0)
340 { 209 {
341 onerror_flags = 0; 210 onerror_flags = 0;
342 return 0; 211 return 0;
343 } 212 }
344 ws.ws_delim = ","; 213 ws.ws_delim = ",";
345 if (mu_wordsplit (val->v.string, &ws, 214 if (mu_wordsplit (str, &ws,
346 MU_WRDSF_NOVAR | MU_WRDSF_NOCMD | 215 MU_WRDSF_NOVAR | MU_WRDSF_NOCMD |
347 MU_WRDSF_DELIM | MU_WRDSF_WS)) 216 MU_WRDSF_DELIM | MU_WRDSF_WS))
348 { 217 {
...@@ -369,6 +238,99 @@ cb_onerror (void *data, mu_config_value_t *val) ...@@ -369,6 +238,99 @@ cb_onerror (void *data, mu_config_value_t *val)
369 mu_wordsplit_free (&ws); 238 mu_wordsplit_free (&ws);
370 return 0; 239 return 0;
371 } 240 }
241
242 static void
243 cli_mailbox_ownership (struct mu_parseopt *po, struct mu_option *opt,
244 char const *arg)
245 {
246 if (set_mailbox_ownership_list (arg))
247 exit (po->po_exit_error);
248 }
249
250 static void
251 cli_onerror (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
252 {
253 if (set_onerror_action (arg))
254 exit (po->po_exit_error);
255 }
256
257 static struct mu_option movemail_options[] = {
258 { "preserve", 'p', NULL, MU_OPTION_DEFAULT,
259 N_("preserve the source mailbox"),
260 mu_c_bool, &preserve_mail },
261 { "keep-messages", 0, NULL, MU_OPTION_ALIAS },
262
263 { "reverse", 'r', NULL, MU_OPTION_DEFAULT,
264 N_("reverse the sorting order"),
265 mu_c_bool, &reverse_order },
266
267 { "emacs", 0, NULL, MU_OPTION_DEFAULT,
268 N_("output information used by Emacs rmail interface"),
269 mu_c_bool, &emacs_mode },
270
271 { "uidl", 'u', NULL, MU_OPTION_DEFAULT,
272 N_("use UIDLs to avoid downloading the same message twice"),
273 mu_c_bool, &uidl_option },
274
275 { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
276 N_("increase verbosity level"),
277 mu_c_incr, &verbose_option },
278
279 { "owner", 'P', N_("MODELIST"), MU_OPTION_DEFAULT,
280 N_("control mailbox ownership"),
281 mu_c_string, cli_mailbox_ownership },
282
283 { "ignore-errors", 0, NULL, MU_OPTION_DEFAULT,
284 N_("try to continue after errors"),
285 mu_c_bool, &ignore_errors },
286
287 { "onerror", 0, N_("KW[,KW...]"), MU_OPTION_DEFAULT,
288 N_("what to do on errors"),
289 mu_c_string, NULL, cli_onerror },
290
291 { "program-id", 0, N_("FMT"), MU_OPTION_DEFAULT,
292 N_("set program identifier for diagnostics (default: program name)"),
293 mu_c_string, &program_id_option },
294
295 { "max-messages", 0, N_("NUMBER"), MU_OPTION_DEFAULT,
296 N_("process at most NUMBER messages"),
297 mu_c_size, &max_messages_option },
298
299 { "notify", 0, NULL, MU_OPTION_DEFAULT,
300 N_("enable biff notification"),
301 mu_c_bool, &notify },
302
303 MU_OPTION_END
304 }, *options[] = { movemail_options, NULL };
305
306 static int
307 cb_mailbox_ownership (void *data, mu_config_value_t *val)
308 {
309 int i;
310
311 if (val->type == MU_CFG_STRING)
312 set_mailbox_ownership_list (val->v.string);
313
314 if (mu_cfg_assert_value_type (val, MU_CFG_LIST))
315 return 1;
316
317 for (i = 0; i < val->v.arg.c; i++)
318 {
319 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
320 return 1;
321 if (set_mailbox_ownership (val->v.arg.v[i].v.string))
322 return 1;
323 }
324 return 0;
325 }
326
327 static int
328 cb_onerror (void *data, mu_config_value_t *val)
329 {
330 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
331 return 1;
332 return set_onerror_action (val->v.string);
333 }
372 334
373 struct mu_cfg_param movemail_cfg_param[] = { 335 struct mu_cfg_param movemail_cfg_param[] = {
374 { "preserve", mu_c_bool, &preserve_mail, 0, NULL, 336 { "preserve", mu_c_bool, &preserve_mail, 0, NULL,
...@@ -406,15 +368,20 @@ struct mu_cfg_param movemail_cfg_param[] = { ...@@ -406,15 +368,20 @@ struct mu_cfg_param movemail_cfg_param[] = {
406 "Setting onerror=abort reverts to the default behavior.") }, 368 "Setting onerror=abort reverts to the default behavior.") },
407 { NULL } 369 { NULL }
408 }; 370 };
409
410 371
411 static const char *movemail_capa[] = { 372 struct mu_cli_setup cli = {
412 "mailutils", 373 options,
413 "common", 374 movemail_cfg_param,
375 N_("GNU movemail -- move messages across mailboxes."),
376 N_("inbox-url destfile [POP-password]")
377 };
378
379 static char *movemail_capa[] = {
414 "debug", 380 "debug",
415 "locking", 381 "locking",
416 "mailbox", 382 "mailbox",
417 "auth", 383 "auth",
384 "tls",
418 NULL 385 NULL
419 }; 386 };
420 387
...@@ -863,7 +830,6 @@ set_program_id (const char *source_name, const char *dest_name) ...@@ -863,7 +830,6 @@ set_program_id (const char *source_name, const char *dest_name)
863 int 830 int
864 main (int argc, char **argv) 831 main (int argc, char **argv)
865 { 832 {
866 int index;
867 size_t total; 833 size_t total;
868 int rc = 0; 834 int rc = 0;
869 char *source_name, *dest_name; 835 char *source_name, *dest_name;
...@@ -880,16 +846,8 @@ main (int argc, char **argv) ...@@ -880,16 +846,8 @@ main (int argc, char **argv)
880 846
881 /* argument parsing */ 847 /* argument parsing */
882 848
883 #ifdef WITH_TLS 849 mu_cli_capa_register (&mu_cli_capa_tls);
884 mu_gocs_register ("tls", mu_tls_module_init); 850 mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv);
885 #endif
886 mu_argp_init (NULL, NULL);
887 if (mu_app_init (&argp, movemail_capa, movemail_cfg_param,
888 argc, argv, 0, &index, NULL))
889 exit (1);
890
891 argc -= index;
892 argv += index;
893 851
894 if (argc < 2 || argc > 3) 852 if (argc < 2 || argc > 3)
895 { 853 {
......
...@@ -23,7 +23,7 @@ bin_PROGRAMS = readmsg ...@@ -23,7 +23,7 @@ bin_PROGRAMS = readmsg
23 readmsg_SOURCES = readmsg.c msglist.c readmsg.h 23 readmsg_SOURCES = readmsg.c msglist.c readmsg.h
24 24
25 readmsg_LDADD =\ 25 readmsg_LDADD =\
26 ${MU_APP_LIBRARIES}\ 26 ${MU_APP_NEW_LIBRARIES}\
27 ${MU_LIB_MBOX}\ 27 ${MU_LIB_MBOX}\
28 ${MU_LIB_IMAP}\ 28 ${MU_LIB_IMAP}\
29 ${MU_LIB_POP}\ 29 ${MU_LIB_POP}\
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
20 #endif 20 #endif
21 21
22 #include "readmsg.h" 22 #include "readmsg.h"
23 #include "mailutils/libargp.h" 23 #include "mailutils/cli.h"
24 #include "mu_umaxtostr.h" 24 #include "mu_umaxtostr.h"
25 25
26 #define WEEDLIST_SEPARATOR " :," 26 #define WEEDLIST_SEPARATOR " :,"
...@@ -30,41 +30,6 @@ static void print_header (mu_message_t, int, int, char **); ...@@ -30,41 +30,6 @@ static void print_header (mu_message_t, int, int, char **);
30 static void print_body (mu_message_t); 30 static void print_body (mu_message_t);
31 static int string_starts_with (const char * s1, const char *s2); 31 static int string_starts_with (const char * s1, const char *s2);
32 32
33 static char doc[] = N_("GNU readmsg -- print messages.");
34 static error_t readmsg_parse_opt (int key, char *arg, struct argp_state *astate);
35
36 static struct argp_option options[] =
37 {
38 { "debug", 'd', 0, 0, N_("display debugging information"), 1 },
39 { "header", 'h', 0, 0, N_("display entire header"), 1 },
40 { "weedlist", 'w', N_("LIST"), 0,
41 N_("list of header names separated by whitespace or commas"), 1 },
42 { "folder", 'f', N_("FOLDER"), 0, N_("folder to use"), 1 },
43 { "no-header", 'n', 0, 0, N_("exclude all headers"), 1 },
44 { "form-feeds", 'p', 0, 0, N_("output formfeeds between messages"), 1 },
45 { "show-all-match", 'a', NULL, 0,
46 N_("print all messages matching pattern, not only the first"), 1 },
47 {0, 0, 0, 0}
48 };
49
50 static struct argp argp = {
51 options,
52 readmsg_parse_opt,
53 NULL,
54 doc,
55 NULL,
56 NULL, NULL
57 };
58
59 static const char *readmsg_argp_capa[] = {
60 "mailutils",
61 "common",
62 "debug",
63 "mailbox",
64 "locking",
65 NULL
66 };
67
68 int dbug = 0; 33 int dbug = 0;
69 const char *mailbox_name = NULL; 34 const char *mailbox_name = NULL;
70 const char *weedlist = NULL; 35 const char *weedlist = NULL;
...@@ -73,57 +38,30 @@ int all_header = 0; ...@@ -73,57 +38,30 @@ int all_header = 0;
73 int form_feed = 0; 38 int form_feed = 0;
74 int show_all = 0; 39 int show_all = 0;
75 40
76 static error_t 41 static struct mu_option readmsg_options[] =
77 readmsg_parse_opt (int key, char *arg, struct argp_state *astate)
78 { 42 {
79 static mu_list_t lst; 43 { "debug", 'd', NULL, MU_OPTION_DEFAULT,
80 44 N_("display debugging information"),
81 switch (key) 45 mu_c_incr, &dbug },
82 { 46 { "header", 'h', NULL, MU_OPTION_DEFAULT,
83 case 'd': 47 N_("display entire headers"),
84 dbug++; 48 mu_c_bool, &all_header },
85 break; 49 { "weedlist", 'w', N_("LIST"), MU_OPTION_DEFAULT,
86 50 N_("list of header names separated by whitespace or commas"),
87 case 'h': 51 mu_c_string, &weedlist },
88 mu_argp_node_list_new (lst, "header", "yes"); 52 { "folder", 'f', N_("FOLDER"), MU_OPTION_DEFAULT,
89 break; 53 N_("folder to use"), mu_c_string, &mailbox_name },
90 54 { "no-header", 'n', NULL, MU_OPTION_DEFAULT,
91 case 'f': 55 N_("exclude all headers"),
92 mu_argp_node_list_new (lst, "folder", arg); 56 mu_c_bool, &no_header },
93 break; 57 { "form-feeds", 'p', NULL, MU_OPTION_DEFAULT,
94 58 N_("output formfeeds between messages"),
95 case 'w': 59 mu_c_bool, &form_feed },
96 mu_argp_node_list_new (lst, "weedlist", arg); 60 { "show-all-match", 'a', NULL, MU_OPTION_DEFAULT,
97 break; 61 N_("print all messages matching pattern, not only the first"),
98 62 mu_c_bool, &show_all },
99 case 'n': 63 MU_OPTION_END
100 mu_argp_node_list_new (lst, "no-header", "yes"); 64 }, *options[] = { readmsg_options, NULL };
101 break;
102
103 case 'p':
104 mu_argp_node_list_new (lst, "form-feeds", "yes");
105 break;
106
107 case 'a':
108 mu_argp_node_list_new (lst, "show-all-match", "yes");
109 break;
110
111 case ARGP_KEY_INIT:
112 mu_argp_node_list_init (&lst);
113 break;
114
115 case ARGP_KEY_FINI:
116 if (dbug)
117 mu_argp_node_list_new (lst, "debug", mu_umaxtostr (0, dbug));
118 mu_argp_node_list_finish (lst, NULL, NULL);
119 break;
120
121 default:
122 return ARGP_ERR_UNKNOWN;
123 }
124 return 0;
125 }
126
127 65
128 struct mu_cfg_param readmsg_cfg_param[] = { 66 struct mu_cfg_param readmsg_cfg_param[] = {
129 { "debug", mu_c_int, &dbug, 0, NULL, 67 { "debug", mu_c_int, &dbug, 0, NULL,
...@@ -145,6 +83,21 @@ struct mu_cfg_param readmsg_cfg_param[] = { ...@@ -145,6 +83,21 @@ struct mu_cfg_param readmsg_cfg_param[] = {
145 { NULL } 83 { NULL }
146 }; 84 };
147 85
86 struct mu_cli_setup cli = {
87 options,
88 readmsg_cfg_param,
89 N_("GNU readmsg -- print messages."),
90 NULL
91 };
92
93 static char *readmsg_argp_capa[] = {
94 "debug",
95 "mailbox",
96 "locking",
97 "tls",
98 NULL
99 };
100
148 static int 101 static int
149 string_starts_with (const char * s1, const char *s2) 102 string_starts_with (const char * s1, const char *s2)
150 { 103 {
...@@ -158,7 +111,7 @@ string_starts_with (const char * s1, const char *s2) ...@@ -158,7 +111,7 @@ string_starts_with (const char * s1, const char *s2)
158 111
159 while (*p1 && *p2) 112 while (*p1 && *p2)
160 { 113 {
161 if ((n = toupper (*p1++) - toupper (*p2++)) != 0) 114 if ((n = mu_toupper (*p1++) - mu_toupper (*p2++)) != 0)
162 break; 115 break;
163 } 116 }
164 return (n == 0); 117 return (n == 0);
...@@ -276,7 +229,6 @@ main (int argc, char **argv) ...@@ -276,7 +229,6 @@ main (int argc, char **argv)
276 int *set = NULL; 229 int *set = NULL;
277 int n = 0; 230 int n = 0;
278 int i; 231 int i;
279 int index;
280 mu_mailbox_t mbox = NULL; 232 mu_mailbox_t mbox = NULL;
281 struct mu_wordsplit ws; 233 struct mu_wordsplit ws;
282 char **weedv; 234 char **weedv;
...@@ -290,15 +242,9 @@ main (int argc, char **argv) ...@@ -290,15 +242,9 @@ main (int argc, char **argv)
290 mu_register_all_mbox_formats (); 242 mu_register_all_mbox_formats ();
291 mu_register_extra_formats (); 243 mu_register_extra_formats ();
292 244
293 #ifdef WITH_TLS 245 mu_cli_capa_register (&mu_cli_capa_tls);
294 mu_gocs_register ("tls", mu_tls_module_init);
295 #endif
296 mu_argp_init (NULL, NULL);
297 if (mu_app_init (&argp, readmsg_argp_capa, readmsg_cfg_param,
298 argc, argv, 0, &index, NULL))
299 exit (1);
300 246
301 argc -= index; 247 mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
302 248
303 if (argc == 0) 249 if (argc == 0)
304 { 250 {
...@@ -376,7 +322,7 @@ main (int argc, char **argv) ...@@ -376,7 +322,7 @@ main (int argc, char **argv)
376 } 322 }
377 323
378 /* Build an array containing the message number. */ 324 /* Build an array containing the message number. */
379 msglist (mbox, show_all, argc, &argv[index], &set, &n); 325 msglist (mbox, show_all, argc, argv, &set, &n);
380 326
381 for (i = 0; i < n; ++i) 327 for (i = 0; i < n; ++i)
382 { 328 {
......
...@@ -22,7 +22,7 @@ EXTRA_DIST = examples ...@@ -22,7 +22,7 @@ EXTRA_DIST = examples
22 bin_PROGRAMS = sieve 22 bin_PROGRAMS = sieve
23 sieve_SOURCES = sieve.c 23 sieve_SOURCES = sieve.c
24 sieve_LDADD =\ 24 sieve_LDADD =\
25 ${MU_APP_LIBRARIES}\ 25 ${MU_APP_NEW_LIBRARIES}\
26 ${MU_LIB_SIEVE}\ 26 ${MU_LIB_SIEVE}\
27 ${MU_LIB_MBOX}\ 27 ${MU_LIB_MBOX}\
28 ${MU_LIB_IMAP}\ 28 ${MU_LIB_IMAP}\
......
...@@ -43,64 +43,10 @@ ...@@ -43,64 +43,10 @@
43 #include <mailutils/stream.h> 43 #include <mailutils/stream.h>
44 #include <mailutils/nls.h> 44 #include <mailutils/nls.h>
45 #include <mailutils/tls.h> 45 #include <mailutils/tls.h>
46 46 #include <mailutils/cli.h>
47 #include "mailutils/libargp.h"
48
49 static char doc[] =
50 N_("GNU sieve -- a mail filtering tool.")
51 "\v"
52 N_("Debug flags:\n\
53 g - main parser traces\n\
54 T - mailutils traces (same as --debug-level=sieve.trace0-trace1)\n\
55 P - network protocols (same as --debug-level=sieve.=prot)\n\
56 t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
57 i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n");
58 47
59 #define D_DEFAULT "TPt" 48 #define D_DEFAULT "TPt"
60 49
61 #define ARG_LINE_INFO 257
62 #define ARG_NO_PROGRAM_NAME 258
63
64 static struct argp_option options[] =
65 {
66 {"no-actions", 'n', 0, 0,
67 N_("do not execute any actions, just print what would be done"), 0},
68 {"dry-run", 0, NULL, OPTION_ALIAS, NULL },
69 {"keep-going", 'k', 0, 0,
70 N_("keep on going if execution fails on a message"), 0},
71
72 {"compile-only", 'c', 0, 0,
73 N_("compile script and exit"), 0},
74
75 {"dump", 'D', 0, 0,
76 N_("compile script, dump disassembled sieve code to terminal and exit"), 0 },
77
78 {"mbox-url", 'f', N_("MBOX"), 0,
79 N_("mailbox to sieve (defaults to user's mail spool)"), 0},
80
81 {"ticket", 't', N_("TICKET"), 0,
82 N_("ticket file for user authentication"), 0},
83
84 {"debug", 'd', N_("FLAGS"), OPTION_ARG_OPTIONAL,
85 N_("debug flags (defaults to \"" D_DEFAULT "\")"), 0},
86
87 {"verbose", 'v', NULL, 0,
88 N_("log all actions"), 0},
89
90 {"line-info", ARG_LINE_INFO, N_("BOOL"), OPTION_ARG_OPTIONAL,
91 N_("print source location along with action logs (default)") },
92
93 {"email", 'e', N_("ADDRESS"), 0,
94 N_("override user email address"), 0},
95 {"expression", 'E', NULL, 0,
96 N_("treat SCRIPT as Sieve program text"), 0},
97
98 {"no-program-name", ARG_NO_PROGRAM_NAME, NULL, 0,
99 N_("do not prefix diagnostic messages with the program name"), 0},
100
101 {0}
102 };
103
104 int keep_going; 50 int keep_going;
105 int compile_only; 51 int compile_only;
106 char *mbox_url; 52 char *mbox_url;
...@@ -112,17 +58,6 @@ int expression_option; ...@@ -112,17 +58,6 @@ int expression_option;
112 static int sieve_print_locus = 1; /* Should the log messages include the 58 static int sieve_print_locus = 1; /* Should the log messages include the
113 locus */ 59 locus */
114 60
115 static int
116 is_true_p (char *p)
117 {
118 int rc;
119 if (!p)
120 return 1;
121 if ((rc = mu_true_answer_p (p)) == -1)
122 return 0;
123 return rc;
124 }
125
126 static void 61 static void
127 set_debug_level (const char *arg) 62 set_debug_level (const char *arg)
128 { 63 {
...@@ -164,98 +99,88 @@ set_debug_level (const char *arg) ...@@ -164,98 +99,88 @@ set_debug_level (const char *arg)
164 } 99 }
165 } 100 }
166 101
167 int 102 static void
168 mu_compat_printer (void *data, mu_log_level_t level, const char *buf) 103 cli_dry_run (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
169 { 104 {
170 fputs (buf, stderr); 105 sieve_debug |= MU_SIEVE_DRY_RUN;
171 return 0; 106 verbose = 1;
172 } 107 }
173 108
174 static error_t 109 static void
175 parser (int key, char *arg, struct argp_state *state) 110 cli_compile_and_dump (struct mu_parseopt *po, struct mu_option *opt,
111 char const *arg)
176 { 112 {
177 static mu_list_t lst; 113 compile_only = 2;
178 114 }
179 switch (key)
180 {
181 case 'E':
182 expression_option = 1;
183 break;
184
185 case 'e':
186 mu_argp_node_list_new (lst, "email", arg);
187 break;
188
189 case 'n':
190 sieve_debug |= MU_SIEVE_DRY_RUN;
191 mu_argp_node_list_new (lst, "verbose", "yes");
192 break;
193
194 case 'k':
195 mu_argp_node_list_new (lst, "keep-going", "yes");
196 break;
197
198 case 'c':
199 compile_only = 1;
200 break;
201
202 case 'D':
203 compile_only = 2;
204 break;
205
206 case 'f':
207 mu_argp_node_list_new (lst, "mbox-url", arg);
208 break;
209
210 case 't':
211 mu_argp_node_list_new (lst, "ticket", arg);
212 break;
213
214 case 'd':
215 mu_argp_node_list_new (lst, "debug", arg ? arg : D_DEFAULT);
216 break;
217
218 case 'v':
219 mu_argp_node_list_new (lst, "verbose", "yes");
220 break;
221
222 case ARG_LINE_INFO:
223 mu_argp_node_list_new (lst, "line-info",
224 is_true_p (arg) ? "yes" : "no");
225 break;
226
227 case ARG_NO_PROGRAM_NAME:
228 mu_log_tag = NULL;
229 break;
230
231 case ARGP_KEY_ARG:
232 if (script)
233 argp_error (state, _("Only one SCRIPT can be specified"));
234 script = mu_tilde_expansion (arg, MU_HIERARCHY_DELIMITER, NULL);
235 break;
236
237 case ARGP_KEY_INIT:
238 mu_argp_node_list_init (&lst);
239 break;
240
241 case ARGP_KEY_FINI:
242 mu_argp_node_list_finish (lst, NULL, NULL);
243 break;
244
245 default:
246 return ARGP_ERR_UNKNOWN;
247 }
248 115
249 return 0; 116 static void
117 cli_debug (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
118 {
119 set_debug_level (arg);
250 } 120 }
251 121
252 static struct argp argp = 122 static void
123 cli_email (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
253 { 124 {
254 options, 125 int rc = mu_set_user_email (arg);
255 parser, 126 if (rc)
256 N_("SCRIPT"), 127 mu_parseopt_error (po, _("invalid email: %s"), mu_strerror (rc));
257 doc 128 }
258 }; 129
130 static void
131 cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt,
132 char const *arg)
133 {
134 mu_log_tag = NULL;
135 }
136
137 static struct mu_option sieve_options[] = {
138 { "no-actions", 'n', NULL, MU_OPTION_DEFAULT,
139 N_("do not execute any actions, just print what would be done"),
140 mu_c_string, NULL, cli_dry_run },
141 { "dry-run", 0, NULL, MU_OPTION_ALIAS },
142 { "keep-going", 'k', NULL, MU_OPTION_DEFAULT,
143 N_("keep on going if execution fails on a message"),
144 mu_c_bool, &keep_going },
145 { "compile-only", 'c', NULL, MU_OPTION_DEFAULT,
146 N_("compile script and exit"),
147 mu_c_bool, &compile_only },
148 { "dump", 'D', NULL, MU_OPTION_DEFAULT,
149 N_("compile script, dump disassembled sieve code to terminal and exit"),
150 mu_c_string, NULL, cli_compile_and_dump },
151 { "mbox-url", 'f', N_("MBOX"), MU_OPTION_DEFAULT,
152 N_("mailbox to sieve (defaults to user's mail spool)"),
153 mu_c_string, &mbox_url },
154 { "ticket", 't', N_("TICKET"), MU_OPTION_DEFAULT,
155 N_("ticket file for user authentication"),
156 mu_c_string, &mu_ticket_file },
157 { "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL,
158 N_("debug flags (defaults to \"" D_DEFAULT "\")"),
159 mu_c_string, NULL, cli_debug },
160 { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
161 N_("log all actions"),
162 mu_c_bool, &verbose },
163 { "line-info", 0, N_("BOOL"), MU_OPTION_DEFAULT,
164 N_("print source location along with action logs (default)"),
165 mu_c_bool, &sieve_print_locus },
166 { "email", 'e', N_("ADDRESS"), MU_OPTION_DEFAULT,
167 N_("override user email address"),
168 mu_c_string, NULL, cli_email },
169 { "expression", 'E', NULL, MU_OPTION_DEFAULT,
170 N_("treat SCRIPT as Sieve program text"),
171 mu_c_bool, &expression_option },
172 { "no-program-name", 0, NULL, MU_OPTION_DEFAULT,
173 N_("do not prefix diagnostic messages with the program name"),
174 mu_c_string, NULL, cli_no_program_name },
175 MU_OPTION_END
176 }, *options[] = { sieve_options, NULL };
177
178 int
179 mu_compat_printer (void *data, mu_log_level_t level, const char *buf)
180 {
181 fputs (buf, stderr);
182 return 0;
183 }
259 184
260 185
261 static int 186 static int
...@@ -307,18 +232,24 @@ static struct mu_cfg_param sieve_cfg_param[] = { ...@@ -307,18 +232,24 @@ static struct mu_cfg_param sieve_cfg_param[] = {
307 }; 232 };
308 233
309 234
310 static const char *sieve_argp_capa[] = 235 static char *sieve_argp_capa[] = {
311 {
312 "mailutils",
313 "common",
314 "debug", 236 "debug",
315 "mailbox", 237 "mailbox",
316 "locking", 238 "locking",
317 "logging", 239 "logging",
318 "mailer", 240 "mailer",
241 "tls",
242 "sieve",
319 NULL 243 NULL
320 }; 244 };
321 245
246 static struct mu_cli_setup cli = {
247 options,
248 sieve_cfg_param,
249 N_("GNU sieve -- a mail filtering tool."),
250 "SCRIPT"
251 };
252
322 static void 253 static void
323 _sieve_action_log (void *unused, 254 _sieve_action_log (void *unused,
324 mu_stream_t stream, size_t msgno, 255 mu_stream_t stream, size_t msgno,
...@@ -456,25 +387,29 @@ main (int argc, char *argv[]) ...@@ -456,25 +387,29 @@ main (int argc, char *argv[])
456 /* Native Language Support */ 387 /* Native Language Support */
457 MU_APP_INIT_NLS (); 388 MU_APP_INIT_NLS ();
458 389
459 mu_argp_init (NULL, NULL); 390 mu_cli_capa_register (&mu_cli_capa_tls);
460 #ifdef WITH_TLS 391 mu_cli_capa_register (&mu_cli_capa_sieve);
461 mu_gocs_register ("tls", mu_tls_module_init);
462 #endif
463 mu_gocs_register ("sieve", mu_sieve_module_init);
464 mu_sieve_debug_init (); 392 mu_sieve_debug_init ();
465 393
466 mu_register_all_formats (); 394 mu_register_all_formats ();
467 395
468 if (mu_app_init (&argp, sieve_argp_capa, sieve_cfg_param, 396 mu_cli (argc, argv, &cli, sieve_argp_capa, NULL, &argc, &argv);
469 argc, argv, ARGP_IN_ORDER, NULL, NULL)) 397
470 exit (EX_USAGE); 398 if (argc == 0)
471
472 if (!script)
473 { 399 {
474 mu_error (_("script must be specified")); 400 mu_error (_("script must be specified"));
475 exit (EX_USAGE); 401 exit (EX_USAGE);
476 } 402 }
477 403 else if (argc == 1)
404 {
405 script = mu_tilde_expansion (argv[0], MU_HIERARCHY_DELIMITER, NULL);
406 }
407 else
408 {
409 mu_error (_("only one SCRIPT can be specified"));
410 exit (EX_USAGE);
411 }
412
478 /* Sieve interpreter setup. */ 413 /* Sieve interpreter setup. */
479 rc = mu_sieve_machine_init (&mach); 414 rc = mu_sieve_machine_init (&mach);
480 if (rc) 415 if (rc)
......