mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Bugfix: demo plugin broken due to v2.9.6 changes
This commit is contained in:
parent
0905787f5f
commit
41a98d68c5
4 changed files with 32 additions and 14 deletions
|
|
@ -61,21 +61,22 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isDemoAccount($oAccount)
|
private function isDemoAccount()
|
||||||
{
|
{
|
||||||
|
$oAccount = $this->Manager()->Actions()->GetAccount();
|
||||||
return ($oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email'));
|
return ($oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function JsonActionPreCall($sAction)
|
public function JsonActionPreCall($sAction)
|
||||||
{
|
{
|
||||||
if ('AccountSetup' === $sAction && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) {
|
if ('AccountSetup' === $sAction && $this->isDemoAccount()) {
|
||||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FilterSendMessage($oMessage)
|
public function FilterSendMessage($oMessage)
|
||||||
{
|
{
|
||||||
if ($oMessage && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) {
|
if ($oMessage && $this->isDemoAccount()) {
|
||||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,12 +88,9 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
public function MainFabrica($sName, &$oDriver)
|
public function MainFabrica($sName, &$oDriver)
|
||||||
{
|
{
|
||||||
if ('storage' === $sName || 'storage-local' === $sName) {
|
if ('storage' === $sName || 'storage-local' === $sName) {
|
||||||
$oAccount = $this->Manager()->Actions()->GetAccount();
|
|
||||||
if ($this->isDemoAccount($oAccount)) {
|
|
||||||
require_once __DIR__ . '/storage.php';
|
require_once __DIR__ . '/storage.php';
|
||||||
$oDriver = new \DemoStorage(APP_PRIVATE_DATA.'storage', $sName === 'storage-local');
|
$oDriver = new \DemoStorage(APP_PRIVATE_DATA.'storage', $sName === 'storage-local');
|
||||||
|
$oDriver->setDemoEmail($this->Config()->Get('plugin', 'email'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use RainLoop\Providers\Storage\Enumerations\StorageType;
|
||||||
|
|
||||||
class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
|
class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -7,18 +9,36 @@ class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
|
||||||
*/
|
*/
|
||||||
protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
|
protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
|
||||||
{
|
{
|
||||||
if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) {
|
$sEmail = $sSubFolder = '';
|
||||||
|
if ($mAccount instanceof \RainLoop\Model\MainAccount) {
|
||||||
|
$sEmail = $mAccount->Email();
|
||||||
|
if (StorageType::SIGN_ME === $iStorageType) {
|
||||||
|
$sSubFolder = '/.sign_me';
|
||||||
|
} else if (StorageType::SESSION === $iStorageType) {
|
||||||
|
$sSubFolder = '/.sessions';
|
||||||
|
}
|
||||||
|
} else if (\is_string($mAccount)) {
|
||||||
|
$sEmail = $mAccount;
|
||||||
|
}
|
||||||
|
if ($sEmail != $this->sDemoEmail) {
|
||||||
return parent::generateFileName($mAccount, $iStorageType, $sKey, $bMkDir, $bForDeleteAction);
|
return parent::generateFileName($mAccount, $iStorageType, $sKey, $bMkDir, $bForDeleteAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sDataPath = "{$this->sDataPath}/demo";
|
$sDataPath = "{$this->sDataPath}/demo";
|
||||||
|
|
||||||
if (\is_dir($sDataPath) && 0 === \random_int(0, 100)) {
|
if (\is_dir($sDataPath) && 0 === \random_int(0, 100)) {
|
||||||
\MailSo\Base\Utils::RecRmDir("{$this->sDataPath}/demo");
|
\MailSo\Base\Utils::RecTimeDirRemove($sDataPath, 3600 * 3); // 3 hours
|
||||||
}
|
}
|
||||||
|
|
||||||
$sDataPath .= '/' . \RainLoop\Utils::fixName(\RainLoop\Utils::GetConnectionToken());
|
$sDataPath .= '/' . \RainLoop\Utils::fixName(\RainLoop\Utils::GetConnectionToken()) . $sSubFolder;
|
||||||
\is_dir($sDataPath) || \mkdir($sDataPath, 0700, true);
|
\is_dir($sDataPath) || \mkdir($sDataPath, 0700, true);
|
||||||
|
|
||||||
return $sDataPath . '/' . ($sKey ? \RainLoop\Utils::fixName($sKey) : '');
|
return $sDataPath . '/' . ($sKey ? \RainLoop\Utils::fixName($sKey) : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private $sDemoEmail;
|
||||||
|
public function setDemoEmail(string $sEmail)
|
||||||
|
{
|
||||||
|
$this->sDemoEmail = $sEmail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,7 @@ class Actions
|
||||||
if (false !== \strpos($sLine, '{user:uid}')) {
|
if (false !== \strpos($sLine, '{user:uid}')) {
|
||||||
$sLine = \str_replace('{user:uid}',
|
$sLine = \str_replace('{user:uid}',
|
||||||
Utils::UrlEncode(\base_convert(\sprintf('%u',
|
Utils::UrlEncode(\base_convert(\sprintf('%u',
|
||||||
\crc32(\md5(Utils::GetConnectionToken()))), 10, 32), $bUrlEncode),
|
\crc32(Utils::GetConnectionToken())), 10, 32), $bUrlEncode),
|
||||||
$sLine
|
$sLine
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
||||||
if ($this->bLocal && !$bForDeleteAction) {
|
if ($this->bLocal && !$bForDeleteAction) {
|
||||||
$sSubFolder = $mAccount->Email();
|
$sSubFolder = $mAccount->Email();
|
||||||
}
|
}
|
||||||
} else if (\is_string($mAccount) && empty($sEmail)) {
|
} else if (\is_string($mAccount)) {
|
||||||
$sEmail = $mAccount;
|
$sEmail = $mAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue