mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Enhancing email component to allow using alias for attachments. Closes #6
This commit is contained in:
parent
fdd8a51a07
commit
1b8165d890
2 changed files with 37 additions and 8 deletions
|
@ -556,15 +556,15 @@ class EmailComponent extends Object{
|
|||
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['Message-ID'] = $this->messageId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$headers['X-Mailer'] = $this->xMailer;
|
||||
|
||||
if (!empty($this->headers)) {
|
||||
|
@ -624,14 +624,17 @@ class EmailComponent extends Object{
|
|||
*/
|
||||
function _attachFiles() {
|
||||
$files = array();
|
||||
foreach ($this->attachments as $attachment) {
|
||||
foreach ($this->attachments as $filename => $attachment) {
|
||||
$file = $this->_findFiles($attachment);
|
||||
if (!empty($file)) {
|
||||
$files[] = $file;
|
||||
if (is_int($filename)) {
|
||||
$filename = basename($file);
|
||||
}
|
||||
$files[$filename] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
foreach ($files as $filename => $file) {
|
||||
$handle = fopen($file, 'rb');
|
||||
$data = fread($handle, filesize($file));
|
||||
$data = chunk_split(base64_encode($data)) ;
|
||||
|
@ -640,7 +643,7 @@ class EmailComponent extends Object{
|
|||
$this->__message[] = '--' . $this->__boundary;
|
||||
$this->__message[] = 'Content-Type: application/octet-stream';
|
||||
$this->__message[] = 'Content-Transfer-Encoding: base64';
|
||||
$this->__message[] = 'Content-Disposition: attachment; filename="' . basename($file) . '"';
|
||||
$this->__message[] = 'Content-Disposition: attachment; filename="' . basename($filename) . '"';
|
||||
$this->__message[] = '';
|
||||
$this->__message[] = $data;
|
||||
$this->__message[] = '';
|
||||
|
|
|
@ -779,6 +779,32 @@ HTMLBLOC;
|
|||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testSendWithAttachments() {
|
||||
$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__,
|
||||
'some-name.php' => __FILE__
|
||||
);
|
||||
$body = '<p>This is the body of the message</p>';
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="email.test.php"') . '/', $msg);
|
||||
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="some-name.php"') . '/', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSendAsIsNotIgnoredIfAttachmentsPresent method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testSendAsIsNotIgnoredIfAttachmentsPresent() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
|
@ -812,7 +838,7 @@ HTMLBLOC;
|
|||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
* testNoDoubleNewlinesInHeaders function
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
|
|
Loading…
Add table
Reference in a new issue