2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-05-29 15:20:28 +00:00
|
|
|
* Email Component
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller.Component
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.3467
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-01-28 06:36:30 +00:00
|
|
|
|
|
|
|
App::uses('Component', 'Controller');
|
2010-12-04 18:15:07 +00:00
|
|
|
App::uses('Multibyte', 'I18n');
|
2011-04-27 02:19:17 +00:00
|
|
|
App::uses('CakeEmail', 'Network/Email');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-06-03 17:26:30 +00:00
|
|
|
* EmailComponent
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-06-03 17:26:30 +00:00
|
|
|
* This component is used for handling Internet Message Format based
|
|
|
|
* based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller.Component
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/components/email.html
|
|
|
|
* @link https://book.cakephp.org/2.0/en/core-utility-libraries/email.html
|
2014-09-02 15:03:22 +00:00
|
|
|
* @deprecated 3.0.0 Will be removed in 3.0. Use Network/CakeEmail instead
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-07-04 19:12:42 +00:00
|
|
|
class EmailComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Recipient of the email
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $to = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The mail which the email is sent from
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $from = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The email the recipient will reply to
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $replyTo = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The read receipt email
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $readReceipt = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The mail that will be used in case of any errors like
|
|
|
|
* - Remote mailserver down
|
|
|
|
* - Remote user has exceeded his quota
|
|
|
|
* - Unknown user
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $return = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Carbon Copy
|
|
|
|
*
|
|
|
|
* List of email's that should receive a copy of the email.
|
|
|
|
* The Recipient WILL be able to see this list
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cc = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Blind Carbon Copy
|
|
|
|
*
|
|
|
|
* List of email's that should receive a copy of the email.
|
|
|
|
* The Recipient WILL NOT be able to see this list
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $bcc = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-23 03:08:46 +00:00
|
|
|
/**
|
2011-12-02 05:58:09 +00:00
|
|
|
* The date to put in the Date: header. This should be a date
|
|
|
|
* conforming with the RFC2822 standard. Leave null, to have
|
2010-11-23 03:08:46 +00:00
|
|
|
* today's date generated.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-08-19 02:16:16 +00:00
|
|
|
public $date = null;
|
2010-11-23 03:08:46 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The subject of the email
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $subject = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Associative array of a user defined headers
|
2008-06-03 17:26:30 +00:00
|
|
|
* Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $headers = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* List of additional headers
|
|
|
|
*
|
|
|
|
* These will NOT be used if you are using safemode and mail()
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $additionalParams = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Layout for the View
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $layout = 'default';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Template for the view
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $template = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-26 20:41:43 +00:00
|
|
|
/**
|
|
|
|
* Line feed character(s) to be used when sending using mail() function
|
2011-01-30 23:15:12 +00:00
|
|
|
* By default PHP_EOL is used.
|
2010-11-26 20:41:43 +00:00
|
|
|
* RFC2822 requires it to be CRLF but some Unix
|
|
|
|
* mail transfer agents replace LF by CRLF automatically
|
|
|
|
* (which leads to doubling CR if CRLF is used).
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-04-17 15:21:04 +00:00
|
|
|
public $lineFeed = PHP_EOL;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* What format should the email be sent in
|
|
|
|
*
|
|
|
|
* Supported formats:
|
|
|
|
* - text
|
|
|
|
* - html
|
|
|
|
* - both
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $sendAs = 'text';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* What method should the email be sent by
|
|
|
|
*
|
|
|
|
* Supported methods:
|
|
|
|
* - mail
|
|
|
|
* - smtp
|
|
|
|
* - debug
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $delivery = 'mail';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* charset the email is sent in
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $charset = 'utf-8';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* List of files that should be attached to the email.
|
|
|
|
*
|
|
|
|
* Can be both absolute and relative paths
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $attachments = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* What mailer should EmailComponent identify itself as
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $xMailer = 'CakePHP Email Component';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2011-12-02 05:58:09 +00:00
|
|
|
* The list of paths to search if an attachment isn't absolute
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $filePaths = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* List of options to use for smtp mail method
|
|
|
|
*
|
|
|
|
* Options is:
|
|
|
|
* - port
|
|
|
|
* - host
|
|
|
|
* - timeout
|
|
|
|
* - username
|
|
|
|
* - password
|
2009-09-23 03:10:35 +00:00
|
|
|
* - client
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-06-26 16:29:20 +00:00
|
|
|
public $smtpOptions = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-12-16 20:47:12 +00:00
|
|
|
* Contains the rendered plain text message if one was sent.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2009-12-16 20:47:12 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $textMessage = null;
|
2009-12-16 20:47:12 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-16 20:52:14 +00:00
|
|
|
* Contains the rendered HTML message if one was sent.
|
2009-12-16 20:47:12 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $htmlMessage = null;
|
2009-12-16 20:47:12 +00:00
|
|
|
|
2010-01-24 22:29:53 +00:00
|
|
|
/**
|
|
|
|
* Whether to generate a Message-ID header for the
|
|
|
|
* e-mail. True to generate a Message-ID, False to let
|
|
|
|
* it be handled by sendmail (or similar) or a string
|
|
|
|
* to completely override the Message-ID.
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* If you are sending Email from a shell, be sure to set this value. As you
|
2010-11-22 17:58:51 +00:00
|
|
|
* could encounter delivery issues if you do not.
|
|
|
|
*
|
2010-01-24 22:29:53 +00:00
|
|
|
* @var mixed
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $messageId = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-04-17 21:30:21 +00:00
|
|
|
/**
|
|
|
|
* Controller reference
|
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @var Controller
|
2011-04-17 21:30:21 +00:00
|
|
|
*/
|
|
|
|
protected $_controller = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components
|
|
|
|
* @param array $settings Array of configuration settings.
|
|
|
|
*/
|
|
|
|
public function __construct(ComponentCollection $collection, $settings = array()) {
|
|
|
|
$this->_controller = $collection->getController();
|
|
|
|
parent::__construct($collection, $settings);
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-01-02 22:50:28 +00:00
|
|
|
* Initialize component
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param Controller $controller Instantiating controller
|
2011-07-29 04:06:43 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-02-23 14:06:25 +00:00
|
|
|
public function initialize(Controller $controller) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (Configure::read('App.encoding') !== null) {
|
|
|
|
$this->charset = Configure::read('App.encoding');
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Send an email using the specified content, template and layout
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string|array $content Either an array of text lines, or a string with contents
|
2010-04-28 02:50:34 +00:00
|
|
|
* If you are rendering a template this variable will be sent to the templates as `$content`
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $template Template to use when sending email
|
|
|
|
* @param string $layout Layout to use to enclose email body
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function send($content = null, $template = null, $layout = null) {
|
2011-04-17 15:02:08 +00:00
|
|
|
$lib = new CakeEmail();
|
|
|
|
$lib->charset = $this->charset;
|
2012-11-26 04:00:43 +00:00
|
|
|
$lib->headerCharset = $this->charset;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-04-17 15:02:08 +00:00
|
|
|
$lib->from($this->_formatAddresses((array)$this->from));
|
|
|
|
if (!empty($this->to)) {
|
|
|
|
$lib->to($this->_formatAddresses((array)$this->to));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-04-17 15:02:08 +00:00
|
|
|
if (!empty($this->cc)) {
|
|
|
|
$lib->cc($this->_formatAddresses((array)$this->cc));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-04-17 15:02:08 +00:00
|
|
|
if (!empty($this->bcc)) {
|
|
|
|
$lib->bcc($this->_formatAddresses((array)$this->bcc));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-04-17 15:02:08 +00:00
|
|
|
if (!empty($this->replyTo)) {
|
|
|
|
$lib->replyTo($this->_formatAddresses((array)$this->replyTo));
|
2009-12-16 20:47:12 +00:00
|
|
|
}
|
2011-04-17 15:02:08 +00:00
|
|
|
if (!empty($this->return)) {
|
|
|
|
$lib->returnPath($this->_formatAddresses((array)$this->return));
|
|
|
|
}
|
2012-09-05 19:49:09 +00:00
|
|
|
if (!empty($this->readReceipt)) {
|
2011-04-17 15:02:08 +00:00
|
|
|
$lib->readReceipt($this->_formatAddresses((array)$this->readReceipt));
|
2010-06-21 03:37:25 +00:00
|
|
|
}
|
2009-08-10 02:20:22 +00:00
|
|
|
|
2015-08-06 02:12:13 +00:00
|
|
|
$lib->subject($this->subject);
|
|
|
|
$lib->messageID($this->messageId);
|
2011-06-19 22:43:11 +00:00
|
|
|
$lib->helpers($this->_controller->helpers);
|
2011-04-17 15:02:08 +00:00
|
|
|
|
2011-04-23 02:41:52 +00:00
|
|
|
$headers = array('X-Mailer' => $this->xMailer);
|
2011-04-17 15:02:08 +00:00
|
|
|
foreach ($this->headers as $key => $value) {
|
|
|
|
$headers['X-' . $key] = $value;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-21 22:32:52 +00:00
|
|
|
if ($this->date) {
|
2011-04-17 15:02:08 +00:00
|
|
|
$headers['Date'] = $this->date;
|
|
|
|
}
|
|
|
|
$lib->setHeaders($headers);
|
2009-08-10 02:20:22 +00:00
|
|
|
|
2011-04-17 15:02:08 +00:00
|
|
|
if ($template) {
|
|
|
|
$this->template = $template;
|
|
|
|
}
|
|
|
|
if ($layout) {
|
|
|
|
$this->layout = $layout;
|
|
|
|
}
|
2011-04-21 04:00:58 +00:00
|
|
|
$lib->template($this->template, $this->layout)->viewVars($this->_controller->viewVars)->emailFormat($this->sendAs);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (!empty($this->attachments)) {
|
2011-04-17 16:02:26 +00:00
|
|
|
$lib->attachments($this->_formatAttachFiles());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 14:47:46 +00:00
|
|
|
$lib->transport(ucfirst($this->delivery));
|
2011-04-17 15:02:08 +00:00
|
|
|
if ($this->delivery === 'mail') {
|
2011-04-17 16:02:26 +00:00
|
|
|
$lib->config(array('eol' => $this->lineFeed, 'additionalParameters' => $this->additionalParams));
|
2011-04-17 15:02:08 +00:00
|
|
|
} elseif ($this->delivery === 'smtp') {
|
2011-04-17 16:02:26 +00:00
|
|
|
$lib->config($this->smtpOptions);
|
|
|
|
} else {
|
|
|
|
$lib->config(array());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2011-04-17 15:02:08 +00:00
|
|
|
$sent = $lib->send($content);
|
2008-06-09 23:35:38 +00:00
|
|
|
|
2011-04-17 21:58:33 +00:00
|
|
|
$this->htmlMessage = $lib->message(CakeEmail::MESSAGE_HTML);
|
|
|
|
if (empty($this->htmlMessage)) {
|
|
|
|
$this->htmlMessage = null;
|
|
|
|
}
|
|
|
|
$this->textMessage = $lib->message(CakeEmail::MESSAGE_TEXT);
|
|
|
|
if (empty($this->textMessage)) {
|
|
|
|
$this->textMessage = null;
|
|
|
|
}
|
|
|
|
|
2010-06-25 04:32:20 +00:00
|
|
|
$this->_header = array();
|
|
|
|
$this->_message = array();
|
2008-06-09 23:35:38 +00:00
|
|
|
|
2008-06-06 18:31:11 +00:00
|
|
|
return $sent;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Reset all EmailComponent internal variables to be able to send out a new email.
|
|
|
|
*
|
2011-07-29 04:06:43 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function reset() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->template = null;
|
2010-02-04 02:13:11 +00:00
|
|
|
$this->to = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->from = null;
|
|
|
|
$this->replyTo = null;
|
|
|
|
$this->return = null;
|
|
|
|
$this->cc = array();
|
|
|
|
$this->bcc = array();
|
|
|
|
$this->subject = null;
|
|
|
|
$this->additionalParams = null;
|
2010-11-23 03:08:46 +00:00
|
|
|
$this->date = null;
|
2009-07-10 00:07:51 +00:00
|
|
|
$this->attachments = array();
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->htmlMessage = null;
|
|
|
|
$this->textMessage = null;
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->messageId = true;
|
2012-02-02 01:24:02 +00:00
|
|
|
$this->delivery = 'mail';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2011-04-17 15:02:08 +00:00
|
|
|
* Format the attach array
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-04-17 15:02:08 +00:00
|
|
|
* @return array
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-04-17 15:02:08 +00:00
|
|
|
protected function _formatAttachFiles() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$files = array();
|
2010-04-02 19:02:23 +00:00
|
|
|
foreach ($this->attachments as $filename => $attachment) {
|
2009-03-22 04:19:20 +00:00
|
|
|
$file = $this->_findFiles($attachment);
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!empty($file)) {
|
2010-04-02 19:02:23 +00:00
|
|
|
if (is_int($filename)) {
|
|
|
|
$filename = basename($file);
|
|
|
|
}
|
|
|
|
$files[$filename] = $file;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-17 15:02:08 +00:00
|
|
|
return $files;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Find the specified attachment in the list of file paths
|
|
|
|
*
|
|
|
|
* @param string $attachment Attachment file name to find
|
2014-11-05 12:03:27 +00:00
|
|
|
* @return string|null Path to located file
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _findFiles($attachment) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (file_exists($attachment)) {
|
|
|
|
return $attachment;
|
|
|
|
}
|
|
|
|
foreach ($this->filePaths as $path) {
|
|
|
|
if (file_exists($path . DS . $attachment)) {
|
|
|
|
$file = $path . DS . $attachment;
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-04-17 15:02:08 +00:00
|
|
|
/**
|
|
|
|
* Format addresses to be an array with email as key and alias as value
|
|
|
|
*
|
2014-05-31 21:36:05 +00:00
|
|
|
* @param array $addresses Address to format.
|
2011-04-17 15:02:08 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function _formatAddresses($addresses) {
|
|
|
|
$formatted = array();
|
|
|
|
foreach ($addresses as $address) {
|
|
|
|
if (preg_match('/((.*))?\s?<(.+)>/', $address, $matches) && !empty($matches[2])) {
|
2012-04-24 01:41:08 +00:00
|
|
|
$formatted[$this->_strip($matches[3])] = $matches[2];
|
2011-04-17 15:02:08 +00:00
|
|
|
} else {
|
|
|
|
$address = $this->_strip($address);
|
|
|
|
$formatted[$address] = $address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $formatted;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-09-02 15:16:10 +00:00
|
|
|
* Remove certain elements (such as bcc:, to:, %0a) from given value.
|
2011-12-02 05:58:09 +00:00
|
|
|
* Helps prevent header injection / manipulation on user content.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $value Value to strip
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $message Set to true to indicate main message content
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Stripped value
|
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _strip($value, $message = false) {
|
2012-11-21 14:39:03 +00:00
|
|
|
$search = '%0a|%0d|Content-(?:Type|Transfer-Encoding)\:';
|
2009-07-02 02:58:43 +00:00
|
|
|
$search .= '|charset\=|mime-version\:|multipart/mixed|(?:[^a-z]to|b?cc)\:.*';
|
|
|
|
|
2008-10-01 18:36:38 +00:00
|
|
|
if ($message !== true) {
|
2008-11-11 19:54:15 +00:00
|
|
|
$search .= '|\r|\n';
|
2008-10-01 18:36:38 +00:00
|
|
|
}
|
|
|
|
$search = '#(?:' . $search . ')#i';
|
|
|
|
while (preg_match($search, $value)) {
|
|
|
|
$value = preg_replace($search, '', $value);
|
|
|
|
}
|
|
|
|
return $value;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|