Subject: [sup-talk] [PATCH] Fix problem with account selector

From: Mark Alexander <[email-masked]>
Date: Mon, 15 Apr 2013 10:01:11 -0400

Here is the commit on my fork (I also did a pull request)
for something that I found useful when using the same
inbox for both personal and work email:

https://github.com/bloovis/sup/commit/4f843f53feac2cc7e1f7d8f5a32043878b398ace

When sending a message, the account selector was ignoring
the account set by the before-edit hook.  Fix this
by running the hook before setting up the account selector.
---
 lib/sup/modes/edit-message-mode.rb |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index 464d935..1ed5969 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -116,6 +116,8 @@ EOS
     @selector_label_width = 0
     @async_mode = nil
 
+    HookManager.run "before-edit", :header => @header, :body => @body
+
     @account_selector = nil
     # only show account selector if there is more than one email address
     if $config[:account_selector] && AccountManager.user_emails.length > 1
@@ -145,7 +147,6 @@ EOS
       end
     add_selector @crypto_selector if @crypto_selector
 
-    HookManager.run "before-edit", :header => @header, :body => @body
     if @crypto_selector
       HookManager.run "crypto-mode", :header => @header, :body => @body, :crypto_selector => @crypto_selector
     end
-- 
1.7.9.5
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Mark Alexander <[email-masked]>
Date: Wed, 17 Apr 2013 06:22:08 -0400

I should probably explain the rationale behind this patch.

For a couple of years I used a single instance of sup to handle email
for two different accounts: one for personal email, and the other for
work email.  When I sent a message to somebody at work, I wanted the
From: address to be set automatically to my work email address.
Otherwise I wanted the From: address to be set to my personal email
address.  To do this I wrote a before-edit hook that looked like this
(with my company name changed to "widgets"):

  unless header["In-reply-to"]
    if header["To"] =~ /widgets/
      to = header["To"]
      info "Sending as widgets, to = #{to}"
      header["From"] = "Mark Alexander <[email-masked]>"
    else
      to = header["To"]
      info "Sending as pobox, to = #{to}"
      header["From"] = "Mark Alexander <[email-masked]>"
    end
  end

But the hook didn't work; the account selector was changing the From:
address back to [email-masked] even after the hook had set it to
[email-masked].  The fix was to run the hook before the account
selector was initialized.
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk