Added MailSo hooks

This commit is contained in:
RainLoop Team 2014-10-09 19:18:58 +04:00
parent cfbda969d1
commit e1d3010054
9 changed files with 79 additions and 31 deletions

View file

@ -4,7 +4,6 @@ namespace MailSo;
/** /**
* @category MailSo * @category MailSo
* @package Base
*/ */
class Config class Config
{ {

View file

@ -0,0 +1,46 @@
<?php
namespace MailSo;
/**
* @category MailSo
*/
class Hooks
{
/**
* @var array
*/
static $aCallbacks = array();
/**
* @param string $sName
* @param array $aArg
*/
static public function Run($sName, $aArg = array())
{
if (isset(\MailSo\Hooks::$aCallbacks[$sName]))
{
foreach (\MailSo\Hooks::$aCallbacks[$sName] as $mCallback)
{
\call_user_func_array($mCallback, $aArg);
}
}
}
/**
* @param string $sName
* @param mixed $mCallback
*/
static public function Add($sName, $mCallback)
{
if (\is_callable($mCallback))
{
if (!isset(\MailSo\Hooks::$aCallbacks[$sName]))
{
\MailSo\Hooks::$aCallbacks[$sName] = array();
}
\MailSo\Hooks::$aCallbacks[$sName][] = $mCallback;
}
}
}

View file

@ -147,12 +147,7 @@ class ImapClient extends \MailSo\Net\NetClient
$this->IsSupported('STARTTLS'), $this->iSecurityType)) $this->IsSupported('STARTTLS'), $this->iSecurityType))
{ {
$this->SendRequestWithCheck('STARTTLS'); $this->SendRequestWithCheck('STARTTLS');
if (!@\stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) $this->EnableCrypto();
{
$this->writeLogException(
new \MailSo\Imap\Exceptions\RuntimeException('Cannot enable STARTTLS'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$this->aCapabilityItems = null; $this->aCapabilityItems = null;
} }

View file

@ -242,14 +242,18 @@ abstract class NetClient
// $iErrorNo, $sErrorStr, $this->iConnectTimeOut); // $iErrorNo, $sErrorStr, $this->iConnectTimeOut);
$bVerifySsl = !!$bVerifySsl; $bVerifySsl = !!$bVerifySsl;
$rStreamContext = \stream_context_create(array( $aStreamContextSettings = array(
'ssl' => array( 'ssl' => array(
'verify_host' => $bVerifySsl, 'verify_host' => $bVerifySsl,
'verify_peer' => $bVerifySsl, 'verify_peer' => $bVerifySsl,
'verify_peer_name' => $bVerifySsl, 'verify_peer_name' => $bVerifySsl,
'allow_self_signed' => !$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')); \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 * @return void
*/ */

View file

@ -73,12 +73,7 @@ class Pop3Client extends \MailSo\Net\NetClient
in_array('STLS', $this->Capa()), $this->iSecurityType)) in_array('STLS', $this->Capa()), $this->iSecurityType))
{ {
$this->sendRequestWithCheck('STLS'); $this->sendRequestWithCheck('STLS');
if (!@stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) $this->EnableCrypto();
{
$this->writeLogException(
new \MailSo\Pop3\Exceptions\RuntimeException('Cannot enable STARTTLS'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$this->aCapa = null; $this->aCapa = null;
} }

View file

@ -101,12 +101,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
$this->IsSupported('STARTTLS'), $this->iSecurityType)) $this->IsSupported('STARTTLS'), $this->iSecurityType))
{ {
$this->sendRequestWithCheck('STARTTLS'); $this->sendRequestWithCheck('STARTTLS');
if (!@stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) $this->EnableCrypto();
{
$this->writeLogException(
new \MailSo\Sieve\Exceptions\RuntimeException('Cannot enable STARTTLS'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$mResponse = $this->parseResponse(); $mResponse = $this->parseResponse();
$this->validateResponse($mResponse); $this->validateResponse($mResponse);

View file

@ -528,12 +528,7 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->IsSupported('STARTTLS'), $this->iSecurityType, $this->HasSupportedAuth())) $this->IsSupported('STARTTLS'), $this->iSecurityType, $this->HasSupportedAuth()))
{ {
$this->sendRequestWithCheck('STARTTLS', 220); $this->sendRequestWithCheck('STARTTLS', 220);
if (!@\stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) $this->EnableCrypto();
{
$this->writeLogException(
new \MailSo\Smtp\Exceptions\RuntimeException('Cannot enable STARTTLS'),
\MailSo\Log\Enumerations\Type::WARNING, true);
}
$this->ehloOrHelo($sEhloHost); $this->ehloOrHelo($sEhloHost);
} }

View file

@ -101,7 +101,7 @@ class Application extends \RainLoop\Config\AbstractConfig
'Enable CSRF protection (http://en.wikipedia.org/wiki/Cross-site_request_forgery)'), 'Enable CSRF protection (http://en.wikipedia.org/wiki/Cross-site_request_forgery)'),
'custom_server_signature' => array('RainLoop'), 'custom_server_signature' => array('RainLoop'),
'x_frame_options_header' => array('SAMEORIGIN'), 'x_frame_options_header' => array(''),
'openpgp' => array(false), 'openpgp' => array(false),
'use_rsa_encryption' => array(false), 'use_rsa_encryption' => array(false),
'admin_login' => array('admin', 'Login and password for web admin panel'), 'admin_login' => array('admin', 'Login and password for web admin panel'),

View file

@ -468,7 +468,8 @@ class PdoAddressBook
else else
{ {
$sSql = 'INSERT INTO rainloop_ab_contacts '. $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)'; '(:id_user, :id_contact_str, :display, :changed, :etag)';
$this->prepareAndExecute($sSql, $this->prepareAndExecute($sSql,
@ -514,7 +515,8 @@ class PdoAddressBook
if (0 < \count($aParams)) if (0 < \count($aParams))
{ {
$sSql = 'INSERT INTO rainloop_ab_properties '. $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)'; '(:id_contact, :id_user, :prop_type, :prop_type_str, :prop_value, :prop_value_custom, :prop_frec)';
$this->prepareAndExecute($sSql, $aParams, true); $this->prepareAndExecute($sSql, $aParams, true);