Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] hook with external file ref
@ 2011-03-03 13:26 Philippe LeCavalier
  2011-03-03 17:35 ` David J. Hamilton
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe LeCavalier @ 2011-03-03 13:26 UTC (permalink / raw)
  To: sup-talk

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.
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-talk] hook with external file ref
  2011-03-03 13:26 [sup-talk] hook with external file ref Philippe LeCavalier
@ 2011-03-03 17:35 ` David J. Hamilton
  2011-03-03 19:12   ` Philippe LeCavalier
  0 siblings, 1 reply; 6+ messages in thread
From: David J. Hamilton @ 2011-03-03 17:35 UTC (permalink / raw)
  To: sup-talk

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-talk] hook with external file ref
  2011-03-03 17:35 ` David J. Hamilton
@ 2011-03-03 19:12   ` Philippe LeCavalier
  2011-03-04 14:06     ` Philippe LeCavalier
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe LeCavalier @ 2011-03-03 19:12 UTC (permalink / raw)
  To: David J. Hamilton; +Cc: sup-talk

Thank you David.
Excerpts from David J. Hamilton's message of Thu Mar 03 12:35:20 -0500 2011:
> 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.

I'll give this a try and see what the outcome is.
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-talk] hook with external file ref
  2011-03-03 19:12   ` Philippe LeCavalier
@ 2011-03-04 14:06     ` Philippe LeCavalier
       [not found]       ` <1299618530-sup-9754@nyx.local>
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe LeCavalier @ 2011-03-04 14:06 UTC (permalink / raw)
  To: Philippe LeCavalier; +Cc: sup-talk

Hi David.
Excerpts from Philippe LeCavalier's message of Thu Mar 03 14:12:40 -0500 2011:
> Thank you David.
> Excerpts from David J. Hamilton's message of Thu Mar 03 12:35:20 -0500 2011:
> > 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
I'm getting "undetermined quoted string" with the above code. Any ideas?

-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-talk] hook with external file ref
       [not found]       ` <1299618530-sup-9754@nyx.local>
@ 2011-03-09  2:13         ` Philippe LeCavalier
  2011-03-10 14:13           ` Philippe LeCavalier
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe LeCavalier @ 2011-03-09  2:13 UTC (permalink / raw)
  To: David J. Hamilton; +Cc: sup-talk

Hi David.
Excerpts from David J. Hamilton's message of Tue Mar 08 16:16:00 -0500 2011:
> Hi Philippe,
> 
> Excerpts from Philippe LeCavalier's message of Fri Mar 04 06:06:17 -0800 2011:
> > Hi David.
> > I'm getting "undetermined quoted string" with the above code. Any ideas?
> 
> Sorry for the late reply.  I don't see what in the above code would give you
> that error.
It's quite possible it's something unrelated to that hook.
> Could you please post your complete before-add-message.rb file?
Since I have yet to settle on a "style" of code for this hook I'm only
playing around with different options. As such, I only apply them 1 at a
time. At the moment I only have your example in there.
> Your addressfile is just a list of domains right?  Something like:
> 
>   gmail.com
>   somewhereelse.net
>   example.org
Yup. Exactly.
> 
> One more thing: the code I originally posted does contain an error: you want to
> use /#{pattern.chomp}/ rather than /#{pattern}/.  So, for example, if your
> addressfile was in /tmp/addressfile you would have:
> 
>   patterns = File.readlines "/tmp/addressfile"
>   patterns.each do |pattern|
>     if message.from.email =~ /#{pattern.chomp}/
>       message.add_label :somelabel
>     end
>   end
I'll try the above. Perhaps that will "settle" things. Back in a bit
once I have a chance to test that.

Thanks again David.
-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-talk] hook with external file ref
  2011-03-09  2:13         ` Philippe LeCavalier
@ 2011-03-10 14:13           ` Philippe LeCavalier
  0 siblings, 0 replies; 6+ messages in thread
From: Philippe LeCavalier @ 2011-03-10 14:13 UTC (permalink / raw)
  To: David J. Hamilton, sup-talk

Excerpts from Philippe LeCavalier's message of Tue Mar 08 21:13:26 -0500 2011:
> Hi David.
> Excerpts from David J. Hamilton's message of Tue Mar 08 16:16:00 -0500 2011:
> > Hi Philippe,
> > 
> > Excerpts from Philippe LeCavalier's message of Fri Mar 04 06:06:17 -0800 2011:
> > > Hi David.
> > > I'm getting "undetermined quoted string" with the above code. Any ideas?
> > 
> > Sorry for the late reply.  I don't see what in the above code would give you
> > that error.
> It's quite possible it's something unrelated to that hook.
Not certain what was going on there. I opened sup with debug to try and
catch the so called "undetermined string" and now I'm not even getting
the error. Strange thing is, I was seeing that over a long period of
time ie a week or more...anyway. Guess I'll drop that.
> > Could you please post your complete before-add-message.rb file?
> Since I have yet to settle on a "style" of code for this hook I'm only
> playing around with different options. As such, I only apply them 1 at a
> time. At the moment I only have your example in there.
> > Your addressfile is just a list of domains right?  Something like:
> > 
> >   gmail.com
> >   somewhereelse.net
> >   example.org
> Yup. Exactly.
> > 
> > One more thing: the code I originally posted does contain an error: you want to
> > use /#{pattern.chomp}/ rather than /#{pattern}/.  So, for example, if your
> > addressfile was in /tmp/addressfile you would have:
> > 
> >   patterns = File.readlines "/tmp/addressfile"
> >   patterns.each do |pattern|
> >     if message.from.email =~ /#{pattern.chomp}/
> >       message.add_label :somelabel
> >     end
> >   end
> I'll try the above. Perhaps that will "settle" things. Back in a bit
> once I have a chance to test that.
> 
> Thanks again David.
Now that I've got no errors I can focus on the hook above. After adding
chomp to the code I now get nothing at all. The log shows the hook is
being read but nothing happens. No label is added and I've confirm for
certain there should be. So no error, but no action ;-) Any suggestions?

-- 
Thanks,
Phil
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-10 14:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-03 13:26 [sup-talk] hook with external file ref Philippe LeCavalier
2011-03-03 17:35 ` David J. Hamilton
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox