From: David J. Hamilton <groups@hjdivad.com>
To: sup-talk <sup-talk@rubyforge.org>
Subject: Re: [sup-talk] hook with external file ref
Date: Thu, 03 Mar 2011 09:35:20 -0800 [thread overview]
Message-ID: <1299173352-sup-4428@nyx.local> (raw)
In-Reply-To: <1299158755-sup-5116@plc.intranet.plecavalier.com>
Excerpts from Philippe LeCavalier's message of Thu Mar 03 05:26:03 -0800 2011:
> From: Philippe LeCavalier <support@plecavalier.com>
> To: sup-talk <sup-talk@rubyforge.ord>
> Cc:
> Bcc:
> Subject: hook with external file ref
>
> addressfile = File.open("/home/user/path/addressfile","r")
> if ! addressfile.grep(/#{message.from.email}/).empty?
> message.add_label :somelabel
> end
>
> In the wiki it states "which contains one e-mail address per line". I'm just
> wondering what I would have to change in the code in order to list just the
> domain.
It's a bit tricky because you're trying to find the email address in the
address file, rather than match one of many patterns in the address file to the
email. If you use the latter approach you should be able to put whatever
patterns you want, including just the domain.
patterns = File.readlines "/path/to/my/addressfile"
patterns.each do |pattern|
if message.from.email =~ /#{pattern}/
message.add_label :somelabel
end
end
If you take this approach then you should be able to have lines in your
addressfile like ‘foo.com’ (sans quotes). This will actually match a little
more than what you probably intend (e.g. it would match emails from
foo.com@bar.com or even joe@foodcom.net), but is likely good enough and saves
you from having to learn regular expressions.
--
med vänlig hälsning
David J. Hamilton
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
next prev parent reply other threads:[~2011-03-03 18:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-03 13:26 Philippe LeCavalier
2011-03-03 17:35 ` David J. Hamilton [this message]
2011-03-03 19:12 ` Philippe LeCavalier
2011-03-04 14:06 ` Philippe LeCavalier
[not found] ` <1299618530-sup-9754@nyx.local>
2011-03-09 2:13 ` Philippe LeCavalier
2011-03-10 14:13 ` Philippe LeCavalier
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=1299173352-sup-4428@nyx.local \
--to=groups@hjdivad.com \
--cc=sup-talk@rubyforge.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox