diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-26 16:55:53 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-26 16:55:53 +0000 |
commit | 26868d8b140406cce8c2494efbac7f8f85f452d0 (patch) | |
tree | 7ec888c3bd17942c5d9d9fba8ab7f10f330b13e8 /config | |
parent | abdcd7d705c523fda1ee67a0bde07d5e25d88951 (diff) | |
download | redmine-26868d8b140406cce8c2494efbac7f8f85f452d0.tar.gz redmine-26868d8b140406cce8c2494efbac7f8f85f452d0.zip |
Port async delivery methods to Rails 3.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9532 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/10-patches.rb | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index dccf2d0ef..ea353c49d 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -49,26 +49,39 @@ end ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" } -module AsynchronousMailer - # Adds :async_smtp and :async_sendmail delivery methods - # to perform email deliveries asynchronously - %w(smtp sendmail).each do |type| - define_method("perform_delivery_async_#{type}") do |mail| +require 'mail' + +module DeliveryMethods + class AsyncSMTP < ::Mail::SMTP + def deliver!(*args) + Thread.start do + super *args + end + end + end + + class AsyncSendmail < ::Mail::Sendmail + def deliver!(*args) Thread.start do - send "perform_delivery_#{type}", mail + super *args end end end - # Adds a delivery method that writes emails in tmp/emails for testing purpose - def perform_delivery_tmp_file(mail) - dest_dir = File.join(Rails.root, 'tmp', 'emails') - Dir.mkdir(dest_dir) unless File.directory?(dest_dir) - File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) } + class TmpFile + def initialize(*args); end + + def deliver!(mail) + dest_dir = File.join(Rails.root, 'tmp', 'emails') + Dir.mkdir(dest_dir) unless File.directory?(dest_dir) + File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) } + end end end -ActionMailer::Base.send :include, AsynchronousMailer +ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP +ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail +ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile module ActionController module MimeResponds |