aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/old_api.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib/action_mailer/old_api.rb')
-rw-r--r--actionmailer/lib/action_mailer/old_api.rb72
1 files changed, 34 insertions, 38 deletions
diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb
index 79d024a350..04728cafb0 100644
--- a/actionmailer/lib/action_mailer/old_api.rb
+++ b/actionmailer/lib/action_mailer/old_api.rb
@@ -8,9 +8,7 @@ module ActionMailer
included do
extend ActionMailer::AdvAttrAccessor
-
- @@protected_instance_variables = %w(@parts)
- cattr_reader :protected_instance_variables
+ self.protected_instance_variables.concat %w(@parts @mail_was_called)
# Specify the BCC addresses for the message
adv_attr_accessor :bcc
@@ -42,11 +40,11 @@ module ActionMailer
# The recipient addresses for the message, either as a string (for a single
# address) or an array (for multiple addresses).
- adv_attr_accessor :recipients
+ adv_attr_accessor :recipients, "Please pass :to as hash key to mail() instead"
# The date on which the message was sent. If not set (the default), the
# header will be set by the delivery agent.
- adv_attr_accessor :sent_on
+ adv_attr_accessor :sent_on, "Please pass :date as hash key to mail() instead"
# Specify the subject of the message.
adv_attr_accessor :subject
@@ -54,20 +52,12 @@ module ActionMailer
# Specify the template name to use for current message. This is the "base"
# template name, without the extension or directory, and may be used to
# have multiple mailer methods share the same template.
- adv_attr_accessor :template
-
- # Override the mailer name, which defaults to an inflected version of the
- # mailer's class name. If you want to use a template in a non-standard
- # location, you can use this to specify that location.
- adv_attr_accessor :mailer_name
+ adv_attr_accessor :template, "Please pass :template_name or :template_path as hash key to mail() instead"
# Define the body of the message. This is either a Hash (in which case it
# specifies the variables to pass to the template when it is rendered),
# or a string, in which case it specifies the actual text of the message.
adv_attr_accessor :body
-
- # Alias controller_path to mailer_name so render :partial in views work.
- alias :controller_path :mailer_name
end
def process(method_name, *args)
@@ -84,6 +74,8 @@ module ActionMailer
# part itself is yielded to the block so that other properties (charset,
# body, headers, etc.) can be set on it.
def part(params)
+ ActiveSupport::Deprecation.warn "part() is deprecated and will be removed in future versions. " <<
+ "Please pass a block to mail() instead."
params = {:content_type => params} if String === params
if custom_headers = params.delete(:headers)
@@ -99,6 +91,8 @@ module ActionMailer
# Add an attachment to a multipart message. This is simply a part with the
# content-disposition set to "attachment".
def attachment(params, &block)
+ ActiveSupport::Deprecation.warn "attachment() is deprecated and will be removed in future versions. " <<
+ "Please use the attachments[] API instead."
params = { :content_type => params } if String === params
params[:content] ||= params.delete(:data) || params.delete(:body)
@@ -116,43 +110,43 @@ module ActionMailer
def normalize_nonfile_hash(params)
content_disposition = "attachment;"
-
+
mime_type = params.delete(:mime_type)
-
+
if content_type = params.delete(:content_type)
content_type = "#{mime_type || content_type};"
end
params[:body] = params.delete(:data) if params[:data]
-
+
{ :content_type => content_type,
:content_disposition => content_disposition }.merge(params)
end
-
+
def normalize_file_hash(params)
filename = File.basename(params.delete(:filename))
content_disposition = "attachment; filename=\"#{File.basename(filename)}\""
-
+
mime_type = params.delete(:mime_type)
-
+
if (content_type = params.delete(:content_type)) && (content_type !~ /filename=/)
content_type = "#{mime_type || content_type}; filename=\"#{filename}\""
end
-
+
params[:body] = params.delete(:data) if params[:data]
-
+
{ :content_type => content_type,
:content_disposition => content_disposition }.merge(params)
end
- def create_mail
+ def create_mail
m = @_message
- set_fields!({:subject => subject, :to => recipients, :from => from,
- :bcc => bcc, :cc => cc, :reply_to => reply_to}, charset)
+ set_fields!({:subject => @subject, :to => @recipients, :from => @from,
+ :bcc => @bcc, :cc => @cc, :reply_to => @reply_to}, @charset)
- m.mime_version = mime_version unless mime_version.nil?
- m.date = sent_on.to_time rescue sent_on if sent_on
+ m.mime_version = @mime_version if @mime_version
+ m.date = @sent_on.to_time rescue @sent_on if @sent_on
@headers.each { |k, v| m[k] = v }
@@ -178,19 +172,21 @@ module ActionMailer
wrap_delivery_behavior!
m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii?
-
+
@_message
end
-
+
# Set up the default values for the various instance variables of this
# mailer. Subclasses may override this method to provide different
# defaults.
- def initialize_defaults(method_name)
+ def initialize_defaults(method_name)
@charset ||= self.class.default[:charset].try(:dup)
@content_type ||= self.class.default[:content_type].try(:dup)
@implicit_parts_order ||= self.class.default[:parts_order].try(:dup)
@mime_version ||= self.class.default[:mime_version].try(:dup)
+ @cc, @bcc, @reply_to, @subject, @from, @recipients = nil, nil, nil, nil, nil, nil
+
@mailer_name ||= self.class.mailer_name.dup
@template ||= method_name
@mail_was_called = false
@@ -201,11 +197,11 @@ module ActionMailer
@body ||= {}
end
- def create_parts
+ def create_parts
if String === @body
@parts.unshift create_inline_part(@body)
elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ }
- lookup_context.find_all(@template, @mailer_name).each do |template|
+ lookup_context.find_all(@template, [@mailer_name]).each do |template|
self.formats = template.formats
@parts << create_inline_part(render(:template => template), template.mime_type)
end
@@ -216,11 +212,11 @@ module ActionMailer
# If this is a multipart e-mail add the mime_version if it is not
# already set.
- @mime_version ||= "1.0" if !@parts.empty?
+ @mime_version ||= "1.0" unless @parts.empty?
end
end
- def create_inline_part(body, mime_type=nil)
+ def create_inline_part(body, mime_type=nil)
ct = mime_type || "text/plain"
main_type, sub_type = split_content_type(ct.to_s)
@@ -242,17 +238,17 @@ module ActionMailer
m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to]
end
- def split_content_type(ct)
+ def split_content_type(ct)
ct.to_s.split("/")
end
- def parse_content_type(defaults=nil)
+ def parse_content_type
if @content_type.blank?
[ nil, {} ]
else
ctype, *attrs = @content_type.split(/;\s*/)
- attrs = attrs.inject({}) { |h,s| k,v = s.split(/\=/, 2); h[k] = v; h }
- [ctype, {"charset" => @charset}.merge(attrs)]
+ attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }]
+ [ctype, {"charset" => @charset}.merge!(attrs)]
end
end
end