From 1999d9e6ef8b21e94958487b6da4eca8de5598cf Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 29 Dec 2023 23:23:13 +0200 Subject: [PATCH] compose: remove server-side handling It's no longer needed: composition happens on the mu4e side only (until a message is saved). --- lib/mu-server.cc | 99 ------------------------------------------- mu4e/mu4e-obsolete.el | 2 + mu4e/mu4e-server.el | 21 --------- mu4e/mu4e.el | 1 - 4 files changed, 2 insertions(+), 121 deletions(-) diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 46626c22..473952e9 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -301,21 +301,6 @@ Server::Private::make_command_map() "add a message to the store", [&](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( "contacts", CommandInfo{ @@ -521,90 +506,6 @@ Server::Private::add_handler(const Command& cmd) 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 [:original ] [:include] ) message - * (details: see code below) - * - * Note ':include' t or nil determines whether to include attachments - */ - -static Option -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(""); - - auto comp_lst = Sexp().put_props(":compose", Sexp::Symbol(ctype)); - - - if (ctype == "reply" || ctype == "forward" || - ctype == "edit" || ctype == "resend") { - - const unsigned docid{static_cast(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 Server::Private::contacts_handler(const Command& cmd) { diff --git a/mu4e/mu4e-obsolete.el b/mu4e/mu4e-obsolete.el index e02f2af2..a85f61cc 100644 --- a/mu4e/mu4e-obsolete.el +++ b/mu4e/mu4e-obsolete.el @@ -36,6 +36,8 @@ (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 'mu4e-compose-crypto-reply-encrypted-policy' variable is deprecated. 'mu4e-compose-crypto-policy' should be used instead" "2020-03-06") diff --git a/mu4e/mu4e-server.el b/mu4e/mu4e-server.el index 176f2284..2830021f 100644 --- a/mu4e/mu4e-server.el +++ b/mu4e/mu4e-server.el @@ -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 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 .") - (defvar mu4e-info-func nil "Function called for each (:info type ....) sexp received. from the server process.") @@ -563,20 +556,6 @@ On success, we receive `'(:info add :path :docid )' as well as `'(:update )`'; otherwise, we receive an error." (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) "Ask for contacts with PERSONAL AFTER MAXNUM TSTAMP. diff --git a/mu4e/mu4e.el b/mu4e/mu4e.el index 8fa3d2d0..d202a3ce 100644 --- a/mu4e/mu4e.el +++ b/mu4e/mu4e.el @@ -255,7 +255,6 @@ chance." (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-compose-func #'mu4e--compose-setup) (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-pong-func #'mu4e--default-handler)