From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: irek Newsgroups: gmane.emacs.devel Subject: rmail-ordered-headers patch proposal Date: Wed, 23 Feb 2022 13:36:05 +0100 Message-ID: <87pmndn4ju.fsf@gumen.pl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12281"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Feb 23 13:58:56 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMrEO-00030H-P0 for ged-emacs-devel@m.gmane-mx.org; Wed, 23 Feb 2022 13:58:56 +0100 Original-Received: from localhost ([::1]:34292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMrEN-0005FA-6r for ged-emacs-devel@m.gmane-mx.org; Wed, 23 Feb 2022 07:58:55 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:44992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMqsU-000142-W7 for emacs-devel@gnu.org; Wed, 23 Feb 2022 07:36:20 -0500 Original-Received: from mxcwn02.webd.pl ([194.181.228.14]:63036) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMqsS-0006yK-Fj for emacs-devel@gnu.org; Wed, 23 Feb 2022 07:36:18 -0500 Original-Received: from wn02.int.webd ([192.168.101.102] helo=wn02.webd.pl) by mta01.webd.pl with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1nMqsL-00023l-9X for emacs-devel@gnu.org; Wed, 23 Feb 2022 13:36:09 +0100 Original-Received: from [192.168.101.231] (port=47266 helo=mta01.int.webd) by wn02.webd.pl with esmtp (Exim 4.93) (envelope-from ) id 1nMqsL-0007hF-0Z; Wed, 23 Feb 2022 13:36:09 +0100 X-Quarantine-ID: X-Virus-Scanned: amavisd-new at mxwn02.webd.pl Original-Received: from wn02.webd.pl ([192.168.101.102]) by mta01.int.webd (mxwn02.webd.pl [192.168.101.200]) (amavisd-new, port 10024) with ESMTP id z7ett9vqi4cJ; Wed, 23 Feb 2022 13:36:06 +0100 (CET) Original-Received: from public-gprs171325.centertel.pl ([46.134.8.126]:1977 helo=mother) by wn02.webd.pl with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nMqsI-0007Mx-9Y; Wed, 23 Feb 2022 13:36:06 +0100 Received-SPF: pass client-ip=194.181.228.14; envelope-from=mail@gumen.pl; helo=mxcwn02.webd.pl X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 23 Feb 2022 07:57:09 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:286620 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=rmail-ordered-headers.diff 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)) --=-=-=--