Mail method accepting all headers set via the hash

This commit is contained in:
José Valim and Mikel Lindsaar
2010-01-21 00:10:22 +11:00
parent c34cfcc29f
commit d3da87ce77
2 changed files with 31 additions and 7 deletions

View File

@@ -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 @@ module ActionMailer #:nodoc:
include ActionMailer::DeliveryMethods
private_class_method :new #:nodoc:
@@raise_delivery_errors = true
@@ -355,6 +355,9 @@ module ActionMailer #:nodoc:
# 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 @@ module ActionMailer #:nodoc:
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 File

@@ -11,7 +11,7 @@ require 'abstract_unit'
# 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 @@ require 'abstract_unit'
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 @@ class BaseTest < Test::Unit::TestCase
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