Commit 32734a9f authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

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.
parent 1d3b82b7
Pipeline #28479518 passed with stages
in 14 minutes and 49 seconds
......@@ -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"
......
......@@ -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);
......
......@@ -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);
......
......@@ -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" },
......
......@@ -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)
......
......@@ -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))
......
......@@ -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:
......
......@@ -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);
}
/**
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment