2012-03-13 22:06:17 +01:00
|
|
|
/* -*-Mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
2011-08-11 19:20:22 +02:00
|
|
|
|
2009-11-28 13:06:21 +01:00
|
|
|
/*
|
2012-01-21 11:12:41 +01:00
|
|
|
** Copyright (C) 2008-2012 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-11-14 12:55:04 +01:00
|
|
|
#if HAVE_CONFIG_H
|
2010-01-08 19:54:55 +01:00
|
|
|
#include "config.h"
|
2010-08-27 07:26:41 +02:00
|
|
|
#endif /*HAVE_CONFIG_H*/
|
2010-01-08 19:54:55 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
#include "mu-util.h"
|
2009-11-28 13:06:21 +01:00
|
|
|
#include "mu-config.h"
|
2011-01-04 22:19:03 +01:00
|
|
|
#include "mu-cmd.h"
|
2009-11-28 13:06:21 +01:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
static MuConfig MU_CONFIG;
|
|
|
|
|
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},
|
|
|
|
{"xml", MU_CONFIG_FORMAT_XML},
|
|
|
|
{"xquery", MU_CONFIG_FORMAT_XQUERY}
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static void
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_mu_defaults (void)
|
2010-08-14 14:29:46 +02:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
gchar *exp;
|
2010-08-14 14:29:46 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.muhome)
|
|
|
|
MU_CONFIG.muhome = mu_util_guess_mu_homedir();
|
2010-08-14 14:29:46 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
exp = mu_util_dir_expand(MU_CONFIG.muhome);
|
2011-05-22 09:40:12 +02:00
|
|
|
if (exp) {
|
2012-03-13 22:06:17 +01:00
|
|
|
g_free(MU_CONFIG.muhome);
|
|
|
|
MU_CONFIG.muhome = exp;
|
2011-05-22 09:40:12 +02:00
|
|
|
}
|
2011-05-25 21:01:05 +02:00
|
|
|
|
2012-01-21 11:12:41 +01:00
|
|
|
/* check for the MU_NOCOLOR env var; but in any case don't
|
|
|
|
* use colors unless we're writing to a tty */
|
|
|
|
if (g_getenv (MU_NOCOLOR) != NULL)
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.nocolor = TRUE;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-26 22:35:34 +02:00
|
|
|
if (!isatty(fileno(stdout)))
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.nocolor = TRUE;
|
2009-11-28 13:06:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_mu (void)
|
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},
|
2012-03-13 22:06:17 +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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"specify an alternative mu directory", NULL},
|
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},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor,
|
2012-01-21 11:12:41 +01:00
|
|
|
"don't use ANSI-colors in some 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},
|
2011-05-22 09:40:12 +02:00
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_index_defaults (void)
|
2010-08-14 14:29:46 +02:00
|
|
|
{
|
2011-11-20 00:26:32 +01:00
|
|
|
char *exp;
|
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.maildir)
|
|
|
|
MU_CONFIG.maildir = mu_util_guess_maildir ();
|
2011-11-20 00:26:32 +01:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
if (MU_CONFIG.maildir) {
|
|
|
|
exp = mu_util_dir_expand(MU_CONFIG.maildir);
|
2012-01-22 17:39:10 +01:00
|
|
|
if (exp) {
|
2012-03-13 22:06:17 +01:00
|
|
|
g_free(MU_CONFIG.maildir);
|
|
|
|
MU_CONFIG.maildir = exp;
|
2012-01-22 17:39:10 +01:00
|
|
|
}
|
2011-11-20 00:26:32 +01:00
|
|
|
}
|
2010-08-14 14:29:46 +02:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_index (void)
|
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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"top of the maildir", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"reindex", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.reindex,
|
2011-05-22 09:40:12 +02:00
|
|
|
"index even already indexed messages (false)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"rebuild", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.rebuild,
|
2011-05-22 09:40:12 +02:00
|
|
|
"rebuild the database from scratch (false)", NULL},
|
2012-06-17 16:49:55 +02:00
|
|
|
{"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY,&MU_CONFIG.my_addresses,
|
|
|
|
"my e-mail address (regexp); can be used multiple times", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"autoupgrade", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.autoupgrade,
|
2012-06-20 08:20:15 +02:00
|
|
|
"auto-upgrade the database with new mu versions (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},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"xbatchsize", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.xbatchsize,
|
2011-05-22 09:40:12 +02:00
|
|
|
"set transaction batchsize for xapian commits (0)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"max-msg-size", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.max_msg_size,
|
2011-05-22 09:40:12 +02:00
|
|
|
"set the maximum size for message files", NULL},
|
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
og = g_option_group_new("index",
|
|
|
|
"options for the 'index' command",
|
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
2009-11-28 13:06:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static void
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_find_defaults (void)
|
2010-08-14 14:29:46 +02:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
/* note, when no fields are specified, we use
|
|
|
|
* date-from-subject, and sort descending by date. If fields
|
|
|
|
* *are* specified, we sort in ascending order. */
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!MU_CONFIG.fields) {
|
|
|
|
MU_CONFIG.fields = "d f s";
|
|
|
|
if (!MU_CONFIG.sortfield)
|
|
|
|
MU_CONFIG.sortfield = "d";
|
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);
|
2009-11-28 13:06:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_find (void)
|
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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"fields to display in the output", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"sortfield", 's', 0, G_OPTION_ARG_STRING, &MU_CONFIG.sortfield,
|
2011-05-22 09:40:12 +02:00
|
|
|
"field to sort on", NULL},
|
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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"use a bookmarked query", NULL},
|
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},
|
2012-07-12 17:09:04 +02:00
|
|
|
/* {"summary", 'k', 0, G_OPTION_ARG_NONE, &MU_CONFIG.summary, */
|
|
|
|
/* "(deprecated; use --summary-len)", NULL}, */
|
2012-04-28 11:56:57 +02:00
|
|
|
{"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
|
|
|
|
"use up to <n> lines for the summary (5)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir,
|
2011-05-22 09:40:12 +02:00
|
|
|
"output as symbolic links to a target maildir", NULL},
|
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',"
|
2011-08-03 22:00:48 +02:00
|
|
|
"'sexp', 'xquery')", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"exec", 'e', 0, G_OPTION_ARG_STRING, &MU_CONFIG.exec,
|
2011-07-06 22:35:52 +02:00
|
|
|
"execute command on each match message", NULL},
|
2012-07-12 14:53:36 +02:00
|
|
|
{"after", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.after,
|
|
|
|
"only show messages whose m_time > T (t_time)", NULL},
|
2011-05-22 09:40:12 +02:00
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
og = g_option_group_new("find",
|
|
|
|
"options for the 'find' command",
|
|
|
|
"", 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 *
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_mkdir (void)
|
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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"set the mode (as in chmod), in octal notation", NULL},
|
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
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
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
og = g_option_group_new("mkdir", "options for the 'mkdir' command",
|
|
|
|
"", 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
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_cfind_defaults (void)
|
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 *
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_cfind (void)
|
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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"output format ('plain'(*), 'mutt', 'wanderlust',"
|
|
|
|
"'org-contact', 'csv')", NULL},
|
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,
|
|
|
|
"only get addresses last seen after T", NULL},
|
2011-05-22 09:40:12 +02:00
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
og = g_option_group_new("cfind", "options for the 'cfind' command",
|
|
|
|
"", 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
static void
|
2012-03-13 22:06:17 +01:00
|
|
|
set_group_view_defaults (void)
|
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
|
|
|
}
|
|
|
|
|
2011-05-25 21:01:05 +02:00
|
|
|
static GOptionGroup *
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_view (void)
|
2011-05-25 21:01:05 +02:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"summary", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.summary,
|
2012-07-12 17:09:04 +02:00
|
|
|
"(deprecated; use --summary-len)", NULL},
|
|
|
|
/* {"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len, */
|
|
|
|
/* "use up to <n> lines for the summary (5)", NULL}, */
|
2012-03-13 22:06:17 +01:00
|
|
|
{"terminate", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.terminator,
|
2011-07-07 21:59:44 +02:00
|
|
|
"terminate messages with ascii-0x07 (\\f, form-feed)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
|
2011-07-27 07:20:06 +02:00
|
|
|
"output format ('plain'(*), 'sexp')", NULL},
|
2011-05-25 21:01:05 +02:00
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
og = g_option_group_new("view", "options for the 'view' command",
|
2011-05-25 21:01:05 +02:00
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-04 23:59:35 +01:00
|
|
|
|
2011-01-02 13:59:03 +01:00
|
|
|
static GOptionGroup*
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_extract (void)
|
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,
|
2011-05-22 09:40:12 +02:00
|
|
|
"save specific parts (comma-separated list)", NULL},
|
2012-03-13 22:06:17 +01:00
|
|
|
{"target-dir", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.targetdir,
|
2011-05-22 09:40:12 +02:00
|
|
|
"target directory for saving", NULL},
|
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},
|
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.targetdir = g_strdup("."); /* default is the current dir */
|
2011-05-22 09:40:12 +02:00
|
|
|
|
|
|
|
og = g_option_group_new("extract",
|
|
|
|
"options for the 'extract' command",
|
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
2010-08-29 15:30:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:10:11 +01:00
|
|
|
|
2011-08-29 22:36:36 +02:00
|
|
|
static GOptionGroup*
|
2012-03-13 22:06:17 +01:00
|
|
|
config_options_group_server (void)
|
2011-08-29 22:36:36 +02:00
|
|
|
{
|
|
|
|
GOptionGroup *og;
|
|
|
|
GOptionEntry entries[] = {
|
2012-03-13 22:06:17 +01:00
|
|
|
{"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.maildir,
|
2011-08-29 22:36:36 +02:00
|
|
|
"top of the maildir", NULL},
|
|
|
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
og = g_option_group_new("server",
|
|
|
|
"options for the 'server' command",
|
|
|
|
"", NULL, NULL);
|
|
|
|
g_option_group_add_entries(og, entries);
|
|
|
|
|
|
|
|
return og;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-30 20:58:35 +02:00
|
|
|
static gboolean
|
2012-03-13 22:06:17 +01:00
|
|
|
parse_cmd (int *argcp, char ***argvp)
|
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 {
|
2011-05-22 09:40:12 +02:00
|
|
|
const gchar* _name;
|
2011-05-22 12:44:12 +02:00
|
|
|
MuConfigCmd _cmd;
|
2011-08-29 22:36:36 +02:00
|
|
|
} cmd_map[] = {
|
2011-08-01 21:42:23 +02:00
|
|
|
{ "cfind", MU_CONFIG_CMD_CFIND },
|
|
|
|
{ "extract", MU_CONFIG_CMD_EXTRACT },
|
|
|
|
{ "find", MU_CONFIG_CMD_FIND },
|
|
|
|
{ "index", MU_CONFIG_CMD_INDEX },
|
2011-05-22 09:40:12 +02:00
|
|
|
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
|
|
|
{ "view", MU_CONFIG_CMD_VIEW },
|
2011-08-10 22:57:34 +02:00
|
|
|
{ "add", MU_CONFIG_CMD_ADD },
|
|
|
|
{ "remove", MU_CONFIG_CMD_REMOVE },
|
2011-08-29 22:36:36 +02:00
|
|
|
{ "server", MU_CONFIG_CMD_SERVER }
|
2011-05-22 09:40:12 +02:00
|
|
|
};
|
2011-08-30 20:58:35 +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
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
MU_CONFIG.cmd = MU_CONFIG_CMD_UNKNOWN;
|
|
|
|
MU_CONFIG.cmdstr = (*argvp)[1];
|
2011-01-13 20:41:07 +01:00
|
|
|
|
2011-08-30 20:58:35 +02:00
|
|
|
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
|
2012-03-13 22:06:17 +01:00
|
|
|
if (strcmp (MU_CONFIG.cmdstr, cmd_map[i]._name) == 0)
|
|
|
|
MU_CONFIG.cmd = cmd_map[i]._cmd;
|
2011-01-04 22:19:03 +01:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
return TRUE;
|
2011-01-02 17:10:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-06 11:15:43 +01:00
|
|
|
static void
|
2012-03-13 22:06:17 +01:00
|
|
|
add_context_group (GOptionContext *context)
|
2010-12-07 22:17:05 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GOptionGroup *group;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
switch (MU_CONFIG.cmd) {
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_INDEX:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_index();
|
|
|
|
break;
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_FIND:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_find();
|
|
|
|
break;
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_MKDIR:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_mkdir();
|
|
|
|
break;
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_EXTRACT:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_extract();
|
|
|
|
break;
|
2011-05-22 09:40:12 +02:00
|
|
|
case MU_CONFIG_CMD_CFIND:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_cfind();
|
|
|
|
break;
|
2011-05-25 21:01:05 +02:00
|
|
|
case MU_CONFIG_CMD_VIEW:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_view();
|
|
|
|
break;
|
2011-08-29 22:36:36 +02:00
|
|
|
case MU_CONFIG_CMD_SERVER:
|
2012-03-13 22:06:17 +01:00
|
|
|
group = config_options_group_server();
|
|
|
|
break;
|
2011-09-03 09:41:24 +02:00
|
|
|
default:
|
|
|
|
return; /* no group to add */
|
2011-05-22 09:40:12 +02:00
|
|
|
}
|
|
|
|
|
2011-09-03 09:41:24 +02:00
|
|
|
g_option_context_add_group(context, group);
|
2011-03-06 11:15:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2012-03-13 22:06:17 +01:00
|
|
|
parse_params (int *argcp, char ***argvp)
|
2011-03-06 11:15:43 +01:00
|
|
|
{
|
2011-05-22 09:40:12 +02:00
|
|
|
GError *err = NULL;
|
|
|
|
GOptionContext *context;
|
|
|
|
gboolean rv;
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
context = g_option_context_new("- mu general option");
|
2012-03-13 22:06:17 +01:00
|
|
|
g_option_context_set_main_group(context, config_options_group_mu());
|
2011-03-06 11:15:43 +01:00
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
add_context_group (context);
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-26 22:35:34 +02:00
|
|
|
rv = g_option_context_parse (context, argcp, argvp, &err);
|
2011-05-22 09:40:12 +02:00
|
|
|
g_option_context_free (context);
|
|
|
|
if (!rv) {
|
|
|
|
g_printerr ("mu: error in options: %s\n", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-22 20:11:50 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
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*
|
2012-03-13 22:06:17 +01:00
|
|
|
mu_config_init (int *argcp, char ***argvp)
|
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
|
|
|
|
2012-03-13 22:06:17 +01:00
|
|
|
if (!parse_cmd (argcp, argvp) ||
|
|
|
|
!parse_params(argcp, argvp)) {
|
|
|
|
mu_config_uninit (&MU_CONFIG);
|
2011-05-22 09:40:12 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
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();
|
|
|
|
set_group_index_defaults();
|
|
|
|
set_group_find_defaults();
|
|
|
|
set_group_cfind_defaults();
|
|
|
|
set_group_view_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;
|
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
|
2012-03-13 22:06:17 +01:00
|
|
|
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
|
|
|
|
2011-05-22 09:40:12 +02:00
|
|
|
g_free (opts->muhome);
|
|
|
|
g_free (opts->maildir);
|
|
|
|
g_free (opts->linksdir);
|
|
|
|
g_free (opts->targetdir);
|
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
|
|
|
|
mu_config_param_num (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
|
|
|
}
|