From 7eb81887beaae1e8a345a0294b0fddbaf2b20a5e Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 5 Sep 2012 19:47:27 +0200 Subject: [PATCH] Make the `C-c C-n' command in Message more sturdy * message.el (message-insert-newsgroups): Don't insert newsgroup duplicates (bug#12275). --- lisp/ChangeLog | 5 +++++ lisp/message.el | 32 +++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 537938327..b5b7063ca 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-09-05 Lars Ingebrigtsen + + * message.el (message-insert-newsgroups): Don't insert newsgroup + duplicates (bug#12275). + 2012-09-05 John Wiegley * gnus.el (gnus-expand-group-parameters): Allow regexp substitutions in diff --git a/lisp/message.el b/lisp/message.el index 1fea5f912..12002b671 100644 --- a/lisp/message.el +++ b/lisp/message.el @@ -3336,11 +3336,33 @@ or in the synonym headers, defined by `message-header-synonyms'." (defun message-insert-newsgroups () "Insert the Newsgroups header from the article being replied to." (interactive) - (when (and (message-position-on-field "Newsgroups") - (mail-fetch-field "newsgroups") - (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups")))) - (insert ",")) - (insert (or (message-fetch-reply-field "newsgroups") ""))) + (let ((old-newsgroups (mail-fetch-field "newsgroups")) + (new-newsgroups (message-fetch-reply-field "newsgroups")) + (first t) + insert-newsgroups) + (message-position-on-field "Newsgroups") + (cond + ((not new-newsgroups) + (error "No Newsgroups to insert")) + ((not old-newsgroups) + (insert new-newsgroups)) + (t + (setq new-newsgroups (split-string new-newsgroups "[, ]+") + old-newsgroups (split-string old-newsgroups "[, ]+")) + (dolist (group new-newsgroups) + (unless (member group old-newsgroups) + (push group insert-newsgroups))) + (if (null insert-newsgroups) + (error "Newgroup%s already in the header" + (if (> (length new-newsgroups) 1) + "s" "")) + (when old-newsgroups + (setq first nil)) + (dolist (group insert-newsgroups) + (unless first + (insert ",")) + (setq first nil) + (insert group))))))) -- 2.25.1