Subject: Re: bug#39112: 27.0.60; gnus-summary-attach-article 'S A' with multiple articles selected repeats latest article

From: Eric Abrahamsen <[email-masked]>
Date: Fri, 17 Jan 2020 21:07:54 -0800

On 01/14/20 03:42 AM, Pankaj Jangid wrote:
> Eric Abrahamsen <[email-masked]> writes:
>
>>> That command sets up the message-mode buffer and makes it current
>>> before iterating over the articles, so it's unable to actually find
>>> the articles and simply repeats the last value of
>>> gnus-original-article-buffer.
>>
>> Okay, that was only right by accident. The real problem was that the
>> code inside the iterate was setting the buffer to the message-mode
>> buffer. Then the calls to `gnus-summary-select-article' kept
>> re-setting to the summary-buffer, but always on the same article.
>>
>> Anyway, would you test this patch and confirm it fixes the problem?
>
> Just did that. Following observation,
>
> when I process mark multiple items in summary-buffer and move the point
> to anything other than the latest marked mail and then press 'S A', the
> last mail is not added and the second-last email gets attached twice.
>
> When the point is on the last marked email and then I press 'S A', it
> works fine.

Sorry, got busy for a couple of days there...

Looks like the currently-opened message is interfering with the process
somewhat. I've tried this out a few different ways and this new version
of the patch seems to do the right thing, would you give it another
shot?

Eric

diff --git a/lisp/gnus/gnus-msg.el b/lisp/gnus/gnus-msg.el
index 466a62713e..daaea3980b 100644
--- a/lisp/gnus/gnus-msg.el
+++ b/lisp/gnus/gnus-msg.el
@@ -1985,13 +1985,14 @@ gnus-summary-attach-article
                                       buffers t nil nil (car buffers))))
       (gnus-summary-mail-other-window)
       (setq destination (current-buffer)))
+    (gnus-summary-expand-window)
     (gnus-summary-iterate n
       (gnus-summary-select-article)
-      (set-buffer destination)
-      ;; Attach at the end of the buffer.
-      (save-excursion
-	(goto-char (point-max))
-	(message-forward-make-body-mime gnus-original-article-buffer)))
+      (with-current-buffer destination
+       ;; Attach at the end of the buffer.
+       (save-excursion
+	 (goto-char (point-max))
+	 (message-forward-make-body-mime gnus-original-article-buffer))))
     (gnus-configure-windows 'message t)))
 
 (provide 'gnus-msg)