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:
DarkAngelBGE 2009-07-21 21:54:05 +00:00
parent fefbe77208
commit caeac73562
2 changed files with 46 additions and 6 deletions

View file

@ -504,12 +504,16 @@ class EmailComponent extends Object{
*/ */
function __formatMessage($message) { function __formatMessage($message) {
if (!empty($this->attachments)) { if (!empty($this->attachments)) {
$prefix = array( $prefix[] = '--' . $this->__boundary;
'--' . $this->__boundary, if ($this->sendAs === 'text') {
'Content-Type: text/plain; charset=' . $this->charset, $prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
'Content-Transfer-Encoding: 7bit', } 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); $message = array_merge($prefix, $message);
} }
return $message; return $message;

View file

@ -556,6 +556,42 @@ TEXTBLOC;
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches); preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
$this->assertEqual(trim($matches[1]), $subject); $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 * testReset method
* *