/* -*-Mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* ** Copyright (C) 2008-2012 Dirk-Jan C. Binnema ** ** 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. ** */ #if HAVE_CONFIG_H #include "config.h" #endif /*HAVE_CONFIG_H*/ #include #include /* memset */ #include #include #include "mu-util.h" #include "mu-config.h" #include "mu-cmd.h" static MuConfig MU_CONFIG; 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; } static void set_group_mu_defaults (void) { gchar *exp; if (!MU_CONFIG.muhome) MU_CONFIG.muhome = mu_util_guess_mu_homedir(); exp = mu_util_dir_expand(MU_CONFIG.muhome); if (exp) { g_free(MU_CONFIG.muhome); MU_CONFIG.muhome = exp; } /* 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) MU_CONFIG.nocolor = TRUE; if (!isatty(fileno(stdout)) || !isatty(fileno(stderr))) MU_CONFIG.nocolor = TRUE; } static GOptionGroup* config_options_group_mu (void) { GOptionGroup *og; GOptionEntry entries[] = { {"debug", 'd', 0, G_OPTION_ARG_NONE, &MU_CONFIG.debug, "print debug output to standard error (false)", NULL}, {"quiet", 'q', 0, G_OPTION_ARG_NONE, &MU_CONFIG.quiet, "don't give any progress information (false)", NULL}, {"version", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.version, "display version and copyright information (false)", NULL}, {"muhome", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.muhome, "specify an alternative mu directory", ""}, {"log-stderr", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.log_stderr, "log to standard error (false)", NULL}, {"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor, "don't use ANSI-colors in output (false)", NULL}, {"verbose", 'v', 0, G_OPTION_ARG_NONE, &MU_CONFIG.verbose, "verbose output (false)", NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &MU_CONFIG.params, "parameters", NULL}, {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; } #define expand_dir(D) \ if ((D)) { \ char *exp; \ exp = mu_util_dir_expand((D)); \ if (exp) { \ g_free((D)); \ (D) = exp; \ } \ } static void set_group_index_defaults (void) { if (!MU_CONFIG.maildir) MU_CONFIG.maildir = mu_util_guess_maildir (); expand_dir (MU_CONFIG.maildir); } static GOptionGroup* config_options_group_index (void) { GOptionGroup *og; GOptionEntry entries[] = { {"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.maildir, "top of the maildir", ""}, {"reindex", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.reindex, "index even already indexed messages (false)", NULL}, {"rebuild", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.rebuild, "rebuild the database from scratch (false)", NULL}, {"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY, &MU_CONFIG.my_addresses, "my e-mail address (regexp); can be used multiple times", "
"}, {"autoupgrade", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.autoupgrade, "auto-upgrade the database with new mu versions (false)", NULL}, {"nocleanup", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocleanup, "don't clean up the database after indexing (false)", NULL}, {"xbatchsize", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.xbatchsize, "set transaction batchsize for xapian commits (0)", NULL}, {"max-msg-size", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.max_msg_size, "set the maximum size for message files", ""}, {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; } static void set_group_find_defaults (void) { /* 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. */ if (!MU_CONFIG.fields) { MU_CONFIG.fields = "d f s"; if (!MU_CONFIG.sortfield) MU_CONFIG.sortfield = "d"; } if (!MU_CONFIG.formatstr) /* by default, use plain output */ MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN; else MU_CONFIG.format = get_output_format (MU_CONFIG.formatstr); expand_dir (MU_CONFIG.linksdir); } static GOptionGroup* config_options_group_find (void) { GOptionGroup *og; GOptionEntry entries[] = { {"fields", 'f', 0, G_OPTION_ARG_STRING, &MU_CONFIG.fields, "fields to display in the output", ""}, {"sortfield", 's', 0, G_OPTION_ARG_STRING, &MU_CONFIG.sortfield, "field to sort on", ""}, {"threads", 't', 0, G_OPTION_ARG_NONE, &MU_CONFIG.threads, "show message threads", NULL}, {"bookmark", 'b', 0, G_OPTION_ARG_STRING, &MU_CONFIG.bookmark, "use a bookmarked query", ""}, {"reverse", 'z', 0, G_OPTION_ARG_NONE, &MU_CONFIG.reverse, "sort in reverse (descending) order (z -> a)", NULL}, {"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir, "output as symbolic links to a target maildir", ""}, {"clearlinks", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.clearlinks, "clear old links before filling a linksdir (false)", NULL}, {"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr, "output format ('plain'(*), 'links', 'xml'," "'sexp', 'xquery')", ""}, {"exec", 'e', 0, G_OPTION_ARG_STRING, &MU_CONFIG.exec, "execute command on each match message", ""}, {"after", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.after, "only show messages whose m_time > T (t_time)", ""}, {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; } static GOptionGroup * config_options_group_mkdir (void) { GOptionGroup *og; GOptionEntry entries[] = { {"mode", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.dirmode, "set the mode (as in chmod), in octal notation", ""}, {NULL, 0, 0, 0, NULL, NULL, NULL} }; /* set dirmode before, because '0000' is a valid mode */ MU_CONFIG.dirmode = 0755; og = g_option_group_new("mkdir", "Options for the 'mkdir' command", "", NULL, NULL); g_option_group_add_entries(og, entries); return og; } static void set_group_cfind_defaults (void) { if (!MU_CONFIG.formatstr) /* by default, use plain output */ MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN; else MU_CONFIG.format = get_output_format (MU_CONFIG.formatstr); } static GOptionGroup * config_options_group_cfind (void) { GOptionGroup *og; GOptionEntry entries[] = { {"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr, "output format ('plain'(*), 'mutt', 'wanderlust'," "'org-contact', 'csv')", ""}, {"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, 0, 0, 0, NULL, NULL, NULL} }; og = g_option_group_new("cfind", "Options for the 'cfind' command", "", NULL, NULL); g_option_group_add_entries(og, entries); return og; } static GOptionGroup * config_options_group_script (void) { GOptionGroup *og; GOptionEntry entries[] = { {"script", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.script, "script to run (see `mu help script')", "