aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib/action_mailer/base.rb')
-rw-r--r--actionmailer/lib/action_mailer/base.rb96
1 files changed, 72 insertions, 24 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 84f5bd23a9..3b459da9bd 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -1,12 +1,8 @@
require 'active_support/core_ext/class'
-require 'action_mailer/part'
-require 'action_mailer/vendor/text_format'
-require 'action_mailer/vendor/tmail'
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
#
- #
# = Mailer Models
#
# To use Action Mailer, you need to create a mailer model.
@@ -253,7 +249,7 @@ module ActionMailer #:nodoc:
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
# +implicit_parts_order+.
class Base < AbstractController::Base
- include PartContainer, Quoting
+ include Quoting
extend AdvAttrAccessor
include AbstractController::Rendering
@@ -350,6 +346,33 @@ module ActionMailer #:nodoc:
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
+ # 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)
+ params = {:content_type => params} if String === params
+ if custom_headers = params.delete(:headers)
+ ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' <<
+ 'Please just pass in custom headers directly.', caller[0,10])
+ 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)
+ super # Run deprecation hooks
+
+ params = { :content_type => params } if String === params
+ params = { :content_disposition => "attachment",
+ :content_transfer_encoding => "base64" }.merge(params)
+
+ part(params, &block)
+ end
+
class << self
attr_writer :mailer_name
@@ -395,8 +418,7 @@ module ActionMailer #:nodoc:
# end
def receive(raw_email)
logger.info "Received mail:\n #{raw_email}" unless logger.nil?
- mail = TMail::Mail.parse(raw_email)
- mail.base64_decode
+ mail = Mail.new(raw_email)
new.receive(mail)
end
@@ -457,7 +479,7 @@ module ActionMailer #:nodoc:
create_mail
end
- # Delivers a TMail::Mail object. By default, it delivers the cached mail
+ # 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.
def deliver!(mail = @mail)
@@ -504,18 +526,18 @@ module ActionMailer #:nodoc:
super # Run deprecation hooks
if String === response_body
- @parts.unshift Part.new(
- :content_type => "text/plain",
- :disposition => "inline",
- :charset => charset,
+ @parts.unshift Mail::Part.new(
+ :content_type => ["text", "plain", {:charset => charset}],
+ :content_disposition => "inline",
:body => response_body
)
else
self.class.template_root.find_all(@template, {}, mailer_name).each do |template|
- @parts << Part.new(
- :content_type => template.mime_type ? template.mime_type.to_s : "text/plain",
- :disposition => "inline",
- :charset => charset,
+ ct = template.mime_type ? template.mime_type.to_s : "text/plain"
+ main_type, sub_type = ct.split("/")
+ @parts << Mail::Part.new(
+ :content_type => [main_type, sub_type, {:charset => charset}],
+ :content_disposition => "inline",
:body => render_to_body(:_template => template)
)
end
@@ -535,8 +557,8 @@ module ActionMailer #:nodoc:
order = order.collect { |s| s.downcase }
parts = parts.sort do |a, b|
- a_ct = a.content_type.downcase
- b_ct = b.content_type.downcase
+ a_ct = a.content_type.string.downcase
+ b_ct = b.content_type.string.downcase
a_in = order.include? a_ct
b_in = order.include? b_ct
@@ -561,7 +583,7 @@ module ActionMailer #:nodoc:
end
def create_mail
- m = TMail::Mail.new
+ m = Mail.new
m.subject, = quote_any_if_necessary(charset, subject)
m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
@@ -576,17 +598,43 @@ module ActionMailer #:nodoc:
real_content_type, ctype_attrs = parse_content_type
if @parts.empty?
- m.set_content_type(real_content_type, nil, ctype_attrs)
- m.body = normalize_new_lines(body)
+ main_type, sub_type = split_content_type(real_content_type)
+ m.content_type([main_type, sub_type, ctype_attrs])
+ m.body = body
elsif @parts.size == 1 && @parts.first.parts.empty?
- m.set_content_type(real_content_type, nil, ctype_attrs)
- m.body = normalize_new_lines(@parts.first.body)
+ main_type, sub_type = split_content_type(real_content_type)
+ m.content_type([main_type, sub_type, ctype_attrs])
+ m.body = @parts.first.body.encoded
else
- setup_multiple_parts(m, real_content_type, ctype_attrs)
+ @parts.each do |p|
+ m.add_part(p)
+ end
+
+ if real_content_type =~ /multipart/
+ ctype_attrs.delete "charset"
+ main_type, sub_type = split_content_type(real_content_type)
+ m.content_type([main_type, sub_type, ctype_attrs])
+ end
end
@mail = m
end
+
+ def split_content_type(ct)
+ ct.to_s.split("/")
+ end
+
+ def parse_content_type(defaults=nil)
+ if content_type.blank?
+ return defaults ?
+ [ defaults.content_type, { 'charset' => defaults.charset } ] :
+ [ nil, {} ]
+ end
+ ctype, *attrs = content_type.split(/;\s*/)
+ attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h }
+ [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)]
+ end
+
end
end