Skip to content

Commit

Permalink
avoid generating invalid SMTP commands in ruby pre 1.9
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
joeyAghion authored and NZKoz committed Nov 28, 2009
1 parent bfe0328 commit da61a6c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def create_mail
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']
sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first

smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
Expand Down
34 changes: 34 additions & 0 deletions actionmailer/test/mail_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def cancelled_account(recipient)
self.body = "Goodbye, Mr. #{recipient}"
end

def from_with_name
from "System <system@loudthinking.com>"
recipients "root@loudthinking.com"
body "Nothing to see here."
end

def from_without_name
from "system@loudthinking.com"
recipients "root@loudthinking.com"
body "Nothing to see here."
end

def cc_bcc(recipient)
recipients recipient
subject "testing bcc/cc"
Expand Down Expand Up @@ -454,6 +466,28 @@ def test_cc_bcc
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end

def test_from_without_name_for_smtp
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_from_without_name

mail = MockSMTP.deliveries.first
assert_not_nil mail
mail, from, to = mail

assert_equal 'system@loudthinking.com', from.to_s
end

def test_from_with_name_for_smtp
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_from_with_name

mail = MockSMTP.deliveries.first
assert_not_nil mail
mail, from, to = mail

assert_equal 'system@loudthinking.com', from.to_s
end

def test_reply_to
expected = new_mail

Expand Down

0 comments on commit da61a6c

Please sign in to comment.