2009-11-28 13:06:21 +01:00
|
|
|
/*
|
2020-01-19 16:32:32 +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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
#ifndef MU_CONFIG_HH__
|
|
|
|
#define MU_CONFIG_HH__
|
2009-11-28 13:06:21 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
2010-01-21 19:05:19 +01:00
|
|
|
#include <sys/types.h> /* for mode_t */
|
2011-01-04 22:19:03 +01:00
|
|
|
#include <mu-msg-fields.h>
|
2020-11-28 09:16:43 +01:00
|
|
|
#include <mu-msg.hh>
|
2019-12-16 20:44:35 +01:00
|
|
|
#include <utils/mu-util.h>
|
2009-11-28 13:06:21 +01:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
namespace Mu {
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2012-01-21 11:12:41 +01:00
|
|
|
/* env var; if non-empty, color are disabled */
|
|
|
|
#define MU_NOCOLOR "MU_NOCOLOR"
|
2011-05-25 21:01:05 +02:00
|
|
|
|
2019-12-28 10:19:12 +01:00
|
|
|
typedef enum {
|
2011-07-27 07:20:06 +02:00
|
|
|
MU_CONFIG_FORMAT_UNKNOWN = 0,
|
|
|
|
|
|
|
|
/* for cfind, find, view */
|
|
|
|
MU_CONFIG_FORMAT_PLAIN, /* plain output */
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
/* for cfind */
|
|
|
|
MU_CONFIG_FORMAT_MUTT_ALIAS, /* mutt alias style */
|
|
|
|
MU_CONFIG_FORMAT_MUTT_AB, /* mutt ext abook */
|
|
|
|
MU_CONFIG_FORMAT_WL, /* Wanderlust abook */
|
|
|
|
MU_CONFIG_FORMAT_CSV, /* comma-sep'd values */
|
|
|
|
MU_CONFIG_FORMAT_ORG_CONTACT, /* org-contact */
|
|
|
|
MU_CONFIG_FORMAT_BBDB, /* BBDB */
|
2019-04-28 12:58:34 +02:00
|
|
|
MU_CONFIG_FORMAT_DEBUG,
|
2011-07-27 07:20:06 +02:00
|
|
|
|
|
|
|
/* for find, view */
|
2011-08-03 22:00:48 +02:00
|
|
|
MU_CONFIG_FORMAT_SEXP, /* output sexps (emacs) */
|
2018-11-11 11:16:49 +01:00
|
|
|
MU_CONFIG_FORMAT_JSON, /* output JSON */
|
2011-07-27 07:20:06 +02:00
|
|
|
|
|
|
|
/* for find */
|
|
|
|
MU_CONFIG_FORMAT_LINKS, /* output as symlinks */
|
|
|
|
MU_CONFIG_FORMAT_XML, /* output xml */
|
2012-07-12 14:53:36 +02:00
|
|
|
MU_CONFIG_FORMAT_XQUERY, /* output the xapian query */
|
2017-10-24 21:58:32 +02:00
|
|
|
MU_CONFIG_FORMAT_MQUERY, /* output the mux query */
|
2012-07-12 14:53:36 +02:00
|
|
|
|
|
|
|
MU_CONFIG_FORMAT_EXEC /* execute some command */
|
2019-12-28 10:19:12 +01:00
|
|
|
} MuConfigFormat;
|
2011-07-27 07:20:06 +02:00
|
|
|
|
2019-12-28 10:19:12 +01:00
|
|
|
typedef enum {
|
2011-07-27 07:20:06 +02:00
|
|
|
MU_CONFIG_CMD_UNKNOWN = 0,
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2012-07-19 19:45:06 +02:00
|
|
|
MU_CONFIG_CMD_ADD,
|
|
|
|
MU_CONFIG_CMD_CFIND,
|
|
|
|
MU_CONFIG_CMD_EXTRACT,
|
2011-05-22 09:25:21 +02:00
|
|
|
MU_CONFIG_CMD_FIND,
|
2012-07-19 19:45:06 +02:00
|
|
|
MU_CONFIG_CMD_HELP,
|
|
|
|
MU_CONFIG_CMD_INDEX,
|
2020-02-06 19:22:43 +01:00
|
|
|
MU_CONFIG_CMD_INFO,
|
|
|
|
MU_CONFIG_CMD_INIT,
|
2011-05-22 09:25:21 +02:00
|
|
|
MU_CONFIG_CMD_MKDIR,
|
2011-08-03 22:00:48 +02:00
|
|
|
MU_CONFIG_CMD_REMOVE,
|
2012-10-22 22:16:01 +02:00
|
|
|
MU_CONFIG_CMD_SCRIPT,
|
2011-08-29 22:36:36 +02:00
|
|
|
MU_CONFIG_CMD_SERVER,
|
2017-01-14 12:09:17 +01:00
|
|
|
MU_CONFIG_CMD_TICKLE,
|
2012-07-17 18:17:49 +02:00
|
|
|
MU_CONFIG_CMD_VERIFY,
|
2012-07-19 19:45:06 +02:00
|
|
|
MU_CONFIG_CMD_VIEW,
|
2011-08-29 22:36:36 +02:00
|
|
|
|
2011-09-12 19:38:40 +02:00
|
|
|
MU_CONFIG_CMD_NONE
|
2019-12-28 10:19:12 +01:00
|
|
|
} MuConfigCmd;
|
2011-01-02 17:05:43 +01:00
|
|
|
|
|
|
|
|
2012-09-19 09:44:16 +02:00
|
|
|
#define mu_config_cmd_is_valid(C) \
|
|
|
|
((C) > MU_CONFIG_CMD_UNKNOWN && (C) < MU_CONFIG_CMD_NONE)
|
|
|
|
|
|
|
|
|
2009-11-28 13:06:21 +01:00
|
|
|
/* struct with all configuration options for mu; it will be filled
|
|
|
|
* from the config file, and/or command line arguments */
|
|
|
|
|
2011-01-04 22:19:03 +01:00
|
|
|
struct _MuConfig {
|
2011-01-02 17:05:43 +01:00
|
|
|
|
2013-12-29 16:37:07 +01:00
|
|
|
MuConfigCmd cmd; /* the command, or
|
2011-05-22 09:25:21 +02:00
|
|
|
* MU_CONFIG_CMD_NONE */
|
2017-10-24 21:58:32 +02:00
|
|
|
char *cmdstr; /* cmd string, for user
|
|
|
|
* info */
|
2011-05-22 09:25:21 +02:00
|
|
|
/* general options */
|
2020-05-30 12:24:53 +02:00
|
|
|
gboolean quiet; /* don't give any output */
|
|
|
|
gboolean debug; /* log debug-level info */
|
2012-10-18 23:51:04 +02:00
|
|
|
gchar *muhome; /* the House of Mu */
|
2013-12-29 16:37:07 +01:00
|
|
|
gboolean version; /* request mu version */
|
|
|
|
gboolean log_stderr; /* log to stderr (not logfile) */
|
|
|
|
gchar** params; /* parameters (for querying) */
|
2014-02-15 11:09:07 +01:00
|
|
|
gboolean nocolor; /* don't use use ansi-colors
|
|
|
|
* in some output */
|
2013-12-29 16:37:07 +01:00
|
|
|
gboolean verbose; /* verbose output */
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
/* options for init */
|
|
|
|
gchar *maildir; /* where the mails are */
|
2020-06-27 10:36:34 +02:00
|
|
|
char** my_addresses; /* 'my e-mail address', for mu cfind;
|
|
|
|
* can be use multiple times */
|
|
|
|
int max_msg_size; /* maximum size for message files */
|
|
|
|
int batch_size; /* database transaction batch size */
|
|
|
|
|
2011-05-22 09:25:21 +02:00
|
|
|
/* options for indexing */
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2011-05-22 09:25:21 +02:00
|
|
|
gboolean nocleanup; /* don't cleanup del'd mails from db */
|
|
|
|
gboolean rebuild; /* empty the database before indexing */
|
2016-07-23 18:18:09 +02:00
|
|
|
gboolean lazycheck; /* don't check dirs with up-to-date
|
|
|
|
* timestamps */
|
2020-06-27 10:36:34 +02:00
|
|
|
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-06-19 20:03:33 +02:00
|
|
|
/* options for querying 'find' (and view-> 'summary') */
|
2012-10-18 23:51:04 +02:00
|
|
|
gchar *fields; /* fields to show in output */
|
|
|
|
gchar *sortfield; /* field to sort by (string) */
|
2013-09-27 16:11:04 +02:00
|
|
|
int maxnum; /* max # of entries to print */
|
2011-09-22 20:00:52 +02:00
|
|
|
gboolean reverse; /* sort in revers order (z->a) */
|
2011-06-19 20:03:33 +02:00
|
|
|
gboolean threads; /* show message threads */
|
2012-04-28 11:56:57 +02:00
|
|
|
|
2012-07-12 17:09:04 +02:00
|
|
|
gboolean summary; /* OBSOLETE: use summary_len */
|
2012-04-28 11:56:57 +02:00
|
|
|
int summary_len; /* max # of lines for summary */
|
|
|
|
|
2019-07-28 13:25:19 +02:00
|
|
|
gchar *bookmark; /* use bookmark */
|
2012-10-18 23:51:04 +02:00
|
|
|
gchar *formatstr; /* output type for find
|
2011-07-27 07:20:06 +02:00
|
|
|
* (plain,links,xml,json,sexp)
|
|
|
|
* and view (plain, sexp) and cfind
|
|
|
|
*/
|
|
|
|
MuConfigFormat format; /* the decoded formatstr */
|
2012-10-18 23:51:04 +02:00
|
|
|
gchar *exec; /* command to execute on the
|
2011-07-06 01:09:46 +02:00
|
|
|
* files for the matched
|
|
|
|
* messages */
|
2019-12-28 06:48:06 +01:00
|
|
|
gboolean skip_dups; /* if there are multiple
|
|
|
|
* messages with the same
|
|
|
|
* msgid, show only the first
|
|
|
|
* one */
|
|
|
|
gboolean include_related; /* included related messages
|
|
|
|
* in results */
|
2012-07-12 14:53:36 +02:00
|
|
|
/* for find and cind */
|
|
|
|
time_t after; /* only show messages or
|
2019-11-06 16:13:39 +01:00
|
|
|
* addresses last seen after
|
2012-07-12 14:53:36 +02:00
|
|
|
* T */
|
2012-08-01 16:05:24 +02:00
|
|
|
/* options for crypto
|
|
|
|
* ie, 'view', 'extract' */
|
2012-07-17 18:17:49 +02:00
|
|
|
gboolean auto_retrieve; /* assume we're online */
|
|
|
|
gboolean use_agent; /* attempt to use the gpg-agent */
|
2012-08-01 16:05:24 +02:00
|
|
|
gboolean decrypt; /* try to decrypt the
|
|
|
|
* message body, if any */
|
|
|
|
gboolean verify; /* try to crypto-verify the
|
|
|
|
* message */
|
2012-07-17 18:17:49 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
/* options for view */
|
2011-07-07 21:59:44 +02:00
|
|
|
gboolean terminator; /* add separator \f between
|
|
|
|
* multiple messages in mu
|
|
|
|
* view */
|
2012-08-01 16:05:24 +02:00
|
|
|
|
2012-07-12 14:53:36 +02:00
|
|
|
/* options for cfind (and 'find' --> "after") */
|
2012-06-20 10:28:34 +02:00
|
|
|
gboolean personal; /* only show 'personal' addresses */
|
2012-07-12 14:53:36 +02:00
|
|
|
/* also 'after' --> see above */
|
2011-08-30 20:58:35 +02:00
|
|
|
|
2011-05-22 09:25:21 +02:00
|
|
|
/* output to a maildir with symlinks */
|
2012-10-18 23:51:04 +02:00
|
|
|
gchar *linksdir; /* maildir to output symlinks */
|
2011-05-22 09:25:21 +02:00
|
|
|
gboolean clearlinks; /* clear a linksdir before filling */
|
|
|
|
mode_t dirmode; /* mode for the created maildir */
|
|
|
|
|
|
|
|
/* options for extracting parts */
|
2013-12-29 16:39:04 +01:00
|
|
|
gboolean save_all; /* extract all parts */
|
|
|
|
gboolean save_attachments; /* extract all attachment parts */
|
2011-05-22 09:25:21 +02:00
|
|
|
gchar *parts; /* comma-sep'd list of parts
|
|
|
|
* to save / open */
|
2012-10-18 23:51:04 +02:00
|
|
|
gchar *targetdir; /* where to save the attachments */
|
2011-05-22 09:25:21 +02:00
|
|
|
gboolean overwrite; /* should we overwrite same-named files */
|
2011-05-22 12:44:12 +02:00
|
|
|
gboolean play; /* after saving, try to 'play'
|
2011-08-30 20:58:35 +02:00
|
|
|
* (open) the attmnt using xdgopen */
|
2020-01-19 16:32:32 +01:00
|
|
|
/* for server */
|
2020-01-19 16:23:24 +01:00
|
|
|
gboolean commands; /* dump documentations for server
|
|
|
|
* commands */
|
2020-05-05 20:24:37 +02:00
|
|
|
gchar *eval; /* command to evaluate */
|
2020-01-19 16:32:32 +01:00
|
|
|
|
2020-05-05 20:24:37 +02:00
|
|
|
/* options for mu-script */
|
2013-12-29 16:37:07 +01:00
|
|
|
gchar *script; /* script to run */
|
2013-06-09 11:11:01 +02:00
|
|
|
const char **script_params; /* parameters for scripts */
|
2009-11-28 13:06:21 +01:00
|
|
|
};
|
2011-01-04 22:19:03 +01:00
|
|
|
typedef struct _MuConfig MuConfig;
|
2009-11-28 13:06:21 +01:00
|
|
|
|
2011-01-04 22:19:03 +01:00
|
|
|
/**
|
2012-03-13 22:06:17 +01:00
|
|
|
* initialize a mu config object
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2009-11-29 23:04:16 +01:00
|
|
|
* set default values for the configuration options; when you call
|
|
|
|
* mu_config_init, you should also call mu_config_uninit when the data
|
|
|
|
* is no longer needed.
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2012-10-24 22:47:47 +02:00
|
|
|
* Note that this is _static_ data, ie., mu_config_init will always
|
|
|
|
* return the same pointer
|
2012-03-13 22:06:17 +01:00
|
|
|
*
|
2012-10-24 22:47:47 +02:00
|
|
|
* @param argcp: pointer to argc
|
|
|
|
* @param argvp: pointer to argv
|
|
|
|
* @param err: receives error information
|
2009-11-28 13:06:21 +01:00
|
|
|
*/
|
2012-10-24 22:47:47 +02:00
|
|
|
MuConfig *mu_config_init (int *argcp, char ***argvp, GError **err)
|
2011-05-22 09:25:21 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2011-01-04 22:19:03 +01:00
|
|
|
/**
|
2012-03-13 22:06:17 +01:00
|
|
|
* free the MuConfig structure
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2011-01-04 22:19:03 +01:00
|
|
|
* @param opts a MuConfig struct, or NULL
|
2009-11-29 23:04:16 +01:00
|
|
|
*/
|
2012-03-13 22:06:17 +01:00
|
|
|
void mu_config_uninit (MuConfig *conf);
|
|
|
|
|
2009-11-29 23:04:16 +01:00
|
|
|
|
2011-01-04 22:19:03 +01:00
|
|
|
/**
|
|
|
|
* execute the command / options in this config
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2012-03-13 22:06:17 +01:00
|
|
|
* @param opts a MuConfig struct
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2011-05-22 09:25:21 +02:00
|
|
|
* @return a value denoting the success/failure of the execution;
|
2011-08-11 19:20:22 +02:00
|
|
|
* MU_ERROR_NONE (0) for success, non-zero for a failure. This is to used for
|
|
|
|
* the exit code of the process
|
2012-03-13 22:06:17 +01:00
|
|
|
*
|
2011-01-04 22:19:03 +01:00
|
|
|
*/
|
2020-06-08 22:04:05 +02:00
|
|
|
MuError mu_config_execute (const MuConfig *conf);
|
2009-11-29 23:04:16 +01:00
|
|
|
|
2011-05-26 22:35:34 +02:00
|
|
|
/**
|
|
|
|
* count the number of non-option parameters
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2012-03-13 22:06:17 +01:00
|
|
|
* @param opts a MuConfig struct
|
2011-08-30 20:58:35 +02:00
|
|
|
*
|
2011-05-26 22:35:34 +02:00
|
|
|
* @return the number of non-option parameters, or 0 in case of error
|
|
|
|
*/
|
2020-06-08 22:04:05 +02:00
|
|
|
size_t mu_config_param_num (const MuConfig *conf);
|
2011-05-26 22:35:34 +02:00
|
|
|
|
|
|
|
|
2012-08-01 16:05:24 +02:00
|
|
|
/**
|
|
|
|
* determine MuMsgOptions for command line args
|
|
|
|
*
|
|
|
|
* @param opts a MuConfig struct
|
|
|
|
*
|
|
|
|
* @return the corresponding MuMsgOptions
|
|
|
|
*/
|
2020-06-08 22:04:05 +02:00
|
|
|
MuMsgOptions mu_config_get_msg_options (const MuConfig *opts);
|
2012-08-01 16:05:24 +02:00
|
|
|
|
|
|
|
|
2012-09-17 18:53:30 +02:00
|
|
|
/**
|
|
|
|
* print help text for the current command
|
|
|
|
*
|
|
|
|
* @param cmd the command to show help for
|
|
|
|
*/
|
2020-06-08 22:04:05 +02:00
|
|
|
void mu_config_show_help (const MuConfigCmd cmd);
|
2012-09-17 18:53:30 +02:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
} // namespace Mu.
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2009-11-28 13:06:21 +01:00
|
|
|
#endif /*__MU_CONFIG_H__*/
|