Re: [PATCH] wip: Add forward-message-refs function.

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <apAL5KhK7w8EjBDr@devuan>
Hi Kevin,

> Date: 2026-08-27 10:58:09+0800
> From: "Kevin J. McCarthy" <[email protected]>
>
> This is NOT ready for committing.  I'm sending this out to get general
> feedback on the idea of using a function as opposed to a quadoption,
> and on a few implementation details.
> 
> This reuses the existing Mutt functions to set references, which means
> they are like reply references: the full list.  It clears out the
> In-Reply-To header afterwards, because I personally feel like that
> header is a step too far for a "forward".

Seems reasonable.

> 
> There is code to support taggged messages, however the Mutt

s/ggg/gg/

> code (at least in the index and pager) on purpose removes References
> that are combined from two different "parents".  See
> https://gitlab.com/muttmua/mutt/-/blob/2edbf659b7882b611fcfb4cb509b66349090134f/send.c#L827

Out of curiousity, how can a message have more than one parents?
How do I trigger such a case?  Is it that if I reply/forward while
having several tagged paragraphs, the rpely/fwd has all the tagged
messages as parents?  (I have never done something like that.)

> 
> Note the attachment menu is missing that check (in the reply case
> too). :shrug:.  I'd appreciate feeedback about what to do with tagged
> messages.  I don't think mixing References: headers makes sense for
> more than one message, but I haven't disabled it in the attachment
> menu (yet).

I have never done this, so I can't comment much.

> 
> I thought the quadoption, for those who want to choose, might be a bit
> annoying after a while.

I personally don't forward enough messages that it could become
annoying.  However, I expect if it could become annoying to someone,
they could enable it as 'yes', and then edit out the headers in the
editor in the few cases where they want it removed.  In general, I
suspect one will want either yes or no, and ask-yes will be a bit rare,
with ask-no being more rare.  Thus, I expect this manual editing would
be rare.

We'd need to allow editing the References field (currently, it's not,
AFAIK).

>  I'd like feedback about this implementation
> versus a quadoption.  With two functions, you can bind to different
> keys.  It's also possible to implement a toggle function (but of
> course that can be done with a quadoption too):

I expect one would only want one of them (likely, depending on religious
believes), so the new function might be a bit overkill.  I'd find it
surprising that one would want to have both functions available.

> 
> set muttlisp_inline_eval
> set my_f = "normal forward"
> macro index,pager ,f                      \
> '<enter-command>bind index,pager,attach f \
>     (if (equal $my_f "normal forward") \
>         forward-message-refs           \
>       forward-message)<enter>\
> <enter-command>set my_f =              \
>   (if (equal $my_f "normal forward")   \
>       "forward with references"        \
>     "normal forward")<enter>\
> <enter-command>echo $my_f<enter>'
> ---
>  OPS          |  7 +++++++
>  attach.h     |  2 +-
>  curs_main.c  | 12 +++++++++---
>  functions.h  |  3 +++
>  mutt.h       |  1 +
>  pager.c      | 14 +++++++++++---
>  recvattach.c |  4 +++-
>  recvcmd.c    | 22 ++++++++++++++++++----
>  send.c       |  7 +++++++
>  9 files changed, 60 insertions(+), 12 deletions(-)

I have no comments on the code.  Thanks for implementing a draft of
this!


Have a lovely day!
Alex

