From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Help needed to simplify code for customisation
Date: Tue, 10 Mar 2009 20:39:21 -0600 [thread overview]
Message-ID: <gp788l$ja9$1@ger.gmane.org> (raw)
In-Reply-To: <gp4idk$ju5$1@rileyrgdev.motzarella.org>
Richard Riley wrote:
> Could someone please recommend the best way to remove the 3 similar lines
> doing string-match on the "account" assign and iterate a variable list to
> which I can "add-to-list" in other .el libraries for example?
>
> ,----
> | (if (message-mail-p)
> | (save-excursion
> | (let* ((from
> | (save-restriction
> | (message-narrow-to-headers)
> | (message-fetch-field "from")))
> | (account
> | (cond
> | ((string-match ".*root.*" from)"richardriley")
> | ((string-match ".*richardriley.*" from)"richardriley")
> | ((string-match ".*rileyrgdev.*" from)"rileyrgdev")
> | ))
> | )
> | (setq message-sendmail-extra-arguments (list "-a" account))
> | )))
> | )
> `----
>
> Thanks for any pointers,
Why not use message-field-value instead of message-fetch-field, since
it takes care of the narrowing as well?
(string-match ".*foo.*" BAR) is equivalent to (string-match "foo" BAR)
when used as a predicate.
Your patterns are not very specific and admit false positives e.g.
"FOO@BARrichardrileyBAZ.com" and "foo@bar.com (not richardriley)".
At the very least, they should be anchored with \< and \>.
Better yet, use mail-header-parse-address to split the header into
MAILBOX and COMMENT components, then match only on MAILBOX.
Here's what I came up with:
(defvar my-sendmail-accounts
'(("root" . "richardriley") ("richardriley") ("rileyrgdev"))
"Alist of (MAILBOX . ACCOUNT) pairs. If ACCOUNT is nil, use MAILBOX.")
(when (message-mail-p)
(let ((sender (car (mail-header-parse-address (message-field-value
"From"))))
(accounts-regexp (format "\\`\\(%s\\)\\>"
(mapconcat (function car)
my-sendmail-accounts
"\\|")
)))
(when (string-match accounts-regexp sender)
(let ((mailbox-account (assoc (match-string 0 sender)
my-sendmail-accounts)))
(setq message-sendmail-extra-arguments
(list "-a" (or (cdr mailbox-account)
(car mailbox-account))))))))
--
Kevin Rodgers
Denver, Colorado, USA
prev parent reply other threads:[~2009-03-11 2:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-10 2:14 Help needed to simplify code for customisation Richard Riley
2009-03-10 6:44 ` Xah Lee
[not found] ` <b5ecffc4-3770-4c6e-8f1c-38042d65d09e@a39g2000yqc.googlegroups.com>
2009-03-10 11:42 ` William James
2009-03-10 16:53 ` Marco Antoniotti
2009-03-11 6:37 ` Kenneth Tilton
2009-03-11 2:39 ` Kevin Rodgers [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='gp788l$ja9$1@ger.gmane.org' \
--to=kevin.d.rodgers@gmail.com \
--cc=help-gnu-emacs@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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.