--- tests/Zend/Mail/MailTest.php (revision 23226) +++ tests/Zend/Mail/MailTest.php (working copy) @@ -992,6 +992,22 @@ } } + /** + * @group ZF-10367 + */ + public function testClearHeader() + { + $mail = new Zend_Mail(); + + $mail->addHeader('foo', 'bar'); + $headers = $mail->getHeaders(); + $this->assertTrue(isset($headers['foo'])); + + $mail->clearHeader('foo'); + $headers = $mail->getHeaders(); + $this->assertFalse(isset($headers['foo'])); + } + public static function dataSubjects() { return array( Index: library/Zend/Mail.php =================================================================== --- library/Zend/Mail.php (revision 23226) +++ library/Zend/Mail.php (working copy) @@ -538,12 +538,11 @@ * Clear header from the message * * @param string $headerName + * @deprecated use public method directly */ protected function _clearHeader($headerName) { - if (isset($this->_headers[$headerName])){ - unset($this->_headers[$headerName]); - } + $this->clearHeader($headerName); } /** @@ -633,6 +632,20 @@ } /** + * Clear header from the message + * + * @param string $headerName + * @return Zend_Mail Provides fluent inter + */ + public function clearHeader($headerName) + { + if (isset($this->_headers[$headerName])){ + unset($this->_headers[$headerName]); + } + return $this; + } + + /** * Clears list of recipient email addresses * * @return Zend_Mail Provides fluent interface @@ -642,9 +655,9 @@ $this->_recipients = array(); $this->_to = array(); - $this->_clearHeader('To'); - $this->_clearHeader('Cc'); - $this->_clearHeader('Bcc'); + $this->clearHeader('To'); + $this->clearHeader('Cc'); + $this->clearHeader('Bcc'); return $this; } @@ -729,7 +742,7 @@ public function clearFrom() { $this->_from = null; - $this->_clearHeader('From'); + $this->clearHeader('From'); return $this; } @@ -742,7 +755,7 @@ public function clearReplyTo() { $this->_replyTo = null; - $this->_clearHeader('Reply-To'); + $this->clearHeader('Reply-To'); return $this; } @@ -894,7 +907,7 @@ public function clearReturnPath() { $this->_returnPath = null; - $this->_clearHeader('Return-Path'); + $this->clearHeader('Return-Path'); return $this; } @@ -940,7 +953,7 @@ public function clearSubject() { $this->_subject = null; - $this->_clearHeader('Subject'); + $this->clearHeader('Subject'); return $this; } @@ -1010,7 +1023,7 @@ public function clearDate() { $this->_date = null; - $this->_clearHeader('Date'); + $this->clearHeader('Date'); return $this; } @@ -1068,7 +1081,7 @@ public function clearMessageId() { $this->_messageId = null; - $this->_clearHeader('Message-Id'); + $this->clearHeader('Message-Id'); return $this; }