2010-01-20 06:25:09 -05:00
|
|
|
module ActionMailer
|
2010-01-24 11:49:44 -05:00
|
|
|
# This is the API which is deprecated and is going to be removed on Rails 3.1 release.
|
|
|
|
# Part of the old API will be deprecated after 3.1, for a smoother deprecation process.
|
2010-06-11 06:15:34 -04:00
|
|
|
# Check those in OldApi instead.
|
2010-01-22 05:01:21 -05:00
|
|
|
module DeprecatedApi #:nodoc:
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2010-01-26 05:46:42 -05:00
|
|
|
included do
|
|
|
|
[:charset, :content_type, :mime_version, :implicit_parts_order].each do |method|
|
|
|
|
class_eval <<-FILE, __FILE__, __LINE__ + 1
|
|
|
|
def self.default_#{method}
|
|
|
|
@@default_#{method}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_#{method}=(value)
|
|
|
|
ActiveSupport::Deprecation.warn "ActionMailer::Base.default_#{method}=value is deprecated, " <<
|
2010-01-27 22:37:47 -05:00
|
|
|
"use default :#{method} => value instead"
|
2010-01-26 05:46:42 -05:00
|
|
|
@@default_#{method} = value
|
|
|
|
end
|
|
|
|
|
|
|
|
@@default_#{method} = nil
|
|
|
|
FILE
|
|
|
|
end
|
|
|
|
end
|
2010-01-23 19:15:42 -05:00
|
|
|
|
2010-01-26 05:46:42 -05:00
|
|
|
module ClassMethods
|
2010-01-23 19:15:42 -05:00
|
|
|
# Deliver the given mail object directly. This can be used to deliver
|
|
|
|
# a preconstructed mail object, like:
|
|
|
|
#
|
|
|
|
# email = MyMailer.create_some_mail(parameters)
|
|
|
|
# email.set_some_obscure_header "frobnicate"
|
|
|
|
# MyMailer.deliver(email)
|
2010-01-24 10:37:28 -05:00
|
|
|
def deliver(mail, show_warning=true)
|
|
|
|
if show_warning
|
2010-01-24 11:31:18 -05:00
|
|
|
ActiveSupport::Deprecation.warn "#{self}.deliver is deprecated, call " <<
|
|
|
|
"deliver in the mailer instance instead", caller[0,2]
|
2010-01-24 10:37:28 -05:00
|
|
|
end
|
2010-01-23 19:15:42 -05:00
|
|
|
|
2010-01-24 10:37:28 -05:00
|
|
|
raise "no mail object available for delivery!" unless mail
|
|
|
|
wrap_delivery_behavior(mail)
|
2010-01-23 20:30:13 -05:00
|
|
|
mail.deliver
|
2010-01-23 19:15:42 -05:00
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
2010-01-24 12:40:04 -05:00
|
|
|
def template_root
|
|
|
|
self.view_paths && self.view_paths.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def template_root=(root)
|
2010-01-31 21:32:28 -05:00
|
|
|
ActiveSupport::Deprecation.warn "template_root= is deprecated, use prepend_view_path instead", caller[0,2]
|
2010-01-24 12:40:04 -05:00
|
|
|
self.view_paths = ActionView::Base.process_view_paths(root)
|
|
|
|
end
|
|
|
|
|
|
|
|
def respond_to?(method_symbol, include_private = false)
|
2010-01-22 05:10:37 -05:00
|
|
|
matches_dynamic_method?(method_symbol) || super
|
|
|
|
end
|
|
|
|
|
2010-01-24 12:40:04 -05:00
|
|
|
def method_missing(method_symbol, *parameters)
|
2010-01-22 05:10:37 -05:00
|
|
|
if match = matches_dynamic_method?(method_symbol)
|
|
|
|
case match[1]
|
2010-01-24 11:31:18 -05:00
|
|
|
when 'create'
|
|
|
|
ActiveSupport::Deprecation.warn "#{self}.create_#{match[2]} is deprecated, " <<
|
|
|
|
"use #{self}.#{match[2]} instead", caller[0,2]
|
|
|
|
new(match[2], *parameters).message
|
|
|
|
when 'deliver'
|
|
|
|
ActiveSupport::Deprecation.warn "#{self}.deliver_#{match[2]} is deprecated, " <<
|
|
|
|
"use #{self}.#{match[2]}.deliver instead", caller[0,2]
|
2010-01-24 11:49:44 -05:00
|
|
|
new(match[2], *parameters).message.deliver
|
2010-01-22 05:10:37 -05:00
|
|
|
else super
|
|
|
|
end
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2010-01-24 12:40:04 -05:00
|
|
|
def matches_dynamic_method?(method_name)
|
2010-01-22 05:10:37 -05:00
|
|
|
method_name = method_name.to_s
|
|
|
|
/^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-23 19:15:42 -05:00
|
|
|
# Delivers a Mail object. By default, it delivers the cached mail
|
|
|
|
# object (from the <tt>create!</tt> method). If no cached mail object exists, and
|
|
|
|
# no alternate has been given as the parameter, this will fail.
|
2010-01-24 10:37:28 -05:00
|
|
|
def deliver!(mail = @_message)
|
2010-01-24 11:49:44 -05:00
|
|
|
ActiveSupport::Deprecation.warn "Calling deliver in the AM::Base object is deprecated, " <<
|
|
|
|
"please call deliver in the Mail instance", caller[0,2]
|
2010-01-24 10:37:28 -05:00
|
|
|
self.class.deliver(mail, false)
|
2010-01-23 19:15:42 -05:00
|
|
|
end
|
2010-01-24 10:37:28 -05:00
|
|
|
alias :deliver :deliver!
|
2010-01-23 19:15:42 -05:00
|
|
|
|
2010-01-22 05:01:21 -05:00
|
|
|
def render(*args)
|
|
|
|
options = args.last.is_a?(Hash) ? args.last : {}
|
2010-01-26 13:15:20 -05:00
|
|
|
|
|
|
|
if options[:body].is_a?(Hash)
|
2010-01-24 10:37:28 -05:00
|
|
|
ActiveSupport::Deprecation.warn(':body in render deprecated. Please use instance ' <<
|
|
|
|
'variables as assigns instead', caller[0,1])
|
2010-01-26 13:15:20 -05:00
|
|
|
|
|
|
|
options[:body].each { |k,v| instance_variable_set(:"@#{k}", v) }
|
2010-01-22 05:01:21 -05:00
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
2010-01-20 06:25:09 -05:00
|
|
|
|
2010-01-22 05:01:21 -05:00
|
|
|
# Render a message but does not set it as mail body. Useful for rendering
|
|
|
|
# data for part and attachments.
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# render_message "special_message"
|
|
|
|
# render_message :template => "special_message"
|
|
|
|
# render_message :inline => "<%= 'Hi!' %>"
|
|
|
|
#
|
2010-01-24 10:37:28 -05:00
|
|
|
def render_message(*args)
|
|
|
|
ActiveSupport::Deprecation.warn "render_message is deprecated, use render instead", caller[0,2]
|
|
|
|
render(*args)
|
2010-01-22 05:01:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2010-01-26 05:46:42 -05:00
|
|
|
|
|
|
|
def initialize_defaults(*)
|
|
|
|
@charset ||= self.class.default_charset.try(:dup)
|
|
|
|
@content_type ||= self.class.default_content_type.try(:dup)
|
|
|
|
@implicit_parts_order ||= self.class.default_implicit_parts_order.try(:dup)
|
|
|
|
@mime_version ||= self.class.default_mime_version.try(:dup)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2010-01-24 12:40:04 -05:00
|
|
|
def create_parts
|
2010-01-24 11:49:44 -05:00
|
|
|
if @body.is_a?(Hash) && !@body.empty?
|
|
|
|
ActiveSupport::Deprecation.warn "Giving a hash to body is deprecated, please use instance variables instead", caller[0,2]
|
2010-01-22 05:01:21 -05:00
|
|
|
@body.each { |k, v| instance_variable_set(:"@#{k}", v) }
|
|
|
|
end
|
2010-01-24 11:49:44 -05:00
|
|
|
super
|
2010-01-20 06:25:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2010-01-27 22:37:47 -05:00
|
|
|
end
|