summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mu/mu-cmd-find.cc180
-rw-r--r--mu/mu-cmd-index.cc15
-rw-r--r--mu/mu-cmd.cc7
-rw-r--r--mu/mu-config.cc285
-rw-r--r--mu/mu-config.hh10
-rw-r--r--mu/tests/test-mu-query.cc12
6 files changed, 217 insertions, 292 deletions
diff --git a/mu/mu-cmd-find.cc b/mu/mu-cmd-find.cc
index 0f19ae6..1f653a3 100644
--- a/mu/mu-cmd-find.cc
+++ b/mu/mu-cmd-find.cc
@@ -28,8 +28,7 @@
#include <stdlib.h>
#include <signal.h>
-#include "message/mu-fields.hh"
-#include "mu-msg.hh"
+#include "message/mu-message.hh"
#include "mu-maildir.hh"
#include "mu-query-match-deciders.hh"
#include "mu-query.hh"
@@ -56,7 +55,8 @@ struct OutputInfo {
constexpr auto FirstOutput{OutputInfo{0, true, false, {}, {}}};
constexpr auto LastOutput{OutputInfo{0, false, true, {}, {}}};
-using OutputFunc = std::function<bool(MuMsg*, const OutputInfo&, const MuConfig*, GError**)>;
+using OutputFunc = std::function<bool(const Option<Message>& msg, const OutputInfo&,
+ const MuConfig*, GError**)>;
static gboolean
print_internal(const Store& store,
@@ -95,13 +95,16 @@ run_query(const Store& store, const std::string& expr, const MuConfig* opts,
}
static gboolean
-exec_cmd(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** err)
+exec_cmd(const Option<Message>& msg, const OutputInfo& info, const MuConfig* opts, GError** err)
{
+ if (!msg)
+ return TRUE;
+
gint status;
char * cmdline, *escpath;
gboolean rv;
- escpath = g_shell_quote(mu_msg_get_path(msg));
+ escpath = g_shell_quote(msg->path().c_str());
cmdline = g_strdup_printf("%s %s", opts->exec, escpath);
rv = g_spawn_command_line_sync(cmdline, NULL, NULL, &status, err);
@@ -201,14 +204,16 @@ prepare_links(const MuConfig* opts, GError** err)
}
static bool
-output_link(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** err)
+output_link(const Option<Message>& msg, const OutputInfo& info, const MuConfig* opts, GError** err)
{
+ if (msg)
+ return true;
+
if (info.header)
return prepare_links(opts, err);
else if (info.footer)
return true;
- if (auto&& res = mu_maildir_link(
- mu_msg_get_path(msg), opts->linksdir); !res) {
+ if (auto&& res = mu_maildir_link(msg->path(), opts->linksdir); !res) {
res.error().fill_g_error(err);
return FALSE;
}
@@ -251,97 +256,46 @@ ansi_reset_maybe(Field::Id field_id, gboolean color)
fputs(MU_COLOR_DEFAULT, stdout);
}
-static const char*
-field_string_list(MuMsg* msg, Field::Id field_id)
-{
- char* str;
- const GSList* lst;
- static char buf[80];
-
- lst = mu_msg_get_field_string_list(msg, field_id);
- if (!lst)
- return NULL;
-
- str = mu_str_from_list(lst, ',');
- if (str) {
- strncpy(buf, str, sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = '\0';
- g_free(str);
- return buf;
- }
-
- return NULL;
-}
-
-/* ugly... for backward compat */
-static const char*
-flags_s(Flags flags)
-{
- static char buf[64];
- const auto flagstr{to_string(flags)};
-
- ::strncpy(buf, flagstr.c_str(), sizeof(buf) - 1);
-
- return buf;
-}
-
static std::string
-display_field(MuMsg* msg, Field::Id field_id)
+display_field(const Message& msg, Field::Id field_id)
{
- gint64 val;
-
switch (field_from_id(field_id).type) {
- case Field::Type::String: {
- const gchar* str;
- str = mu_msg_get_field_string(msg, field_id);
- return str ? str : "";
- }
+ case Field::Type::String:
+ return msg.document().string_value(field_id);
case Field::Type::Integer:
if (field_id == Field::Id::Priority) {
- const auto val = static_cast<char>(mu_msg_get_field_numeric(msg, field_id));
- const auto prio = priority_from_char(val);
- return priority_name_c_str(prio);
+ return to_string(msg.priority());
} else if (field_id == Field::Id::Flags) {
- val = mu_msg_get_field_numeric(msg, field_id);
- return flags_s(static_cast<Flags>(val));
+ return to_string(msg.flags());
} else /* as string */
- return mu_msg_get_field_string(msg, field_id);
-
+ return msg.document().string_value(field_id);
case Field::Type::TimeT:
return time_to_string(
- "%c", static_cast<::time_t>(mu_msg_get_field_numeric(msg, field_id)));
+ "%c", static_cast<::time_t>(msg.document().integer_value(field_id)));
case Field::Type::ByteSize:
- val = mu_msg_get_field_numeric(msg, field_id);
- return mu_str_size_s((unsigned)val);
- case Field::Type::StringList: {
- const char* str;
- str = field_string_list(msg, field_id);
- return str ? str : "";
- }
- default: g_return_val_if_reached(NULL);
+ return to_string(msg.document().integer_value(field_id));
+ case Field::Type::StringList:
+ return join(msg.document().string_vec_value(field_id), ',');
+ default:
+ g_return_val_if_reached("");
+ return "";
}
}
static void
-print_summary(MuMsg* msg, const MuConfig* opts)
+print_summary(const Message& msg, const MuConfig* opts)
{
- const char* body;
- char* summ;
- MuMsgOptions msgopts;
-
- msgopts = mu_config_get_msg_options(opts);
- body = mu_msg_get_body_text(msg, msgopts);
+ const auto body{msg.body_text()};
+ if (!body)
+ return;
- if (body)
- summ = mu_str_summarize(body, (unsigned)opts->summary_len);
- else
- summ = NULL;
+ const auto summ{to_string_opt_gchar(
+ mu_str_summarize(body->c_str(),
+ opts->summary_len))};
g_print("Summary: ");
- mu_util_fputs_encoded(summ ? summ : "<none>", stdout);
+ mu_util_fputs_encoded(summ ? summ->c_str() : "<none>", stdout);
g_print("\n");
-
- g_free(summ);
}
static void
@@ -376,7 +330,8 @@ thread_indent(const QueryMatch& info, const MuConfig* opts)
}
static void
-output_plain_fields(MuMsg* msg, const char* fields, gboolean color, gboolean threads)
+output_plain_fields(const Message& msg, const char* fields,
+ gboolean color, gboolean threads)
{
const char* myfields;
int nonempty;
@@ -401,7 +356,8 @@ output_plain_fields(MuMsg* msg, const char* fields, gboolean color, gboolean thr
}
static gboolean
-output_plain(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** err)
+output_plain(const Option<Message>& msg, const OutputInfo& info,
+ const MuConfig* opts, GError** err)
{
if (!msg)
return true;
@@ -412,10 +368,10 @@ output_plain(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError**
if (opts->threads && info.match_info)
thread_indent(*info.match_info, opts);
- output_plain_fields(msg, opts->fields, !opts->nocolor, opts->threads);
+ output_plain_fields(*msg, opts->fields, !opts->nocolor, opts->threads);
if (opts->summary_len > 0)
- print_summary(msg, opts);
+ print_summary(*msg, opts);
return TRUE;
}
@@ -462,27 +418,28 @@ to_string(const Mu::Sexp& sexp, bool color, size_t level = 0)
: Color::BrightBlue))
<< sexp.value() << col.reset();
break;
- default: throw std::logic_error("invalid type");
+ default:
+ throw std::logic_error("invalid type");
}
return sstrm.str();
}
static bool
-output_sexp(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** err)
+output_sexp(const Option<Message>& msg, const OutputInfo& info, const MuConfig* opts, GError** err)
{
- if (!msg)
- return true;
-
- fputs(msg_to_sexp(msg, 0, MU_MSG_OPTION_HEADERS_ONLY).to_sexp_string().c_str(), stdout);
+ fputs(msg->to_sexp().to_sexp_string().c_str(), stdout);
fputs("\n", stdout);
return true;
}
static bool
-output_json(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** err)
+output_json(const Option<Message>& msg, const OutputInfo& info, const MuConfig* opts, GError** err)
{
+ if (!msg)
+ return true;
+
if (info.header) {
g_print("[\n");
return true;
@@ -494,27 +451,24 @@ output_json(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** e
}
g_print("%s%s\n",
- msg_to_sexp(msg, info.docid, MU_MSG_OPTION_HEADERS_ONLY).to_json_string().c_str(),
+ msg->to_sexp().to_json_string().c_str(),
info.last ? "" : ",");
return true;
}
static void
-print_attr_xml(const char* elm, const char* str)
+print_attr_xml(const std::string& elm, const std::string& str)
{
- gchar* esc;
-
- if (mu_str_is_empty(str))
+ if (str.empty())
return; /* empty: don't include */
- esc = g_markup_escape_text(str, -1);
- g_print("\t\t<%s>%s</%s>\n", elm, esc, elm);
- g_free(esc);
+ auto&& esc{to_string_opt_gchar(g_markup_escape_text(str.c_str(), -1))};
+ g_print("\t\t<%s>%s</%s>\n", elm.c_str(), esc.value_or("").c_str(), elm.c_str());
}
static bool
-output_xml(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** err)
+output_xml(const Option<Message>& msg, const OutputInfo& info, const MuConfig* opts, GError** err)
{
if (info.header) {
g_print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
@@ -528,15 +482,15 @@ output_xml(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** er
}
g_print("\t<message>\n");
- print_attr_xml("from", mu_msg_get_from(msg));
- print_attr_xml("to", mu_msg_get_to(msg));
- print_attr_xml("cc", mu_msg_get_cc(msg));
- print_attr_xml("subject", mu_msg_get_subject(msg));
- g_print("\t\t<date>%u</date>\n", (unsigned)mu_msg_get_date(msg));
- g_print("\t\t<size>%u</size>\n", (unsigned)mu_msg_get_size(msg));
- print_attr_xml("msgid", mu_msg_get_msgid(msg));
- print_attr_xml("path", mu_msg_get_path(msg));
- print_attr_xml("maildir", mu_msg_get_maildir(msg));
+ print_attr_xml("from", to_string(msg->from()));
+ print_attr_xml("to", to_string(msg->to()));
+ print_attr_xml("cc", to_string(msg->cc()));
+ print_attr_xml("subject", msg->subject());
+ g_print("\t\t<date>%u</date>\n", (unsigned)msg->date());
+ g_print("\t\t<size>%u</size>\n", (unsigned)msg->size());
+ print_attr_xml("msgid", msg->message_id());
+ print_attr_xml("path", msg->path());
+ print_attr_xml("maildir", msg->maildir());
g_print("\t</message>\n");
return true;
@@ -565,16 +519,16 @@ output_query_results(const QueryResults& qres, const MuConfig* opts, GError** er
return false;
gboolean rv{true};
- output_func(NULL, FirstOutput, opts, NULL);
+ output_func(Nothing, FirstOutput, opts, {});
size_t n{0};
for (auto&& item : qres) {
n++;
- auto msg{item.floating_msg()};
+ auto msg{item.message()};
if (!msg)
continue;
- if (opts->after != 0 && mu_msg_get_timestamp(msg) < opts->after)
+ if (opts->after != 0 && msg->mtime() < opts->after)
continue;
rv = output_func(msg,
@@ -588,7 +542,7 @@ output_query_results(const QueryResults& qres, const MuConfig* opts, GError** er
if (!rv)
break;
}
- output_func(NULL, LastOutput, opts, NULL);
+ output_func(Nothing, LastOutput, opts, {});
return rv;
}
diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc
index fd73809..c386a04 100644
--- a/mu/mu-cmd-index.cc
+++ b/mu/mu-cmd-index.cc
@@ -30,7 +30,6 @@
#include <signal.h>
#include <unistd.h>
-#include "mu-msg.hh"
#include "index/mu-indexer.hh"
#include "mu-store.hh"
#include "mu-runtime.hh"
@@ -60,7 +59,7 @@ install_sig_handler(void)
for (i = 0; i != G_N_ELEMENTS(sigs); ++i)
if (sigaction(sigs[i], &action, NULL) != 0)
g_critical("set sigaction for %d failed: %s",
- sigs[i], g_strerror(errno));
+ sigs[i], g_strerror(errno));
}
static void
@@ -91,18 +90,18 @@ Mu::mu_cmd_index(Mu::Store& store, const MuConfig* opts, GError** err)
}
if (opts->max_msg_size < 0) {
mu_util_g_set_error(err,
- MU_ERROR_IN_PARAMETERS,
- "the maximum message size must be >= 0");
+ MU_ERROR_IN_PARAMETERS,
+ "the maximum message size must be >= 0");
return MU_ERROR;
}
const auto mdir{store.properties().root_maildir};
if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) {
mu_util_g_set_error(err,
- MU_ERROR_FILE,
- "'%s' is not readable: %s",
- mdir.c_str(),
- g_strerror(errno));
+ MU_ERROR_FILE,
+ "'%s' is not readable: %s",
+ mdir.c_str(),
+ g_strerror(errno));
return MU_ERROR;
}
diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc
index 9420b22..c47309c 100644
--- a/mu/mu-cmd.cc
+++ b/mu/mu-cmd.cc
@@ -29,8 +29,6 @@
#include <errno.h>
#include "mu-config.hh"
-#include "mu-msg.hh"
-#include "mu-msg-part.hh"
#include "mu-cmd.hh"
#include "mu-maildir.hh"
#include "mu-contacts-cache.hh"
@@ -43,6 +41,7 @@
#include "utils/mu-error.hh"
#include "utils/mu-utils.hh"
+#include "message/mu-message.hh"
#define VIEW_TERMINATOR '\f' /* form-feed */
@@ -303,8 +302,8 @@ foreach_msg_file(Mu::Store& store, const MuConfig* opts, ForeachMsgFunc foreach_
static bool
add_path_func(Mu::Store& store, const char* path, GError** err)
{
- const auto docid = store.add_message(path);
- g_debug("added message @ %s, docid=%u", path, docid);
+ const auto docid{store.add_message(path)};
+ g_debug("added message @ %s, docid=%u", path, docid.value());
return true;
}
diff --git a/mu/mu-config.cc b/mu/mu-config.cc
index 530cf5a..d1e0b34 100644
--- a/mu/mu-config.cc
+++ b/mu/mu-config.cc
@@ -41,19 +41,19 @@ get_output_format(const char* formatstr)
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},
- {"json", MU_CONFIG_FORMAT_JSON},
- {"xml", MU_CONFIG_FORMAT_XML},
- {"xquery", MU_CONFIG_FORMAT_XQUERY},
- {"mquery", MU_CONFIG_FORMAT_MQUERY},
- {"debug", MU_CONFIG_FORMAT_DEBUG}};
+ {"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},
+ {"json", MU_CONFIG_FORMAT_JSON},
+ {"xml", MU_CONFIG_FORMAT_XML},
+ {"xquery", MU_CONFIG_FORMAT_XQUERY},
+ {"mquery", MU_CONFIG_FORMAT_MQUERY},
+ {"debug", MU_CONFIG_FORMAT_DEBUG}};
for (i = 0; i != G_N_ELEMENTS(formats); i++)
if (strcmp(formats[i].name, formatstr) == 0)
@@ -94,24 +94,24 @@ config_options_group_mu()
{
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", 'V', 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", "<dir>"},
- {"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, (GOptionArg)0, NULL, NULL, NULL}};
+ {"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", 'V', 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", "<dir>"},
+ {"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, (GOptionArg)0, NULL, NULL, NULL}};
og = g_option_group_new("mu", "general mu options", "", NULL, NULL);
g_option_group_add_entries(og, entries);
@@ -133,15 +133,15 @@ config_options_group_init()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- {"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.maildir,
- "top of the maildir", "<maildir>"},
- {"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY, &MU_CONFIG.my_addresses,
- "my e-mail address; can be used multiple times", "<address>"},
- {"max-message-size", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.max_msg_size,
- "Maximum allowed size for messages", "<size-in-bytes>"},
- {"batch-size", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.batch_size,
- "Number of changes in a database transaction batch", "<number>"},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ {"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.maildir,
+ "top of the maildir", "<maildir>"},
+ {"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY, &MU_CONFIG.my_addresses,
+ "my e-mail address; can be used multiple times", "<address>"},
+ {"max-message-size", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.max_msg_size,
+ "Maximum allowed size for messages", "<size-in-bytes>"},
+ {"batch-size", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.batch_size,
+ "Number of changes in a database transaction batch", "<number>"},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("init", "Options for the 'init' command", "", NULL, NULL);
g_option_group_add_entries(og, entries);
@@ -151,14 +151,14 @@ config_options_group_init()
static gboolean
index_post_parse_func(GOptionContext* context, GOptionGroup* group, gpointer data,
- GError** error)
+ GError** error)
{
if (!MU_CONFIG.maildir && !MU_CONFIG.my_addresses)
return TRUE;
g_printerr("%sNOTE%s: as of mu 1.3.8, 'mu index' no longer uses the\n"
- "--maildir/-m or --my-address options.\n\n",
- color_maybe(MU_COLOR_RED), color_maybe(MU_COLOR_DEFAULT));
+ "--maildir/-m or --my-address options.\n\n",
+ color_maybe(MU_COLOR_RED), color_maybe(MU_COLOR_DEFAULT));
g_printerr("Instead, these options should be passed to 'mu init'.\n");
g_printerr(
"See the mu-init(1) or the mu4e reference manual,\n'Initializing the message "
@@ -172,21 +172,21 @@ config_options_group_index()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- /* only here so we can tell users they are deprecated */
- {"maildir", 'm', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
- &MU_CONFIG.maildir, "top of the maildir", "<maildir>"},
- {"my-address", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY,
- &MU_CONFIG.my_addresses, "my e-mail address; can be used multiple times",
- "<address>"},
-
- {"lazy-check", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.lazycheck,
- "only check dir-timestamps (false)", NULL},
- {"nocleanup", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocleanup,
- "don't clean up the database after indexing (false)", NULL},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ /* only here so we can tell users they are deprecated */
+ {"maildir", 'm', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
+ &MU_CONFIG.maildir, "top of the maildir", "<maildir>"},
+ {"my-address", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY,
+ &MU_CONFIG.my_addresses, "my e-mail address; can be used multiple times",
+ "<address>"},
+
+ {"lazy-check", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.lazycheck,
+ "only check dir-timestamps (false)", NULL},
+ {"nocleanup", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocleanup,
+ "don't clean up the database after indexing (false)", NULL},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("index", "Options for the 'index' command", "", NULL,
- NULL);
+ NULL);
g_option_group_add_entries(og, entries);
g_option_group_set_parse_hooks(og, NULL, (GOptionParseFunc)index_post_parse_func);
@@ -217,37 +217,37 @@ config_options_group_find()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- {"fields", 'f', 0, G_OPTION_ARG_STRING, &MU_CONFIG.fields,
- "fields to display in the output", "<fields>"},
- {"sortfield", 's', 0, G_OPTION_ARG_STRING, &MU_CONFIG.sortfield,
- "field to sort on", "<field>"},
- {"maxnum", 'n', 0, G_OPTION_ARG_INT, &MU_CONFIG.maxnum,
- "number of entries to display in the output", "<number>"},
- {"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", "<bookmark>"},
- {"reverse", 'z', 0, G_OPTION_ARG_NONE, &MU_CONFIG.reverse,
- "sort in reverse (descending) order (z -> a)", NULL},
- {"skip-dups", 'u', 0, G_OPTION_ARG_NONE, &MU_CONFIG.skip_dups,
- "show only the first of messages duplicates (false)", NULL},
- {"include-related", 'r', 0, G_OPTION_ARG_NONE, &MU_CONFIG.include_related,
- "include related messages in results (false)", NULL},
- {"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir,
- "output as symbolic links to a target maildir", "<dir>"},
- {"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',"
+ {"fields", 'f', 0, G_OPTION_ARG_STRING, &MU_CONFIG.fields,
+ "fields to display in the output", "<fields>"},
+ {"sortfield", 's', 0, G_OPTION_ARG_STRING, &MU_CONFIG.sortfield,
+ "field to sort on", "<field>"},
+ {"maxnum", 'n', 0, G_OPTION_ARG_INT, &MU_CONFIG.maxnum,
+ "number of entries to display in the output", "<number>"},
+ {"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", "<bookmark>"},
+ {"reverse", 'z', 0, G_OPTION_ARG_NONE, &MU_CONFIG.reverse,
+ "sort in reverse (descending) order (z -> a)", NULL},
+ {"skip-dups", 'u', 0, G_OPTION_ARG_NONE, &MU_CONFIG.skip_dups,
+ "show only the first of messages duplicates (false)", NULL},
+ {"include-related", 'r', 0, G_OPTION_ARG_NONE, &MU_CONFIG.include_related,
+ "include related messages in results (false)", NULL},
+ {"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir,
+ "output as symbolic links to a target maildir", "<dir>"},
+ {"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')",
- "<format>"},
- {"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
- "use up to <n> lines for the summary, or 0 for none (0)", "<len>"},
- {"exec", 'e', 0, G_OPTION_ARG_STRING, &MU_CONFIG.exec,
- "execute command on each match message", "<command>"},
- {"after", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.after,
- "only show messages whose m_time > T (t_time)", "<timestamp>"},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ "<format>"},
+ {"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
+ "use up to <n> lines for the summary, or 0 for none (0)", "<len>"},
+ {"exec", 'e', 0, G_OPTION_ARG_STRING, &MU_CONFIG.exec,
+ "execute command on each match message", "<command>"},
+ {"after", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.after,
+ "only show messages whose m_time > T (t_time)", "<timestamp>"},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("find", "Options for the 'find' command", "", NULL, NULL);
g_option_group_add_entries(og, entries);
@@ -260,15 +260,15 @@ config_options_group_mkdir()
{
GOptionGroup* og;
GOptionEntry entries[] = {{"mode", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.dirmode,
- "set the mode (as in chmod), in octal notation",
- "<mode>"},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ "set the mode (as in chmod), in octal notation",
+ "<mode>"},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, 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);
+ NULL);
g_option_group_add_entries(og, entries);
return og;
@@ -288,18 +288,18 @@ config_options_group_cfind()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- {"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
- "output format (plain(*), mutt-alias, mutt-ab, wl, "
+ {"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
+ "output format (plain(*), mutt-alias, mutt-ab, wl, "
"org-contact, bbdb, csv)",
- "<format>"},
- {"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", "<timestamp>"},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ "<format>"},
+ {"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", "<timestamp>"},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("cfind", "Options for the 'cfind' command", "", NULL,
- NULL);
+ NULL);
g_option_group_add_entries(og, entries);
return og;
@@ -310,11 +310,11 @@ config_options_group_script()
{
GOptionGroup* og;
GOptionEntry entries[] = {{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
- &MU_CONFIG.params, "script parameters", NULL},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ &MU_CONFIG.params, "script parameters", NULL},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("script", "Options for the 'script' command", "", NULL,
- NULL);
+ NULL);
g_option_group_add_entries(og, entries);
@@ -349,13 +349,13 @@ config_options_group_view()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- {"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
- "use up to <n> lines for the summary, or 0 for none (0)", "<len>"},
- {"terminate", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.terminator,
- "terminate messages with ascii-0x07 (\\f, form-feed)", NULL},
- {"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
- "output format ('plain'(*), 'sexp')", "<format>"},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ {"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
+ "use up to <n> lines for the summary, or 0 for none (0)", "<len>"},
+ {"terminate", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.terminator,
+ "terminate messages with ascii-0x07 (\\f, form-feed)", NULL},
+ {"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
+ "output format ('plain'(*), 'sexp')", "<format>"},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("view", "Options for the 'view' command", "", NULL, NULL);
@@ -379,21 +379,21 @@ config_options_group_extract()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- {"save-attachments", 'a', 0, G_OPTION_ARG_NONE, &MU_CONFIG.save_attachments,
- "save all attachments (false)", NULL},
- {"save-all", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.save_all,
- "save all parts (incl. non-attachments) (false)", NULL},
- {"parts", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.parts,
- "save specific parts (comma-separated list)", "<parts>"},
- {"target-dir", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.targetdir,
- "target directory for saving", "<dir>"},
- {"overwrite", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.overwrite,
- "overwrite existing files (false)", NULL},
- {"play", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.play,
- "try to 'play' (open) the extracted parts", NULL},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ {"save-attachments", 'a', 0, G_OPTION_ARG_NONE, &MU_CONFIG.save_attachments,
+ "save all attachments (false)", NULL},
+ {"save-all", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.save_all,
+ "save all parts (incl. non-attachments) (false)", NULL},
+ {"parts", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.parts,
+ "save specific parts (comma-separated list)", "<parts>"},
+ {"target-dir", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.targetdir,
+ "target directory for saving", "<dir>"},
+ {"overwrite", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.overwrite,
+ "overwrite existing files (false)", NULL},
+ {"play", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.play,
+ "try to 'play' (open) the extracted parts", NULL},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("extract", "Options for the 'extract' command", "", NULL,
- NULL);
+ NULL);
g_option_group_add_entries(og, entries);
g_option_group_add_entries(og, crypto_option_entries());
@@ -405,7 +405,7 @@ config_options_group_verify()
{
GOptionGroup* og;
og = g_option_group_new("verify", "Options for the 'verify' command", "", NULL,
- NULL);
+ NULL);
g_option_group_add_entries(og, crypto_option_entries());
return og;
@@ -416,14 +416,14 @@ config_options_group_server()
{
GOptionGroup* og;
GOptionEntry entries[] = {
- {"commands", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.commands,
- "list the available command and their parameters, then exit", NULL},
- {"eval", 'e', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &MU_CONFIG.eval,
- "expression to evaluate", "<expr>"},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
+ {"commands", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.commands,
+ "list the available command and their parameters, then exit", NULL},
+ {"eval", 'e', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &MU_CONFIG.eval,
+ "expression to evaluate", "<expr>"},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("server", "Options for the 'server' command", "", NULL,
- NULL);
+ NULL);
g_option_group_add_entries(og, entries);
return og;
@@ -481,7 +481,7 @@ parse_cmd(int* argcp, char*** argvp, GError** err)
#ifndef BUILD_GUILE
if (MU_CONFIG.cmd == MU_CONFIG_CMD_SCRIPT) {
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS,
- "command 'script' not supported");
+ "command 'script' not supported");
return FALSE;
}
#endif /*!BUILD_GUILE*/
@@ -489,7 +489,7 @@ parse_cmd(int* argcp, char*** argvp, GError** err)
if (MU_CONFIG.cmdstr && MU_CONFIG.cmdstr[0] != '-' &&
MU_CONFIG.cmd == MU_CONFIG_CMD_UNKNOWN) {
mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "unknown command '%s'",
- MU_CONFIG.cmdstr);
+ MU_CONFIG.cmdstr);
return FALSE;
}
@@ -525,7 +525,7 @@ massage_help(const char* help)
char* str;
rx = g_regex_new("^Usage:.*\n.*\n", (GRegexCompileFlags)0,
- G_REGEX_MATCH_NEWLINE_ANY, NULL);
+ G_REGEX_MATCH_NEWLINE_ANY, NULL);
str = g_regex_replace(rx, help, -1, 0, "", G_REGEX_MATCH_NEWLINE_ANY, NULL);
g_regex_unref(rx);
return str;
@@ -544,7 +544,7 @@ get_help_string(MuConfigCmd cmd, bool long_help)
};
const auto help_it = std::find_if(all_help.begin(), all_help.end(),
- [&](auto&& info) { return info.cmd == cmd; });
+ [&](auto&& info) { return info.cmd == cmd; });
if (help_it == all_help.end()) {
g_critical("cannot find info for %u", cmd);
return "";
@@ -711,23 +711,6 @@ Mu::mu_config_param_num(const MuConfig* opts)
return n;
}
-MuMsgOptions
-Mu::mu_config_get_msg_options(const MuConfig* muopts)
-{
- int opts;
-
- opts = MU_MSG_OPTION_NONE;
-
- if (muopts->decrypt)
- opts |= MU_MSG_OPTION_DECRYPT;
- if (muopts->auto_retrieve)
- opts |= MU_MSG_OPTION_AUTO_RETRIEVE;
- if (muopts->overwrite)
- opts |= MU_MSG_OPTION_OVERWRITE;
-
- return (MuMsgOptions)opts;
-}
-
Message::Options
Mu::mu_config_message_options(const MuConfig *conf)
{
diff --git a/mu/mu-config.hh b/mu/mu-config.hh
index b1162f3..5d5ff47 100644
--- a/mu/mu-config.hh
+++ b/mu/mu-config.hh
@@ -23,7 +23,6 @@
#include <glib.h>
#include <sys/types.h> /* for mode_t */
#include <message/mu-message.hh>
-#include <mu-msg.hh>
#include <utils/mu-util.h>
namespace Mu {
@@ -226,15 +225,6 @@ MuError mu_config_execute(const MuConfig* conf);
size_t mu_config_param_num(const MuConfig* conf);
/**
- * determine MuMsgOptions for command line args
- *
- * @param opts a MuConfig struct
- *
- * @return the corresponding MuMsgOptions
- */
-MuMsgOptions mu_config_get_msg_options(const MuConfig* opts);
-
-/**
* determine Message::Options from command line args
*
* @param opts a MuConfig struct
diff --git a/mu/tests/test-mu-query.cc b/mu/tests/test-mu-query.cc
index e009a98..98c9ddb 100644
--- a/mu/tests/test-mu-query.cc
+++ b/mu/tests/test-mu-query.cc
@@ -246,19 +246,19 @@ test_mu_query_accented_chars_01(void)
g_assert_true(!!qres);
g_assert_false(qres->empty());
- auto begin{qres->begin()};
- auto msg{begin.floating_msg()};
+ const auto msg{qres->begin().message()};
if (!msg) {
g_warning("error getting message");
g_assert_not_reached();
}
- g_assert_cmpstr(mu_msg_get_subject(msg), ==, "Greetings from Lothlórien");
+ assert_equal(msg->subject(), "Greetings from Lothlórien");
/* TODO: fix this again */
- auto summ = mu_str_summarize(mu_msg_get_body_text(msg, MU_MSG_OPTION_NONE), 5);
- g_assert_cmpstr(summ, ==, "Let's write some fünkÿ text using umlauts. Foo.");
- g_free(summ);
+ const auto summ{to_string_opt_gchar(
+ mu_str_summarize(msg->body_text().value_or("").c_str(), 5))};
+ g_assert_true(!!summ);
+ assert_equal(*summ, "Let's write some fünkÿ text using umlauts. Foo.");
}
static void