snappymail/rainloop/v/0.0.0/app/libraries/RainLoop/Api.php

219 lines
5.8 KiB
PHP
Raw Normal View History

<?php
namespace RainLoop;
class Api
{
2020-03-16 20:08:53 +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)
{
static::SetupDefaultMailSoConfig();
$bOne = static::RunResult();
}
return $bOne;
}
2020-03-11 01:45:00 +08:00
public static function Actions() : Actions
{
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-11 01:45:00 +08:00
return static::Actions()->Config();
}
2020-03-16 20:08:53 +08:00
public static function Logger() : \MailSo\Log\Logger
{
2020-03-11 01:45:00 +08:00
return static::Actions()->Logger();
}
2020-03-11 01:45:00 +08:00
protected static function SetupDefaultMailSoConfig() : void
{
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);
\MailSo\Config::$MessageListCountLimitTrigger =
2020-03-11 01:45:00 +08:00
(int) static::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
\MailSo\Config::$MessageListDateFilter =
2020-03-11 01:45:00 +08:00
(int) static::Config()->Get('labs', 'imap_message_list_date_filter', 0);
\MailSo\Config::$MessageListPermanentFilter =
2020-03-11 01:45:00 +08:00
\trim(static::Config()->Get('labs', 'imap_message_list_permanent_filter', ''));
\MailSo\Config::$MessageAllHeaders =
2020-03-11 01:45:00 +08:00
!!static::Config()->Get('labs', 'imap_message_all_headers', false);
\MailSo\Config::$LargeThreadLimit =
2020-03-11 01:45:00 +08:00
(int) static::Config()->Get('labs', 'imap_large_thread_limit', 50);
\MailSo\Config::$ImapTimeout =
2020-03-11 01:45:00 +08:00
(int) static::Config()->Get('labs', 'imap_timeout', 300);
\MailSo\Config::$BoundaryPrefix = '_RainLoop_';
2020-03-11 01:45:00 +08:00
\MailSo\Config::$SystemLogger = static::Logger();
2020-03-11 01:45:00 +08:00
$sSslCafile = static::Config()->Get('ssl', 'cafile', '');
$sSslCapath = static::Config()->Get('ssl', 'capath', '');
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))
{
\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-11 01:45:00 +08:00
\MailSo\Config::$CheckNewMessages = !!static::Config()->Get('labs', 'check_new_messages', true);
2020-03-11 01:45:00 +08:00
if (static::Config()->Get('labs', 'strict_html_parser', true))
{
\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'
);
}
}
}
public static function Version() : string
{
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),
\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));
}
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();
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-11 01:45:00 +08:00
static::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
}
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
{
if (!\defined('RAINLOOP_EXIT_ON_END'))
{
\define('RAINLOOP_EXIT_ON_END', true);
}
}
}