* [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
* Re: [sup-devel] [PATCH] new hook: compose-from
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
0 siblings, 1 reply; 3+ messages in thread
From: Edward Z. Yang @ 2010-03-09 18:18 UTC (permalink / raw)
To: sup-devel
Excerpts from Michael Stapelberg's message of Tue Mar 09 12:54:18 -0500 2010:
> 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
I use before-edit.rb to do a similar thing. Are the semantics the same?
Cheers,
Edward
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-devel] [PATCH] new hook: compose-from
2010-03-09 18:18 ` Edward Z. Yang
@ 2010-03-09 22:21 ` Michael Stapelberg
0 siblings, 0 replies; 3+ messages in thread
From: Michael Stapelberg @ 2010-03-09 22:21 UTC (permalink / raw)
To: sup-devel
Hi Edward,
Excerpts from Edward Z. Yang's message of Di Mär 09 19:18:00 +0100 2010:
> I use before-edit.rb to do a similar thing. Are the semantics the same?
Roughly. header["To"] contains a full string (not only the entered address)
and you have to set header["From"] to a string instead of a Person object.
But yeah, seems like you are right and this hook is redundant.
Best regards,
Michael
_______________________________________________
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