Skip to content
This repository
Browse code

avoid generating invalid SMTP commands in ruby pre 1.9

Signed-off-by: Michael Koziarski <michael@koziarski.com>

Conflicts:

	actionmailer/lib/action_mailer/base.rb
  • Loading branch information...
commit 7e0aa35c20f06fd9ef245155e30e81cfb38bad05 1 parent 02c3c9d
Michael Koziarski authored November 28, 2009
2  actionmailer/lib/action_mailer/delivery_method/smtp.rb
@@ -16,7 +16,7 @@ class Smtp < Method
16 16
       def perform_delivery(mail)
17 17
         destinations = mail.destinations
18 18
         mail.ready_to_send
19  
-        sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']
  19
+        sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first
20 20
 
21 21
         smtp = Net::SMTP.new(settings[:address], settings[:port])
22 22
         smtp.enable_starttls_auto if settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
34  actionmailer/test/mail_service_test.rb
@@ -31,6 +31,18 @@ def cancelled_account(recipient)
31 31
     render :text => "Goodbye, Mr. #{recipient}"
32 32
   end
33 33
 
  34
+  def from_with_name
  35
+    from       "System <system@loudthinking.com>"
  36
+    recipients "root@loudthinking.com"
  37
+    body       "Nothing to see here."
  38
+  end
  39
+
  40
+  def from_without_name
  41
+    from       "system@loudthinking.com"
  42
+    recipients "root@loudthinking.com"
  43
+    body       "Nothing to see here."
  44
+  end
  45
+
34 46
   def cc_bcc(recipient)
35 47
     recipients recipient
36 48
     subject    "testing bcc/cc"
@@ -487,6 +499,28 @@ def test_cc_bcc
487 499
     assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
488 500
   end
489 501
 
  502
+  def test_from_without_name_for_smtp
  503
+    ActionMailer::Base.delivery_method = :smtp
  504
+    TestMailer.deliver_from_without_name
  505
+
  506
+    mail = MockSMTP.deliveries.first
  507
+    assert_not_nil mail
  508
+    mail, from, to = mail
  509
+
  510
+    assert_equal 'system@loudthinking.com', from.to_s
  511
+  end
  512
+
  513
+  def test_from_with_name_for_smtp
  514
+    ActionMailer::Base.delivery_method = :smtp
  515
+    TestMailer.deliver_from_with_name
  516
+
  517
+    mail = MockSMTP.deliveries.first
  518
+    assert_not_nil mail
  519
+    mail, from, to = mail
  520
+
  521
+    assert_equal 'system@loudthinking.com', from.to_s
  522
+  end
  523
+
490 524
   def test_reply_to
491 525
     expected = new_mail
492 526
 

1 note on commit 7e0aa35

Levin Alexander

thank you!

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