Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Rasmus <rasmus@gmx.us>
To: info-gnus-english@gnu.org
Subject: Re: [patches] allow functions some variables
Date: Sat, 30 May 2015 15:42:13 +0200	[thread overview]
Message-ID: <87lhg6yyfe.fsf@gmx.us> (raw)
In-Reply-To: <87twv2nml7.fsf@gmx.us>

[-- Attachment #1: Type: text/plain, Size: 157 bytes --]

Hi,

> The attached patches allow these three variables to be functions.

There was a bug in the first patch.

Thanks,
Rasmus

-- 
May the Force be with you

[-- Attachment #2: 0001-Allow-message-alternative-emails-to-be-a-function.patch --]
[-- Type: text/x-diff, Size: 6501 bytes --]

From ceb6d295ba62fc43344e514d1be1c264e968301c Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Sat, 23 May 2015 13:29:56 +0200
Subject: [PATCH 1/3] Allow message-alternative-emails to be a function

---
 GNUS-NEWS              |  2 ++
 lisp/ChangeLog         |  7 +++++++
 lisp/gnus-icalendar.el |  5 +++--
 lisp/message.el        | 35 +++++++++++++++++++----------------
 texi/message.texi      |  8 ++++----
 5 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/GNUS-NEWS b/GNUS-NEWS
index ee3584f..edaa2d5 100644
--- a/GNUS-NEWS
+++ b/GNUS-NEWS
@@ -9,6 +9,8 @@ For older news, see Gnus info node "New Features".
 \f
 * New features
 
+** message-alternative-emails can take a function as a value.
+
 ** nnimap can request and use the Gmail "X-GM-LABELS".
 
 ** New package `gnus-notifications.el' can send notifications when you
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6539a61..3febb8e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -12,6 +12,13 @@
 	* gnus-art.el (gnus-button-alist):
 	Also treat "‘" and "’" as quoting chars.
 
+2015-05-23  Rasmus Pank Roulund  <emacs@pank.eu>
+
+	* message.el (message-alternative-emails): Allow function as value.
+	(message-use-alternative-email-as-from):
+	(message-is-yours-p): Allow function value for
+	`message-alternative-emails'
+
 2015-05-19  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* gnus-art.el (gnus-treat-strip-list-identifiers)
diff --git a/lisp/gnus-icalendar.el b/lisp/gnus-icalendar.el
index dc423d8..be5b732 100644
--- a/lisp/gnus-icalendar.el
+++ b/lisp/gnus-icalendar.el
@@ -704,9 +704,10 @@ These will be used to retrieve the RSVP information from ical events."
   (apply #'append
          (mapcar (lambda (x) (if (listp x) x (list x)))
                  (list user-full-name (regexp-quote user-mail-address)
-                       ; NOTE: these can be lists
+                       ;; NOTE: these can be lists
                        gnus-ignored-from-addresses ; already regexp-quoted
-                       message-alternative-emails  ;
+                       (unless (functionp message-alternative-emails)  ; String or function.
+                         message-alternative-emails)
                        (mapcar #'regexp-quote gnus-icalendar-additional-identities)))))
 
 ;; TODO: make the template customizable
diff --git a/lisp/message.el b/lisp/message.el
index 2bc8116..d219a41 100644
--- a/lisp/message.el
+++ b/lisp/message.el
@@ -1734,17 +1734,20 @@ should be sent in several parts.  If it is nil, the size is unlimited."
 		 (integer 1000000)))
 
 (defcustom message-alternative-emails nil
-  "*Regexp matching alternative email addresses.
+  "*Regexp or predicate function matching alternative email addresses.
 The first address in the To, Cc or From headers of the original
 article matching this variable is used as the From field of
 outgoing messages.
 
+If a function, an email string is passed as the argument.
+
 This variable has precedence over posting styles and anything that runs
 off `message-setup-hook'."
   :group 'message-headers
   :link '(custom-manual "(message)Message Headers")
   :type '(choice (const :tag "Always use primary" nil)
-		 regexp))
+		 regexp
+                 function))
 
 (defcustom message-hierarchical-addresses nil
   "A list of hierarchical mail address definitions.
@@ -7248,7 +7251,7 @@ want to get rid of this query permanently."))
 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
 are yours except those that have Cancel-Lock header not belonging to you.
 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
-regexp to match all of yours addresses."
+to match all of yours addresses."
   ;; Canlock-logic as suggested by Per Abrahamsen
   ;; <abraham@dina.kvl.dk>
   ;;
@@ -7280,12 +7283,14 @@ regexp to match all of yours addresses."
 		 (downcase (car (mail-header-parse-address
 				 (message-make-from))))))
 	   ;; Email address in From field matches
-	   ;; 'message-alternative-emails' regexp
+	   ;; 'message-alternative-emails' regexp or function.
 	   (and from
 		message-alternative-emails
-		(string-match
-		 message-alternative-emails
-		 (car (mail-header-parse-address from))))))))))
+                (cond ((functionp message-alternative-emails)
+                       (funcall message-alternative-emails
+                                (mail-header-parse-address from)))
+                      (t (string-match message-alternative-emails
+                                       (car (mail-header-parse-address from))))))))))))
 
 ;;;###autoload
 (defun message-cancel-news (&optional arg)
@@ -8320,16 +8325,14 @@ From headers in the original article."
   (require 'mail-utils)
   (let* ((fields '("To" "Cc" "From"))
 	 (emails
-	  (split-string
+	  (message-tokenize-header
 	   (mail-strip-quoted-names
-	    (mapconcat 'message-fetch-reply-field fields ","))
-	   "[ \f\t\n\r\v,]+"))
-	 email)
-    (while emails
-      (if (string-match message-alternative-emails (car emails))
-	  (setq email (car emails)
-		emails nil))
-      (pop emails))
+	    (mapconcat 'message-fetch-reply-field fields ","))))
+	 (email (cond ((functionp message-alternative-emails)
+                       (car (remove-if-not message-alternative-emails emails)))
+                      (t (loop for email in emails
+                               if (string-match-p message-alternative-emails email)
+                               return email)))))
     (unless (or (not email) (equal email user-mail-address))
       (message-remove-header "From")
       (goto-char (point-max))
diff --git a/texi/message.texi b/texi/message.texi
index b7aa6bf..1b18a04 100644
--- a/texi/message.texi
+++ b/texi/message.texi
@@ -1523,10 +1523,10 @@ trailing old subject.  In this case,
 
 @item message-alternative-emails
 @vindex message-alternative-emails
-Regexp matching alternative email addresses.  The first address in the
-To, Cc or From headers of the original article matching this variable is
-used as the From field of outgoing messages, replacing the default From
-value.
+Regexp or predicate function matching alternative email addresses.
+The first address in the To, Cc or From headers of the original
+article matching this variable is used as the From field of outgoing
+messages, replacing the default From value.
 
 For example, if you have two secondary email addresses john@@home.net
 and john.doe@@work.com and want to use them in the From field when
-- 
2.4.1




      reply	other threads:[~2015-05-30 13:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-24 13:15 Rasmus
2015-05-30 13:42 ` Rasmus [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhg6yyfe.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=info-gnus-english@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).