]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix message-replace-header after recent change
authordickmao <none>
Tue, 22 Jun 2021 22:23:48 +0000 (00:23 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 22 Jun 2021 22:23:48 +0000 (00:23 +0200)
* lisp/gnus/message.el (message-replace-header): Restore else
branch removed by mistake in 989de3b824 (bug#49179).

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

index 0c027ca2905e8d7e435696f3a3dba2ee900cc7ef..69e2c5cbbc1bd60c98725153517349dbbfd443c9 100644 (file)
@@ -8730,11 +8730,11 @@ headers.  If FORCE, insert new field even if NEW-VALUE is empty."
       (message-narrow-to-headers)
       (message-remove-header header))
     (when (or force (> (length new-value) 0))
-      (when after
-        (if (listp after)
-            (apply #'message-position-on-field
-                   (append (list header) after))
-          (message-position-on-field header after))
+      (if after
+          (apply #'message-position-on-field header
+                 (if (listp after)
+                     after
+                   (list after)))
        (message-position-on-field header))
       (insert new-value))))
 
index 36ec8c51d159356ed2d2ac657e788ac7adef2000..b4f2b7f675d61236ed31eb371258266e65b334a3 100644 (file)
                       "\"larsi@gnus.org\" <larsi@gnus.org>")
                      "larsi@gnus.org")))
 
+(ert-deftest message-replace-header ()
+  (with-temp-buffer
+    (save-excursion
+      (insert "From: dang@gnus.org
+To: user1,
+    user2
+Cc: user3,
+    user4
+--text follows this line--
+Hello.
+"))
+    (save-excursion
+      (message-replace-header "From" "ding@gnus.org")
+      (should (cl-search "ding" (message-field-value "From"))))
+    (save-excursion
+      (message-replace-header "From" "dong@gnus.org" "To")
+      (should (cl-search "dong" (message-field-value "From")))
+      (should (re-search-forward "From:"))
+      (should-error (re-search-forward "To:"))
+      (should (re-search-forward "Cc:")))
+    (save-excursion
+      (message-replace-header "From" "dang@gnus.org" (split-string "To Cc"))
+      (should (cl-search "dang" (message-field-value "From")))
+      (should (re-search-forward "From:"))
+      (should-error (re-search-forward "To:"))
+      ;; That this isn't so is probably a bug from 1997.
+      ;; (should-error (re-search-forward "Cc:"))
+      )))
+
 (provide 'message-mode-tests)
 
 ;;; message-mode-tests.el ends here