فهرست منبع

[Zend_Mail] Email set in ReplyTo() is no more part of repicientlist. #ZF-7702

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18563 44c647ce-9c0f-0410-b52a-842ac1e357ba
freak 16 سال پیش
والد
کامیت
34cfcdbd9f
3فایلهای تغییر یافته به همراه72 افزوده شده و 4 حذف شده
  1. 46 3
      library/Zend/Mail.php
  2. 1 0
      tests/Zend/Acl/AclTest.php
  3. 25 1
      tests/Zend/Mail/MailTest.php

+ 46 - 3
library/Zend/Mail.php

@@ -91,6 +91,12 @@ class Zend_Mail extends Zend_Mime_Message
      */
     protected $_to = array();
 
+    /*
+     * Reply-To header
+     * @var string
+     */
+    protected $_replyTo;
+    
     /**
      * Array of all recipients
      * @var array
@@ -618,13 +624,26 @@ class Zend_Mail extends Zend_Mime_Message
      * @param string $email
      * @param string $name
      * @return Zend_Mail
+     * @throws Zend_Mail_Exception if called more than one time
      */
-    public function setReplyTo($email, $name=null)
+    public function setReplyTo($email, $name = null)
     {
-        $this->_addRecipientAndHeader('Reply-To', $email, $name);
+    	if($this->_replyTo === null) {
+    		$email = $this->_filterEmail($email);
+    		$name = $this->_filterEmail($name);
+    		$this->_replyTo = $email;
+    		$this->_storeHeader('Reply-To', $this->_formatAddress($email, $name), true);
+    	} else {
+    		/**
+    		 * @see Zend_Mail_Exception
+    		 */
+            require_once 'Zend/Mail/Exception.php';
+            throw new Zend_Mail_Exception('Reply-To Header set twice');
+        }
+
         return $this;
     }
-
+    
     /**
      * Returns the sender of the mail
      *
@@ -636,6 +655,17 @@ class Zend_Mail extends Zend_Mime_Message
     }
 
     /**
+     * Returns the current Reply-To address of the message
+     * If no Reply-To header is set, returns the value of {@link $_from}.
+     *
+     * @return string|null Reply-To address, null when not set
+     */
+    public function getReplyTo()
+    {
+        return $this->_replyTo;
+    }
+    
+    /**
      * Clears the sender from the mail
      *
      * @return Zend_Mail Provides fluent interface
@@ -648,6 +678,19 @@ class Zend_Mail extends Zend_Mime_Message
         return $this;
     }
 
+     /**
+      * Clears the current Reply-To address from the message
+      *
+      * @return Zend_Mail Provides fluent interface
+      */
+    public function clearReplyTo()
+    {
+        $this->_replyTo = null;
+        $this->_clearHeader('Reply-To');
+
+        return $this;
+    }
+
     /**
      * Sets the Return-Path header of the message
      *

+ 1 - 0
tests/Zend/Acl/AclTest.php

@@ -1273,4 +1273,5 @@ class Zend_Acl_AclTest extends PHPUnit_Framework_TestCase
 
         $this->assertTrue($allowed);
     }
+
 }

+ 25 - 1
tests/Zend/Mail/MailTest.php

@@ -757,7 +757,31 @@ class Zend_Mail_MailTest extends PHPUnit_Framework_TestCase
         $headers = $mail->getHeaders();
         $this->assertMailHeaderConformsToRfc($headers['Subject'][0]);
     }
-
+    
+    /**
+     * @group ZF-7702
+     */
+    public function testReplyToIsNoRecipient() {
+    	$mail = new Zend_Mail();
+    	$mail->setReplyTo('foo@example.com','foobar');
+    	$this->assertEquals(0, count($mail->getRecipients()));
+    }
+    
+    public function testGetReplyToReturnsReplyTo() {
+    	$mail = new Zend_Mail();
+    	$mail->setReplyTo('foo@example.com');
+    	$this->assertEquals('foo@example.com',$mail->getReplyTo());
+    }
+    
+    /**
+     * @expectedException Zend_Mail_Exception
+     */
+    public function testReplyToCantBeSetTwice() {
+        $mail = new Zend_Mail();
+        $mail->setReplyTo('user@example.com');
+        $mail->setReplyTo('user2@example.com');
+    }
+    
     public static function dataSubjects()
     {
         return array(