From a0ec982789ccc3459c732f8cbfb0d94c9a6bc1d9 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 13 Feb 2022 12:03:16 +0200 Subject: [PATCH] mu4e/server: honor rename-move for view-message, too It's technically a 'move', so apply user preference. --- lib/mu-server.cc | 42 ++++++++++++++++++------------------------ mu4e/mu4e-server.el | 5 ++++- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/mu-server.cc b/lib/mu-server.cc index aefffc6a..324a36b8 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -120,8 +120,7 @@ private: const Option qm, MuMsgOptions opts) const; - Sexp::List - move_docid(Store::Id docid, const std::string& flagstr, bool new_name, bool no_view); + Sexp::List move_docid(Store::Id docid, const std::string& flagstr, bool new_name, bool no_view); Sexp::List perform_move(Store::Id docid, MuMsg* msg, const std::string& maildirarg, @@ -129,8 +128,8 @@ private: bool new_name, bool no_view); - bool maybe_mark_as_read(MuMsg* msg, Store::Id docid); - bool maybe_mark_msgid_as_read(const char* msgid); + bool maybe_mark_as_read(MuMsg* msg, Store::Id docid, bool rename); + bool maybe_mark_msgid_as_read(const char* msgid, bool rename); Store& store_; Server::Output output_; @@ -338,6 +337,7 @@ Server::Private::make_command_map() {":path", ArgInfo{Type::String, false, "message filesystem path"}}, {":mark-as-read", ArgInfo{Type::Symbol, false, "mark message as read (if not already)"}}, + {":rename", ArgInfo{Type::Symbol, false, "change filename when moving"}}, }, "view a message. exactly one of docid/msgid/path must be specified", [&](const auto& params) { view_handler(params); }}); @@ -613,7 +613,7 @@ determine_docids(const Store& store, const Parameters& params) "precisely one of docid and msgid must be specified"); if (docid != 0) - return {(unsigned)docid}; + return {static_cast(docid)}; else return docids_for_msgid(store, msgid.c_str()); } @@ -1047,7 +1047,7 @@ Server::Private::sent_handler(const Parameters& params) } bool -Server::Private::maybe_mark_as_read(MuMsg* msg, Store::Id docid) +Server::Private::maybe_mark_as_read(MuMsg* msg, Store::Id docid, bool rename) { if (!msg) throw Error{Error::Code::Store, "missing message"}; @@ -1062,7 +1062,7 @@ Server::Private::maybe_mark_as_read(MuMsg* msg, Store::Id docid) mu_msg_get_maildir(msg), newflags, TRUE, - FALSE, /*new_name,*/ + rename ? TRUE : FALSE, &gerr)) throw Error{Error::Code::File, &gerr, "failed to move message"}; @@ -1082,7 +1082,7 @@ Server::Private::maybe_mark_as_read(MuMsg* msg, Store::Id docid) } bool -Server::Private::maybe_mark_msgid_as_read(const char* msgid) +Server::Private::maybe_mark_msgid_as_read(const char* msgid, bool rename) { if (!msgid) return false; // nothing to do. @@ -1093,7 +1093,7 @@ Server::Private::maybe_mark_msgid_as_read(const char* msgid) if (!msg) continue; try { - maybe_mark_as_read(msg, docid); + maybe_mark_as_read(msg, docid, rename); } catch (...) { mu_msg_unref(msg); throw; @@ -1106,29 +1106,23 @@ Server::Private::maybe_mark_msgid_as_read(const char* msgid) void Server::Private::view_handler(const Parameters& params) { - Store::Id docid{Store::InvalidId}; - const auto path{get_string_or(params, ":path")}; const auto mark_as_read{get_bool_or(params, ":mark-as-read")}; + const auto rename{get_bool_or(params, ":rename")}; + const auto docids{determine_docids(store(), params)}; - GError* gerr{}; - MuMsg* msg{}; - - if (!path.empty()) { /* only use for old view (embedded msgs) */ - docid = Store::InvalidId; - msg = mu_msg_new_from_file(path.c_str(), NULL, &gerr); - } else { - docid = determine_docids(store(), params).at(0); - msg = store().find_message(docid); - } + if (docids.empty()) + throw Error{Error::Code::Store, "failed to find message for view"}; + const auto docid{docids.at(0)}; + MuMsg* msg{store().find_message(docid)}; if (!msg) - throw Error{Error::Code::Store, &gerr, "failed to find message for view"}; + throw Error{Error::Code::Store, "failed to find message for view"}; if (mark_as_read) { // maybe mark the main message as read. - maybe_mark_as_read(msg, docid); + maybe_mark_as_read(msg, docid, rename); /* maybe mark _all_ messsage with same message-id as read */ - maybe_mark_msgid_as_read(mu_msg_get_msgid(msg)); + maybe_mark_msgid_as_read(mu_msg_get_msgid(msg), rename); } Sexp::List seq; diff --git a/mu4e/mu4e-server.el b/mu4e/mu4e-server.el index 33658bc9..92a05882 100644 --- a/mu4e/mu4e-server.el +++ b/mu4e/mu4e-server.el @@ -563,7 +563,10 @@ The result will be delivered to the function registered as `(view :docid ,(if (stringp docid-or-msgid) nil docid-or-msgid) :msgid ,(if (stringp docid-or-msgid) docid-or-msgid nil) - :mark-as-read ,mark-as-read))) + :mark-as-read ,mark-as-read + ;; when moving (due to mark-as-read), change filenames + ;; if so configured. + :rename ,mu4e-change-filenames-when-moving))) (provide 'mu4e-server)