Skip to content
This repository
Browse code

Add ActionMailer#reply_to. [#245 state:resolved]

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

0 notes on commit cf6299d

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