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

@ -92,7 +92,7 @@
sString = Utils.trim(sString); sString = Utils.trim(sString);
var var
mRegex = /(?:"([^"]+)")? ?<?(.*?@[^>,]+)>?,? ?/g, mRegex = /(?:"([^"]+)")? ?[<]?(.*?@[^>,]+)>?,? ?/g,
mMatch = mRegex.exec(sString) mMatch = mRegex.exec(sString)
; ;

View file

@ -210,8 +210,8 @@
}; };
RemoteAdminStorage.prototype.createOrUpdateDomain = function (fCallback, RemoteAdminStorage.prototype.createOrUpdateDomain = function (fCallback,
bCreate, sName, sIncHost, iIncPort, sIncSecure, bIncVerifySsl, bIncShortLogin, bCreate, sName, sIncHost, iIncPort, sIncSecure, bIncShortLogin,
sOutHost, iOutPort, sOutSecure, bOutShortLogin, bOutVerifySsl, bOutAuth, sWhiteList) sOutHost, iOutPort, sOutSecure, bOutShortLogin, bOutAuth, sWhiteList)
{ {
this.defaultRequest(fCallback, 'AdminDomainSave', { this.defaultRequest(fCallback, 'AdminDomainSave', {
'Create': bCreate ? '1' : '0', 'Create': bCreate ? '1' : '0',
@ -219,12 +219,10 @@
'IncHost': sIncHost, 'IncHost': sIncHost,
'IncPort': iIncPort, 'IncPort': iIncPort,
'IncSecure': sIncSecure, 'IncSecure': sIncSecure,
'IncVerifySsl': bIncVerifySsl ? '1' : '0',
'IncShortLogin': bIncShortLogin ? '1' : '0', 'IncShortLogin': bIncShortLogin ? '1' : '0',
'OutHost': sOutHost, 'OutHost': sOutHost,
'OutPort': iOutPort, 'OutPort': iOutPort,
'OutSecure': sOutSecure, 'OutSecure': sOutSecure,
'OutVerifySsl': bOutVerifySsl ? '1' : '0',
'OutShortLogin': bOutShortLogin ? '1' : '0', 'OutShortLogin': bOutShortLogin ? '1' : '0',
'OutAuth': bOutAuth ? '1' : '0', 'OutAuth': bOutAuth ? '1' : '0',
'WhiteList': sWhiteList 'WhiteList': sWhiteList
@ -232,19 +230,16 @@
}; };
RemoteAdminStorage.prototype.testConnectionForDomain = function (fCallback, sName, RemoteAdminStorage.prototype.testConnectionForDomain = function (fCallback, sName,
sIncHost, iIncPort, sIncSecure, bIncVerifySsl, sIncHost, iIncPort, sIncSecure, sOutHost, iOutPort, sOutSecure, bOutAuth)
sOutHost, iOutPort, sOutSecure, bOutVerifySsl, bOutAuth)
{ {
this.defaultRequest(fCallback, 'AdminDomainTest', { this.defaultRequest(fCallback, 'AdminDomainTest', {
'Name': sName, 'Name': sName,
'IncHost': sIncHost, 'IncHost': sIncHost,
'IncPort': iIncPort, 'IncPort': iIncPort,
'IncSecure': sIncSecure, 'IncSecure': sIncSecure,
'IncVerifySsl': bIncVerifySsl ? '1' : '0',
'OutHost': sOutHost, 'OutHost': sOutHost,
'OutPort': iOutPort, 'OutPort': iOutPort,
'OutSecure': sOutSecure, 'OutSecure': sOutSecure,
'OutVerifySsl': bOutVerifySsl ? '1' : '0',
'OutAuth': bOutAuth ? '1' : '0' 'OutAuth': bOutAuth ? '1' : '0'
}); });
}; };

View file

@ -63,12 +63,10 @@
this.imapServer = ko.observable(''); this.imapServer = ko.observable('');
this.imapPort = ko.observable('' + Consts.Values.ImapDefaulPort); this.imapPort = ko.observable('' + Consts.Values.ImapDefaulPort);
this.imapSecure = ko.observable(Enums.ServerSecure.None); this.imapSecure = ko.observable(Enums.ServerSecure.None);
this.imapVerifySsl = ko.observable(false);
this.imapShortLogin = ko.observable(false); this.imapShortLogin = ko.observable(false);
this.smtpServer = ko.observable(''); this.smtpServer = ko.observable('');
this.smtpPort = ko.observable('' + Consts.Values.SmtpDefaulPort); this.smtpPort = ko.observable('' + Consts.Values.SmtpDefaulPort);
this.smtpSecure = ko.observable(Enums.ServerSecure.None); this.smtpSecure = ko.observable(Enums.ServerSecure.None);
this.smtpVerifySsl = ko.observable(false);
this.smtpShortLogin = ko.observable(false); this.smtpShortLogin = ko.observable(false);
this.smtpAuth = ko.observable(true); this.smtpAuth = ko.observable(true);
this.whiteList = ko.observable(''); this.whiteList = ko.observable('');
@ -106,12 +104,10 @@
this.imapServer(), this.imapServer(),
Utils.pInt(this.imapPort()), Utils.pInt(this.imapPort()),
this.imapSecure(), this.imapSecure(),
this.imapVerifySsl(),
this.imapShortLogin(), this.imapShortLogin(),
this.smtpServer(), this.smtpServer(),
Utils.pInt(this.smtpPort()), Utils.pInt(this.smtpPort()),
this.smtpSecure(), this.smtpSecure(),
this.smtpVerifySsl(),
this.smtpShortLogin(), this.smtpShortLogin(),
this.smtpAuth(), this.smtpAuth(),
this.whiteList() this.whiteList()
@ -130,11 +126,9 @@
this.imapServer(), this.imapServer(),
Utils.pInt(this.imapPort()), Utils.pInt(this.imapPort()),
this.imapSecure(), this.imapSecure(),
this.imapVerifySsl(),
this.smtpServer(), this.smtpServer(),
Utils.pInt(this.smtpPort()), Utils.pInt(this.smtpPort()),
this.smtpSecure(), this.smtpSecure(),
this.smtpVerifySsl(),
this.smtpAuth() this.smtpAuth()
); );
}, this.canBeTested); }, this.canBeTested);
@ -289,12 +283,10 @@
this.imapServer(Utils.trim(oDomain.IncHost)); this.imapServer(Utils.trim(oDomain.IncHost));
this.imapPort('' + Utils.pInt(oDomain.IncPort)); this.imapPort('' + Utils.pInt(oDomain.IncPort));
this.imapSecure(Utils.trim(oDomain.IncSecure)); this.imapSecure(Utils.trim(oDomain.IncSecure));
this.imapVerifySsl(!!oDomain.IncVerifySsl);
this.imapShortLogin(!!oDomain.IncShortLogin); this.imapShortLogin(!!oDomain.IncShortLogin);
this.smtpServer(Utils.trim(oDomain.OutHost)); this.smtpServer(Utils.trim(oDomain.OutHost));
this.smtpPort('' + Utils.pInt(oDomain.OutPort)); this.smtpPort('' + Utils.pInt(oDomain.OutPort));
this.smtpSecure(Utils.trim(oDomain.OutSecure)); this.smtpSecure(Utils.trim(oDomain.OutSecure));
this.smtpVerifySsl(!!oDomain.OutVerifySsl);
this.smtpShortLogin(!!oDomain.OutShortLogin); this.smtpShortLogin(!!oDomain.OutShortLogin);
this.smtpAuth(!!oDomain.OutAuth); this.smtpAuth(!!oDomain.OutAuth);
this.whiteList(Utils.trim(oDomain.WhiteList)); this.whiteList(Utils.trim(oDomain.WhiteList));
@ -325,12 +317,10 @@
this.imapServer(''); this.imapServer('');
this.imapPort('' + Consts.Values.ImapDefaulPort); this.imapPort('' + Consts.Values.ImapDefaulPort);
this.imapSecure(Enums.ServerSecure.None); this.imapSecure(Enums.ServerSecure.None);
this.imapVerifySsl(false);
this.imapShortLogin(false); this.imapShortLogin(false);
this.smtpServer(''); this.smtpServer('');
this.smtpPort('' + Consts.Values.SmtpDefaulPort); this.smtpPort('' + Consts.Values.SmtpDefaulPort);
this.smtpSecure(Enums.ServerSecure.None); this.smtpSecure(Enums.ServerSecure.None);
this.smtpVerifySsl(false);
this.smtpShortLogin(false); this.smtpShortLogin(false);
this.smtpAuth(true); this.smtpAuth(true);
this.whiteList(''); this.whiteList('');

View file

@ -189,7 +189,8 @@
this.facebookCommand = Utils.createCommand(this, function () { this.facebookCommand = Utils.createCommand(this, function () {
window.open(Links.socialFacebook(), 'Facebook', window.open(Links.socialFacebook(), 'Facebook',
'left=200,top=100,width=650,height=335,menubar=no,status=no,resizable=yes,scrollbars=yes'); 'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes');
return true; return true;
}, function () { }, function () {
@ -201,7 +202,8 @@
this.googleCommand = Utils.createCommand(this, function () { this.googleCommand = Utils.createCommand(this, function () {
window.open(Links.socialGoogle(), 'Google', window.open(Links.socialGoogle(), 'Google',
'left=200,top=100,width=650,height=335,menubar=no,status=no,resizable=yes,scrollbars=yes'); 'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes');
return true; return true;
}, function () { }, function () {
@ -213,7 +215,7 @@
this.twitterCommand = Utils.createCommand(this, function () { this.twitterCommand = Utils.createCommand(this, function () {
window.open(Links.socialTwitter(), 'Twitter', window.open(Links.socialTwitter(), 'Twitter',
'left=200,top=100,width=650,height=335,menubar=no,status=no,resizable=yes,scrollbars=yes'); 'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes');
return true; return true;

View file

@ -33,6 +33,7 @@ var
rename = require('gulp-rename'), rename = require('gulp-rename'),
replace = require('gulp-replace'), replace = require('gulp-replace'),
uglify = require('gulp-uglify'), uglify = require('gulp-uglify'),
plumber = require('gulp-plumber'),
gutil = require('gulp-util') gutil = require('gulp-util')
; ;
@ -191,11 +192,12 @@ gulp.task('css:main', ['less:main'], function() {
var var
// csslint = require('gulp-csslint'), // csslint = require('gulp-csslint'),
csscomb = require('gulp-csscomb'), // csscomb = require('gulp-csscomb'),
autoprefixer = require('gulp-autoprefixer') autoprefixer = require('gulp-autoprefixer')
; ;
return gulp.src(cfg.paths.css.main.src) return gulp.src(cfg.paths.css.main.src)
.pipe(plumber())
.pipe(concat(cfg.paths.css.main.name)) .pipe(concat(cfg.paths.css.main.name))
.pipe(autoprefixer('last 3 versions', '> 1%', 'ie 9', 'Firefox ESR', 'Opera 12.1')) .pipe(autoprefixer('last 3 versions', '> 1%', 'ie 9', 'Firefox ESR', 'Opera 12.1'))
// .pipe(csscomb()) // .pipe(csscomb())
@ -209,6 +211,7 @@ gulp.task('css:main', ['less:main'], function() {
gulp.task('css:main:min', ['css:main'], function() { gulp.task('css:main:min', ['css:main'], function() {
var minifyCss = require('gulp-minify-css'); var minifyCss = require('gulp-minify-css');
return gulp.src(cfg.paths.staticCSS + cfg.paths.css.main.name) return gulp.src(cfg.paths.staticCSS + cfg.paths.css.main.name)
.pipe(plumber())
.pipe(minifyCss({ .pipe(minifyCss({
'keepSpecialComments': 0 'keepSpecialComments': 0
})) }))

View file

@ -64,6 +64,7 @@
"gulp-closure-compiler": "*", "gulp-closure-compiler": "*",
"gulp-csslint": "*", "gulp-csslint": "*",
"gulp-beautify": "*", "gulp-beautify": "*",
"gulp-plumber": "*",
"gulp-concat-util": "*" "gulp-concat-util": "*"
} }
} }

View file

@ -2,457 +2,5 @@
namespace RainLoop; namespace RainLoop;
class Account // for backward compatibility
{ class Account extends \RainLoop\Model\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;
}
}

View file

@ -869,7 +869,7 @@ class Actions
if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword)) if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword))
{ {
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true); $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)) if ($oDomain->ValidateWhiteList($sEmail, $sLogin))
{ {
@ -1529,7 +1529,7 @@ class Actions
$sLine = \trim(\implode('.', $aDomainParts), '. '); $sLine = \trim(\implode('.', $aDomainParts), '. ');
$oDomain = $oDomainProvider->Load($sLine); $oDomain = $oDomainProvider->Load($sLine);
if ($oDomain && $oDomain instanceof \RainLoop\Domain) if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
{ {
$bAdded = true; $bAdded = true;
$this->Logger()->Write('Check "'.$sLine.'": OK ('.$sEmail.' > '.$sEmail.'@'.$sLine.')', $this->Logger()->Write('Check "'.$sLine.'": OK ('.$sEmail.' > '.$sEmail.'@'.$sLine.')',
@ -2950,7 +2950,7 @@ class Actions
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this); $oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this);
return $this->DefaultResponse(__FUNCTION__, 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); $oImapClient->SetTimeOuts(5);
$iTime = \microtime(true); $iTime = \microtime(true);
$oImapClient->Connect($oDomain->IncHost($oDomain->Name()), $oDomain->IncPort(), $oImapClient->Connect($oDomain->IncHost(), $oDomain->IncPort(),
$oDomain->IncSecure(), $oDomain->IncVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate'))); $oDomain->IncSecure(), !!$this->Config()->Get('ssl', 'verify_certificate'));
$iImapTime = \microtime(true) - $iTime; $iImapTime = \microtime(true) - $iTime;
$oImapClient->Disconnect(); $oImapClient->Disconnect();
@ -3005,8 +3005,8 @@ class Actions
$oSmtpClient->SetTimeOuts(5); $oSmtpClient->SetTimeOuts(5);
$iTime = \microtime(true); $iTime = \microtime(true);
$oSmtpClient->Connect($oDomain->OutHost($oDomain->Name()), $oDomain->OutPort(), '127.0.0.1', $oSmtpClient->Connect($oDomain->OutHost(), $oDomain->OutPort(), '127.0.0.1',
$oDomain->OutSecure(), $oDomain->OutVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate'))); $oDomain->OutSecure(), !!$this->Config()->Get('ssl', 'verify_certificate'));
$iSmtpTime = \microtime(true) - $iTime; $iSmtpTime = \microtime(true) - $iTime;
$oSmtpClient->Disconnect(); $oSmtpClient->Disconnect();
@ -3422,11 +3422,10 @@ class Actions
{ {
$this->Logger()->Write('Versions GC: Begin'); $this->Logger()->Write('Versions GC: Begin');
$iLimitToDelete = 3;
$sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/'; $sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/';
$aDirs = @\array_map('basename', @\array_filter(@\glob($sVPath.'*'), 'is_dir')); $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)) if (\is_array($aDirs) && 5 < \count($aDirs))
{ {
\uasort($aDirs, 'version_compare'); \uasort($aDirs, 'version_compare');
@ -3439,12 +3438,7 @@ class Actions
@\MailSo\Base\Utils::RecRmDir($sVPath.$sName); @\MailSo\Base\Utils::RecRmDir($sVPath.$sName);
$this->Logger()->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version'); $this->Logger()->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version');
$iLimitToDelete--; break;
if (0 > $iLimitToDelete)
{
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 <?php
namespace RainLoop; namespace RainLoop\Model;
use MailSo\Net\Enumerations\ConnectionSecurityType; use MailSo\Net\Enumerations\ConnectionSecurityType;
@ -28,11 +28,6 @@ class Domain
*/ */
private $iIncSecure; private $iIncSecure;
/**
* @var bool
*/
private $bIncVerifySsl;
/** /**
* @var bool * @var bool
*/ */
@ -53,11 +48,6 @@ class Domain
*/ */
private $iOutSecure; private $iOutSecure;
/**
* @var bool
*/
private $bOutVerifySsl;
/** /**
* @var bool * @var bool
*/ */
@ -78,29 +68,25 @@ class Domain
* @param string $sIncHost * @param string $sIncHost
* @param int $iIncPort * @param int $iIncPort
* @param int $iIncSecure * @param int $iIncSecure
* @param bool $bIncVerifySsl
* @param bool $bIncShortLogin * @param bool $bIncShortLogin
* @param string $sOutHost * @param string $sOutHost
* @param int $iOutPort * @param int $iOutPort
* @param int $iOutSecure * @param int $iOutSecure
* @param bool $bOutVerifySsl
* @param bool $bOutShortLogin * @param bool $bOutShortLogin
* @param bool $bOutAuth * @param bool $bOutAuth
* @param string $sWhiteList = '' * @param string $sWhiteList = ''
*/ */
private function __construct($sName, $sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin, private function __construct($sName, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth, $sWhiteList = '') $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $sWhiteList = '')
{ {
$this->sName = $sName; $this->sName = $sName;
$this->sIncHost = $sIncHost; $this->sIncHost = $sIncHost;
$this->iIncPort = $iIncPort; $this->iIncPort = $iIncPort;
$this->iIncSecure = $iIncSecure; $this->iIncSecure = $iIncSecure;
$this->bIncVerifySsl = !!$bIncVerifySsl;
$this->bIncShortLogin = $bIncShortLogin; $this->bIncShortLogin = $bIncShortLogin;
$this->sOutHost = $sOutHost; $this->sOutHost = $sOutHost;
$this->iOutPort = $iOutPort; $this->iOutPort = $iOutPort;
$this->iOutSecure = $iOutSecure; $this->iOutSecure = $iOutSecure;
$this->bOutVerifySsl = !!$bOutVerifySsl;
$this->bOutShortLogin = $bOutShortLogin; $this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth; $this->bOutAuth = $bOutAuth;
$this->sWhiteList = \trim($sWhiteList); $this->sWhiteList = \trim($sWhiteList);
@ -111,26 +97,24 @@ class Domain
* @param string $sIncHost * @param string $sIncHost
* @param int $iIncPort * @param int $iIncPort
* @param int $iIncSecure * @param int $iIncSecure
* @param bool $bIncVerifySsl
* @param bool $bIncShortLogin * @param bool $bIncShortLogin
* @param string $sOutHost * @param string $sOutHost
* @param int $iOutPort * @param int $iOutPort
* @param int $iOutSecure * @param int $iOutSecure
* @param bool $bOutVerifySsl
* @param bool $bOutShortLogin * @param bool $bOutShortLogin
* @param bool $bOutAuth * @param bool $bOutAuth
* @param string $sWhiteList = '' * @param string $sWhiteList = ''
* *
* @return \RainLoop\Domain * @return \RainLoop\Model\Domain
*/ */
public static function NewInstance($sName, public static function NewInstance($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList = '') $sWhiteList = '')
{ {
return new self($sName, return new self($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList); $sWhiteList);
} }
@ -138,7 +122,7 @@ class Domain
* @param string $sName * @param string $sName
* @param array $aDomain * @param array $aDomain
* *
* @return \RainLoop\Domain|null * @return \RainLoop\Model\Domain|null
*/ */
public static function NewInstanceFromDomainConfigArray($sName, $aDomain) public static function NewInstanceFromDomainConfigArray($sName, $aDomain)
{ {
@ -152,15 +136,11 @@ class Domain
$iIncSecure = self::StrConnectionSecurityTypeToCons( $iIncSecure = self::StrConnectionSecurityTypeToCons(
!empty($aDomain['imap_secure']) ? $aDomain['imap_secure'] : ''); !empty($aDomain['imap_secure']) ? $aDomain['imap_secure'] : '');
$bIncVerifySsl = isset($aDomain['imap_verify_ssl']) ? (bool) $aDomain['smtp_verify_ssl'] : false;;
$sOutHost = (string) $aDomain['smtp_host']; $sOutHost = (string) $aDomain['smtp_host'];
$iOutPort = (int) $aDomain['smtp_port']; $iOutPort = (int) $aDomain['smtp_port'];
$iOutSecure = self::StrConnectionSecurityTypeToCons( $iOutSecure = self::StrConnectionSecurityTypeToCons(
!empty($aDomain['smtp_secure']) ? $aDomain['smtp_secure'] : ''); !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; $bOutAuth = isset($aDomain['smtp_auth']) ? (bool) $aDomain['smtp_auth'] : true;
$sWhiteList = (string) (isset($aDomain['white_list']) ? $aDomain['white_list'] : ''); $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; $bOutShortLogin = isset($aDomain['smtp_short_login']) ? (bool) $aDomain['smtp_short_login'] : false;
$oDomain = self::NewInstance($sName, $oDomain = self::NewInstance($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList); $sWhiteList);
} }
@ -213,12 +193,10 @@ class Domain
'imap_host = "'.$this->encodeIniString($this->sIncHost).'"', 'imap_host = "'.$this->encodeIniString($this->sIncHost).'"',
'imap_port = '.$this->iIncPort, 'imap_port = '.$this->iIncPort,
'imap_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iIncSecure).'"', 'imap_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iIncSecure).'"',
'imap_verify_ssl = '.($this->bIncVerifySsl ? 'On' : 'Off'),
'imap_short_login = '.($this->bIncShortLogin ? 'On' : 'Off'), 'imap_short_login = '.($this->bIncShortLogin ? 'On' : 'Off'),
'smtp_host = "'.$this->encodeIniString($this->sOutHost).'"', 'smtp_host = "'.$this->encodeIniString($this->sOutHost).'"',
'smtp_port = '.$this->iOutPort, 'smtp_port = '.$this->iOutPort,
'smtp_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iOutSecure).'"', 'smtp_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iOutSecure).'"',
'smtp_verify_ssl = '.($this->bOutVerifySsl ? 'On' : 'Off'),
'smtp_short_login = '.($this->bOutShortLogin ? 'On' : 'Off'), 'smtp_short_login = '.($this->bOutShortLogin ? 'On' : 'Off'),
'smtp_auth = '.($this->bOutAuth ? 'On' : 'Off'), 'smtp_auth = '.($this->bOutAuth ? 'On' : 'Off'),
'white_list = "'.$this->encodeIniString($this->sWhiteList).'"' 'white_list = "'.$this->encodeIniString($this->sWhiteList).'"'
@ -270,32 +248,28 @@ class Domain
* @param string $sIncHost * @param string $sIncHost
* @param int $iIncPort * @param int $iIncPort
* @param int $iIncSecure * @param int $iIncSecure
* @param bool $bIncVerifySsl
* @param bool $bIncShortLogin * @param bool $bIncShortLogin
* @param string $sOutHost * @param string $sOutHost
* @param int $iOutPort * @param int $iOutPort
* @param int $iOutSecure * @param int $iOutSecure
* @param bool $bOutVerifySsl
* @param bool $bOutShortLogin * @param bool $bOutShortLogin
* @param bool $bOutAuth * @param bool $bOutAuth
* @param string $sWhiteList = '' * @param string $sWhiteList = ''
* *
* @return \RainLoop\Domain * @return \RainLoop\Model\Domain
*/ */
public function UpdateInstance( public function UpdateInstance(
$sIncHost, $iIncPort, $iIncSecure, $bIncVerifySsl, $bIncShortLogin, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutVerifySsl, $bOutShortLogin, $bOutAuth, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList = '') $sWhiteList = '')
{ {
$this->sIncHost = \MailSo\Base\Utils::IdnToAscii($sIncHost); $this->sIncHost = \MailSo\Base\Utils::IdnToAscii($sIncHost);
$this->iIncPort = $iIncPort; $this->iIncPort = $iIncPort;
$this->iIncSecure = $iIncSecure; $this->iIncSecure = $iIncSecure;
$this->bIncVerifySsl = !!$bIncVerifySsl;
$this->bIncShortLogin = $bIncShortLogin; $this->bIncShortLogin = $bIncShortLogin;
$this->sOutHost = \MailSo\Base\Utils::IdnToAscii($sOutHost); $this->sOutHost = \MailSo\Base\Utils::IdnToAscii($sOutHost);
$this->iOutPort = $iOutPort; $this->iOutPort = $iOutPort;
$this->iOutSecure = $iOutSecure; $this->iOutSecure = $iOutSecure;
$this->bOutVerifySsl = !!$bOutVerifySsl;
$this->bOutShortLogin = $bOutShortLogin; $this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth; $this->bOutAuth = $bOutAuth;
$this->sWhiteList = \trim($sWhiteList); $this->sWhiteList = \trim($sWhiteList);
@ -312,13 +286,11 @@ class Domain
} }
/** /**
* @param string $sRealDomainName = ''
*
* @return string * @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; return $this->iIncSecure;
} }
/**
* @param bool|null $bGlobalVerify = null
*
* @return bool
*/
public function IncVerifySsl($bGlobalVerify = null)
{
return null === $bGlobalVerify ? $this->bIncVerifySsl : !!$bGlobalVerify;
}
/** /**
* @return bool * @return bool
*/ */
@ -356,12 +318,11 @@ class Domain
} }
/** /**
* @param string $sRealDomainName = ''
* @return string * @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(), 'IncHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->IncHost()) : $this->IncHost(),
'IncPort' => $this->IncPort(), 'IncPort' => $this->IncPort(),
'IncSecure' => $this->IncSecure(), 'IncSecure' => $this->IncSecure(),
'IncVerifySsl' => $this->IncVerifySsl(),
'IncShortLogin' => $this->IncShortLogin(), 'IncShortLogin' => $this->IncShortLogin(),
'OutHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->OutHost()) : $this->OutHost(), 'OutHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->OutHost()) : $this->OutHost(),
'OutPort' => $this->OutPort(), 'OutPort' => $this->OutPort(),
'OutSecure' => $this->OutSecure(), 'OutSecure' => $this->OutSecure(),
'OutVerifySsl' => $this->OutVerifySsl(),
'OutShortLogin' => $this->OutShortLogin(), 'OutShortLogin' => $this->OutShortLogin(),
'OutAuth' => $this->OutAuth(), 'OutAuth' => $this->OutAuth(),
'WhiteList' => $this->WhiteList() 'WhiteList' => $this->WhiteList()

View file

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

View file

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

View file

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

View file

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

View file

@ -6,16 +6,16 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form class="form-horizontal domain-form" action="#/" onsubmit="return false;"> <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"> <div class="span10">
Name <span style="color: #aaa">(wildcard supported)</span> Name <span style="color: #aaa">(wildcard supported)</span>
<br /> <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" /> data-bind="textInput: name, hasfocus: name.focused" />
<span class="error-desc" data-bind="text: savingError"></span> <span class="error-desc" data-bind="text: savingError"></span>
</div> </div>
</div> </div>
<br />
<div class="row"> <div class="row">
<div class="span5" data-bind="css: { 'testing-done': testingDone, 'testing-error': testingImapError }"> <div class="span5" data-bind="css: { 'testing-done': testingDone, 'testing-error': testingImapError }">
<div class="legend imap-header"> <div class="legend imap-header">
@ -47,21 +47,13 @@
<option value="1">SSL/TLS</option> <option value="1">SSL/TLS</option>
<option value="2">STARTTLS</option> <option value="2">STARTTLS</option>
</select> </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>
</div> </div>
<br /> <br />
<div data-bind="component: { <div data-bind="component: {
name: 'Checkbox', name: 'Checkbox',
params: { params: {
label: 'Use short login form', label: 'Use short login',
value: imapShortLogin, value: imapShortLogin,
inline: true inline: true
} }
@ -99,21 +91,13 @@
<option value="1">SSL/TLS</option> <option value="1">SSL/TLS</option>
<option value="2">STARTTLS</option> <option value="2">STARTTLS</option>
</select> </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>
</div> </div>
<br /> <br />
<div data-bind="component: { <div data-bind="component: {
name: 'Checkbox', name: 'Checkbox',
params: { params: {
label: 'Use short login form', label: 'Use short login',
value: smtpShortLogin, value: smtpShortLogin,
inline: true inline: true
} }
@ -151,7 +135,7 @@
Test Test
</a> </a>
<a class="btn button-white-list pull-left" data-bind="command: whiteListCommand"> <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; &nbsp;&nbsp;
<span data-bind="visible: !whiteListPage()">White List</span> <span data-bind="visible: !whiteListPage()">White List</span>
<span data-bind="visible: whiteListPage()">Back</span> <span data-bind="visible: whiteListPage()">Back</span>

858
vendors/jua/_/jua.js vendored
View file

@ -1,435 +1,435 @@
(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();(function ($, window, queue) { (function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();(function ($, window, queue) {
'use strict'; 'use strict';
/** /**
* @param {*} mValue * @param {*} mValue
* @return {boolean} * @return {boolean}
*/ */
function isUndefined(mValue) function isUndefined(mValue)
{ {
return 'undefined' === typeof mValue; return 'undefined' === typeof mValue;
} }
/** /**
* @param {Object} mObjectFirst * @param {Object} mObjectFirst
* @param {Object=} mObjectSecond * @param {Object=} mObjectSecond
* @return {Object} * @return {Object}
*/ */
function extend(mObjectFirst, mObjectSecond) function extend(mObjectFirst, mObjectSecond)
{ {
if (mObjectSecond) if (mObjectSecond)
{ {
for (var sProp in mObjectSecond) for (var sProp in mObjectSecond)
{ {
if (mObjectSecond.hasOwnProperty(sProp)) if (mObjectSecond.hasOwnProperty(sProp))
{ {
mObjectFirst[sProp] = mObjectSecond[sProp]; mObjectFirst[sProp] = mObjectSecond[sProp];
} }
} }
} }
return mObjectFirst; return mObjectFirst;
} }
/** /**
* @param {*} oParent * @param {*} oParent
* @param {*} oDescendant * @param {*} oDescendant
* *
* @return {boolean} * @return {boolean}
*/ */
function contains(oParent, oDescendant) function contains(oParent, oDescendant)
{ {
var bResult = false; var bResult = false;
if (oParent && oDescendant) if (oParent && oDescendant)
{ {
if (oParent === oDescendant) if (oParent === oDescendant)
{ {
bResult = true; bResult = true;
} }
else if (oParent.contains) else if (oParent.contains)
{ {
bResult = oParent.contains(oDescendant); bResult = oParent.contains(oDescendant);
} }
else else
{ {
/*jshint bitwise: false*/ /*jshint bitwise: false*/
bResult = oDescendant.compareDocumentPosition ? bResult = oDescendant.compareDocumentPosition ?
!!(oDescendant.compareDocumentPosition(oParent) & 8) : false; !!(oDescendant.compareDocumentPosition(oParent) & 8) : false;
/*jshint bitwise: true*/ /*jshint bitwise: true*/
} }
} }
return bResult; return bResult;
} }
function mainClearTimeout(iTimer) function mainClearTimeout(iTimer)
{ {
if (0 < iTimer) if (0 < iTimer)
{ {
clearTimeout(iTimer); clearTimeout(iTimer);
} }
iTimer = 0; iTimer = 0;
} }
/** /**
* @param {Event} oEvent * @param {Event} oEvent
* @return {?Event} * @return {?Event}
*/ */
function getEvent(oEvent) function getEvent(oEvent)
{ {
oEvent = (oEvent && (oEvent.originalEvent ? oEvent = (oEvent && (oEvent.originalEvent ?
oEvent.originalEvent : oEvent)) || window.event; oEvent.originalEvent : oEvent)) || window.event;
return oEvent.dataTransfer ? oEvent : null; return oEvent.dataTransfer ? oEvent : null;
} }
/** /**
* @param {Object} oValues * @param {Object} oValues
* @param {string} sKey * @param {string} sKey
* @param {?} mDefault * @param {?} mDefault
* @return {?} * @return {?}
*/ */
function getValue(oValues, sKey, mDefault) function getValue(oValues, sKey, mDefault)
{ {
return (!oValues || !sKey || isUndefined(oValues[sKey])) ? mDefault : oValues[sKey]; return (!oValues || !sKey || isUndefined(oValues[sKey])) ? mDefault : oValues[sKey];
} }
/** /**
* @param {Object} oOwner * @param {Object} oOwner
* @param {string} sPublicName * @param {string} sPublicName
* @param {*} mObject * @param {*} mObject
*/ */
function setValue(oOwner, sPublicName, mObject) function setValue(oOwner, sPublicName, mObject)
{ {
oOwner[sPublicName] = mObject; oOwner[sPublicName] = mObject;
} }
/** /**
* @param {*} aData * @param {*} aData
* @return {boolean} * @return {boolean}
*/ */
function isNonEmptyArray(aData) function isNonEmptyArray(aData)
{ {
return aData && aData.length && 0 < aData.length ? true : false; return aData && aData.length && 0 < aData.length ? true : false;
} }
/** /**
* @param {*} mValue * @param {*} mValue
* @return {number} * @return {number}
*/ */
function pInt(mValue) function pInt(mValue)
{ {
return parseInt(mValue || 0, 10); return parseInt(mValue || 0, 10);
} }
/** /**
* @param {Function} fFunction * @param {Function} fFunction
* @param {Object=} oScope * @param {Object=} oScope
* @return {Function} * @return {Function}
*/ */
function scopeBind(fFunction, oScope) function scopeBind(fFunction, oScope)
{ {
return function () { return function () {
return fFunction.apply(isUndefined(oScope) ? null : oScope, return fFunction.apply(isUndefined(oScope) ? null : oScope,
Array.prototype.slice.call(arguments)); Array.prototype.slice.call(arguments));
}; };
} }
/** /**
* @param {number=} iLen * @param {number=} iLen
* @return {string} * @return {string}
*/ */
function fakeMd5(iLen) function fakeMd5(iLen)
{ {
var var
sResult = '', sResult = '',
sLine = '0123456789abcdefghijklmnopqrstuvwxyz' sLine = '0123456789abcdefghijklmnopqrstuvwxyz'
; ;
iLen = isUndefined(iLen) ? 32 : pInt(iLen); iLen = isUndefined(iLen) ? 32 : pInt(iLen);
while (sResult.length < iLen) while (sResult.length < iLen)
{ {
sResult += sLine.substr(Math.round(Math.random() * sLine.length), 1); sResult += sLine.substr(Math.round(Math.random() * sLine.length), 1);
} }
return sResult; return sResult;
} }
/** /**
* @return {string} * @return {string}
*/ */
function getNewUid() function getNewUid()
{ {
return 'jua-uid-' + fakeMd5(16) + '-' + (new Date()).getTime().toString(); return 'jua-uid-' + fakeMd5(16) + '-' + (new Date()).getTime().toString();
} }
/** /**
* @param {*} oFile * @param {*} oFile
* @param {string=} sPath * @param {string=} sPath
* @return {Object} * @return {Object}
*/ */
function getDataFromFile(oFile, sPath) function getDataFromFile(oFile, sPath)
{ {
var var
sFileName = isUndefined(oFile.fileName) ? (isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName, sFileName = isUndefined(oFile.fileName) ? (isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName,
iSize = isUndefined(oFile.fileSize) ? (isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize, iSize = isUndefined(oFile.fileSize) ? (isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize,
sType = isUndefined(oFile.type) ? null : oFile.type sType = isUndefined(oFile.type) ? null : oFile.type
; ;
return { return {
'FileName': sFileName, 'FileName': sFileName,
'Size': iSize, 'Size': iSize,
'Type': sType, 'Type': sType,
'Folder': isUndefined(sPath) ? '' : sPath, 'Folder': isUndefined(sPath) ? '' : sPath,
'File' : oFile 'File' : oFile
}; };
} }
/** /**
* @param {*} aItems * @param {*} aItems
* @param {Function} fFileCallback * @param {Function} fFileCallback
* @param {boolean=} bEntry = false * @param {boolean=} bEntry = false
* @param {boolean=} bAllowFolderDragAndDrop = true * @param {boolean=} bAllowFolderDragAndDrop = true
* @param {number=} iLimit = 20 * @param {number=} iLimit = 20
* @param {Function=} fLimitCallback * @param {Function=} fLimitCallback
*/ */
function getDataFromFiles(aItems, fFileCallback, bEntry, bAllowFolderDragAndDrop, iLimit, fLimitCallback) function getDataFromFiles(aItems, fFileCallback, bEntry, bAllowFolderDragAndDrop, iLimit, fLimitCallback)
{ {
var var
iInputLimit = 0, iInputLimit = 0,
iLen = 0, iLen = 0,
iIndex = 0, iIndex = 0,
oItem = null, oItem = null,
oEntry = null, oEntry = null,
bUseLimit = false, bUseLimit = false,
bCallLimit = false, bCallLimit = false,
fTraverseFileTree = function (oItem, sPath, fCallback, fLimitCallbackProxy) { fTraverseFileTree = function (oItem, sPath, fCallback, fLimitCallbackProxy) {
if (oItem && !isUndefined(oItem['name'])) if (oItem && !isUndefined(oItem['name']))
{ {
sPath = sPath || ''; sPath = sPath || '';
if (oItem['isFile']) if (oItem['isFile'])
{ {
oItem.file(function (oFile) { oItem.file(function (oFile) {
if (!bUseLimit || 0 <= --iLimit) if (!bUseLimit || 0 <= --iLimit)
{ {
fCallback(getDataFromFile(oFile, sPath)); fCallback(getDataFromFile(oFile, sPath));
} }
else if (bUseLimit && !bCallLimit) else if (bUseLimit && !bCallLimit)
{ {
if (0 > iLimit && fLimitCallback) if (0 > iLimit && fLimitCallback)
{ {
bCallLimit = true; bCallLimit = true;
fLimitCallback(iInputLimit); fLimitCallback(iInputLimit);
} }
} }
}); });
} }
else if (bAllowFolderDragAndDrop && oItem['isDirectory'] && oItem['createReader']) else if (bAllowFolderDragAndDrop && oItem['isDirectory'] && oItem['createReader'])
{ {
var var
oDirReader = oItem['createReader'](), oDirReader = oItem['createReader'](),
iIndex = 0, iIndex = 0,
iLen = 0 iLen = 0
; ;
if (oDirReader && oDirReader['readEntries']) if (oDirReader && oDirReader['readEntries'])
{ {
oDirReader['readEntries'](function (aEntries) { oDirReader['readEntries'](function (aEntries) {
if (aEntries && isNonEmptyArray(aEntries)) if (aEntries && isNonEmptyArray(aEntries))
{ {
for (iIndex = 0, iLen = aEntries.length; iIndex < iLen; iIndex++) for (iIndex = 0, iLen = aEntries.length; iIndex < iLen; iIndex++)
{ {
fTraverseFileTree(aEntries[iIndex], sPath + oItem['name'] + '/', fCallback, fLimitCallbackProxy); fTraverseFileTree(aEntries[iIndex], sPath + oItem['name'] + '/', fCallback, fLimitCallbackProxy);
} }
} }
}); });
} }
} }
} }
} }
; ;
bAllowFolderDragAndDrop = isUndefined(bAllowFolderDragAndDrop) ? true : !!bAllowFolderDragAndDrop; bAllowFolderDragAndDrop = isUndefined(bAllowFolderDragAndDrop) ? true : !!bAllowFolderDragAndDrop;
bEntry = isUndefined(bEntry) ? false : !!bEntry; bEntry = isUndefined(bEntry) ? false : !!bEntry;
iLimit = isUndefined(iLimit) ? Jua.iDefLimit : pInt(iLimit); iLimit = isUndefined(iLimit) ? Jua.iDefLimit : pInt(iLimit);
iInputLimit = iLimit; iInputLimit = iLimit;
bUseLimit = 0 < iLimit; bUseLimit = 0 < iLimit;
aItems = aItems && 0 < aItems.length ? aItems : null; aItems = aItems && 0 < aItems.length ? aItems : null;
if (aItems) if (aItems)
{ {
for (iIndex = 0, iLen = aItems.length; iIndex < iLen; iIndex++) for (iIndex = 0, iLen = aItems.length; iIndex < iLen; iIndex++)
{ {
oItem = aItems[iIndex]; oItem = aItems[iIndex];
if (oItem) if (oItem)
{ {
if (bEntry) if (bEntry)
{ {
if ('file' === oItem['kind'] && oItem['webkitGetAsEntry']) if ('file' === oItem['kind'] && oItem['webkitGetAsEntry'])
{ {
oEntry = oItem['webkitGetAsEntry'](); oEntry = oItem['webkitGetAsEntry']();
if (oEntry) if (oEntry)
{ {
fTraverseFileTree(oEntry, '', fFileCallback, fLimitCallback); fTraverseFileTree(oEntry, '', fFileCallback, fLimitCallback);
} }
} }
} }
else else
{ {
if (!bUseLimit || 0 <= --iLimit) if (!bUseLimit || 0 <= --iLimit)
{ {
fFileCallback(getDataFromFile(oItem)); fFileCallback(getDataFromFile(oItem));
} }
else if (bUseLimit && !bCallLimit) else if (bUseLimit && !bCallLimit)
{ {
if (0 > iLimit && fLimitCallback) if (0 > iLimit && fLimitCallback)
{ {
bCallLimit = true; bCallLimit = true;
fLimitCallback(iInputLimit); fLimitCallback(iInputLimit);
} }
} }
} }
} }
} }
} }
} }
/** /**
* @param {*} oInput * @param {*} oInput
* @param {Function} fFileCallback * @param {Function} fFileCallback
* @param {number=} iLimit = 20 * @param {number=} iLimit = 20
* @param {Function=} fLimitCallback * @param {Function=} fLimitCallback
*/ */
function getDataFromInput(oInput, fFileCallback, iLimit, fLimitCallback) function getDataFromInput(oInput, fFileCallback, iLimit, fLimitCallback)
{ {
var aFiles = oInput && oInput.files && 0 < oInput.files.length ? oInput.files : null; var aFiles = oInput && oInput.files && 0 < oInput.files.length ? oInput.files : null;
if (aFiles) if (aFiles)
{ {
getDataFromFiles(aFiles, fFileCallback, false, false, iLimit, fLimitCallback); getDataFromFiles(aFiles, fFileCallback, false, false, iLimit, fLimitCallback);
} }
else else
{ {
fFileCallback({ fFileCallback({
'FileName': oInput.value.split('\\').pop().split('/').pop(), 'FileName': oInput.value.split('\\').pop().split('/').pop(),
'Size': null, 'Size': null,
'Type': null, 'Type': null,
'Folder': '', 'Folder': '',
'File' : null 'File' : null
}); });
} }
} }
function eventContainsFiles(oEvent) function eventContainsFiles(oEvent)
{ {
var bResult = false; var bResult = false;
if (oEvent && oEvent.dataTransfer && oEvent.dataTransfer.types && oEvent.dataTransfer.types.length) if (oEvent && oEvent.dataTransfer && oEvent.dataTransfer.types && oEvent.dataTransfer.types.length)
{ {
var var
iIindex = 0, iIindex = 0,
iLen = oEvent.dataTransfer.types.length iLen = oEvent.dataTransfer.types.length
; ;
for (; iIindex < iLen; iIindex++) for (; iIindex < iLen; iIindex++)
{ {
if (oEvent.dataTransfer.types[iIindex].toLowerCase() === 'files') if (oEvent.dataTransfer.types[iIindex].toLowerCase() === 'files')
{ {
bResult = true; bResult = true;
break; break;
} }
} }
} }
return bResult; return bResult;
} }
/** /**
* @param {Event} oEvent * @param {Event} oEvent
* @param {Function} fFileCallback * @param {Function} fFileCallback
* @param {number=} iLimit = 20 * @param {number=} iLimit = 20
* @param {Function=} fLimitCallback * @param {Function=} fLimitCallback
* @param {boolean=} bAllowFolderDragAndDrop = true * @param {boolean=} bAllowFolderDragAndDrop = true
*/ */
function getDataFromDragEvent(oEvent, fFileCallback, iLimit, fLimitCallback, bAllowFolderDragAndDrop) function getDataFromDragEvent(oEvent, fFileCallback, iLimit, fLimitCallback, bAllowFolderDragAndDrop)
{ {
var var
aItems = null, aItems = null,
aFiles = null aFiles = null
; ;
oEvent = getEvent(oEvent); oEvent = getEvent(oEvent);
if (oEvent) if (oEvent)
{ {
aItems = (oEvent.dataTransfer ? getValue(oEvent.dataTransfer, 'items', null) : null) || getValue(oEvent, 'items', null); aItems = (oEvent.dataTransfer ? getValue(oEvent.dataTransfer, 'items', null) : null) || getValue(oEvent, 'items', null);
if (aItems && 0 < aItems.length && aItems[0] && aItems[0]['webkitGetAsEntry']) if (aItems && 0 < aItems.length && aItems[0] && aItems[0]['webkitGetAsEntry'])
{ {
getDataFromFiles(aItems, fFileCallback, true, bAllowFolderDragAndDrop, iLimit, fLimitCallback); getDataFromFiles(aItems, fFileCallback, true, bAllowFolderDragAndDrop, iLimit, fLimitCallback);
} }
else if (eventContainsFiles(oEvent)) else if (eventContainsFiles(oEvent))
{ {
aFiles = (getValue(oEvent, 'files', null) || (oEvent.dataTransfer ? aFiles = (getValue(oEvent, 'files', null) || (oEvent.dataTransfer ?
getValue(oEvent.dataTransfer, 'files', null) : null)); getValue(oEvent.dataTransfer, 'files', null) : null));
if (aFiles && 0 < aFiles.length) if (aFiles && 0 < aFiles.length)
{ {
getDataFromFiles(aFiles, fFileCallback, false, false, iLimit, fLimitCallback); getDataFromFiles(aFiles, fFileCallback, false, false, iLimit, fLimitCallback);
} }
} }
} }
} }
function createNextLabel() function createNextLabel()
{ {
return $('<label style="' + return $('<label style="' +
'position: absolute; background-color:#fff; right: 0px; top: 0px; left: 0px; bottom: 0px; margin: 0px; padding: 0px; cursor: pointer;' + 'position: absolute; background-color:#fff; right: 0px; top: 0px; left: 0px; bottom: 0px; margin: 0px; padding: 0px; cursor: pointer;' +
'"></label>').css({ '"></label>').css({
'opacity': 0 'opacity': 0
}); });
} }
function createNextInput() function createNextInput()
{ {
return $('<input type="file" tabindex="-1" hidefocus="hidefocus" style="position: absolute; left: -9999px;" />'); return $('<input type="file" tabindex="-1" hidefocus="hidefocus" style="position: absolute; left: -9999px;" />');
} }
/** /**
* @param {string=} sName * @param {string=} sName
* @param {boolean=} bMultiple = true * @param {boolean=} bMultiple = true
* @return {?Object} * @return {?Object}
*/ */
function getNewInput(sName, bMultiple) function getNewInput(sName, bMultiple)
{ {
sName = isUndefined(sName) ? '' : sName.toString(); sName = isUndefined(sName) ? '' : sName.toString();
var oLocal = createNextInput(); var oLocal = createNextInput();
if (0 < sName.length) if (0 < sName.length)
{ {
oLocal.attr('name', sName); oLocal.attr('name', sName);
} }
if (isUndefined(bMultiple) ? true : bMultiple) if (isUndefined(bMultiple) ? true : bMultiple)
{ {
oLocal.prop('multiple', true); oLocal.prop('multiple', true);
} }
return oLocal; return oLocal;
} }
/** /**
* @param {?} mStringOrFunction * @param {?} mStringOrFunction
* @param {Array=} aFunctionParams * @param {Array=} aFunctionParams
* @return {string} * @return {string}
*/ */
function getStringOrCallFunction(mStringOrFunction, aFunctionParams) function getStringOrCallFunction(mStringOrFunction, aFunctionParams)
{ {
return $.isFunction(mStringOrFunction) ? return $.isFunction(mStringOrFunction) ?
mStringOrFunction.apply(null, $.isArray(aFunctionParams) ? aFunctionParams : []).toString() : mStringOrFunction.apply(null, $.isArray(aFunctionParams) ? aFunctionParams : []).toString() :
mStringOrFunction.toString(); mStringOrFunction.toString();
} }
/** /**
* @constructor * @constructor

File diff suppressed because one or more lines are too long