Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing issue where Date header would be missing from Emails sent by

EmailComponent.
Adding user configurable field for date.
Test cases added.  Fixes #1304
  • Loading branch information...
commit d5fb0b25cb521d3b65e10d5265571ccd941b29ac 1 parent d9484c1
@markstory markstory authored
View
16 cake/libs/controller/components/email.php
@@ -98,6 +98,15 @@ class EmailComponent extends Object{
var $bcc = array();
/**
+ * The date to put in the Date: header. This should be a date
+ * conformant with the RFC2822 standard. Leave null, to have
+ * today's date generated.
+ *
+ * @var string
+ */
+ var $date = null;
+
+/**
* The subject of the email
*
* @var string
@@ -410,6 +419,7 @@ function reset() {
$this->bcc = array();
$this->subject = null;
$this->additionalParams = null;
+ $this->date = null;
$this->smtpError = null;
$this->attachments = array();
$this->htmlMessage = null;
@@ -574,6 +584,12 @@ function _createHeader() {
}
}
+ $date = $this->date;
+ if ($date == false) {
+ $date = date(DATE_RFC2822);
+ }
+ $headers['Date'] = $date;
+
$headers['X-Mailer'] = $this->xMailer;
if (!empty($this->headers)) {
View
25 cake/tests/cases/libs/controller/components/email.test.php
@@ -493,6 +493,7 @@ function testSendFormats() {
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
+ $date = date(DATE_RFC2822);
$message = <<<MSGBLOC
<pre>To: postmaster@localhost
From: noreply@example.com
@@ -501,6 +502,7 @@ function testSendFormats() {
From: noreply@example.com
Reply-To: noreply@example.com
+Date: $date
X-Mailer: CakePHP Email Component
Content-Type: {CONTENTTYPE}
Content-Transfer-Encoding: 7bitParameters:
@@ -544,6 +546,7 @@ function testTemplates() {
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
+ $date = date(DATE_RFC2822);
$header = <<<HEADBLOC
To: postmaster@localhost
From: noreply@example.com
@@ -552,6 +555,7 @@ function testTemplates() {
From: noreply@example.com
Reply-To: noreply@example.com
+Date: $date
X-Mailer: CakePHP Email Component
Content-Type: {CONTENTTYPE}
Content-Transfer-Encoding: 7bitParameters:
@@ -689,6 +693,7 @@ function testSendDebug() {
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
+ $this->assertPattern('/Date: ' . date(DATE_RFC2822) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
@@ -716,6 +721,7 @@ function testSendDebugWithNoSessions() {
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
+ $this->assertPattern('/Date: ' . date(DATE_RFC2822) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
@@ -849,7 +855,24 @@ function testSendContentArray() {
$this->assertPattern('/First line\n/', $result);
$this->assertPattern('/Second line\n/', $result);
$this->assertPattern('/Third line\n/', $result);
+ }
+
+/**
+ * test setting a custom date.
+ *
+ * @return void
+ */
+ function testDateProperty() {
+ $this->Controller->EmailTest->to = 'postmaster@localhost';
+ $this->Controller->EmailTest->from = 'noreply@example.com';
+ $this->Controller->EmailTest->subject = 'Cake Debug Test';
+ $this->Controller->EmailTest->date = 'Today!';
+ $this->Controller->EmailTest->template = null;
+ $this->Controller->EmailTest->delivery = 'debug';
+ $this->assertTrue($this->Controller->EmailTest->send('test message'));
+ $result = $this->Controller->Session->read('Message.email.message');
+ $this->assertPattern('/Date: Today!\n/', $result);
}
/**
@@ -1043,6 +1066,7 @@ function testReset() {
$this->Controller->EmailTest->return = 'test.return@example.com';
$this->Controller->EmailTest->cc = array('cc1@example.com', 'cc2@example.com');
$this->Controller->EmailTest->bcc = array('bcc1@example.com', 'bcc2@example.com');
+ $this->Controller->EmailTest->date = 'Today!';
$this->Controller->EmailTest->subject = 'Test subject';
$this->Controller->EmailTest->additionalParams = 'X-additional-header';
$this->Controller->EmailTest->delivery = 'smtp';
@@ -1064,6 +1088,7 @@ function testReset() {
$this->assertNull($this->Controller->EmailTest->return);
$this->assertIdentical($this->Controller->EmailTest->cc, array());
$this->assertIdentical($this->Controller->EmailTest->bcc, array());
+ $this->assertNull($this->Controller->EmailTest->date);
$this->assertNull($this->Controller->EmailTest->subject);
$this->assertNull($this->Controller->EmailTest->additionalParams);
$this->assertIdentical($this->Controller->EmailTest->getHeaders(), array());
Please sign in to comment.
Something went wrong with that request. Please try again.