From: Kevin McCarthy Date: Wed, 22 Aug 2018 22:07:45 +0000 (-0700) Subject: Add compose-to-sender functionality. X-Git-Tag: 2019-10-25~671^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ffa7736b7ac164cc4ca6371fd28a43a9f884b68;p=neomutt Add compose-to-sender functionality. This patch is loosely based on the NeoMutt feature, but adds in support for the attach menu, reuses functionality in send.c, and has proper mode checks. Thanks to Enno for the opening the ticket requesting the port. --- diff --git a/curs_main.c b/curs_main.c index 39e4af24a..f531463b0 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1764,11 +1764,11 @@ int mutt_index_menu(void) break; case OP_COMPOSE_TO_SENDER: - if (Context) - { - mutt_compose_to_sender(tag ? NULL : CURHDR); - menu->redraw = REDRAW_FULL; - } + CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + ci_send_message (SEND_TO_SENDER, NULL, NULL, Context, tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; break; /* -------------------------------------------------------------------- diff --git a/functions.h b/functions.h index 78e4eb52e..dcdcea96a 100644 --- a/functions.h +++ b/functions.h @@ -394,6 +394,7 @@ const struct Binding OpAttach[] = { /* map: attachment */ { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" }, { "collapse-parts", OP_ATTACH_COLLAPSE, "v" }, + { "compose-to-sender", OP_COMPOSE_TO_SENDER, NULL }, { "delete-entry", OP_DELETE, "d" }, { "display-toggle-weed", OP_DISPLAY_HEADERS, "h" }, { "edit-type", OP_EDIT_TYPE, "\005" }, diff --git a/opcodes.h b/opcodes.h index 1b64eb8ee..3ad260f30 100644 --- a/opcodes.h +++ b/opcodes.h @@ -76,7 +76,7 @@ _fmt(OP_COMPOSE_TOGGLE_DISPOSITION, N_("toggle disposition between inline/attachment")) \ _fmt(OP_COMPOSE_TOGGLE_RECODE, N_("toggle recoding of this attachment")) \ _fmt(OP_COMPOSE_TOGGLE_UNLINK, N_("toggle whether to delete file after sending it")) \ - _fmt(OP_COMPOSE_TO_SENDER, N_("compose a new message to the sender")) \ + _fmt(OP_COMPOSE_TO_SENDER, N_("compose new message to the current message sender")) \ _fmt(OP_COMPOSE_UPDATE_ENCODING, N_("update an attachment's encoding info")) \ _fmt(OP_COMPOSE_WRITE_MESSAGE, N_("write the message to a folder")) \ _fmt(OP_COPY_MESSAGE, N_("copy a message to a file/mailbox")) \ diff --git a/pager.c b/pager.c index bf8e707b1..5a85e5cbf 100644 --- a/pager.c +++ b/pager.c @@ -2899,7 +2899,12 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e break; case OP_COMPOSE_TO_SENDER: - mutt_compose_to_sender(extra->hdr); + CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra)); + CHECK_ATTACH; + if (IsMsgAttach (extra)) + mutt_attach_mail_sender (extra->fp, extra->hdr, extra->actx, extra->bdy); + else + ci_send_message (SEND_TO_SENDER, NULL, NULL, extra->ctx, extra->hdr); pager_menu->redraw = REDRAW_FULL; break; diff --git a/recvattach.c b/recvattach.c index c4bfc6131..2d0b094fc 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1568,6 +1568,13 @@ void mutt_view_attachments(struct Header *hdr) menu->redraw = REDRAW_FULL; break; + case OP_COMPOSE_TO_SENDER: + CHECK_ATTACH; + mutt_attach_mail_sender (CURATTACH->fp, hdr, actx, + menu->tagprefix ? NULL : CURATTACH->content); + menu->redraw = REDRAW_FULL; + break; + case OP_EDIT_TYPE: recvattach_edit_content_type(actx, menu, hdr); menu->redraw |= REDRAW_INDEX; diff --git a/recvcmd.c b/recvcmd.c index e087e806f..568d4bfe2 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -1035,3 +1035,32 @@ void mutt_attach_reply(FILE *fp, struct Header *hdr, struct AttachCtx *actx, mutt_set_flag(Context, hdr, MUTT_REPLIED, 1); } } + +void mutt_attach_mail_sender(FILE *fp, struct Header *hdr, + struct AttachCtx *actx, struct Body *cur) +{ + if (!check_all_msg(actx, cur, 0)) + { + mutt_error(_("You may only compose to sender with message/rfc822 parts.")); + return; + } + + struct Header *tmphdr = mutt_header_new(); + tmphdr->env = mutt_env_new(); + + if (cur) + { + if (mutt_fetch_recips(tmphdr->env, cur->hdr->env, SEND_TO_SENDER) == -1) + return; + } + else + { + for (int i = 0; i < actx->idxlen; i++) + { + if (actx->idx[i]->content->tagged && + mutt_fetch_recips(tmphdr->env, actx->idx[i]->content->hdr->env, SEND_TO_SENDER) == -1) + return; + } + } + ci_send_message(0, tmphdr, NULL, NULL, NULL); +} diff --git a/recvcmd.h b/recvcmd.h index f3d714f1c..b6a703a06 100644 --- a/recvcmd.h +++ b/recvcmd.h @@ -36,5 +36,6 @@ void mutt_attach_bounce(FILE *fp, struct AttachCtx *actx, struct Body *cur); void mutt_attach_resend(FILE *fp, struct AttachCtx *actx, struct Body *cur); void mutt_attach_forward(FILE *fp, struct Header *hdr, struct AttachCtx *actx, struct Body *cur, int flags); void mutt_attach_reply(FILE *fp, struct Header *hdr, struct AttachCtx *actx, struct Body *cur, int flags); +void mutt_attach_mail_sender(FILE *fp, struct Header *hdr, struct AttachCtx *actx, struct Body *cur); #endif /* _MUTT_RECVCMD_H */ diff --git a/send.c b/send.c index 3486e180b..e69efb6ad 100644 --- a/send.c +++ b/send.c @@ -760,6 +760,10 @@ int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, int flags) return -1; /* abort */ } } + else if (flags & SEND_TO_SENDER) + { + mutt_addr_append(&out->to, in->from, 0); + } else { if (default_to(&out->to, in, flags & SEND_GROUP_REPLY, hmfupto) == MUTT_ABORT) @@ -965,7 +969,7 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, if (!curenv) return -1; - if (flags & SEND_REPLY) + if (flags & (SEND_REPLY|SEND_TO_SENDER)) { #ifdef USE_NNTP if ((flags & SEND_NEWS)) @@ -999,8 +1003,11 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, return -1; } - mutt_make_misc_reply_headers(env, curenv); - make_reference_headers(tag ? NULL : curenv, env, ctx); + if (flags & SEND_REPLY) + { + mutt_make_misc_reply_headers(env, curenv); + make_reference_headers (tag ? NULL : curenv, env, ctx); + } } else if (flags & SEND_FORWARD) { @@ -1401,32 +1408,6 @@ static void fix_end_of_file(const char *data) mutt_file_fclose(&fp); } -/** - * mutt_compose_to_sender - Compose an email to the sender - * @param hdr Header of original email - * @retval 0 Message was successfully sent - * @retval -1 Message was aborted or an error occurred - * @retval 1 Message was postponed - */ -int mutt_compose_to_sender(struct Header *hdr) -{ - struct Header *msg = mutt_header_new(); - - msg->env = mutt_env_new(); - if (!hdr) - { - for (int i = 0; i < Context->msgcount; i++) - { - if (message_is_tagged(Context, i)) - mutt_addr_append(&msg->env->to, Context->hdrs[i]->env->from, false); - } - } - else - msg->env->to = mutt_addr_copy_list(hdr->env->from, false); - - return ci_send_message(0, msg, NULL, NULL, NULL); -} - /** * mutt_resend_message - Resend an email * @param fp File containing email @@ -1729,7 +1710,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, if (!(flags & (SEND_POSTPONED | SEND_RESEND)) && !((flags & SEND_DRAFT_FILE) && ResumeDraftFiles)) { - if ((flags & (SEND_REPLY | SEND_FORWARD)) && ctx && + if ((flags & (SEND_REPLY | SEND_FORWARD | SEND_TO_SENDER)) && ctx && envelope_defaults(msg->env, ctx, cur, flags) == -1) { goto cleanup; diff --git a/send.h b/send.h index 480dc1d3e..a1d1231d3 100644 --- a/send.h +++ b/send.h @@ -91,11 +91,11 @@ extern bool UseFrom; #define SEND_POSTPONED_FCC (1 << 9) /**< used by mutt_get_postponed() to signal that the x-mutt-fcc header field was present */ #define SEND_NO_FREE_HEADER (1 << 10) /**< Used by the -E flag */ #define SEND_DRAFT_FILE (1 << 11) /**< Used by the -H flag */ -#define SEND_NEWS (1 << 12) +#define SEND_TO_SENDER (1 << 12) +#define SEND_NEWS (1 << 13) int ci_send_message(int flags, struct Header *msg, char *tempfile, struct Context *ctx, struct Header *cur); void mutt_add_to_reference_headers(struct Envelope *env, struct Envelope *curenv); -int mutt_compose_to_sender(struct Header *hdr); struct Address *mutt_default_from(void); void mutt_encode_descriptions(struct Body *b, bool recurse); int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, int flags);