Skip to content
Browse files

Updating the from address for ar_mailer to use the return-path if it'…

…s present
  • Loading branch information...
1 parent 13397da commit 70971281ce31c0c41f538d60c8e72be3fbc8f96b Dustin Tinney committed with Nov 11, 2009
Showing with 13 additions and 1 deletion.
  1. +2 −1 lib/action_mailer/ar_mailer.rb
  2. +11 −0 test/test_armailer.rb
View
3 lib/action_mailer/ar_mailer.rb
@@ -23,8 +23,9 @@ def self.email_class
# used.
def perform_delivery_activerecord(mail)
+ sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']
mail.destinations.each do |destination|
- self.class.email_class.create :mail => mail.encoded, :to => destination, :from => mail.from.first
+ self.class.email_class.create :mail => mail.encoded, :to => destination, :from => sender
end
end
View
11 test/test_armailer.rb
@@ -7,6 +7,7 @@ def mail
@mail = Object.new
def @mail.encoded() 'email' end
def @mail.from() ['nobody@example.com'] end
+ def @mail.[](key) {'return-path' => $return_path, 'from' => 'nobody@example.com'}[key] end
def @mail.destinations() %w[user1@example.com user2@example.com] end
end
@@ -15,6 +16,7 @@ def @mail.destinations() %w[user1@example.com user2@example.com] end
class TestARMailer < Test::Unit::TestCase
def setup
+ $return_path = nil
Mailer.email_class = Email
Email.records.clear
@@ -28,6 +30,15 @@ def test_self_email_class_equals
assert_equal 2, Newsletter.records.length
end
+
+ def test_perform_delivery_activerecord_when_return_path_is_present
+ $return_path = stub(:spec => 'return-path@example.com')
+ Mailer.deliver_mail
+
+ assert_equal 2, Email.records.length
+ record = Email.records.first
+ assert_equal 'return-path@example.com', record.from
+ end
def test_perform_delivery_activerecord
Mailer.deliver_mail

2 comments on commit 7097128

@myobie
myobie commented on 7097128 Jan 18, 2010

I am pretty sure this commit is messing up my emails being sent.

In my from column I am seeing the YAML representation of a SMTP Headers class with a From class in it. If I revert back to mail.from.first then it works as expected.

Anyone else seeing this? I am using rails 2.3.4

@adzap
Owner
adzap commented on 7097128 Jan 18, 2010

You are right, this is a bug. It should be mail.from.first rather than mail['from'], which is just the TMail header. Missed that when I pulled it in. Wonder why the other fork hasn't seen issues.

Will fix and push an update.

Please sign in to comment.
Something went wrong with that request. Please try again.