Index: /library/Zend/Mail.php =================================================================== --- /library/Zend/Mail.php (revision 7111) +++ /library/Zend/Mail.php (working copy) @@ -113,6 +113,12 @@ protected $_subject = null; /** + * Date: header + * @var string + */ + protected $_date = null; + + /** * text/plain MIME part * @var false|Zend_Mime_Part */ @@ -595,6 +601,48 @@ } /** + * Sets Date-header + * + * @param string $date + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception if called subsequent times + */ + public function setDate($date) + { + if ($this->_date === null) { + if (is_int($date)) { + $date = date(DATE_RFC2822, $date); + } else if (is_string($date)) { + $date = date(DATE_RFC2822, strtotime($date)); + if (!$date) { + throw new Zend_Mail_Exception('String representations of Date Header must be ' . + 'strtotime()-compatible'); + } + } else if (is_object($date) && $date instanceof Zend_Date) { + $date = $date->get(Zend_Date::RFC_2822); + } else { + throw new Zend_Mail_Exception(__METHOD__ . ' only accepts UNIX timestamps, Zend_Date objects, ' . + ' and strtotime()-compatible strings'); + } + $this->_date = $date; + $this->_storeHeader('Date', $date, true); + } else { + throw new Zend_Mail_Exception('Date Header set twice'); + } + return $this; + } + + /** + * Returns the formatted date of the message + * + * @return string + */ + public function getDate() + { + return $this->_date; + } + + /** * Add a custom header to the message * * @param string $name @@ -605,7 +653,7 @@ */ public function addHeader($name, $value, $append = false) { - if (in_array(strtolower($name), array('to', 'cc', 'bcc', 'from', 'subject', 'return-path'))) { + if (in_array(strtolower($name), array('to', 'cc', 'bcc', 'from', 'subject', 'date', 'return-path'))) { throw new Zend_Mail_Exception('Cannot set standard header from addHeader()'); } @@ -644,6 +692,10 @@ $transport = self::$_defaultTransport; } } + + if (is_null($this->_date)) { + $this->setDate(Zend_Date::now()); + } $transport->send($this);