Subject: Re: [sup-devel] [PATCH] add sendmail hook

From: Ben Walton <[email-masked]>
Date: Wed, 29 Sep 2010 20:56:53 -0400

Excerpts from Sascha Silbe's message of Wed Sep 29 10:13:00 -0400 2010:

> Add a hook that is run in place of the sendmail command. This allows
> last-minute adjustments including sending a separate copy to each
> recipient and setting the envelope sender, i.e. VERP (variable
> envelope return path).

+1 for this.  The patch looks sane although I didn't actually test it.
-Ben

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Rich Lane <[email-masked]>
Date: Fri, 08 Oct 2010 00:22:42 -0400

Applied to master.

---

From: Sascha Silbe <[email-masked]>
Date: Wed, 29 Sep 2010 16:13:00 +0200

Add a hook that is run in place of the sendmail command. This allows
last-minute adjustments including sending a separate copy to each recipient
and setting the envelope sender, i.e. VERP (variable envelope return path).

Signed-off-by: Sascha Silbe <[email-masked]>
---
 lib/sup/modes/edit-message-mode.rb |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

I've been using this for about three months now for setting the envelope
sender to the subscription address, allowing me to use a different address
in the From: header and doing crossposts even if though I use a separate
subscription address for each mailing list.

diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index bba07b5..d80ff9b 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -58,6 +58,18 @@ Return value:
      none
 EOS

+  HookManager.register "sendmail", <<EOS
+Sends the given mail. If this hook doesn't exist, the sendmail command
+configured for the account is used.
+The message will be saved after this hook is run, so any modification to it
+will be recorded.
+Variables:
+    message: RMail::Message instance of the mail to send
+    account: Account instance matching the From address
+Return value:
+     True if mail has been sent successfully, false otherwise.
+EOS
+
   attr_reader :status
   attr_accessor :body, :header
   bool_reader :edited
@@ -341,8 +353,17 @@ protected
     begin
       date = Time.now
       m = build_message date
-      IO.popen(acct.sendmail, "w") { |p| p.puts m }
-      raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
+
+      if HookManager.enabled? "sendmail"
+	if not HookManager.run "sendmail", :message => m, :account => acct
+          warn "Sendmail hook was not successful"
+          return false
+	end
+      else
+        IO.popen(acct.sendmail, "w") { |p| p.puts m }
+        raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
+      end
+
       SentManager.write_sent_message(date, from_email) { |f| f.puts sanitize_body(m.to_s) }
       BufferManager.kill_buffer buffer
       BufferManager.flash "Message sent!"
--
1.7.1