From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.7.146 with SMTP id d18cs101445ebd; Wed, 13 Jan 2010 07:50:54 -0800 (PST) Received: by 10.224.115.74 with SMTP id h10mr691457qaq.372.1263397854374; Wed, 13 Jan 2010 07:50:54 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 2si2263495qwi.27.2010.01.13.07.50.53; Wed, 13 Jan 2010 07:50:54 -0800 (PST) Received-SPF: pass (google.com: domain of sup-talk-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-talk-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-talk-bounces@rubyforge.org; dkim=neutral (body hash did not verify) header.i=@gmail.com Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id C0FB215B802B; Wed, 13 Jan 2010 10:50:44 -0500 (EST) Received: from mail-px0-f174.google.com (mail-px0-f174.google.com [209.85.216.174]) by rubyforge.org (Postfix) with ESMTP id BDA5F18582C1 for ; Wed, 13 Jan 2010 10:49:06 -0500 (EST) Received: by pxi4 with SMTP id 4so5688913pxi.33 for ; Wed, 13 Jan 2010 07:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:content-type:subject:from:to :in-reply-to:references:date:message-id:user-agent :content-transfer-encoding; bh=8i9XJJggy3qLgRdDVfAwr3E95e/WWkPvlfCpl6PeHeQ=; b=ha5TEf4qLiFRP0yWMUTDInLnMi83SQL1btXYEt40xFPmoM9LIV3D0JTd6RYU60917K KAqGbRdQo84pEe3Nq6nwe10lOyis7bmYUbSv6vGDpNtX+vSS1mT28JNUDB+bCyD48S0j EvbUQazbo+m0lrRef6AWseMQxdGJ+u5nhc3fM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:subject:from:to:in-reply-to:references:date:message-id :user-agent:content-transfer-encoding; b=GWzpm9Y09qskrgeBw/Zh5BhWKSISE0AEN8wXTOYB0roBugyN5XduPPKaUK6id9+pez WgP+lZEG9gjAS4QqVaQU4t/U+YnQwbR8lA9U1L08VI43zu4VgrwFPRweTAvJ+cD67ccE X4zWDXVYkcy65YHEfh3vjzpWt+8Jq1/WkusOw= Received: by 10.114.18.29 with SMTP id 29mr7327455war.147.1263397745778; Wed, 13 Jan 2010 07:49:05 -0800 (PST) Received: from localhost (c-76-98-110-216.hsd1.nj.comcast.net [76.98.110.216]) by mx.google.com with ESMTPS id 21sm23034594pzk.7.2010.01.13.07.49.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 13 Jan 2010 07:49:04 -0800 (PST) From: Eric Sherman To: sup-talk In-reply-to: <1263386714-sup-5331@sam.mediasupervision.de> References: <1263386714-sup-5331@sam.mediasupervision.de> Date: Wed, 13 Jan 2010 10:49:00 -0500 Message-Id: <1263396697-sup-5561@changeling.local> User-Agent: Sup/git Subject: Re: [sup-talk] Ruby question: before-add-message.rb and adding multiple labels at once X-BeenThere: sup-talk@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: User & developer discussion of Sup List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-talk-bounces@rubyforge.org Errors-To: sup-talk-bounces@rubyforge.org 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