Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: David Z Maze <dmaze@mit.edu>
Subject: Re: Lisp recipe to set From header
Date: Fri, 27 Jan 2006 17:39:45 -0500	[thread overview]
Message-ID: <y68zmlhs3bi.fsf@contents-vnder-pressvre.mit.edu> (raw)
In-Reply-To: <878xt1xsle.fsf@knight.monnsta.net>

Matthew King <matthew.king@monnsta.net> writes:

> I have the following:
>
> ;;; Set From header based on To header
> (setq gnus-posting-styles
>       '(("nn.+:"
> 	 (From (save-excursion
> 		 (set-buffer gnus-article-buffer)
> 		 (message-fetch-field "to"))))))
>
> What I really want to do is only set the From address to be one from a
> pre-set list and to fall back on user-mail-address if there is no
> match.

;; Totally untested:
(defvar mk-to-header-list
  '("matthew.king@monnsta.net")
  "Names it's valid to take from the To: header of messages.")

(defun mk-to-header-or-default ()
  "Returns the To: header of `gnus-article-buffer' if it's in
  `mk-to-header-list', or `user-mail-address' otherwise."
  (let ((to-header (save-excursion
                     (set-buffer gnus-article-buffer)
                     (message-fetch-field "to"))))
    (if (member to-header mk-to-header-list)
      to-header
      gnus-article-buffer)))

(setq gnus-posting-styles '(("nn.+:" (From (mk-to-header-or-default)))))

  --dzm

      parent reply	other threads:[~2006-01-27 22:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-27 21:34 Matthew King
2006-01-27 22:12 ` Sébastien Kirche
2006-01-27 22:39 ` David Z Maze [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=y68zmlhs3bi.fsf@contents-vnder-pressvre.mit.edu \
    --to=dmaze@mit.edu \
    /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).