From 7e0aa35c20f06fd9ef245155e30e81cfb38bad05 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 28 Nov 2009 13:34:05 +1300 Subject: [PATCH] avoid generating invalid SMTP commands in ruby pre 1.9 Signed-off-by: Michael Koziarski Conflicts: actionmailer/lib/action_mailer/base.rb --- .../lib/action_mailer/delivery_method/smtp.rb | 2 +- actionmailer/test/mail_service_test.rb | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb index 86b0ae83294ba..95c117c9e0570 100644 --- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -16,7 +16,7 @@ class Smtp < Method def perform_delivery(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(settings[:address], settings[:port]) smtp.enable_starttls_auto if settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index c98f0a7601c57..697265b8ec7f8 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -31,6 +31,18 @@ def cancelled_account(recipient) render :text => "Goodbye, Mr. #{recipient}" end + def from_with_name + from "System " + 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" @@ -487,6 +499,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