> 
> diff --git a/OPS b/OPS
> index aee20ac1..d50510b8 100644
> --- a/OPS
> +++ b/OPS
> @@ -582,6 +582,13 @@ OP_FLAG_MESSAGE N_("toggle a message's 'important' flag")
>   */
>  OP_FORWARD_MESSAGE N_("forward a message with comments")
>  
> +/* L10N: Help screen description for OP_FORWARD_MESSAGE_REFS
> +   index menu: <forward-message-refs>
> +   pager menu: <forward-message-refs>
> +   attachment menu: <forward-message-refs>
> + */
> +OP_FORWARD_MESSAGE_REFS N_("forward a message with references headers and comments")
> +
>  /* L10N: Help screen description for OP_GENERIC_SELECT_ENTRY
>     generic menu: <select-entry>
>   */
> diff --git a/attach.h b/attach.h
> index 4838a9f0..a3075f85 100644
> --- a/attach.h
> +++ b/attach.h
> @@ -71,7 +71,7 @@ void mutt_print_attachment_list(ATTACH_CONTEXT *actx, FILE *fp, int tag, BODY *t
>  
>  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_forward(FILE *, HEADER *, ATTACH_CONTEXT *, BODY *, int);
>  void mutt_attach_reply(FILE *, HEADER *, ATTACH_CONTEXT *, BODY *, int);
>  void mutt_attach_mail_sender(FILE *, HEADER *, ATTACH_CONTEXT *, BODY *);
>  
> diff --git a/curs_main.c b/curs_main.c
> index 372007ff..b1b2bae2 100644
> --- a/curs_main.c
> +++ b/curs_main.c
> @@ -2312,17 +2312,23 @@ int mutt_index_menu(void)
>          break;
>  
>        case OP_FORWARD_MESSAGE:
> +      case OP_FORWARD_MESSAGE_REFS:
> +      {
> +        int forwardflags;
>  
>          CHECK_MSGCOUNT;
>          CHECK_VISIBLE;
>          CHECK_ATTACH;
> +
> +        forwardflags = SENDFORWARD | SENDBACKGROUNDEDIT |
> +          (op == OP_FORWARD_MESSAGE_REFS ? SENDFORWARDREFS : 0);
> +
>          if (option(OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
>            mutt_check_traditional_pgp(tag ? NULL : CURHDR, &menu->redraw);
> -        mutt_send_message(SENDFORWARD | SENDBACKGROUNDEDIT,
> -                          NULL, NULL, Context, tag ? NULL : CURHDR);
> +        mutt_send_message(forwardflags, NULL, NULL, Context, tag ? NULL : CURHDR);
>          menu->redraw = REDRAW_FULL;
>          break;
> -
> +      }
>  
>        case OP_FORGET_PASSPHRASE:
>          crypt_forget_passphrase();
> diff --git a/functions.h b/functions.h
> index eab3df3d..c8cb301f 100644
> --- a/functions.h
> +++ b/functions.h
> @@ -173,6 +173,7 @@ const struct menu_func_op_t OpMain[] = { /* map: index */
>    { "flag-message",              OP_FLAG_MESSAGE },
>    { "forget-passphrase",         OP_FORGET_PASSPHRASE },
>    { "forward-message",           OP_FORWARD_MESSAGE },
> +  { "forward-message-refs",      OP_FORWARD_MESSAGE_REFS },
>    { "group-chat-reply",          OP_GROUP_CHAT_REPLY },
>    { "group-reply",               OP_GROUP_REPLY },
>  #ifdef USE_IMAP
> @@ -371,6 +372,7 @@ const struct menu_func_op_t OpPager[] = { /* map: pager */
>    { "flag-message",              OP_FLAG_MESSAGE },
>    { "forget-passphrase",         OP_FORGET_PASSPHRASE },
>    { "forward-message",           OP_FORWARD_MESSAGE },
> +  { "forward-message-refs",      OP_FORWARD_MESSAGE_REFS },
>    { "group-chat-reply",          OP_GROUP_CHAT_REPLY },
>    { "group-reply",               OP_GROUP_REPLY },
>    { "half-down",                 OP_HALF_DOWN },
> @@ -571,6 +573,7 @@ const struct menu_func_op_t OpAttach[] = { /* map: attachment */
>    { "extract-keys",          OP_EXTRACT_KEYS },
>    { "forget-passphrase",     OP_FORGET_PASSPHRASE },
>    { "forward-message",       OP_FORWARD_MESSAGE },
> +  { "forward-message-refs",  OP_FORWARD_MESSAGE_REFS },
>    { "group-chat-reply",      OP_GROUP_CHAT_REPLY },
>    { "group-reply",           OP_GROUP_REPLY },
>    { "list-reply",            OP_LIST_REPLY },
> diff --git a/mutt.h b/mutt.h
> index cc3b0baa..816a557d 100644
> --- a/mutt.h
> +++ b/mutt.h
> @@ -353,6 +353,7 @@ enum
>  #define SENDGROUPCHATREPLY      (1<<13)
>  #define SENDBACKGROUNDEDIT      (1<<14)  /* Allow background editing */
>  #define SENDCHECKPOSTPONED      (1<<15)  /* Check for postponed messages */
> +#define SENDFORWARDREFS         (1<<16)
>  
>  /* flags for mutt_edit_headers() */
>  #define MUTT_EDIT_HEADERS_BACKGROUND  1
> diff --git a/pager.c b/pager.c
> index fcadf26e..820ed1fc 100644
> --- a/pager.c
> +++ b/pager.c
> @@ -2950,15 +2950,23 @@ search_next:
>          break;
>  
>        case OP_FORWARD_MESSAGE:
> +      case OP_FORWARD_MESSAGE_REFS:
> +      {
> +        int forwardflags;
> +
>          CHECK_MODE(IsHeader(extra) || IsMsgAttach(extra));
>          CHECK_ATTACH;
> +
> +        forwardflags = SENDFORWARD | SENDBACKGROUNDEDIT |
> +          (ch == OP_FORWARD_MESSAGE_REFS ? SENDFORWARDREFS : 0);
> +
>          if (IsMsgAttach(extra))
>            mutt_attach_forward(extra->fp, extra->hdr, extra->actx,
> -                              extra->bdy);
> +                              extra->bdy, forwardflags);
>          else
> -          mutt_send_message(SENDFORWARD | SENDBACKGROUNDEDIT,
> -                            NULL, NULL, extra->ctx, extra->hdr);
> +          mutt_send_message(forwardflags, NULL, NULL, extra->ctx, extra->hdr);
>          break;
> +      }
>  
>        case OP_DECRYPT_SAVE:
>          if (!WithCrypto)
> diff --git a/recvattach.c b/recvattach.c
> index 1ed30ed6..3ad3fe0d 100644
> --- a/recvattach.c
> +++ b/recvattach.c
> @@ -1599,9 +1599,11 @@ void mutt_view_attachments(HEADER *hdr)
>          break;
>  
>        case OP_FORWARD_MESSAGE:
> +      case OP_FORWARD_MESSAGE_REFS:
>          CHECK_ATTACH;
>          mutt_attach_forward(CURATTACH->fp, hdr, actx,
> -                            menu->tagprefix ? NULL : CURATTACH->content);
> +                            menu->tagprefix ? NULL : CURATTACH->content,
> +                            op == OP_FORWARD_MESSAGE_REFS ? SENDFORWARDREFS : 0);
>          menu->redraw = REDRAW_FULL;
>          break;
>  
> diff --git a/recvcmd.c b/recvcmd.c
> index a5fc5c8a..fbcbcee7 100644
> --- a/recvcmd.c
> +++ b/recvcmd.c
> @@ -629,7 +629,7 @@ bail:
>   */
>  
>  static void attach_forward_msgs(FILE * fp, HEADER * hdr,
> -                                ATTACH_CONTEXT *actx, BODY * cur)
> +                                ATTACH_CONTEXT *actx, BODY * cur, int flags)
>  {
>    HEADER *curhdr = NULL;
>    HEADER *tmphdr = NULL;
> @@ -656,6 +656,20 @@ static void attach_forward_msgs(FILE * fp, HEADER * hdr,
>    tmphdr->env = mutt_new_envelope();
>    mutt_make_forward_subject(tmphdr->env, Context, curhdr);
>  
> +  if (flags & SENDFORWARDREFS)
> +  {
> +    if (cur)
> +      mutt_add_to_reference_headers(tmphdr->env, curhdr->env, NULL, NULL);
> +    else
> +    {
> +      LIST **p = NULL, **q = NULL;
> +
> +      for (i = 0; i < actx->idxlen; i++)
> +        if (actx->idx[i]->content->tagged)
> +          mutt_add_to_reference_headers(tmphdr->env, actx->idx[i]->content->hdr->env, &p, &q);
> +    }
> +    mutt_free_list(&tmphdr->env->in_reply_to);
> +  }
>  
>    tmpbody = mutt_buffer_pool_get();
>  
> @@ -744,14 +758,14 @@ cleanup:
>    mutt_buffer_pool_release(&tmpbody);
>  }
>  
> -void mutt_attach_forward(FILE * fp, HEADER * hdr,
> -                         ATTACH_CONTEXT *actx, BODY * cur)
> +void mutt_attach_forward(FILE *fp, HEADER *hdr,
> +                         ATTACH_CONTEXT *actx, BODY *cur, int flags)
>  {
>    short nattach;
>  
>  
>    if (check_all_msg(actx, cur, 0) == 0)
> -    attach_forward_msgs(fp, hdr, actx, cur);
> +    attach_forward_msgs(fp, hdr, actx, cur, flags);
>    else
>    {
>      nattach = count_tagged(actx);
> diff --git a/send.c b/send.c
> index 65445b1c..7be6eded 100644
> --- a/send.c
> +++ b/send.c
> @@ -889,7 +889,14 @@ envelope_defaults(ENVELOPE *env, CONTEXT *ctx, HEADER *cur, int flags)
>      }
>    }
>    else if (flags & SENDFORWARD)
> +  {
> +    if (flags & SENDFORWARDREFS)
> +    {
> +      mutt_make_reference_headers(tag ? NULL : curenv, env, ctx);
> +      mutt_free_list(&env->in_reply_to);
> +    }
>      mutt_make_forward_subject(env, ctx, cur);
> +  }
>  
>    return (0);
>  }
> -- 
> 2.55.0
> 

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmqQELIACgkQ64mZXMKQ
wqkEOA/+JLdEWSMKlkMzMs3heeyXiy8rgxEiZ02Y1Etlyr6PkP6cqPJ29GrnHlVE
gh+mLUupaGeZJgfnSslw5I94vx6H5uNGPMSN0zFCavYmdyBrsWfUJwJ4vzDd7xIs
8YG3Y7QOaPLMWeIO4ePg5QBl0HYJkSqQ0IeLK/V7N6Mfe5l6TgtsjVIBUgMdRmr2
2zIO2IhwIRj6GrVhz2JIYrCg61ZNHXDGSo+N8gh4IXt37aG2MYoHglSdVD0B+k+w
kK/HAjlh0URXsAZgoWvOkao9dkQZLi+yBRcShxv8vkQisOg/5XNb1CtrcpMyOiS0
uoBVdCp+8HyX4iPRRqTmPKM94a51xk3TFNZMW0IBODmDtStCZGgfqTrwEARUtJLH
ZZhA06VdWawST/NK0NgIjyjptmTklGDAEcmLYToPKX8TWofBo9q7rkPt+MH/dOS/
JXJm/rKeFcD5b64TPtbw3YQnOdOVBZwJogSwfIe9fOwBHNn3sxnBqexwaJ9cMXIs
WtZUvlL9uILRh2vQ2ZDDYxNQg0wzwBODZlH3bN7/FpaO1jb3zIZqx7hbWufXPPE7
fRzD0jPwTDcnGUVUF3R68HaJzyqyzX7j4SP7Yw1OHzVjFO3uBlnCcgSI4HA/c9me
/cgRIcsulZr7Ezj8ATda2p+fTR1tJ86rCyCkiYXrX2b0JF6v6hg=
=kgrx
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.