diff options
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/adv_attr_accessor.rb | 28 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 24 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/old_api.rb | 255 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/tmail_compat.rb | 37 |
4 files changed, 3 insertions, 341 deletions
diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb deleted file mode 100644 index c1aa8021ce..0000000000 --- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb +++ /dev/null @@ -1,28 +0,0 @@ -module ActionMailer - module AdvAttrAccessor #:nodoc: - def adv_attr_accessor(name, deprecation=nil) - ivar = "@#{name}" - deprecation ||= "Please pass :#{name} as hash key to mail() instead" - - class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1 - def #{name}=(value) - ActiveSupport::Deprecation.warn "#{name}= is deprecated. #{deprecation}" - #{ivar} = value - end - - def #{name}(*args) - raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1 - if args.empty? - ActiveSupport::Deprecation.warn "#{name}() is deprecated and will be removed in future versions." - #{ivar} if instance_variable_names.include?(#{ivar.inspect}) - else - ActiveSupport::Deprecation.warn "#{name}(value) is deprecated. #{deprecation}" - #{ivar} = args.first - end - end - ACCESSORS - - self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables) - end - end -end diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index f00a0c8ae0..103da05639 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,5 +1,4 @@ require 'mail' -require 'action_mailer/tmail_compat' require 'action_mailer/collector' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' @@ -131,9 +130,6 @@ module ActionMailer #:nodoc: # # config.action_mailer.default_url_options = { :host => "example.com" } # - # Setting <tt>ActionMailer::Base.default_url_options</tt> directly is now deprecated, use the configuration - # option mentioned above to set the default host. - # # If you do decide to set a default <tt>:host</tt> for your mailers you want to use the # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are # generated because the <tt>url_for</tt> view helper will, by default, generate relative URLs when a @@ -297,9 +293,9 @@ module ActionMailer #:nodoc: # information and a cryptographic Message Digest 5 algorithm to hash important information) # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server # and starts to use it. - # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is - # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name - # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the + # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is + # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name + # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the # constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER,...). # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method. @@ -325,19 +321,6 @@ module ActionMailer #:nodoc: # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with # <tt>delivery_method :test</tt>. Most useful for unit and functional testing. # - # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to - # set the default +:charset+. - # - # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above - # to set the default +:content_type+. - # - # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above - # to set the default +:mime_version+. - # - # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above - # to set the default +:parts_order+. Parts Order is used when a message is built implicitly - # (i.e. multiple parts are assembled from templates which specify the content type in their - # filenames) this variable controls how the parts are ordered. class Base < AbstractController::Base include DeliveryMethods abstract! @@ -352,7 +335,6 @@ module ActionMailer #:nodoc: self.protected_instance_variables = %w(@_action_has_layout) helper ActionMailer::MailHelper - include ActionMailer::OldApi private_class_method :new #:nodoc: diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb deleted file mode 100644 index bfa9499764..0000000000 --- a/actionmailer/lib/action_mailer/old_api.rb +++ /dev/null @@ -1,255 +0,0 @@ -require 'active_support/concern' -require 'active_support/core_ext/object/try' -require 'active_support/core_ext/object/blank' - -module ActionMailer - module OldApi #:nodoc: - extend ActiveSupport::Concern - - included do - extend ActionMailer::AdvAttrAccessor - self.protected_instance_variables.concat %w(@parts @mail_was_called @headers) - - # Specify the BCC addresses for the message - adv_attr_accessor :bcc - - # Specify the CC addresses for the message. - adv_attr_accessor :cc - - # Specify the charset to use for the message. This defaults to the - # +default_charset+ specified for ActionMailer::Base. - adv_attr_accessor :charset - - # Specify the content type for the message. This defaults to <tt>text/plain</tt> - # in most cases, but can be automatically set in some situations. - adv_attr_accessor :content_type - - # Specify the from address for the message. - adv_attr_accessor :from - - # Specify the address (if different than the "from" address) to direct - # replies to this message. - adv_attr_accessor :reply_to - - # Specify the order in which parts should be sorted, based on content-type. - # This defaults to the value for the +default_implicit_parts_order+. - adv_attr_accessor :implicit_parts_order - - # Defaults to "1.0", but may be explicitly given if needed. - adv_attr_accessor :mime_version - - # The recipient addresses for the message, either as a string (for a single - # address) or an array (for multiple addresses). - 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, "Please pass :date as hash key to mail() instead" - - # Specify the subject of the message. - adv_attr_accessor :subject - - # 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, "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 - end - - def process(method_name, *args) - initialize_defaults(method_name) - super - unless @mail_was_called - create_parts - create_mail - end - @_message - end - - # Add a part to a multipart message, with the given content-type. The - # 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) - params.merge!(custom_headers) - end - - part = Mail::Part.new(params) - - yield part if block_given? - @parts << part - end - - # 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) - - if params[:filename] - params = normalize_file_hash(params) - else - params = normalize_nonfile_hash(params) - end - - part(params, &block) - end - - protected - - 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 - m = @_message - - set_fields!({:subject => @subject, :to => @recipients, :from => @from, - :bcc => @bcc, :cc => @cc, :reply_to => @reply_to}, @charset) - - 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 } - - real_content_type, ctype_attrs = parse_content_type - main_type, sub_type = split_content_type(real_content_type) - - if @parts.size == 1 && @parts.first.parts.empty? - m.content_type([main_type, sub_type, ctype_attrs]) - m.body = @parts.first.body.encoded - else - @parts.each do |p| - m.add_part(p) - end - - m.body.set_sort_order(@implicit_parts_order) - m.body.sort_parts! - - if real_content_type =~ /multipart/ - ctype_attrs.delete "charset" - m.content_type([main_type, sub_type, ctype_attrs]) - end - end - - 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) - @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 - - @parts ||= [] - @headers ||= {} - @sent_on ||= Time.now - @body ||= {} - end - - 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| - self.formats = template.formats - @parts << create_inline_part(render(:template => template), template.mime_type) - end - - if @parts.size > 1 - @content_type = "multipart/alternative" if @content_type !~ /^multipart/ - end - - # If this is a multipart e-mail add the mime_version if it is not - # already set. - @mime_version ||= "1.0" unless @parts.empty? - end - end - - def create_inline_part(body, mime_type=nil) - ct = mime_type || "text/plain" - main_type, sub_type = split_content_type(ct.to_s) - - Mail::Part.new( - :content_type => [main_type, sub_type, {:charset => charset}], - :content_disposition => "inline", - :body => body - ) - end - - def set_fields!(headers, charset) #:nodoc: - m = @_message - m.charset = charset - m.subject ||= headers.delete(:subject) if headers[:subject] - m.to ||= headers.delete(:to) if headers[:to] - m.from ||= headers.delete(:from) if headers[:from] - m.cc ||= headers.delete(:cc) if headers[:cc] - m.bcc ||= headers.delete(:bcc) if headers[:bcc] - m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to] - end - - def split_content_type(ct) - ct.to_s.split("/") - end - - def parse_content_type - if @content_type.blank? - [ nil, {} ] - else - ctype, *attrs = @content_type.split(/;\s*/) - attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }] - [ctype, {"charset" => @charset}.merge!(attrs)] - end - end - end -end diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb deleted file mode 100644 index 1b2cdcfb27..0000000000 --- a/actionmailer/lib/action_mailer/tmail_compat.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Mail - class Message - - def set_content_type(*args) - message = 'Message#set_content_type is deprecated, please just call ' << - 'Message#content_type with the same arguments' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - content_type(*args) - end - - alias :old_transfer_encoding :transfer_encoding - def transfer_encoding(value = nil) - if value - message = 'Message#transfer_encoding is deprecated, ' << - 'please call Message#content_transfer_encoding with the same arguments' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - content_transfer_encoding(value) - else - old_transfer_encoding - end - end - - def transfer_encoding=(value) - message = 'Message#transfer_encoding= is deprecated, ' << - 'please call Message#content_transfer_encoding= with the same arguments' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - self.content_transfer_encoding = value - end - - def original_filename - message = 'Message#original_filename is deprecated, please call Message#filename' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - filename - end - - end -end |