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',
|
2022-03-21 20:00:10 +08:00
|
|
|
REQUIRED = '2.14.0',
|
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');
|
2020-12-30 22:50:47 +08:00
|
|
|
$this->addHook('json.action-pre-call', 'JsonActionPreCall');
|
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)
|
|
|
|
{
|
2021-10-25 15:45:22 +08:00
|
|
|
if (!$bAdmin && \is_array($aResult) && isset($aResult['Auth']) && !$aResult['Auth']) {
|
2015-02-13 01:54:12 +08:00
|
|
|
$aResult['DevEmail'] = $this->Config()->Get('plugin', 'email', $aResult['DevEmail']);
|
|
|
|
$aResult['DevPassword'] = APP_DUMMY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
$latin = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $aActionParams['Folder']);
|
|
|
|
if (false !== \strpos($latin, 'nigger')) {
|
|
|
|
\error_log("blocked {$sMethodName} {$aActionParams['Folder']}");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
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'));
|
|
|
|
}
|
|
|
|
|
2020-12-30 22:50:47 +08:00
|
|
|
public function JsonActionPreCall($sAction)
|
2015-02-13 01:54:12 +08:00
|
|
|
{
|
2021-12-15 20:06:30 +08:00
|
|
|
if ('AccountSetup' === $sAction && $this->isDemoAccount()) {
|
2015-02-13 01:54:12 +08:00
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|