2015-02-13 01:54:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|
|
|
{
|
2021-02-10 16:50:20 +08:00
|
|
|
const
|
2021-08-28 05:49:03 +08:00
|
|
|
NAME = 'Demo Account Extension',
|
2021-02-10 16:50:20 +08:00
|
|
|
CATEGORY = 'Login',
|
2023-01-25 01:58:25 +08:00
|
|
|
REQUIRED = '2.25',
|
2021-08-28 05:49:03 +08:00
|
|
|
DESCRIPTION = 'Extension to enable a demo account';
|
2021-02-10 16:50:20 +08:00
|
|
|
|
2015-02-13 01:54:12 +08:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-08-31 00:04:54 +08:00
|
|
|
public function Init() : void
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
|
|
|
$this->addHook('filter.app-data', 'FilterAppData');
|
|
|
|
$this->addHook('filter.action-params', 'FilterActionParams');
|
2022-12-08 16:08:41 +08:00
|
|
|
$this->addHook('json.before-accountsetup', 'BeforeAccountSetup');
|
2015-02-13 01:54:12 +08:00
|
|
|
$this->addHook('filter.send-message', 'FilterSendMessage');
|
2015-02-13 03:56:06 +08:00
|
|
|
$this->addHook('main.fabrica', 'MainFabrica');
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-08-31 00:04:54 +08:00
|
|
|
protected function configMapping() : array
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('email')->SetLabel('Demo Email')
|
|
|
|
->SetDefaultValue('demo@domain.com'),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('Demo Password')
|
2022-02-28 23:13:41 +08:00
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('recipient_delimiter')->SetLabel('recipient_delimiter')
|
|
|
|
->SetDefaultValue(''),
|
2015-02-13 01:54:12 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function FilterAppData($bAdmin, &$aResult)
|
|
|
|
{
|
2022-10-04 16:04:41 +08:00
|
|
|
if (!$bAdmin && \is_array($aResult) && empty($aResult['Auth'])) {
|
2015-02-13 01:54:12 +08:00
|
|
|
$aResult['DevEmail'] = $this->Config()->Get('plugin', 'email', $aResult['DevEmail']);
|
2022-11-18 16:18:28 +08:00
|
|
|
$aResult['DevPassword'] = '********';
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function FilterActionParams($sMethodName, &$aActionParams)
|
|
|
|
{
|
2021-10-25 15:45:22 +08:00
|
|
|
if ('DoLogin' === $sMethodName
|
|
|
|
&& isset($aActionParams['Email'])
|
|
|
|
&& isset($aActionParams['Password'])
|
|
|
|
&& $this->Config()->Get('plugin', 'email') === $aActionParams['Email']) {
|
|
|
|
$aActionParams['Password'] = $this->Config()->Get('plugin', 'password');
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
2022-05-21 06:40:07 +08:00
|
|
|
else if ('DoFolderCreate' === $sMethodName || 'DoFolderRename' === $sMethodName) {
|
|
|
|
// Block spam https://github.com/the-djmaze/snappymail/issues/371
|
2023-01-25 01:58:25 +08:00
|
|
|
$latin = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $aActionParams['folder']);
|
2022-05-21 06:40:07 +08:00
|
|
|
if (false !== \strpos($latin, 'nigger')) {
|
2023-01-25 01:58:25 +08:00
|
|
|
\error_log("blocked {$sMethodName} {$aActionParams['folder']}");
|
2024-01-22 22:11:44 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
|
2022-05-21 06:40:07 +08:00
|
|
|
}
|
|
|
|
}
|
2023-12-25 23:07:59 +08:00
|
|
|
else if ('DoFolderClear' === $sMethodName || 'DoMessageDelete' === $sMethodName) {
|
2024-01-22 22:11:44 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
|
2023-12-25 23:07:59 +08:00
|
|
|
}
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \RainLoop\Model\Account $oAccount
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-12-15 20:06:30 +08:00
|
|
|
private function isDemoAccount()
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
2021-12-15 20:06:30 +08:00
|
|
|
$oAccount = $this->Manager()->Actions()->GetAccount();
|
2015-02-13 01:54:12 +08:00
|
|
|
return ($oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email'));
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:08:41 +08:00
|
|
|
public function BeforeAccountSetup()
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
2022-12-08 16:08:41 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
|
|
|
|
2021-08-18 18:25:17 +08:00
|
|
|
public function FilterSendMessage($oMessage)
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
2021-12-15 20:06:30 +08:00
|
|
|
if ($oMessage && $this->isDemoAccount()) {
|
2022-02-28 23:13:41 +08:00
|
|
|
$recipient_delimiter = $this->Config()->Get('plugin', 'recipient_delimiter');
|
|
|
|
$regex = '/^' . \preg_quote($this->Config()->Get('plugin', 'email')) . '$/D';
|
|
|
|
if ($recipient_delimiter) {
|
|
|
|
$regex = \str_replace('@', '('.\preg_quote($recipient_delimiter).'.+)?@', $regex);
|
|
|
|
}
|
2021-12-31 18:25:37 +08:00
|
|
|
foreach ($oMessage->GetTo() as $oEmail) {
|
2022-02-28 23:13:41 +08:00
|
|
|
if (!\preg_match($regex, $oEmail->GetEmail())) {
|
2021-12-31 18:25:37 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($oMessage->GetCc() ?: [] as $oEmail) {
|
2022-02-28 23:13:41 +08:00
|
|
|
if (!\preg_match($regex, $oEmail->GetEmail())) {
|
2021-12-31 18:25:37 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($oMessage->GetBcc() ?: [] as $oEmail) {
|
2022-02-28 23:13:41 +08:00
|
|
|
if (!\preg_match($regex, $oEmail->GetEmail())) {
|
2021-12-31 18:25:37 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $sName
|
|
|
|
* @param mixed $oDriver
|
|
|
|
*/
|
2015-02-13 03:56:06 +08:00
|
|
|
public function MainFabrica($sName, &$oDriver)
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
2021-11-09 00:40:21 +08:00
|
|
|
if ('storage' === $sName || 'storage-local' === $sName) {
|
2021-12-15 20:06:30 +08:00
|
|
|
require_once __DIR__ . '/storage.php';
|
|
|
|
$oDriver = new \DemoStorage(APP_PRIVATE_DATA.'storage', $sName === 'storage-local');
|
|
|
|
$oDriver->setDemoEmail($this->Config()->Get('plugin', 'email'));
|
2015-02-13 01:54:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|