diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 3457f4c2..04b83db7 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -98,6 +98,7 @@ struct Server::Private { void move_handler(const Command& cmd); void mkdir_handler(const Command& cmd); void ping_handler(const Command& cmd); + void queries_handler(const Command& cmd); void quit_handler(const Command& cmd); void remove_handler(const Command& cmd); void sent_handler(const Command& cmd); @@ -287,17 +288,20 @@ Server::Private::make_command_map() [&](const auto& params) { mkdir_handler(params); }}); cmap.emplace( "ping", + CommandInfo{ + ArgMap{}, + "ping the mu-server and get server information in the response", + [&](const auto& params) { ping_handler(params); }}); + + cmap.emplace( + "queries", CommandInfo{ ArgMap{ {":queries", ArgInfo{Type::List, false, "queries for which to get read/unread numbers"}}, - {":skip-dups", - ArgInfo{Type::Symbol, - false, - "whether to exclude messages with duplicate message-ids"}}, }, - "ping the mu-server and get information in response", - [&](const auto& params) { ping_handler(params); }}); + "get unread/totals information for a list of queries", + [&](const auto& params) { queries_handler(params); }}); cmap.emplace("quit", CommandInfo{{}, "quit the mu server", [&](const auto& params) { quit_handler(params); @@ -916,9 +920,28 @@ Server::Private::ping_handler(const Command& cmd) const auto storecount{store().size()}; if (storecount == (unsigned)-1) throw Error{Error::Code::Store, "failed to read store"}; + Sexp addrs; + for (auto&& addr : store().properties().personal_addresses) + addrs.add(addr); + output_sexp(Sexp() + .put_props(":pong", "mu") + .put_props(":props", + Sexp().put_props( + ":version", VERSION, + ":personal-addresses", std::move(addrs), + ":database-path", store().properties().database_path, + ":root-maildir", store().properties().root_maildir, + ":doccount", storecount))); +} + + +void +Server::Private::queries_handler(const Command& cmd) +{ const auto queries{cmd.string_vec_arg(":queries") .value_or(std::vector{})}; + Sexp qresults; for (auto&& q : queries) { const auto count{store_.count_query(q)}; @@ -929,22 +952,10 @@ Server::Private::ping_handler(const Command& cmd) ":unread", unread)); } - Sexp addrs; - for (auto&& addr : store().properties().personal_addresses) - addrs.add(addr); - - auto lst = Sexp().put_props(":pong", "mu"); - auto proplst = Sexp().put_props( - ":version", VERSION, - ":personal-addresses", std::move(addrs), - ":database-path", store().properties().database_path, - ":root-maildir", store().properties().root_maildir, - ":doccount", storecount, - ":queries", std::move(qresults)); - - output_sexp(lst.put_props(":props", std::move(proplst))); + output_sexp(Sexp(":queries"_sym, std::move(qresults))); } + void Server::Private::quit_handler(const Command& cmd) { diff --git a/lib/utils/mu-command-handler.cc b/lib/utils/mu-command-handler.cc index efa2233e..1037e8fa 100644 --- a/lib/utils/mu-command-handler.cc +++ b/lib/utils/mu-command-handler.cc @@ -106,8 +106,7 @@ CommandHandler::invoke(const Command& cmd, bool do_validate) const const auto cmit{cmap_.find(cmd.name())}; if (cmit == cmap_.cend()) return Err(Error::Code::Command, - "unknown command in command '%s'", - cmd.to_string().c_str()); + "unknown command '%s'", cmd.to_string().c_str()); const auto& cmd_info{cmit->second}; if (do_validate) {