unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Reiner Steib <reinersteib+from-uce@imap.cc>
Subject: Re: [Gnus] `From' according to `Envelope-to'.
Date: Tue, 06 Sep 2005 20:31:54 +0200	[thread overview]
Message-ID: <v9oe76jbdx.fsf@marauder.physik.uni-ulm.de> (raw)
In-Reply-To: mailman.6077.1126027440.20277.help-gnu-emacs@gnu.org

On Tue, Sep 06 2005, Michael Cadilhac wrote:

[ Crosspost & Followup-To: gnu.emacs.gnus ]

>   As I've multiple  aliases for the same mailbox,  I receive mail sent
>   to different addresses (mentioned in the `envelope-to' field of the
>   received messages).
>
>   In order to not  disturb the sender, I want - when  replying - to be
>   warned like :
>
>   ``Your default "from"  field is `michael.cadilhac@lrde.org', but the
>   sender used `mc@lrde.epita.fr'. Change ?''

I use the following code to check the "To" header.  After changing
(message-fetch-field "to") to (message-fetch-field "envelope-to") it
might do what you want.

You also need to set `rs-message-to-from-addresses' or
`gnus-ignored-from-addresses'.

--8<---------------cut here---------------start------------->8---
(defvar rs-message-to-from-addresses gnus-ignored-from-addresses
  "Regexp matching To headers.

When using entries like

  ((message-mail-p)
   (address (rs-message-to-from-address)))

or

  ((message-mail-p)
   (address (rs-message-to-from-address \"foo@example.invalid\")))

in `gnus-posting-styles', the address in the From header is taken
from the To header of the article you are replying to.")

;;;###autoload
(defun rs-message-to-from-address (&optional fallback)
  "Return a suitable address.

See `rs-message-to-from-addresses' for more."
  (let ((to (and (boundp 'gnus-article-buffer)
		 (gnus-buffer-live-p gnus-article-buffer)
		 ;; `gnus-buffer-live-p' already returns
		 ;; `gnus-article-buffer', but it's not documented.  So
		 ;; let's be careful.
		 gnus-article-buffer
		 (with-current-buffer gnus-article-buffer
		   (message-fetch-field "to")))))
    (cond ((and to
		(not (string-match "," to));; FIXME
		(string-match rs-message-to-from-addresses to))
	   (let ((from (cadr (mail-extract-address-components to))))
	     ;; gnus-extract-address-components fails for dit Outlook stuff!
	     (if (and (string-match rs-message-to-from-addresses from)
		      (string-match (concat "^"
					    (if (boundp 'gnus-button-valid-localpart-regexp)
						gnus-button-valid-localpart-regexp
					      "[a-z0-9-_+.]+")
					    "@" message-valid-fqdn-regexp "$")
				    from))
		 from
	       (if (y-or-n-p
		    (format "Address <%s> might be bogus.  Use anyway? "
			    from))
		   from))))
	  (fallback fallback)
	  (t user-mail-address))))
--8<---------------cut here---------------end--------------->8---

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

       reply	other threads:[~2005-09-06 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6077.1126027440.20277.help-gnu-emacs@gnu.org>
2005-09-06 18:31 ` Reiner Steib [this message]
2005-09-06 17:10 [Gnus] `From' according to `Envelope-to' Michael Cadilhac

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=v9oe76jbdx.fsf@marauder.physik.uni-ulm.de \
    --to=reinersteib+from-uce@imap.cc \
    --cc=Reiner.Steib@gmx.de \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).