From e1d3010054fc0824dfd3f0a346799ab9588274fd Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Thu, 9 Oct 2014 19:18:58 +0400 Subject: [PATCH] Added MailSo hooks --- .../v/0.0.0/app/libraries/MailSo/Config.php | 1 - .../v/0.0.0/app/libraries/MailSo/Hooks.php | 46 +++++++++++++++++++ .../app/libraries/MailSo/Imap/ImapClient.php | 7 +-- .../app/libraries/MailSo/Net/NetClient.php | 25 +++++++++- .../app/libraries/MailSo/Pop3/Pop3Client.php | 7 +-- .../MailSo/Sieve/ManageSieveClient.php | 7 +-- .../app/libraries/MailSo/Smtp/SmtpClient.php | 9 +--- .../libraries/RainLoop/Config/Application.php | 2 +- .../Providers/AddressBook/PdoAddressBook.php | 6 ++- 9 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 rainloop/v/0.0.0/app/libraries/MailSo/Hooks.php diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Config.php b/rainloop/v/0.0.0/app/libraries/MailSo/Config.php index f522c2da4..30771fc48 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Config.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Config.php @@ -4,7 +4,6 @@ namespace MailSo; /** * @category MailSo - * @package Base */ class Config { diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Hooks.php b/rainloop/v/0.0.0/app/libraries/MailSo/Hooks.php new file mode 100644 index 000000000..55c6f2601 --- /dev/null +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Hooks.php @@ -0,0 +1,46 @@ +IsSupported('STARTTLS'), $this->iSecurityType)) { $this->SendRequestWithCheck('STARTTLS'); - if (!@\stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) - { - $this->writeLogException( - new \MailSo\Imap\Exceptions\RuntimeException('Cannot enable STARTTLS'), - \MailSo\Log\Enumerations\Type::ERROR, true); - } + $this->EnableCrypto(); $this->aCapabilityItems = null; } diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index 8822fce10..00999226d 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -242,14 +242,18 @@ abstract class NetClient // $iErrorNo, $sErrorStr, $this->iConnectTimeOut); $bVerifySsl = !!$bVerifySsl; - $rStreamContext = \stream_context_create(array( + $aStreamContextSettings = array( 'ssl' => array( 'verify_host' => $bVerifySsl, 'verify_peer' => $bVerifySsl, 'verify_peer_name' => $bVerifySsl, 'allow_self_signed' => !$bVerifySsl ) - )); + ); + + \MailSo\Hooks::Run('Net.NetClient.StreamContextSettings/Filter', array(&$aStreamContextSettings)); + + $rStreamContext = \stream_context_create($aStreamContextSettings); \set_error_handler(array(&$this, 'capturePhpErrorWithException')); @@ -287,6 +291,23 @@ abstract class NetClient } } + /** + * @param {int} $iCryptoType = STREAM_CRYPTO_METHOD_TLS_CLIENT + */ + public function EnableCrypto($iCryptoType = STREAM_CRYPTO_METHOD_TLS_CLIENT) + { + if (\is_resource($this->rConnect) && + \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_socket_enable_crypto')) + { + if (!@\stream_socket_enable_crypto($this->rConnect, true, $iCryptoType)) + { + $this->writeLogException( + new \MailSo\Net\Exceptions\Exception('Cannot enable STARTTLS. [type='.$iCryptoType.']'), + \MailSo\Log\Enumerations\Type::ERROR, true); + } + } + } + /** * @return void */ diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Pop3/Pop3Client.php b/rainloop/v/0.0.0/app/libraries/MailSo/Pop3/Pop3Client.php index d1bb7835f..ec1611b55 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Pop3/Pop3Client.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Pop3/Pop3Client.php @@ -73,12 +73,7 @@ class Pop3Client extends \MailSo\Net\NetClient in_array('STLS', $this->Capa()), $this->iSecurityType)) { $this->sendRequestWithCheck('STLS'); - if (!@stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) - { - $this->writeLogException( - new \MailSo\Pop3\Exceptions\RuntimeException('Cannot enable STARTTLS'), - \MailSo\Log\Enumerations\Type::ERROR, true); - } + $this->EnableCrypto(); $this->aCapa = null; } diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php index 431c22853..5ce8d81bb 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php @@ -101,12 +101,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient $this->IsSupported('STARTTLS'), $this->iSecurityType)) { $this->sendRequestWithCheck('STARTTLS'); - if (!@stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) - { - $this->writeLogException( - new \MailSo\Sieve\Exceptions\RuntimeException('Cannot enable STARTTLS'), - \MailSo\Log\Enumerations\Type::ERROR, true); - } + $this->EnableCrypto(); $mResponse = $this->parseResponse(); $this->validateResponse($mResponse); diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php index f66a8eb7a..91da2c606 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php @@ -528,13 +528,8 @@ class SmtpClient extends \MailSo\Net\NetClient $this->IsSupported('STARTTLS'), $this->iSecurityType, $this->HasSupportedAuth())) { $this->sendRequestWithCheck('STARTTLS', 220); - if (!@\stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) - { - $this->writeLogException( - new \MailSo\Smtp\Exceptions\RuntimeException('Cannot enable STARTTLS'), - \MailSo\Log\Enumerations\Type::WARNING, true); - } - + $this->EnableCrypto(); + $this->ehloOrHelo($sEhloHost); } else if (\MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS === $this->iSecurityType) diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php index e4d77dbdd..fdca65dac 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -101,7 +101,7 @@ class Application extends \RainLoop\Config\AbstractConfig 'Enable CSRF protection (http://en.wikipedia.org/wiki/Cross-site_request_forgery)'), 'custom_server_signature' => array('RainLoop'), - 'x_frame_options_header' => array('SAMEORIGIN'), + 'x_frame_options_header' => array(''), 'openpgp' => array(false), 'use_rsa_encryption' => array(false), 'admin_login' => array('admin', 'Login and password for web admin panel'), diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php index 6c0469283..b234af3cd 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php @@ -468,7 +468,8 @@ class PdoAddressBook else { $sSql = 'INSERT INTO rainloop_ab_contacts '. - '( id_user, id_contact_str, display, changed, etag) VALUES '. + '( id_user, id_contact_str, display, changed, etag)'. + ' VALUES '. '(:id_user, :id_contact_str, :display, :changed, :etag)'; $this->prepareAndExecute($sSql, @@ -514,7 +515,8 @@ class PdoAddressBook if (0 < \count($aParams)) { $sSql = 'INSERT INTO rainloop_ab_properties '. - '( id_contact, id_user, prop_type, prop_type_str, prop_value, prop_value_custom, prop_frec) VALUES '. + '( id_contact, id_user, prop_type, prop_type_str, prop_value, prop_value_custom, prop_frec)'. + ' VALUES '. '(:id_contact, :id_user, :prop_type, :prop_type_str, :prop_value, :prop_value_custom, :prop_frec)'; $this->prepareAndExecute($sSql, $aParams, true);