Subject: Re: [sup-devel] [PATCH] Message#edit_labels [was: Ruby question: before-add-message.rb and adding multiple labels at once]

From: Tero Tilus <[email-masked]>
Date: Fri, 22 Jan 2010 01:51:05 +0200

Tero Tilus, 2010-01-17 00:41:
> Gregor Hoffleit, 2010-01-15 19:01:
>> May I request a new function "message.edit_labels"
> 
> I'll be using that one too.  Here's a patch.

Did this get merged?  I got no feedback.

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Tero Tilus <[email-masked]>
Date: Mon, 25 Jan 2010 04:05:30 +0200

William Morgan, 2010-01-23 15:11:
> This is very similar to ThreadViewMode#multi_edit_labels, so I would
> prefer a solution that shared a codepath.

Similar indeed.  Factored out.

> It's also important to call LabelManager.<< for each label, to make
> sure they appear in label-list-mode.

I went a step further with this.  Counting on people not having
billion-mail threads and gazillions of tags (and thus this potentially
having performance implications) I dropped all the LabelManager.<<
calls to Message to ensure that every time labels change, LabelManager
is informed.

Patch v2 attached.

---

From: Tero Tilus <[email-masked]>
Date: Thu, 04 Feb 2010 09:58:29 +0200

Tero Tilus, 2010-01-25 04:05:
> > It's also important to call LabelManager.<< for each label, to
> > make sure they appear in label-list-mode.
> 
> billion-mail threads and gazillions of tags (and thus this
> potentially having performance implications) I dropped all the
> LabelManager.<< calls down to Message to ensure that every time
> labels change, LabelManager is informed.

...and that broke sup-dump.  Patch v3 (rebased to next) attached.

---

From: Tero Tilus <[email-masked]>
Date: Sun, 17 Jan 2010 00:41:09 +0200

Gregor Hoffleit, 2010-01-15 19:01:
> Ok. I ended up with
> 
>     ([:list,:"sup-devel"].each {|l| message.add_label l}; message.remove_label :inbox) if message.subj =~ /\[sup-devel\]/
> 
> May I request a new function "message.edit_labels" that groks the syntax
> of the 'edit labels' command (cf. multi_edit_labels in thread-index-mode.rb):
> 
>     message.edit_labels "list sup-devel -inbox" if message.subj =~ /\[sup-devel\]/
> 
> Comments?

I'll be using that one too.  Here's a patch.  Message#edit_labels
accepts array of strings.  I thought it'll be better that way.
Otherwise it gets really ugly with spaces in labels.

So your usecase would be

  message.edit_labels %w{list sup-devel -inbox} if message.subj =~ /\[sup-devel\]/

By the way, my pretty general list-labeling code looks like this
<http://pastie.org/781240>.

And then the patch...

>From 9eff953dbda404b149a77969305c5732fa1d694e Mon Sep 17 00:00:00 2001
From: Tero Tilus <[email-masked]>
Date: Sun, 17 Jan 2010 00:23:26 +0200
Subject: [PATCH] Message#edit_labels

Signed-off-by: Tero Tilus <[email-masked]>
---
 lib/sup/message.rb |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 3e55de5..e047927 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -206,6 +206,18 @@ class Message
     @labels.delete l
     @dirty = true
   end
+  ## calling m.edit_labels ['foo', '-index', '+bar']
+  ## adds labels foo and bar and removes label index
+  def edit_labels l_arr
+    l_arr.each do |signedlabel|
+      signedlabel, sign, label = signedlabel.match(/^(-|\+)?(.*)$/).to_a
+      if sign == '-'
+        remove_label label
+      else
+        add_label label
+      end
+    end
+  end
 
   def recipients
     @to + @cc + @bcc
-- 
1.5.6.5

---

From: William Morgan <[email-masked]>
Date: Sat, 23 Jan 2010 08:11:33 -0500

> Did this get merged?  I got no feedback.

Sorry about that. This is very similar to the code in
ThreadViewMode#multi_edit_labels, so I would prefer a solution that
shared a codepath. It's also important to call LabelManager.<< for each
label, to make sure they appear in label-list-mode.
-- 
William <[email-masked]>
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel