public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add ActionMailer#reply_to. [#245 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Adam (author)
Fri May 23 10:40:36 -0700 2008
lifo (committer)
Thu May 29 02:38:00 -0700 2008
commit  cf6299dbd73a8cb6d74265df03d01abe885e686a
tree    e54c80862aa91a2ca8fcf48d4d0775bad0bac912
parent  abb1bd2efa43b8efbb3faf4ccfb9246704a9044c
...
35
36
37
38
 
 
39
40
41
...
317
318
319
 
 
 
 
320
321
322
...
576
577
578
579
580
581
582
583
 
 
 
 
 
584
585
 
 
586
587
588
...
35
36
37
 
38
39
40
41
42
...
318
319
320
321
322
323
324
325
326
327
...
581
582
583
 
 
 
 
 
584
585
586
587
588
589
 
590
591
592
593
594
0
@@ -35,7 +35,8 @@ module ActionMailer #:nodoc:
0
   # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
0
   # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
0
   # * <tt>cc</tt> - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the <tt>Cc:</tt> header.
0
-  # * <tt>bcc</tt> - Takes one or more email address. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header.
0
+  # * <tt>bcc</tt> - Takes one or more email addresses. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header.
0
+  # * <tt>reply_to</tt> - Takes one or more email addresses. These addresses will be listed as the default recipients when replying to your email. Sets the <tt>Reply-To:</tt> header.
0
   # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent.
0
   # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
0
   # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
0
@@ -317,6 +318,10 @@ module ActionMailer #:nodoc:
0
     # Specify the from address for the message.
0
     adv_attr_accessor :from
0
 
0
+    # Specify the address (if different than the "from" address) to direct
0
+    # replies to this message.
0
+    adv_attr_accessor :reply_to
0
+
0
     # Specify additional headers to be added to the message.
0
     adv_attr_accessor :headers
0
 
0
@@ -576,13 +581,14 @@ module ActionMailer #:nodoc:
0
       def create_mail
0
         m = TMail::Mail.new
0
 
0
-        m.subject, = quote_any_if_necessary(charset, subject)
0
-        m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
0
-        m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
0
-        m.cc  = quote_address_if_necessary(cc, charset) unless cc.nil?
0
-
0
+        m.subject,     = quote_any_if_necessary(charset, subject)
0
+        m.to, m.from   = quote_any_address_if_necessary(charset, recipients, from)
0
+        m.bcc          = quote_address_if_necessary(bcc, charset) unless bcc.nil?
0
+        m.cc           = quote_address_if_necessary(cc, charset) unless cc.nil?
0
+        m.reply_to     = quote_address_if_necessary(reply_to, charset) unless reply_to.nil?
0
         m.mime_version = mime_version unless mime_version.nil?
0
-        m.date = sent_on.to_time rescue sent_on if sent_on
0
+        m.date         = sent_on.to_time rescue sent_on if sent_on
0
+
0
         headers.each { |k, v| m[k] = v }
0
 
0
         real_content_type, ctype_attrs = parse_content_type
...
40
41
42
43
 
44
45
46
...
40
41
42
 
43
44
45
46
0
@@ -40,7 +40,7 @@ module ActionMailer
0
     # regular email address, or it can be a phrase followed by an address in
0
     # brackets. The phrase is the only part that will be quoted, and only if
0
     # it needs to be. This allows extended characters to be used in the
0
-    # "to", "from", "cc", and "bcc" headers.
0
+    # "to", "from", "cc", "bcc" and "reply-to" headers.
0
     def quote_address_if_necessary(address, charset)
0
       if Array === address
0
         address.map { |a| quote_address_if_necessary(a, charset) }
...
40
41
42
 
 
 
 
 
 
 
 
 
43
44
45
...
445
446
447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
449
450
...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
0
@@ -40,6 +40,15 @@ class TestMailer < ActionMailer::Base
0
     body       "Nothing to see here."
0
   end
0
 
0
+  def different_reply_to(recipient)
0
+    recipients recipient
0
+    subject    "testing reply_to"
0
+    from       "system@loudthinking.com"
0
+    sent_on    Time.local(2008, 5, 23)
0
+    reply_to   "atraver@gmail.com"
0
+    body       "Nothing to see here."
0
+  end
0
+
0
   def iso_charset(recipient)
0
     @recipients = recipient
0
     @subject    = "testing isø charsets"
0
@@ -445,6 +454,31 @@ class ActionMailerTest < Test::Unit::TestCase
0
     assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
0
   end
0
 
0
+  def test_reply_to
0
+    expected = new_mail
0
+
0
+    expected.to       = @recipient
0
+    expected.subject  = "testing reply_to"
0
+    expected.body     = "Nothing to see here."
0
+    expected.from     = "system@loudthinking.com"
0
+    expected.reply_to = "atraver@gmail.com"
0
+    expected.date     = Time.local 2008, 5, 23
0
+
0
+    created = nil
0
+    assert_nothing_raised do
0
+      created = TestMailer.create_different_reply_to @recipient
0
+    end
0
+    assert_not_nil created
0
+    assert_equal expected.encoded, created.encoded
0
+
0
+    assert_nothing_raised do
0
+      TestMailer.deliver_different_reply_to @recipient
0
+    end
0
+
0
+    assert_not_nil ActionMailer::Base.deliveries.first
0
+    assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
0
+  end
0
+
0
   def test_iso_charset
0
     expected = new_mail( "iso-8859-1" )
0
     expected.to      = @recipient

Comments