2009-11-28 13:06:21 +01:00
|
|
|
/*
|
2020-01-01 14:43:10 +01:00
|
|
|
** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2009-11-28 13:06:21 +01:00
|
|
|
**
|
|
|
|
** This program 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.
|
|
|
|
**
|
|
|
|
** This program 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 this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-01-08 19:54:55 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-11-28 13:06:21 +01:00
|
|
|
#include <glib.h>
|
2010-12-07 22:17:05 +01:00
|
|
|
#include <string.h> /* memset */
|
2011-05-26 22:35:34 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
2009-11-29 23:04:16 +01:00
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
#include "mu-config.hh"
|
|
|
|
#include "mu-cmd.hh"
|
2009-11-28 13:06:21 +01:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
using namespace Mu;
|
2020-02-08 13:27:52 +01:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
static MuConfig MU_CONFIG;
|
|
|
|
|
2020-02-08 13:27:52 +01:00
|
|
|
#define color_maybe(C) (MU_CONFIG.nocolor ? "" : (C))
|
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
static MuConfigFormat
|
|
|
|
get_output_format (const char *formatstr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct {
|
|
|
|
const char* name;
|
|
|
|
MuConfigFormat format;
|
|
|
|
} formats [] = {
|
|
|
|
{"mutt-alias", MU_CONFIG_FORMAT_MUTT_ALIAS},
|
|
|
|
{"mutt-ab", MU_CONFIG_FORMAT_MUTT_AB},
|
|
|
|
{"wl", MU_CONFIG_FORMAT_WL},
|
|
|
|
{"csv", MU_CONFIG_FORMAT_CSV},
|
|
|
|
{"org-contact", MU_CONFIG_FORMAT_ORG_CONTACT},
|
|
|
|
{"bbdb", MU_CONFIG_FORMAT_BBDB},
|
|
|
|
{"links", MU_CONFIG_FORMAT_LINKS},
|
|
|
|
{"plain", MU_CONFIG_FORMAT_PLAIN},
|
|
|
|
{"sexp", MU_CONFIG_FORMAT_SEXP},
|
2018-11-11 11:16:49 +01:00
|
|
|
{"json", MU_CONFIG_FORMAT_JSON},
|
2011-07-27 07:20:06 +02:00
|
|
|
{"xml", MU_CONFIG_FORMAT_XML},
|
2017-10-24 21:58:32 +02:00
|
|
|
{"xquery", MU_CONFIG_FORMAT_XQUERY},
|
2019-04-28 12:58:34 +02:00
|
|
|
{"mquery", MU_CONFIG_FORMAT_MQUERY},
|
|
|
|
{"debug", MU_CONFIG_FORMAT_DEBUG}
|
2011-07-27 07:20:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(formats); i++)
|
|
|
|
if (strcmp (formats[i].name, formatstr) == 0)
|
|
|
|
return formats[i].format;
|
|
|
|
|
|
|
|
return MU_CONFIG_FORMAT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
#define expand_dir(D) \
|
|
|
|
if ((D)) { \
|
|
|
|
char *exp; \
|
|
|
|
exp = mu_util_dir_expand((D)); \
|
|
|
|
if (exp) { \
|
|
|
|
g_free((D)); \
|
|
|
|
(D) = exp; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static void
|
2021-02-15 17:40:54 +01:00
|
|
|
set_group_mu_defaults ()
|
2010-08-14 14:29:46 +02:00
|
|
|
{
|
2019-07-12 16:36:08 +02:00
|
|
|
/* If muhome is not set, we use the XDG Base Directory Specification
|
|
|
|
* locations. */
|
2020-02-06 19:22:43 +01:00
|
|
|
if (MU_CONFIG.muhome)
|
|
|
|
expand_dir(MU_CONFIG.muhome);
|
2009-11-28 13:06:21 +01:00
|
|
|
|
2019-01-22 18:08:24 +01:00
|
|
|
/* check for the MU_NOCOLOR or NO_COLOR env vars; but in any case don't
|
2014-02-15 11:09:07 +01:00
|
|
|
* use colors unless we're writing to a tty */
|
2019-01-28 16:50:47 +01:00
|
|
|
if (g_getenv (MU_NOCOLOR) != NULL || g_getenv ("NO_COLOR") != NULL)
|
2014-02-15 11:09:07 +01:00
|
|
|
MU_CONFIG.nocolor = TRUE;
|
|
|
|
|
|
|
|
if (!isatty(fileno(stdout)) || !isatty(fileno(stderr)))
|
2014-01-30 18:05:59 +01:00
|
|
|
MU_CONFIG.nocolor = TRUE;
|
2014-01-23 17:26:05 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_mu ()
|
2010-12-07 22:17:05 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"debug", 'd', 0, G_OPTION_ARG_NONE, &MU_CONFIG.debug,
|
2011-05-22 09:40:12 +02:00
|
|
|
"print debug output to standard error (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &MU_CONFIG.quiet,
|
2011-05-22 09:40:12 +02:00
|
|
|
"don't give any progress information (false)", NULL},
|
2021-02-13 12:33:12 +01:00
|
|
|
{"version", 'V', 0, G_OPTION_ARG_NONE, &MU_CONFIG.version,
|
2011-05-22 09:40:12 +02:00
|
|
|
"display version and copyright information (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"muhome", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.muhome,
|
2012-09-17 17:39:28 +02:00
|
|
|
"specify an alternative mu directory", "<dir>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"log-stderr", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.log_stderr,
|
2011-05-22 09:40:12 +02:00
|
|
|
"log to standard error (false)", NULL},
|
2014-02-15 11:09:07 +01:00
|
|
|
{"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor,
|
|
|
|
"don't use ANSI-colors in output (false)", NULL},
|
2012-07-17 18:17:49 +02:00
|
|
|
{"verbose", 'v', 0, G_OPTION_ARG_NONE, &MU_CONFIG.verbose,
|
|
|
|
"verbose output (false)", NULL},
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
|
2012-03-13 22:06:17 +01:00
|
|
|
&MU_CONFIG.params, "parameters", NULL},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, (GOptionArg)0, NULL, NULL, NULL}
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
og = g_option_group_new("mu", "general mu options", "", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
2010-12-07 22:17:05 +01:00
|
|
|
}
|
2009-11-28 13:06:21 +01:00
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static void
|
2021-02-15 17:40:54 +01:00
|
|
|
set_group_init_defaults ()
|
2010-08-14 14:29:46 +02:00
|
|
|
{
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.maildir)
|
2020-02-06 19:22:43 +01:00
|
|
|
MU_CONFIG.maildir = mu_util_guess_maildir();
|
2011-11-20 00:26:32 +01:00
|
|
|
|
2012-09-16 12:15:44 +02:00
|
|
|
expand_dir (MU_CONFIG.maildir);
|
2010-08-14 14:29:46 +02:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_init ()
|
2009-11-28 13:06:21 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.maildir,
|
2012-09-17 17:39:28 +02:00
|
|
|
"top of the maildir", "<maildir>"},
|
2020-02-06 19:22:43 +01:00
|
|
|
{"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY,
|
|
|
|
&MU_CONFIG.my_addresses, "my e-mail address; can be used multiple times",
|
|
|
|
"<address>"},
|
2020-06-27 10:36:34 +02:00
|
|
|
{"max-message-size", 0, 0, G_OPTION_ARG_INT,
|
|
|
|
&MU_CONFIG.max_msg_size, "Maximum allowed size for messages",
|
|
|
|
"<size-in-bytes>"},
|
|
|
|
{"batch-size", 0, 0, G_OPTION_ARG_INT,
|
2021-06-01 09:13:50 +02:00
|
|
|
&MU_CONFIG.batch_size,
|
2020-06-27 10:36:34 +02:00
|
|
|
"Number of changes in a database transaction batch",
|
|
|
|
"<number>"},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2020-02-06 19:22:43 +01:00
|
|
|
};
|
|
|
|
|
2020-06-27 10:36:34 +02:00
|
|
|
og = g_option_group_new("init", "Options for the 'init' command",
|
2020-02-06 19:22:43 +01:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
2020-02-08 13:27:52 +01:00
|
|
|
static gboolean
|
|
|
|
index_post_parse_func (GOptionContext *context, GOptionGroup *group,
|
|
|
|
gpointer data, GError **error)
|
|
|
|
{
|
|
|
|
if (!MU_CONFIG.maildir && !MU_CONFIG.my_addresses)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
g_printerr ("%sNOTE%s: as of mu 1.3.8, 'mu index' no longer uses the\n"
|
|
|
|
"--maildir/-m or --my-address options.\n\n",
|
|
|
|
color_maybe(MU_COLOR_RED), color_maybe(MU_COLOR_DEFAULT));
|
|
|
|
g_printerr ("Instead, these options should be passed to 'mu init'.\n");
|
|
|
|
g_printerr ("See the mu-init(1) or the mu4e reference manual,\n'Initializing the message store' for details.\n\n");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_index ()
|
2020-02-06 19:22:43 +01:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2020-02-08 13:27:52 +01:00
|
|
|
/* only here so we can tell users they are deprecated */
|
|
|
|
{"maildir", 'm', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
|
|
|
|
&MU_CONFIG.maildir, "top of the maildir", "<maildir>"},
|
|
|
|
{"my-address", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY,
|
|
|
|
&MU_CONFIG.my_addresses, "my e-mail address; can be used multiple times",
|
|
|
|
"<address>"},
|
|
|
|
|
2016-07-23 18:18:09 +02:00
|
|
|
{"lazy-check", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.lazycheck,
|
|
|
|
"only check dir-timestamps (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"nocleanup", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocleanup,
|
2011-05-22 09:40:12 +02:00
|
|
|
"don't clean up the database after indexing (false)", NULL},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
|
|
|
|
2020-02-08 13:27:52 +01:00
|
|
|
og = g_option_group_new("index", "Options for the 'index' command",
|
2011-05-22 09:40:12 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
2020-02-08 13:27:52 +01:00
|
|
|
g_option_group_set_parse_hooks(og, NULL, (GOptionParseFunc)index_post_parse_func);
|
2011-05-22 09:40:12 +02:00
|
|
|
|
|
|
|
return og;
|
2009-11-28 13:06:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static void
|
2021-02-15 17:40:54 +01:00
|
|
|
set_group_find_defaults ()
|
2010-08-14 14:29:46 +02:00
|
|
|
{
|
2021-02-15 17:40:54 +01:00
|
|
|
/* note, when no fields are specified, we use date-from-subject */
|
2013-12-21 19:24:15 +01:00
|
|
|
if (!MU_CONFIG.fields || !*MU_CONFIG.fields) {
|
2013-12-29 16:37:07 +01:00
|
|
|
MU_CONFIG.fields = g_strdup ("d f s");
|
2021-02-15 17:40:54 +01:00
|
|
|
if (!MU_CONFIG.sortfield) {
|
2013-12-29 16:37:07 +01:00
|
|
|
MU_CONFIG.sortfield = g_strdup ("d");
|
2021-02-15 17:40:54 +01:00
|
|
|
}
|
2011-05-22 09:40:12 +02:00
|
|
|
}
|
2010-08-14 14:29:46 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.formatstr) /* by default, use plain output */
|
|
|
|
MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN;
|
2011-07-27 07:20:06 +02:00
|
|
|
else
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.format =
|
|
|
|
get_output_format (MU_CONFIG.formatstr);
|
2012-09-16 12:15:44 +02:00
|
|
|
|
|
|
|
expand_dir (MU_CONFIG.linksdir);
|
2009-11-28 13:06:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_find ()
|
2009-11-28 13:06:21 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"fields", 'f', 0, G_OPTION_ARG_STRING, &MU_CONFIG.fields,
|
2012-09-17 17:39:28 +02:00
|
|
|
"fields to display in the output", "<fields>"},
|
2012-09-19 09:44:16 +02:00
|
|
|
{"sortfield", 's', 0, G_OPTION_ARG_STRING,
|
|
|
|
&MU_CONFIG.sortfield,
|
2012-09-17 17:39:28 +02:00
|
|
|
"field to sort on", "<field>"},
|
2013-09-27 16:11:04 +02:00
|
|
|
{"maxnum", 'n', 0, G_OPTION_ARG_INT, &MU_CONFIG.maxnum,
|
|
|
|
"number of entries to display in the output", "<number>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"threads", 't', 0, G_OPTION_ARG_NONE, &MU_CONFIG.threads,
|
2011-06-19 20:03:33 +02:00
|
|
|
"show message threads", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"bookmark", 'b', 0, G_OPTION_ARG_STRING, &MU_CONFIG.bookmark,
|
2012-09-17 17:39:28 +02:00
|
|
|
"use a bookmarked query", "<bookmark>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"reverse", 'z', 0, G_OPTION_ARG_NONE, &MU_CONFIG.reverse,
|
2011-09-22 20:00:52 +02:00
|
|
|
"sort in reverse (descending) order (z -> a)", NULL},
|
2019-12-28 06:48:06 +01:00
|
|
|
{"skip-dups", 'u', 0, G_OPTION_ARG_NONE,
|
|
|
|
&MU_CONFIG.skip_dups,
|
2012-12-22 20:12:52 +01:00
|
|
|
"show only the first of messages duplicates (false)", NULL},
|
2019-12-28 06:48:06 +01:00
|
|
|
{"include-related", 'r', 0, G_OPTION_ARG_NONE,
|
|
|
|
&MU_CONFIG.include_related,
|
|
|
|
"include related messages in results (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir,
|
2012-09-17 17:39:28 +02:00
|
|
|
"output as symbolic links to a target maildir", "<dir>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"clearlinks", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.clearlinks,
|
2011-05-22 09:40:12 +02:00
|
|
|
"clear old links before filling a linksdir (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
|
2011-05-22 09:40:12 +02:00
|
|
|
"output format ('plain'(*), 'links', 'xml',"
|
2012-09-17 17:39:28 +02:00
|
|
|
"'sexp', 'xquery')", "<format>"},
|
2013-08-24 10:20:26 +02:00
|
|
|
{"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
|
|
|
|
"use up to <n> lines for the summary, or 0 for none (0)",
|
|
|
|
"<len>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"exec", 'e', 0, G_OPTION_ARG_STRING, &MU_CONFIG.exec,
|
2012-09-17 17:39:28 +02:00
|
|
|
"execute command on each match message", "<command>"},
|
2012-07-12 14:53:36 +02:00
|
|
|
{"after", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.after,
|
2012-09-19 09:44:16 +02:00
|
|
|
"only show messages whose m_time > T (t_time)",
|
|
|
|
"<timestamp>"},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
og = g_option_group_new("find",
|
2012-08-01 16:05:24 +02:00
|
|
|
"Options for the 'find' command",
|
2011-05-22 09:40:12 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
2010-01-02 13:44:26 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup *
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_mkdir ()
|
2010-12-07 22:17:05 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"mode", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.dirmode,
|
2012-09-17 17:39:28 +02:00
|
|
|
"set the mode (as in chmod), in octal notation", "<mode>"},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
2010-12-07 22:17:05 +01:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
/* set dirmode before, because '0000' is a valid mode */
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.dirmode = 0755;
|
2010-12-07 22:17:05 +01:00
|
|
|
|
2012-08-01 16:05:24 +02:00
|
|
|
og = g_option_group_new("mkdir", "Options for the 'mkdir' command",
|
2011-05-22 09:40:12 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
2010-12-07 22:17:05 +01:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
return og;
|
2010-12-07 22:17:05 +01:00
|
|
|
}
|
2010-01-21 19:05:19 +01:00
|
|
|
|
2011-03-04 23:59:35 +01:00
|
|
|
static void
|
2021-02-15 17:40:54 +01:00
|
|
|
set_group_cfind_defaults ()
|
2011-03-04 23:59:35 +01:00
|
|
|
{
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.formatstr) /* by default, use plain output */
|
|
|
|
MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN;
|
2011-07-27 07:20:06 +02:00
|
|
|
else
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.format = get_output_format (MU_CONFIG.formatstr);
|
2011-03-04 23:59:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static GOptionGroup *
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_cfind ()
|
2011-03-04 23:59:35 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
|
2013-05-05 11:18:08 +02:00
|
|
|
"output format (plain(*), mutt-alias, mutt-ab, wl, "
|
|
|
|
"org-contact, bbdb, csv)", "<format>"},
|
2012-06-20 08:20:15 +02:00
|
|
|
{"personal", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.personal,
|
|
|
|
"whether to only get 'personal' contacts", NULL},
|
|
|
|
{"after", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.after,
|
2012-09-17 17:39:28 +02:00
|
|
|
"only get addresses last seen after T", "<timestamp>"},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-08-01 16:05:24 +02:00
|
|
|
og = g_option_group_new("cfind", "Options for the 'cfind' command",
|
2011-05-22 09:40:12 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
2011-03-04 23:59:35 +01:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
return og;
|
2011-03-04 23:59:35 +01:00
|
|
|
}
|
|
|
|
|
2012-10-18 23:51:04 +02:00
|
|
|
static GOptionGroup *
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_script ()
|
2012-10-18 23:51:04 +02:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2013-06-09 11:11:01 +02:00
|
|
|
{G_OPTION_REMAINING, 0,0, G_OPTION_ARG_STRING_ARRAY,
|
|
|
|
&MU_CONFIG.params, "script parameters", NULL},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2012-10-18 23:51:04 +02:00
|
|
|
};
|
|
|
|
|
2012-10-22 22:16:01 +02:00
|
|
|
og = g_option_group_new("script", "Options for the 'script' command",
|
2012-10-18 23:51:04 +02:00
|
|
|
"", NULL, NULL);
|
2013-06-09 11:11:01 +02:00
|
|
|
|
2012-10-18 23:51:04 +02:00
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
static void
|
2021-02-15 17:40:54 +01:00
|
|
|
set_group_view_defaults ()
|
2011-07-27 07:20:06 +02:00
|
|
|
{
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.formatstr) /* by default, use plain output */
|
|
|
|
MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN;
|
2011-07-27 07:20:06 +02:00
|
|
|
else
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.format = get_output_format (MU_CONFIG.formatstr);
|
2011-07-27 07:20:06 +02:00
|
|
|
}
|
|
|
|
|
2012-08-01 16:05:24 +02:00
|
|
|
|
|
|
|
/* crypto options are used in a few different commands */
|
|
|
|
static GOptionEntry*
|
2021-02-15 17:40:54 +01:00
|
|
|
crypto_option_entries ()
|
2012-08-01 16:05:24 +02:00
|
|
|
{
|
|
|
|
static GOptionEntry entries[] = {
|
|
|
|
{"auto-retrieve", 'r', 0, G_OPTION_ARG_NONE,
|
|
|
|
&MU_CONFIG.auto_retrieve,
|
|
|
|
"attempt to retrieve keys online (false)", NULL},
|
|
|
|
{"use-agent", 'a', 0, G_OPTION_ARG_NONE, &MU_CONFIG.use_agent,
|
|
|
|
"attempt to use the GPG agent (false)", NULL},
|
|
|
|
{"decrypt", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.decrypt,
|
|
|
|
"attempt to decrypt the message", NULL},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2012-08-01 16:05:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2011-05-25 21:01:05 +02:00
|
|
|
static GOptionGroup *
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_view ()
|
2011-05-25 21:01:05 +02:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-09-17 17:26:03 +02:00
|
|
|
{"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
|
2012-09-17 17:39:28 +02:00
|
|
|
"use up to <n> lines for the summary, or 0 for none (0)",
|
|
|
|
"<len>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"terminate", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.terminator,
|
2012-09-17 17:39:28 +02:00
|
|
|
"terminate messages with ascii-0x07 (\\f, form-feed)",
|
|
|
|
"<term>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
|
2012-09-17 17:39:28 +02:00
|
|
|
"output format ('plain'(*), 'sexp')", "<format>"},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-05-25 21:01:05 +02:00
|
|
|
};
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-08-01 16:05:24 +02:00
|
|
|
og = g_option_group_new("view", "Options for the 'view' command",
|
2011-05-25 21:01:05 +02:00
|
|
|
"", NULL, NULL);
|
2012-08-01 16:05:24 +02:00
|
|
|
|
2011-05-25 21:01:05 +02:00
|
|
|
g_option_group_add_entries(og, entries);
|
2012-08-01 16:05:24 +02:00
|
|
|
g_option_group_add_entries(og, crypto_option_entries());
|
2011-05-25 21:01:05 +02:00
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
2012-09-16 12:15:44 +02:00
|
|
|
static void
|
2021-02-15 17:40:54 +01:00
|
|
|
set_group_extract_defaults ()
|
2012-09-16 12:15:44 +02:00
|
|
|
{
|
2013-04-16 23:07:53 +02:00
|
|
|
if (!MU_CONFIG.targetdir)
|
|
|
|
MU_CONFIG.targetdir = g_strdup (".");
|
|
|
|
|
2012-09-16 12:15:44 +02:00
|
|
|
expand_dir (MU_CONFIG.targetdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_extract ()
|
2010-08-29 15:30:55 +02:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
|
|
|
{"save-attachments", 'a', 0, G_OPTION_ARG_NONE,
|
2012-03-13 22:06:17 +01:00
|
|
|
&MU_CONFIG.save_attachments,
|
2011-05-22 09:40:12 +02:00
|
|
|
"save all attachments (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"save-all", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.save_all,
|
2011-05-22 09:40:12 +02:00
|
|
|
"save all parts (incl. non-attachments) (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"parts", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.parts,
|
2012-09-17 17:39:28 +02:00
|
|
|
"save specific parts (comma-separated list)", "<parts>"},
|
2012-09-19 09:44:16 +02:00
|
|
|
{"target-dir", 0, 0, G_OPTION_ARG_FILENAME,
|
|
|
|
&MU_CONFIG.targetdir,
|
2012-09-17 17:39:28 +02:00
|
|
|
"target directory for saving", "<dir>"},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"overwrite", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.overwrite,
|
2011-05-22 09:40:12 +02:00
|
|
|
"overwrite existing files (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"play", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.play,
|
2011-05-22 09:40:12 +02:00
|
|
|
"try to 'play' (open) the extracted parts", NULL},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
|
|
|
og = g_option_group_new("extract",
|
2012-08-01 16:05:24 +02:00
|
|
|
"Options for the 'extract' command",
|
2011-05-22 09:40:12 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
2012-08-01 16:05:24 +02:00
|
|
|
g_option_group_add_entries(og, crypto_option_entries());
|
2011-05-22 09:40:12 +02:00
|
|
|
|
|
|
|
return og;
|
2010-08-29 15:30:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:10:11 +01:00
|
|
|
|
2012-07-17 18:17:49 +02:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_verify ()
|
2012-07-17 18:17:49 +02:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
og = g_option_group_new("verify",
|
2012-08-01 16:05:24 +02:00
|
|
|
"Options for the 'verify' command",
|
2012-07-17 18:17:49 +02:00
|
|
|
"", NULL, NULL);
|
2012-08-01 16:05:24 +02:00
|
|
|
g_option_group_add_entries(og, crypto_option_entries());
|
2012-07-17 18:17:49 +02:00
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:36:36 +02:00
|
|
|
static GOptionGroup*
|
2021-02-15 17:40:54 +01:00
|
|
|
config_options_group_server ()
|
2011-08-29 22:36:36 +02:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2020-01-19 16:23:24 +01:00
|
|
|
{"commands", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.commands,
|
|
|
|
"list the available command and their parameters, then exit", NULL},
|
2020-05-05 20:24:37 +02:00
|
|
|
{"eval", 'e', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING,
|
|
|
|
&MU_CONFIG.eval, "expression to evaluate", "<expr>"},
|
2020-06-08 22:04:05 +02:00
|
|
|
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
|
2011-08-29 22:36:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
og = g_option_group_new("server",
|
2012-08-01 16:05:24 +02:00
|
|
|
"Options for the 'server' command",
|
2011-08-29 22:36:36 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
static MuConfigCmd
|
|
|
|
cmd_from_string (const char *str)
|
2011-01-02 17:10:11 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
int i;
|
2011-08-29 22:36:36 +02:00
|
|
|
struct {
|
2012-07-19 19:45:06 +02:00
|
|
|
const gchar* name;
|
|
|
|
MuConfigCmd cmd;
|
2011-08-29 22:36:36 +02:00
|
|
|
} cmd_map[] = {
|
2012-10-17 22:56:47 +02:00
|
|
|
{ "add", MU_CONFIG_CMD_ADD },
|
|
|
|
{ "cfind", MU_CONFIG_CMD_CFIND },
|
2011-08-01 21:42:23 +02:00
|
|
|
{ "extract", MU_CONFIG_CMD_EXTRACT },
|
2012-10-17 22:56:47 +02:00
|
|
|
{ "find", MU_CONFIG_CMD_FIND },
|
|
|
|
{ "help", MU_CONFIG_CMD_HELP },
|
|
|
|
{ "index", MU_CONFIG_CMD_INDEX },
|
2020-02-06 19:22:43 +01:00
|
|
|
{ "info", MU_CONFIG_CMD_INFO },
|
|
|
|
{ "init", MU_CONFIG_CMD_INIT },
|
2012-10-17 22:56:47 +02:00
|
|
|
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
|
|
|
{ "remove", MU_CONFIG_CMD_REMOVE },
|
2013-06-09 11:11:01 +02:00
|
|
|
{ "script", MU_CONFIG_CMD_SCRIPT },
|
2012-10-17 22:56:47 +02:00
|
|
|
{ "server", MU_CONFIG_CMD_SERVER },
|
2017-01-14 12:09:17 +01:00
|
|
|
{ "tickle", MU_CONFIG_CMD_TICKLE },
|
2012-10-17 22:56:47 +02:00
|
|
|
{ "verify", MU_CONFIG_CMD_VERIFY },
|
|
|
|
{ "view", MU_CONFIG_CMD_VIEW }
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-09-17 18:53:30 +02:00
|
|
|
if (!str)
|
|
|
|
return MU_CONFIG_CMD_UNKNOWN;
|
2012-07-19 19:45:06 +02:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
|
|
|
|
if (strcmp (str, cmd_map[i].name) == 0)
|
|
|
|
return cmd_map[i].cmd;
|
2013-09-28 20:20:22 +02:00
|
|
|
#ifdef BUILD_GUILE
|
|
|
|
/* if we don't recognize it and it's not an option, it may be
|
|
|
|
* some script */
|
2013-10-07 22:15:00 +02:00
|
|
|
if (str[0] != '-')
|
2013-09-28 20:20:22 +02:00
|
|
|
return MU_CONFIG_CMD_SCRIPT;
|
|
|
|
#endif /*BUILD_GUILE*/
|
|
|
|
|
|
|
|
return MU_CONFIG_CMD_UNKNOWN;
|
2012-07-19 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2012-10-24 22:47:47 +02:00
|
|
|
parse_cmd (int *argcp, char ***argvp, GError **err)
|
2012-07-19 19:45:06 +02:00
|
|
|
{
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.cmd = MU_CONFIG_CMD_NONE;
|
|
|
|
MU_CONFIG.cmdstr = NULL;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
if (*argcp < 2) /* no command found at all */
|
|
|
|
return TRUE;
|
2011-08-30 20:58:35 +02:00
|
|
|
else if ((**argvp)[1] == '-')
|
2011-05-22 09:40:12 +02:00
|
|
|
/* if the first param starts with '-', there is no
|
|
|
|
* command, just some option (like --version, --help
|
|
|
|
* etc.)*/
|
|
|
|
return TRUE;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2013-12-29 16:37:07 +01:00
|
|
|
MU_CONFIG.cmdstr = g_strdup ((*argvp)[1]);
|
2012-07-19 19:45:06 +02:00
|
|
|
MU_CONFIG.cmd = cmd_from_string (MU_CONFIG.cmdstr);
|
2011-01-04 22:19:03 +01:00
|
|
|
|
2012-10-24 22:47:47 +02:00
|
|
|
#ifndef BUILD_GUILE
|
|
|
|
if (MU_CONFIG.cmd == MU_CONFIG_CMD_SCRIPT) {
|
|
|
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
|
|
|
"command 'script' not supported");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif /*!BUILD_GUILE*/
|
|
|
|
|
2013-09-28 20:20:22 +02:00
|
|
|
if (MU_CONFIG.cmdstr && MU_CONFIG.cmdstr[0] != '-' &&
|
|
|
|
MU_CONFIG.cmd == MU_CONFIG_CMD_UNKNOWN) {
|
|
|
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
|
|
|
"unknown command '%s'",
|
|
|
|
MU_CONFIG.cmdstr);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
return TRUE;
|
2011-01-02 17:10:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
static GOptionGroup*
|
|
|
|
get_option_group (MuConfigCmd cmd)
|
2010-12-07 22:17:05 +01:00
|
|
|
{
|
2012-07-19 19:45:06 +02:00
|
|
|
switch (cmd) {
|
2012-10-17 22:56:47 +02:00
|
|
|
case MU_CONFIG_CMD_CFIND:
|
|
|
|
return config_options_group_cfind();
|
|
|
|
case MU_CONFIG_CMD_EXTRACT:
|
|
|
|
return config_options_group_extract();
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_FIND:
|
2012-07-19 19:45:06 +02:00
|
|
|
return config_options_group_find();
|
2012-10-17 22:56:47 +02:00
|
|
|
case MU_CONFIG_CMD_INDEX:
|
|
|
|
return config_options_group_index();
|
2020-02-06 19:22:43 +01:00
|
|
|
case MU_CONFIG_CMD_INIT:
|
|
|
|
return config_options_group_init();
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_MKDIR:
|
2012-07-19 19:45:06 +02:00
|
|
|
return config_options_group_mkdir();
|
2012-10-17 22:56:47 +02:00
|
|
|
case MU_CONFIG_CMD_SERVER:
|
|
|
|
return config_options_group_server();
|
2012-10-22 22:16:01 +02:00
|
|
|
case MU_CONFIG_CMD_SCRIPT:
|
|
|
|
return config_options_group_script();
|
2012-07-17 18:17:49 +02:00
|
|
|
case MU_CONFIG_CMD_VERIFY:
|
2012-10-17 22:56:47 +02:00
|
|
|
return config_options_group_verify();
|
2011-05-25 21:01:05 +02:00
|
|
|
case MU_CONFIG_CMD_VIEW:
|
2012-07-19 19:45:06 +02:00
|
|
|
return config_options_group_view();
|
2011-09-03 09:41:24 +02:00
|
|
|
default:
|
2012-07-19 19:45:06 +02:00
|
|
|
return NULL; /* no group to add */
|
2011-05-22 09:40:12 +02:00
|
|
|
}
|
2012-07-19 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-20 10:05:18 +02:00
|
|
|
/* ugh yuck massaging the GOption text output; glib prepares some text
|
2019-11-06 16:13:39 +01:00
|
|
|
* which has a 'Usage:' for the 'help' command. However, we need the
|
2012-07-20 10:05:18 +02:00
|
|
|
* help for the command we're asking help for. So, we remove the Usage:
|
|
|
|
* from what glib generates. :-( */
|
2012-07-19 19:45:06 +02:00
|
|
|
static gchar*
|
|
|
|
massage_help (const char *help)
|
|
|
|
{
|
|
|
|
GRegex *rx;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
rx = g_regex_new ("^Usage:.*\n.*\n",
|
2020-06-08 22:04:05 +02:00
|
|
|
(GRegexCompileFlags)0, G_REGEX_MATCH_NEWLINE_ANY, NULL);
|
2012-07-19 19:45:06 +02:00
|
|
|
str = g_regex_replace (rx, help,
|
|
|
|
-1, 0, "",
|
|
|
|
G_REGEX_MATCH_NEWLINE_ANY, NULL);
|
|
|
|
g_regex_unref (rx);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 18:53:30 +02:00
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
get_help_string (MuConfigCmd cmd, gboolean long_help)
|
|
|
|
{
|
|
|
|
unsigned u;
|
|
|
|
|
|
|
|
/* this include gets us MU_HELP_STRINGS */
|
|
|
|
#include "mu-help-strings.h"
|
|
|
|
|
|
|
|
for (u = 0; u != G_N_ELEMENTS(MU_HELP_STRINGS); ++u)
|
|
|
|
if (cmd == MU_HELP_STRINGS[u].cmd) {
|
|
|
|
if (long_help)
|
|
|
|
return MU_HELP_STRINGS[u].long_help;
|
|
|
|
else
|
|
|
|
return MU_HELP_STRINGS[u].usage ;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached ("");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-11-28 09:16:43 +01:00
|
|
|
Mu::mu_config_show_help (MuConfigCmd cmd)
|
2012-07-19 19:45:06 +02:00
|
|
|
{
|
|
|
|
GOptionContext *ctx;
|
|
|
|
GOptionGroup *group;
|
2018-11-03 14:48:46 +01:00
|
|
|
char *help, *cleanhelp;
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2012-09-19 09:44:16 +02:00
|
|
|
g_return_if_fail (mu_config_cmd_is_valid(cmd));
|
|
|
|
|
2012-12-22 23:04:09 +01:00
|
|
|
ctx = g_option_context_new ("- mu help");
|
2012-09-17 18:53:30 +02:00
|
|
|
g_option_context_set_main_group (ctx, config_options_group_mu());
|
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
group = get_option_group (cmd);
|
|
|
|
if (group)
|
|
|
|
g_option_context_add_group (ctx, group);
|
|
|
|
|
2018-11-03 14:48:46 +01:00
|
|
|
g_option_context_set_description (ctx, get_help_string (cmd, TRUE));
|
|
|
|
help = g_option_context_get_help (ctx, TRUE, group);
|
|
|
|
cleanhelp = massage_help (help);
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2016-12-27 16:45:19 +01:00
|
|
|
g_print ("usage:\n\t%s%s",
|
2012-09-17 18:53:30 +02:00
|
|
|
get_help_string (cmd, FALSE), cleanhelp);
|
|
|
|
|
2018-11-03 14:48:46 +01:00
|
|
|
g_free (help);
|
2012-07-19 19:45:06 +02:00
|
|
|
g_free (cleanhelp);
|
2018-11-03 14:48:46 +01:00
|
|
|
g_option_context_free (ctx);
|
2012-09-17 18:53:30 +02:00
|
|
|
}
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2012-09-17 18:53:30 +02:00
|
|
|
static gboolean
|
2021-02-15 17:40:54 +01:00
|
|
|
cmd_help ()
|
2012-09-17 18:53:30 +02:00
|
|
|
{
|
|
|
|
MuConfigCmd cmd;
|
|
|
|
|
2012-10-23 10:32:55 +02:00
|
|
|
if (!MU_CONFIG.params)
|
|
|
|
cmd = MU_CONFIG_CMD_UNKNOWN;
|
|
|
|
else
|
|
|
|
cmd = cmd_from_string (MU_CONFIG.params[1]);
|
|
|
|
|
2012-09-17 18:53:30 +02:00
|
|
|
if (cmd == MU_CONFIG_CMD_UNKNOWN) {
|
|
|
|
mu_config_show_help (MU_CONFIG_CMD_HELP);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mu_config_show_help (cmd);
|
2012-10-23 10:32:55 +02:00
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
return TRUE;
|
2012-09-17 18:53:30 +02:00
|
|
|
}
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2011-03-06 11:15:43 +01:00
|
|
|
static gboolean
|
2012-10-24 22:47:47 +02:00
|
|
|
parse_params (int *argcp, char ***argvp, GError **err)
|
2011-03-06 11:15:43 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionContext *context;
|
2012-10-22 22:16:01 +02:00
|
|
|
GOptionGroup *group;
|
2011-05-22 09:40:12 +02:00
|
|
|
gboolean rv;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
context = g_option_context_new("- mu general options");
|
2012-12-22 23:04:09 +01:00
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
g_option_context_set_help_enabled (context, TRUE);
|
2012-10-22 22:16:01 +02:00
|
|
|
rv = TRUE;
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2012-10-23 19:57:46 +02:00
|
|
|
g_option_context_set_main_group(context,
|
|
|
|
config_options_group_mu());
|
2012-12-24 10:13:44 +01:00
|
|
|
g_option_context_set_ignore_unknown_options (context, FALSE);
|
2012-10-23 19:57:46 +02:00
|
|
|
|
2012-10-22 22:16:01 +02:00
|
|
|
switch (MU_CONFIG.cmd) {
|
2012-12-22 23:04:09 +01:00
|
|
|
case MU_CONFIG_CMD_NONE:
|
2012-10-22 22:16:01 +02:00
|
|
|
case MU_CONFIG_CMD_HELP:
|
|
|
|
/* 'help' is special; sucks in the options of the
|
|
|
|
* command after it */
|
2012-10-24 22:47:47 +02:00
|
|
|
rv = g_option_context_parse (context, argcp, argvp, err) &&
|
2012-09-17 18:53:30 +02:00
|
|
|
cmd_help ();
|
2012-10-22 22:16:01 +02:00
|
|
|
break;
|
2013-06-09 11:11:01 +02:00
|
|
|
case MU_CONFIG_CMD_SCRIPT:
|
|
|
|
/* all unknown commands are passed to 'script' */
|
|
|
|
g_option_context_set_ignore_unknown_options (context, TRUE);
|
|
|
|
group = get_option_group (MU_CONFIG.cmd);
|
|
|
|
g_option_context_add_group (context, group);
|
|
|
|
rv = g_option_context_parse (context, argcp, argvp, err);
|
|
|
|
MU_CONFIG.script = g_strdup (MU_CONFIG.cmdstr);
|
|
|
|
/* argvp contains the script parameters */
|
|
|
|
MU_CONFIG.script_params = (const char**)&((*argvp)[1]);
|
|
|
|
break;
|
|
|
|
|
2012-10-22 22:16:01 +02:00
|
|
|
default:
|
2012-07-19 19:45:06 +02:00
|
|
|
group = get_option_group (MU_CONFIG.cmd);
|
|
|
|
if (group)
|
2012-12-24 10:13:44 +01:00
|
|
|
g_option_context_add_group (context, group);
|
|
|
|
|
2012-10-24 22:47:47 +02:00
|
|
|
rv = g_option_context_parse (context, argcp, argvp, err);
|
2012-12-22 23:04:09 +01:00
|
|
|
break;
|
2012-07-19 19:45:06 +02:00
|
|
|
}
|
2012-12-24 10:13:44 +01:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
g_option_context_free (context);
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2012-10-24 22:47:47 +02:00
|
|
|
return rv ? TRUE : FALSE;
|
2011-07-22 20:11:50 +02:00
|
|
|
}
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2010-01-06 00:24:37 +01:00
|
|
|
|
2011-01-04 22:19:03 +01:00
|
|
|
MuConfig*
|
2020-11-28 09:16:43 +01:00
|
|
|
Mu::mu_config_init (int *argcp, char ***argvp, GError **err)
|
2010-01-21 19:05:19 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
g_return_val_if_fail (argcp && argvp, NULL);
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
memset (&MU_CONFIG, 0, sizeof(MU_CONFIG));
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
if (!parse_cmd (argcp, argvp, err))
|
2012-07-19 19:45:06 +02:00
|
|
|
goto errexit;
|
|
|
|
|
2012-10-24 22:47:47 +02:00
|
|
|
if (!parse_params(argcp, argvp, err))
|
2012-07-19 19:45:06 +02:00
|
|
|
goto errexit;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
/* fill in the defaults if user did not specify */
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_mu_defaults();
|
2020-02-06 19:22:43 +01:00
|
|
|
set_group_init_defaults();
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_find_defaults();
|
|
|
|
set_group_cfind_defaults();
|
|
|
|
set_group_view_defaults();
|
2012-09-16 12:15:44 +02:00
|
|
|
set_group_extract_defaults();
|
2011-05-22 09:40:12 +02:00
|
|
|
/* set_group_mkdir_defaults (config); */
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
return &MU_CONFIG;
|
2012-07-19 19:45:06 +02:00
|
|
|
|
|
|
|
errexit:
|
|
|
|
mu_config_uninit (&MU_CONFIG);
|
|
|
|
return NULL;
|
2010-01-21 19:05:19 +01:00
|
|
|
}
|
2009-11-29 23:04:16 +01:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
void
|
2020-11-28 09:16:43 +01:00
|
|
|
Mu::mu_config_uninit (MuConfig *opts)
|
2009-11-29 23:04:16 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
if (!opts)
|
|
|
|
return;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2013-12-29 16:37:07 +01:00
|
|
|
g_free (opts->cmdstr);
|
2011-05-22 09:40:12 +02:00
|
|
|
g_free (opts->muhome);
|
|
|
|
g_free (opts->maildir);
|
2013-12-29 16:37:07 +01:00
|
|
|
g_free (opts->fields);
|
|
|
|
g_free (opts->sortfield);
|
|
|
|
g_free (opts->bookmark);
|
|
|
|
g_free (opts->formatstr);
|
|
|
|
g_free (opts->exec);
|
2011-05-22 09:40:12 +02:00
|
|
|
g_free (opts->linksdir);
|
|
|
|
g_free (opts->targetdir);
|
2013-12-29 16:37:07 +01:00
|
|
|
g_free (opts->parts);
|
|
|
|
g_free (opts->script);
|
2020-05-05 20:24:37 +02:00
|
|
|
g_free (opts->eval);
|
2011-09-03 09:41:24 +02:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
g_strfreev (opts->params);
|
2012-03-13 22:06:17 +01:00
|
|
|
|
|
|
|
memset (opts, 0, sizeof(MU_CONFIG));
|
2011-01-04 22:19:03 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
size_t
|
2020-11-28 09:16:43 +01:00
|
|
|
Mu::mu_config_param_num (const MuConfig *opts)
|
2011-05-26 22:35:34 +02:00
|
|
|
{
|
2012-03-13 22:06:17 +01:00
|
|
|
size_t n;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
g_return_val_if_fail (opts && opts->params, 0);
|
|
|
|
for (n = 0; opts->params[n]; ++n);
|
2011-05-26 22:35:34 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
return n;
|
2011-05-26 22:35:34 +02:00
|
|
|
}
|
2012-08-01 16:05:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
MuMsgOptions
|
2020-11-28 09:16:43 +01:00
|
|
|
Mu::mu_config_get_msg_options (const MuConfig *muopts)
|
2012-08-01 16:05:24 +02:00
|
|
|
{
|
2020-06-08 22:04:05 +02:00
|
|
|
int opts;
|
2012-08-01 16:05:24 +02:00
|
|
|
|
|
|
|
opts = MU_MSG_OPTION_NONE;
|
|
|
|
|
|
|
|
if (muopts->decrypt)
|
|
|
|
opts |= MU_MSG_OPTION_DECRYPT;
|
|
|
|
if (muopts->verify)
|
|
|
|
opts |= MU_MSG_OPTION_VERIFY;
|
|
|
|
if (muopts->use_agent)
|
|
|
|
opts |= MU_MSG_OPTION_USE_AGENT;
|
|
|
|
if (muopts->auto_retrieve)
|
|
|
|
opts |= MU_MSG_OPTION_AUTO_RETRIEVE;
|
|
|
|
if (muopts->overwrite)
|
|
|
|
opts |= MU_MSG_OPTION_OVERWRITE;
|
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
return (MuMsgOptions)opts;
|
2012-08-01 16:05:24 +02:00
|
|
|
}
|