commit 8ea0970996bc1ab5fdcc68eb5cd6145654949a54
parent feeee41cf0d4dae0a2e01fe117cbef9bcff63560
Author: Sascha Silbe <sascha-pgp@silbe.org>
Date: Wed, 29 Sep 2010 10:13:00 -0400
add sendmail hook
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
Diffstat:
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git 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!"