Skip to content
Permalink
Browse files

Added support for Message-ID headers.

  • Loading branch information...
Phally committed Jan 24, 2010
1 parent 2e46504 commit 3c265283e7a6f9422d2aab1a4112646fe0eb7060
@@ -255,6 +255,17 @@ class EmailComponent extends Object{
*/
var $htmlMessage = null;
/**
* Whether to generate a Message-ID header for the
* e-mail. True to generate a Message-ID, False to let
* it be handled by sendmail (or similar) or a string
* to completely override the Message-ID.
*
* @var mixed
* @access public
*/
var $messageId = true;
/**
* Temporary store of message header lines
*
@@ -394,6 +405,7 @@ function reset() {
$this->attachments = array();
$this->htmlMessage = null;
$this->textMessage = null;
$this->messageId = true;
$this->__header = array();
$this->__boundary = null;
$this->__message = array();
@@ -540,6 +552,15 @@ function _createHeader() {
if ($this->delivery == 'smtp') {
$headers['Subject'] = $this->_encode($this->subject);
}
if ($this->messageId !== false) {
if ($this->messageId === true) {
$headers['Message-ID'] = '<' . String::UUID() . '@' . env('HTTP_HOST') . '>';
} else {
$headers['Message-ID'] = $this->messageId;
}
}
$headers['X-Mailer'] = $this->xMailer;
if (!empty($this->headers)) {
@@ -334,6 +334,7 @@ function testSendFormats() {
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
$message = <<<MSGBLOC
<pre>To: postmaster@localhost
@@ -384,6 +385,7 @@ function testTemplates() {
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
$header = <<<HEADBLOC
To: postmaster@localhost
@@ -803,6 +805,7 @@ function testReset() {
$this->Controller->EmailTest->attachments = array('attachment1', 'attachment2');
$this->Controller->EmailTest->textMessage = 'This is the body of the message';
$this->Controller->EmailTest->htmlMessage = 'This is the body of the message';
$this->Controller->EmailTest->messageId = false;
$this->assertFalse($this->Controller->EmailTest->send('Should not work'));
@@ -823,6 +826,7 @@ function testReset() {
$this->assertNull($this->Controller->EmailTest->smtpError);
$this->assertIdentical($this->Controller->EmailTest->attachments, array());
$this->assertNull($this->Controller->EmailTest->textMessage);
$this->assertTrue($this->Controller->EmailTest->messageId);
}
function testPluginCustomViewClass() {
@@ -856,5 +860,39 @@ function testStartup() {
$this->assertNull($this->Controller->EmailTest->startup($this->Controller));
}
/**
* testMessageId method
*
* @access public
* @return void
*/
function testMessageId() {
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'debug';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = $this->Controller->Session->read('Message.email.message');
$this->assertPattern('/Message-ID: \<[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}@' . env('HTTP_HOST') . '\>\n/', $result);
$this->Controller->EmailTest->messageId = '<22091985.998877@localhost>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = $this->Controller->Session->read('Message.email.message');
$this->assertPattern('/Message-ID: <22091985.998877@localhost>\n/', $result);
$this->Controller->EmailTest->messageId = false;
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = $this->Controller->Session->read('Message.email.message');
$this->assertNoPattern('/Message-ID:/', $result);
}
}
?>

0 comments on commit 3c26528

Please sign in to comment.
You can’t perform that action at this time.