1 /* 2 ** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> 3 ** 4 ** This program is free software; you can redistribute it and/or modify it 5 ** under the terms of the GNU General Public License as published by the 6 ** Free Software Foundation; either version 3, or (at your option) any 7 ** later version. 8 ** 9 ** This program is distributed in the hope that it will be useful, 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 ** GNU General Public License for more details. 13 ** 14 ** You should have received a copy of the GNU General Public License 15 ** along with this program; if not, write to the Free Software Foundation, 16 ** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 ** 18 */ 19 20 #ifndef MU_CONFIG_HH__ 21 #define MU_CONFIG_HH__ 22 23 #include <glib.h> 24 #include <sys/types.h> /* for mode_t */ 25 #include <mu-msg-fields.h> 26 #include <mu-msg.hh> 27 #include <utils/mu-util.h> 28 29 namespace Mu { 30 31 /* env var; if non-empty, color are disabled */ 32 #define MU_NOCOLOR "MU_NOCOLOR" 33 34 typedef enum { 35 MU_CONFIG_FORMAT_UNKNOWN = 0, 36 37 /* for cfind, find, view */ 38 MU_CONFIG_FORMAT_PLAIN, /* plain output */ 39 40 /* for cfind */ 41 MU_CONFIG_FORMAT_MUTT_ALIAS, /* mutt alias style */ 42 MU_CONFIG_FORMAT_MUTT_AB, /* mutt ext abook */ 43 MU_CONFIG_FORMAT_WL, /* Wanderlust abook */ 44 MU_CONFIG_FORMAT_CSV, /* comma-sep'd values */ 45 MU_CONFIG_FORMAT_ORG_CONTACT, /* org-contact */ 46 MU_CONFIG_FORMAT_BBDB, /* BBDB */ 47 MU_CONFIG_FORMAT_DEBUG, 48 49 /* for find, view */ 50 MU_CONFIG_FORMAT_SEXP, /* output sexps (emacs) */ 51 MU_CONFIG_FORMAT_JSON, /* output JSON */ 52 53 /* for find */ 54 MU_CONFIG_FORMAT_LINKS, /* output as symlinks */ 55 MU_CONFIG_FORMAT_XML, /* output xml */ 56 MU_CONFIG_FORMAT_XQUERY, /* output the xapian query */ 57 MU_CONFIG_FORMAT_MQUERY, /* output the mux query */ 58 59 MU_CONFIG_FORMAT_EXEC /* execute some command */ 60 } MuConfigFormat; 61 62 typedef enum { 63 MU_CONFIG_CMD_UNKNOWN = 0, 64 65 MU_CONFIG_CMD_ADD, 66 MU_CONFIG_CMD_CFIND, 67 MU_CONFIG_CMD_EXTRACT, 68 MU_CONFIG_CMD_FIND, 69 MU_CONFIG_CMD_HELP, 70 MU_CONFIG_CMD_INDEX, 71 MU_CONFIG_CMD_INFO, 72 MU_CONFIG_CMD_INIT, 73 MU_CONFIG_CMD_MKDIR, 74 MU_CONFIG_CMD_REMOVE, 75 MU_CONFIG_CMD_SCRIPT, 76 MU_CONFIG_CMD_SERVER, 77 MU_CONFIG_CMD_TICKLE, 78 MU_CONFIG_CMD_VERIFY, 79 MU_CONFIG_CMD_VIEW, 80 81 MU_CONFIG_CMD_NONE 82 } MuConfigCmd; 83 84 85 #define mu_config_cmd_is_valid(C) \ 86 ((C) > MU_CONFIG_CMD_UNKNOWN && (C) < MU_CONFIG_CMD_NONE) 87 88 89 /* struct with all configuration options for mu; it will be filled 90 * from the config file, and/or command line arguments */ 91 92 struct _MuConfig { 93 94 MuConfigCmd cmd; /* the command, or 95 * MU_CONFIG_CMD_NONE */ 96 char *cmdstr; /* cmd string, for user 97 * info */ 98 /* general options */ 99 gboolean quiet; /* don't give any output */ 100 gboolean debug; /* log debug-level info */ 101 gchar *muhome; /* the House of Mu */ 102 gboolean version; /* request mu version */ 103 gboolean log_stderr; /* log to stderr (not logfile) */ 104 gchar** params; /* parameters (for querying) */ 105 gboolean nocolor; /* don't use use ansi-colors 106 * in some output */ 107 gboolean verbose; /* verbose output */ 108 109 /* options for init */ 110 gchar *maildir; /* where the mails are */ 111 char** my_addresses; /* 'my e-mail address', for mu cfind; 112 * can be use multiple times */ 113 int max_msg_size; /* maximum size for message files */ 114 int batch_size; /* database transaction batch size */ 115 116 /* options for indexing */ 117 118 gboolean nocleanup; /* don't cleanup del'd mails from db */ 119 gboolean rebuild; /* empty the database before indexing */ 120 gboolean lazycheck; /* don't check dirs with up-to-date 121 * timestamps */ 122 123 124 /* options for querying 'find' (and view-> 'summary') */ 125 gchar *fields; /* fields to show in output */ 126 gchar *sortfield; /* field to sort by (string) */ 127 int maxnum; /* max # of entries to print */ 128 gboolean reverse; /* sort in revers order (z->a) */ 129 gboolean threads; /* show message threads */ 130 131 gboolean summary; /* OBSOLETE: use summary_len */ 132 int summary_len; /* max # of lines for summary */ 133 134 gchar *bookmark; /* use bookmark */ 135 gchar *formatstr; /* output type for find 136 * (plain,links,xml,json,sexp) 137 * and view (plain, sexp) and cfind 138 */ 139 MuConfigFormat format; /* the decoded formatstr */ 140 gchar *exec; /* command to execute on the 141 * files for the matched 142 * messages */ 143 gboolean skip_dups; /* if there are multiple 144 * messages with the same 145 * msgid, show only the first 146 * one */ 147 gboolean include_related; /* included related messages 148 * in results */ 149 /* for find and cind */ 150 time_t after; /* only show messages or 151 * addresses last seen after 152 * T */ 153 /* options for crypto 154 * ie, 'view', 'extract' */ 155 gboolean auto_retrieve; /* assume we're online */ 156 gboolean use_agent; /* attempt to use the gpg-agent */ 157 gboolean decrypt; /* try to decrypt the 158 * message body, if any */ 159 gboolean verify; /* try to crypto-verify the 160 * message */ 161 162 /* options for view */ 163 gboolean terminator; /* add separator \f between 164 * multiple messages in mu 165 * view */ 166 167 /* options for cfind (and 'find' --> "after") */ 168 gboolean personal; /* only show 'personal' addresses */ 169 /* also 'after' --> see above */ 170 171 /* output to a maildir with symlinks */ 172 gchar *linksdir; /* maildir to output symlinks */ 173 gboolean clearlinks; /* clear a linksdir before filling */ 174 mode_t dirmode; /* mode for the created maildir */ 175 176 /* options for extracting parts */ 177 gboolean save_all; /* extract all parts */ 178 gboolean save_attachments; /* extract all attachment parts */ 179 gchar *parts; /* comma-sep'd list of parts 180 * to save / open */ 181 gchar *targetdir; /* where to save the attachments */ 182 gboolean overwrite; /* should we overwrite same-named files */ 183 gboolean play; /* after saving, try to 'play' 184 * (open) the attmnt using xdgopen */ 185 /* for server */ 186 gboolean commands; /* dump documentations for server 187 * commands */ 188 gchar *eval; /* command to evaluate */ 189 190 /* options for mu-script */ 191 gchar *script; /* script to run */ 192 const char **script_params; /* parameters for scripts */ 193 }; 194 typedef struct _MuConfig MuConfig; 195 196 /** 197 * initialize a mu config object 198 * 199 * set default values for the configuration options; when you call 200 * mu_config_init, you should also call mu_config_uninit when the data 201 * is no longer needed. 202 * 203 * Note that this is _static_ data, ie., mu_config_init will always 204 * return the same pointer 205 * 206 * @param argcp: pointer to argc 207 * @param argvp: pointer to argv 208 * @param err: receives error information 209 */ 210 MuConfig *mu_config_init (int *argcp, char ***argvp, GError **err) 211 G_GNUC_WARN_UNUSED_RESULT; 212 /** 213 * free the MuConfig structure 214 * 215 * @param opts a MuConfig struct, or NULL 216 */ 217 void mu_config_uninit (MuConfig *conf); 218 219 220 /** 221 * execute the command / options in this config 222 * 223 * @param opts a MuConfig struct 224 * 225 * @return a value denoting the success/failure of the execution; 226 * MU_ERROR_NONE (0) for success, non-zero for a failure. This is to used for 227 * the exit code of the process 228 * 229 */ 230 MuError mu_config_execute (const MuConfig *conf); 231 232 /** 233 * count the number of non-option parameters 234 * 235 * @param opts a MuConfig struct 236 * 237 * @return the number of non-option parameters, or 0 in case of error 238 */ 239 size_t mu_config_param_num (const MuConfig *conf); 240 241 242 /** 243 * determine MuMsgOptions for command line args 244 * 245 * @param opts a MuConfig struct 246 * 247 * @return the corresponding MuMsgOptions 248 */ 249 MuMsgOptions mu_config_get_msg_options (const MuConfig *opts); 250 251 252 /** 253 * print help text for the current command 254 * 255 * @param cmd the command to show help for 256 */ 257 void mu_config_show_help (const MuConfigCmd cmd); 258 259 } // namespace Mu. 260 261 #endif /*__MU_CONFIG_H__*/ 262