mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Applying patch from ' matsinet', fixes #6475, EmailComponent ignoring sendAs when attachments present, adding tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8242 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
fefbe77208
commit
caeac73562
2 changed files with 46 additions and 6 deletions
|
@ -504,12 +504,16 @@ class EmailComponent extends Object{
|
|||
*/
|
||||
function __formatMessage($message) {
|
||||
if (!empty($this->attachments)) {
|
||||
$prefix = array(
|
||||
'--' . $this->__boundary,
|
||||
'Content-Type: text/plain; charset=' . $this->charset,
|
||||
'Content-Transfer-Encoding: 7bit',
|
||||
''
|
||||
);
|
||||
$prefix[] = '--' . $this->__boundary;
|
||||
if ($this->sendAs === 'text') {
|
||||
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||
} elseif ($this->sendAs === 'html') {
|
||||
$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||
} elseif ($this->sendAs === 'both') {
|
||||
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
|
||||
}
|
||||
$prefix[] = 'Content-Transfer-Encoding: 7bit';
|
||||
$prefix[] = '';
|
||||
$message = array_merge($prefix, $message);
|
||||
}
|
||||
return $message;
|
||||
|
|
|
@ -556,6 +556,42 @@ TEXTBLOC;
|
|||
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
||||
$this->assertEqual(trim($matches[1]), $subject);
|
||||
}
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testSendAsIsNotIgnoredIfAttachmentsPresent() {
|
||||
$this->Controller->EmailTest->reset();
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Attachment Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->attachments = array(__FILE__);
|
||||
$body = '<p>This is the body of the message</p>';
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$this->assertNoPattern('/text\/plain/', $msg);
|
||||
$this->assertPattern('/text\/html/', $msg);
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$this->assertPattern('/text\/plain/', $msg);
|
||||
$this->assertNoPattern('/text\/html/', $msg);
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'both';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$this->assertNoPattern('/text\/plain/', $msg);
|
||||
$this->assertNoPattern('/text\/html/', $msg);
|
||||
$this->assertPattern('/multipart\/alternative/', $msg);
|
||||
}
|
||||
/**
|
||||
* testReset method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue