Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mail method accepting all headers set via the hash

  • Loading branch information...
commit d3da87ce771845f99bbdc04d6d6587b22655b063 1 parent c34cfcc
@mikel mikel authored
View
6 actionmailer/lib/action_mailer/base.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/class'
+require "active_support/core_ext/module/delegation"
require 'mail'
require 'action_mailer/tmail_compat'
@@ -267,7 +268,6 @@ class Base < AbstractController::Base
include ActionMailer::DeliveryMethods
-
private_class_method :new #:nodoc:
@@raise_delivery_errors = true
@@ -355,6 +355,9 @@ class Base < AbstractController::Base
# Expose the internal Mail message
attr_reader :message
+ # Pass calls to headers and attachment to the Mail#Message instance
+ delegate :headers, :attachments, :to => :@message
+
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
@@ -478,7 +481,6 @@ def mail(headers = {})
m.cc = quote_address_if_necessary(headers[:cc], m.charset) if headers[:cc]
m.bcc = quote_address_if_necessary(headers[:bcc], m.charset) if headers[:bcc]
m.reply_to = quote_address_if_necessary(headers[:reply_to], m.charset) if headers[:reply_to]
- m.mime_version = headers[:mime_version] if headers[:mime_version]
m.date = headers[:date] if headers[:date]
m.body.set_sort_order(headers[:parts_order] || @@default_implicit_parts_order)
View
32 actionmailer/test/base_test.rb
@@ -11,7 +11,7 @@
# end
#
# def goodbye(user)
-# headers["Reply-To"] = 'cancelations@example.com'
+# headers["X-SPAM"] = 'Not-SPAM'
# mail(:subject => 'Goodbye', :to => user.email_address) do |format|
# format.html { render "shared_template "}
# format.text # goodbye.text.erb
@@ -40,11 +40,14 @@
class BaseTest < Test::Unit::TestCase
class TestMailer < ActionMailer::Base
+
def welcome(hash = {})
+ headers['X-SPAM'] = "Not SPAM"
hash = {:to => 'mikel@test.lindsaar.net', :from => 'jose@test.plataformatec.com',
:subject => 'The first email on new API!'}.merge!(hash)
mail(hash)
end
+
end
def test_the_method_call_to_mail_does_not_raise_error
@@ -57,12 +60,31 @@ def test_should_set_the_headers_of_the_mail_message
assert_equal(email.from, ['jose@test.plataformatec.com'])
assert_equal(email.subject, 'The first email on new API!')
end
-
- def test_calling_mail_should_pass_the_header_hash_to_the_new_mail_object
-
+
+ def test_should_allow_all_headers_set
+ @time = Time.now
+ email = TestMailer.deliver_welcome(:bcc => 'bcc@test.lindsaar.net',
+ :cc => 'cc@test.lindsaar.net',
+ :content_type => 'multipart/mixed',
+ :charset => 'iso-8559-1',
+ :mime_version => '2.0',
+ :reply_to => 'reply-to@test.lindsaar.net',
+ :date => @time)
+ assert_equal(email.bcc, ['bcc@test.lindsaar.net'])
+ assert_equal(email.cc, ['cc@test.lindsaar.net'])
+ assert_equal(email.content_type, 'multipart/mixed')
+ assert_equal(email.charset, 'iso-8559-1')
+ assert_equal(email.mime_version, '2.0')
+ assert_equal(email.reply_to, ['reply-to@test.lindsaar.net'])
+ assert_equal(email.date, @time)
end
- def test_it_should_guard_against_old_api_if_mail_method_called
+# def test_should_allow_custom_headers_to_be_set
+# email = TestMailer.deliver_welcome
+# assert_equal("Not SPAM", email['X-SPAM'])
+# end
+
+ def test_should_use_class_defaults
end
Please sign in to comment.
Something went wrong with that request. Please try again.