From: Kevin McCarthy Date: Wed, 22 Aug 2018 22:07:45 +0000 (-0700) Subject: Add compose-to-sender functionality. X-Git-Tag: mutt-1-11-rel~83 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32734a9fb5d4dc68a9c557d472dbfdee0a4b5d26;p=mutt 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/OPS b/OPS index c0c95806..e9779874 100644 --- a/OPS +++ b/OPS @@ -39,6 +39,7 @@ OP_COMPOSE_POSTPONE_MESSAGE "save this message to send later" OP_COMPOSE_RENAME_ATTACHMENT "send attachment with a different name" OP_COMPOSE_RENAME_FILE "rename/move an attached file" OP_COMPOSE_SEND_MESSAGE "send the message" +OP_COMPOSE_TO_SENDER "compose new message to the current message sender" OP_COMPOSE_TOGGLE_DISPOSITION "toggle disposition between inline/attachment" OP_COMPOSE_TOGGLE_UNLINK "toggle whether to delete file after sending it" OP_COMPOSE_UPDATE_ENCODING "update an attachment's encoding info" diff --git a/attach.h b/attach.h index 12e3ca04..84b1fd24 100644 --- a/attach.h +++ b/attach.h @@ -73,6 +73,7 @@ void mutt_attach_bounce (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *); void mutt_attach_resend (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *); void mutt_attach_forward (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *); void mutt_attach_reply (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *, int); +void mutt_attach_mail_sender (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *); void mutt_actx_add_attach (ATTACH_CONTEXT *actx, ATTACHPTR *attach); void mutt_actx_add_fp (ATTACH_CONTEXT *actx, FILE *new_fp); diff --git a/curs_main.c b/curs_main.c index 18493bb7..9556c920 100644 --- a/curs_main.c +++ b/curs_main.c @@ -2056,6 +2056,15 @@ int mutt_index_menu (void) ci_bounce_message (tag ? NULL : CURHDR); break; + case OP_COMPOSE_TO_SENDER: + + CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + ci_send_message (SENDTOSENDER, NULL, NULL, Context, tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; + break; + case OP_CREATE_ALIAS: mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, NULL); diff --git a/functions.h b/functions.h index 442531ad..3ce925f8 100644 --- a/functions.h +++ b/functions.h @@ -93,6 +93,7 @@ const struct binding_t OpMain[] = { /* map: index */ { "next-unread-mailbox", OP_MAIN_NEXT_UNREAD_MAILBOX, NULL }, { "collapse-thread", OP_MAIN_COLLAPSE_THREAD, "\033v" }, { "collapse-all", OP_MAIN_COLLAPSE_ALL, "\033V" }, + { "compose-to-sender", OP_COMPOSE_TO_SENDER, NULL}, { "copy-message", OP_COPY_MESSAGE, "C" }, { "decode-copy", OP_DECODE_COPY, "\033C" }, { "decode-save", OP_DECODE_SAVE, "\033s" }, @@ -195,6 +196,7 @@ const struct binding_t OpPager[] = { /* map: pager */ { "change-folder", OP_MAIN_CHANGE_FOLDER, "c" }, { "change-folder-readonly", OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" }, { "next-unread-mailbox", OP_MAIN_NEXT_UNREAD_MAILBOX, NULL }, + { "compose-to-sender", OP_COMPOSE_TO_SENDER, NULL}, { "copy-message", OP_COPY_MESSAGE, "C" }, { "decode-copy", OP_DECODE_COPY, "\033C" }, { "delete-message", OP_DELETE, "d" }, @@ -310,6 +312,7 @@ const struct binding_t OpPager[] = { /* map: pager */ const struct binding_t OpAttach[] = { /* map: attachment */ { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, { "display-toggle-weed", OP_DISPLAY_HEADERS, "h" }, + { "compose-to-sender", OP_COMPOSE_TO_SENDER, NULL}, { "edit-type", OP_EDIT_TYPE, "\005" }, { "print-entry", OP_PRINT, "p" }, { "save-entry", OP_SAVE, "s" }, diff --git a/mutt.h b/mutt.h index aea790f1..d541ae9a 100644 --- a/mutt.h +++ b/mutt.h @@ -345,6 +345,7 @@ enum #define SENDPOSTPONEDFCC (1<<9) /* used by mutt_get_postponed() to signal that the x-mutt-fcc header field was present */ #define SENDNOFREEHEADER (1<<10) /* Used by the -E flag */ #define SENDDRAFTFILE (1<<11) /* Used by the -H flag */ +#define SENDTOSENDER (1<<12) /* flags for mutt_compose_menu() */ #define MUTT_COMPOSE_NOFREEHEADER (1<<0) diff --git a/pager.c b/pager.c index 2a1dae79..ac7196b8 100644 --- a/pager.c +++ b/pager.c @@ -2471,7 +2471,18 @@ search_next: rc = OP_CHECK_TRADITIONAL; } break; - + + case OP_COMPOSE_TO_SENDER: + 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 (SENDTOSENDER, NULL, NULL, extra->ctx, extra->hdr); + pager_menu->redraw = REDRAW_FULL; + break; + case OP_CREATE_ALIAS: CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra)); if (IsMsgAttach (extra)) diff --git a/recvattach.c b/recvattach.c index 768e1d6f..6f52ff01 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1322,6 +1322,13 @@ void mutt_view_attachments (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_REPLY: case OP_GROUP_REPLY: case OP_LIST_REPLY: diff --git a/recvcmd.c b/recvcmd.c index 17a027e1..32060f4b 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -706,6 +706,38 @@ void mutt_attach_forward (FILE * fp, HEADER * hdr, } } +void mutt_attach_mail_sender (FILE *fp, HEADER *hdr, ATTACH_CONTEXT *actx, + BODY *cur) +{ + HEADER *tmphdr = NULL; + short i; + + if (check_all_msg (actx, cur, 0) == -1) + { + mutt_error _("You may only compose to sender with message/rfc822 parts."); + return; + } + + tmphdr = mutt_new_header (); + tmphdr->env = mutt_new_envelope (); + + if (cur) + { + if (mutt_fetch_recips (tmphdr->env, cur->hdr->env, SENDTOSENDER) == -1) + return; + } + else + { + for (i = 0; i < actx->idxlen; i++) + { + if (actx->idx[i]->content->tagged && + mutt_fetch_recips (tmphdr->env, actx->idx[i]->content->hdr->env, + SENDTOSENDER) == -1) + return; + } + } + ci_send_message (0, tmphdr, NULL, NULL, NULL); +} /** diff --git a/send.c b/send.c index 51c2fc25..70c5be96 100644 --- a/send.c +++ b/send.c @@ -549,6 +549,8 @@ int mutt_fetch_recips (ENVELOPE *out, ENVELOPE *in, int flags) default_to (&out->cc, in, flags & SENDLISTREPLY, hmfupto) == -1) return (-1); /* abort */ } + else if (flags & SENDTOSENDER) + rfc822_append (&out->to, in->from, 0); else { if (default_to (&out->to, in, flags & SENDGROUPREPLY, hmfupto) == -1) @@ -716,7 +718,7 @@ envelope_defaults (ENVELOPE *env, CONTEXT *ctx, HEADER *cur, int flags) else curenv = cur->env; - if (flags & SENDREPLY) + if (flags & (SENDREPLY|SENDTOSENDER)) { if (tag) { @@ -738,8 +740,11 @@ envelope_defaults (ENVELOPE *env, CONTEXT *ctx, HEADER *cur, int flags) return (-1); } - mutt_make_misc_reply_headers (env, ctx, cur, curenv); - mutt_make_reference_headers (tag ? NULL : curenv, env, ctx); + if (flags & SENDREPLY) + { + mutt_make_misc_reply_headers (env, ctx, cur, curenv); + mutt_make_reference_headers (tag ? NULL : curenv, env, ctx); + } } else if (flags & SENDFORWARD) mutt_make_forward_subject (env, ctx, cur); @@ -1315,7 +1320,7 @@ ci_send_message (int flags, /* send mode */ if (! (flags & (SENDPOSTPONED|SENDRESEND)) && ! ((flags & SENDDRAFTFILE) && option (OPTRESUMEDRAFTFILES))) { - if ((flags & (SENDREPLY | SENDFORWARD)) && ctx && + if ((flags & (SENDREPLY | SENDFORWARD | SENDTOSENDER)) && ctx && envelope_defaults (msg->env, ctx, cur, flags) == -1) goto cleanup;