mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixed the set of boundary.
This commit is contained in:
parent
25705af8ed
commit
1004b1a168
3 changed files with 56 additions and 4 deletions
|
@ -601,7 +601,6 @@ class CakeEmail {
|
|||
}
|
||||
|
||||
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';
|
||||
|
@ -892,6 +891,8 @@ class CakeEmail {
|
|||
}
|
||||
}
|
||||
|
||||
$this->_createBoundary();
|
||||
|
||||
$message = $this->_wrap($content);
|
||||
if (empty($this->_template)) {
|
||||
$message = $this->_formatMessage($message);
|
||||
|
@ -905,7 +906,7 @@ class CakeEmail {
|
|||
$this->_attachFiles();
|
||||
}
|
||||
|
||||
if (!is_null($this->_boundary)) {
|
||||
if (!empty($this->_attachments)) {
|
||||
$this->_message[] = '';
|
||||
$this->_message[] = '--' . $this->_boundary . '--';
|
||||
$this->_message[] = '';
|
||||
|
@ -1147,8 +1148,10 @@ class CakeEmail {
|
|||
*
|
||||
* @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()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -161,6 +161,7 @@ class SmtpTransport extends AbstractTransport {
|
|||
$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.");
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,15 @@ class TestCakeEmail extends CakeEmail {
|
|||
return parent::_wrap($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the boundary attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBoundary() {
|
||||
return $this->_boundary;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -580,6 +589,45 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue