From 2540701f300144fba8a3871f1f0c046c0ff41c5a Mon Sep 17 00:00:00 2001 From: dickmao Date: Wed, 23 Jun 2021 00:23:48 +0200 Subject: [PATCH] Fix message-replace-header after recent change * lisp/gnus/message.el (message-replace-header): Restore else branch removed by mistake in 989de3b824 (bug#49179). --- lisp/gnus/message.el | 10 +++++----- test/lisp/gnus/message-tests.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index 0c027ca2905..69e2c5cbbc1 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -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)))) diff --git a/test/lisp/gnus/message-tests.el b/test/lisp/gnus/message-tests.el index 36ec8c51d15..b4f2b7f675d 100644 --- a/test/lisp/gnus/message-tests.el +++ b/test/lisp/gnus/message-tests.el @@ -154,6 +154,35 @@ "\"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 -- 2.39.2