2020-03-10 00:04:17 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RainLoop;
|
|
|
|
|
|
|
|
class Api
|
|
|
|
{
|
2020-03-16 20:08:53 +08:00
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function RunResult() : bool
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @staticvar bool $bOne
|
|
|
|
*/
|
|
|
|
public static function Handle() : bool
|
|
|
|
{
|
|
|
|
static $bOne = null;
|
|
|
|
if (null === $bOne)
|
|
|
|
{
|
2020-03-12 02:36:43 +08:00
|
|
|
static::SetupDefaultMailSoConfig();
|
|
|
|
$bOne = static::RunResult();
|
2020-03-10 00:04:17 +08:00
|
|
|
}
|
|
|
|
return $bOne;
|
|
|
|
}
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
public static function Actions() : Actions
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
|
|
|
static $oActions = null;
|
|
|
|
if (null === $oActions)
|
|
|
|
{
|
|
|
|
$oActions = \RainLoop\Actions::NewInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $oActions;
|
|
|
|
}
|
|
|
|
|
2020-03-16 20:08:53 +08:00
|
|
|
public static function Config() : \RainLoop\Config\Application
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
2020-03-11 01:45:00 +08:00
|
|
|
return static::Actions()->Config();
|
2020-03-10 00:04:17 +08:00
|
|
|
}
|
|
|
|
|
2020-03-16 20:08:53 +08:00
|
|
|
public static function Logger() : \MailSo\Log\Logger
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
2020-03-11 01:45:00 +08:00
|
|
|
return static::Actions()->Logger();
|
2020-03-10 00:04:17 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
protected static function SetupDefaultMailSoConfig() : void
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
|
|
|
if (\class_exists('MailSo\Config'))
|
|
|
|
{
|
|
|
|
\MailSo\Config::$MessageListFastSimpleSearch =
|
2020-03-11 01:45:00 +08:00
|
|
|
!!static::Config()->Get('labs', 'imap_message_list_fast_simple_search', true);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$MessageListCountLimitTrigger =
|
2020-03-11 01:45:00 +08:00
|
|
|
(int) static::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$MessageListDateFilter =
|
2020-03-11 01:45:00 +08:00
|
|
|
(int) static::Config()->Get('labs', 'imap_message_list_date_filter', 0);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$MessageListPermanentFilter =
|
2020-03-11 01:45:00 +08:00
|
|
|
\trim(static::Config()->Get('labs', 'imap_message_list_permanent_filter', ''));
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$MessageAllHeaders =
|
2020-03-11 01:45:00 +08:00
|
|
|
!!static::Config()->Get('labs', 'imap_message_all_headers', false);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$LargeThreadLimit =
|
2020-03-11 01:45:00 +08:00
|
|
|
(int) static::Config()->Get('labs', 'imap_large_thread_limit', 50);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$ImapTimeout =
|
2020-03-11 01:45:00 +08:00
|
|
|
(int) static::Config()->Get('labs', 'imap_timeout', 300);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
|
|
|
\MailSo\Config::$BoundaryPrefix = '_RainLoop_';
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
\MailSo\Config::$SystemLogger = static::Logger();
|
2020-03-10 00:04:17 +08:00
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
$sSslCafile = static::Config()->Get('ssl', 'cafile', '');
|
|
|
|
$sSslCapath = static::Config()->Get('ssl', 'capath', '');
|
2020-03-10 00:04:17 +08:00
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
\RainLoop\Utils::$CookieDefaultPath = static::Config()->Get('labs', 'cookie_default_path', '');
|
|
|
|
if (static::Config()->Get('labs', 'cookie_default_secure', false))
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
|
|
|
\RainLoop\Utils::$CookieDefaultSecure = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($sSslCafile) || !empty($sSslCapath))
|
|
|
|
{
|
|
|
|
\MailSo\Hooks::Add('Net.NetClient.StreamContextSettings/Filter', function (&$aStreamContextSettings) use ($sSslCafile, $sSslCapath) {
|
|
|
|
if (isset($aStreamContextSettings['ssl']) && \is_array($aStreamContextSettings['ssl']))
|
|
|
|
{
|
|
|
|
if (empty($aStreamContextSettings['ssl']['cafile']) && !empty($sSslCafile))
|
|
|
|
{
|
|
|
|
$aStreamContextSettings['ssl']['cafile'] = $sSslCafile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($aStreamContextSettings['ssl']['capath']) && !empty($sSslCapath))
|
|
|
|
{
|
|
|
|
$aStreamContextSettings['ssl']['capath'] = $sSslCapath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
\MailSo\Config::$HtmlStrictDebug = !!static::Config()->Get('debug', 'enable', false);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
\MailSo\Config::$CheckNewMessages = !!static::Config()->Get('labs', 'check_new_messages', true);
|
2020-03-10 00:04:17 +08:00
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
if (static::Config()->Get('labs', 'strict_html_parser', true))
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
|
|
|
\MailSo\Config::$HtmlStrictAllowedAttributes = array(
|
|
|
|
// rainloop
|
|
|
|
'data-wrp',
|
|
|
|
// defaults
|
|
|
|
'name',
|
|
|
|
'dir', 'lang', 'style', 'title',
|
|
|
|
'background', 'bgcolor', 'alt', 'height', 'width', 'src', 'href',
|
|
|
|
'border', 'bordercolor', 'charset', 'direction', 'language',
|
|
|
|
// a
|
|
|
|
'coords', 'download', 'hreflang', 'shape',
|
|
|
|
// body
|
|
|
|
'alink', 'bgproperties', 'bottommargin', 'leftmargin', 'link', 'rightmargin', 'text', 'topmargin', 'vlink',
|
|
|
|
'marginwidth', 'marginheight', 'offset',
|
|
|
|
// button,
|
|
|
|
'disabled', 'type', 'value',
|
|
|
|
// col
|
|
|
|
'align', 'valign',
|
|
|
|
// font
|
|
|
|
'color', 'face', 'size',
|
|
|
|
// form
|
|
|
|
'novalidate',
|
|
|
|
// hr
|
|
|
|
'noshade',
|
|
|
|
// img
|
|
|
|
'hspace', 'sizes', 'srcset', 'vspace', 'usemap',
|
|
|
|
// input, textarea
|
|
|
|
'checked', 'max', 'min', 'maxlength', 'multiple', 'pattern', 'placeholder', 'readonly', 'required', 'step', 'wrap',
|
|
|
|
// label
|
|
|
|
'for',
|
|
|
|
// meter
|
|
|
|
'low', 'high', 'optimum',
|
|
|
|
// ol
|
|
|
|
'reversed', 'start',
|
|
|
|
// option
|
|
|
|
'selected', 'label',
|
|
|
|
// table
|
|
|
|
'cols', 'rows', 'frame', 'rules', 'summary', 'cellpadding', 'cellspacing',
|
|
|
|
// td
|
|
|
|
'abbr', 'axis', 'colspan', 'rowspan', 'headers', 'nowrap'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 19:55:03 +08:00
|
|
|
public static function Version() : string
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
|
|
|
return APP_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetUserSsoHash(string $sEmail, string $sPassword, array $aAdditionalOptions = array(), bool $bUseTimeout = true) : string
|
|
|
|
{
|
|
|
|
$sSsoHash = \MailSo\Base\Utils::Sha1Rand(\md5($sEmail).\md5($sPassword));
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
return static::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash),
|
2020-03-10 00:04:17 +08:00
|
|
|
\RainLoop\Utils::EncodeKeyValuesQ(array(
|
|
|
|
'Email' => $sEmail,
|
|
|
|
'Password' => $sPassword,
|
|
|
|
'AdditionalOptions' => $aAdditionalOptions,
|
|
|
|
'Time' => $bUseTimeout ? \time() : 0
|
|
|
|
))) ? $sSsoHash : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function ClearUserSsoHash(string $sSsoHash) : bool
|
|
|
|
{
|
2020-03-11 01:45:00 +08:00
|
|
|
return static::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
|
2020-03-10 00:04:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function ClearUserData(string $sEmail) : bool
|
|
|
|
{
|
|
|
|
if (0 < \strlen($sEmail))
|
|
|
|
{
|
|
|
|
$sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
$oStorageProvider = static::Actions()->StorageProvider();
|
2020-03-10 00:04:17 +08:00
|
|
|
if ($oStorageProvider && $oStorageProvider->IsActive())
|
|
|
|
{
|
|
|
|
$oStorageProvider->DeleteStorage($sEmail);
|
|
|
|
}
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
if (static::Actions()->AddressBookProvider() &&
|
|
|
|
static::Actions()->AddressBookProvider()->IsActive())
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
2020-03-11 01:45:00 +08:00
|
|
|
static::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
|
2020-03-10 00:04:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function LogoutCurrentLogginedUser() : bool
|
|
|
|
{
|
|
|
|
\RainLoop\Utils::ClearCookie('rlsession');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-11 01:45:00 +08:00
|
|
|
public static function ExitOnEnd() : void
|
2020-03-10 00:04:17 +08:00
|
|
|
{
|
|
|
|
if (!\defined('RAINLOOP_EXIT_ON_END'))
|
|
|
|
{
|
|
|
|
\define('RAINLOOP_EXIT_ON_END', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|