Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: Eric Sherman <hyperbolist@gmail.com>
To: sup-talk <sup-talk@rubyforge.org>
Subject: Re: [sup-talk] Ruby question: before-add-message.rb and adding multiple labels at once
Date: Wed, 13 Jan 2010 10:49:00 -0500	[thread overview]
Message-ID: <1263396697-sup-5561@changeling.local> (raw)
In-Reply-To: <1263386714-sup-5331@sam.mediasupervision.de>

Excerpts from Gregor Hoffleit's message of Wed Jan 13 08:13:18 -0500 2010:
> In order to keep before-add-message.rb readable, I was using one-line
> filters like:
> 
>     message.add_label "ad apple" if message.from.email =~ /@insideapple.apple.com/
>     message.add_label "ad amazon" if message.from.email =~ /promotion.*@amazon.com/
>     message.add_label "list sup" if message.subj =~ /\[sup-talk\]/
>     message.add_label "list sup-devel" if message.subj =~ /\[sup-devel\]/
> 
> That seemed to work, somehow. Only now I realized that message.add_label
> in fact only takes a single label as argument.
> 
> Is it true that I have to change the above syntax into the much more
> verbose:
> 
>     if message.subj =~ /\[sup-devel\]/
>     message.add_label :list
>     message.add_label :"sup-devel"
>     end
> 
> Removing a message from the inbox ("message.remove_label :inbox") while
> applying a label leads to a similar 'code bloat'.

You could try this:
[:list, :sup-devel].each { |l| message.add_label l } if condition
[:inbox, :unread].each { |l| message.remove_label l } if condition

Or something like this:
case [message.from, message.subj].flatten.to_s
  when /foo/ then
    [:label1, :label2].each { |l| message.add_label l }
    [:inbox, :unread].each { |l| message.remove_label l }
  when /bar/ then
    [:label3, :label4].each { |l| message.add_label l }
    [:inbox, :unread].each { |l| message.remove_label l }
end
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk


  reply	other threads:[~2010-01-13 15:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-13 13:13 Gregor Hoffleit
2010-01-13 15:49 ` Eric Sherman [this message]
2010-01-15 15:51   ` Gregor Hoffleit
2010-01-17 15:29 ` William Morgan
2010-01-15 17:01 Gregor Hoffleit

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=1263396697-sup-5561@changeling.local \
    --to=hyperbolist@gmail.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