aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFoo2016-02-08 13:28:37 +1100
committerLars Ingebrigtsen2016-02-08 13:28:37 +1100
commit357ae5dba5faac5ff48ebb971cb29500f87f02a6 (patch)
tree97fc02b211a7ac17899c28df8ef7a8e0f88e7f72
parentd0c29576099b02ba75c2458f4c3ac175d1ba9250 (diff)
downloademacs-357ae5dba5faac5ff48ebb971cb29500f87f02a6.tar.gz
emacs-357ae5dba5faac5ff48ebb971cb29500f87f02a6.zip
Allow various Gnus and Message address variables to be functions
* doc/misc/gnus.texi (To From Newsgroups): gnus-ignored-from-addresses can be a function. * doc/misc/message.texi (Wide Reply): message-dont-reply-to-names can be a function. * lisp/gnus/gnus-icalendar.el (gnus-icalendar-identities): message-alternative-emails can be a function. * lisp/gnus/gnus-notifications.el (gnus-notifications): message-alternative-emails can be a function (bug#22315). * lisp/gnus/gnus-sum.el (gnus-summary-from-or-to-or-newsgroups): gnus-ignored-from-addresses can be a function (bug#22315).
-rw-r--r--doc/misc/gnus.texi11
-rw-r--r--doc/misc/message.texi13
-rw-r--r--etc/GNUS-NEWS2
-rw-r--r--lisp/gnus/gnus-icalendar.el14
-rw-r--r--lisp/gnus/gnus-notifications.el6
-rw-r--r--lisp/gnus/gnus-sum.el19
-rw-r--r--lisp/gnus/message.el63
7 files changed, 81 insertions, 47 deletions
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 8dd0c1ba9d5..e6e3e7617ee 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -5042,11 +5042,12 @@ access the @code{X-Newsreader} header:
5042 5042
5043@item 5043@item
5044@vindex gnus-ignored-from-addresses 5044@vindex gnus-ignored-from-addresses
5045The @code{gnus-ignored-from-addresses} variable says when the @samp{%f} 5045The @code{gnus-ignored-from-addresses} variable says when the
5046summary line spec returns the @code{To}, @code{Newsreader} or 5046@samp{%f} summary line spec returns the @code{To}, @code{Newsreader}
5047@code{From} header. If this regexp matches the contents of the 5047or @code{From} header. The variable may be a regexp or a predicate
5048@code{From} header, the value of the @code{To} or @code{Newsreader} 5048function. If this matches the contents of the @code{From}
5049headers are used instead. 5049header, the value of the @code{To} or @code{Newsreader} headers are
5050used instead.
5050 5051
5051To distinguish regular articles from those where the @code{From} field 5052To distinguish regular articles from those where the @code{From} field
5052has been swapped, a string is prefixed to the @code{To} or 5053has been swapped, a string is prefixed to the @code{To} or
diff --git a/doc/misc/message.texi b/doc/misc/message.texi
index 761fb772f46..fa4fa4398b4 100644
--- a/doc/misc/message.texi
+++ b/doc/misc/message.texi
@@ -185,8 +185,9 @@ but you can change the behavior to suit your needs by fiddling with the
185 185
186@vindex message-dont-reply-to-names 186@vindex message-dont-reply-to-names
187Addresses that match the @code{message-dont-reply-to-names} regular 187Addresses that match the @code{message-dont-reply-to-names} regular
188expression (or list of regular expressions) will be removed from the 188expression (or list of regular expressions or a predicate function)
189@code{Cc} header. A value of @code{nil} means exclude your name only. 189will be removed from the @code{Cc} header. A value of @code{nil} means
190exclude your name only.
190 191
191@vindex message-prune-recipient-rules 192@vindex message-prune-recipient-rules
192@code{message-prune-recipient-rules} is used to prune the addresses 193@code{message-prune-recipient-rules} is used to prune the addresses
@@ -1672,10 +1673,10 @@ trailing old subject. In this case,
1672 1673
1673@item message-alternative-emails 1674@item message-alternative-emails
1674@vindex message-alternative-emails 1675@vindex message-alternative-emails
1675Regexp matching alternative email addresses. The first address in the 1676Regexp or predicate function matching alternative email addresses.
1676To, Cc or From headers of the original article matching this variable is 1677The first address in the To, Cc or From headers of the original
1677used as the From field of outgoing messages, replacing the default From 1678article matching this variable is used as the From field of outgoing
1678value. 1679messages, replacing the default From value.
1679 1680
1680For example, if you have two secondary email addresses john@@home.net 1681For example, if you have two secondary email addresses john@@home.net
1681and john.doe@@work.com and want to use them in the From field when 1682and john.doe@@work.com and want to use them in the From field when
diff --git a/etc/GNUS-NEWS b/etc/GNUS-NEWS
index 4efb53e69c3..c1a5bd757c6 100644
--- a/etc/GNUS-NEWS
+++ b/etc/GNUS-NEWS
@@ -9,6 +9,8 @@ For older news, see Gnus info node "New Features".
9 9
10* New features 10* New features
11 11
12** message-alternative-emails can take a function as a value.
13
12** nnimap can request and use the Gmail "X-GM-LABELS". 14** nnimap can request and use the Gmail "X-GM-LABELS".
13 15
14** New package `gnus-notifications.el' can send notifications when you 16** New package `gnus-notifications.el' can send notifications when you
diff --git a/lisp/gnus/gnus-icalendar.el b/lisp/gnus/gnus-icalendar.el
index 4faef063bba..050478bbc79 100644
--- a/lisp/gnus/gnus-icalendar.el
+++ b/lisp/gnus/gnus-icalendar.el
@@ -702,12 +702,14 @@ only makes sense to define names or email addresses."
702 702
703These will be used to retrieve the RSVP information from ical events." 703These will be used to retrieve the RSVP information from ical events."
704 (apply #'append 704 (apply #'append
705 (mapcar (lambda (x) (if (listp x) x (list x))) 705 (mapcar
706 (list user-full-name (regexp-quote user-mail-address) 706 (lambda (x) (if (listp x) x (list x)))
707 ; NOTE: these can be lists 707 (list user-full-name (regexp-quote user-mail-address)
708 gnus-ignored-from-addresses ; already regexp-quoted 708 ;; NOTE: these can be lists
709 message-alternative-emails ; 709 gnus-ignored-from-addresses ; already regexp-quoted
710 (mapcar #'regexp-quote gnus-icalendar-additional-identities))))) 710 (unless (functionp message-alternative-emails) ; String or function.
711 message-alternative-emails)
712 (mapcar #'regexp-quote gnus-icalendar-additional-identities)))))
711 713
712;; TODO: make the template customizable 714;; TODO: make the template customizable
713(defmethod gnus-icalendar-event->gnus-calendar ((event gnus-icalendar-event) &optional reply-status) 715(defmethod gnus-icalendar-event->gnus-calendar ((event gnus-icalendar-event) &optional reply-status)
diff --git a/lisp/gnus/gnus-notifications.el b/lisp/gnus/gnus-notifications.el
index 54a75b69c85..5a116cc0f75 100644
--- a/lisp/gnus/gnus-notifications.el
+++ b/lisp/gnus/gnus-notifications.el
@@ -180,8 +180,10 @@ This is typically a function to add in
180 ;; Ignore mails from ourselves 180 ;; Ignore mails from ourselves
181 (unless (and gnus-ignored-from-addresses 181 (unless (and gnus-ignored-from-addresses
182 address 182 address
183 (gnus-string-match-p gnus-ignored-from-addresses 183 (cond ((functionp gnus-ignored-from-addresses)
184 address)) 184 (funcall gnus-ignored-from-addresses address))
185 (t (gnus-string-match-p (gnus-ignored-from-addresses)
186 address))))
185 (let* ((photo-file (gnus-notifications-get-photo-file address)) 187 (let* ((photo-file (gnus-notifications-get-photo-file address))
186 (notification-id (gnus-notifications-notify 188 (notification-id (gnus-notifications-notify
187 (or (car address-components) address) 189 (or (car address-components) address)
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index f2b2782a08c..bc31ce91346 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -1171,14 +1171,19 @@ which it may alter in any way."
1171 (not (string= user-mail-address "")) 1171 (not (string= user-mail-address ""))
1172 (regexp-quote user-mail-address)) 1172 (regexp-quote user-mail-address))
1173 "*From headers that may be suppressed in favor of To headers. 1173 "*From headers that may be suppressed in favor of To headers.
1174This can be a regexp or a list of regexps." 1174This can be a regexp, a list of regexps or a function.
1175
1176If a function, an email string is passed as the argument."
1175 :version "21.1" 1177 :version "21.1"
1176 :group 'gnus-summary 1178 :group 'gnus-summary
1177 :type '(choice regexp 1179 :type '(choice regexp
1178 (repeat :tag "Regexp List" regexp))) 1180 (repeat :tag "Regexp List" regexp)
1181 function))
1179 1182
1180(defsubst gnus-ignored-from-addresses () 1183(defsubst gnus-ignored-from-addresses ()
1181 (gmm-regexp-concat gnus-ignored-from-addresses)) 1184 (cond ((functionp gnus-ignored-from-addresses)
1185 gnus-ignored-from-addresses)
1186 (t (gmm-regexp-concat gnus-ignored-from-addresses))))
1182 1187
1183(defcustom gnus-summary-to-prefix "-> " 1188(defcustom gnus-summary-to-prefix "-> "
1184 "*String prefixed to the To field in the summary line when 1189 "*String prefixed to the To field in the summary line when
@@ -3686,15 +3691,17 @@ buffer that was in action when the last article was fetched."
3686 3691
3687(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from) 3692(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3688 (let ((mail-parse-charset gnus-newsgroup-charset) 3693 (let ((mail-parse-charset gnus-newsgroup-charset)
3689 (ignored-from-addresses (gnus-ignored-from-addresses))
3690 ;; Is it really necessary to do this next part for each summary line? 3694 ;; Is it really necessary to do this next part for each summary line?
3691 ;; Luckily, doesn't seem to slow things down much. 3695 ;; Luckily, doesn't seem to slow things down much.
3692 (mail-parse-ignored-charsets 3696 (mail-parse-ignored-charsets
3693 (with-current-buffer gnus-summary-buffer 3697 (with-current-buffer gnus-summary-buffer
3694 gnus-newsgroup-ignored-charsets))) 3698 gnus-newsgroup-ignored-charsets)))
3695 (or 3699 (or
3696 (and ignored-from-addresses 3700 (and gnus-ignored-from-addresses
3697 (string-match ignored-from-addresses gnus-tmp-from) 3701 (cond ((functionp gnus-ignored-from-addresses)
3702 (funcall gnus-ignored-from-addresses
3703 (mail-strip-quoted-names gnus-tmp-from)))
3704 (t (string-match (gnus-ignored-from-addresses) gnus-tmp-from)))
3698 (let ((extra-headers (mail-header-extra header)) 3705 (let ((extra-headers (mail-header-extra header))
3699 to 3706 to
3700 newsgroups) 3707 newsgroups)
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 77e471ffb5f..8a7ed4fffbe 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -1358,8 +1358,10 @@ If nil, you might be asked to input the charset."
1358(defcustom message-dont-reply-to-names 1358(defcustom message-dont-reply-to-names
1359 (and (boundp 'mail-dont-reply-to-names) mail-dont-reply-to-names) 1359 (and (boundp 'mail-dont-reply-to-names) mail-dont-reply-to-names)
1360 "*Addresses to prune when doing wide replies. 1360 "*Addresses to prune when doing wide replies.
1361This can be a regexp or a list of regexps. Also, a value of nil means 1361This can be a regexp, a list of regexps or a predicate function.
1362exclude your own user name only." 1362Also, a value of nil means exclude your own user name only.
1363
1364If a function email is passed as the argument."
1363 :version "24.3" 1365 :version "24.3"
1364 :group 'message 1366 :group 'message
1365 :link '(custom-manual "(message)Wide Reply") 1367 :link '(custom-manual "(message)Wide Reply")
@@ -1368,7 +1370,10 @@ exclude your own user name only."
1368 (repeat :tag "Regexp List" regexp))) 1370 (repeat :tag "Regexp List" regexp)))
1369 1371
1370(defsubst message-dont-reply-to-names () 1372(defsubst message-dont-reply-to-names ()
1371 (gmm-regexp-concat message-dont-reply-to-names)) 1373 (cond ((functionp message-dont-reply-to-names)
1374 message-dont-reply-to-names)
1375 ((stringp message-dont-reply-to-names)
1376 (gmm-regexp-concat message-dont-reply-to-names))))
1372 1377
1373(defvar message-shoot-gnksa-feet nil 1378(defvar message-shoot-gnksa-feet nil
1374 "*A list of GNKSA feet you are allowed to shoot. 1379 "*A list of GNKSA feet you are allowed to shoot.
@@ -1694,17 +1699,20 @@ should be sent in several parts. If it is nil, the size is unlimited."
1694 (integer 1000000))) 1699 (integer 1000000)))
1695 1700
1696(defcustom message-alternative-emails nil 1701(defcustom message-alternative-emails nil
1697 "*Regexp matching alternative email addresses. 1702 "*Regexp or predicate function matching alternative email addresses.
1698The first address in the To, Cc or From headers of the original 1703The first address in the To, Cc or From headers of the original
1699article matching this variable is used as the From field of 1704article matching this variable is used as the From field of
1700outgoing messages. 1705outgoing messages.
1701 1706
1707If a function, an email string is passed as the argument.
1708
1702This variable has precedence over posting styles and anything that runs 1709This variable has precedence over posting styles and anything that runs
1703off `message-setup-hook'." 1710off `message-setup-hook'."
1704 :group 'message-headers 1711 :group 'message-headers
1705 :link '(custom-manual "(message)Message Headers") 1712 :link '(custom-manual "(message)Message Headers")
1706 :type '(choice (const :tag "Always use primary" nil) 1713 :type '(choice (const :tag "Always use primary" nil)
1707 regexp)) 1714 regexp
1715 function))
1708 1716
1709(defcustom message-hierarchical-addresses nil 1717(defcustom message-hierarchical-addresses nil
1710 "A list of hierarchical mail address definitions. 1718 "A list of hierarchical mail address definitions.
@@ -6867,9 +6875,20 @@ want to get rid of this query permanently.")))
6867 ;; Squeeze whitespace. 6875 ;; Squeeze whitespace.
6868 (while (string-match "[ \t][ \t]+" recipients) 6876 (while (string-match "[ \t][ \t]+" recipients)
6869 (setq recipients (replace-match " " t t recipients))) 6877 (setq recipients (replace-match " " t t recipients)))
6870 ;; Remove addresses that match `mail-dont-reply-to-names'. 6878 ;; Remove addresses that match `message-dont-reply-to-names'.
6871 (let ((mail-dont-reply-to-names (message-dont-reply-to-names))) 6879 (setq recipients
6872 (setq recipients (mail-dont-reply-to recipients))) 6880 (cond ((functionp message-dont-reply-to-names)
6881 (mapconcat
6882 'identity
6883 (delq nil
6884 (mapcar (lambda (mail)
6885 (unless (funcall message-dont-reply-to-names
6886 (mail-strip-quoted-names mail))
6887 mail))
6888 (message-tokenize-header recipients)))
6889 ", "))
6890 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6891 (mail-dont-reply-to recipients)))))
6873 ;; Perhaps "Mail-Copies-To: never" removed the only address? 6892 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6874 (if (string-equal recipients "") 6893 (if (string-equal recipients "")
6875 (setq recipients author)) 6894 (setq recipients author))
@@ -7151,7 +7170,7 @@ want to get rid of this query permanently."))
7151If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles 7170If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7152are yours except those that have Cancel-Lock header not belonging to you. 7171are yours except those that have Cancel-Lock header not belonging to you.
7153Instead of shooting GNKSA feet, you should modify `message-alternative-emails' 7172Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7154regexp to match all of yours addresses." 7173to match all of yours addresses."
7155 ;; Canlock-logic as suggested by Per Abrahamsen 7174 ;; Canlock-logic as suggested by Per Abrahamsen
7156 ;; <abraham@dina.kvl.dk> 7175 ;; <abraham@dina.kvl.dk>
7157 ;; 7176 ;;
@@ -7183,12 +7202,14 @@ regexp to match all of yours addresses."
7183 (downcase (car (mail-header-parse-address 7202 (downcase (car (mail-header-parse-address
7184 (message-make-from)))))) 7203 (message-make-from))))))
7185 ;; Email address in From field matches 7204 ;; Email address in From field matches
7186 ;; 'message-alternative-emails' regexp 7205 ;; 'message-alternative-emails' regexp or function.
7187 (and from 7206 (and from
7188 message-alternative-emails 7207 message-alternative-emails
7189 (string-match 7208 (cond ((functionp message-alternative-emails)
7190 message-alternative-emails 7209 (funcall message-alternative-emails
7191 (car (mail-header-parse-address from)))))))))) 7210 (mail-header-parse-address from)))
7211 (t (string-match message-alternative-emails
7212 (car (mail-header-parse-address from))))))))))))
7192 7213
7193;;;###autoload 7214;;;###autoload
7194(defun message-cancel-news (&optional arg) 7215(defun message-cancel-news (&optional arg)
@@ -8214,16 +8235,14 @@ From headers in the original article."
8214 (require 'mail-utils) 8235 (require 'mail-utils)
8215 (let* ((fields '("To" "Cc" "From")) 8236 (let* ((fields '("To" "Cc" "From"))
8216 (emails 8237 (emails
8217 (split-string 8238 (message-tokenize-header
8218 (mail-strip-quoted-names 8239 (mail-strip-quoted-names
8219 (mapconcat 'message-fetch-reply-field fields ",")) 8240 (mapconcat 'message-fetch-reply-field fields ","))))
8220 "[ \f\t\n\r\v,]+")) 8241 (email (cond ((functionp message-alternative-emails)
8221 email) 8242 (car (cl-remove-if-not message-alternative-emails emails)))
8222 (while emails 8243 (t (loop for email in emails
8223 (if (string-match message-alternative-emails (car emails)) 8244 if (string-match-p message-alternative-emails email)
8224 (setq email (car emails) 8245 return email)))))
8225 emails nil))
8226 (pop emails))
8227 (unless (or (not email) (equal email user-mail-address)) 8246 (unless (or (not email) (equal email user-mail-address))
8228 (message-remove-header "From") 8247 (message-remove-header "From")
8229 (goto-char (point-max)) 8248 (goto-char (point-max))