Subject: bug#67360: 29.1; MH-E forwarded email has a mangled default Subject header

From: Bill Wohler <[email-masked]>
Date: Sat, 30 Dec 2023 14:05:29 -0800

Thanks, Mike! My forwcomps only injects one header field so I never saw
this before. Uncommenting the Subject field made it possible to
reproduce this issue.

Yes, I agree that the code clearly wants to replace the Subject field,
not append to it, and this patch works for me as well. Please feel free
to commit the patch and resolve the issue. Thanks again!

Mike Kupfer <[email-masked]> wrote:

> Eli Zaretskii wrote:
> 
> > > From: Chris Siebenmann <[email-masked]>
> > > Date: Tue, 21 Nov 2023 19:49:24 -0500
> > > 
> > > If you attempt to forward an email message in MH-E with mh-forward
> > > (bound to eg 'f'), then the resulting Subject: of the draft message will
> > > be manged and come out as, for example:
> > > 
> > > 	Subject: test forwarding subject (fwd) Chris Siebenmann: test forwarding subject
> [...]
> > > I suspect that the intention is to replace any existing Subject:, or
> > > perhaps mh-forward assumes that the draft won't have one. Unfortunately
> > > for mh-forward, mh-insert-fields is specifically documented to *append*
> > > to the existing header field value, if there is one, not overwrite it,
> > > so the resulting Subject: of the draft is as we see here: the original
> > > subject created by 'forw', and then an appended Subject from mh-forward.
> > > This result is not terribly useful.
> 
> Indeed.
> 
> Yeah, mh-insert-fields seems like the wrong choice for Subject.  It's
> more suited for headers like To or Cc, when you might want to add to the
> existing list of recipients.  Replacing mh-insert-fields with
> mh-modify-header-field works for me.
> 
> diff --git a/lisp/mh-e/mh-comp.el b/lisp/mh-e/mh-comp.el
> index 92d31bf1826..0d1dcdf626a 100644
> --- a/lisp/mh-e/mh-comp.el
> +++ b/lisp/mh-e/mh-comp.el
> @@ -574,7 +574,7 @@ mh-forward
>          (setq orig-subject (mh-get-header-field "Subject:")))
>        (let ((forw-subject
>               (mh-forwarded-letter-subject orig-from orig-subject)))
> -        (mh-insert-fields "Subject:" forw-subject)
> +        (mh-modify-header-field "Subject" forw-subject t)
>          (goto-char (point-min))
>          ;; Set the local value of mh-mail-header-separator according to what is
>          ;; present in the buffer...
> 
> > > Reproduction in emacs -Q provided you have NMH and MH-E set up:
> > > * enter MH-E with 'M-x mh-rmail'
> > > * arrange to have some message in your inbox that you can forward, for
> > >   example by 'F r' to see all of your inbox.
> 
> Hide your personal forwcomps if you have one.
> 
> > > * display your test message to forward, eg cursor to it and hit Return
> > > * start to forward with 'f' or 'M-x mh-forward'.
> 
> mike
> 

-- 
Bill Wohler <[email-masked]> aka <[email-masked]>
http://www.newt.com/wohler/, GnuPG ID:610BD9AD