mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-05 15:43:53 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Abstract send email
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Network.Email
|
||||
* @since CakePHP(tm) v 2.0.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -34,7 +33,7 @@ abstract class AbstractTransport {
|
|||
/**
|
||||
* Send mail
|
||||
*
|
||||
* @params CakeEmail $email
|
||||
* @param CakeEmail $email CakeEmail instance.
|
||||
* @return array
|
||||
*/
|
||||
abstract public function send(CakeEmail $email);
|
||||
|
@ -42,12 +41,12 @@ abstract class AbstractTransport {
|
|||
/**
|
||||
* Set the config
|
||||
*
|
||||
* @param array $config
|
||||
* @param array $config Configuration options.
|
||||
* @return array Returns configs
|
||||
*/
|
||||
public function config($config = null) {
|
||||
if (is_array($config)) {
|
||||
$this->_config = $config;
|
||||
$this->_config = $config + $this->_config;
|
||||
}
|
||||
return $this->_config;
|
||||
}
|
||||
|
@ -56,7 +55,7 @@ abstract class AbstractTransport {
|
|||
* Help to convert headers in string
|
||||
*
|
||||
* @param array $headers Headers in format key => value
|
||||
* @param string $eol
|
||||
* @param string $eol End of line string.
|
||||
* @return string
|
||||
*/
|
||||
protected function _headersToString($headers, $eol = "\r\n") {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* Emulates the email sending process for testing purposes
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Network.Email
|
||||
* @since CakePHP(tm) v 2.0.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
App::uses('AbstractTransport', 'Network/Email');
|
||||
|
||||
/**
|
||||
* Debug Transport class, useful for emulate the email sending process and inspect the resulted
|
||||
|
|
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* Send mail using mail() function
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Network.Email
|
||||
* @since CakePHP(tm) v 2.0.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
App::uses('AbstractTransport', 'Network/Email');
|
||||
|
||||
/**
|
||||
* Send mail using mail() function
|
||||
|
@ -39,11 +39,20 @@ class MailTransport extends AbstractTransport {
|
|||
$headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
|
||||
$to = $headers['To'];
|
||||
unset($headers['To']);
|
||||
foreach ($headers as $key => $header) {
|
||||
$headers[$key] = str_replace(array("\r", "\n"), '', $header);
|
||||
}
|
||||
$headers = $this->_headersToString($headers, $eol);
|
||||
$subject = str_replace(array("\r", "\n"), '', $email->subject());
|
||||
$to = str_replace(array("\r", "\n"), '', $to);
|
||||
|
||||
$message = implode($eol, $email->message());
|
||||
|
||||
$params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
|
||||
$this->_mail($to, $email->subject(), $message, $headers, $params);
|
||||
$this->_mail($to, $subject, $message, $headers, $params);
|
||||
|
||||
$headers .= $eol . 'Subject: ' . $subject;
|
||||
$headers .= $eol . 'To: ' . $to;
|
||||
return array('headers' => $headers, 'message' => $message);
|
||||
}
|
||||
|
||||
|
@ -62,11 +71,15 @@ class MailTransport extends AbstractTransport {
|
|||
if (ini_get('safe_mode')) {
|
||||
//@codingStandardsIgnoreStart
|
||||
if (!@mail($to, $subject, $message, $headers)) {
|
||||
throw new SocketException(__d('cake_dev', 'Could not send email.'));
|
||||
$error = error_get_last();
|
||||
$msg = 'Could not send email: ' . (isset($error['message']) ? $error['message'] : 'unknown');
|
||||
throw new SocketException($msg);
|
||||
}
|
||||
} elseif (!@mail($to, $subject, $message, $headers, $params)) {
|
||||
$error = error_get_last();
|
||||
$msg = 'Could not send email: ' . (isset($error['message']) ? $error['message'] : 'unknown');
|
||||
//@codingStandardsIgnoreEnd
|
||||
throw new SocketException(__d('cake_dev', 'Could not send email.'));
|
||||
throw new SocketException($msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,21 +2,20 @@
|
|||
/**
|
||||
* Send mail using SMTP protocol
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Network.Email
|
||||
* @since CakePHP(tm) v 2.0.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AbstractTransport', 'Network/Email');
|
||||
App::uses('CakeSocket', 'Network');
|
||||
|
||||
/**
|
||||
|
@ -33,13 +32,6 @@ class SmtpTransport extends AbstractTransport {
|
|||
*/
|
||||
protected $_socket;
|
||||
|
||||
/**
|
||||
* CakeEmail
|
||||
*
|
||||
* @var CakeEmail
|
||||
*/
|
||||
protected $_cakeEmail;
|
||||
|
||||
/**
|
||||
* Content of email to return
|
||||
*
|
||||
|
@ -47,6 +39,42 @@ class SmtpTransport extends AbstractTransport {
|
|||
*/
|
||||
protected $_content;
|
||||
|
||||
/**
|
||||
* The response of the last sent SMTP command.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_lastResponse = array();
|
||||
|
||||
/**
|
||||
* Returns the response of the last sent SMTP command.
|
||||
*
|
||||
* A response consists of one or more lines containing a response
|
||||
* code and an optional response message text:
|
||||
* ```
|
||||
* array(
|
||||
* array(
|
||||
* 'code' => '250',
|
||||
* 'message' => 'mail.example.com'
|
||||
* ),
|
||||
* array(
|
||||
* 'code' => '250',
|
||||
* 'message' => 'PIPELINING'
|
||||
* ),
|
||||
* array(
|
||||
* 'code' => '250',
|
||||
* 'message' => '8BITMIME'
|
||||
* ),
|
||||
* // etc...
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLastResponse() {
|
||||
return $this->_lastResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send mail
|
||||
*
|
||||
|
@ -55,12 +83,10 @@ class SmtpTransport extends AbstractTransport {
|
|||
* @throws SocketException
|
||||
*/
|
||||
public function send(CakeEmail $email) {
|
||||
$this->_cakeEmail = $email;
|
||||
|
||||
$this->_connect();
|
||||
$this->_auth();
|
||||
$this->_sendRcpt();
|
||||
$this->_sendData();
|
||||
$this->_sendRcpt($email);
|
||||
$this->_sendData($email);
|
||||
$this->_disconnect();
|
||||
|
||||
return $this->_content;
|
||||
|
@ -69,19 +95,44 @@ class SmtpTransport extends AbstractTransport {
|
|||
/**
|
||||
* Set the configuration
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
* @param array $config Configuration options.
|
||||
* @return array Returns configs
|
||||
*/
|
||||
public function config($config = array()) {
|
||||
public function config($config = null) {
|
||||
if ($config === null) {
|
||||
return $this->_config;
|
||||
}
|
||||
$default = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 25,
|
||||
'timeout' => 30,
|
||||
'username' => null,
|
||||
'password' => null,
|
||||
'client' => null
|
||||
'client' => null,
|
||||
'tls' => false,
|
||||
'ssl_allow_self_signed' => false
|
||||
);
|
||||
$this->_config = $config + $default;
|
||||
$this->_config = array_merge($default, $this->_config, $config);
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and stores the reponse lines in `'code' => 'message'` format.
|
||||
*
|
||||
* @param array $responseLines Response lines to parse.
|
||||
* @return void
|
||||
*/
|
||||
protected function _bufferResponseLines(array $responseLines) {
|
||||
$response = array();
|
||||
foreach ($responseLines as $responseLine) {
|
||||
if (preg_match('/^(\d{3})(?:[ -]+(.*))?$/', $responseLine, $match)) {
|
||||
$response[] = array(
|
||||
'code' => $match[1],
|
||||
'message' => isset($match[2]) ? $match[2] : null
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->_lastResponse = array_merge($this->_lastResponse, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +158,15 @@ class SmtpTransport extends AbstractTransport {
|
|||
|
||||
try {
|
||||
$this->_smtpSend("EHLO {$host}", '250');
|
||||
if ($this->_config['tls']) {
|
||||
$this->_smtpSend("STARTTLS", '220');
|
||||
$this->_socket->enableCrypto('tls');
|
||||
$this->_smtpSend("EHLO {$host}", '250');
|
||||
}
|
||||
} catch (SocketException $e) {
|
||||
if ($this->_config['tls']) {
|
||||
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.'));
|
||||
}
|
||||
try {
|
||||
$this->_smtpSend("HELO {$host}", '250');
|
||||
} catch (SocketException $e2) {
|
||||
|
@ -124,51 +183,91 @@ class SmtpTransport extends AbstractTransport {
|
|||
*/
|
||||
protected function _auth() {
|
||||
if (isset($this->_config['username']) && isset($this->_config['password'])) {
|
||||
$authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
|
||||
if ($authRequired == '334') {
|
||||
if (!$this->_smtpSend(base64_encode($this->_config['username']), '334')) {
|
||||
$replyCode = $this->_smtpSend('AUTH LOGIN', '334|500|502|504');
|
||||
if ($replyCode == '334') {
|
||||
try {
|
||||
$this->_smtpSend(base64_encode($this->_config['username']), '334');
|
||||
} catch (SocketException $e) {
|
||||
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the username.'));
|
||||
}
|
||||
if (!$this->_smtpSend(base64_encode($this->_config['password']), '235')) {
|
||||
try {
|
||||
$this->_smtpSend(base64_encode($this->_config['password']), '235');
|
||||
} catch (SocketException $e) {
|
||||
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the password.'));
|
||||
}
|
||||
} elseif ($authRequired != '503') {
|
||||
throw new SocketException(__d('cake_dev', 'SMTP does not require authentication.'));
|
||||
} elseif ($replyCode == '504') {
|
||||
throw new SocketException(__d('cake_dev', 'SMTP authentication method not allowed, check if SMTP server requires TLS.'));
|
||||
} else {
|
||||
throw new SocketException(__d('cake_dev', 'AUTH command not recognized or not implemented, SMTP server may not require authentication.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send emails
|
||||
* Prepares the `MAIL FROM` SMTP command.
|
||||
*
|
||||
* @return void
|
||||
* @throws SocketException
|
||||
* @param string $email The email address to send with the command.
|
||||
* @return string
|
||||
*/
|
||||
protected function _sendRcpt() {
|
||||
$from = $this->_cakeEmail->from();
|
||||
$this->_smtpSend('MAIL FROM:<' . key($from) . '>');
|
||||
|
||||
$to = $this->_cakeEmail->to();
|
||||
$cc = $this->_cakeEmail->cc();
|
||||
$bcc = $this->_cakeEmail->bcc();
|
||||
$emails = array_merge(array_keys($to), array_keys($cc), array_keys($bcc));
|
||||
foreach ($emails as $email) {
|
||||
$this->_smtpSend('RCPT TO:<' . $email . '>');
|
||||
}
|
||||
protected function _prepareFromCmd($email) {
|
||||
return 'MAIL FROM:<' . $email . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Data
|
||||
* Prepares the `RCPT TO` SMTP command.
|
||||
*
|
||||
* @return void
|
||||
* @throws SocketException
|
||||
* @param string $email The email address to send with the command.
|
||||
* @return string
|
||||
*/
|
||||
protected function _sendData() {
|
||||
$this->_smtpSend('DATA', '354');
|
||||
protected function _prepareRcptCmd($email) {
|
||||
return 'RCPT TO:<' . $email . '>';
|
||||
}
|
||||
|
||||
$headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
|
||||
$headers = $this->_headersToString($headers);
|
||||
$lines = $this->_cakeEmail->message();
|
||||
/**
|
||||
* Prepares the `from` email address.
|
||||
*
|
||||
* @param CakeEmail $email CakeEmail
|
||||
* @return array
|
||||
*/
|
||||
protected function _prepareFromAddress(CakeEmail $email) {
|
||||
$from = $email->returnPath();
|
||||
if (empty($from)) {
|
||||
$from = $email->from();
|
||||
}
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the recipient email addresses.
|
||||
*
|
||||
* @param CakeEmail $email CakeEmail
|
||||
* @return array
|
||||
*/
|
||||
protected function _prepareRecipientAddresses(CakeEmail $email) {
|
||||
$to = $email->to();
|
||||
$cc = $email->cc();
|
||||
$bcc = $email->bcc();
|
||||
return array_merge(array_keys($to), array_keys($cc), array_keys($bcc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the message headers.
|
||||
*
|
||||
* @param CakeEmail $email CakeEmail
|
||||
* @return array
|
||||
*/
|
||||
protected function _prepareMessageHeaders(CakeEmail $email) {
|
||||
return $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'to', 'cc', 'subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the message body.
|
||||
*
|
||||
* @param CakeEmail $email CakeEmail
|
||||
* @return string
|
||||
*/
|
||||
protected function _prepareMessage(CakeEmail $email) {
|
||||
$lines = $email->message();
|
||||
$messages = array();
|
||||
foreach ($lines as $line) {
|
||||
if ((!empty($line)) && ($line[0] === '.')) {
|
||||
|
@ -177,7 +276,39 @@ class SmtpTransport extends AbstractTransport {
|
|||
$messages[] = $line;
|
||||
}
|
||||
}
|
||||
$message = implode("\r\n", $messages);
|
||||
return implode("\r\n", $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send emails
|
||||
*
|
||||
* @param CakeEmail $email CakeEmail
|
||||
* @return void
|
||||
* @throws SocketException
|
||||
*/
|
||||
protected function _sendRcpt(CakeEmail $email) {
|
||||
$from = $this->_prepareFromAddress($email);
|
||||
$this->_smtpSend($this->_prepareFromCmd(key($from)));
|
||||
|
||||
$emails = $this->_prepareRecipientAddresses($email);
|
||||
foreach ($emails as $email) {
|
||||
$this->_smtpSend($this->_prepareRcptCmd($email));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Data
|
||||
*
|
||||
* @param CakeEmail $email CakeEmail
|
||||
* @return void
|
||||
* @throws SocketException
|
||||
*/
|
||||
protected function _sendData(CakeEmail $email) {
|
||||
$this->_smtpSend('DATA', '354');
|
||||
|
||||
$headers = $this->_headersToString($this->_prepareMessageHeaders($email));
|
||||
$message = $this->_prepareMessage($email);
|
||||
|
||||
$this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
|
||||
$this->_content = array('headers' => $headers, 'message' => $message);
|
||||
}
|
||||
|
@ -206,13 +337,15 @@ class SmtpTransport extends AbstractTransport {
|
|||
/**
|
||||
* Protected method for sending data to SMTP connection
|
||||
*
|
||||
* @param string $data data to be sent to SMTP server
|
||||
* @param string|boolean $checkCode code to check for in server response, false to skip
|
||||
* @return void
|
||||
* @param string|null $data Data to be sent to SMTP server
|
||||
* @param string|bool $checkCode Code to check for in server response, false to skip
|
||||
* @return string|null The matched code, or null if nothing matched
|
||||
* @throws SocketException
|
||||
*/
|
||||
protected function _smtpSend($data, $checkCode = '250') {
|
||||
if (!is_null($data)) {
|
||||
$this->_lastResponse = array();
|
||||
|
||||
if ($data !== null) {
|
||||
$this->_socket->write($data . "\r\n");
|
||||
}
|
||||
while ($checkCode !== false) {
|
||||
|
@ -227,6 +360,8 @@ class SmtpTransport extends AbstractTransport {
|
|||
$responseLines = explode("\r\n", rtrim($response, "\r\n"));
|
||||
$response = end($responseLines);
|
||||
|
||||
$this->_bufferResponseLines($responseLines);
|
||||
|
||||
if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) {
|
||||
if ($code[2] === '-') {
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue