Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: marc.hartstein@alum.vassar.edu (Marc Hartstein)
Subject: [sup-talk] [PATCH] add reply-from hook for user-defined handling of default from in replies
Date: Thu, 12 Jun 2008 12:05:46 -0400	[thread overview]
Message-ID: <1213286746-24268-1-git-send-email-marc.hartstein@alum.vassar.edu> (raw)
In-Reply-To: <1209484583-sup-8823@south>

The reply-from hook can now be used to process headers in a different manner
than the default for purposes of generating a default From: header when
replying to an email.
---
 lib/sup/modes/reply-mode.rb |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index e7b2929..d6a7dc6 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -19,6 +19,16 @@ Return value:
   A string containing the text of the quote line (can be multi-line)
 EOS
 
+  HookManager.register "reply-from", <<EOS
+Selects a default address for the From: header of a new reply.
+Variables:
+  message: a message object representing the message being replied to
+    (useful values include message.recipient_email, message.to, and message.cc)
+Return value:
+  A Person to be used as the default for the From: header, or nil to use the
+  default behavior.
+EOS
+
   def initialize message
     @m = message
 
@@ -29,8 +39,19 @@ EOS
 
     ## first, determine the address at which we received this email. this will
     ## become our From: address in the reply.
+    hook_reply_from = HookManager.run "reply-from", :message => @m
+
+    ## sanity check that selection is a Person (or we'll fail below)
+    ## don't check that it's an Account, though; assume they know what they're doing.
+    if hook_reply_from && !(hook_reply_from.is_a? Person)
+        Redwood::log "reply-from returned non-Person, using default from."
+        hook_reply_from = nil
+    end
+
     from =
-      if @m.recipient_email && AccountManager.is_account_email?(@m.recipient_email)
+      if hook_reply_from
+        hook_reply_from
+      elsif @m.recipient_email && AccountManager.is_account_email?(@m.recipient_email)
         PersonManager.person_for(@m.recipient_email)
       elsif(b = (@m.to + @m.cc).find { |p| AccountManager.is_account? p })
         b
-- 
1.5.3.7



  reply	other threads:[~2008-06-12 16:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-27  6:49 [sup-talk] [PATCH] Config control over how From address is generated when replying William Morgan
2008-04-28  4:11 ` Marc Hartstein
2008-04-29 16:19   ` William Morgan
2008-06-12 16:05     ` Marc Hartstein [this message]
2008-06-12 16:12       ` [sup-talk] [PATCH] add reply-from hook for user-defined handling of default from in replies Marc Hartstein
2008-06-19 17:56         ` William Morgan

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=1213286746-24268-1-git-send-email-marc.hartstein@alum.vassar.edu \
    --to=marc.hartstein@alum.vassar.edu \
    /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