mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Resolve #893
This commit is contained in:
parent
3396a3d791
commit
a86c143160
6 changed files with 15 additions and 22 deletions
|
|
@ -31,7 +31,7 @@ class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sDataPath .= '/' . \RainLoop\Utils::fixName(\RainLoop\Utils::GetConnectionToken());
|
$sDataPath .= '/' . \MailSo\Base\Utils::SecureFileName(\RainLoop\Utils::GetConnectionToken());
|
||||||
if (!\is_dir($sDataPath) && \mkdir($sDataPath, 0700, true)) {
|
if (!\is_dir($sDataPath) && \mkdir($sDataPath, 0700, true)) {
|
||||||
\file_put_contents("{$sDataPath}/settings",'{"RemoveColors":true,"ListInlineAttachments":true}');
|
\file_put_contents("{$sDataPath}/settings",'{"RemoveColors":true,"ListInlineAttachments":true}');
|
||||||
if (\mkdir($sDataPath.'/.gnupg/private-keys-v1.d', 0700, true)) {
|
if (\mkdir($sDataPath.'/.gnupg/private-keys-v1.d', 0700, true)) {
|
||||||
|
|
|
||||||
|
|
@ -490,11 +490,13 @@ abstract class Utils
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Replace ampersand, spaces and reserved characters (based on Win95 VFAT)
|
/**
|
||||||
# en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
* Replace control characters, ampersand and reserved characters (based on Win95 VFAT)
|
||||||
|
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||||
|
*/
|
||||||
public static function SecureFileName(string $sFileName) : string
|
public static function SecureFileName(string $sFileName) : string
|
||||||
{
|
{
|
||||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $sFileName);
|
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\pC]#su', '-', $sFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Trim(string $sValue) : string
|
public static function Trim(string $sValue) : string
|
||||||
|
|
|
||||||
|
|
@ -144,9 +144,9 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
|
||||||
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
|
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
|
||||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||||
$sFilePath = $this->sDataPath
|
$sFilePath = $this->sDataPath
|
||||||
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
|
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
|
||||||
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown')
|
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown')
|
||||||
.($sSubEmail ? '/'.\RainLoop\Utils::fixName($sSubEmail) : '')
|
.($sSubEmail ? '/'.\MailSo\Base\Utils::SecureFileName($sSubEmail) : '')
|
||||||
.'/.files/'.\sha1($sKey);
|
.'/.files/'.\sha1($sKey);
|
||||||
|
|
||||||
if ($bMkDir && !\is_dir(\dirname($sFilePath)) && !\mkdir(\dirname($sFilePath), 0700, true)) {
|
if ($bMkDir && !\is_dir(\dirname($sFilePath)) && !\mkdir(\dirname($sFilePath), 0700, true)) {
|
||||||
|
|
|
||||||
|
|
@ -137,9 +137,9 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
||||||
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
|
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
|
||||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||||
$sFilePath = $this->sDataPath
|
$sFilePath = $this->sDataPath
|
||||||
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
|
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
|
||||||
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown')
|
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown')
|
||||||
.'/'.($sSubFolder ? \RainLoop\Utils::fixName($sSubFolder).'/' : '');
|
.'/'.($sSubFolder ? \MailSo\Base\Utils::SecureFileName($sSubFolder).'/' : '');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \Exception("Invalid storage type {$iStorageType}");
|
throw new \Exception("Invalid storage type {$iStorageType}");
|
||||||
|
|
@ -163,7 +163,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
||||||
if (StorageType::NOBODY === $iStorageType) {
|
if (StorageType::NOBODY === $iStorageType) {
|
||||||
$sFilePath .= \sha1($sKey ?: \time());
|
$sFilePath .= \sha1($sKey ?: \time());
|
||||||
} else {
|
} else {
|
||||||
$sFilePath .= ($sKey ? \RainLoop\Utils::fixName($sKey) : '');
|
$sFilePath .= ($sKey ? \MailSo\Base\Utils::SecureFileName($sKey) : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $sFilePath;
|
return $sFilePath;
|
||||||
|
|
|
||||||
|
|
@ -275,15 +275,6 @@ class Utils
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace control characters, ampersand, spaces and reserved characters (based on Win95 VFAT)
|
|
||||||
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
|
||||||
*/
|
|
||||||
public static function fixName(string $filename) : string
|
|
||||||
{
|
|
||||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function saveFile(string $filename, string $data) : void
|
public static function saveFile(string $filename, string $data) : void
|
||||||
{
|
{
|
||||||
$dir = \dirname($filename);
|
$dir = \dirname($filename);
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ abstract class Upgrade
|
||||||
$aEmail = \explode('@', \basename($sDomainDir));
|
$aEmail = \explode('@', \basename($sDomainDir));
|
||||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||||
$sNewDir = $sDataPath
|
$sNewDir = $sDataPath
|
||||||
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
|
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
|
||||||
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown');
|
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown');
|
||||||
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
|
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
|
||||||
foreach (\glob("{$sDomainDir}/*") as $sItem) {
|
foreach (\glob("{$sDomainDir}/*") as $sItem) {
|
||||||
$sName = \basename($sItem);
|
$sName = \basename($sItem);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue