Skip to content

Commit

Permalink
Changed to addresses come before others headers. It is not a RFC rule…
Browse files Browse the repository at this point in the history
…, just to keep more readable the header.
  • Loading branch information
jrbasso committed Apr 13, 2011
1 parent ace4258 commit 89b4cb7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
37 changes: 19 additions & 18 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -528,24 +528,7 @@ public function getHeaders($include = array()) {
);
$include += $defaults;

$headers = $this->_headers;
if (!isset($headers['X-Mailer'])) {
$headers['X-Mailer'] = Configure::read('Email.XMailer');
if (empty($headers['X-Mailer'])) {
$headers['X-Mailer'] = self::EMAIL_CLIENT;
}
}
if (!isset($headers['Date'])) {
$headers['Date'] = date(DATE_RFC2822);
}
if ($this->_messageId !== false) {
if ($this->_messageId === true) {
$headers['Message-ID'] = '<' . String::UUID() . '@' . env('HTTP_HOST') . '>';
} else {
$headers['Message-ID'] = $this->_messageId;
}
}

$headers = array();
$relation = array(
'from' => 'From',
'replyTo' => 'Reply-To',
Expand All @@ -566,6 +549,24 @@ public function getHeaders($include = array()) {
}
}

$headers += $this->_headers;
if (!isset($headers['X-Mailer'])) {
$headers['X-Mailer'] = Configure::read('Email.XMailer');
if (empty($headers['X-Mailer'])) {
$headers['X-Mailer'] = self::EMAIL_CLIENT;
}
}
if (!isset($headers['Date'])) {
$headers['Date'] = date(DATE_RFC2822);
}
if ($this->_messageId !== false) {
if ($this->_messageId === true) {
$headers['Message-ID'] = '<' . String::UUID() . '@' . env('HTTP_HOST') . '>';
} else {
$headers['Message-ID'] = $this->_messageId;
}
}

if ($include['subject']) {
$headers['Subject'] = $this->_subject;
}
Expand Down
17 changes: 15 additions & 2 deletions lib/Cake/tests/Case/Network/CakeEmailTest.php
Expand Up @@ -240,15 +240,28 @@ public function testHeaders() {
$this->CakeEmail->setFrom('cake@cakephp.org');
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);

$expected['From'] = 'cake@cakephp.org';
$expected = array(
'From' => 'cake@cakephp.org',
'X-Something' => 'very nice',
'X-Other' => 'cool',
'X-Mailer' => 'CakePHP Email Component',
'Date' => date(DATE_RFC2822)
);
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);

$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
$expected['From'] = 'CakePHP <cake@cakephp.org>';
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);

$this->CakeEmail->setTo(array('cake@cakephp.org', 'php@cakephp.org' => 'CakePHP'));
$expected['To'] = 'cake@cakephp.org, CakePHP <php@cakephp.org>';
$expected = array(
'From' => 'CakePHP <cake@cakephp.org>',
'To' => 'cake@cakephp.org, CakePHP <php@cakephp.org>',
'X-Something' => 'very nice',
'X-Other' => 'cool',
'X-Mailer' => 'CakePHP Email Component',
'Date' => date(DATE_RFC2822)
);
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected);
}

Expand Down

0 comments on commit 89b4cb7

Please sign in to comment.