mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
Merge the RainLoop\Providers\Storage\FixFileStorage into SnappyMail\Upgrade
This commit is contained in:
parent
66d1cf02b9
commit
a50b537892
5 changed files with 47 additions and 73 deletions
|
|
@ -131,15 +131,6 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace control characters, ampersand, spaces and reserved characters (based on Win95 VFAT)
|
||||
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
*/
|
||||
private static function fixName($filename)
|
||||
{
|
||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
||||
}
|
||||
|
||||
private function generateFullFileName(\RainLoop\Model\Account $oAccount, string $sKey, bool $bMkDir = false) : string
|
||||
{
|
||||
if ($oAccount instanceof \RainLoop\Model\AdditionalAccount) {
|
||||
|
|
@ -153,9 +144,9 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
|
|||
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
|
||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||
$sFilePath = $this->sDataPath
|
||||
.'/'.static::fixName($sDomain ?: 'unknown.tld')
|
||||
.'/'.static::fixName(\implode('@', $aEmail) ?: '.unknown')
|
||||
.($sSubEmail ? '/'.static::fixName($sSubEmail) : '')
|
||||
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
|
||||
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown')
|
||||
.($sSubEmail ? '/'.\RainLoop\Utils::fixName($sSubEmail) : '')
|
||||
.'/.files/'.\sha1($sKey);
|
||||
|
||||
if ($bMkDir && !\is_dir(\dirname($sFilePath)) && !\mkdir(\dirname($sFilePath), 0700, true)) {
|
||||
|
|
|
|||
|
|
@ -85,15 +85,6 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
|||
return $this->bLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace control characters, ampersand, spaces and reserved characters (based on Win95 VFAT)
|
||||
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
*/
|
||||
protected static function fixName($filename)
|
||||
{
|
||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Model\Account|string|null $mAccount
|
||||
*/
|
||||
|
|
@ -125,15 +116,15 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
|||
return '';
|
||||
}
|
||||
if (\is_dir("{$this->sDataPath}/cfg")) {
|
||||
FixFileStorage::FixIt($this->sDataPath);
|
||||
\SnappyMail\Upgrade::FileStorage($this->sDataPath);
|
||||
}
|
||||
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
|
||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||
$sFilePath = $this->sDataPath
|
||||
.'/'.static::fixName($sDomain ?: 'unknown.tld')
|
||||
.'/'.static::fixName(\implode('@', $aEmail) ?: '.unknown')
|
||||
.'/'.($sSubEmail ? static::fixName($sSubEmail).'/' : '')
|
||||
.($sKey ? static::fixName($sKey) : '');
|
||||
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
|
||||
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown')
|
||||
.'/'.($sSubEmail ? \RainLoop\Utils::fixName($sSubEmail).'/' : '')
|
||||
.($sKey ? \RainLoop\Utils::fixName($sKey) : '');
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("Invalid storage type {$iStorageType}");
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Storage;
|
||||
|
||||
abstract class FixFileStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* Replace control characters, ampersand, spaces and reserved characters (based on Win95 VFAT)
|
||||
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
*/
|
||||
private static function fixName($filename)
|
||||
{
|
||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
||||
}
|
||||
|
||||
public static function FixIt(string $sDataPath)
|
||||
{
|
||||
// /cfg/ex/example@example.com
|
||||
foreach (\glob("{$sDataPath}/cfg/*", GLOB_ONLYDIR) as $sOldDir) {
|
||||
foreach (\glob("{$sOldDir}/*", GLOB_ONLYDIR) as $sDomainDir) {
|
||||
$aEmail = \explode('@', \basename($sDomainDir));
|
||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||
$sNewDir = $sDataPath
|
||||
.'/'.static::fixName($sDomain ?: 'unknown.tld')
|
||||
.'/'.static::fixName(\implode('@', $aEmail) ?: '.unknown');
|
||||
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
|
||||
foreach (\glob("{$sDomainDir}/*") as $sItem) {
|
||||
$sName = \basename($sItem);
|
||||
if ('sign_me' === $sName) {
|
||||
// Security issue
|
||||
// https://github.com/RainLoop/rainloop-webmail/issues/2133
|
||||
\unlink($sItem);
|
||||
} else {
|
||||
\rename($sItem, "{$sNewDir}/{$sName}");
|
||||
}
|
||||
}
|
||||
\MailSo\Base\Utils::RecRmDir($sDomainDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
\MailSo\Base\Utils::RecRmDir("{$sDataPath}/cfg");
|
||||
\MailSo\Base\Utils::RecRmDir("{$sDataPath}/data");
|
||||
\MailSo\Base\Utils::RecRmDir("{$sDataPath}/files");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -240,4 +240,13 @@ class Utils
|
|||
return @\parse_ini_file($sFileName, !!$bProcessSections) ?: array();
|
||||
// return @\parse_ini_string(\file_get_contents($sFileName), $bProcessSections) ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($filename)
|
||||
{
|
||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,36 @@ use RainLoop\Providers\Storage\Enumerations\StorageType;
|
|||
abstract class Upgrade
|
||||
{
|
||||
|
||||
public static function FileStorage(string $sDataPath)
|
||||
{
|
||||
// /cfg/ex/example@example.com
|
||||
foreach (\glob("{$sDataPath}/cfg/*", GLOB_ONLYDIR) as $sOldDir) {
|
||||
foreach (\glob("{$sOldDir}/*", GLOB_ONLYDIR) as $sDomainDir) {
|
||||
$aEmail = \explode('@', \basename($sDomainDir));
|
||||
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
|
||||
$sNewDir = $sDataPath
|
||||
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
|
||||
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown');
|
||||
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
|
||||
foreach (\glob("{$sDomainDir}/*") as $sItem) {
|
||||
$sName = \basename($sItem);
|
||||
if ('sign_me' === $sName) {
|
||||
// Security issue
|
||||
// https://github.com/RainLoop/rainloop-webmail/issues/2133
|
||||
\unlink($sItem);
|
||||
} else {
|
||||
\rename($sItem, "{$sNewDir}/{$sName}");
|
||||
}
|
||||
}
|
||||
\MailSo\Base\Utils::RecRmDir($sDomainDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
\MailSo\Base\Utils::RecRmDir("{$sDataPath}/cfg");
|
||||
\MailSo\Base\Utils::RecRmDir("{$sDataPath}/data");
|
||||
\MailSo\Base\Utils::RecRmDir("{$sDataPath}/files");
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to convert the old less secure data into better secured data
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue