Code refactoring

This commit is contained in:
RainLoop Team 2014-11-12 20:46:05 +04:00
parent 78ce33e77c
commit 2545ce3cd9
17 changed files with 946 additions and 1034 deletions

View file

@ -2,457 +2,5 @@
namespace RainLoop;
class Account
{
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sLogin;
/**
* @var int
*/
private $sPassword;
/**
* @var string
*/
private $sProxyAuthUser;
/**
* @var string
*/
private $sProxyAuthPassword;
/**
* @var string
*/
private $sSignMeToken;
/**
* @var \RainLoop\Domain
*/
private $oDomain;
/**
* @var string
*/
private $sParentEmail;
/**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
* @param \RainLoop\Domain $oDomain
* @param string $sSignMeToken = ''
* @param string $sProxyAuthUser = ''
* @param string $sProxyAuthPassword = ''
*
* @return void
*/
protected function __construct($sEmail, $sLogin, $sPassword, \RainLoop\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '')
{
$this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
$this->sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
$this->sPassword = $sPassword;
$this->oDomain = $oDomain;
$this->sSignMeToken = $sSignMeToken;
$this->sProxyAuthUser = $sProxyAuthUser;
$this->sProxyAuthPassword = $sProxyAuthPassword;
}
/**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
* @param \RainLoop\Domain $oDomain
* @param string $sSignMeToken = ''
* @param string $sProxyAuthUser = ''
* @param string $sProxyAuthPassword = ''
*
* @return \RainLoop\Account
*/
public static function NewInstance($sEmail, $sLogin, $sPassword, \RainLoop\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '')
{
return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken, $sProxyAuthUser, $sProxyAuthPassword);
}
/**
* @return string
*/
public function Email()
{
return $this->sEmail;
}
/**
* @return string
*/
public function ParentEmail()
{
return $this->sParentEmail;
}
/**
* @return string
*/
public function ProxyAuthUser()
{
return $this->sProxyAuthUser;
}
/**
* @return string
*/
public function ProxyAuthPassword()
{
return $this->sProxyAuthPassword;
}
/**
* @return string
*/
public function ParentEmailHelper()
{
return 0 < \strlen($this->sParentEmail) ? $this->sParentEmail : $this->sEmail;
}
/**
* @return string
*/
public function IncLogin()
{
$sLogin = $this->sLogin;
if ($this->oDomain->IncShortLogin())
{
$sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($this->sLogin);
}
return $sLogin;
}
/**
* @return string
*/
public function IncPassword()
{
return $this->sPassword;
}
/**
* @return string
*/
public function OutLogin()
{
$sLogin = $this->sLogin;
if ($this->oDomain->OutShortLogin())
{
$sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($this->sLogin);
}
return $sLogin;
}
/**
* @return string
*/
public function Login()
{
return $this->IncLogin();
}
/**
* @return string
*/
public function Password()
{
return $this->IncPassword();
}
/**
* @return bool
*/
public function SignMe()
{
return 0 < \strlen($this->sSignMeToken);
}
/**
* @return string
*/
public function SignMeToken()
{
return $this->sSignMeToken;
}
/**
* @return \RainLoop\Domain
*/
public function Domain()
{
return $this->oDomain;
}
/**
* @return \RainLoop\Domain
*/
public function Hash()
{
return md5(APP_SALT.$this->Email().APP_SALT.$this->DomainIncHost().
APP_SALT.$this->DomainIncPort().APP_SALT.$this->Password().APP_SALT.'0'.APP_SALT.$this->ParentEmail().APP_SALT);
}
/**
* @param string $sPassword
*
* @return void
*/
public function SetPassword($sPassword)
{
$this->sPassword = $sPassword;
}
/**
* @param string $sParentEmail
*
* @return void
*/
public function SetParentEmail($sParentEmail)
{
$this->sParentEmail = \MailSo\Base\Utils::IdnToAscii($sParentEmail, true);
}
/**
* @param string $sProxyAuthUser
*
* @return void
*/
public function SetProxyAuthUser($sProxyAuthUser)
{
return $this->sProxyAuthUser = $sProxyAuthUser;
}
/**
* @param string $sProxyAuthPassword
*
* @return void
*/
public function SetProxyAuthPassword($sProxyAuthPassword)
{
return $this->sProxyAuthPassword = $sProxyAuthPassword;
}
/**
* @return string
*/
public function DomainIncHost()
{
return $this->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($this->Email()));
}
/**
* @return int
*/
public function DomainIncPort()
{
return $this->Domain()->IncPort();
}
/**
* @return int
*/
public function DomainIncSecure()
{
return $this->Domain()->IncSecure();
}
/**
* @param bool|null $bGlobalVerify = null
*
* @return bool
*/
public function DomainIncVerifySsl($bGlobalVerify = null)
{
return $this->Domain()->IncVerifySsl($bGlobalVerify);
}
/**
* @return string
*/
public function DomainOutHost()
{
return $this->Domain()->OutHost(\MailSo\Base\Utils::GetDomainFromEmail($this->Email()));
}
/**
* @return int
*/
public function DomainOutPort()
{
return $this->Domain()->OutPort();
}
/**
* @return int
*/
public function DomainOutSecure()
{
return $this->Domain()->OutSecure();
}
/**
* @return bool
*/
public function DomainOutAuth()
{
return $this->Domain()->OutAuth();
}
/**
* @param bool|null $bGlobalVerify = null
*
* @return bool
*/
public function DomainOutVerifySsl($bGlobalVerify = null)
{
return $this->Domain()->OutVerifySsl($bGlobalVerify);
}
/**
* @return string
*/
public function GetAuthToken()
{
return \RainLoop\Utils::EncodeKeyValues(array(
'token', // 0
$this->sEmail, // 1
$this->sLogin, // 2
$this->sPassword, // 3
\RainLoop\Utils::Fingerprint(), // 4
$this->sSignMeToken, // 5
$this->sParentEmail, // 6
\RainLoop\Utils::GetShortToken(), // 7
$this->sProxyAuthUser, // 8
$this->sProxyAuthPassword, // 9
0 // 10
));
}
/**
* @param \RainLoop\Plugins\Manager $oPlugins
* @param \MailSo\Mail\MailClient $oMailClient
* @param \RainLoop\Application $oConfig
*
* @return bool
*/
public function IncConnectAndLoginHelper($oPlugins, $oMailClient, $oConfig)
{
$bLogin = false;
$aImapCredentials = array(
'UseConnect' => true,
'UseAuth' => true,
'Host' => $this->DomainIncHost(),
'Port' => $this->DomainIncPort(),
'Secure' => $this->DomainIncSecure(),
'Login' => $this->IncLogin(),
'Password' => $this->Password(),
'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => $this->DomainIncVerifySsl(!!$oConfig->Get('ssl', 'verify_certificate')),
'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'use_imap_auth_plain')
);
$oPlugins->RunHook('filter.imap-credentials', array($this, &$aImapCredentials));
$oPlugins->RunHook('event.imap-pre-connect', array($this, $aImapCredentials['UseConnect'], $aImapCredentials));
if ($aImapCredentials['UseConnect'])
{
$oMailClient
->Connect($aImapCredentials['Host'], $aImapCredentials['Port'],
$aImapCredentials['Secure'], $aImapCredentials['VerifySsl']);
}
$oPlugins->RunHook('event.imap-pre-login', array($this, $aImapCredentials['UseAuth'], $aImapCredentials));
if ($aImapCredentials['UseAuth'])
{
if (0 < \strlen($aImapCredentials['ProxyAuthUser']) &&
0 < \strlen($aImapCredentials['ProxyAuthPassword']))
{
$oMailClient
->Login($aImapCredentials['ProxyAuthUser'], $aImapCredentials['ProxyAuthPassword'],
$aImapCredentials['Login'], $aImapCredentials['UseAuthPlainIfSupported']);
}
else
{
$oMailClient->Login($aImapCredentials['Login'], $aImapCredentials['Password'], '',
$aImapCredentials['UseAuthPlainIfSupported']);
}
$bLogin = true;
}
$oPlugins->RunHook('event.imap-post-login', array($this, $aImapCredentials['UseAuth'], $bLogin, $aImapCredentials));
return $bLogin;
}
/**
* @param \RainLoop\Plugins\Manager $oPlugins
* @param \MailSo\Smtp\SmtpClient $oSmtpClient
* @param \RainLoop\Application $oConfig
*
* @return bool
*/
public function OutConnectAndLoginHelper($oPlugins, $oSmtpClient, $oConfig)
{
$bLogin = false;
$aSmtpCredentials = array(
'UseConnect' => true,
'UseAuth' => $this->DomainOutAuth(),
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(),
'Host' => $this->DomainOutHost(),
'Port' => $this->DomainOutPort(),
'Secure' => $this->DomainOutSecure(),
'Login' => $this->OutLogin(),
'Password' => $this->Password(),
'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => $this->DomainOutVerifySsl(!!$oConfig->Get('ssl', 'verify_certificate'))
);
$oPlugins->RunHook('filter.smtp-credentials', array($this, &$aSmtpCredentials));
$oPlugins->RunHook('event.smtp-pre-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
if ($aSmtpCredentials['UseConnect'])
{
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'],
$aSmtpCredentials['Ehlo'], $aSmtpCredentials['Secure'], $aSmtpCredentials['VerifySsl']);
}
$oPlugins->RunHook('event.smtp-post-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
$oPlugins->RunHook('event.smtp-pre-login', array($this, $aSmtpCredentials['UseAuth'], $aSmtpCredentials));
if ($aSmtpCredentials['UseAuth'])
{
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
$bLogin = true;
}
$oPlugins->RunHook('event.smtp-post-login', array($this, $aSmtpCredentials['UseAuth'], $bLogin, $aSmtpCredentials));
return $bLogin;
}
}
// for backward compatibility
class Account extends \RainLoop\Model\Account {}

View file

@ -869,7 +869,7 @@ class Actions
if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword))
{
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true);
if ($oDomain instanceof \RainLoop\Domain)
if ($oDomain instanceof \RainLoop\Model\Domain)
{
if ($oDomain->ValidateWhiteList($sEmail, $sLogin))
{
@ -1529,7 +1529,7 @@ class Actions
$sLine = \trim(\implode('.', $aDomainParts), '. ');
$oDomain = $oDomainProvider->Load($sLine);
if ($oDomain && $oDomain instanceof \RainLoop\Domain)
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
{
$bAdded = true;
$this->Logger()->Write('Check "'.$sLine.'": OK ('.$sEmail.' > '.$sEmail.'@'.$sLine.')',
@ -2950,7 +2950,7 @@ class Actions
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this);
return $this->DefaultResponse(__FUNCTION__,
$oDomain instanceof \RainLoop\Domain ? $this->DomainProvider()->Save($oDomain) : false);
$oDomain instanceof \RainLoop\Model\Domain ? $this->DomainProvider()->Save($oDomain) : false);
}
/**
@ -2977,8 +2977,8 @@ class Actions
$oImapClient->SetTimeOuts(5);
$iTime = \microtime(true);
$oImapClient->Connect($oDomain->IncHost($oDomain->Name()), $oDomain->IncPort(),
$oDomain->IncSecure(), $oDomain->IncVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate')));
$oImapClient->Connect($oDomain->IncHost(), $oDomain->IncPort(),
$oDomain->IncSecure(), !!$this->Config()->Get('ssl', 'verify_certificate'));
$iImapTime = \microtime(true) - $iTime;
$oImapClient->Disconnect();
@ -3005,8 +3005,8 @@ class Actions
$oSmtpClient->SetTimeOuts(5);
$iTime = \microtime(true);
$oSmtpClient->Connect($oDomain->OutHost($oDomain->Name()), $oDomain->OutPort(), '127.0.0.1',
$oDomain->OutSecure(), $oDomain->OutVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate')));
$oSmtpClient->Connect($oDomain->OutHost(), $oDomain->OutPort(), '127.0.0.1',
$oDomain->OutSecure(), !!$this->Config()->Get('ssl', 'verify_certificate'));
$iSmtpTime = \microtime(true) - $iTime;
$oSmtpClient->Disconnect();
@ -3422,11 +3422,10 @@ class Actions
{
$this->Logger()->Write('Versions GC: Begin');
$iLimitToDelete = 3;
$sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/';
$aDirs = @\array_map('basename', @\array_filter(@\glob($sVPath.'*'), 'is_dir'));
$this->Logger()->Write('Versions GC: Count:'.(\is_array($aDirs) ? \count($aDirs) : 0));
if (\is_array($aDirs) && 5 < \count($aDirs))
{
\uasort($aDirs, 'version_compare');
@ -3439,12 +3438,7 @@ class Actions
@\MailSo\Base\Utils::RecRmDir($sVPath.$sName);
$this->Logger()->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version');
$iLimitToDelete--;
if (0 > $iLimitToDelete)
{
break;
}
break;
}
}
}

View file

@ -0,0 +1,438 @@
<?php
namespace RainLoop\Model;
class Account
{
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sLogin;
/**
* @var int
*/
private $sPassword;
/**
* @var string
*/
private $sProxyAuthUser;
/**
* @var string
*/
private $sProxyAuthPassword;
/**
* @var string
*/
private $sSignMeToken;
/**
* @var \RainLoop\Model\Domain
*/
private $oDomain;
/**
* @var string
*/
private $sParentEmail;
/**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
* @param \RainLoop\Model\Domain $oDomain
* @param string $sSignMeToken = ''
* @param string $sProxyAuthUser = ''
* @param string $sProxyAuthPassword = ''
*
* @return void
*/
protected function __construct($sEmail, $sLogin, $sPassword, \RainLoop\Model\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '')
{
$this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
$this->sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
$this->sPassword = $sPassword;
$this->oDomain = $oDomain;
$this->sSignMeToken = $sSignMeToken;
$this->sProxyAuthUser = $sProxyAuthUser;
$this->sProxyAuthPassword = $sProxyAuthPassword;
}
/**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
* @param \RainLoop\Model\Domain $oDomain
* @param string $sSignMeToken = ''
* @param string $sProxyAuthUser = ''
* @param string $sProxyAuthPassword = ''
*
* @return \RainLoop\Model\Account
*/
public static function NewInstance($sEmail, $sLogin, $sPassword, \RainLoop\Model\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '')
{
return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken, $sProxyAuthUser, $sProxyAuthPassword);
}
/**
* @return string
*/
public function Email()
{
return $this->sEmail;
}
/**
* @return string
*/
public function ParentEmail()
{
return $this->sParentEmail;
}
/**
* @return string
*/
public function ProxyAuthUser()
{
return $this->sProxyAuthUser;
}
/**
* @return string
*/
public function ProxyAuthPassword()
{
return $this->sProxyAuthPassword;
}
/**
* @return string
*/
public function ParentEmailHelper()
{
return 0 < \strlen($this->sParentEmail) ? $this->sParentEmail : $this->sEmail;
}
/**
* @return string
*/
public function IncLogin()
{
$sLogin = $this->sLogin;
if ($this->oDomain->IncShortLogin())
{
$sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($this->sLogin);
}
return $sLogin;
}
/**
* @return string
*/
public function IncPassword()
{
return $this->sPassword;
}
/**
* @return string
*/
public function OutLogin()
{
$sLogin = $this->sLogin;
if ($this->oDomain->OutShortLogin())
{
$sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($this->sLogin);
}
return $sLogin;
}
/**
* @return string
*/
public function Login()
{
return $this->IncLogin();
}
/**
* @return string
*/
public function Password()
{
return $this->IncPassword();
}
/**
* @return bool
*/
public function SignMe()
{
return 0 < \strlen($this->sSignMeToken);
}
/**
* @return string
*/
public function SignMeToken()
{
return $this->sSignMeToken;
}
/**
* @return \RainLoop\Model\Domain
*/
public function Domain()
{
return $this->oDomain;
}
/**
* @return string
*/
public function Hash()
{
return md5(APP_SALT.$this->Email().APP_SALT.$this->DomainIncHost().
APP_SALT.$this->DomainIncPort().APP_SALT.$this->Password().APP_SALT.'0'.APP_SALT.$this->ParentEmail().APP_SALT);
}
/**
* @param string $sPassword
*
* @return void
*/
public function SetPassword($sPassword)
{
$this->sPassword = $sPassword;
}
/**
* @param string $sParentEmail
*
* @return void
*/
public function SetParentEmail($sParentEmail)
{
$this->sParentEmail = \MailSo\Base\Utils::IdnToAscii($sParentEmail, true);
}
/**
* @param string $sProxyAuthUser
*
* @return void
*/
public function SetProxyAuthUser($sProxyAuthUser)
{
return $this->sProxyAuthUser = $sProxyAuthUser;
}
/**
* @param string $sProxyAuthPassword
*
* @return void
*/
public function SetProxyAuthPassword($sProxyAuthPassword)
{
return $this->sProxyAuthPassword = $sProxyAuthPassword;
}
/**
* @return string
*/
public function DomainIncHost()
{
return $this->Domain()->IncHost();
}
/**
* @return int
*/
public function DomainIncPort()
{
return $this->Domain()->IncPort();
}
/**
* @return int
*/
public function DomainIncSecure()
{
return $this->Domain()->IncSecure();
}
/**
* @return string
*/
public function DomainOutHost()
{
return $this->Domain()->OutHost();
}
/**
* @return int
*/
public function DomainOutPort()
{
return $this->Domain()->OutPort();
}
/**
* @return int
*/
public function DomainOutSecure()
{
return $this->Domain()->OutSecure();
}
/**
* @return bool
*/
public function DomainOutAuth()
{
return $this->Domain()->OutAuth();
}
/**
* @return string
*/
public function GetAuthToken()
{
return \RainLoop\Utils::EncodeKeyValues(array(
'token', // 0
$this->sEmail, // 1
$this->sLogin, // 2
$this->sPassword, // 3
\RainLoop\Utils::Fingerprint(), // 4
$this->sSignMeToken, // 5
$this->sParentEmail, // 6
\RainLoop\Utils::GetShortToken(), // 7
$this->sProxyAuthUser, // 8
$this->sProxyAuthPassword, // 9
0 // 10
));
}
/**
* @param \RainLoop\Plugins\Manager $oPlugins
* @param \MailSo\Mail\MailClient $oMailClient
* @param \RainLoop\Application $oConfig
*
* @return bool
*/
public function IncConnectAndLoginHelper($oPlugins, $oMailClient, $oConfig)
{
$bLogin = false;
$aImapCredentials = array(
'UseConnect' => true,
'UseAuth' => true,
'Host' => $this->DomainIncHost(),
'Port' => $this->DomainIncPort(),
'Secure' => $this->DomainIncSecure(),
'Login' => $this->IncLogin(),
'Password' => $this->Password(),
'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate'),
'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'use_imap_auth_plain')
);
$oPlugins->RunHook('filter.imap-credentials', array($this, &$aImapCredentials));
$oPlugins->RunHook('event.imap-pre-connect', array($this, $aImapCredentials['UseConnect'], $aImapCredentials));
if ($aImapCredentials['UseConnect'])
{
$oMailClient
->Connect($aImapCredentials['Host'], $aImapCredentials['Port'],
$aImapCredentials['Secure'], $aImapCredentials['VerifySsl']);
}
$oPlugins->RunHook('event.imap-pre-login', array($this, $aImapCredentials['UseAuth'], $aImapCredentials));
if ($aImapCredentials['UseAuth'])
{
if (0 < \strlen($aImapCredentials['ProxyAuthUser']) &&
0 < \strlen($aImapCredentials['ProxyAuthPassword']))
{
$oMailClient
->Login($aImapCredentials['ProxyAuthUser'], $aImapCredentials['ProxyAuthPassword'],
$aImapCredentials['Login'], $aImapCredentials['UseAuthPlainIfSupported']);
}
else
{
$oMailClient->Login($aImapCredentials['Login'], $aImapCredentials['Password'], '',
$aImapCredentials['UseAuthPlainIfSupported']);
}
$bLogin = true;
}
$oPlugins->RunHook('event.imap-post-login', array($this, $aImapCredentials['UseAuth'], $bLogin, $aImapCredentials));
return $bLogin;
}
/**
* @param \RainLoop\Plugins\Manager $oPlugins
* @param \MailSo\Smtp\SmtpClient $oSmtpClient
* @param \RainLoop\Application $oConfig
*
* @return bool
*/
public function OutConnectAndLoginHelper($oPlugins, $oSmtpClient, $oConfig)
{
$bLogin = false;
$aSmtpCredentials = array(
'UseConnect' => true,
'UseAuth' => $this->DomainOutAuth(),
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(),
'Host' => $this->DomainOutHost(),
'Port' => $this->DomainOutPort(),
'Secure' => $this->DomainOutSecure(),
'Login' => $this->OutLogin(),
'Password' => $this->Password(),
'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate')
);
$oPlugins->RunHook('filter.smtp-credentials', array($this, &$aSmtpCredentials));
$oPlugins->RunHook('event.smtp-pre-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
if ($aSmtpCredentials['UseConnect'])
{
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'],
$aSmtpCredentials['Ehlo'], $aSmtpCredentials['Secure'], $aSmtpCredentials['VerifySsl']);
}
$oPlugins->RunHook('event.smtp-post-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
$oPlugins->RunHook('event.smtp-pre-login', array($this, $aSmtpCredentials['UseAuth'], $aSmtpCredentials));
if ($aSmtpCredentials['UseAuth'])
{
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
$bLogin = true;
}
$oPlugins->RunHook('event.smtp-post-login', array($this, $aSmtpCredentials['UseAuth'], $bLogin, $aSmtpCredentials));
return $bLogin;
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace RainLoop;
namespace RainLoop\Model;
use MailSo\Net\Enumerations\ConnectionSecurityType;
@ -28,11 +28,6 @@ class Domain
*/
private $iIncSecure;
/**
* @var bool
*/
private $bIncVerifySsl;
/**
* @var bool
*/
@ -53,11 +48,6 @@ class Domain
*/
private $iOutSecure;
/**
* @var bool
*/
private $bOutVerifySsl;
/**
* @var bool
*/
@ -78,29 +68,25 @@ class Domain
* @param string $sIncHost
* @param int $iIncPort
* @param int $iIncSecure
* @param bool $bIncVerifySsl
* @param bool $bIncShortLogin
* @param string $sOutHost
* @param int $iOutPort
* @param int $iOutSecure
* @param bool $bOutVerifySsl
* @param bool $bOutShortLogin
* @param bool $bOutAuth
* @param string $sWhiteList = ''
*/
private function __construct($sName, $sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth, $sWhiteList = '')
private function __construct($sName, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $sWhiteList = '')
{
$this->sName = $sName;
$this->sIncHost = $sIncHost;
$this->iIncPort = $iIncPort;
$this->iIncSecure = $iIncSecure;
$this->bIncVerifySsl = !!$bIncVerifySsl;
$this->bIncShortLogin = $bIncShortLogin;
$this->sOutHost = $sOutHost;
$this->iOutPort = $iOutPort;
$this->iOutSecure = $iOutSecure;
$this->bOutVerifySsl = !!$bOutVerifySsl;
$this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth;
$this->sWhiteList = \trim($sWhiteList);
@ -111,26 +97,24 @@ class Domain
* @param string $sIncHost
* @param int $iIncPort
* @param int $iIncSecure
* @param bool $bIncVerifySsl
* @param bool $bIncShortLogin
* @param string $sOutHost
* @param int $iOutPort
* @param int $iOutSecure
* @param bool $bOutVerifySsl
* @param bool $bOutShortLogin
* @param bool $bOutAuth
* @param string $sWhiteList = ''
*
* @return \RainLoop\Domain
* @return \RainLoop\Model\Domain
*/
public static function NewInstance($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList = '')
{
return new self($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList);
}
@ -138,7 +122,7 @@ class Domain
* @param string $sName
* @param array $aDomain
*
* @return \RainLoop\Domain|null
* @return \RainLoop\Model\Domain|null
*/
public static function NewInstanceFromDomainConfigArray($sName, $aDomain)
{
@ -152,15 +136,11 @@ class Domain
$iIncSecure = self::StrConnectionSecurityTypeToCons(
!empty($aDomain['imap_secure']) ? $aDomain['imap_secure'] : '');
$bIncVerifySsl = isset($aDomain['imap_verify_ssl']) ? (bool) $aDomain['smtp_verify_ssl'] : false;;
$sOutHost = (string) $aDomain['smtp_host'];
$iOutPort = (int) $aDomain['smtp_port'];
$iOutSecure = self::StrConnectionSecurityTypeToCons(
!empty($aDomain['smtp_secure']) ? $aDomain['smtp_secure'] : '');
$bOutVerifySsl = isset($aDomain['smtp_verify_ssl']) ? (bool) $aDomain['smtp_verify_ssl'] : false;
$bOutAuth = isset($aDomain['smtp_auth']) ? (bool) $aDomain['smtp_auth'] : true;
$sWhiteList = (string) (isset($aDomain['white_list']) ? $aDomain['white_list'] : '');
@ -168,8 +148,8 @@ class Domain
$bOutShortLogin = isset($aDomain['smtp_short_login']) ? (bool) $aDomain['smtp_short_login'] : false;
$oDomain = self::NewInstance($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList);
}
@ -213,12 +193,10 @@ class Domain
'imap_host = "'.$this->encodeIniString($this->sIncHost).'"',
'imap_port = '.$this->iIncPort,
'imap_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iIncSecure).'"',
'imap_verify_ssl = '.($this->bIncVerifySsl ? 'On' : 'Off'),
'imap_short_login = '.($this->bIncShortLogin ? 'On' : 'Off'),
'smtp_host = "'.$this->encodeIniString($this->sOutHost).'"',
'smtp_port = '.$this->iOutPort,
'smtp_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iOutSecure).'"',
'smtp_verify_ssl = '.($this->bOutVerifySsl ? 'On' : 'Off'),
'smtp_short_login = '.($this->bOutShortLogin ? 'On' : 'Off'),
'smtp_auth = '.($this->bOutAuth ? 'On' : 'Off'),
'white_list = "'.$this->encodeIniString($this->sWhiteList).'"'
@ -270,32 +248,28 @@ class Domain
* @param string $sIncHost
* @param int $iIncPort
* @param int $iIncSecure
* @param bool $bIncVerifySsl
* @param bool $bIncShortLogin
* @param string $sOutHost
* @param int $iOutPort
* @param int $iOutSecure
* @param bool $bOutVerifySsl
* @param bool $bOutShortLogin
* @param bool $bOutAuth
* @param string $sWhiteList = ''
*
* @return \RainLoop\Domain
* @return \RainLoop\Model\Domain
*/
public function UpdateInstance(
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList = '')
{
$this->sIncHost = \MailSo\Base\Utils::IdnToAscii($sIncHost);
$this->iIncPort = $iIncPort;
$this->iIncSecure = $iIncSecure;
$this->bIncVerifySsl = !!$bIncVerifySsl;
$this->bIncShortLogin = $bIncShortLogin;
$this->sOutHost = \MailSo\Base\Utils::IdnToAscii($sOutHost);
$this->iOutPort = $iOutPort;
$this->iOutSecure = $iOutSecure;
$this->bOutVerifySsl = !!$bOutVerifySsl;
$this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth;
$this->sWhiteList = \trim($sWhiteList);
@ -312,13 +286,11 @@ class Domain
}
/**
* @param string $sRealDomainName = ''
*
* @return string
*/
public function IncHost($sRealDomainName = '')
public function IncHost()
{
return 0 < \strlen($sRealDomainName) ? \str_replace('{domain:name}', $sRealDomainName, $this->sIncHost) : $this->sIncHost;
return $this->sIncHost;
}
/**
@ -337,16 +309,6 @@ class Domain
return $this->iIncSecure;
}
/**
* @param bool|null $bGlobalVerify = null
*
* @return bool
*/
public function IncVerifySsl($bGlobalVerify = null)
{
return null === $bGlobalVerify ? $this->bIncVerifySsl : !!$bGlobalVerify;
}
/**
* @return bool
*/
@ -356,12 +318,11 @@ class Domain
}
/**
* @param string $sRealDomainName = ''
* @return string
*/
public function OutHost($sRealDomainName = '')
public function OutHost()
{
return 0 < \strlen($sRealDomainName) ? \str_replace('{domain:name}', $sRealDomainName, $this->sOutHost) : $this->sOutHost;
return $this->sOutHost;
}
/**
@ -450,12 +411,10 @@ class Domain
'IncHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->IncHost()) : $this->IncHost(),
'IncPort' => $this->IncPort(),
'IncSecure' => $this->IncSecure(),
'IncVerifySsl' => $this->IncVerifySsl(),
'IncShortLogin' => $this->IncShortLogin(),
'OutHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->OutHost()) : $this->OutHost(),
'OutPort' => $this->OutPort(),
'OutSecure' => $this->OutSecure(),
'OutVerifySsl' => $this->OutVerifySsl(),
'OutShortLogin' => $this->OutShortLogin(),
'OutAuth' => $this->OutAuth(),
'WhiteList' => $this->WhiteList()

View file

@ -1,6 +1,6 @@
<?php
namespace RainLoop;
namespace RainLoop\Model;
class Identity
{
@ -54,7 +54,7 @@ class Identity
* @param string $sReplyTo = ''
* @param string $sBcc = ''
*
* @return \RainLoop\Identity
* @return \RainLoop\Model\Identity
*/
public static function NewInstance($sId, $sEmail, $sName = '', $sReplyTo = '', $sBcc = '')
{
@ -72,12 +72,12 @@ class Identity
/**
* @param string $sId
*
* @return \RainLoop\Identity
* @return \RainLoop\Model\Identity
*/
public function SetId($sId)
{
$this->sId = $sId;
return $this;
}
@ -92,7 +92,7 @@ class Identity
/**
* @param string $sEmail
*
* @return \RainLoop\Identity
* @return \RainLoop\Model\Identity
*/
public function SetEmail($sEmail)
{
@ -112,7 +112,7 @@ class Identity
/**
* @param string $sName
*
* @return \RainLoop\Identity
* @return \RainLoop\Model\Identity
*/
public function SetName($sName)
{
@ -132,7 +132,7 @@ class Identity
/**
* @param string $sReplyTo
*
* @return \RainLoop\Identity
* @return \RainLoop\Model\Identity
*/
public function SetReplyTo($sReplyTo)
{
@ -152,7 +152,7 @@ class Identity
/**
* @param string $sBcc
*
* @return \RainLoop\Identity
* @return \RainLoop\Model\Identity
*/
public function SetBcc($sBcc)
{
@ -163,7 +163,7 @@ class Identity
/**
* @param bool $bAjax = false
*
*
* @return array
*/
public function ToSimpleJSON($bAjax = false)

View file

@ -45,12 +45,12 @@ class Domain extends \RainLoop\Providers\AbstractProvider
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
*
* @return \RainLoop\Domain|null
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true)
{
$oDomain = $this->oDriver->Load($sName, $bFindWithWildCard, $bCheckDisabled);
if ($oDomain instanceof \RainLoop\Domain)
if ($oDomain instanceof \RainLoop\Model\Domain)
{
$this->oPlugins->RunHook('filter.domain', array(&$oDomain));
}
@ -59,11 +59,11 @@ class Domain extends \RainLoop\Providers\AbstractProvider
}
/**
* @param \RainLoop\Domain $oDomain
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain)
public function Save(\RainLoop\Model\Domain $oDomain)
{
return $this->bAdmin ? $this->oDriver->Save($oDomain) : false;
}
@ -115,7 +115,7 @@ class Domain extends \RainLoop\Providers\AbstractProvider
* @param \RainLoop\Actions $oActions
* @param string $sNameForTest = ''
*
* @return \RainLoop\Domain | null
* @return \RainLoop\Model\Domain | null
*/
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
{
@ -128,12 +128,10 @@ class Domain extends \RainLoop\Providers\AbstractProvider
$sIncHost = (string) $oActions->GetActionParam('IncHost', '');
$iIncPort = (int) $oActions->GetActionParam('IncPort', 143);
$iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$bIncVerifySsl = '1' === (string) $oActions->GetActionParam('IncVerifySsl', '0');
$bIncShortLogin = '1' === (string) $oActions->GetActionParam('IncShortLogin', '0');
$sOutHost = (string) $oActions->GetActionParam('OutHost', '');
$iOutPort = (int) $oActions->GetActionParam('OutPort', 25);
$iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$bOutVerifySsl = '1' === (string) $oActions->GetActionParam('OutVerifySsl', '0');
$bOutShortLogin = '1' === (string) $oActions->GetActionParam('OutShortLogin', '0');
$bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
@ -146,7 +144,7 @@ class Domain extends \RainLoop\Providers\AbstractProvider
if (0 < strlen($sName) || 0 < strlen($sNameForTest))
{
$oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
if ($oDomain instanceof \RainLoop\Domain)
if ($oDomain instanceof \RainLoop\Model\Domain)
{
if ($bCreate)
{
@ -155,16 +153,16 @@ class Domain extends \RainLoop\Providers\AbstractProvider
else
{
$oDomain->UpdateInstance(
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList);
}
}
else
{
$oDomain = \RainLoop\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth,
$oDomain = \RainLoop\Model\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList);
}
}

View file

@ -147,7 +147,7 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
*
* @return \RainLoop\Domain|null
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true)
{
@ -155,14 +155,14 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
$sDisabled = '';
$sFoundedValue = '';
$sRealFileName = $this->codeFileName($sName);
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
}
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
@ -192,7 +192,7 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
}
//---
$mResult = \RainLoop\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
}
else if ($bFindWithWildCard)
{
@ -214,11 +214,11 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
}
/**
* @param \RainLoop\Domain $oDomain
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain)
public function Save(\RainLoop\Model\Domain $oDomain)
{
$sRealFileName = $this->codeFileName($oDomain->Name());

View file

@ -18,16 +18,16 @@ interface DomainAdminInterface extends DomainInterface
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
*
* @return \RainLoop\Domain|null
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true);
/**
* @param \RainLoop\Domain $oDomain
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain);
public function Save(\RainLoop\Model\Domain $oDomain);
/**
* @param string $sName

View file

@ -6,16 +6,16 @@
</div>
<div class="modal-body">
<form class="form-horizontal domain-form" action="#/" onsubmit="return false;">
<div class="row" data-bind="visible: !edit()">
<div class="row" data-bind="visible: !edit()" style="margin-bottom: 20px;">
<div class="span10">
Name <span style="color: #aaa">(wildcard supported)</span>
<br />
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
<input type="text" class="span4" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="textInput: name, hasfocus: name.focused" />
<span class="error-desc" data-bind="text: savingError"></span>
</div>
</div>
<br />
<div class="row">
<div class="span5" data-bind="css: { 'testing-done': testingDone, 'testing-error': testingImapError }">
<div class="legend imap-header">
@ -47,21 +47,13 @@
<option value="1">SSL/TLS</option>
<option value="2">STARTTLS</option>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;
<div data-bind="visible: '1' === imapSecure() && false, component: {
name: 'Checkbox',
params: {
label: 'Verify ssl certificate',
value: imapVerifySsl
}
}"></div>
</div>
</div>
<br />
<div data-bind="component: {
name: 'Checkbox',
params: {
label: 'Use short login form',
label: 'Use short login',
value: imapShortLogin,
inline: true
}
@ -99,21 +91,13 @@
<option value="1">SSL/TLS</option>
<option value="2">STARTTLS</option>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;
<div data-bind="visible: '1' === smtpSecure() && false, component: {
name: 'Checkbox',
params: {
label: 'Verify ssl certificate',
value: smtpVerifySsl
}
}"></div>
</div>
</div>
<br />
<div data-bind="component: {
name: 'Checkbox',
params: {
label: 'Use short login form',
label: 'Use short login',
value: smtpShortLogin,
inline: true
}
@ -151,7 +135,7 @@
Test
</a>
<a class="btn button-white-list pull-left" data-bind="command: whiteListCommand">
<i data-bind="css: {'icon-right': !whiteListPage(), 'icon-left': whiteListPage()}"></i>
<i data-bind="css: {'icon-users': !whiteListPage(), 'icon-left': whiteListPage()}"></i>
&nbsp;&nbsp;
<span data-bind="visible: !whiteListPage()">White List</span>
<span data-bind="visible: whiteListPage()">Back</span>