diff options
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 40 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail_compat.rb | 14 |
3 files changed, 32 insertions, 24 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 7f31aeb7f5..d5deb96427 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -366,10 +366,27 @@ 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) + STDERR.puts("Passing custom headers with :headers => {} is deprecated. Please just pass in custom headers directly.") + params = params.merge(custom_headers) + end part = Mail::Part.new(params) - yield part - self.parts << part + 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) + params = { :content_type => params } if String === params + params = { :disposition => "attachment", + :transfer_encoding => "base64" }.merge(params) + part(params, &block) end class << self @@ -417,8 +434,7 @@ module ActionMailer #:nodoc: # end def receive(raw_email) logger.info "Received mail:\n #{raw_email}" unless logger.nil? - mail = Mail.parse(raw_email) - mail.base64_decode + mail = Mail.new(raw_email) new.receive(mail) end @@ -598,25 +614,31 @@ module ActionMailer #:nodoc: real_content_type, ctype_attrs = parse_content_type if @parts.empty? - m.set_content_type(real_content_type, nil, ctype_attrs) + main_type, sub_type = split_content_type(real_content_type) + m.content_type(main_type, sub_type, ctype_attrs) m.body = normalize_new_lines(body) elsif @parts.size == 1 && @parts.first.parts.empty? - m.set_content_type(real_content_type, nil, ctype_attrs) + main_type, sub_type = split_content_type(real_content_type) + m.content_type(main_type, sub_type, ctype_attrs) m.body = normalize_new_lines(@parts.first.body) else @parts.each do |p| - part = (Mail === p ? p : p.to_mail(self)) - m.parts << part + m.parts << p end if real_content_type =~ /multipart/ ctype_attrs.delete "charset" - m.set_content_type(real_content_type, nil, ctype_attrs) + main_type, sub_type = split_content_type(real_content_type) + m.content_type([main_type.to_s, sub_type.to_s, 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? diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 3f69b12c97..49f6d680a2 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -44,7 +44,7 @@ module ActionMailer def set_expected_mail @expected = Mail.new - @expected.set_content_type "text", "plain", { "charset" => charset } + @expected.content_type ["text", "plain", { "charset" => charset }] @expected.mime_version = '1.0' end diff --git a/actionmailer/lib/action_mailer/vendor/tmail_compat.rb b/actionmailer/lib/action_mailer/vendor/tmail_compat.rb index 988a2d3378..0e240eb478 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail_compat.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail_compat.rb @@ -2,22 +2,8 @@ # Created in 1.2 of Mail. Will be deprecated STDERR.puts("DEPRECATION WARNING, Mail running in TMail compatibility mode. This will be deprecated soon.") -module Mail - - def Mail.parse(string) - STDERR.puts("DEPRECATION WARNING, Mail.parse(string) is deprecated, please use Mail.new") - ::Mail.new(string) - end - -end - class Mail::Message - def set_content_type(*args) - STDERR.puts("DEPRECATION WARNING, Message#set_content_type is deprecated, please use Message#content_type") - content_type(args) - end - def set_content_disposition(*args) STDERR.puts("DEPRECATION WARNING, Message#set_content_disposition is deprecated, please use Message#content_disposition") content_disposition(args) |