Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Michael Stapelberg <michael+sup@stapelberg.de>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] new hook: compose-from
Date: Tue, 09 Mar 2010 18:54:18 +0100	[thread overview]
Message-ID: <1268157224-sup-7509@midna.zekjur.net> (raw)

[-- 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

             reply	other threads:[~2010-03-09 17:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-09 17:54 Michael Stapelberg [this message]
2010-03-09 18:18 ` Edward Z. Yang
2010-03-09 22:21   ` Michael Stapelberg

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=1268157224-sup-7509@midna.zekjur.net \
    --to=michael+sup@stapelberg.de \
    --cc=sup-devel@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