server: use mu-message-fields

This commit is contained in:
Dirk-Jan C. Binnema
2022-03-05 00:35:26 +02:00
parent ca5bb06457
commit f576fc59b9

View File

@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "mu-message-flags.hh" #include "mu-message-flags.hh"
#include "mu-msg-fields.h" #include "mu-message-fields.hh"
#include "mu-msg.hh" #include "mu-msg.hh"
#include "mu-server.hh" #include "mu-server.hh"
@ -49,6 +49,7 @@
#include "utils/mu-readline.hh" #include "utils/mu-readline.hh"
using namespace Mu; using namespace Mu;
using namespace Mu::Message;
using namespace Command; using namespace Command;
/// @brief object to manage the server-context for all commands. /// @brief object to manage the server-context for all commands.
@ -559,7 +560,7 @@ docids_for_msgid(const Store& store, const std::string& msgid, size_t max = 100)
throw Error(Error::Code::InvalidArgument, "invalid message-id '%s'", msgid.c_str()); throw Error(Error::Code::InvalidArgument, "invalid message-id '%s'", msgid.c_str());
} }
const auto xprefix{mu_msg_field_shortcut(MU_MSG_FIELD_ID_MSGID)}; const auto xprefix{message_field(Field::Id::MessageId).shortcut};
/*XXX this is a bit dodgy */ /*XXX this is a bit dodgy */
auto tmp{g_ascii_strdown(msgid.c_str(), -1)}; auto tmp{g_ascii_strdown(msgid.c_str(), -1)};
auto expr{g_strdup_printf("%c:%s", xprefix, tmp)}; auto expr{g_strdup_printf("%c:%s", xprefix, tmp)};
@ -567,7 +568,7 @@ docids_for_msgid(const Store& store, const std::string& msgid, size_t max = 100)
GError* gerr{}; GError* gerr{};
std::lock_guard l{store.lock()}; std::lock_guard l{store.lock()};
const auto res{store.run_query(expr, MU_MSG_FIELD_ID_NONE, QueryFlags::None, max)}; const auto res{store.run_query(expr, {}, QueryFlags::None, max)};
g_free(expr); g_free(expr);
if (!res) if (!res)
throw Error(Error::Code::Store, &gerr, "failed to run msgid-query"); throw Error(Error::Code::Store, &gerr, "failed to run msgid-query");
@ -672,14 +673,11 @@ Server::Private::find_handler(const Parameters& params)
const auto skip_dups{get_bool_or(params, ":skip-dups", false)}; const auto skip_dups{get_bool_or(params, ":skip-dups", false)};
const auto include_related{get_bool_or(params, ":include-related", false)}; const auto include_related{get_bool_or(params, ":include-related", false)};
MuMsgFieldId sort_field{MU_MSG_FIELD_ID_NONE};
if (!sortfieldstr.empty()) { auto sort_field = message_field_id(sortfieldstr);
sort_field = mu_msg_field_id_from_name(sortfieldstr.c_str() + 1, FALSE); // skip ':' if (!sort_field && sortfieldstr.empty())
if (sort_field == MU_MSG_FIELD_ID_NONE) throw Error{Error::Code::InvalidArgument, "invalid sort field %s",
throw Error{Error::Code::InvalidArgument, sortfieldstr.c_str()};
"invalid sort field %s",
sortfieldstr.c_str()};
}
if (batch_size < 1) if (batch_size < 1)
throw Error{Error::Code::InvalidArgument, "invalid batch-size %d", batch_size}; throw Error{Error::Code::InvalidArgument, "invalid batch-size %d", batch_size};