mirror of https://github.com/djcb/mu.git
mu4e/server: honor rename-move for view-message, too
It's technically a 'move', so apply user preference.
This commit is contained in:
parent
a66fd4dae4
commit
a0ec982789
|
@ -120,8 +120,7 @@ private:
|
||||||
const Option<QueryMatch&> qm,
|
const Option<QueryMatch&> qm,
|
||||||
MuMsgOptions opts) const;
|
MuMsgOptions opts) const;
|
||||||
|
|
||||||
Sexp::List
|
Sexp::List move_docid(Store::Id docid, const std::string& flagstr, bool new_name, bool no_view);
|
||||||
move_docid(Store::Id docid, const std::string& flagstr, bool new_name, bool no_view);
|
|
||||||
Sexp::List perform_move(Store::Id docid,
|
Sexp::List perform_move(Store::Id docid,
|
||||||
MuMsg* msg,
|
MuMsg* msg,
|
||||||
const std::string& maildirarg,
|
const std::string& maildirarg,
|
||||||
|
@ -129,8 +128,8 @@ private:
|
||||||
bool new_name,
|
bool new_name,
|
||||||
bool no_view);
|
bool no_view);
|
||||||
|
|
||||||
bool maybe_mark_as_read(MuMsg* msg, Store::Id docid);
|
bool maybe_mark_as_read(MuMsg* msg, Store::Id docid, bool rename);
|
||||||
bool maybe_mark_msgid_as_read(const char* msgid);
|
bool maybe_mark_msgid_as_read(const char* msgid, bool rename);
|
||||||
|
|
||||||
Store& store_;
|
Store& store_;
|
||||||
Server::Output output_;
|
Server::Output output_;
|
||||||
|
@ -338,6 +337,7 @@ Server::Private::make_command_map()
|
||||||
{":path", ArgInfo{Type::String, false, "message filesystem path"}},
|
{":path", ArgInfo{Type::String, false, "message filesystem path"}},
|
||||||
{":mark-as-read",
|
{":mark-as-read",
|
||||||
ArgInfo{Type::Symbol, false, "mark message as read (if not already)"}},
|
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",
|
"view a message. exactly one of docid/msgid/path must be specified",
|
||||||
[&](const auto& params) { view_handler(params); }});
|
[&](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");
|
"precisely one of docid and msgid must be specified");
|
||||||
|
|
||||||
if (docid != 0)
|
if (docid != 0)
|
||||||
return {(unsigned)docid};
|
return {static_cast<Store::Id>(docid)};
|
||||||
else
|
else
|
||||||
return docids_for_msgid(store, msgid.c_str());
|
return docids_for_msgid(store, msgid.c_str());
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1047,7 @@ Server::Private::sent_handler(const Parameters& params)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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)
|
if (!msg)
|
||||||
throw Error{Error::Code::Store, "missing message"};
|
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),
|
mu_msg_get_maildir(msg),
|
||||||
newflags,
|
newflags,
|
||||||
TRUE,
|
TRUE,
|
||||||
FALSE, /*new_name,*/
|
rename ? TRUE : FALSE,
|
||||||
&gerr))
|
&gerr))
|
||||||
throw Error{Error::Code::File, &gerr, "failed to move message"};
|
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
|
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)
|
if (!msgid)
|
||||||
return false; // nothing to do.
|
return false; // nothing to do.
|
||||||
|
@ -1093,7 +1093,7 @@ Server::Private::maybe_mark_msgid_as_read(const char* msgid)
|
||||||
if (!msg)
|
if (!msg)
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
maybe_mark_as_read(msg, docid);
|
maybe_mark_as_read(msg, docid, rename);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
mu_msg_unref(msg);
|
mu_msg_unref(msg);
|
||||||
throw;
|
throw;
|
||||||
|
@ -1106,29 +1106,23 @@ Server::Private::maybe_mark_msgid_as_read(const char* msgid)
|
||||||
void
|
void
|
||||||
Server::Private::view_handler(const Parameters& params)
|
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 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{};
|
if (docids.empty())
|
||||||
MuMsg* msg{};
|
throw Error{Error::Code::Store, "failed to find message for view"};
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const auto docid{docids.at(0)};
|
||||||
|
MuMsg* msg{store().find_message(docid)};
|
||||||
if (!msg)
|
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) {
|
if (mark_as_read) {
|
||||||
// maybe mark the main message 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 _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;
|
Sexp::List seq;
|
||||||
|
|
|
@ -563,7 +563,10 @@ The result will be delivered to the function registered as
|
||||||
`(view
|
`(view
|
||||||
:docid ,(if (stringp docid-or-msgid) nil docid-or-msgid)
|
:docid ,(if (stringp docid-or-msgid) nil docid-or-msgid)
|
||||||
:msgid ,(if (stringp docid-or-msgid) docid-or-msgid nil)
|
: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)
|
(provide 'mu4e-server)
|
||||||
|
|
Loading…
Reference in New Issue