mirror of https://github.com/djcb/mu.git
compose: remove server-side handling
It's no longer needed: composition happens on the mu4e side only (until a message is saved).
This commit is contained in:
parent
0a5845fe8b
commit
1999d9e6ef
|
@ -301,21 +301,6 @@ Server::Private::make_command_map()
|
||||||
"add a message to the store",
|
"add a message to the store",
|
||||||
[&](const auto& params) { add_handler(params); }});
|
[&](const auto& params) { add_handler(params); }});
|
||||||
|
|
||||||
cmap.emplace(
|
|
||||||
"compose",
|
|
||||||
CommandInfo{
|
|
||||||
ArgMap{
|
|
||||||
{":type",
|
|
||||||
ArgInfo{Type::Symbol,
|
|
||||||
true,
|
|
||||||
"type of composition: reply/forward/edit/resend/new"}},
|
|
||||||
{":docid",
|
|
||||||
ArgInfo{Type::Number, false, "document id of parent-message, if any"}},
|
|
||||||
{":decrypt",
|
|
||||||
ArgInfo{Type::Symbol, false, "whether to decrypt encrypted parts (if any)"}}},
|
|
||||||
"compose a new message",
|
|
||||||
[&](const auto& params) { compose_handler(params); }});
|
|
||||||
|
|
||||||
cmap.emplace(
|
cmap.emplace(
|
||||||
"contacts",
|
"contacts",
|
||||||
CommandInfo{
|
CommandInfo{
|
||||||
|
@ -521,90 +506,6 @@ Server::Private::add_handler(const Command& cmd)
|
||||||
msg_sexp_str(msg_res.value(), docid, {})));
|
msg_sexp_str(msg_res.value(), docid, {})));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'compose' produces the un-changed *original* message sexp (ie., the message
|
|
||||||
* to reply to, forward or edit) for a new message to compose). It takes two
|
|
||||||
* parameters: 'type' with the compose type (either reply, forward or
|
|
||||||
* edit/resend), and 'docid' for the message to reply to. Note, type:new does
|
|
||||||
* not have an original message, and therefore does not need a docid
|
|
||||||
*
|
|
||||||
* In returns a (:compose <type> [:original <original-msg>] [:include] ) message
|
|
||||||
* (details: see code below)
|
|
||||||
*
|
|
||||||
* Note ':include' t or nil determines whether to include attachments
|
|
||||||
*/
|
|
||||||
|
|
||||||
static Option<Sexp>
|
|
||||||
maybe_add_attachment(Message& message, const MessagePart& part, size_t index)
|
|
||||||
{
|
|
||||||
if (!part.is_attachment())
|
|
||||||
return Nothing;
|
|
||||||
|
|
||||||
const auto cache_path{message.cache_path(index)};
|
|
||||||
if (!cache_path)
|
|
||||||
throw cache_path.error();
|
|
||||||
|
|
||||||
const auto cooked_name{part.cooked_filename()};
|
|
||||||
const auto fname{join_paths(*cache_path, cooked_name.value_or("part"))};
|
|
||||||
|
|
||||||
const auto res = part.to_file(fname, true);
|
|
||||||
if (!res)
|
|
||||||
throw res.error();
|
|
||||||
|
|
||||||
Sexp pi;
|
|
||||||
if (auto cdescr = part.content_description(); cdescr)
|
|
||||||
pi.put_props(":description", *cdescr);
|
|
||||||
else if (cooked_name)
|
|
||||||
pi.put_props(":description", cooked_name.value());
|
|
||||||
|
|
||||||
pi.put_props(":file-name", fname,
|
|
||||||
":mime-type",
|
|
||||||
part.mime_type().value_or("application/octet-stream"));
|
|
||||||
|
|
||||||
return Some(std::move(pi));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Server::Private::compose_handler(const Command& cmd)
|
|
||||||
{
|
|
||||||
const auto ctype = cmd.symbol_arg(":type").value_or("<error>");
|
|
||||||
|
|
||||||
auto comp_lst = Sexp().put_props(":compose", Sexp::Symbol(ctype));
|
|
||||||
|
|
||||||
|
|
||||||
if (ctype == "reply" || ctype == "forward" ||
|
|
||||||
ctype == "edit" || ctype == "resend") {
|
|
||||||
|
|
||||||
const unsigned docid{static_cast<unsigned>(cmd.number_arg(":docid").value_or(0))};
|
|
||||||
auto msg{store().find_message(docid)};
|
|
||||||
if (!msg)
|
|
||||||
throw Error{Error::Code::Store, "failed to get message {}", docid};
|
|
||||||
|
|
||||||
auto msg_sexp = unwrap(Sexp::parse(msg_sexp_str(msg.value(), docid, {})));
|
|
||||||
comp_lst.put_props(":original", msg_sexp);
|
|
||||||
if (ctype == "forward") {
|
|
||||||
// when forwarding, attach any attachment in the orig
|
|
||||||
size_t index{};
|
|
||||||
Sexp attseq;
|
|
||||||
for (auto&& part: msg->parts()) {
|
|
||||||
if (auto attsexp = maybe_add_attachment(
|
|
||||||
*msg, part, index); attsexp) {
|
|
||||||
attseq.add(std::move(*attsexp));
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!attseq.empty()) {
|
|
||||||
comp_lst.put_props(":include", std::move(attseq),
|
|
||||||
":cache-path", *msg->cache_path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (ctype != "new")
|
|
||||||
throw Error(Error::Code::InvalidArgument, "invalid compose type '{}'", ctype);
|
|
||||||
|
|
||||||
output_sexp(comp_lst);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::Private::contacts_handler(const Command& cmd)
|
Server::Private::contacts_handler(const Command& cmd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
|
|
||||||
(make-obsolete-variable 'mu4e-auto-retrieve-keys "no longer used." "1.3.1")
|
(make-obsolete-variable 'mu4e-auto-retrieve-keys "no longer used." "1.3.1")
|
||||||
|
|
||||||
|
(make-obsolete-variable 'mu4e-compose-func "no longer used" "1.11.26")
|
||||||
|
|
||||||
(make-obsolete-variable 'mu4e-compose-crypto-reply-encrypted-policy "The use of the
|
(make-obsolete-variable 'mu4e-compose-crypto-reply-encrypted-policy "The use of the
|
||||||
'mu4e-compose-crypto-reply-encrypted-policy' variable is deprecated.
|
'mu4e-compose-crypto-reply-encrypted-policy' variable is deprecated.
|
||||||
'mu4e-compose-crypto-policy' should be used instead" "2020-03-06")
|
'mu4e-compose-crypto-policy' should be used instead" "2020-03-06")
|
||||||
|
|
|
@ -142,13 +142,6 @@ the number of matches. See `mu4e--server-filter' for the format.")
|
||||||
This before new headers are displayed, to clear the current
|
This before new headers are displayed, to clear the current
|
||||||
headers buffer. See `mu4e--server-filter' for the format.")
|
headers buffer. See `mu4e--server-filter' for the format.")
|
||||||
|
|
||||||
(defvar mu4e-compose-func nil
|
|
||||||
"Function called for each compose message received.
|
|
||||||
I.e., the original message that is used as basis for composing a
|
|
||||||
new message (i.e., either a reply or a forward); the function is
|
|
||||||
passed msg and a symbol (either reply or forward). See
|
|
||||||
`mu4e--server-filter' for the format of <msg-plist>.")
|
|
||||||
|
|
||||||
(defvar mu4e-info-func nil
|
(defvar mu4e-info-func nil
|
||||||
"Function called for each (:info type ....) sexp received.
|
"Function called for each (:info type ....) sexp received.
|
||||||
from the server process.")
|
from the server process.")
|
||||||
|
@ -563,20 +556,6 @@ On success, we receive `'(:info add :path <path> :docid <docid>)'
|
||||||
as well as `'(:update <msg-sexp>)`'; otherwise, we receive an error."
|
as well as `'(:update <msg-sexp>)`'; otherwise, we receive an error."
|
||||||
(mu4e--server-call-mu `(add :path ,path)))
|
(mu4e--server-call-mu `(add :path ,path)))
|
||||||
|
|
||||||
(defun mu4e--server-compose (type decrypt &optional docid)
|
|
||||||
"Compose a message of TYPE, DECRYPT it and use DOCID.
|
|
||||||
TYPE is a symbol, either `forward', `reply', `edit', `resend' or
|
|
||||||
`new', based on an original message (ie, replying to, forwarding,
|
|
||||||
editing, resending) with DOCID or nil for type `new'.
|
|
||||||
|
|
||||||
The result is delivered to the function registered as
|
|
||||||
`mu4e-compose-func'."
|
|
||||||
(mu4e--server-call-mu
|
|
||||||
`(compose
|
|
||||||
:type ,type
|
|
||||||
:decrypt ,(and decrypt t)
|
|
||||||
:docid ,docid)))
|
|
||||||
|
|
||||||
(defun mu4e--server-contacts (personal after maxnum tstamp)
|
(defun mu4e--server-contacts (personal after maxnum tstamp)
|
||||||
"Ask for contacts with PERSONAL AFTER MAXNUM TSTAMP.
|
"Ask for contacts with PERSONAL AFTER MAXNUM TSTAMP.
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,6 @@ chance."
|
||||||
(mu4e-setq-if-nil mu4e-erase-func #'mu4e~headers-clear)
|
(mu4e-setq-if-nil mu4e-erase-func #'mu4e~headers-clear)
|
||||||
|
|
||||||
(mu4e-setq-if-nil mu4e-sent-func #'mu4e--default-handler)
|
(mu4e-setq-if-nil mu4e-sent-func #'mu4e--default-handler)
|
||||||
(mu4e-setq-if-nil mu4e-compose-func #'mu4e--compose-setup)
|
|
||||||
(mu4e-setq-if-nil mu4e-contacts-func #'mu4e--update-contacts)
|
(mu4e-setq-if-nil mu4e-contacts-func #'mu4e--update-contacts)
|
||||||
(mu4e-setq-if-nil mu4e-info-func #'mu4e--info-handler)
|
(mu4e-setq-if-nil mu4e-info-func #'mu4e--info-handler)
|
||||||
(mu4e-setq-if-nil mu4e-pong-func #'mu4e--default-handler)
|
(mu4e-setq-if-nil mu4e-pong-func #'mu4e--default-handler)
|
||||||
|
|
Loading…
Reference in New Issue