Port async delivery methods to Rails 3.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9532 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
abdcd7d705
commit
26868d8b14
|
@ -49,26 +49,39 @@ end
|
||||||
|
|
||||||
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
|
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
|
||||||
|
|
||||||
module AsynchronousMailer
|
require 'mail'
|
||||||
# Adds :async_smtp and :async_sendmail delivery methods
|
|
||||||
# to perform email deliveries asynchronously
|
module DeliveryMethods
|
||||||
%w(smtp sendmail).each do |type|
|
class AsyncSMTP < ::Mail::SMTP
|
||||||
define_method("perform_delivery_async_#{type}") do |mail|
|
def deliver!(*args)
|
||||||
Thread.start do
|
Thread.start do
|
||||||
send "perform_delivery_#{type}", mail
|
super *args
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds a delivery method that writes emails in tmp/emails for testing purpose
|
class AsyncSendmail < ::Mail::Sendmail
|
||||||
def perform_delivery_tmp_file(mail)
|
def deliver!(*args)
|
||||||
dest_dir = File.join(Rails.root, 'tmp', 'emails')
|
Thread.start do
|
||||||
Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
|
super *args
|
||||||
File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) }
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
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 ActionController
|
||||||
module MimeResponds
|
module MimeResponds
|
||||||
|
|
Loading…
Reference in New Issue