mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 22:47:03 +03:00
Added "[labs] imap_show_login_alert" setting
Small fixes
This commit is contained in:
parent
f749d77fff
commit
43d1794423
81 changed files with 132 additions and 48 deletions
446
rainloop/v/0.0.0/app/libraries/RainLoop/Model/Account.php
Normal file
446
rainloop/v/0.0.0/app/libraries/RainLoop/Model/Account.php
Normal file
|
|
@ -0,0 +1,446 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Model;
|
||||
|
||||
class Account extends \RainLoop\Account // for backward compatibility
|
||||
{
|
||||
/**
|
||||
* @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', false),
|
||||
'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true),
|
||||
'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'], $aImapCredentials['AllowSelfSigned']);
|
||||
|
||||
}
|
||||
|
||||
$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|null $oSmtpClient
|
||||
* @param \RainLoop\Application $oConfig
|
||||
* @param bool $bUsePhpMail = false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function OutConnectAndLoginHelper($oPlugins, $oSmtpClient, $oConfig, &$bUsePhpMail = false)
|
||||
{
|
||||
$bLogin = false;
|
||||
|
||||
$aSmtpCredentials = array(
|
||||
'UseConnect' => true,
|
||||
'UseAuth' => $this->DomainOutAuth(),
|
||||
'UsePhpMail' => $bUsePhpMail,
|
||||
'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', false),
|
||||
'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true)
|
||||
);
|
||||
|
||||
$oPlugins->RunHook('filter.smtp-credentials', array($this, &$aSmtpCredentials));
|
||||
|
||||
$bUsePhpMail = $aSmtpCredentials['UsePhpMail'];
|
||||
|
||||
$oPlugins->RunHook('event.smtp-pre-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
|
||||
|
||||
if ($aSmtpCredentials['UseConnect'] && !$aSmtpCredentials['UsePhpMail'] && $oSmtpClient)
|
||||
{
|
||||
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'], $aSmtpCredentials['Ehlo'],
|
||||
$aSmtpCredentials['Secure'], $aSmtpCredentials['VerifySsl'], $aSmtpCredentials['AllowSelfSigned']
|
||||
);
|
||||
}
|
||||
|
||||
$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'] && !$aSmtpCredentials['UsePhpMail'] && $oSmtpClient)
|
||||
{
|
||||
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
|
||||
|
||||
$bLogin = true;
|
||||
}
|
||||
|
||||
$oPlugins->RunHook('event.smtp-post-login', array($this, $aSmtpCredentials['UseAuth'], $bLogin, $aSmtpCredentials));
|
||||
|
||||
return $bLogin;
|
||||
}
|
||||
}
|
||||
536
rainloop/v/0.0.0/app/libraries/RainLoop/Model/Domain.php
Normal file
536
rainloop/v/0.0.0/app/libraries/RainLoop/Model/Domain.php
Normal file
|
|
@ -0,0 +1,536 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Model;
|
||||
|
||||
use MailSo\Net\Enumerations\ConnectionSecurityType;
|
||||
|
||||
class Domain
|
||||
{
|
||||
const DEFAULT_FORWARDED_FLAG = '$Forwarded';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sIncHost;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iIncPort;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iIncSecure;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bIncShortLogin;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sOutHost;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iOutPort;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iOutSecure;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bOutShortLogin;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bOutAuth;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bOutUsePhpMail;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bUseSieve;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sSieveHost;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iSievePort;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iSieveSecure;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sWhiteList;
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sIncHost
|
||||
* @param int $iIncPort
|
||||
* @param int $iIncSecure
|
||||
* @param bool $bIncShortLogin
|
||||
* @param bool $bUseSieve
|
||||
* @param string $sSieveHost
|
||||
* @param int $iSievePort
|
||||
* @param int $iSieveSecure
|
||||
* @param string $sOutHost
|
||||
* @param int $iOutPort
|
||||
* @param int $iOutSecure
|
||||
* @param bool $bOutShortLogin
|
||||
* @param bool $bOutAuth
|
||||
* @param bool $bOutUsePhpMail = false
|
||||
* @param string $sWhiteList = ''
|
||||
*/
|
||||
private function __construct($sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail = false,
|
||||
$sWhiteList = '')
|
||||
{
|
||||
$this->sName = $sName;
|
||||
$this->sIncHost = $sIncHost;
|
||||
$this->iIncPort = $iIncPort;
|
||||
$this->iIncSecure = $iIncSecure;
|
||||
$this->bIncShortLogin = $bIncShortLogin;
|
||||
|
||||
$this->sOutHost = $sOutHost;
|
||||
$this->iOutPort = $iOutPort;
|
||||
$this->iOutSecure = $iOutSecure;
|
||||
$this->bOutShortLogin = $bOutShortLogin;
|
||||
$this->bOutAuth = $bOutAuth;
|
||||
$this->bOutUsePhpMail = $bOutUsePhpMail;
|
||||
|
||||
$this->bUseSieve = $bUseSieve;
|
||||
$this->sSieveHost = $sSieveHost;
|
||||
$this->iSievePort = $iSievePort;
|
||||
$this->iSieveSecure = $iSieveSecure;
|
||||
|
||||
$this->sWhiteList = \trim($sWhiteList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sIncHost
|
||||
* @param int $iIncPort
|
||||
* @param int $iIncSecure
|
||||
* @param bool $bIncShortLogin
|
||||
* @param bool $bUseSieve
|
||||
* @param string $sSieveHost
|
||||
* @param int $iSievePort
|
||||
* @param int $iSieveSecure
|
||||
* @param string $sOutHost
|
||||
* @param int $iOutPort
|
||||
* @param int $iOutSecure
|
||||
* @param bool $bOutShortLogin
|
||||
* @param bool $bOutAuth
|
||||
* @param bool $bOutUsePhpMail = false
|
||||
* @param string $sWhiteList = ''
|
||||
*
|
||||
* @return \RainLoop\Model\Domain
|
||||
*/
|
||||
public static function NewInstance($sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
|
||||
$sWhiteList = '')
|
||||
{
|
||||
return new self($sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
|
||||
$sWhiteList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param array $aDomain
|
||||
*
|
||||
* @return \RainLoop\Model\Domain|null
|
||||
*/
|
||||
public static function NewInstanceFromDomainConfigArray($sName, $aDomain)
|
||||
{
|
||||
$oDomain = null;
|
||||
|
||||
if (0 < \strlen($sName) && \is_array($aDomain) && 0 < \strlen($aDomain['imap_host']) && 0 < \strlen($aDomain['imap_port']))
|
||||
{
|
||||
$sIncHost = (string) $aDomain['imap_host'];
|
||||
$iIncPort = (int) $aDomain['imap_port'];
|
||||
$iIncSecure = self::StrConnectionSecurityTypeToCons(
|
||||
!empty($aDomain['imap_secure']) ? $aDomain['imap_secure'] : '');
|
||||
|
||||
$bUseSieve = isset($aDomain['sieve_use']) ? (bool) $aDomain['sieve_use'] : false;
|
||||
|
||||
$sSieveHost = empty($aDomain['sieve_host']) ? '' : (string) $aDomain['sieve_host'];
|
||||
$iSievePort = empty($aDomain['sieve_port']) ? 2000 : (int) $aDomain['sieve_port'];
|
||||
$iSieveSecure = self::StrConnectionSecurityTypeToCons(
|
||||
!empty($aDomain['sieve_secure']) ? $aDomain['sieve_secure'] : '');
|
||||
|
||||
$sOutHost = empty($aDomain['smtp_host']) ? '' : (string) $aDomain['smtp_host'];
|
||||
$iOutPort = empty($aDomain['smtp_port']) ? 25 : (int) $aDomain['smtp_port'];
|
||||
$iOutSecure = self::StrConnectionSecurityTypeToCons(
|
||||
!empty($aDomain['smtp_secure']) ? $aDomain['smtp_secure'] : '');
|
||||
|
||||
$bOutAuth = isset($aDomain['smtp_auth']) ? (bool) $aDomain['smtp_auth'] : true;
|
||||
$bOutUsePhpMail = isset($aDomain['smtp_php_mail']) ? (bool) $aDomain['smtp_php_mail'] : false;
|
||||
$sWhiteList = (string) (isset($aDomain['white_list']) ? $aDomain['white_list'] : '');
|
||||
|
||||
$bIncShortLogin = isset($aDomain['imap_short_login']) ? (bool) $aDomain['imap_short_login'] : false;
|
||||
$bOutShortLogin = isset($aDomain['smtp_short_login']) ? (bool) $aDomain['smtp_short_login'] : false;
|
||||
|
||||
$oDomain = self::NewInstance($sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
|
||||
$sWhiteList);
|
||||
}
|
||||
|
||||
return $oDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sStr
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function encodeIniString($sStr)
|
||||
{
|
||||
return str_replace('"', '\\"', $sStr);
|
||||
}
|
||||
|
||||
public function Normalize()
|
||||
{
|
||||
$this->sIncHost = \trim($this->sIncHost);
|
||||
$this->sSieveHost = \trim($this->sSieveHost);
|
||||
$this->sOutHost = \trim($this->sOutHost);
|
||||
$this->sWhiteList = \trim($this->sWhiteList);
|
||||
|
||||
if ($this->iIncPort <= 0)
|
||||
{
|
||||
$this->iIncPort = 143;
|
||||
}
|
||||
|
||||
if ($this->iSievePort <= 0)
|
||||
{
|
||||
$this->iSievePort = 2000;
|
||||
}
|
||||
|
||||
if ($this->iOutPort <= 0)
|
||||
{
|
||||
$this->iOutPort = 25;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function ToIniString()
|
||||
{
|
||||
$this->Normalize();
|
||||
return \implode("\n", array(
|
||||
'imap_host = "'.$this->encodeIniString($this->sIncHost).'"',
|
||||
'imap_port = '.$this->iIncPort,
|
||||
'imap_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iIncSecure).'"',
|
||||
'imap_short_login = '.($this->bIncShortLogin ? 'On' : 'Off'),
|
||||
'sieve_use = '.($this->bUseSieve ? 'On' : 'Off'),
|
||||
'sieve_host = "'.$this->encodeIniString($this->sSieveHost).'"',
|
||||
'sieve_port = '.$this->iSievePort,
|
||||
'sieve_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iSieveSecure).'"',
|
||||
'smtp_host = "'.$this->encodeIniString($this->sOutHost).'"',
|
||||
'smtp_port = '.$this->iOutPort,
|
||||
'smtp_secure = "'.self::ConstConnectionSecurityTypeToStr($this->iOutSecure).'"',
|
||||
'smtp_short_login = '.($this->bOutShortLogin ? 'On' : 'Off'),
|
||||
'smtp_auth = '.($this->bOutAuth ? 'On' : 'Off'),
|
||||
'smtp_php_mail = '.($this->bOutUsePhpMail ? 'On' : 'Off'),
|
||||
'white_list = "'.$this->encodeIniString($this->sWhiteList).'"'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sType
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function StrConnectionSecurityTypeToCons($sType)
|
||||
{
|
||||
$iSecurityType = ConnectionSecurityType::NONE;
|
||||
switch (strtoupper($sType))
|
||||
{
|
||||
case 'SSL':
|
||||
$iSecurityType = ConnectionSecurityType::SSL;
|
||||
break;
|
||||
case 'TLS':
|
||||
$iSecurityType = ConnectionSecurityType::STARTTLS;
|
||||
break;
|
||||
}
|
||||
return $iSecurityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iSecurityType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function ConstConnectionSecurityTypeToStr($iSecurityType)
|
||||
{
|
||||
$sType = 'None';
|
||||
switch ($iSecurityType)
|
||||
{
|
||||
case ConnectionSecurityType::SSL:
|
||||
$sType = 'SSL';
|
||||
break;
|
||||
case ConnectionSecurityType::STARTTLS:
|
||||
$sType = 'TLS';
|
||||
break;
|
||||
}
|
||||
|
||||
return $sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIncHost
|
||||
* @param int $iIncPort
|
||||
* @param int $iIncSecure
|
||||
* @param bool $bIncShortLogin
|
||||
* @param bool $bUseSieve
|
||||
* @param string $sOutHost
|
||||
* @param int $iOutPort
|
||||
* @param int $iOutSecure
|
||||
* @param bool $bOutShortLogin
|
||||
* @param bool $bOutAuth
|
||||
* @param bool $bOutUsePhpMail = false
|
||||
* @param string $sWhiteList = ''
|
||||
*
|
||||
* @return \RainLoop\Model\Domain
|
||||
*/
|
||||
public function UpdateInstance(
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
|
||||
$sWhiteList = '')
|
||||
{
|
||||
$this->sIncHost = \MailSo\Base\Utils::IdnToAscii($sIncHost);
|
||||
$this->iIncPort = $iIncPort;
|
||||
$this->iIncSecure = $iIncSecure;
|
||||
$this->bIncShortLogin = $bIncShortLogin;
|
||||
|
||||
$this->bUseSieve = $bUseSieve;
|
||||
$this->sSieveHost = \MailSo\Base\Utils::IdnToAscii($sSieveHost);
|
||||
$this->iSievePort = $iSievePort;
|
||||
$this->iSieveSecure = $iSieveSecure;
|
||||
|
||||
$this->sOutHost = \MailSo\Base\Utils::IdnToAscii($sOutHost);
|
||||
$this->iOutPort = $iOutPort;
|
||||
$this->iOutSecure = $iOutSecure;
|
||||
$this->bOutShortLogin = $bOutShortLogin;
|
||||
$this->bOutAuth = $bOutAuth;
|
||||
$this->bOutUsePhpMail = $bOutUsePhpMail;
|
||||
|
||||
$this->sWhiteList = \trim($sWhiteList);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Name()
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function IncHost()
|
||||
{
|
||||
return $this->sIncHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function IncPort()
|
||||
{
|
||||
return $this->iIncPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function IncSecure()
|
||||
{
|
||||
return $this->iIncSecure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IncShortLogin()
|
||||
{
|
||||
return $this->bIncShortLogin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function UseSieve()
|
||||
{
|
||||
return $this->bUseSieve;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function SieveHost()
|
||||
{
|
||||
return $this->sSieveHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function SievePort()
|
||||
{
|
||||
return $this->iSievePort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function SieveSecure()
|
||||
{
|
||||
return $this->iSieveSecure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function OutHost()
|
||||
{
|
||||
return $this->sOutHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function OutPort()
|
||||
{
|
||||
return $this->iOutPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function OutSecure()
|
||||
{
|
||||
return $this->iOutSecure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function OutShortLogin()
|
||||
{
|
||||
return $this->bOutShortLogin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function OutAuth()
|
||||
{
|
||||
return $this->bOutAuth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function OutUsePhpMail()
|
||||
{
|
||||
return $this->bOutUsePhpMail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function WhiteList()
|
||||
{
|
||||
return $this->sWhiteList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sLogin = ''
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ValidateWhiteList($sEmail, $sLogin = '')
|
||||
{
|
||||
$sW = \trim($this->sWhiteList);
|
||||
if (0 < strlen($sW))
|
||||
{
|
||||
$sEmail = \MailSo\Base\Utils::IdnToUtf8($sEmail, true);
|
||||
$sLogin = \MailSo\Base\Utils::IdnToUtf8($sLogin);
|
||||
|
||||
$sW = \preg_replace('/([^\s]+)@[^\s]*/', '$1', $sW);
|
||||
$sW = ' '.\trim(\preg_replace('/[\s;,\r\n\t]+/', ' ', $sW)).' ';
|
||||
|
||||
$sUserPart = \MailSo\Base\Utils::GetAccountNameFromEmail(0 < \strlen($sLogin) ? $sLogin : $sEmail);
|
||||
return false !== \strpos($sW, ' '.$sUserPart.' ');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bAjax = false
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToSimpleJSON($bAjax = false)
|
||||
{
|
||||
return array(
|
||||
'Name' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->Name()) : $this->Name(),
|
||||
'IncHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->IncHost()) : $this->IncHost(),
|
||||
'IncPort' => $this->IncPort(),
|
||||
'IncSecure' => $this->IncSecure(),
|
||||
'IncShortLogin' => $this->IncShortLogin(),
|
||||
'UseSieve' => $this->UseSieve(),
|
||||
'SieveHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->SieveHost()) : $this->SieveHost(),
|
||||
'SievePort' => $this->SievePort(),
|
||||
'SieveSecure' => $this->SieveSecure(),
|
||||
'OutHost' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->OutHost()) : $this->OutHost(),
|
||||
'OutPort' => $this->OutPort(),
|
||||
'OutSecure' => $this->OutSecure(),
|
||||
'OutShortLogin' => $this->OutShortLogin(),
|
||||
'OutAuth' => $this->OutAuth(),
|
||||
'OutUsePhpMail' => $this->OutUsePhpMail(),
|
||||
'WhiteList' => $this->WhiteList()
|
||||
);
|
||||
}
|
||||
}
|
||||
179
rainloop/v/0.0.0/app/libraries/RainLoop/Model/Identity.php
Normal file
179
rainloop/v/0.0.0/app/libraries/RainLoop/Model/Identity.php
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Model;
|
||||
|
||||
class Identity
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sEmail;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sReplyTo;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sBcc;
|
||||
|
||||
/**
|
||||
* @param string $sId
|
||||
* @param string $sEmail
|
||||
* @param string $sName
|
||||
* @param string $sReplyTo
|
||||
* @param string $sBcc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct($sId, $sEmail, $sName, $sReplyTo, $sBcc)
|
||||
{
|
||||
$this->sId = $sId;
|
||||
$this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
|
||||
$this->sName = \trim($sName);
|
||||
$this->sReplyTo = \trim($sReplyTo);
|
||||
$this->sBcc = \trim($sBcc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sId
|
||||
* @param string $sEmail
|
||||
* @param string $sName = ''
|
||||
* @param string $sReplyTo = ''
|
||||
* @param string $sBcc = ''
|
||||
*
|
||||
* @return \RainLoop\Model\Identity
|
||||
*/
|
||||
public static function NewInstance($sId, $sEmail, $sName = '', $sReplyTo = '', $sBcc = '')
|
||||
{
|
||||
return new self($sId, $sEmail, $sName, $sReplyTo, $sBcc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Id()
|
||||
{
|
||||
return $this->sId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sId
|
||||
*
|
||||
* @return \RainLoop\Model\Identity
|
||||
*/
|
||||
public function SetId($sId)
|
||||
{
|
||||
$this->sId = $sId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Email()
|
||||
{
|
||||
return $this->sEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
*
|
||||
* @return \RainLoop\Model\Identity
|
||||
*/
|
||||
public function SetEmail($sEmail)
|
||||
{
|
||||
$this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Name()
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return \RainLoop\Model\Identity
|
||||
*/
|
||||
public function SetName($sName)
|
||||
{
|
||||
$this->sName = $sName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function ReplyTo()
|
||||
{
|
||||
return $this->sReplyTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sReplyTo
|
||||
*
|
||||
* @return \RainLoop\Model\Identity
|
||||
*/
|
||||
public function SetReplyTo($sReplyTo)
|
||||
{
|
||||
$this->sReplyTo = $sReplyTo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Bcc()
|
||||
{
|
||||
return $this->sBcc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sBcc
|
||||
*
|
||||
* @return \RainLoop\Model\Identity
|
||||
*/
|
||||
public function SetBcc($sBcc)
|
||||
{
|
||||
$this->sBcc = $sBcc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bAjax = false
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToSimpleJSON($bAjax = false)
|
||||
{
|
||||
return array(
|
||||
'Id' => $this->Id(),
|
||||
'Email' => $bAjax ? \MailSo\Base\Utils::IdnToUtf8($this->Email()) : $this->Email(),
|
||||
'Name' => $this->Name(),
|
||||
'ReplyTo' => $this->ReplyTo(),
|
||||
'Bcc' => $this->Bcc()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue