2010-08-20 20:38:54 +02:00
|
|
|
/*
|
2020-02-06 19:22:43 +01:00
|
|
|
** Copyright (C) 2010-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-08-20 20:38:54 +02: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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
#include <iostream>
|
2020-06-27 10:50:02 +02:00
|
|
|
#include <iomanip>
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2010-08-22 21:50:19 +02:00
|
|
|
#include <stdlib.h>
|
2011-05-25 21:02:24 +02:00
|
|
|
#include <stdio.h>
|
2011-08-02 07:14:19 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2010-08-22 21:50:19 +02:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
#include "mu-msg.hh"
|
|
|
|
#include "mu-msg-part.hh"
|
2020-06-08 22:04:05 +02:00
|
|
|
#include "mu-cmd.hh"
|
2020-11-28 09:16:43 +01:00
|
|
|
#include "mu-maildir.hh"
|
2022-02-19 21:08:54 +01:00
|
|
|
#include "mu-contacts-cache.hh"
|
2020-11-07 13:06:23 +01:00
|
|
|
#include "mu-runtime.hh"
|
2022-03-20 13:12:41 +01:00
|
|
|
#include "message/mu-message.hh"
|
2019-12-16 20:44:35 +01:00
|
|
|
|
|
|
|
#include "utils/mu-util.h"
|
|
|
|
#include "utils/mu-str.h"
|
2011-01-05 19:38:33 +01:00
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
#include "utils/mu-error.hh"
|
|
|
|
|
2011-07-07 21:59:44 +02:00
|
|
|
#define VIEW_TERMINATOR '\f' /* form-feed */
|
2011-06-13 23:08:13 +02:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
using namespace Mu;
|
|
|
|
|
2011-07-31 11:17:14 +02:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
view_msg_sexp(MuMsg* msg, const MuConfig* opts)
|
2011-07-31 11:17:14 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
::fputs(msg_to_sexp(msg, 0, mu_config_get_msg_options(opts)).to_sexp_string().c_str(),
|
2022-03-20 13:12:41 +01:00
|
|
|
stdout);
|
2011-07-31 11:17:14 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-21 19:20:38 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
each_part(MuMsg* msg, MuMsgPart* part, gchar** attach)
|
2011-05-21 19:20:38 +02:00
|
|
|
{
|
2012-08-01 16:04:26 +02:00
|
|
|
char *fname, *tmp;
|
2011-05-21 19:20:38 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!mu_msg_part_maybe_attachment(part))
|
2012-08-01 16:04:26 +02:00
|
|
|
return;
|
2011-05-21 19:20:38 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
fname = mu_msg_part_get_filename(part, FALSE);
|
2012-08-01 16:04:26 +02:00
|
|
|
if (!fname)
|
|
|
|
return;
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmp = *attach;
|
|
|
|
*attach = g_strdup_printf("%s%s'%s'", *attach ? *attach : "", *attach ? ", " : "", fname);
|
|
|
|
g_free(tmp);
|
2011-05-21 19:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return comma-sep'd list of attachments */
|
2021-10-20 11:18:15 +02:00
|
|
|
static gchar*
|
|
|
|
get_attach_str(MuMsg* msg, const MuConfig* opts)
|
2011-05-21 19:20:38 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar* attach;
|
2016-07-24 15:00:04 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
const auto msgopts =
|
|
|
|
(MuMsgOptions)(mu_config_get_msg_options(opts) | MU_MSG_OPTION_CONSOLE_PASSWORD);
|
2011-05-21 19:20:38 +02:00
|
|
|
|
|
|
|
attach = NULL;
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_part_foreach(msg, msgopts, (MuMsgPartForeachFunc)each_part, &attach);
|
2011-05-21 19:20:38 +02:00
|
|
|
return attach;
|
2011-08-29 22:38:55 +02:00
|
|
|
}
|
2011-05-21 19:20:38 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
#define color_maybe(C) \
|
|
|
|
do { \
|
|
|
|
if (color) \
|
|
|
|
fputs((C), stdout); \
|
|
|
|
} while (0)
|
2011-05-21 19:20:38 +02:00
|
|
|
|
2011-05-25 21:02:24 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
print_field(const char* field, const char* val, gboolean color)
|
2011-05-25 21:02:24 +02:00
|
|
|
{
|
|
|
|
if (!val)
|
|
|
|
return;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_MAGENTA);
|
|
|
|
mu_util_fputs_encoded(field, stdout);
|
|
|
|
color_maybe(MU_COLOR_DEFAULT);
|
|
|
|
fputs(": ", stdout);
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-06-02 10:09:04 +02:00
|
|
|
if (val) {
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_GREEN);
|
|
|
|
mu_util_fputs_encoded(val, stdout);
|
2011-06-02 10:09:04 +02:00
|
|
|
}
|
2011-05-25 21:02:24 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_DEFAULT);
|
|
|
|
fputs("\n", stdout);
|
2011-05-25 21:02:24 +02:00
|
|
|
}
|
|
|
|
|
2012-04-28 11:56:57 +02:00
|
|
|
/* a summary_len of 0 mean 'don't show summary, show body */
|
2011-06-19 20:24:08 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
body_or_summary(MuMsg* msg, const MuConfig* opts)
|
2011-06-19 20:24:08 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
const char* body;
|
2020-06-08 22:04:05 +02:00
|
|
|
gboolean color;
|
2021-10-20 11:18:15 +02:00
|
|
|
int my_opts = mu_config_get_msg_options(opts) | MU_MSG_OPTION_CONSOLE_PASSWORD;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2012-07-22 18:39:37 +02:00
|
|
|
color = !opts->nocolor;
|
2021-10-20 11:18:15 +02:00
|
|
|
body = mu_msg_get_body_text(msg, (MuMsgOptions)my_opts);
|
2012-09-12 11:12:48 +02:00
|
|
|
if (!body) {
|
2022-03-20 13:12:41 +01:00
|
|
|
if (any_of(mu_msg_get_flags(msg) & Flags::Encrypted)) {
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_CYAN);
|
|
|
|
g_print("[No body found; "
|
2022-03-20 13:12:41 +01:00
|
|
|
"message has encrypted parts]\n");
|
2012-09-12 11:12:48 +02:00
|
|
|
} else {
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_MAGENTA);
|
|
|
|
g_print("[No body found]\n");
|
2012-09-12 11:12:48 +02:00
|
|
|
}
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_DEFAULT);
|
2012-07-27 17:04:49 +02:00
|
|
|
return;
|
2012-09-12 11:12:48 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2012-07-22 18:39:37 +02:00
|
|
|
if (opts->summary_len != 0) {
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar* summ;
|
|
|
|
summ = mu_str_summarize(body, opts->summary_len);
|
|
|
|
print_field("Summary", summ, color);
|
|
|
|
g_free(summ);
|
2011-06-19 20:24:08 +02:00
|
|
|
} else {
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_print_encoded("%s", body);
|
|
|
|
if (!g_str_has_suffix(body, "\n"))
|
|
|
|
g_print("\n");
|
2011-06-19 20:24:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-05 19:38:33 +01:00
|
|
|
/* we ignore fields for now */
|
2012-04-28 11:56:57 +02:00
|
|
|
/* summary_len == 0 means "no summary */
|
2011-01-05 19:38:33 +01:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
view_msg_plain(MuMsg* msg, const MuConfig* opts)
|
2011-01-05 19:38:33 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar* attachs;
|
|
|
|
time_t date;
|
|
|
|
const GSList* lst;
|
|
|
|
gboolean color;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2012-07-22 18:39:37 +02:00
|
|
|
color = !opts->nocolor;
|
2012-09-13 20:12:12 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
print_field("From", mu_msg_get_from(msg), color);
|
|
|
|
print_field("To", mu_msg_get_to(msg), color);
|
|
|
|
print_field("Cc", mu_msg_get_cc(msg), color);
|
|
|
|
print_field("Bcc", mu_msg_get_bcc(msg), color);
|
|
|
|
print_field("Subject", mu_msg_get_subject(msg), color);
|
|
|
|
|
2022-02-22 21:48:29 +01:00
|
|
|
if ((date = mu_msg_get_date(msg))) {
|
|
|
|
const auto dstr{time_to_string("%c", date)};
|
|
|
|
print_field("Date", dstr.c_str(), color);
|
|
|
|
}
|
2021-10-20 11:18:15 +02:00
|
|
|
|
|
|
|
if ((lst = mu_msg_get_tags(msg))) {
|
|
|
|
gchar* tags;
|
|
|
|
tags = mu_str_from_list(lst, ',');
|
|
|
|
print_field("Tags", tags, color);
|
|
|
|
g_free(tags);
|
2011-06-16 07:14:07 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if ((attachs = get_attach_str(msg, opts))) {
|
|
|
|
print_field("Attachments", attachs, color);
|
|
|
|
g_free(attachs);
|
2011-05-21 19:20:38 +02:00
|
|
|
}
|
2011-06-19 20:24:08 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
body_or_summary(msg, opts);
|
2011-06-19 20:24:08 +02:00
|
|
|
|
2011-01-05 19:38:33 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-08-09 06:52:55 +02:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
handle_msg(const char* fname, const MuConfig* opts, GError** err)
|
2011-06-13 23:08:13 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
2011-08-09 06:52:55 +02:00
|
|
|
gboolean rv;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
msg = mu_msg_new_from_file(fname, NULL, err);
|
2011-09-03 09:44:36 +02:00
|
|
|
if (!msg)
|
2011-08-09 06:52:55 +02:00
|
|
|
return FALSE;
|
2011-07-31 11:17:14 +02:00
|
|
|
|
|
|
|
switch (opts->format) {
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_FORMAT_PLAIN: rv = view_msg_plain(msg, opts); break;
|
|
|
|
case MU_CONFIG_FORMAT_SEXP: rv = view_msg_sexp(msg, opts); break;
|
|
|
|
default: g_critical("bug: should not be reached"); rv = FALSE;
|
2011-07-31 11:17:14 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2011-06-13 23:08:13 +02:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
view_params_valid(const MuConfig* opts, GError** err)
|
2011-07-27 07:20:06 +02:00
|
|
|
{
|
|
|
|
/* note: params[0] will be 'view' */
|
|
|
|
if (!opts->params[0] || !opts->params[1]) {
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "error in parameters");
|
2011-07-27 07:20:06 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
switch (opts->format) {
|
|
|
|
case MU_CONFIG_FORMAT_PLAIN:
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_FORMAT_SEXP: break;
|
2011-07-27 07:20:06 +02:00
|
|
|
default:
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "invalid output format");
|
2011-07-27 07:20:06 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-07-27 07:20:06 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_view(const MuConfig* opts, GError** err)
|
2011-01-05 19:38:33 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
int i;
|
2011-08-09 06:52:55 +02:00
|
|
|
gboolean rv;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
|
|
|
g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_VIEW, MU_ERROR_INTERNAL);
|
2011-07-27 07:20:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = view_params_valid(opts, err);
|
2011-09-03 09:44:36 +02:00
|
|
|
if (!rv)
|
|
|
|
goto leave;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-09-03 09:44:36 +02:00
|
|
|
for (i = 1; opts->params[i]; ++i) {
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = handle_msg(opts->params[i], opts, err);
|
2011-08-09 06:52:55 +02:00
|
|
|
if (!rv)
|
2011-06-13 23:08:13 +02:00
|
|
|
break;
|
2011-09-03 09:44:36 +02:00
|
|
|
|
2011-06-13 23:08:13 +02:00
|
|
|
/* add a separator between two messages? */
|
2011-07-07 21:59:44 +02:00
|
|
|
if (opts->terminator)
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("%c", VIEW_TERMINATOR);
|
2011-01-05 19:38:33 +01:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-09-03 09:44:36 +02:00
|
|
|
leave:
|
|
|
|
if (!rv)
|
2020-06-08 22:04:05 +02:00
|
|
|
return err && *err ? (MuError)(*err)->code : MU_ERROR;
|
2011-09-03 09:44:36 +02:00
|
|
|
|
|
|
|
return MU_OK;
|
2011-01-05 19:38:33 +01:00
|
|
|
}
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_mkdir(const MuConfig* opts, GError** err)
|
2011-01-05 19:38:33 +01:00
|
|
|
{
|
|
|
|
int i;
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
|
|
|
g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_MKDIR, MU_ERROR_INTERNAL);
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-01-05 19:38:33 +01:00
|
|
|
if (!opts->params[1]) {
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "missing directory parameter");
|
2011-08-11 19:20:22 +02:00
|
|
|
return MU_ERROR_IN_PARAMETERS;
|
2011-01-05 19:38:33 +01:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2022-02-16 22:03:48 +01:00
|
|
|
for (i = 1; opts->params[i]; ++i) {
|
|
|
|
if (auto&& res{mu_maildir_mkdir(opts->params[i],
|
|
|
|
opts->dirmode, FALSE)}; !res) {
|
|
|
|
g_set_error(err, MU_ERROR_DOMAIN, MU_ERROR_FILE,
|
|
|
|
"%s", res.error().what());
|
|
|
|
return MU_ERROR_FILE_CANNOT_MKDIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-11 19:20:22 +02:00
|
|
|
return MU_OK;
|
2011-01-05 19:38:33 +01:00
|
|
|
}
|
2011-03-02 22:26:54 +01:00
|
|
|
|
2011-08-02 20:27:32 +02:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
check_file_okay(const char* path, gboolean cmd_add)
|
2011-08-03 22:00:48 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!g_path_is_absolute(path)) {
|
|
|
|
g_printerr("path is not absolute: %s\n", path);
|
2011-08-03 22:00:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-08-11 07:22:24 +02:00
|
|
|
if (cmd_add && access(path, R_OK) != 0) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_printerr("path is not readable: %s: %s\n", path, g_strerror(errno));
|
2011-08-03 22:00:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
typedef bool (*ForeachMsgFunc)(Mu::Store& store, const char* path, GError** err);
|
2017-01-14 11:32:20 +01:00
|
|
|
|
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
foreach_msg_file(Mu::Store& store, const MuConfig* opts, ForeachMsgFunc foreach_func, GError** err)
|
2017-01-14 11:32:20 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
unsigned u;
|
|
|
|
gboolean all_ok;
|
2011-08-03 22:00:48 +02:00
|
|
|
|
|
|
|
/* note: params[0] will be 'add' */
|
|
|
|
if (!opts->params[0] || !opts->params[1]) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("usage: mu %s <file> [<files>]\n",
|
2022-03-20 13:12:41 +01:00
|
|
|
opts->params[0] ? opts->params[0] : "<cmd>");
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "missing parameters");
|
2011-08-11 19:20:22 +02:00
|
|
|
return MU_ERROR_IN_PARAMETERS;
|
2011-08-02 20:27:32 +02:00
|
|
|
}
|
|
|
|
|
2017-01-14 11:32:20 +01:00
|
|
|
for (u = 1, all_ok = TRUE; opts->params[u]; ++u) {
|
|
|
|
const char* path;
|
|
|
|
|
|
|
|
path = opts->params[u];
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!check_file_okay(path, TRUE)) {
|
2017-01-14 11:32:20 +01:00
|
|
|
all_ok = FALSE;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_printerr("not a valid message file: %s\n", path);
|
2017-01-14 11:32:20 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-08-10 22:57:34 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!foreach_func(store, path, err)) {
|
2017-01-14 11:32:20 +01:00
|
|
|
all_ok = FALSE;
|
2021-10-20 11:18:15 +02:00
|
|
|
g_printerr("error with %s: %s\n",
|
2022-03-20 13:12:41 +01:00
|
|
|
path,
|
|
|
|
(err && *err) ? (*err)->message : "something went wrong");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_clear_error(err);
|
2017-01-14 11:32:20 +01:00
|
|
|
continue;
|
2011-08-10 22:57:34 +02:00
|
|
|
}
|
2011-09-03 09:44:36 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2017-01-14 11:32:20 +01:00
|
|
|
if (!all_ok) {
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_g_set_error(err,
|
2022-03-20 13:12:41 +01:00
|
|
|
MU_ERROR_XAPIAN_STORE_FAILED,
|
|
|
|
"%s failed for some message(s)",
|
|
|
|
opts->params[0]);
|
2011-09-03 09:44:36 +02:00
|
|
|
return MU_ERROR_XAPIAN_STORE_FAILED;
|
2011-08-10 22:57:34 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2011-09-03 09:44:36 +02:00
|
|
|
return MU_OK;
|
2011-08-02 20:27:32 +02:00
|
|
|
}
|
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
static bool
|
2021-10-20 11:18:15 +02:00
|
|
|
add_path_func(Mu::Store& store, const char* path, GError** err)
|
2011-08-10 22:57:34 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
const auto docid = store.add_message(path);
|
|
|
|
g_debug("added message @ %s, docid=%u", path, docid);
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return true;
|
2017-01-14 11:32:20 +01:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_add(Mu::Store& store, const MuConfig* opts, GError** err)
|
2017-01-14 11:32:20 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
|
|
|
g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_ADD, MU_ERROR_INTERNAL);
|
2011-08-02 20:27:32 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return foreach_msg_file(store, opts, add_path_func, err);
|
2017-01-14 11:32:20 +01:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
static bool
|
2021-10-20 11:18:15 +02:00
|
|
|
remove_path_func(Mu::Store& store, const char* path, GError** err)
|
2017-01-14 11:32:20 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
const auto res = store.remove_message(path);
|
|
|
|
g_debug("removed %s (%s)", path, res ? "yes" : "no");
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return true;
|
2011-08-01 21:42:23 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_remove(Mu::Store& store, const MuConfig* opts, GError** err)
|
2017-01-14 11:32:20 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
|
|
|
g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_REMOVE, MU_ERROR_INTERNAL);
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return foreach_msg_file(store, opts, remove_path_func, err);
|
2017-01-14 11:32:20 +01:00
|
|
|
}
|
2012-07-17 18:17:49 +02:00
|
|
|
|
2012-08-30 19:26:35 +02:00
|
|
|
struct _VData {
|
|
|
|
MuMsgPartSigStatus combined_status;
|
2021-10-20 11:18:15 +02:00
|
|
|
char* report;
|
|
|
|
gboolean oneline;
|
2012-08-30 19:26:35 +02:00
|
|
|
};
|
|
|
|
typedef struct _VData VData;
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
each_sig(MuMsg* msg, MuMsgPart* part, VData* vdata)
|
2012-07-17 18:17:49 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsgPartSigStatusReport* report;
|
2012-09-19 10:36:02 +02:00
|
|
|
|
2012-08-30 19:26:35 +02:00
|
|
|
report = part->sig_status_report;
|
|
|
|
if (!report)
|
|
|
|
return;
|
|
|
|
|
2012-09-19 10:36:02 +02:00
|
|
|
if (vdata->oneline)
|
2021-10-20 11:18:15 +02:00
|
|
|
vdata->report = g_strdup_printf("%s%s%s",
|
2022-03-20 13:12:41 +01:00
|
|
|
vdata->report ? vdata->report : "",
|
|
|
|
vdata->report ? "; " : "",
|
|
|
|
report->report);
|
2012-09-19 10:36:02 +02:00
|
|
|
else
|
2021-10-20 11:18:15 +02:00
|
|
|
vdata->report = g_strdup_printf("%s%s\t%s",
|
2022-03-20 13:12:41 +01:00
|
|
|
vdata->report ? vdata->report : "",
|
|
|
|
vdata->report ? "\n" : "",
|
|
|
|
report->report);
|
2012-08-30 19:26:35 +02:00
|
|
|
|
|
|
|
if (vdata->combined_status == MU_MSG_PART_SIG_STATUS_BAD ||
|
|
|
|
vdata->combined_status == MU_MSG_PART_SIG_STATUS_ERROR)
|
2012-07-17 18:17:49 +02:00
|
|
|
return;
|
|
|
|
|
2012-08-30 19:26:35 +02:00
|
|
|
vdata->combined_status = report->verdict;
|
2012-07-17 18:17:49 +02:00
|
|
|
}
|
|
|
|
|
2012-08-30 19:26:35 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
print_verdict(VData* vdata, gboolean color, gboolean verbose)
|
2012-08-30 19:26:35 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("verdict: ");
|
2012-08-30 19:26:35 +02:00
|
|
|
|
|
|
|
switch (vdata->combined_status) {
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_MSG_PART_SIG_STATUS_UNSIGNED: g_print("no signature found"); break;
|
2012-08-30 19:26:35 +02:00
|
|
|
case MU_MSG_PART_SIG_STATUS_GOOD:
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_GREEN);
|
|
|
|
g_print("signature(s) verified");
|
2012-08-30 19:26:35 +02:00
|
|
|
break;
|
|
|
|
case MU_MSG_PART_SIG_STATUS_BAD:
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_RED);
|
|
|
|
g_print("bad signature");
|
2012-08-30 19:26:35 +02:00
|
|
|
break;
|
|
|
|
case MU_MSG_PART_SIG_STATUS_ERROR:
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_RED);
|
|
|
|
g_print("verification failed");
|
2012-08-30 19:26:35 +02:00
|
|
|
break;
|
|
|
|
case MU_MSG_PART_SIG_STATUS_FAIL:
|
2012-09-19 10:36:02 +02:00
|
|
|
color_maybe(MU_COLOR_RED);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("error in verification process");
|
2012-08-30 19:26:35 +02:00
|
|
|
break;
|
2021-10-20 11:18:15 +02:00
|
|
|
default: g_return_if_reached();
|
2012-08-30 19:26:35 +02:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
color_maybe(MU_COLOR_DEFAULT);
|
2015-06-14 10:40:07 +02:00
|
|
|
if (vdata->report && verbose)
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("%s%s\n", (vdata->oneline) ? ";" : "\n", vdata->report);
|
2015-06-14 10:40:07 +02:00
|
|
|
else
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("\n");
|
2012-08-30 19:26:35 +02:00
|
|
|
}
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_verify(const MuConfig* opts, GError** err)
|
2012-07-17 18:17:49 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
2020-06-08 22:04:05 +02:00
|
|
|
int msgopts;
|
|
|
|
VData vdata;
|
2012-07-17 18:17:49 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
|
|
|
g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_VERIFY, MU_ERROR_INTERNAL);
|
2012-07-17 18:17:49 +02:00
|
|
|
|
2012-09-09 13:07:34 +02:00
|
|
|
if (!opts->params[1]) {
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "missing message-file parameter");
|
2012-09-09 13:07:34 +02:00
|
|
|
return MU_ERROR_IN_PARAMETERS;
|
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
msg = mu_msg_new_from_file(opts->params[1], NULL, err);
|
2012-07-17 18:17:49 +02:00
|
|
|
if (!msg)
|
|
|
|
return MU_ERROR;
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
msgopts =
|
|
|
|
mu_config_get_msg_options(opts) | MU_MSG_OPTION_VERIFY | MU_MSG_OPTION_CONSOLE_PASSWORD;
|
2012-09-19 10:36:02 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
vdata.report = NULL;
|
2012-08-30 19:26:35 +02:00
|
|
|
vdata.combined_status = MU_MSG_PART_SIG_STATUS_UNSIGNED;
|
2021-10-20 11:18:15 +02:00
|
|
|
vdata.oneline = FALSE;
|
2012-09-19 10:36:02 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_part_foreach(msg, (MuMsgOptions)msgopts, (MuMsgPartForeachFunc)each_sig, &vdata);
|
2012-08-30 11:53:52 +02:00
|
|
|
|
2012-08-30 19:26:35 +02:00
|
|
|
if (!opts->quiet)
|
2021-10-20 11:18:15 +02:00
|
|
|
print_verdict(&vdata, !opts->nocolor, opts->verbose);
|
2012-07-18 09:30:23 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
|
|
|
g_free(vdata.report);
|
2012-07-17 18:17:49 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return vdata.combined_status == MU_MSG_PART_SIG_STATUS_GOOD ? MU_OK : MU_ERROR;
|
2012-07-17 18:17:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-27 10:50:02 +02:00
|
|
|
template <typename T>
|
2021-10-20 11:18:15 +02:00
|
|
|
static void
|
|
|
|
key_val(const Mu::MaybeAnsi& col, const std::string& key, T val)
|
2020-06-27 10:50:02 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
using Color = Mu::MaybeAnsi::Color;
|
2020-06-27 10:50:02 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
std::cout << col.fg(Color::BrightBlue) << std::left << std::setw(18) << key << col.reset()
|
|
|
|
<< ": ";
|
2020-06-27 10:50:02 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
std::cout << col.fg(Color::Green) << val << col.reset() << "\n";
|
2020-06-27 10:50:02 +02:00
|
|
|
}
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_info(const Mu::Store& store, const MuConfig* opts, GError** err)
|
2020-02-06 19:22:43 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::MaybeAnsi col{!opts->nocolor};
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2022-02-13 13:52:41 +01:00
|
|
|
key_val(col, "maildir", store.properties().root_maildir);
|
|
|
|
key_val(col, "database-path", store.properties().database_path);
|
|
|
|
key_val(col, "schema-version", store.properties().schema_version);
|
|
|
|
key_val(col, "max-message-size", store.properties().max_message_size);
|
|
|
|
key_val(col, "batch-size", store.properties().batch_size);
|
2021-10-20 11:18:15 +02:00
|
|
|
key_val(col, "messages in store", store.size());
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2022-02-13 13:52:41 +01:00
|
|
|
const auto created{store.properties().created};
|
2021-10-20 11:18:15 +02:00
|
|
|
const auto tstamp{::localtime(&created)};
|
2020-06-08 22:04:05 +02:00
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wformat-y2k"
|
2021-10-20 11:18:15 +02:00
|
|
|
char tbuf[64];
|
|
|
|
strftime(tbuf, sizeof(tbuf), "%c", tstamp);
|
2020-06-08 22:04:05 +02:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
key_val(col, "created", tbuf);
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2022-02-13 13:52:41 +01:00
|
|
|
const auto addrs{store.properties().personal_addresses};
|
2021-10-20 11:18:15 +02:00
|
|
|
if (addrs.empty())
|
|
|
|
key_val(col, "personal-address", "<none>");
|
|
|
|
else
|
|
|
|
for (auto&& c : addrs)
|
|
|
|
key_val(col, "personal-address", c);
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return MU_OK;
|
2020-02-06 19:22:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_init(const MuConfig* opts, GError** err)
|
2020-02-06 19:22:43 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
/* not provided, nor could we find a good default */
|
|
|
|
if (!opts->maildir) {
|
|
|
|
mu_util_g_set_error(err,
|
2022-03-20 13:12:41 +01:00
|
|
|
MU_ERROR_IN_PARAMETERS,
|
|
|
|
"missing --maildir parameter and could "
|
|
|
|
"not determine default");
|
2020-02-09 21:40:57 +01:00
|
|
|
return MU_ERROR_IN_PARAMETERS;
|
2021-10-20 11:18:15 +02:00
|
|
|
}
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (opts->max_msg_size < 0) {
|
|
|
|
mu_util_g_set_error(err,
|
2022-03-20 13:12:41 +01:00
|
|
|
MU_ERROR_IN_PARAMETERS,
|
|
|
|
"invalid value for max-message-size");
|
2020-06-27 10:50:02 +02:00
|
|
|
return MU_ERROR_IN_PARAMETERS;
|
2021-10-20 11:18:15 +02:00
|
|
|
} else if (opts->batch_size < 0) {
|
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "invalid value for batch-size");
|
2020-06-27 10:50:02 +02:00
|
|
|
return MU_ERROR_IN_PARAMETERS;
|
2021-10-20 11:18:15 +02:00
|
|
|
}
|
2020-06-27 10:50:02 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::Store::Config conf{};
|
|
|
|
conf.max_message_size = opts->max_msg_size;
|
|
|
|
conf.batch_size = opts->batch_size;
|
2020-06-27 10:50:02 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::StringVec my_addrs;
|
|
|
|
auto addrs = opts->my_addresses;
|
|
|
|
while (addrs && *addrs) {
|
|
|
|
my_addrs.emplace_back(*addrs);
|
|
|
|
++addrs;
|
|
|
|
}
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::Store store(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), opts->maildir, my_addrs, conf);
|
2020-02-06 19:22:43 +01:00
|
|
|
if (!opts->quiet) {
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_info(store, opts, NULL);
|
2020-06-27 10:50:02 +02:00
|
|
|
std::cout << "\nstore created; use the 'index' command to fill/update it.\n";
|
2020-02-06 19:22:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return MU_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
cmd_find(const MuConfig* opts, GError** err)
|
2020-06-08 22:04:05 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), true /*readonly*/};
|
2020-06-08 22:04:05 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return mu_cmd_find(store, opts, err);
|
2020-06-08 22:04:05 +02:00
|
|
|
}
|
2012-07-17 18:17:49 +02:00
|
|
|
|
2011-08-30 20:57:59 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
show_usage(void)
|
2011-08-30 20:57:59 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("usage: mu command [options] [parameters]\n");
|
|
|
|
g_print("where command is one of index, find, cfind, view, mkdir, "
|
2022-03-20 13:12:41 +01:00
|
|
|
"extract, add, remove, script, verify or server\n");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("see the mu, mu-<command> or mu-easy manpages for "
|
2022-03-20 13:12:41 +01:00
|
|
|
"more information\n");
|
2011-08-30 20:57:59 +02:00
|
|
|
}
|
2011-08-29 22:38:55 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
typedef MuError (*readonly_store_func)(const Mu::Store&, const MuConfig*, GError** err);
|
|
|
|
typedef MuError (*writable_store_func)(Mu::Store&, const MuConfig*, GError** err);
|
2019-07-28 13:25:19 +02:00
|
|
|
|
2020-02-04 20:14:30 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
with_readonly_store(readonly_store_func func, const MuConfig* opts, GError** err)
|
2020-02-04 20:14:30 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
const Mu::Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), true /*readonly*/};
|
|
|
|
return func(store, opts, err);
|
2020-02-04 20:14:30 +01:00
|
|
|
}
|
|
|
|
|
2020-02-06 19:22:43 +01:00
|
|
|
static MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
with_writable_store(writable_store_func func, const MuConfig* opts, GError** err)
|
2011-08-30 20:57:59 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), false /*!readonly*/};
|
|
|
|
return func(store, opts, err);
|
2020-02-03 16:38:12 +01:00
|
|
|
}
|
|
|
|
|
2012-09-13 20:12:12 +02:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
check_params(const MuConfig* opts, GError** err)
|
2011-09-03 09:44:36 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!opts->params || !opts->params[0]) { /* no command? */
|
|
|
|
show_usage();
|
|
|
|
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "error in parameters");
|
2011-09-03 09:44:36 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-08-30 20:57:59 +02:00
|
|
|
MuError
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::mu_cmd_execute(const MuConfig* opts, GError** err)
|
|
|
|
try {
|
2012-09-09 13:07:34 +02:00
|
|
|
MuError merr;
|
2012-09-14 09:06:14 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
2011-08-30 20:57:59 +02:00
|
|
|
|
2011-09-03 09:44:36 +02:00
|
|
|
if (!check_params(opts, err))
|
|
|
|
return MU_G_ERROR_CODE(err);
|
2011-08-30 20:57:59 +02:00
|
|
|
|
|
|
|
switch (opts->cmd) {
|
2012-07-19 19:45:06 +02:00
|
|
|
/* already handled in mu-config.c */
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_CMD_HELP:
|
|
|
|
return MU_OK;
|
2012-07-19 19:45:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
/* no store needed */
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_CMD_MKDIR: merr = cmd_mkdir(opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_SCRIPT: merr = mu_cmd_script(opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_VIEW: merr = cmd_view(opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_VERIFY: merr = cmd_verify(opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_EXTRACT:
|
2022-03-28 21:36:32 +02:00
|
|
|
if (const auto res{mu_cmd_extract(opts)}; !res) {
|
|
|
|
res.error().fill_g_error(err);
|
|
|
|
merr = MU_ERROR;
|
|
|
|
} else
|
|
|
|
merr = MU_OK;
|
2021-10-20 11:18:15 +02:00
|
|
|
break;
|
|
|
|
/* read-only store */
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_CMD_CFIND: merr = with_readonly_store(mu_cmd_cfind, opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_FIND: merr = cmd_find(opts, err); break;
|
2020-02-06 19:22:43 +01:00
|
|
|
case MU_CONFIG_CMD_INFO:
|
2021-10-20 11:18:15 +02:00
|
|
|
merr = with_readonly_store(cmd_info, opts, err);
|
|
|
|
break;
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
/* writable store */
|
2020-02-04 20:14:30 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_CMD_ADD: merr = with_writable_store(cmd_add, opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_REMOVE: merr = with_writable_store(cmd_remove, opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_INDEX: merr = with_writable_store(mu_cmd_index, opts, err); break;
|
2020-02-06 19:22:43 +01:00
|
|
|
|
|
|
|
/* commands instantiate store themselves */
|
2021-10-20 11:18:15 +02:00
|
|
|
case MU_CONFIG_CMD_INIT: merr = cmd_init(opts, err); break;
|
|
|
|
case MU_CONFIG_CMD_SERVER: merr = mu_cmd_server(opts, err); break;
|
2020-02-06 19:22:43 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
default: merr = MU_ERROR_IN_PARAMETERS; break;
|
2011-08-30 20:57:59 +02:00
|
|
|
}
|
2012-09-09 13:07:34 +02:00
|
|
|
|
|
|
|
return merr;
|
2020-06-08 22:04:05 +02:00
|
|
|
|
|
|
|
} catch (const Mu::Error& er) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_set_error(err, MU_ERROR_DOMAIN, MU_ERROR, "%s", er.what());
|
|
|
|
return MU_ERROR;
|
2020-06-08 22:04:05 +02:00
|
|
|
} catch (...) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_set_error(err, MU_ERROR_DOMAIN, MU_ERROR, "%s", "caught exception");
|
|
|
|
return MU_ERROR;
|
2011-08-30 20:57:59 +02:00
|
|
|
}
|