Subject: bug#66330: 28.2; Gnus wide reply (S W) changes Subject header when used from Debbugs thread

From: Maxim Cournoyer <[email-masked]>
Date: Tue, 03 Oct 2023 20:26:26 -0400

Hi,

When attempting to reply from an Emacs Debbugs thread specific email,
the Subject line gets set to the subject of the first email in the
thread rather than to that of the specific email I'm replying to, which
looses context.

Example/reproducer:

$ guix shell --container emacs-no-x emacs-debbugs -- emacs

>From the launched Emacs:

1. M-x debbugs-gnu-bugs 65479

2. Press 'a' to load the bug despite the lack of SSL certificates.

3. Navigate to the message titled:
[bug#65479] [PATCH core-updates 02/61] gnu: Add docbook-xml-5.

4. Press S W to send a wide reply.

5. Observe that the Subject header in the email response being edited
has been changed to "Re: bug#65479: [PATCH core-updates 00/61] The
Draining of the XML & DocBook Swamp.", that is, the original subject of
the "bug" (its first message).

I haven't been able to explain what causes that, but I've found where it
occurs.  Following the original 'gnus-article-wide-reply-with-original'
call, it eventually calls to 'message-setup-1', and the Subject
modification happens by unknown code (hooks?) just before the line 6870
("(run-hooks 'message-setup-hook)") runs:

--8<---------------cut here---------------start------------->8---
(defun message-setup-1 (headers &optional yank-action actions return-action)
  (dolist (action actions)
    (condition-case nil
        ;; FIXME: Use functions rather than expressions!
	(add-to-list 'message-send-actions
		     `(apply #',(car action) ',(cdr action)))))
  (setq message-return-action return-action)
  
[...]

  (run-hooks 'message-signature-setup-hook)
  (message-insert-signature)
  (save-restriction
    (message-narrow-to-headers)
    (run-hooks 'message-header-setup-hook))
  (setq buffer-undo-list nil)
  (when message-generate-hashcash
    ;; Generate hashcash headers for recipients already known
    (mail-add-payment-async))

===> Subject header changed HERE

  ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
  ;; values.
  (run-hooks 'message-setup-hook)
  ;; Do this last to give it precedence over posting styles, etc.
  (when (message-mail-p)
    (save-restriction
      (message-narrow-to-headers)
      (if message-alternative-emails
	  (message-use-alternative-email-as-from))))
  (message-position-point)
  ;; Allow correct handling of `message-checksum' in `message-yank-original':
  (set-buffer-modified-p nil)
  (undo-boundary)
  ;; rmail-start-mail expects message-mail to return t (Bug#9392)
  t)
--8<---------------cut here---------------end--------------->8---

Would someone be able to explain what is responsible for this?  It seems
to me it'd be preferable if the subject of the message I'm replying to
was kept rather than replaced this way, to preserve context.

-- 
Thanks,
Maxim