Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] new hook: compose-from
@ 2010-03-09 17:54 Michael Stapelberg
  2010-03-09 18:18 ` Edward Z. Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Stapelberg @ 2010-03-09 17:54 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

Hi,

This hook is useful to use different names/addresses depending on the
destination address, subject, etc. of the message. Example:

  if header["To"] and header["To"] =~ /^sup-(.*)@rubyforge\.org$/
    Person.from_address "Michael Stapelberg <michael+sup@stapelberg.de>"
  end


Best regards,
Michael

[-- Attachment #2: 0001-new-hook-compose-from.patch --]
[-- Type: application/octet-stream, Size: 2209 bytes --]

From 163afe5e216cd6bb8fdfe9fbfb439de2a1e0a63a Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 18:50:48 +0100
Subject: [PATCH] new hook: compose-from

This hook is useful to use different names/addresses depending on the
destination address, subject, etc. of the message. Example:

  if header["To"] and header["To"] =~ /^sup-(.*)@rubyforge\.org$/
    Person.from_address "Michael Stapelberg <michael+sup@stapelberg.de>"
  end
---
 lib/sup/modes/compose-mode.rb |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/lib/sup/modes/compose-mode.rb b/lib/sup/modes/compose-mode.rb
index f0d1e23..c1952fe 100644
--- a/lib/sup/modes/compose-mode.rb
+++ b/lib/sup/modes/compose-mode.rb
@@ -1,9 +1,16 @@
 module Redwood
 
 class ComposeMode < EditMessageMode
+  HookManager.register "compose-from", <<EOS
+Selects a default address for the From: header of a new message.
+Variables:
+  header: the header of the new message
+Return value:
+  A Person to be used as the default for the From: header, or nil to use
+  the default behaviour.
+EOS
   def initialize opts={}
     header = {}
-    header["From"] = (opts[:from] || AccountManager.default_account).full_address
     header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to]
     header["Cc"] = opts[:cc].map { |p| p.full_address }.join(", ") if opts[:cc]
     header["Bcc"] = opts[:bcc].map { |p| p.full_address }.join(", ") if opts[:bcc]
@@ -11,6 +18,18 @@ class ComposeMode < EditMessageMode
     header["References"] = opts[:refs].map { |r| "<#{r}>" }.join(" ") if opts[:refs]
     header["In-Reply-To"] = opts[:replytos].map { |r| "<#{r}>" }.join(" ") if opts[:replytos]
 
+    new_person = if opts[:from]
+      opts[:from]
+    else
+      hook_from = HookManager.run "compose-from", :header => header
+      if hook_from && !(hook_from.is_a? Person)
+        info "compose-from returned non-Person, using default from."
+        hook_from = nil
+      end
+      (hook_from || AccountManager.default_account)
+    end
+    header["From"] = new_person.full_address
+
     super :header => header, :body => (opts[:body] || [])
   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] 3+ messages in thread

end of thread, other threads:[~2010-03-09 22:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-09 17:54 [sup-devel] [PATCH] new hook: compose-from Michael Stapelberg
2010-03-09 18:18 ` Edward Z. Yang
2010-03-09 22:21   ` Michael Stapelberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox