From: Tero Tilus <tero@tilus.net>
To: sup-talk <sup-talk@rubyforge.org>
Cc: Sup developers <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] Message#edit_labels [was: [sup-talk] Ruby question: before-add-message.rb and adding multiple labels at once]
Date: Sun, 17 Jan 2010 00:41:09 +0200 [thread overview]
Message-ID: <1263680819-sup-415@tilus.net> (raw)
In-Reply-To: <1263574849-sup-3477@sam.mediasupervision.de>
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 <tero@tilus.net>
Date: Sun, 17 Jan 2010 00:23:26 +0200
Subject: [PATCH] Message#edit_labels
Signed-off-by: Tero Tilus <tero@tilus.net>
---
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
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next parent reply other threads:[~2010-01-16 22:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1263574849-sup-3477@sam.mediasupervision.de>
2010-01-16 22:41 ` Tero Tilus [this message]
2010-01-21 23:51 ` [sup-devel] [PATCH] Message#edit_labels [was: " Tero Tilus
2010-01-23 13:11 ` William Morgan
2010-01-25 2:05 ` Tero Tilus
2010-02-04 7:58 ` Tero Tilus
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=1263680819-sup-415@tilus.net \
--to=tero@tilus.net \
--cc=sup-devel@rubyforge.org \
--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