>From b9b4512fbf912fb0167c8e97bed361184b1f3997 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sat, 23 May 2015 14:39:36 +0200 Subject: [PATCH 2/3] Allow gnus-ignored-from-addresses to be a function --- GNUS-NEWS | 2 ++ lisp/ChangeLog | 8 ++++++++ lisp/gnus-icalendar.el | 3 ++- lisp/gnus-notifications.el | 6 ++++-- lisp/gnus-sum.el | 19 +++++++++++++------ texi/gnus.texi | 11 ++++++----- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/GNUS-NEWS b/GNUS-NEWS index edaa2d5..dce7eda 100644 --- a/GNUS-NEWS +++ b/GNUS-NEWS @@ -9,6 +9,8 @@ For older news, see Gnus info node "New Features". * New features +** gnus-ignored-from-addresses can take a function as a value. + ** message-alternative-emails can take a function as a value. ** nnimap can request and use the Gmail "X-GM-LABELS". diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3aeb28a..adf2b8b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,13 @@ 2015-05-23 Rasmus Pank Roulund + * gnus-sum.el (gnus-ignored-from-addresses): Allow function as value. + * gnus-notifications.el (gnus-notifications): + * gnus-icalendar.el (gnus-icalendar-identities): + * gnus-sum.el (gnus-ignored-from-addresses): Allow function value for + `gnus-ignored-from-addresses'. + +2015-05-23 Rasmus Pank Roulund + * message.el (message-alternative-emails): Allow function as value. (message-use-alternative-email-as-from): (message-is-yours-p): Allow function value for diff --git a/lisp/gnus-icalendar.el b/lisp/gnus-icalendar.el index be5b732..734f1bf 100644 --- a/lisp/gnus-icalendar.el +++ b/lisp/gnus-icalendar.el @@ -705,7 +705,8 @@ These will be used to retrieve the RSVP information from ical events." (mapcar (lambda (x) (if (listp x) x (list x))) (list user-full-name (regexp-quote user-mail-address) ;; NOTE: these can be lists - gnus-ignored-from-addresses ; already regexp-quoted + (unless (functionp gnus-ignored-from-addresses) ; String or function. + gnus-ignored-from-addresses) ; Already regexp-quoted if string. (unless (functionp message-alternative-emails) ; String or function. message-alternative-emails) (mapcar #'regexp-quote gnus-icalendar-additional-identities))))) diff --git a/lisp/gnus-notifications.el b/lisp/gnus-notifications.el index f73aac1..2172c2f 100644 --- a/lisp/gnus-notifications.el +++ b/lisp/gnus-notifications.el @@ -180,8 +180,10 @@ This is typically a function to add in ;; Ignore mails from ourselves (unless (and gnus-ignored-from-addresses address - (gnus-string-match-p gnus-ignored-from-addresses - address)) + (cond ((functionp gnus-ignored-from-addresses) + (funcall gnus-ignored-from-addresses address)) + (t (gnus-string-match-p (gnus-ignored-from-addresses) + address)))) (let* ((photo-file (gnus-notifications-get-photo-file address)) (notification-id (gnus-notifications-notify (or (car address-components) address) diff --git a/lisp/gnus-sum.el b/lisp/gnus-sum.el index 37a707e..8bc08a1 100644 --- a/lisp/gnus-sum.el +++ b/lisp/gnus-sum.el @@ -1171,14 +1171,19 @@ which it may alter in any way." (not (string= user-mail-address "")) (regexp-quote user-mail-address)) "*From headers that may be suppressed in favor of To headers. -This can be a regexp or a list of regexps." +This can be a regexp, a list of regexps or a function. + +If a function, an email string is passed as the argument." :version "21.1" :group 'gnus-summary :type '(choice regexp - (repeat :tag "Regexp List" regexp))) + (repeat :tag "Regexp List" regexp) + function)) (defsubst gnus-ignored-from-addresses () - (gmm-regexp-concat gnus-ignored-from-addresses)) + (cond ((functionp gnus-ignored-from-addresses) + gnus-ignored-from-addresses) + (t (gmm-regexp-concat gnus-ignored-from-addresses)))) (defcustom gnus-summary-to-prefix "-> " "*String prefixed to the To field in the summary line when @@ -3685,15 +3690,17 @@ buffer that was in action when the last article was fetched." (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from) (let ((mail-parse-charset gnus-newsgroup-charset) - (ignored-from-addresses (gnus-ignored-from-addresses)) ;; Is it really necessary to do this next part for each summary line? ;; Luckily, doesn't seem to slow things down much. (mail-parse-ignored-charsets (with-current-buffer gnus-summary-buffer gnus-newsgroup-ignored-charsets))) (or - (and ignored-from-addresses - (string-match ignored-from-addresses gnus-tmp-from) + (and gnus-ignored-from-addresses + (cond ((functionp gnus-ignored-from-addresses) + (funcall gnus-ignored-from-addresses + (mail-strip-quoted-names gnus-tmp-from))) + (t (string-match (gnus-ignored-from-addresses) gnus-tmp-from))) (let ((extra-headers (mail-header-extra header)) to newsgroups) diff --git a/texi/gnus.texi b/texi/gnus.texi index b190184..84543d7 100644 --- a/texi/gnus.texi +++ b/texi/gnus.texi @@ -5042,11 +5042,12 @@ access the @code{X-Newsreader} header: @item @vindex gnus-ignored-from-addresses -The @code{gnus-ignored-from-addresses} variable says when the @samp{%f} -summary line spec returns the @code{To}, @code{Newsreader} or -@code{From} header. If this regexp matches the contents of the -@code{From} header, the value of the @code{To} or @code{Newsreader} -headers are used instead. +The @code{gnus-ignored-from-addresses} variable says when the +@samp{%f} summary line spec returns the @code{To}, @code{Newsreader} +or @code{From} header. The variable may be a regexp or a predicate +function. If this matches the contents of the @code{From} +header, the value of the @code{To} or @code{Newsreader} headers are +used instead. To distinguish regular articles from those where the @code{From} field has been swapped, a string is prefixed to the @code{To} or -- 2.4.1