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)')
AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)')
AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/libmu_argp/libmu_argp.la ${top_builddir}/libmu_cfg/libmu_cfg.la ${top_builddir}/lib/libmuaux.la')
AC_SUBST(MU_APP_NEW_LIBRARIES,'${top_builddir}/lib/libmuaux.la')
# There are two sets of include directories: MU_LIB_COMMON_INCLUDES, used
# by the libraries, and MU_APP_COMMON_INCLUDES, which is used by applications.
......
......@@ -20,7 +20,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
bin_PROGRAMS = dotlock
dotlock_LDADD = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MAILUTILS}\
@MU_COMMON_LIBRARIES@
......
......@@ -20,49 +20,12 @@
#endif
#include <stdlib.h>
#ifdef __EXT_QNX
# undef __EXT_QNX
#endif
#include <unistd.h>
#include <mailutils/errno.h>
#include <mailutils/locker.h>
#include <mailutils/nls.h>
#include "mailutils/libargp.h"
static char doc[] =
N_("GNU dotlock -- lock mail spool files.")
"\v"
N_("Returns 0 on success, 3 if locking the file fails because\
it's already locked, and 1 if some other kind of error occurred.");
static char args_doc[] = N_("FILE");
static struct argp_option options[] = {
{"unlock", 'u', NULL, 0,
N_("unlock"), 0},
{"force", 'f', N_("MINUTES"), OPTION_ARG_OPTIONAL,
N_("forcibly break an existing lock older than a certain time"), 0},
{"retry", 'r', N_("RETRIES"), OPTION_ARG_OPTIONAL,
N_("retry the lock a few times"), 0},
{"debug", 'd', NULL, 0,
N_("print details of failure reasons to stderr"), 0},
{NULL, 0, NULL, 0, NULL, 0}
};
static error_t parse_opt (int key, char *arg, struct argp_state *state);
static struct argp argp = {
options,
parse_opt,
args_doc,
doc,
};
#include "mailutils/cli.h"
static const char *file;
static int unlock;
......@@ -71,55 +34,25 @@ static int retries;
static time_t force;
static int debug;
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
static struct mu_option dotlock_options[] = {
{ "unlock", 'u', NULL, MU_OPTION_DEFAULT,
N_("unlock"),
mu_c_bool, &unlock },
switch (key)
{
case 'd':
mu_argp_node_list_new (lst, "debug", "yes");
break;
{ "force", 'f', N_("MINUTES"), MU_OPTION_ARG_OPTIONAL,
N_("forcibly break an existing lock older than a certain time"),
mu_c_time, &force },//FIXME: Default value
case 'u':
unlock = 1;
break;
{ "retry", 'r', N_("RETRIES"), MU_OPTION_ARG_OPTIONAL,
N_("retry the lock a few times"),
mu_c_int, &retries },
case 'r':
if (arg)
mu_argp_node_list_new (lst, "retry", arg);
break;
case 'f':
mu_argp_node_list_new (lst, "force", arg ? arg : "0");
break;
case ARGP_KEY_ARG:
if (file)
argp_error (state, _("only one FILE can be specified"));
file = arg;
break;
case ARGP_KEY_NO_ARGS:
if (!mu_help_config_mode)
argp_error (state, _("FILE must be specified"));
return ARGP_ERR_UNKNOWN;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, NULL, NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
{ "debug", 'd', NULL, MU_OPTION_DEFAULT,
N_("print details of failure reasons to stderr"),
mu_c_bool, &debug },
MU_OPTION_END
}, *options[] = { dotlock_options, NULL };
struct mu_cfg_param dotlock_cfg_param[] = {
{ "force", mu_c_time, &force, 0, NULL,
......@@ -131,11 +64,21 @@ struct mu_cfg_param dotlock_cfg_param[] = {
{ NULL }
};
static struct mu_cli_setup cli = {
options,
dotlock_cfg_param,
N_("GNU dotlock -- lock mail spool files."),
//FIXME:
/*
N_("Returns 0 on success, 3 if locking the file fails because\
it's already locked, and 1 if some other kind of error occurred.");
*/
N_("FILE")
};
const char *dotlock_capa[] = {
"mailutils",
"common",
char *capa[] = {
"debug",
NULL
};
......@@ -156,12 +99,23 @@ main (int argc, char *argv[])
if (setegid (usergid) < 0)
return MU_DL_EX_ERROR;
argp_err_exit_status = MU_DL_EX_ERROR;
/* FIXME: Force mu_cli to exit with MU_DL_EX_ERROR on errors? */
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, dotlock_capa, dotlock_cfg_param,
argc, argv, 0, NULL, NULL))
exit (1);
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
switch (argc)
{
case 0:
mu_error (_("FILE must be specified"));
exit (MU_DL_EX_ERROR);
case 1:
file = argv[0];
break;
default:
mu_error (_("only one FILE can be specified"));
}
if (force)
{
......
......@@ -27,7 +27,7 @@ frm_LDADD = $(common_ldadd)
from_LDADD = $(common_ldadd)
common_ldadd = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -29,8 +29,6 @@ static int align = 0; /* Tidy mode. -t option. */
#define IS_NEW 0x100
static int select_attribute;
static char doc[] = N_("GNU frm -- display From: lines.");
static struct attr_tab {
char *name; /* Attribute name */
int code; /* Corresponding IS_.* flag */
......@@ -84,7 +82,7 @@ prepare_attrs (void)
/* Translates the textual status representation to the corresponding
IS_.* flag */
static int
decode_attr (char *arg)
decode_attr (char const *arg)
{
struct attr_tab *p;
int len = strlen (arg);
......@@ -111,105 +109,82 @@ decode_attr (char *arg)
}
static struct argp_option options[] = {
{"debug", 'd', NULL, 0, N_("enable debugging output"), 0},
{"field", 'f', N_("NAME"), 0, N_("header field to display"), 0},
{"to", 'l', NULL, 0, N_("include the To: information"), 0},
{"number", 'n', NULL, 0, N_("display message numbers"), 0},
{"Quiet", 'Q', NULL, 0, N_("do not display headers"), 0},
{"query", 'q', NULL, 0, N_("print a message if the mailbox contains some unread mail"), 0},
{"summary",'S', NULL, 0, N_("print a summary of messages"), 0},
{"status", 's', N_("STATUS"), 0,
/* TRANSLATORS: Please do *not* translate the words "new", "unread",
"old" and "read". They are keywords. */
N_("select messages with the specific attribute:"
" new, unread, old (same as unread) or read (or any unambiguous"
" abbreviation of these)"),
0},
{"align", 't', NULL, 0, N_("tidy mode: align subject lines"), 0},
{0, 0, 0, 0}
};
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
static void
cli_show_field (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
switch (key)
{
case 'd':
frm_debug++;
break;
case 'f':
show_field = arg;
show_field = mu_strdup (arg);
align = 0;
break;
case 'l':
show_to = 1;
break;
case 'n':
show_number = 1;
break;
}
case 'Q':
/* Very silent. */
static void
cli_Quiet (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
be_quiet += 2;
break;
}
case 'q':
static void
cli_query (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
be_quiet++;
show_query = 1;
break;
case 'S':
show_summary = 1;
break;
}
case 's':
static void
cli_status (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
select_attribute = decode_attr (arg);
break;
case 't':
align = 1;
break;
case ARGP_KEY_FINI:
{
size_t s;
if (align && (s = util_getcols ()))
init_output (s);
else
init_output (0);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
static struct mu_option frm_options[] = {
{ "debug", 'd', NULL, MU_OPTION_DEFAULT,
N_("enable debugging output"),
mu_c_incr, &frm_debug },
{ "field", 'f', N_("NAME"), MU_OPTION_DEFAULT,
N_("header field to display"),
mu_c_string, &show_field, cli_show_field },
{ "to", 'l', NULL, MU_OPTION_DEFAULT,
N_("include the To: information"),
mu_c_bool, &show_to },
{ "number", 'n', NULL, MU_OPTION_DEFAULT,
N_("display message numbers"),
mu_c_bool, &show_number },
{ "Quiet", 'Q', NULL, MU_OPTION_DEFAULT,
N_("do not display headers"),
mu_c_int, &be_quiet, cli_Quiet },
{ "query", 'q', NULL, MU_OPTION_DEFAULT,
N_("print a message if the mailbox contains some unread mail"),
mu_c_int, &be_quiet, cli_query },
{ "summary",'S', NULL, MU_OPTION_DEFAULT,
N_("print a summary of messages"),
mu_c_bool, &show_summary },
{ "status", 's', N_("STATUS"), 0,
/* TRANSLATORS: Please do *not* translate the words "new", "unread",
"old" and "read". They are keywords. */
N_("select messages with the specific attribute:"
" new, unread, old (same as unread) or read (or any unambiguous"
" abbreviation of these)"),
mu_c_string, NULL, cli_status},
{ "align", 't', NULL, MU_OPTION_DEFAULT,
N_("tidy mode: align subject lines"),
mu_c_bool, &align },
MU_OPTION_END
}, *options[] = { frm_options, NULL };
static struct mu_cli_setup cli = {
options,
parse_opt,
N_("[URL ...]"),
doc,
NULL,
NULL, NULL
N_("GNU frm -- display From: lines."),
N_("[URL ...]"),
};
static const char *frm_argp_capa[] = {
"mailutils",
"common",
static char *frm_argp_capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
static struct
{
size_t new;
......@@ -342,8 +317,8 @@ frm (char *mailbox_name)
int
main (int argc, char **argv)
{
int c;
int status = 0;
size_t s;
/* Native Language Support */
MU_APP_INIT_NLS ();
......@@ -352,24 +327,29 @@ main (int argc, char **argv)
/* register the formats. */
mu_register_all_mbox_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, frm_argp_capa, NULL, argc, argv, 0, &c, NULL))
exit (1);
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
if (align && (s = util_getcols ()))
init_output (s);
else
init_output (0);
/* have an argument */
if (c == argc)
if (argc == 0)
status = frm (NULL);
else if (c + 1 == argc)
status = frm (argv[c]);
else if (argc == 1)
status = frm (argv[0]);
else
for (; c < argc; c++)
{
mu_printf ("%s:\n", argv[c]);
status = frm (argv[c]);
int i;
for (i = 0; i < argc; i++)
{
mu_printf ("%s:\n", argv[i]);
status = frm (argv[i]);
}
}
return status;
......
......@@ -64,7 +64,7 @@
#include <mailutils/util.h>
#include <mailutils/mime.h>
#include "mailutils/libargp.h"
#include "mailutils/cli.h"
typedef int (*frm_select_t) (size_t index, mu_message_t msg);
......
......@@ -21,58 +21,34 @@ int count_only;
char *sender_option;
char *mailbox_name;
static char doc[] = N_("GNU from -- display from and subject.");
static struct argp_option options[] = {
{"count", 'c', NULL, 0, N_("just print a count of messages and exit")},
{"sender", 's', N_("ADDRESS"), 0,
N_("print only mail from addresses containing the supplied string") },
{"file", 'f', N_("FILE"), 0,
N_("read mail from FILE") },
{"debug", 'd', NULL, 0, N_("enable debugging output"), 0},
{0, 0, 0, 0}
};
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'c':
count_only = 1;
break;
case 's':
sender_option = arg;
break;
case 'f':
mailbox_name = arg;
break;
case 'd':
frm_debug++;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
static struct mu_option from_options[] = {
{ "count", 'c', NULL, MU_OPTION_DEFAULT,
N_("just print a count of messages and exit"),
mu_c_bool, &count_only },
{ "sender", 's', N_("ADDRESS"), MU_OPTION_DEFAULT,
N_("print only mail from addresses containing the supplied string"),
mu_c_string, &sender_option },
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("read mail from FILE"),
mu_c_string, &mailbox_name },
{ "debug", 'd', NULL, MU_OPTION_DEFAULT,
N_("enable debugging output"),
mu_c_incr, &frm_debug },
MU_OPTION_END
}, *options[] = { from_options, NULL };
static struct mu_cli_setup cli = {
options,
parse_opt,
NULL,
N_("GNU from -- display from and subject."),
N_("[OPTIONS] [USER]"),
doc,
};
static const char *capa[] = {
"mailutils",
"common",
static char *capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
......@@ -105,7 +81,6 @@ from_select (size_t index, mu_message_t msg)
int
main (int argc, char **argv)
{
int c;
size_t total;
/* Native Language Support */
......@@ -113,20 +88,16 @@ main (int argc, char **argv)
/* register the formats. */
mu_register_all_mbox_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &c, NULL))
exit (1);
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
if (argc - c > 1)
if (argc > 1)
{
mu_error (_("too many arguments"));
exit (1);
}
else if (argc - c > 0)
else if (argc > 0)
{
if (mailbox_name)
{
......@@ -134,9 +105,9 @@ main (int argc, char **argv)
exit (1);
}
mailbox_name = mu_alloc (strlen (argv[c]) + 2);
mailbox_name = mu_alloc (strlen (argv[0]) + 2);
mailbox_name[0] = '%';
strcpy (mailbox_name + 1, argv[c]);
strcpy (mailbox_name + 1, argv[0]);
}
init_output (0);
......
......@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <stdarg.h>
#include <mailutils/mailutils.h>
#include <mailutils/cli.h>
#ifdef __cplusplus
extern "C" {
......@@ -282,6 +283,8 @@ struct mu_gocs_sieve
int mu_sieve_module_init (enum mu_gocs_op, void *);
extern struct mu_cli_capa mu_cli_capa_sieve;
#ifdef __cplusplus
}
#endif
......
......@@ -20,6 +20,7 @@
#define _MAILUTILS_TLS_H
#include <mailutils/types.h>
#include <mailutils/cli.h>
#ifdef __cplusplus
extern "C" {
......@@ -56,6 +57,8 @@ extern void mu_deinit_tls_libs (void);
extern int mu_tls_enable;
extern struct mu_cli_capa mu_cli_capa_tls;
#ifdef __cplusplus
}
#endif
......
......@@ -384,7 +384,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
optv = init_options (capa, setup, &com_list);
if (mu_parseopt (&po, argc, argv, optv, flags))
exit (EX_USAGE);
exit (po.po_exit_error);
argc -= po.po_arg_start;
argv += po.po_arg_start;
......
......@@ -28,6 +28,7 @@
#include <mailutils/mailbox.h>
#include <mailutils/registrar.h>
#include <mailutils/locker.h>
#include <mailutils/mu_auth.h>
/* *************************************************************************
* Logging section
......@@ -441,6 +442,105 @@ static struct mu_cfg_param address_cfg[] = {
{ NULL }
};
/* ************************************************************************* *
* Authentication & Authorization *
* ************************************************************************* */
static int
cb_authentication (void *data, mu_config_value_t *val)
{
if (val->type == MU_CFG_STRING)
{
if (strcmp (val->v.string, "clear") == 0)
mu_authentication_clear_list ();
else
/*FIXME: use err for error reporting*/
mu_authentication_add_module_list (val->v.string);
}
else if (val->type == MU_CFG_LIST)
{
int i;
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
mu_authentication_clear_list ();
else
mu_authentication_add_module (val->v.arg.v[i].v.string);
}
}
else
{
mu_error (_("expected string value"));
return 1;
}
return 0;
}
static int
cb_authorization (void *data, mu_config_value_t *val)
{
if (val->type == MU_CFG_STRING)
{
if (strcmp (val->v.string, "clear") == 0)
mu_authorization_clear_list ();
else
/*FIXME: use err for error reporting*/
mu_authorization_add_module_list (val->v.string);
}
else if (val->type == MU_CFG_LIST)
{
int i;
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
mu_authorization_clear_list ();
else
mu_authorization_add_module (val->v.arg.v[i].v.string);
}
}
else
{
mu_error (_("expected string value"));
return 1;
}
return 0;
}
static struct mu_cfg_param mu_auth_param[] = {
{ "authentication", mu_cfg_callback, NULL, 0, cb_authentication,
/* FIXME: The description is incomplete. MU-list is also allowed as
argument */
N_("Set a list of modules for authentication. Modlist is a "
"colon-separated list of module names or a word `clear' to "
"clear the previously set up values."),
N_("modlist") },
{ "authorization", mu_cfg_callback, NULL, 0, cb_authorization,
N_("Set a list of modules for authorization. Modlist is a "
"colon-separated list of module names or a word `clear' to "
"clear the previously set up values."),
N_("modlist") },
{ NULL }
};
int
mu_auth_section_parser
(enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
const char *section_label, void **section_data, void *call_data,
mu_cfg_tree_t *tree)
{
switch (stage)
{
case mu_cfg_section_start:
break;
case mu_cfg_section_end:
mu_auth_finish_setup ();
}
return 0;
}
/* ************************************************************************* *
* Registry of standard mailutils' capabilities *
......@@ -453,6 +553,8 @@ struct mu_cli_capa mu_cli_std_capa[] = {
{ "mailbox", NULL, mailbox_cfg, NULL, NULL },
{ "locking", NULL, locking_cfg, NULL, NULL },
{ "address", NULL, address_cfg, NULL, NULL },
{ "auth", NULL, mu_auth_param, mu_auth_section_parser },
{ NULL }
};
......
......@@ -35,15 +35,36 @@
#include <mailutils/errno.h>
#include <mailutils/util.h>
#include <mailutils/property.h>
#include <mailutils/cli.h>
#define SSL_CERT_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_LINKED_WRDIR)
#define SSL_KEY_FILE_CHECKS (MU_FILE_SAFETY_ALL & \
~MU_FILE_SAFETY_OWNER_MISMATCH)
#define SSL_CA_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_LINKED_WRDIR)
struct mu_tls_module_config mu_tls_module_config = {
#ifdef WITH_TLS
1 /* enable by default */
1, /* enable by default */
NULL, /* Certificate file */
SSL_CERT_FILE_CHECKS,
NULL, /* Key file */
SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
NULL, /* CA file */
SSL_CA_FILE_CHECKS
#else
0
#endif
};
//FIXME: REMOVE
int
mu_tls_module_init (enum mu_gocs_op op, void *data)
{
......@@ -775,7 +796,91 @@ mu_tls_client_stream_create (mu_stream_t *pstream,
strin, strout, flags);
}
static int
cb2_safety_checks (const char *name, void *data)
{
int defval;
if (data == &mu_tls_module_config.ssl_key_safety_checks)
defval = SSL_KEY_FILE_CHECKS;
else if (data == &mu_tls_module_config.ssl_cert_safety_checks)
defval = SSL_CERT_FILE_CHECKS;
else if (data == &mu_tls_module_config.ssl_cafile_safety_checks)
defval = SSL_CA_FILE_CHECKS;
else
{
mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
__FILE__, __LINE__);
defval = MU_FILE_SAFETY_ALL;
}
if (mu_file_safety_compose (data, name, defval))
mu_error (_("unknown keyword: %s"), name);
return 0;
}
static int
cb_safety_checks (void *data, mu_config_value_t *arg)
{
return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
}
static struct mu_cfg_param mu_tls_param[] = {
{ "enable", mu_c_bool, &mu_tls_module_config.enable, 0, NULL,
N_("Enable TLS encryption.") },
{ "ssl-cert", mu_c_string, &mu_tls_module_config.ssl_cert, 0, NULL,
N_("Specify SSL certificate file."),
N_("file") },
{ "ssl-key", mu_c_string, &mu_tls_module_config.ssl_key, 0, NULL,
N_("Specify SSL certificate key file."),
N_("file") },
{ "ssl-cafile", mu_c_string, &mu_tls_module_config.ssl_cafile, 0, NULL,
N_("Specify trusted CAs file."),
N_("file") },
{ "ssl-priorities", mu_c_string, &mu_tls_module_config.priorities, 0, NULL,
N_("Set the priorities to use on the ciphers, key exchange methods, "
"macs and compression methods."),
NULL },
{ "key-file-safety-checks", mu_cfg_callback,
&mu_tls_module_config.ssl_key_safety_checks, 0,
cb_safety_checks,
N_("Configure safety checks for SSL key file. Argument is a list or "
"sequence of check names optionally prefixed with '+' to enable or "
"'-' to disable the corresponding check. Valid check names are:\n"
"\n"
" none disable all checks\n"
" all enable all checks\n"
" gwrfil forbid group writable files\n"
" awrfil forbid world writable files\n"
" grdfil forbid group readable files\n"
" ardfil forbid world writable files\n"
" linkwrdir forbid symbolic links in group or world writable directories\n"
" gwrdir forbid files in group writable directories\n"
" awrdir forbid files in world writable directories\n"),
N_("arg: list") },
{ "cert-file-safety-checks", mu_cfg_callback,
&mu_tls_module_config.ssl_cert_safety_checks, 0,
cb_safety_checks,
N_("Configure safety checks for SSL certificate. See above for a description of <arg>."),
N_("arg: list") },
{ "ca-file-safety-checks", mu_cfg_callback,
&mu_tls_module_config.ssl_cafile_safety_checks, 0,
cb_safety_checks,
N_("Configure safety checks for SSL certificate authority file. See above for a description of <arg>."),
N_("arg: list") },
{ NULL }
};
struct mu_cli_capa mu_cli_capa_tls = {
"tls",
NULL,
mu_tls_param,
NULL, NULL
};
#else
struct mu_cli_capa mu_cli_capa_tls = {
"tls",
NULL
};
#endif /* WITH_TLS */
/* EOF */
......
......@@ -22,7 +22,7 @@ SUBDIRS = . tests
bin_PROGRAMS = messages
messages_SOURCES = messages.c
messages_LDADD =\
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -20,85 +20,44 @@
#endif
#include <stdio.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#include <mailutils/mailutils.h>
#include "mailutils/libargp.h"
#include <mailutils/cli.h>
static int messages_count (const char *);
static char doc[] = N_("GNU messages -- count the number of messages in a mailbox");
static char args_doc[] = N_("[mailbox...]");
/* are we loud or quiet? */
static int silent = 0;
static struct argp_option options[] = {
{ NULL, 0, NULL, 0,
/* TRANSLATORS: 'messages' is a program name. Do not translate it! */
N_("messages specific switches:"), 0},
{"quiet", 'q', NULL, 0, N_("only display number of messages")},
{"silent", 's', NULL, OPTION_ALIAS, NULL },
{ 0 }
static struct mu_option messages_options[] = {
{ "quiet", 'q', NULL, MU_OPTION_DEFAULT,
N_("only display number of messages"),
mu_c_bool, &silent },
{"silent", 's', NULL, MU_OPTION_ALIAS },
MU_OPTION_END
};
static const char *argp_capa[] = {
"mailutils",
"common",
static char *capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
struct arguments
{
int argc;
char **argv;
};
/* are we loud or quiet? */
static int silent = 0;
static struct mu_option *options[] = { messages_options, NULL };
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
struct arguments *args = state->input;
switch (key)
{
case 'q':
case 's':
silent = 1;
break;
case ARGP_KEY_ARG:
args->argv = realloc (args->argv,
sizeof (char *) * (state->arg_num + 2));
args->argv[state->arg_num] = arg;
args->argv[state->arg_num + 1] = NULL;
args->argc++;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
struct mu_cli_setup cli = {
options,
parse_opt,
args_doc,
doc,
NULL,
NULL, NULL
N_("GNU messages -- count the number of messages in a mailbox"),
N_("[mailbox...]")
};
int
main (int argc, char **argv)
{
int i = 1;
int err = 0;
struct arguments args = {0, NULL};
/* Native Language Support */
MU_APP_INIT_NLS ();
......@@ -106,20 +65,18 @@ main (int argc, char **argv)
/* register the formats. */
mu_register_all_mbox_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, NULL, &args))
exit (1);
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
if (args.argc < 1 && messages_count (NULL) < 0)
if (argc == 0 && messages_count (NULL) < 0)
err = 1;
else if (args.argc >= 1)
else if (argc >= 1)
{
for (i = 0; i < args.argc; i++)
size_t i;
for (i = 0; i < argc; i++)
{
if (messages_count (args.argv[i]) < 0)
if (messages_count (argv[i]) < 0)
err = 1;
}
}
......
......@@ -47,7 +47,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h
BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h
mimeview_LDADD = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MAILUTILS}\
@LTLIBINTL@
......
......@@ -26,38 +26,11 @@
#include <unistd.h>
#include <fcntl.h>
#include "mailutils/libargp.h"
#include "mailutils/cli.h"
#include "mailutils/argcv.h"
#include "mailcap.h"
static char doc[] = N_("GNU mimeview -- display files, using mailcap mechanism.")
"\v"
N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
N_("\n\nDebug flags are:\n\
g - Mime.types parser traces\n\
l - Mime.types lexical analyzer traces\n\
0-9 - Set debugging level\n");
#define OPT_METAMAIL 256
static struct argp_option options[] = {
{"no-ask", 'a', N_("TYPE-LIST"), OPTION_ARG_OPTIONAL,
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},
{"no-interactive", 'h', NULL, 0,
N_("disable interactive mode"), 0 },
{"print", 0, NULL, OPTION_ALIAS, NULL, 0 },
{"debug", 'd', N_("FLAGS"), OPTION_ARG_OPTIONAL,
N_("enable debugging output"), 0},
{"mimetypes", 't', N_("FILE"), 0,
N_("use this mime.types file"), 0},
{"dry-run", 'n', NULL, 0,
N_("do nothing, just print what would have been done"), 0},
{"metamail", OPT_METAMAIL, N_("FILE"), OPTION_ARG_OPTIONAL,
N_("use metamail to display files"), 0},
{0, 0, 0, 0}
};
int debug_level; /* Debugging level set by --debug option */
static int dry_run; /* Dry run mode */
static char *metamail; /* Name of metamail program, if requested */
......@@ -89,67 +62,61 @@ set_debug_flags (const char *arg)
}
}
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
static void
cli_no_ask (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
static mu_list_t lst;
switch (key)
{
case ARGP_KEY_INIT:
mimetypes_lex_debug (0);
mimetypes_gram_debug (0);
if (interactive == -1)
interactive = isatty (fileno (stdin));
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
if (dry_run && !debug_level)
debug_level = 1;
mu_argp_node_list_finish (lst, NULL, NULL);
break;
case 'a':
no_ask_types = arg ? arg : "*";
no_ask_types = mu_strdup (arg ? arg : "*");
setenv ("MM_NOASK", arg, 1); /* In case we are given --metamail option */
break;
case 'd':
mu_argp_node_list_new (lst, "debug", arg ? arg : "9");
break;
}
case 'h':
static void
cli_no_interactive (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
interactive = 0;
break;
case 'n':
dry_run = 1;
break;
case 't':
mu_argp_node_list_new (lst, "mimetypes", arg);
break;
case OPT_METAMAIL:
mu_argp_node_list_new (lst, "metamail", arg ? arg : "metamail");
break;
}
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
static void
cli_debug (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
set_debug_flags (arg);
}
static struct argp argp = {
options,
parse_opt,
N_("FILE [FILE ...]"),
doc,
NULL,
NULL, NULL
};
static void
cli_metamail (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
if (!arg)
arg = "metamail";
metamail = mu_strdup (arg);
}
static struct mu_option mimeview_options[] = {
{ "no-ask", 'a', N_("TYPE-LIST"), MU_OPTION_ARG_OPTIONAL,
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"),
mu_c_string, NULL, cli_no_ask },
{ "no-interactive", 'h', NULL, MU_OPTION_DEFAULT,
N_("disable interactive mode"),
mu_c_string, NULL, cli_no_interactive },
{ "print", 0, NULL, MU_OPTION_ALIAS },
{ "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL,
N_("enable debugging output"),
mu_c_string, NULL, cli_debug },
{ "mimetypes", 't', N_("FILE"), MU_OPTION_DEFAULT,
N_("use this mime.types file"),
mu_c_string, &mimetypes_config },
{ "dry-run", 'n', NULL, MU_OPTION_DEFAULT,
N_("do nothing, just print what would have been done"),
mu_c_bool, &dry_run },
{ "metamail", 0, N_("FILE"), MU_OPTION_ARG_OPTIONAL,
N_("use metamail to display files"),
mu_c_string, NULL, cli_metamail },
MU_OPTION_END
}, *options[] = { mimeview_options, NULL };
static int
cb_debug (void *data, mu_config_value_t *val)
......@@ -173,11 +140,22 @@ struct mu_cfg_param mimeview_cfg_param[] = {
{ NULL }
};
struct mu_cli_setup cli = {
options,
mimeview_cfg_param,
N_("GNU mimeview -- display files, using mailcap mechanism."),
//FIXME:
/*
N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
N_("\n\nDebug flags are:\n\
g - Mime.types parser traces\n\
l - Mime.types lexical analyzer traces\n\
0-9 - Set debugging level\n");
*/
N_("FILE [FILE ...]")
};
static const char *capa[] = {
"mailutils",
"common",
static char *capa[] = {
"debug",
NULL
};
......@@ -267,16 +245,15 @@ display_file (const char *type)
int
main (int argc, char **argv)
{
int index;
MU_APP_INIT_NLS ();
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, capa, mimeview_cfg_param,
argc, argv, 0, &index, NULL))
exit (1);
argc -= index;
argv += index;
mimetypes_lex_debug (0);
mimetypes_gram_debug (0);
interactive = isatty (fileno (stdin));
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
if (dry_run && !debug_level)
debug_level = 1;
if (argc == 0)
{
......
......@@ -19,7 +19,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@
bin_PROGRAMS = movemail
movemail_LDADD = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -27,46 +27,9 @@
#include <unistd.h>
#include <mailutils/mailutils.h>
#include <mailutils/tls.h>
#include "mailutils/libargp.h"
#include "mailutils/cli.h"
#include <muaux.h>
static char doc[] = N_("GNU movemail -- move messages across mailboxes.");
static char args_doc[] = N_("inbox-url destfile [POP-password]");
enum {
EMACS_OPTION=256,
IGNORE_ERRORS_OPTION,
PROGRAM_ID_OPTION,
MAX_MESSAGES_OPTION,
ONERROR_OPTION,
NOTIFY_OPTION
};
static struct argp_option options[] = {
{ "preserve", 'p', NULL, 0, N_("preserve the source mailbox") },
{ "keep-messages", 0, NULL, OPTION_ALIAS, NULL },
{ "reverse", 'r', NULL, 0, N_("reverse the sorting order") },
{ "emacs", EMACS_OPTION, NULL, 0,
N_("output information used by Emacs rmail interface") },
{ "uidl", 'u', NULL, 0,
N_("use UIDLs to avoid downloading the same message twice") },
{ "verbose", 'v', NULL, 0,
N_("increase verbosity level") },
{ "owner", 'P', N_("MODELIST"), 0,
N_("control mailbox ownership") },
{ "ignore-errors", IGNORE_ERRORS_OPTION, NULL, 0,
N_("try to continue after errors") },
{ "onerror", ONERROR_OPTION, N_("KW[,KW...]"), 0,
N_("what to do on errors") },
{ "program-id", PROGRAM_ID_OPTION, N_("FMT"), 0,
N_("set program identifier for diagnostics (default: program name)") },
{ "max-messages", MAX_MESSAGES_OPTION, N_("NUMBER"), 0,
N_("process at most NUMBER messages") },
{ "notify", NOTIFY_OPTION, NULL, 0,
N_("enable biff notification") },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static int reverse_order;
static int preserve_mail;
static int emacs_mode;
......@@ -136,83 +99,8 @@ mu_kwd_t method_kwd[] = {
{ NULL }
};
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
switch (key)
{
case 'r':
mu_argp_node_list_new (lst, "reverse", "yes");
break;
case 'p':
mu_argp_node_list_new (lst, "preserve", "yes");
break;
case 'P':
mu_argp_node_list_new (lst, "mailbox-ownership", arg);
break;
case 'u':
mu_argp_node_list_new (lst, "uidl", "yes");
break;
case 'v':
verbose_option++;
break;
case EMACS_OPTION:
mu_argp_node_list_new (lst, "emacs", "yes");
break;
case IGNORE_ERRORS_OPTION:
mu_argp_node_list_new (lst, "ignore-errors", "yes");
break;
case NOTIFY_OPTION:
notify = 1;
break;
case ONERROR_OPTION:
mu_argp_node_list_new (lst, "onerror", arg);
break;
case MAX_MESSAGES_OPTION:
mu_argp_node_list_new (lst, "max-messages", arg);
break;
case PROGRAM_ID_OPTION:
mu_argp_node_list_new (lst, "program-id", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, NULL, NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
options,
parse_opt,
args_doc,
doc,
NULL,
NULL, NULL
};
static int
_cb_mailbox_ownership (const char *str)
set_mailbox_ownership (const char *str)
{
if (strcmp (str, "clear") == 0)
so_method_num = 0;
......@@ -280,18 +168,14 @@ _cb_mailbox_ownership (const char *str)
}
static int
cb_mailbox_ownership (void *data, mu_config_value_t *val)
set_mailbox_ownership_list (char const *str)
{
int i;
if (val->type == MU_CFG_STRING)
{
const char *str = val->v.string;
if (!strchr (str, ','))
return _cb_mailbox_ownership (str);
return set_mailbox_ownership (str);
else
{
struct mu_wordsplit ws;
size_t i;
ws.ws_delim = ",";
if (mu_wordsplit (str, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM))
......@@ -302,28 +186,15 @@ cb_mailbox_ownership (void *data, mu_config_value_t *val)
}
for (i = 0; i < ws.ws_wordc; i++)
if (_cb_mailbox_ownership (ws.ws_wordv[i]))
if (set_mailbox_ownership (ws.ws_wordv[i]))
return 1;
mu_wordsplit_free (&ws);
return 0;
}
}
if (mu_cfg_assert_value_type (val, MU_CFG_LIST))
return 1;
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
if (_cb_mailbox_ownership (val->v.arg.v[i].v.string))
return 1;
}
return 0;
}
static int
cb_onerror (void *data, mu_config_value_t *val)
set_onerror_action (char const *str)
{
struct mu_wordsplit ws;
static struct mu_kwd onerror_kw[] = {
......@@ -334,15 +205,13 @@ cb_onerror (void *data, mu_config_value_t *val)
};
int i, flag;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (strcmp (val->v.string, "abort") == 0)
if (strcmp (str, "abort") == 0)
{
onerror_flags = 0;
return 0;
}
ws.ws_delim = ",";
if (mu_wordsplit (val->v.string, &ws,
if (mu_wordsplit (str, &ws,
MU_WRDSF_NOVAR | MU_WRDSF_NOCMD |
MU_WRDSF_DELIM | MU_WRDSF_WS))
{
......@@ -370,6 +239,99 @@ cb_onerror (void *data, mu_config_value_t *val)
return 0;
}
static void
cli_mailbox_ownership (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
if (set_mailbox_ownership_list (arg))
exit (po->po_exit_error);
}
static void
cli_onerror (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
if (set_onerror_action (arg))
exit (po->po_exit_error);
}
static struct mu_option movemail_options[] = {
{ "preserve", 'p', NULL, MU_OPTION_DEFAULT,
N_("preserve the source mailbox"),
mu_c_bool, &preserve_mail },
{ "keep-messages", 0, NULL, MU_OPTION_ALIAS },
{ "reverse", 'r', NULL, MU_OPTION_DEFAULT,
N_("reverse the sorting order"),
mu_c_bool, &reverse_order },
{ "emacs", 0, NULL, MU_OPTION_DEFAULT,
N_("output information used by Emacs rmail interface"),
mu_c_bool, &emacs_mode },
{ "uidl", 'u', NULL, MU_OPTION_DEFAULT,
N_("use UIDLs to avoid downloading the same message twice"),
mu_c_bool, &uidl_option },
{ "verbose", 'v', NULL, MU_OPTION_DEFAULT,
N_("increase verbosity level"),
mu_c_incr, &verbose_option },
{ "owner", 'P', N_("MODELIST"), MU_OPTION_DEFAULT,
N_("control mailbox ownership"),
mu_c_string, cli_mailbox_ownership },
{ "ignore-errors", 0, NULL, MU_OPTION_DEFAULT,
N_("try to continue after errors"),
mu_c_bool, &ignore_errors },
{ "onerror", 0, N_("KW[,KW...]"), MU_OPTION_DEFAULT,
N_("what to do on errors"),
mu_c_string, NULL, cli_onerror },
{ "program-id", 0, N_("FMT"), MU_OPTION_DEFAULT,
N_("set program identifier for diagnostics (default: program name)"),
mu_c_string, &program_id_option },
{ "max-messages", 0, N_("NUMBER"), MU_OPTION_DEFAULT,
N_("process at most NUMBER messages"),
mu_c_size, &max_messages_option },
{ "notify", 0, NULL, MU_OPTION_DEFAULT,
N_("enable biff notification"),
mu_c_bool, &notify },
MU_OPTION_END
}, *options[] = { movemail_options, NULL };
static int
cb_mailbox_ownership (void *data, mu_config_value_t *val)
{
int i;
if (val->type == MU_CFG_STRING)
set_mailbox_ownership_list (val->v.string);
if (mu_cfg_assert_value_type (val, MU_CFG_LIST))
return 1;
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
if (set_mailbox_ownership (val->v.arg.v[i].v.string))
return 1;
}
return 0;
}
static int
cb_onerror (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
return set_onerror_action (val->v.string);
}
struct mu_cfg_param movemail_cfg_param[] = {
{ "preserve", mu_c_bool, &preserve_mail, 0, NULL,
N_("Do not remove messages from the source mailbox.") },
......@@ -407,14 +369,19 @@ struct mu_cfg_param movemail_cfg_param[] = {
{ NULL }
};
struct mu_cli_setup cli = {
options,
movemail_cfg_param,
N_("GNU movemail -- move messages across mailboxes."),
N_("inbox-url destfile [POP-password]")
};
static const char *movemail_capa[] = {
"mailutils",
"common",
static char *movemail_capa[] = {
"debug",
"locking",
"mailbox",
"auth",
"tls",
NULL
};
......@@ -863,7 +830,6 @@ set_program_id (const char *source_name, const char *dest_name)
int
main (int argc, char **argv)
{
int index;
size_t total;
int rc = 0;
char *source_name, *dest_name;
......@@ -880,16 +846,8 @@ main (int argc, char **argv)
/* argument parsing */
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, movemail_capa, movemail_cfg_param,
argc, argv, 0, &index, NULL))
exit (1);
argc -= index;
argv += index;
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv);
if (argc < 2 || argc > 3)
{
......
......@@ -23,7 +23,7 @@ bin_PROGRAMS = readmsg
readmsg_SOURCES = readmsg.c msglist.c readmsg.h
readmsg_LDADD =\
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -20,7 +20,7 @@
#endif
#include "readmsg.h"
#include "mailutils/libargp.h"
#include "mailutils/cli.h"
#include "mu_umaxtostr.h"
#define WEEDLIST_SEPARATOR " :,"
......@@ -30,41 +30,6 @@ static void print_header (mu_message_t, int, int, char **);
static void print_body (mu_message_t);
static int string_starts_with (const char * s1, const char *s2);
static char doc[] = N_("GNU readmsg -- print messages.");
static error_t readmsg_parse_opt (int key, char *arg, struct argp_state *astate);
static struct argp_option options[] =
{
{ "debug", 'd', 0, 0, N_("display debugging information"), 1 },
{ "header", 'h', 0, 0, N_("display entire header"), 1 },
{ "weedlist", 'w', N_("LIST"), 0,
N_("list of header names separated by whitespace or commas"), 1 },
{ "folder", 'f', N_("FOLDER"), 0, N_("folder to use"), 1 },
{ "no-header", 'n', 0, 0, N_("exclude all headers"), 1 },
{ "form-feeds", 'p', 0, 0, N_("output formfeeds between messages"), 1 },
{ "show-all-match", 'a', NULL, 0,
N_("print all messages matching pattern, not only the first"), 1 },
{0, 0, 0, 0}
};
static struct argp argp = {
options,
readmsg_parse_opt,
NULL,
doc,
NULL,
NULL, NULL
};
static const char *readmsg_argp_capa[] = {
"mailutils",
"common",
"debug",
"mailbox",
"locking",
NULL
};
int dbug = 0;
const char *mailbox_name = NULL;
const char *weedlist = NULL;
......@@ -73,57 +38,30 @@ int all_header = 0;
int form_feed = 0;
int show_all = 0;
static error_t
readmsg_parse_opt (int key, char *arg, struct argp_state *astate)
static struct mu_option readmsg_options[] =
{
static mu_list_t lst;
switch (key)
{
case 'd':
dbug++;
break;
case 'h':
mu_argp_node_list_new (lst, "header", "yes");
break;
case 'f':
mu_argp_node_list_new (lst, "folder", arg);
break;
case 'w':
mu_argp_node_list_new (lst, "weedlist", arg);
break;
case 'n':
mu_argp_node_list_new (lst, "no-header", "yes");
break;
case 'p':
mu_argp_node_list_new (lst, "form-feeds", "yes");
break;
case 'a':
mu_argp_node_list_new (lst, "show-all-match", "yes");
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
if (dbug)
mu_argp_node_list_new (lst, "debug", mu_umaxtostr (0, dbug));
mu_argp_node_list_finish (lst, NULL, NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
{ "debug", 'd', NULL, MU_OPTION_DEFAULT,
N_("display debugging information"),
mu_c_incr, &dbug },
{ "header", 'h', NULL, MU_OPTION_DEFAULT,
N_("display entire headers"),
mu_c_bool, &all_header },
{ "weedlist", 'w', N_("LIST"), MU_OPTION_DEFAULT,
N_("list of header names separated by whitespace or commas"),
mu_c_string, &weedlist },
{ "folder", 'f', N_("FOLDER"), MU_OPTION_DEFAULT,
N_("folder to use"), mu_c_string, &mailbox_name },
{ "no-header", 'n', NULL, MU_OPTION_DEFAULT,
N_("exclude all headers"),
mu_c_bool, &no_header },
{ "form-feeds", 'p', NULL, MU_OPTION_DEFAULT,
N_("output formfeeds between messages"),
mu_c_bool, &form_feed },
{ "show-all-match", 'a', NULL, MU_OPTION_DEFAULT,
N_("print all messages matching pattern, not only the first"),
mu_c_bool, &show_all },
MU_OPTION_END
}, *options[] = { readmsg_options, NULL };
struct mu_cfg_param readmsg_cfg_param[] = {
{ "debug", mu_c_int, &dbug, 0, NULL,
......@@ -145,6 +83,21 @@ struct mu_cfg_param readmsg_cfg_param[] = {
{ NULL }
};
struct mu_cli_setup cli = {
options,
readmsg_cfg_param,
N_("GNU readmsg -- print messages."),
NULL
};
static char *readmsg_argp_capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
static int
string_starts_with (const char * s1, const char *s2)
{
......@@ -158,7 +111,7 @@ string_starts_with (const char * s1, const char *s2)
while (*p1 && *p2)
{
if ((n = toupper (*p1++) - toupper (*p2++)) != 0)
if ((n = mu_toupper (*p1++) - mu_toupper (*p2++)) != 0)
break;
}
return (n == 0);
......@@ -276,7 +229,6 @@ main (int argc, char **argv)
int *set = NULL;
int n = 0;
int i;
int index;
mu_mailbox_t mbox = NULL;
struct mu_wordsplit ws;
char **weedv;
......@@ -290,15 +242,9 @@ main (int argc, char **argv)
mu_register_all_mbox_formats ();
mu_register_extra_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, readmsg_argp_capa, readmsg_cfg_param,
argc, argv, 0, &index, NULL))
exit (1);
mu_cli_capa_register (&mu_cli_capa_tls);
argc -= index;
mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
if (argc == 0)
{
......@@ -376,7 +322,7 @@ main (int argc, char **argv)
}
/* Build an array containing the message number. */
msglist (mbox, show_all, argc, &argv[index], &set, &n);
msglist (mbox, show_all, argc, argv, &set, &n);
for (i = 0; i < n; ++i)
{
......
......@@ -22,7 +22,7 @@ EXTRA_DIST = examples
bin_PROGRAMS = sieve
sieve_SOURCES = sieve.c
sieve_LDADD =\
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_SIEVE}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
......
......@@ -43,64 +43,10 @@
#include <mailutils/stream.h>
#include <mailutils/nls.h>
#include <mailutils/tls.h>
#include "mailutils/libargp.h"
static char doc[] =
N_("GNU sieve -- a mail filtering tool.")
"\v"
N_("Debug flags:\n\
g - main parser traces\n\
T - mailutils traces (same as --debug-level=sieve.trace0-trace1)\n\
P - network protocols (same as --debug-level=sieve.=prot)\n\
t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n");
#include <mailutils/cli.h>
#define D_DEFAULT "TPt"
#define ARG_LINE_INFO 257
#define ARG_NO_PROGRAM_NAME 258
static struct argp_option options[] =
{
{"no-actions", 'n', 0, 0,
N_("do not execute any actions, just print what would be done"), 0},
{"dry-run", 0, NULL, OPTION_ALIAS, NULL },
{"keep-going", 'k', 0, 0,
N_("keep on going if execution fails on a message"), 0},
{"compile-only", 'c', 0, 0,
N_("compile script and exit"), 0},
{"dump", 'D', 0, 0,
N_("compile script, dump disassembled sieve code to terminal and exit"), 0 },
{"mbox-url", 'f', N_("MBOX"), 0,
N_("mailbox to sieve (defaults to user's mail spool)"), 0},
{"ticket", 't', N_("TICKET"), 0,
N_("ticket file for user authentication"), 0},
{"debug", 'd', N_("FLAGS"), OPTION_ARG_OPTIONAL,
N_("debug flags (defaults to \"" D_DEFAULT "\")"), 0},
{"verbose", 'v', NULL, 0,
N_("log all actions"), 0},
{"line-info", ARG_LINE_INFO, N_("BOOL"), OPTION_ARG_OPTIONAL,
N_("print source location along with action logs (default)") },
{"email", 'e', N_("ADDRESS"), 0,
N_("override user email address"), 0},
{"expression", 'E', NULL, 0,
N_("treat SCRIPT as Sieve program text"), 0},
{"no-program-name", ARG_NO_PROGRAM_NAME, NULL, 0,
N_("do not prefix diagnostic messages with the program name"), 0},
{0}
};
int keep_going;
int compile_only;
char *mbox_url;
......@@ -112,17 +58,6 @@ int expression_option;
static int sieve_print_locus = 1; /* Should the log messages include the
locus */
static int
is_true_p (char *p)
{
int rc;
if (!p)
return 1;
if ((rc = mu_true_answer_p (p)) == -1)
return 0;
return rc;
}
static void
set_debug_level (const char *arg)
{
......@@ -164,99 +99,89 @@ set_debug_level (const char *arg)
}
}
int
mu_compat_printer (void *data, mu_log_level_t level, const char *buf)
static void
cli_dry_run (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
fputs (buf, stderr);
return 0;
sieve_debug |= MU_SIEVE_DRY_RUN;
verbose = 1;
}
static error_t
parser (int key, char *arg, struct argp_state *state)
static void
cli_compile_and_dump (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
static mu_list_t lst;
switch (key)
{
case 'E':
expression_option = 1;
break;
case 'e':
mu_argp_node_list_new (lst, "email", arg);
break;
case 'n':
sieve_debug |= MU_SIEVE_DRY_RUN;
mu_argp_node_list_new (lst, "verbose", "yes");
break;
case 'k':
mu_argp_node_list_new (lst, "keep-going", "yes");
break;
case 'c':
compile_only = 1;
break;
case 'D':
compile_only = 2;
break;
case 'f':
mu_argp_node_list_new (lst, "mbox-url", arg);
break;
case 't':
mu_argp_node_list_new (lst, "ticket", arg);
break;
case 'd':
mu_argp_node_list_new (lst, "debug", arg ? arg : D_DEFAULT);
break;
}
case 'v':
mu_argp_node_list_new (lst, "verbose", "yes");
break;
static void
cli_debug (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
set_debug_level (arg);
}
case ARG_LINE_INFO:
mu_argp_node_list_new (lst, "line-info",
is_true_p (arg) ? "yes" : "no");
break;
static void
cli_email (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
int rc = mu_set_user_email (arg);
if (rc)
mu_parseopt_error (po, _("invalid email: %s"), mu_strerror (rc));
}
case ARG_NO_PROGRAM_NAME:
static void
cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
mu_log_tag = NULL;
break;
case ARGP_KEY_ARG:
if (script)
argp_error (state, _("Only one SCRIPT can be specified"));
script = mu_tilde_expansion (arg, MU_HIERARCHY_DELIMITER, NULL);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, NULL, NULL);
break;
}
default:
return ARGP_ERR_UNKNOWN;
}
static struct mu_option sieve_options[] = {
{ "no-actions", 'n', NULL, MU_OPTION_DEFAULT,
N_("do not execute any actions, just print what would be done"),
mu_c_string, NULL, cli_dry_run },
{ "dry-run", 0, NULL, MU_OPTION_ALIAS },
{ "keep-going", 'k', NULL, MU_OPTION_DEFAULT,
N_("keep on going if execution fails on a message"),
mu_c_bool, &keep_going },
{ "compile-only", 'c', NULL, MU_OPTION_DEFAULT,
N_("compile script and exit"),
mu_c_bool, &compile_only },
{ "dump", 'D', NULL, MU_OPTION_DEFAULT,
N_("compile script, dump disassembled sieve code to terminal and exit"),
mu_c_string, NULL, cli_compile_and_dump },
{ "mbox-url", 'f', N_("MBOX"), MU_OPTION_DEFAULT,
N_("mailbox to sieve (defaults to user's mail spool)"),
mu_c_string, &mbox_url },
{ "ticket", 't', N_("TICKET"), MU_OPTION_DEFAULT,
N_("ticket file for user authentication"),
mu_c_string, &mu_ticket_file },
{ "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL,
N_("debug flags (defaults to \"" D_DEFAULT "\")"),
mu_c_string, NULL, cli_debug },
{ "verbose", 'v', NULL, MU_OPTION_DEFAULT,
N_("log all actions"),
mu_c_bool, &verbose },
{ "line-info", 0, N_("BOOL"), MU_OPTION_DEFAULT,
N_("print source location along with action logs (default)"),
mu_c_bool, &sieve_print_locus },
{ "email", 'e', N_("ADDRESS"), MU_OPTION_DEFAULT,
N_("override user email address"),
mu_c_string, NULL, cli_email },
{ "expression", 'E', NULL, MU_OPTION_DEFAULT,
N_("treat SCRIPT as Sieve program text"),
mu_c_bool, &expression_option },
{ "no-program-name", 0, NULL, MU_OPTION_DEFAULT,
N_("do not prefix diagnostic messages with the program name"),
mu_c_string, NULL, cli_no_program_name },
MU_OPTION_END
}, *options[] = { sieve_options, NULL };
int
mu_compat_printer (void *data, mu_log_level_t level, const char *buf)
{
fputs (buf, stderr);
return 0;
}
static struct argp argp =
{
options,
parser,
N_("SCRIPT"),
doc
};
static int
cb_debug (void *data, mu_config_value_t *val)
......@@ -307,18 +232,24 @@ static struct mu_cfg_param sieve_cfg_param[] = {
};
static const char *sieve_argp_capa[] =
{
"mailutils",
"common",
static char *sieve_argp_capa[] = {
"debug",
"mailbox",
"locking",
"logging",
"mailer",
"tls",
"sieve",
NULL
};
static struct mu_cli_setup cli = {
options,
sieve_cfg_param,
N_("GNU sieve -- a mail filtering tool."),
"SCRIPT"
};
static void
_sieve_action_log (void *unused,
mu_stream_t stream, size_t msgno,
......@@ -456,24 +387,28 @@ main (int argc, char *argv[])
/* Native Language Support */
MU_APP_INIT_NLS ();
mu_argp_init (NULL, NULL);
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_gocs_register ("sieve", mu_sieve_module_init);
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli_capa_register (&mu_cli_capa_sieve);
mu_sieve_debug_init ();
mu_register_all_formats ();
if (mu_app_init (&argp, sieve_argp_capa, sieve_cfg_param,
argc, argv, ARGP_IN_ORDER, NULL, NULL))
exit (EX_USAGE);
mu_cli (argc, argv, &cli, sieve_argp_capa, NULL, &argc, &argv);
if (!script)
if (argc == 0)
{
mu_error (_("script must be specified"));
exit (EX_USAGE);
}
else if (argc == 1)
{
script = mu_tilde_expansion (argv[0], MU_HIERARCHY_DELIMITER, NULL);
}
else
{
mu_error (_("only one SCRIPT can be specified"));
exit (EX_USAGE);
}
/* Sieve interpreter setup. */
rc = mu_sieve_machine_init (&mach);
......