unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* rmail-ordered-headers patch proposal
@ 2022-02-23 12:36 irek
  2022-02-25  5:00 ` Richard Stallman
  0 siblings, 1 reply; 2+ messages in thread
From: irek @ 2022-02-23 12:36 UTC (permalink / raw)
  To: emacs-devel

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

Hello, as suggested by Jean in thread "Fixed order of headers in Rmail
messages" from help-gnu-emacs@gnu.org mailing list I'm sending an patch
proposal for Rmail.

It adds new variable `rmail-ordered-headers' that gives control over
mail message headers order.  It's a list of string values being header
names.  When list is not nil then `rmail-copy-headers' function will
ignore `rmail-displayed-headers' and `rmail-ignored-headers' that are
regexp based.  Instead code will go over each `rmail-ordered-headers'
value searching for given header name and copy that header with
corresponding value if found, if not then it's skipped.

I have set default value for this custom variable because in my opinion
this should be a default behavior.

Motives behind all of this can be found in thread archive:
https://lists.gnu.org/archive/html/help-gnu-emacs/2022-02/msg00253.html
https://lists.gnu.org/archive/html/help-gnu-emacs/2022-02/msg00291.html

And in package commentary section that adds this behavior using advice:
https://github.com/ir33k/rmail-ordered-headers/blob/master/rmail-ordered-headers.el#L23

Basically patch does the same thing as mentioned package.

Happy to hear any comments on that, suggestions of changes etc.  I'm
aware that if this is going to be merged with Emacs code base then also
info page and NEWS file have to be updated.

BTW Tested on Emacs 25.2.2 and 29.0.50.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rmail-ordered-headers.diff --]
[-- Type: text/x-diff, Size: 1777 bytes --]

diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 6b058d09f9..bac810fa25 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -377,6 +377,17 @@ rmail-nonignored-headers
   :type '(choice (const nil) (regexp))
   :group 'rmail-headers)
 
+;;;###autoload
+(defcustom rmail-ordered-headers '("Date" "From" "To" "Reply-To" "Cc" "Bcc" "Thread-Topic" "Subject")
+  "List of Header field names that Rmail should display in given order.
+Headers with empty values are omitted.  Note that controlling
+headers using this variable is least performent comparing to
+`rmail-displayed-headers' and `rmail-ignored-headers' which are
+ignored when this var is not nil."
+  :type '(repeat string)
+  :group 'rmail-headers
+  :version "29.1")
+
 ;;;###autoload
 (defcustom rmail-displayed-headers nil
   "Regexp to match Header fields that Rmail should display.
@@ -2898,6 +2909,19 @@ rmail-copy-headers
 	      (with-current-buffer rmail-view-buffer
 		(goto-char (1+ len)))))
 
+           ;; Handle case where headers are copied in order.
+	   ((and rmail-ordered-headers (null ignored-headers))
+            (seq-each
+             (lambda (header)
+               (when (re-search-forward (format "^%s:" header) nil t)
+                 (append-to-buffer rmail-view-buffer
+                                   (match-beginning 0)
+                                   (if (re-search-forward header-start-regexp nil t)
+                                       (1- (match-end 0))
+                                     (point-max))))
+               (goto-char (point-min)))
+             rmail-ordered-headers))
+
 	   ;; Handle the case where the headers matching the displayed
 	   ;; headers regexp should be copied.
 	   ((and rmail-displayed-headers (null ignored-headers))

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

* Re: rmail-ordered-headers patch proposal
  2022-02-23 12:36 rmail-ordered-headers patch proposal irek
@ 2022-02-25  5:00 ` Richard Stallman
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Stallman @ 2022-02-25  5:00 UTC (permalink / raw)
  To: irek; +Cc: emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > It adds new variable `rmail-ordered-headers' that gives control over
  > mail message headers order.

This seems like a useful feature.  Thanks.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





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

end of thread, other threads:[~2022-02-25  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 12:36 rmail-ordered-headers patch proposal irek
2022-02-25  5:00 ` Richard Stallman

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).