Skip to content

Commit

Permalink
Fixed the set of boundary.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 19, 2011
1 parent 25705af commit 1004b1a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -601,7 +601,6 @@ public function getHeaders($include = array()) {
}

if (!empty($this->_attachments)) {
$this->_createBoundary();
$headers['MIME-Version'] = '1.0';
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
$headers[] = 'This part of the E-mail should never be seen. If';
Expand Down Expand Up @@ -892,6 +891,8 @@ public function send($content = null) {
}
}

$this->_createBoundary();

$message = $this->_wrap($content);
if (empty($this->_template)) {
$message = $this->_formatMessage($message);
Expand All @@ -905,7 +906,7 @@ public function send($content = null) {
$this->_attachFiles();
}

if (!is_null($this->_boundary)) {
if (!empty($this->_attachments)) {
$this->_message[] = '';
$this->_message[] = '--' . $this->_boundary . '--';
$this->_message[] = '';
Expand Down Expand Up @@ -1147,8 +1148,10 @@ protected function _wrap($message) {
*
* @return void
*/
protected function _createboundary() {
$this->_boundary = md5(uniqid(time()));
protected function _createBoundary() {
if (!empty($this->_attachments) || $this->_emailFormat === 'both') {
$this->_boundary = md5(uniqid(time()));
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Network/Email/SmtpTransport.php
Expand Up @@ -161,6 +161,7 @@ protected function _sendData() {
$headers = $this->_cakeEmail->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
$headers = $this->_headersToString($headers);
$message = implode("\r\n", $this->_cakeEmail->message());
pr($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
$this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
}

Expand Down
48 changes: 48 additions & 0 deletions lib/Cake/tests/Case/Network/CakeEmailTest.php
Expand Up @@ -46,6 +46,15 @@ public function wrap($text) {
return parent::_wrap($text);
}

/**
* Get the boundary attribute
*
* @return string
*/
public function getBoundary() {
return $this->_boundary;
}

}

/**
Expand Down Expand Up @@ -580,6 +589,45 @@ public function testSendRenderWithVars() {
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
}

/**
* testSendMultipleMIME method
*
* @return void
*/
public function testSendMultipleMIME() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;

$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->template('custom', 'default');
$this->CakeEmail->config(array());
$this->CakeEmail->viewVars(array('value' => 12345));
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();

$message = $this->CakeEmail->message();
$boundary = $this->CakeEmail->getBoundary();
$this->assertFalse(empty($boundary));
$this->assertFalse(in_array('--' . $boundary, $message));
$this->assertFalse(in_array('--' . $boundary . '--', $message));
$this->assertTrue(in_array('--alt-' . $boundary, $message));
$this->assertTrue(in_array('--alt-' . $boundary . '--', $message));

$this->CakeEmail->attachments(array('fake.php' => __FILE__));
$this->CakeEmail->send();

$message = $this->CakeEmail->message();
$boundary = $this->CakeEmail->getBoundary();
$this->assertFalse(empty($boundary));
$this->assertTrue(in_array('--' . $boundary, $message));
$this->assertTrue(in_array('--' . $boundary . '--', $message));
$this->assertTrue(in_array('--alt-' . $boundary, $message));
$this->assertTrue(in_array('--alt-' . $boundary . '--', $message));
}

/**
* testFastSend method
*
Expand Down

0 comments on commit 1004b1a

Please sign in to comment.