* [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type
@ 2010-01-20 22:30 Michael Stapelberg
2010-02-27 18:29 ` Rich Lane
0 siblings, 1 reply; 6+ messages in thread
From: Michael Stapelberg @ 2010-01-20 22:30 UTC (permalink / raw)
To: sup-devel
[-- Attachment #1: Type: text/plain, Size: 899 bytes --]
Hi,
I created a hook which modified the body of each new message to look like my
usual skeleton for mails (greeting, content, signature). I did not use the
signature function for that because I wanted to put in the greeting with the
correct recipient.
Now I wanted to make this even more comfortable for me by checking if the
recipient of my mail is speaking english and thus using the english signature
instead of the german one. This was possible to a certain degree, but failed
when I wanted to see if any of the CC'ed addresses matched a certain pattern.
Attached to this mail you can find a patch which will copy the body object
for each type of headers (sender, recipient, all, list) and use the right
version of it in each case (like for the headers).
I am not completely suure if the patch is 100% correct, so please review it
thoroughly. It works for me, though.
Best regards,
Michael
[-- Attachment #2: 0001-Use-multiple-body-arrays-when-calling-before-edit-fo.patch --]
[-- Type: application/octet-stream, Size: 1777 bytes --]
From 96440145b5ea06e418ca301e01a1bfda5e1527e6 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Wed, 20 Jan 2010 23:23:12 +0100
Subject: [PATCH] Use multiple body arrays when calling before-edit for each reply type
This allows for before-edit hooks which modify the body of the message
based on the different headers (previously, they could only modify
headers).
As an example, I use it to sign mail in english if one of the recipients
(not *the* recipient, but one of them) is speaking english.
---
lib/sup/modes/reply-mode.rb | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index 3d39a8a..7f1ae34 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -150,11 +150,13 @@ EOS
:recipient
end)
+ @bodies = {}
@headers.each do |k, v|
- HookManager.run "before-edit", :header => v, :body => body
+ @bodies[k] = Array.new(body)
+ HookManager.run "before-edit", :header => v, :body => @bodies[k]
end
- super :header => @headers[@type_selector.val], :body => body, :twiddles => false
+ super :header => @headers[@type_selector.val], :body => @bodies[@type_selector.val], :twiddles => false
add_selector @type_selector
end
@@ -164,6 +166,7 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ self.body = @bodies[@type_selector.val]
update
end
end
@@ -172,6 +175,7 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ self.body = @bodies[@type_selector.val]
update
end
end
--
1.6.5
[-- Attachment #3: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type
2010-01-20 22:30 [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type Michael Stapelberg
@ 2010-02-27 18:29 ` Rich Lane
2010-03-09 22:58 ` Michael Stapelberg
0 siblings, 1 reply; 6+ messages in thread
From: Rich Lane @ 2010-02-27 18:29 UTC (permalink / raw)
To: Michael Stapelberg; +Cc: sup-devel
What happens when you edit the message and then select another reply type?
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type
2010-02-27 18:29 ` Rich Lane
@ 2010-03-09 22:58 ` Michael Stapelberg
2010-03-12 4:20 ` Rich Lane
0 siblings, 1 reply; 6+ messages in thread
From: Michael Stapelberg @ 2010-03-09 22:58 UTC (permalink / raw)
To: Rich Lane; +Cc: sup-devel
[-- Attachment #1: Type: text/plain, Size: 530 bytes --]
Hi Rich,
Excerpts from Rich Lane's message of Sa Feb 27 19:29:27 +0100 2010:
> What happens when you edit the message and then select another reply type?
You are right, there was a problem here. I reworked the patch, it now behaves
like this:
As long as you did not edit the message, selecting another reply type changes
the body. As soon as you edit one of the bodies, only the headers will be
changed if you switch to a different reply type.
You find the new version of the patch attached to this mail.
Best regards,
Michael
[-- Attachment #2: 0001-Use-multiple-body-arrays-when-calling-before-edit-fo.patch --]
[-- Type: application/octet-stream, Size: 2475 bytes --]
From f939770ebe1a46b39d4f17c1c5447d71f79fb8bf Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 23:56:02 +0100
Subject: [PATCH] Use multiple body arrays when calling before-edit for each reply type
This allows for before-edit hooks which modify the body of the message
based on the different headers (previously, they could only modify
headers).
As an example, I use it to sign mail in english if one of the recipients
(not *the* recipient, but one of them) is speaking english.
---
lib/sup/modes/reply-mode.rb | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index 3d39a8a..d6d6cd1 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -42,6 +42,7 @@ EOS
def initialize message, type_arg=nil
@m = message
+ @edited = false
## it's important to put this early because it forces a read of
## the full headers (most importantly the list-post header, if
@@ -150,11 +151,13 @@ EOS
:recipient
end)
+ @bodies = {}
@headers.each do |k, v|
- HookManager.run "before-edit", :header => v, :body => body
+ @bodies[k] = Array.new(body)
+ HookManager.run "before-edit", :header => v, :body => @bodies[k]
end
- super :header => @headers[@type_selector.val], :body => body, :twiddles => false
+ super :header => @headers[@type_selector.val], :body => @bodies[@type_selector.val], :twiddles => false
add_selector @type_selector
end
@@ -164,6 +167,9 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ if !@edited
+ self.body = @bodies[@type_selector.val]
+ end
update
end
end
@@ -172,6 +178,9 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ if !@edited
+ self.body = @bodies[@type_selector.val]
+ end
update
end
end
@@ -188,6 +197,10 @@ protected
end
def handle_new_text new_header, new_body
+ if new_body != @bodies[@type_selector.val]
+ @bodies[@type_selector.val] = new_body
+ @edited = true
+ end
old_header = @headers[@type_selector.val]
if new_header.size != old_header.size || old_header.any? { |k, v| new_header[k] != v }
@type_selector.set_to :user
--
1.6.5
[-- Attachment #3: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type
2010-03-09 22:58 ` Michael Stapelberg
@ 2010-03-12 4:20 ` Rich Lane
2010-03-12 10:17 ` Michael Stapelberg
0 siblings, 1 reply; 6+ messages in thread
From: Rich Lane @ 2010-03-12 4:20 UTC (permalink / raw)
To: Michael Stapelberg; +Cc: sup-devel
lib/sup/modes/reply-mode.rb:
> + @bodies[k] = Array.new(body)
Why is the body in an array?
lib/sup/modes/reply-mode.rb:
> + if !@edited
> + self.body = @bodies[@type_selector.val]
> + end
The idiomatic way to write this is:
self.body = @bodies[@type_selector.val] unless @edited
The EditMessageMode constructor also calls the before-edit hook, but I
guess if it wasn't broken before it won't be now.
lib/sup/modes/reply-mode.rb:
> + if new_body != @bodies[@type_selector.val]
> + @bodies[@type_selector.val] = new_body
> + @edited = true
> + end
Is there a reason we can't do this unconditionally?
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type
2010-03-12 4:20 ` Rich Lane
@ 2010-03-12 10:17 ` Michael Stapelberg
2010-03-15 5:09 ` Rich Lane
0 siblings, 1 reply; 6+ messages in thread
From: Michael Stapelberg @ 2010-03-12 10:17 UTC (permalink / raw)
To: Rich Lane; +Cc: sup-devel
[-- Attachment #1: Type: text/plain, Size: 811 bytes --]
Hi Rich,
Excerpts from Rich Lane's message of Fr Mär 12 05:20:52 +0100 2010:
> lib/sup/modes/reply-mode.rb:
> > + @bodies[k] = Array.new(body)
>
> Why is the body in an array?
That was left over while refactoring. It isn’t necessary.
> The idiomatic way to write this is:
> self.body = @bodies[@type_selector.val] unless @edited
Alright, changed.
> lib/sup/modes/reply-mode.rb:
> > + if new_body != @bodies[@type_selector.val]
> > + @bodies[@type_selector.val] = new_body
> > + @edited = true
> > + end
>
> Is there a reason we can't do this unconditionally?
Yes, I wanted to avoid setting the @edited flag if the user exited the editor
without making any changes. That way, he can benefit from the changing bodies
for a longer time.
Updated patch attached.
Best regards,
Michael
[-- Attachment #2: 0001-Use-multiple-body-arrays-when-calling-before-edit-fo.patch --]
[-- Type: application/octet-stream, Size: 2426 bytes --]
From 5661f904fd66e1a5f294a2fb602691947860cd97 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 23:56:02 +0100
Subject: [PATCH] Use multiple body arrays when calling before-edit for each reply type
This allows for before-edit hooks which modify the body of the message
based on the different headers (previously, they could only modify
headers).
As an example, I use it to sign mail in english if one of the recipients
(not *the* recipient, but one of them) is speaking english.
---
lib/sup/modes/reply-mode.rb | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index 3d39a8a..bbac922 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -42,6 +42,7 @@ EOS
def initialize message, type_arg=nil
@m = message
+ @edited = false
## it's important to put this early because it forces a read of
## the full headers (most importantly the list-post header, if
@@ -150,11 +151,13 @@ EOS
:recipient
end)
+ @bodies = {}
@headers.each do |k, v|
- HookManager.run "before-edit", :header => v, :body => body
+ @bodies[k] = body
+ HookManager.run "before-edit", :header => v, :body => @bodies[k]
end
- super :header => @headers[@type_selector.val], :body => body, :twiddles => false
+ super :header => @headers[@type_selector.val], :body => @bodies[@type_selector.val], :twiddles => false
add_selector @type_selector
end
@@ -164,6 +167,7 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ self.body = @bodies[@type_selector.val] unless @edited
update
end
end
@@ -172,6 +176,7 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ self.body = @bodies[@type_selector.val] unless @edited
update
end
end
@@ -188,6 +193,10 @@ protected
end
def handle_new_text new_header, new_body
+ if new_body != @bodies[@type_selector.val]
+ @bodies[@type_selector.val] = new_body
+ @edited = true
+ end
old_header = @headers[@type_selector.val]
if new_header.size != old_header.size || old_header.any? { |k, v| new_header[k] != v }
@type_selector.set_to :user
--
1.6.5
[-- Attachment #3: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-03-15 5:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-20 22:30 [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type Michael Stapelberg
2010-02-27 18:29 ` Rich Lane
2010-03-09 22:58 ` Michael Stapelberg
2010-03-12 4:20 ` Rich Lane
2010-03-12 10:17 ` Michael Stapelberg
2010-03-15 5:09 ` Rich Lane
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox