From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Elisp help needed Date: 27 Nov 2003 08:29:08 +0200 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <871xru20u9.fsf@inspiron.meinnetz.de> Reply-To: Eli Zaretskii NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1069914604 2441 80.91.224.253 (27 Nov 2003 06:30:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 Nov 2003 06:30:04 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 27 07:30:02 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1APFf8-0004Wc-00 for ; Thu, 27 Nov 2003 07:30:02 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1APGcV-0003ue-E8 for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Nov 2003 02:31:23 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1APGaf-00031E-T6 for help-gnu-emacs@gnu.org; Thu, 27 Nov 2003 02:29:29 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1APGa5-00021h-PK for help-gnu-emacs@gnu.org; Thu, 27 Nov 2003 02:29:24 -0500 Original-Received: from [207.232.27.5] (helo=WST0054) by monty-python.gnu.org with asmtp (Exim 4.24) id 1APGZv-0001b4-TZ for help-gnu-emacs@gnu.org; Thu, 27 Nov 2003 02:28:44 -0500 Original-To: help-gnu-emacs@gnu.org In-reply-to: <871xru20u9.fsf@inspiron.meinnetz.de> (message from Tassilo Horn on Wed, 26 Nov 2003 23:59:10 +0100) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.emacs.help:14638 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14638 > From: Tassilo Horn > Newsgroups: gnu.emacs.help > Date: Wed, 26 Nov 2003 23:59:10 +0100 > > (defun fs-change-smtp () > "Change the SMTP server according to the current from line." > (save-excursion > (let ((from > (save-restriction > (message-narrow-to-headers) > (message-fetch-field "from")))) > (cond > ((string-match from "heimdall@uni-koblenz.de") > (setq smtpmail-smtp-server "mailhost.uni-koblenz.de")) > ((string-match from "tassilo.horn@freenet.de") > (setq smtpmail-smtp-server "mx.freenet.de")) > ((string-match from "tassilo.horn@gmx.de") > (setq smtpmail-smtp-server "mail.gmx.de")) > (t > (setq smtpmail-smtp-server "mailhost.uni-koblenz.de")))))) > (add-hook 'message-send-hook 'fs-change-smtp) > > But this doesn't work correctly. Always the default of the cond is > taken, even the From-line is another mail address (gmx or freenet). So I > think that the variable from has the wrong content. I think you reversed the arguments to string-match (see the function's doc string). Also, I'm not sure message-fetch-field does what you think it does in the buffer where you compose a message being sent (as opposed to the buffer where you read mail sent by others to you). Anyway, the proper way to solve such problems is to debug them. With the cursor inside the function, type "M-x edebug-defun RET", then do whatever you do to compose a message, and you will see that when fs-change-smtp is called, Edebug, the Emacs Lisp debugger kicks in and lets you step through the code and see the results of each evaluation. That will show you what's wrong. The chapter "Edebug" in the ELisp manual will tell you how to use Edebug. Good luck.