]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove repetitions from recipient addresses in Message
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 12 Apr 2018 12:57:51 +0000 (14:57 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 12 Apr 2018 12:59:41 +0000 (14:59 +0200)
* lisp/gnus/message.el (message--alter-repeat-address): New function.
(message-get-reply-headers): Use it to remove repetitions on the
form "foo@bar.com" <foo@bar.com>.

etc/NEWS
lisp/gnus/message.el
test/lisp/gnus/message-tests.el

index 670167165af99d261a3e3cf76bad830ed20bdfeb..e3f05f3e0f5a5f02c615b22ead73ba227cdbe97c 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -361,6 +361,11 @@ when the PGP keyring contains a public key for every recipient.  To
 achieve this, add 'message-sign-encrypt-if-all-keys-available' to
 'message-send-hook'.
 
+---
+*** When replying a message that have addresses on the form
+'"foo@bar.com" <foo@bar.com>', Message will elide the repeated "name"
+from the address field in the response.
+
 * New Modes and Packages in Emacs 27.1
 
 +++
index b979e1c5044d8e4f6a6aeecdca111d4637f6aaf4..7079cc73e1f9b8ed30f549b649dfcfbb2ae32866 100644 (file)
@@ -6867,6 +6867,9 @@ want to get rid of this query permanently.")))
                    (setq recipients (delq recip recipients))))))))
 
       (setq recipients (message-prune-recipients recipients))
+      (setq recipients
+           (cl-loop for (id . address) in recipients
+                    collect (cons id (message--alter-repeat-address address))))
 
       ;; Build the header alist.  Allow the user to be asked whether
       ;; or not to reply to all recipients in a wide reply.
@@ -6897,6 +6900,15 @@ want to get rid of this query permanently.")))
              (setq recipients (delq recipient recipients))))))))
   recipients)
 
+(defun message--alter-repeat-address (address)
+  "Transform an address on the form \"\"foo@bar.com\"\" <foo@bar.com>\".
+The first bit will be elided if a match is made."
+  (let ((bits (gnus-extract-address-components address)))
+    (if (equal (car bits) (cadr bits))
+       (car bits)
+      ;; Return the original address if we don't have repetition.
+      address)))
+
 (defcustom message-simplify-subject-functions
   '(message-strip-list-identifiers
     message-strip-subject-re
index a95559775b65e61e80fa212b1add0544d92a6312..27b8c10dc03291f8a09e95088816adbd1d7e820c 100644 (file)
       (setq recipients (list person1 person2 person3))
       (should-not (message-all-epg-keys-available-p)))))
 
+(ert-deftest message-alter-repeat-address ()
+  (should (equal (message--alter-repeat-address
+                  "Lars Ingebrigtsen <larsi@gnus.org>")
+                 "Lars Ingebrigtsen <larsi@gnus.org>"))
+
+  (should (equal (message--alter-repeat-address
+                      "\"larsi@gnus.org\" <larsi@gnus.org>")
+                     "larsi@gnus.org")))
+
 (provide 'message-mode-tests)
 
 ;;; message-mode-tests.el ends here