unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#53991: Fix header mangling by message-hide-headers
@ 2022-02-14  9:05 Philip Kaludercic
  2022-02-14 10:51 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Philip Kaludercic @ 2022-02-14  9:05 UTC (permalink / raw)
  To: 53991

[-- Attachment #1: Type: text/plain, Size: 1614 bytes --]

Tags: patch


I have been having issues with mangled headers for a while not,
especially when resuming a message using C-u C-x m.  This could result
in headers being inserted right in the middle of other headers resulting
in stuff like this:

   To: bug-gnuReferences: <...>
   -emacs@gnu.org

that in the best case raises an issue when being sent, in the worse case
silently breaks without you knowing that it was broken.

It appears this was caused by setting mail-user-agent to
'gnus-user-agent.  In gnus-msg-mail, gnus-setup-message calls
message-hide-headers that would try to reorder the headers so that the
headers indicated by message-hidden-headers are placed at the beginning
of the buffer, then narrowed away.  The simplest fix for this issue in
case anyone were to stumble upon it in the future is to set the
message-hidden-headers to nil.

The more complex solution is attached below, and involves replacing the
manual end-of-headers tracking with a marker, that resolves the issue
that the previous implementation had, where end-of-headers could point
right into the middle of a header as described above.

In GNU Emacs 29.0.50 (build 6, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars)
 of 2022-02-06 built on icterid
Repository revision: b0fd3ec2c0131e79b1c62e1f1beb6f29cf076120
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-x-toolkit=athena --with-native-compilation
 'CFLAGS=-Os -march=native -mtune=native -pipe' LDFLAGS=-flto'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-stability-of-message-hide-headers.patch --]
[-- Type: text/patch, Size: 1790 bytes --]

From c64dae033a5ef48beb1895790d678b016f03e017 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Mon, 14 Feb 2022 09:29:04 +0100
Subject: [PATCH] Improve stability of message-hide-headers

* message.el (message-hide-headers): Use a pointer instead of tracking
  the "end-of-headers" point manually.
---
 lisp/gnus/message.el | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index a6c6a16653..9327259c60 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -8621,26 +8621,23 @@ message-hide-headers
 		   message-hidden-headers))
 	(inhibit-point-motion-hooks t)
 	(inhibit-modification-hooks t)
-	(end-of-headers (point-min)))
+	end-of-headers)
     (when regexps
       (save-excursion
 	(save-restriction
 	  (message-narrow-to-headers)
+          (setq end-of-headers (point-min-marker))
 	  (goto-char (point-min))
 	  (while (not (eobp))
 	    (if (not (message-hide-header-p regexps))
 		(message-next-header)
-	      (let ((begin (point))
-		    header header-len)
+	      (let ((begin (point)))
 		(message-next-header)
-		(setq header (buffer-substring begin (point))
-		      header-len (- (point) begin))
-		(delete-region begin (point))
-		(goto-char end-of-headers)
-		(insert header)
-		(setq end-of-headers
-		      (+ end-of-headers header-len))))))))
-    (narrow-to-region end-of-headers (point-max))))
+                (let ((header (delete-and-extract-region begin (point))))
+                  (save-excursion
+                    (goto-char end-of-headers)
+                    (insert-before-markers header))))))))
+      (narrow-to-region end-of-headers (point-max)))))
 
 (defun message-hide-header-p (regexps)
   (let ((result nil)
-- 
2.30.2


[-- Attachment #3: Type: text/plain, Size: 24 bytes --]


-- 
	Philip Kaludercic

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#53991: Fix header mangling by message-hide-headers
  2022-02-14  9:05 bug#53991: Fix header mangling by message-hide-headers Philip Kaludercic
@ 2022-02-14 10:51 ` Lars Ingebrigtsen
  2022-02-14 13:38   ` Philip Kaludercic
  0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-14 10:51 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 53991

Philip Kaludercic <philipk@posteo.net> writes:

> The more complex solution is attached below, and involves replacing the
> manual end-of-headers tracking with a marker, that resolves the issue
> that the previous implementation had, where end-of-headers could point
> right into the middle of a header as described above.

Looks good to me; pushed to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#53991: Fix header mangling by message-hide-headers
  2022-02-14 10:51 ` Lars Ingebrigtsen
@ 2022-02-14 13:38   ` Philip Kaludercic
  2022-02-14 13:46     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Philip Kaludercic @ 2022-02-14 13:38 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 53991

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Philip Kaludercic <philipk@posteo.net> writes:
>
>> The more complex solution is attached below, and involves replacing the
>> manual end-of-headers tracking with a marker, that resolves the issue
>> that the previous implementation had, where end-of-headers could point
>> right into the middle of a header as described above.
>
> Looks good to me; pushed to Emacs 29.

As this issue presumably also affects older versions (the code hasn't
changed for years), should it also be applied to emacs-28?

-- 
	Philip Kaludercic





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#53991: Fix header mangling by message-hide-headers
  2022-02-14 13:38   ` Philip Kaludercic
@ 2022-02-14 13:46     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-14 13:46 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 53991

Philip Kaludercic <philipk@posteo.net> writes:

> As this issue presumably also affects older versions (the code hasn't
> changed for years), should it also be applied to emacs-28?

No, we're only fixing regressions in the emacs-28 branch now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-14 13:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14  9:05 bug#53991: Fix header mangling by message-hide-headers Philip Kaludercic
2022-02-14 10:51 ` Lars Ingebrigtsen
2022-02-14 13:38   ` Philip Kaludercic
2022-02-14 13:46     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).