Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [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

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