Commit 444d20f3 444d20f3c7151c1d30fa6567cce35868c7ec38f3 by Sergey Poznyakoff

Rewrite the mailutils tool

The subcommands are re-implemented as standalone binaries installed
to pkglibexecdir.  The main binary acts as a dispatcher.

* configure.ac: Build mu/libexec/Makefile
* include/mailutils/.gitignore: Ignore gitinfo.h

* include/mailutils/opt.h (mu_parseopt_help_stream_create): New proto.
* libmailutils/cli/cli.c (mu_cli_ext): Honor MU_PARSEOPT_PROG_NAME
setting.
* libmailutils/opt/help.c (mu_parseopt_create_help_stream): New
function.
(mu_program_help,mu_program_usage)
(mu_program_version): Use it.

* mu/Makefile.am: Move commands to separate executables under libexec.
* mu/mu.c: Rewrite.
* mu/dispatch.c: Remove.
* mu/help.c: Remove.
* mu/libexec/.gitignore: New file.
* mu/libexec/Makefile.am: New file.
* mu/libexec/getopt.c: New file.
* mu/getans.c: Move to mu/libexec.
* mu/getarg.c: Likewise.
* mu/getyn.c: Likewise.
* mu/util.c: Likewise.
* mu/verbose.c: Likewise.
* mu/shell.c: Likewise.
* mu/mu.h: Remove.
* mu/libexec/mu.h: New file.
* mu/acl.c: Move to mu/libexec; Rewrite as a standalone program.
* mu/cflags.c: Likewise.
* mu/dbm.c: Likewise.
* mu/filter.c: Likewise.
* mu/flt2047.c: Likewise.
* mu/imap.c: Likewise.
* mu/info.c: Likewise.
* mu/ldflags.c: Likewise.
* mu/logger.c: Likewise.
* mu/pop.c: Likewise.
* mu/query.c: Likewise.
* mu/send.c: Likewise.
* mu/smtp.c: Likewise.
* mu/stat.c: Likewise.
* mu/wicket.c: Likewise.
* mu/mu-setup.awk: Remove.
* po/POTFILES.in: Update.
1 parent 460fc33f
......@@ -1541,6 +1541,7 @@ AC_CONFIG_FILES([
mu-aux/mailutils.spec
sieve/Makefile
mu/Makefile
mu/libexec/Makefile
])
AC_OUTPUT
......
......@@ -2,3 +2,4 @@ Makefile
Makefile.in
errno.h
types.h
gitinfo.h
......
......@@ -185,6 +185,9 @@ void mu_parseopt_error (struct mu_parseopt *po, char const *fmt, ...);
int mu_parseopt_apply (struct mu_parseopt *p);
void mu_parseopt_free (struct mu_parseopt *p);
int mu_parseopt_help_stream_create (mu_stream_t *retstr,
struct mu_parseopt *po,
mu_stream_t outstr);
unsigned mu_parseopt_getcolumn (const char *name);
void mu_option_describe_options (mu_stream_t str, struct mu_parseopt *p);
......
......@@ -483,6 +483,7 @@ run_commit (void *item, void *data)
| MU_PARSEOPT_BUG_ADDRESS \
| MU_PARSEOPT_EXTRA_INFO \
| MU_PARSEOPT_VERSION_HOOK \
| MU_PARSEOPT_PROG_NAME \
| MU_PARSEOPT_NEGATION)
void
......@@ -520,8 +521,13 @@ mu_cli_ext (int argc, char **argv,
/* Set program name */
if (!(hints.flags & MU_CFHINT_PROGRAM))
{
mu_set_program_name (argv[0]);
hints.program = (char*) mu_program_name;
if (pohint->po_flags & MU_PARSEOPT_PROG_NAME)
hints.program = (char *) pohint->po_prog_name;
else
{
mu_set_program_name (argv[0]);
hints.program = (char*) mu_program_name;
}
hints.flags |= MU_CFHINT_PROGRAM;
}
......@@ -610,7 +616,9 @@ mu_cli_ext (int argc, char **argv,
po.po_version_hook = pohint->po_version_hook;
if (flags & MU_PARSEOPT_NEGATION)
po.po_negation = pohint->po_negation;
if (flags & MU_PARSEOPT_PROG_NAME)
po.po_prog_name = pohint->po_prog_name;
appd.setup = setup;
appd.hints = &hints;
appd.append_tree = NULL;
......
......@@ -345,19 +345,21 @@ mu_option_describe_options (mu_stream_t str, struct mu_parseopt *po)
static void print_program_usage (struct mu_parseopt *po, int optsum,
mu_stream_t str);
int
mu_parseopt_help_stream_create (mu_stream_t *retstr,
struct mu_parseopt *po, mu_stream_t outstr)
{
init_usage_vars (po);
return mu_wordwrap_stream_create (retstr, outstr, 0, rmargin);
}
void
mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
{
mu_stream_t str;
int rc;
init_usage_vars (po);
rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
if (rc)
{
abort ();//FIXME
}
if (mu_parseopt_help_stream_create (&str, po, outstr))
abort ();
print_program_usage (po, 0, str);
......@@ -575,16 +577,10 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
void
mu_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t outstr)
{
int rc;
mu_stream_t str;
init_usage_vars (po);
rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
if (rc)
{
abort ();//FIXME
}
if (mu_parseopt_help_stream_create (&str, po, outstr))
abort ();
print_program_usage (po, optsum, str);
mu_stream_destroy (&str);
}
......@@ -592,16 +588,11 @@ mu_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t outstr)
void
mu_program_version (struct mu_parseopt *po, mu_stream_t outstr)
{
int rc;
mu_stream_t str;
init_usage_vars (po);
rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
if (rc)
{
abort ();//FIXME
}
if (mu_parseopt_help_stream_create (&str, po, outstr))
abort ();
po->po_version_hook (po, str);
mu_stream_destroy (&str);
......
......@@ -15,99 +15,15 @@
## You should have received a copy of the GNU General Public License
## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
SUBDIRS = libexec
bin_PROGRAMS = mailutils
bin_SCRIPTS = mailutils-config
EXTRA_DIST = mailutils-config
IDLE_MODULES=
if MU_COND_SUPPORT_POP
POP_C=pop.c
else
IDLE_MODULES+=pop.c
endif
if MU_COND_SUPPORT_IMAP
IMAP_C=imap.c
else
IDLE_MODULES+=imap.c
endif
if MU_COND_DBM
DBM_C=dbm.c
LIBMU_DBM=../libmu_dbm/libmu_dbm.la
else
IDLE_MODULES+=dbm.c
endif
if MU_COND_SUPPORT_SMTP
SMTP_C=smtp.c
else
IDLE_MODULES+=smtp.c
endif
MODULES = \
acl.c\
cflags.c\
$(DBM_C)\
$(IMAP_C)\
filter.c\
flt2047.c\
help.c\
info.c\
ldflags.c\
logger.c\
$(POP_C)\
query.c\
send.c\
stat.c\
$(SMTP_C)\
wicket.c
mailutils_SOURCES = \
dispatch.c\
getans.c\
getarg.c\
getyn.c\
mu.h\
mu.c\
shell.c\
util.c\
verbose.c\
$(MODULES)
mailutils_LDADD = \
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
${MU_LIB_NNTP}\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
${MU_LIB_MAILER}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}\
${LIBMU_DBM} @DBMLIBS@\
@READLINE_LIBS@ @MU_COMMON_LIBRARIES@
AM_CPPFLAGS = \
@MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@\
-DCOMPILE_FLAGS="\"-I$(includedir)\"" \
-DLINK_FLAGS="\"-L$(libdir)\"" \
-DLINK_POSTFLAGS="\"$(MU_LINK_POSTFLAGS)\"" \
-DAUTHLIBS="\"$(MU_AUTHLIBS)\"" \
-DGUILE_LIBS="\"$(GUILE_LIBS)\"" \
-DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
-DI18NLIBS="\"$(LIBINTL)\"" \
-DDBMLIBS="\"$(DBMLIBS)\""
BUILT_SOURCES=mu-setup.c mu-setup.h
EXTRA_DIST=mu-setup.awk mu-setup.c mu-setup.h template.c mailutils-config
mailutils_SOURCES = mu.c
mailutils_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ -DMAILUTILSDIR=\"$(pkglibexecdir)\"
mu-setup.h: Makefile.am $(MODULES) $(IDLE_MODULES)
$(AM_V_GEN)$(AWK) -f $(srcdir)/mu-setup.awk -v mode=h \
$(MODULES) $(IDLE_MODULES) > mu-setup.h
LDADD = ${MU_APP_LIBRARIES} ${MU_LIB_MAILUTILS}
mu-setup.c: Makefile.am $(MODULES) $(IDLE_MODULES)
$(AM_V_GEN)$(AWK) -f $(srcdir)/mu-setup.awk -v mode=c \
$(MODULES) $(IDLE_MODULES) > mu-setup.c
AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/alloc.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/nls.h>
#include "mu.h"
#include "mu-setup.h"
struct mutool_action_tab
{
const char *name;
mutool_action_t action;
const char *docstring;
};
struct mutool_action_tab mutool_action_tab[] = {
#include "mu-setup.c"
{ NULL }
};
mutool_action_t
dispatch_find_action (const char *name)
{
struct mutool_action_tab *p;
for (p = mutool_action_tab; p->name; p++)
if (strcmp (p->name, name) == 0)
return p->action;
return NULL;
}
void
subcommand_help (mu_stream_t str)
{
struct mutool_action_tab *p;
unsigned margin;
mu_stream_printf (str, "%s\n\n", _("Commands are:"));
for (p = mutool_action_tab; p->name; p++)
{
margin = 2;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (str, "%s %s", mu_program_name, p->name);
margin = 29;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (str, "%s", gettext (p->docstring));
}
margin = 0;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (str,
_("\nTry `%s COMMAND --help' to get help on a particular "
"COMMAND.\n\n"),
mu_program_name);
mu_stream_printf (str, "%s\n", _("OPTIONs are:"));
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
/* mu help - specjalnie dla Wojtka :) */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/nls.h>
#include <mailutils/io.h>
#include "mu.h"
static char help_doc[] = N_("mu help - display a terse help summary");
char help_docstring[] = N_("display a terse help summary");
static char help_args_doc[] = N_("[COMMAND]");
int
mutool_help (int argc, char **argv)
{
mu_action_getopt (&argc, &argv, NULL, help_doc, help_args_doc);
if (argc == 1)
{
char *hargv[3];
mutool_action_t action = dispatch_find_action (argv[0]);
if (!action)
{
mu_error (_("don't know what %s is"), argv[0]);
exit (1);
}
hargv[0] = argv[0];
hargv[1] = "--help";
hargv[2] = NULL;
return action (3, hargv);
}
else if (argc > 1)
{
mu_error (_("too many arguments"));
exit (1);
}
return mu_help ();
}
/*
MU Setup: help
mu-handler: mutool_help
mu-docstring: help_docstring
End MU Setup:
*/
pkglibexec_PROGRAMS=\
mailutils-acl\
mailutils-cflags\
mailutils-ldflags\
mailutils-filter\
mailutils-flt2047\
mailutils-info\
mailutils-logger\
mailutils-query\
mailutils-send\
mailutils-smtp\
mailutils-stat\
mailutils-wicket
noinst_HEADERS = mu.h
noinst_LIBRARIES = libmutool.a
libmutool_a_SOURCES = \
getopt.c\
getans.c\
getarg.c\
getyn.c\
shell.c\
util.c\
verbose.c
mailutils_acl_SOURCES = acl.c
mailutils_filter_SOURCES = filter.c
mailutils_flt2047_SOURCES = flt2047.c
mailutils_info_SOURCES = info.c
mailutils_logger_SOURCES = logger.c
mailutils_query_SOURCES = query.c
mailutils_wicket_SOURCES = wicket.c
mailutils_cflags_SOURCES=cflags.c
mailutils_cflags_CPPFLAGS = $(AM_CPPFLAGS)\
-DCOMPILE_FLAGS="\"-I$(includedir)\""
mailutils_ldflags_SOURCES=ldflags.c
mailutils_ldflags_CPPFLAGS = $(AM_CPPFLAGS)\
-DLINK_FLAGS="\"-L$(libdir)\"" \
-DLINK_POSTFLAGS="\"$(MU_LINK_POSTFLAGS)\"" \
-DAUTHLIBS="\"$(MU_AUTHLIBS)\"" \
-DGUILE_LIBS="\"$(GUILE_LIBS)\"" \
-DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
-DI18NLIBS="\"$(LIBINTL)\"" \
-DDBMLIBS="\"$(DBMLIBS)\""
if MU_COND_DBM
pkglibexec_PROGRAMS += mailutils-dbm
mailutils_dbm_SOURCES = dbm.c
mailutils_dbm_LDFLAGS = \
${MU_APP_LIBRARIES}\
../../libmu_dbm/libmu_dbm.la\
@DBMLIBS@\
$(MUTOOL_LIBRARIES_TAIL)
endif
if MU_COND_SUPPORT_POP
pkglibexec_PROGRAMS += mailutils-pop
mailutils_pop_SOURCES = pop.c
mailutils_pop_CPPFLAGS = \
$(AM_CPPFLAGS)\
@MU_AUTHINCS@
mailutils_pop_LDADD =\
${MU_APP_LIBRARIES}\
${MU_LIB_POP}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@\
$(MUTOOL_LIBRARIES_TAIL)
endif
if MU_COND_SUPPORT_IMAP
pkglibexec_PROGRAMS += mailutils-imap
mailutils_imap_SOURCES = imap.c
mailutils_imap_CPPFLAGS = \
$(AM_CPPFLAGS)\
@MU_AUTHINCS@
mailutils_imap_LDADD =\
${MU_APP_LIBRARIES}\
${MU_LIB_IMAP}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@\
$(MUTOOL_LIBRARIES_TAIL)
endif
mailutils_send_SOURCES = send.c
mailutils_send_CPPFLAGS = \
$(AM_CPPFLAGS)\
@MU_AUTHINCS@
mailutils_send_LDADD = \
${MU_APP_LIBRARIES}\
${MU_LIB_MAILER}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@\
$(MUTOOL_LIBRARIES_TAIL)
mailutils_stat_SOURCES = stat.c
mailutils_stat_LDADD = \
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
${MU_LIB_NNTP}\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@\
$(MUTOOL_LIBRARIES_TAIL)
mailutils_smtp_SOURCES = smtp.c
mailutils_smtp_CPPFLAGS = \
$(AM_CPPFLAGS)\
@MU_AUTHINCS@
mailutils_smtp_LDADD = \
${MU_APP_LIBRARIES}\
${MU_LIB_MAILER}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@\
$(MUTOOL_LIBRARIES_TAIL)
MUTOOL_LIBRARIES_TAIL = \
${MU_APP_LIBRARIES}\
./libmutool.a\
${MU_LIB_MAILUTILS}\
@READLINE_LIBS@\
@MU_COMMON_LIBRARIES@
LDADD = ${MU_APP_LIBRARIES} $(MUTOOL_LIBRARIES_TAIL)
AM_CPPFLAGS = \
@MU_APP_COMMON_INCLUDES@
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <mailutils/mailutils.h>
#include <mailutils/nls.h>
#include <sysexits.h>
#include "mu.h"
char acl_docstring[] = N_("test access control lists");
......@@ -41,7 +45,7 @@ static struct mu_cfg_param acl_cfg_param[] = {
};
int
mutool_acl (int argc, char **argv)
main (int argc, char **argv)
{
int rc;
mu_acl_result_t result;
......@@ -126,10 +130,3 @@ mutool_acl (int argc, char **argv)
return 0;
}
/*
MU Setup: acl
mu-handler: mutool_acl
mu-docstring: acl_docstring
End MU Setup:
*/
......
......@@ -14,12 +14,16 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <mailutils/mailutils.h>
#include <mailutils/nls.h>
#include <sysexits.h>
#include "mu.h"
char cflags_docstring[] = N_("show compiler options");
int
mutool_cflags (int argc, char **argv)
main (int argc, char **argv)
{
mu_action_getopt (&argc, &argv, NULL, cflags_docstring, NULL);
if (argc)
......@@ -31,10 +35,3 @@ mutool_cflags (int argc, char **argv)
return 0;
}
/*
MU Setup: cflags
mu-handler: mutool_cflags
mu-docstring: cflags_docstring
End MU Setup:
*/
......
......@@ -14,14 +14,17 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include "mu.h"
#include <config.h>
#include <mailutils/mailutils.h>
#include <mailutils/dbm.h>
#include <fnmatch.h>
#include <regex.h>
#include <sys/stat.h>
#include <grp.h>
#include <sysexits.h>
#include "mu.h"
static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
static char dbm_doc[] = N_("DBM management tool\n"
"Valid COMMANDs are:\n"
"\n"
" create or load - create the database\n"
......@@ -1765,7 +1768,7 @@ struct mu_kwd mode_tab[] =
};
int
mutool_dbm (int argc, char **argv)
main (int argc, char **argv)
{
int index;
......@@ -1852,12 +1855,3 @@ mutool_dbm (int argc, char **argv)
return 0;
}
/*
MU Setup: dbm
mu-handler: mutool_dbm
mu-docstring: dbm_docstring
mu-cond: ENABLE_DBM
End MU Setup:
*/
......
......@@ -92,7 +92,7 @@ negate_filter_mode (int mode)
}
int
mutool_filter (int argc, char **argv)
main (int argc, char **argv)
{
int rc;
mu_stream_t flt, prev_stream;
......@@ -173,10 +173,3 @@ mutool_filter (int argc, char **argv)
return 0;
}
/*
MU Setup: filter
mu-handler: mutool_filter
mu-docstring: filter_docstring
End MU Setup:
*/
......
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "mu.h"
char flt2047_docstring[] = N_("decode/encode email message headers");
......@@ -51,7 +55,7 @@ static struct mu_option flt2047_options[] = {
};
int
mutool_flt2047 (int argc, char **argv)
main (int argc, char **argv)
{
int rc;
char *p;
......@@ -103,10 +107,3 @@ mutool_flt2047 (int argc, char **argv)
return 0;
}
/*
MU Setup: 2047
mu-handler: mutool_flt2047
mu-docstring: flt2047_docstring
End MU Setup:
*/
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <mailutils/mailutils.h>
#include <mailutils/nls.h>
static void
describe (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
{
int len = strcspn (po->po_prog_doc, "\n");
mu_printf ("%.*s\n", len, po->po_prog_doc);
exit (0);
}
struct mu_option common_options[] = {
{ "describe", 0, NULL, MU_OPTION_HIDDEN,
"describe the program",
mu_c_string, NULL, describe },
MU_OPTION_END
};
void
mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
char const *docstring, char const *argdoc)
{
static struct mu_parseopt pohint = {
.po_flags = MU_PARSEOPT_PACKAGE_NAME
| MU_PARSEOPT_PACKAGE_URL
| MU_PARSEOPT_BUG_ADDRESS
| MU_PARSEOPT_VERSION_HOOK,
.po_package_name = PACKAGE_NAME,
.po_package_url = PACKAGE_URL,
.po_bug_address = PACKAGE_BUGREPORT,
.po_version_hook = mu_version_hook
};
static char *defcapa[] = { "debug", NULL };
struct mu_cfg_parse_hints cfhint = { .flags = 0 };
struct mu_option *options[3] = { common_options, opt, NULL };
struct mu_cli_setup cli = {
.prog_doc = (char*) docstring,
.prog_args = (char*) argdoc,
.optv = options
};
char *p;
p = getenv ("MAILUTILS_PROGNAME");
if (p)
{
pohint.po_flags |= MU_PARSEOPT_PROG_NAME;
pohint.po_prog_name = p;
}
MU_APP_INIT_NLS ();
mu_cli_ext (*pargc, *pargv, &cli, &pohint, &cfhint, defcapa, NULL,
pargc, pargv);
}
......@@ -1292,7 +1292,7 @@ struct mutool_command imap_comtab[] = {
};
int
mutool_imap (int argc, char **argv)
main (int argc, char **argv)
{
mu_action_getopt (&argc, &argv, NULL, imap_docstring, NULL);
......@@ -1308,11 +1308,3 @@ mutool_imap (int argc, char **argv)
mutool_shell ("imap", imap_comtab);
return 0;
}
/*
MU Setup: imap
mu-handler: mutool_imap
mu-docstring: imap_docstring
mu-cond: ENABLE_IMAP
End MU Setup:
*/
......
......@@ -14,12 +14,13 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "mu.h"
static char info_doc[] = N_("mu info - print a list of configuration\
options used to build mailutils; optional arguments are interpreted\
as a list of configuration options to check for.");
char info_docstring[] = N_("show Mailutils configuration");
static char info_doc[] = N_("show Mailutils configuration");
static char info_args_doc[] = N_("[capa...]");
static int verbose;
......@@ -32,7 +33,7 @@ static struct mu_option info_options[] = {
};
int
mutool_info (int argc, char **argv)
main (int argc, char **argv)
{
mu_action_getopt (&argc, &argv, info_options, info_doc, info_args_doc);
......@@ -55,10 +56,3 @@ mutool_info (int argc, char **argv)
}
return 0;
}
/*
MU Setup: info
mu-handler: mutool_info
mu-docstring: info_docstring
End MU Setup:
*/
......
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <mailutils/mailutils.h>
#include <mailutils/nls.h>
#include <sysexits.h>
#include "mu.h"
char ldflags_docstring[] = N_("list libraries required to link");
......@@ -121,7 +125,7 @@ sort_entries (void)
int
mutool_ldflags (int argc, char **argv)
main (int argc, char **argv)
{
int j;
......@@ -181,10 +185,3 @@ mutool_ldflags (int argc, char **argv)
mu_printf ("\n");
return 0;
}
/*
MU Setup: ldflags
mu-handler: mutool_ldflags
mu-docstring: ldflags_docstring
End MU Setup:
*/
......
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "mu.h"
char logger_docstring[] = N_("log data using Mailutils log facility");
......@@ -133,7 +137,7 @@ static struct mu_option logger_options[] = {
};
int
mutool_logger (int argc, char **argv)
main (int argc, char **argv)
{
mu_stream_t logger, input;
int rc, mode;
......@@ -202,13 +206,3 @@ mutool_logger (int argc, char **argv)
mu_stream_unref (logger);
return !!rc;
}
/*
MU Setup: logger
mu-handler: mutool_logger
mu-docstring: logger_docstring
End MU Setup:
*/
......
......@@ -18,18 +18,23 @@
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <sysexits.h>
#include <stdarg.h>
#include <mailutils/mailutils.h>
typedef int (*mutool_action_t) (int argc, char **argv);
void mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
char const *docstring, char const *argdoc);
int mu_vgetans (const char *variants, const char *fmt, va_list ap);
int mu_getans (const char *variants, const char *fmt, ...);
int get_bool (const char *str, int *pb);
int get_port (const char *port_str, int *pn);
int mu_vgetyn (const char *fmt, va_list ap);
int mu_getyn (const char *fmt, ...);
int port_from_sa (struct mu_sockaddr *sa);
#define CMD_COALESCE_EXTRA_ARGS 0x01
typedef int (*mutool_action_t) (int argc, char **argv);
struct mutool_command
{
const char *name; /* User printable name of the function. */
......@@ -48,12 +53,6 @@ mu_assoc_t mutool_shell_prompt_assoc (void);
int mutool_shell (const char *name, struct mutool_command *cmd);
mu_stream_t mutool_open_pager (void);
int mu_help (void);
mutool_action_t dispatch_find_action (const char *name);
void subcommand_help (mu_stream_t str);
int port_from_sa (struct mu_sockaddr *sa);
#define VERBOSE_MASK(n) (1<<((n)+1))
#define SET_VERBOSE_MASK(n) (shell_verbose_flags |= VERBOSE_MASK (n))
......@@ -68,12 +67,4 @@ extern int shell_verbose_flags;
int shell_verbose (int argc, char **argv,
void (*set_verbose) (void), void (*set_mask) (void));
int get_bool (const char *str, int *pb);
int get_port (const char *port_str, int *pn);
int mu_getans (const char *variants, const char *fmt, ...);
void mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
char const *docstring, char const *argdoc);
......
......@@ -597,8 +597,12 @@ struct mutool_command pop_comtab[] = {
int
mutool_pop (int argc, char **argv)
main (int argc, char **argv)
{
mu_registrar_record (mu_pop_record);
mu_registrar_record (mu_pops_record);
mu_action_getopt (&argc, &argv, NULL, pop_docstring, NULL);
if (argc)
......@@ -613,11 +617,3 @@ mutool_pop (int argc, char **argv)
mutool_shell ("pop", pop_comtab);
return 0;
}
/*
MU Setup: pop
mu-handler: mutool_pop
mu-docstring: pop_docstring
mu-cond: ENABLE_POP
End MU Setup:
*/
......
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "mu.h"
char query_docstring[] = N_("query configuration values");
......@@ -45,7 +49,7 @@ static struct mu_option query_options[] = {
};
int
mutool_query (int argc, char **argv)
main (int argc, char **argv)
{
static struct mu_cfg_parse_hints hints;
mu_cfg_tree_t *tree = NULL;
......@@ -89,12 +93,3 @@ mutool_query (int argc, char **argv)
}
return 0;
}
/*
MU Setup: query
mu-handler: mutool_query
mu-docstring: query_docstring
End MU Setup:
*/
......
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "mu.h"
static int read_recipients;
......@@ -68,7 +72,7 @@ static struct mu_option send_options[] = {
};
int
mutool_send (int argc, char **argv)
main (int argc, char **argv)
{
char *infile;
mu_stream_t instr;
......@@ -76,7 +80,9 @@ mutool_send (int argc, char **argv)
size_t count;
mu_url_t urlhint, url;
mu_mailer_t mailer;
MU_AUTH_REGISTER_ALL_MODULES ();
MU_ASSERT (mu_address_create_null (&rcpt_addr));
mu_register_all_mailer_formats ();
......
......@@ -908,7 +908,7 @@ struct mutool_command smtp_comtab[] = {
};
int
mutool_smtp (int argc, char **argv)
main (int argc, char **argv)
{
mu_registrar_record (mu_smtp_record);
mu_registrar_record (mu_smtps_record);
......@@ -929,10 +929,3 @@ mutool_smtp (int argc, char **argv)
return 0;
}
/*
MU Setup: smtp
mu-handler: mutool_smtp
mu-docstring: smtp_docstring
End MU Setup:
*/
......
......@@ -14,6 +14,11 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include <sysexits.h>
#include "mu.h"
char stat_docstring[] = N_("display mailbox status");
......@@ -235,7 +240,7 @@ format_stat (char const *fmt, mu_mailbox_t mbx, const char *name)
}
int
mutool_stat (int argc, char **argv)
main (int argc, char **argv)
{
int rc;
mu_mailbox_t mbox;
......@@ -363,20 +368,3 @@ get_name (mu_mailbox_t mbox, char const *mbname, mu_c_storage_t *cstor)
cstor->c_string = mu_strdup (mbname);
return 0;
}
/*
MU Setup: stat
mu-handler: mutool_stat
mu-docstring: stat_docstring
End MU Setup:
*/
......
......@@ -14,6 +14,10 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "mu.h"
char wicket_docstring[] = N_("scan wickets for matching URLs");
......@@ -97,7 +101,7 @@ wicket_match (mu_stream_t stream, const char *str)
}
int
mutool_wicket (int argc, char **argv)
main (int argc, char **argv)
{
mu_stream_t stream;
int rc, i, exit_code;
......@@ -142,11 +146,3 @@ mutool_wicket (int argc, char **argv)
mu_stream_destroy (&stream);
return exit_code;
}
/*
MU Setup: wicket
mu-handler: mutool_wicket
mu-docstring: wicket_docstring
End MU Setup:
*/
......
# This file is part of GNU Mailutils.
# Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
state == 0 && /MU Setup:/ {
if (NF != 3) {
print FILENAME ":" NR ":", "missing module name" > "/dev/stderr"
exit(1)
} else {
state = 1;
module_name=$3;
if (modules[module_name]) {
print FILENAME ":" NR ":", "this module already declared" > "/dev/stderr"
print modules[module_name] ":", "location of the prior declaration" > "/dev/stderr"
} else
modules[module_name] = (FILENAME":"NR);
}
}
state == 1 && /mu-.*:/ {
setup[module_name,substr($1,4,length($1)-4)] = $2;
next
}
state == 1 && /End MU Setup/ { state = 0 }
END {
print "/* -*- buffer-read-only: t -*- vi: set ro:"
print " THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT."
print "*/"
vartab[1] = "handler"
vartab[2] = "docstring"
n = asorti(modules,modname)
for (i = 1; i <= n; i++) {
name = modname[i]
for (j in vartab) {
if (!setup[name,vartab[j]]) {
print modules[name] ":", "mu-" vartab[j], "not defined"
err = 1
}
}
if (err)
continue
if (mode == "h") {
print "extern int", setup[name,"handler"], "(int argc, char **argv);"
print "extern char " setup[name,"docstring"] "[];"
} else {
if (setup[name,"cond"])
print "#ifdef", setup[name,"cond"]
print "{", "\"" name "\",", setup[name,"handler"] ",", setup[name,"docstring"], "},"
if (setup[name,"cond"])
print "#endif"
}
}
}
......@@ -19,10 +19,117 @@
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <mailutils/mailutils.h>
#include <mailutils/tls.h>
#include "mailutils/cli.h"
#include "mu.h"
#include <assert.h>
#include <glob.h>
char *mailutilsdir;
struct mu_tool
{
char *name;
char cmd[1];
};
#define MUTOOL_PREFIX "mailutils-"
mu_list_t
find_tools (char *pat)
{
mu_list_t tool_list;
char *fpat, *pattern;
glob_t gbuf;
mu_list_create (&tool_list);
mu_list_set_destroy_item (tool_list, mu_list_free_item);
fpat = mu_alloc (sizeof MUTOOL_PREFIX + strlen (pat));
strcat (strcpy (fpat, MUTOOL_PREFIX), pat);
pattern = mu_make_file_name (mailutilsdir, fpat);
free (fpat);
if (glob (pattern, 0, NULL, &gbuf) == 0)
{
int i;
for (i = 0; i < gbuf.gl_pathc; i++)
{
char *p;
struct mu_tool *tp = mu_alloc (sizeof (*tp) + strlen (gbuf.gl_pathv[i]));
strcpy (tp->cmd, gbuf.gl_pathv[i]);
p = strrchr (tp->cmd, '/');
assert (p != NULL);
tp->name = p + sizeof MUTOOL_PREFIX;
mu_list_push (tool_list, tp);
}
globfree (&gbuf);
}
return tool_list;
}
static int
mutool_comp (const void *a, const void *b)
{
struct mu_tool const *pa = a;
struct mu_tool const *pb = b;
return strcmp (pa->name, pb->name);
}
static int
show_help (void *item, void *data)
{
struct mu_tool *t = item;
mu_stream_t ostr = data;
mu_stream_t istr;
char *argv[3];
int rc;
argv[0] = t->cmd;
argv[1] = "--describe";
argv[2] = NULL;
rc = mu_prog_stream_create (&istr, t->cmd,
2, argv,
0, NULL, MU_STREAM_READ);
if (rc == 0)
{
unsigned margin;
margin = 2;
mu_stream_ioctl (ostr, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (ostr, "%s %s", mu_program_name, t->name);
margin = 29;
mu_stream_ioctl (ostr, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
rc = mu_stream_copy (ostr, istr, 0, NULL);
if (rc)
mu_diag_funcall (MU_DIAG_ERR, "mu_stream_copy", t->cmd, rc);
mu_stream_destroy (&istr);
}
return 0;
}
void
subcommand_help (mu_stream_t str)
{
mu_list_t tool_list = find_tools ("*");
if (mu_list_is_empty (tool_list))
{
mu_stream_printf (str, _("No commands found.\n"));
}
else
{
mu_list_sort (tool_list, mutool_comp);
mu_list_foreach (tool_list, show_help, str);
mu_list_destroy (&tool_list);
}
}
struct mu_cli_setup cli = {
.prog_doc = N_("GNU Mailutils multi-purpose tool."),
......@@ -31,108 +138,122 @@ struct mu_cli_setup cli = {
.prog_doc_hook = subcommand_help
};
static char *capa[] = {
"debug",
"locking",
"mailbox",
"auth",
NULL
struct mu_parseopt pohint = {
.po_flags = MU_PARSEOPT_PACKAGE_NAME
| MU_PARSEOPT_PACKAGE_URL
| MU_PARSEOPT_BUG_ADDRESS
| MU_PARSEOPT_EXTRA_INFO
| MU_PARSEOPT_VERSION_HOOK,
.po_package_name = PACKAGE_NAME,
.po_package_url = PACKAGE_URL,
.po_bug_address = PACKAGE_BUGREPORT,
.po_extra_info = mu_general_help_text,
.po_version_hook = mu_version_hook,
};
struct mu_cfg_parse_hints cfhint = { .flags = 0 };
int
main (int argc, char **argv)
{
mutool_action_t action;
static struct mu_parseopt pohint = {
.po_flags = MU_PARSEOPT_PACKAGE_NAME
| MU_PARSEOPT_PACKAGE_URL
| MU_PARSEOPT_BUG_ADDRESS
| MU_PARSEOPT_EXTRA_INFO
| MU_PARSEOPT_VERSION_HOOK,
.po_package_name = PACKAGE_NAME,
.po_package_url = PACKAGE_URL,
.po_bug_address = PACKAGE_BUGREPORT,
.po_extra_info = mu_general_help_text,
.po_version_hook = mu_version_hook,
};
struct mu_cfg_parse_hints cfhint = { .flags = 0 };
size_t len;
mu_list_t tool_list;
size_t cnt;
struct mu_tool *tp;
int rc;
char *str;
#define DEVSFX "/.libs/lt-mailutils"
#define DEVSFX_LEN (sizeof (DEVSFX) - 1)
#define SUBDIR "libexec"
#define SUBDIR_LEN (sizeof (SUBDIR) - 1)
len = strlen (argv[0]);
if (len > DEVSFX_LEN
&& strcmp (argv[0] + len - DEVSFX_LEN, DEVSFX) == 0)
{
len -= DEVSFX_LEN;
mailutilsdir = mu_alloc (len + 1 + SUBDIR_LEN + 1);
memcpy (mailutilsdir, argv[0], len);
mailutilsdir[len++] = '/';
strcpy (mailutilsdir + len, SUBDIR);
}
else
mailutilsdir = MAILUTILSDIR;
/* Native Language Support */
MU_APP_INIT_NLS ();
MU_AUTH_REGISTER_ALL_MODULES ();
/* Register the desired mailbox formats. */
mu_register_all_mbox_formats ();
mu_cli_ext (argc, argv, &cli, &pohint, &cfhint, capa, NULL, &argc, &argv);
mu_cli_ext (argc, argv, &cli, &pohint, &cfhint, NULL, NULL, &argc, &argv);
if (argc < 1)
{
mu_error (_("what do you want me to do?"));
exit (1);
}
action = dispatch_find_action (argv[0]);
if (!action)
if (strcmp (argv[0], "help") == 0)
{
mu_error (_("don't know what %s is"), argv[0]);
exit (1);
}
cli.prog_doc_hook = NULL;
cli.prog_doc = N_("display help on mailutils subcommands");
cli.prog_args = N_("[COMMAND]");
pohint.po_flags |= MU_PARSEOPT_PROG_NAME;
mu_asprintf (&str, "%s %s", mu_program_name, argv[0]);
pohint.po_prog_name = str;
mu_cli_ext (argc, argv, &cli, &pohint, &cfhint,
NULL, NULL, &argc, &argv);
/* Run the action. */
exit (action (argc, argv));
}
int
mu_help (void)
{
char *argv[3];
argv[0] = mu_full_program_name;
argv[1] = "--help";
argv[2] = NULL;
mu_cli (2, argv, &cli, capa, NULL, NULL, NULL);
return 0;
}
void
mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
char const *docstring, char const *argdoc)
{
struct mu_parseopt po;
int flags = MU_PARSEOPT_IMMEDIATE;
struct mu_option *options[2];
char const *prog_args[2];
char *progname;
options[0] = opt;
options[1] = NULL;
if (argc == 0)
{
mu_stream_t str;
unsigned margin;
if (mu_parseopt_help_stream_create (&str, &pohint, mu_strout))
abort ();
subcommand_help (str);
mu_asprintf (&progname, "%s %s", mu_program_name, (*pargv)[0]);
po.po_prog_name = progname;
flags |= MU_PARSEOPT_PROG_NAME;
po.po_prog_doc = docstring;
flags |= MU_PARSEOPT_PROG_DOC;
margin = 0;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
if (argdoc)
{
prog_args[0] = argdoc;
prog_args[1] = NULL;
po.po_prog_args = prog_args;
flags |= MU_PARSEOPT_PROG_ARGS;
mu_stream_printf (str, "\n");
mu_stream_printf (str,
_("Run `%s help COMMAND' to get help on a particular mailutils command."),
mu_program_name);
mu_stream_destroy (&str);
exit (0);
}
else if (argc == 1)
{
argv--;
argv[0] = argv[1];
argv[1] = "--help";
argv[2] = NULL;
}
else
{
mu_error (_("too many arguments"));
exit (1);
}
}
po.po_bug_address = PACKAGE_BUGREPORT;
flags |= MU_PARSEOPT_BUG_ADDRESS;
if (mu_parseopt (&po, *pargc, *pargv, options, flags))
exit (po.po_exit_error);
tool_list = find_tools (argv[0]);
mu_list_count (tool_list, &cnt);
if (cnt != 1)
{
mu_error (_("don't know what %s is"), argv[0]);
exit (1);
}
rc = mu_list_head (tool_list, (void**) &tp);
if (rc)
{
mu_diag_funcall (MU_DIAG_CRIT, "mu_list_head", NULL, rc);
exit (2);
}
*pargc -= po.po_arg_start;
*pargv += po.po_arg_start;
mu_parseopt_free (&po);
mu_asprintf (&str, "%s %s", mu_program_name, tp->name);
setenv ("MAILUTILS_PROGNAME", str, 1);
execv (tp->cmd, argv);
mu_diag_funcall (MU_DIAG_CRIT, "execv", tp->cmd, errno);
return 2;
}
......
......@@ -196,20 +196,19 @@ sieve/sieve.c
sql/mysql.c
mu/acl.c
mu/dispatch.c
mu/filter.c
mu/flt2047.c
mu/help.c
mu/info.c
mu/mu.c
mu/pop.c
mu/query.c
mu/shell.c
mu/cflags.c
mu/ldflags.c
mu/wicket.c
mu/logger.c
mu/libexec/acl.c
mu/libexec/filter.c
mu/libexec/flt2047.c
mu/libexec/info.c
mu/libexec/pop.c
mu/libexec/query.c
mu/libexec/shell.c
mu/libexec/cflags.c
mu/libexec/ldflags.c
mu/libexec/wicket.c
mu/libexec/logger.c
mu/libexec/stat.c
# EOF
......