From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Teemu Likonen Newsgroups: gmane.emacs.help Subject: Re: Gnus: How to easily change "From:" from the default to a second account's address? Date: Sat, 03 Dec 2011 21:17:37 +0200 Message-ID: <87mxb9o46m.fsf@mithlond.arda> References: <812215ED-D638-4BE4-8AD3-AC7EB95378E0@math.ethz.ch> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1322939890 16141 80.91.229.12 (3 Dec 2011 19:18:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 3 Dec 2011 19:18:10 +0000 (UTC) Cc: Emacs help To: Marius Hofert Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 03 20:17:58 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RWv5w-0005Gu-VR for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Dec 2011 20:17:57 +0100 Original-Received: from localhost ([::1]:41397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWv5w-0006Lf-EM for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Dec 2011 14:17:56 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:60551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWv5s-0006La-9e for help-gnu-emacs@gnu.org; Sat, 03 Dec 2011 14:17:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWv5q-0003Z8-UF for help-gnu-emacs@gnu.org; Sat, 03 Dec 2011 14:17:52 -0500 Original-Received: from mta-out.inet.fi ([195.156.147.13]:44132 helo=jenni2.inet.fi) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWv5q-0003Ys-GM for help-gnu-emacs@gnu.org; Sat, 03 Dec 2011 14:17:50 -0500 Original-Received: from mithlond.arda (84.251.132.215) by jenni2.inet.fi (8.5.140.02) id 4EB3AFE101591459; Sat, 3 Dec 2011 21:17:38 +0200 Original-Received: from dtw by mithlond.arda with local (Exim 4.72) (envelope-from ) id 1RWv5d-0004Ua-SE; Sat, 03 Dec 2011 21:17:37 +0200 In-Reply-To: <812215ED-D638-4BE4-8AD3-AC7EB95378E0@math.ethz.ch> (Marius Hofert's message of "Wed, 23 Nov 2011 17:24:49 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 195.156.147.13 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83116 Archived-At: * 2011-11-23T17:24:49+01:00 * Marius Hofert wrote: > If I want to create a new message with "m", it shows my default email > address in "From:" [...] every once in a while I would like to hav > "From: my.name@googlemail.com" instead of "From: my.name@uni.edu". So > far, I deleted the entry and typed in my gmail account's address. Is > there a simpler way? Here's my solution for (1) setting up Gnus for several mail addresses and (2) cycling them easily in a message-mode buffer (using F9 key). (setq user-full-name "User Name") (defvar my-email-addresses '("primary.address@internet.invalid" "other.address@somewhere.invalid" "yet.another@invalid")) ;; Set important variables (let ((addr my-email-addresses)) (setq-default user-mail-address (car addr) message-alternative-emails (regexp-opt (cdr addr) 'words) message-dont-reply-to-names (regexp-opt addr 'words) gnus-ignored-from-addresses message-dont-reply-to-names)) ;; The cycling functionality (add-hook 'message-mode-hook 'my-message-mode-hook) (defun my-message-mode-hook () (define-key message-mode-map (kbd "") 'my-message-toggle-from)) (defun my-message-toggle-from () (interactive) (require 'mail-extr) (let* ((current (nth 1 (mail-extract-address-components (message-fetch-field "From")))) (next (or (nth 1 (member current my-email-addresses)) (nth 0 my-email-addresses)))) (when (and current next) (save-excursion (save-restriction (message-narrow-to-head) (save-match-data (when (re-search-forward "^From: " nil t) (message-narrow-to-field) (delete-region (point-min) (point-max)) (insert "From: " user-full-name " <" next ">\n"))))))))