mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 08:27:03 +03:00
Improved support RFC 6855 / RFC 5738 (UTF8)
This commit is contained in:
parent
769ac33bcd
commit
361e991aea
8 changed files with 106 additions and 164 deletions
|
|
@ -204,34 +204,22 @@ END;
|
||||||
return $sInputString;
|
return $sInputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sFromEncoding === Enumerations\Charset::ISO_8859_1
|
if ($sToEncoding === Enumerations\Charset::UTF_8) {
|
||||||
&& $sToEncoding === Enumerations\Charset::UTF_8) {
|
if ($sFromEncoding === Enumerations\Charset::ISO_8859_1) {
|
||||||
return \utf8_encode($sInputString);
|
return \utf8_encode($sInputString);
|
||||||
|
}
|
||||||
|
if ($sFromEncoding === Enumerations\Charset::UTF_7_IMAP) {
|
||||||
|
return static::Utf7ModifiedToUtf8($sInputString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sFromEncoding === Enumerations\Charset::UTF_8
|
if ($sFromEncoding === Enumerations\Charset::UTF_8) {
|
||||||
&& $sToEncoding === Enumerations\Charset::ISO_8859_1) {
|
if ($sToEncoding === Enumerations\Charset::ISO_8859_1) {
|
||||||
return \utf8_decode($sInputString);
|
return \utf8_decode($sInputString);
|
||||||
}
|
}
|
||||||
|
if ($sToEncoding === Enumerations\Charset::UTF_7_IMAP) {
|
||||||
if ($sFromEncoding === Enumerations\Charset::UTF_7_IMAP
|
return static::Utf8ToUtf7Modified($sInputString);
|
||||||
&& $sToEncoding === Enumerations\Charset::UTF_8) {
|
}
|
||||||
$sResult = static::Utf7ModifiedToUtf8($sInputString);
|
|
||||||
return (false !== $sResult) ? $sResult : $sInputString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sFromEncoding === Enumerations\Charset::UTF_8
|
|
||||||
&& $sToEncoding === Enumerations\Charset::UTF_7_IMAP) {
|
|
||||||
$sResult = static::Utf8ToUtf7Modified($sInputString);
|
|
||||||
return (false !== $sResult) ? $sResult : $sInputString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sFromEncoding === Enumerations\Charset::UTF_7_IMAP) {
|
|
||||||
return static::ConvertEncoding(
|
|
||||||
static::ModifiedToPlainUtf7($sInputString),
|
|
||||||
Enumerations\Charset::UTF_7,
|
|
||||||
$sToEncoding
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::MbConvertEncoding($sInputString, $sFromEncoding, $sToEncoding);
|
return static::MbConvertEncoding($sInputString, $sFromEncoding, $sToEncoding);
|
||||||
|
|
@ -780,10 +768,12 @@ END;
|
||||||
case 'application/x-rar-compressed':
|
case 'application/x-rar-compressed':
|
||||||
case 'application/x-msdownload':
|
case 'application/x-msdownload':
|
||||||
case 'application/vnd.ms-cab-compressed':
|
case 'application/vnd.ms-cab-compressed':
|
||||||
|
case 'application/gzip':
|
||||||
case 'application/x-gzip':
|
case 'application/x-gzip':
|
||||||
case 'application/x-bzip':
|
case 'application/x-bzip':
|
||||||
case 'application/x-bzip2':
|
case 'application/x-bzip2':
|
||||||
case 'application/x-debian-package':
|
case 'application/x-debian-package':
|
||||||
|
case 'application/x-tar':
|
||||||
return 'archive';
|
return 'archive';
|
||||||
|
|
||||||
case 'application/msword':
|
case 'application/msword':
|
||||||
|
|
@ -808,6 +798,8 @@ END;
|
||||||
case 'zip':
|
case 'zip':
|
||||||
case '7z':
|
case '7z':
|
||||||
case 'rar':
|
case 'rar':
|
||||||
|
case 'tar':
|
||||||
|
case 'tgz':
|
||||||
return 'archive';
|
return 'archive';
|
||||||
|
|
||||||
case 'pdf':
|
case 'pdf':
|
||||||
|
|
@ -1328,62 +1320,22 @@ END;
|
||||||
return $mResult;
|
return $mResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function ModifiedToPlainUtf7(string $sUtfModifiedString) : string
|
|
||||||
{
|
|
||||||
$sUtf = '';
|
|
||||||
$bBase = false;
|
|
||||||
|
|
||||||
for ($iIndex = 0, $iLen = \strlen($sUtfModifiedString); $iIndex < $iLen; $iIndex++)
|
|
||||||
{
|
|
||||||
if ('&' === $sUtfModifiedString[$iIndex])
|
|
||||||
{
|
|
||||||
if (isset($sUtfModifiedString[$iIndex+1]) && '-' === $sUtfModifiedString[$iIndex + 1])
|
|
||||||
{
|
|
||||||
$sUtf .= '&';
|
|
||||||
$iIndex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sUtf .= '+';
|
|
||||||
$bBase = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ($sUtfModifiedString[$iIndex] == '-' && $bBase)
|
|
||||||
{
|
|
||||||
$bBase = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($bBase && ',' === $sUtfModifiedString[$iIndex])
|
|
||||||
{
|
|
||||||
$sUtf .= '/';
|
|
||||||
}
|
|
||||||
else if (!$bBase && '+' === $sUtfModifiedString[$iIndex])
|
|
||||||
{
|
|
||||||
$sUtf .= '+-';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sUtf .= $sUtfModifiedString[$iIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sUtf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function Utf7ModifiedToUtf8(string $sStr) : string
|
public static function Utf7ModifiedToUtf8(string $sStr) : string
|
||||||
{
|
{
|
||||||
return \is_callable('imap_mutf7_to_utf8')
|
$sResult = \is_callable('imap_mutf7_to_utf8')
|
||||||
? \imap_mutf7_to_utf8($sStr)
|
? \imap_mutf7_to_utf8($sStr)
|
||||||
: \mb_convert_encoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
: \mb_convert_encoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
||||||
|
// static::MbConvertEncoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
||||||
|
return (false === $sResult) ? $sStr : $sResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Utf8ToUtf7Modified(string $sStr) : string
|
public static function Utf8ToUtf7Modified(string $sStr) : string
|
||||||
{
|
{
|
||||||
return \is_callable('imap_utf8_to_mutf7')
|
$sResult = \is_callable('imap_utf8_to_mutf7')
|
||||||
? \imap_utf8_to_mutf7($sStr)
|
? \imap_utf8_to_mutf7($sStr)
|
||||||
: \mb_convert_encoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
: \mb_convert_encoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
||||||
|
// static::MbConvertEncoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
||||||
|
return (false === $sResult) ? $sStr : $sResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function FunctionExistsAndEnabled($mFunctionNameOrNames) : bool
|
public static function FunctionExistsAndEnabled($mFunctionNameOrNames) : bool
|
||||||
|
|
|
||||||
|
|
@ -84,16 +84,16 @@ class ResponseCollection extends \MailSo\Base\Collection
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ('STATUS' === $oResponse->StatusOrIndex && isset($oResponse->ResponseList[2])) {
|
if ('STATUS' === $oResponse->StatusOrIndex && isset($oResponse->ResponseList[2])) {
|
||||||
$sFullNameRaw = $oImapClient->toUTF8($oResponse->ResponseList[2]);
|
$sFullName = $oImapClient->toUTF8($oResponse->ResponseList[2]);
|
||||||
if (!isset($aReturn[$sFullNameRaw])) {
|
if (!isset($aReturn[$sFullName])) {
|
||||||
$aReturn[$sFullNameRaw] = new Folder($sFullNameRaw);
|
$aReturn[$sFullName] = new Folder($sFullName);
|
||||||
}
|
}
|
||||||
$aReturn[$sFullNameRaw]->setStatusFromResponse($oResponse);
|
$aReturn[$sFullName]->setStatusFromResponse($oResponse);
|
||||||
}
|
}
|
||||||
else if ($sStatus === $oResponse->StatusOrIndex && 5 == \count($oResponse->ResponseList)) {
|
else if ($sStatus === $oResponse->StatusOrIndex && 5 == \count($oResponse->ResponseList)) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$sFullNameRaw = $oImapClient->toUTF8($oResponse->ResponseList[4]);
|
$sFullName = $oImapClient->toUTF8($oResponse->ResponseList[4]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $oResponse->ResponseList[0] = *
|
* $oResponse->ResponseList[0] = *
|
||||||
|
|
@ -102,12 +102,12 @@ class ResponseCollection extends \MailSo\Base\Collection
|
||||||
* $oResponse->ResponseList[3] = Delimiter
|
* $oResponse->ResponseList[3] = Delimiter
|
||||||
* $oResponse->ResponseList[4] = FullName
|
* $oResponse->ResponseList[4] = FullName
|
||||||
*/
|
*/
|
||||||
if (!isset($aReturn[$sFullNameRaw])) {
|
if (!isset($aReturn[$sFullName])) {
|
||||||
$oFolder = new Folder($sFullNameRaw,
|
$oFolder = new Folder($sFullName,
|
||||||
$oResponse->ResponseList[3], $oResponse->ResponseList[2]);
|
$oResponse->ResponseList[3], $oResponse->ResponseList[2]);
|
||||||
$aReturn[$sFullNameRaw] = $oFolder;
|
$aReturn[$sFullName] = $oFolder;
|
||||||
} else {
|
} else {
|
||||||
$oFolder = $aReturn[$sFullNameRaw];
|
$oFolder = $aReturn[$sFullName];
|
||||||
$oFolder->setDelimiter($oResponse->ResponseList[3]);
|
$oFolder->setDelimiter($oResponse->ResponseList[3]);
|
||||||
$oFolder->setFlags($oResponse->ResponseList[2]);
|
$oFolder->setFlags($oResponse->ResponseList[2]);
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +120,7 @@ class ResponseCollection extends \MailSo\Base\Collection
|
||||||
$sDelimiter = $oFolder->Delimiter();
|
$sDelimiter = $oFolder->Delimiter();
|
||||||
}
|
}
|
||||||
|
|
||||||
$aReturn[$sFullNameRaw] = $oFolder;
|
$aReturn[$sFullName] = $oFolder;
|
||||||
}
|
}
|
||||||
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException)
|
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,10 @@ class Folder implements \JsonSerializable
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public static function NewNonExistentInstance(string $sFullNameRaw, string $sDelimiter) : self
|
public static function NewNonExistentInstance(string $sFullName, string $sDelimiter) : self
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
new \MailSo\Imap\Folder($sFullNameRaw, $sDelimiter, array('\\Noselect')), false, false);
|
new \MailSo\Imap\Folder($sFullName, $sDelimiter, array('\\Noselect')), false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Name() : string
|
public function Name() : string
|
||||||
|
|
|
||||||
|
|
@ -52,19 +52,19 @@ class FolderCollection extends \MailSo\Base\Collection
|
||||||
parent::append($oFolder, $bToTop);
|
parent::append($oFolder, $bToTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetByFullNameRaw(string $sFullNameRaw) : ?Folder
|
public function GetByFullName(string $sFullName) : ?Folder
|
||||||
{
|
{
|
||||||
$mResult = null;
|
$mResult = null;
|
||||||
foreach ($this as $oFolder)
|
foreach ($this as $oFolder)
|
||||||
{
|
{
|
||||||
if ($oFolder->FullName() === $sFullNameRaw)
|
if ($oFolder->FullName() === $sFullName)
|
||||||
{
|
{
|
||||||
$mResult = $oFolder;
|
$mResult = $oFolder;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if ($oFolder->HasSubFolders())
|
else if ($oFolder->HasSubFolders())
|
||||||
{
|
{
|
||||||
$mResult = $oFolder->SubFolders(true)->GetByFullNameRaw($sFullNameRaw);
|
$mResult = $oFolder->SubFolders(true)->GetByFullName($sFullName);
|
||||||
if ($mResult)
|
if ($mResult)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
@ -99,7 +99,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
||||||
{
|
{
|
||||||
$sDelimiter = '/';
|
$sDelimiter = '/';
|
||||||
|
|
||||||
$oFolder = $this->GetByFullNameRaw('INBOX');
|
$oFolder = $this->GetByFullName('INBOX');
|
||||||
if (!$oFolder && isset($this[0]))
|
if (!$oFolder && isset($this[0]))
|
||||||
{
|
{
|
||||||
$oFolder = $this[0];
|
$oFolder = $this[0];
|
||||||
|
|
|
||||||
|
|
@ -1273,18 +1273,18 @@ class MailClient
|
||||||
{
|
{
|
||||||
\array_pop($aFolderExplode);
|
\array_pop($aFolderExplode);
|
||||||
|
|
||||||
$sNonExistentFolderFullNameRaw = '';
|
$sNonExistentFolderFullName = '';
|
||||||
foreach ($aFolderExplode as $sFolderExplodeItem)
|
foreach ($aFolderExplode as $sFolderExplodeItem)
|
||||||
{
|
{
|
||||||
$sNonExistentFolderFullNameRaw .= \strlen($sNonExistentFolderFullNameRaw)
|
$sNonExistentFolderFullName .= \strlen($sNonExistentFolderFullName)
|
||||||
? $sDelimiter.$sFolderExplodeItem : $sFolderExplodeItem;
|
? $sDelimiter.$sFolderExplodeItem : $sFolderExplodeItem;
|
||||||
|
|
||||||
if (!isset($aSortedByLenImapFolders[$sNonExistentFolderFullNameRaw]))
|
if (!isset($aSortedByLenImapFolders[$sNonExistentFolderFullName]))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$aAddedFolders[$sNonExistentFolderFullNameRaw] =
|
$aAddedFolders[$sNonExistentFolderFullName] =
|
||||||
Folder::NewNonExistentInstance($sNonExistentFolderFullNameRaw, $sDelimiter);
|
Folder::NewNonExistentInstance($sNonExistentFolderFullName, $sDelimiter);
|
||||||
}
|
}
|
||||||
catch (\Throwable $oExc)
|
catch (\Throwable $oExc)
|
||||||
{
|
{
|
||||||
|
|
@ -1325,52 +1325,48 @@ class MailClient
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullNameRaw = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : self
|
public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullName = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : self
|
||||||
{
|
{
|
||||||
$sFolderNameInUtf8 = \trim($sFolderNameInUtf8);
|
$sFolderNameInUtf8 = \trim($sFolderNameInUtf8);
|
||||||
$sFolderParentFullNameRaw = \trim($sFolderParentFullNameRaw);
|
$sFolderParentFullName = \trim($sFolderParentFullName);
|
||||||
|
|
||||||
if (!\strlen($sFolderNameInUtf8))
|
if (!\strlen($sFolderNameInUtf8))
|
||||||
{
|
{
|
||||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\strlen($sDelimiter) || \strlen($sFolderParentFullNameRaw))
|
if (!\strlen($sDelimiter) || \strlen($sFolderParentFullName))
|
||||||
{
|
{
|
||||||
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sFolderParentFullNameRaw);
|
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sFolderParentFullName);
|
||||||
if (null === $sDelimiter)
|
if (null === $sDelimiter)
|
||||||
{
|
{
|
||||||
// TODO: Translate
|
// TODO: Translate
|
||||||
throw new Exceptions\RuntimeException(
|
throw new Exceptions\RuntimeException(
|
||||||
\strlen($sFolderParentFullNameRaw)
|
\strlen($sFolderParentFullName)
|
||||||
? 'Cannot create folder in non-existent parent folder.'
|
? 'Cannot create folder in non-existent parent folder.'
|
||||||
: 'Cannot get folder delimiter.');
|
: 'Cannot get folder delimiter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\strlen($sDelimiter) && \strlen($sFolderParentFullNameRaw))
|
if (\strlen($sDelimiter) && \strlen($sFolderParentFullName))
|
||||||
{
|
{
|
||||||
$sFolderParentFullNameRaw .= $sDelimiter;
|
$sFolderParentFullName .= $sDelimiter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sFullNameRawToCreate = \MailSo\Base\Utils::ConvertEncoding($sFolderNameInUtf8,
|
if (\strlen($sDelimiter) && false !== \strpos($sFolderNameInUtf8, $sDelimiter))
|
||||||
\MailSo\Base\Enumerations\Charset::UTF_8,
|
|
||||||
\MailSo\Base\Enumerations\Charset::UTF_7_IMAP);
|
|
||||||
|
|
||||||
if (\strlen($sDelimiter) && false !== \strpos($sFullNameRawToCreate, $sDelimiter))
|
|
||||||
{
|
{
|
||||||
// TODO: Translate
|
// TODO: Translate
|
||||||
throw new Exceptions\RuntimeException(
|
throw new Exceptions\RuntimeException(
|
||||||
'New folder name contains delimiter.');
|
'New folder name contains delimiter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sFullNameRawToCreate = $sFolderParentFullNameRaw.$sFullNameRawToCreate;
|
$sFullNameToCreate = $sFolderParentFullName.$sFolderNameInUtf8;
|
||||||
|
|
||||||
$this->oImapClient->FolderCreate($sFullNameRawToCreate);
|
$this->oImapClient->FolderCreate($sFullNameToCreate);
|
||||||
|
|
||||||
if ($bSubscribeOnCreation)
|
if ($bSubscribeOnCreation)
|
||||||
{
|
{
|
||||||
$this->oImapClient->FolderSubscribe($sFullNameRawToCreate);
|
$this->oImapClient->FolderSubscribe($sFullNameToCreate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -1379,76 +1375,72 @@ class MailClient
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function FolderMove(string $sPrevFolderFullNameRaw, string $sNextFolderFullNameInUtf, bool $bSubscribeOnMove = true) : self
|
public function FolderMove(string $sPrevFolderFullName, string $sNextFolderFullNameInUtf, bool $bSubscribeOnMove = true) : self
|
||||||
{
|
{
|
||||||
return $this->folderModify($sPrevFolderFullNameRaw, $sNextFolderFullNameInUtf, false, $bSubscribeOnMove);
|
return $this->folderModify($sPrevFolderFullName, $sNextFolderFullNameInUtf, false, $bSubscribeOnMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function FolderRename(string $sPrevFolderFullNameRaw, string $sNewTopFolderNameInUtf, bool $bSubscribeOnRename = true) : self
|
public function FolderRename(string $sPrevFolderFullName, string $sNewTopFolderNameInUtf, bool $bSubscribeOnRename = true) : self
|
||||||
{
|
{
|
||||||
return $this->folderModify($sPrevFolderFullNameRaw, $sNewTopFolderNameInUtf, true, $bSubscribeOnRename);
|
return $this->folderModify($sPrevFolderFullName, $sNewTopFolderNameInUtf, true, $bSubscribeOnRename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
* @throws \MailSo\Base\Exceptions\RuntimeException
|
* @throws \MailSo\Base\Exceptions\RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function folderModify(string $sPrevFolderFullNameRaw, string $sNextFolderNameInUtf, bool $bRename, bool $bSubscribeOnModify) : self
|
protected function folderModify(string $sPrevFolderFullName, string $sNextFolderNameInUtf, bool $bRename, bool $bSubscribeOnModify) : self
|
||||||
{
|
{
|
||||||
if (!\strlen($sPrevFolderFullNameRaw) || !\strlen($sNextFolderNameInUtf))
|
if (!\strlen($sPrevFolderFullName) || !\strlen($sNextFolderNameInUtf))
|
||||||
{
|
{
|
||||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sPrevFolderFullNameRaw);
|
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sPrevFolderFullName);
|
||||||
if (!$sDelimiter)
|
if (!$sDelimiter)
|
||||||
{
|
{
|
||||||
// TODO: Translate
|
// TODO: Translate
|
||||||
throw new Exceptions\RuntimeException('Cannot '.($bRename?'rename':'move').' non-existent folder.');
|
throw new Exceptions\RuntimeException('Cannot '.($bRename?'rename':'move').' non-existent folder.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$iLast = \strrpos($sPrevFolderFullNameRaw, $sDelimiter);
|
$iLast = \strrpos($sPrevFolderFullName, $sDelimiter);
|
||||||
|
|
||||||
$aSubscribeFolders = array();
|
$aSubscribeFolders = array();
|
||||||
if ($bSubscribeOnModify)
|
if ($bSubscribeOnModify)
|
||||||
{
|
{
|
||||||
$aSubscribeFolders = $this->oImapClient->FolderSubscribeList($sPrevFolderFullNameRaw, '*');
|
$aSubscribeFolders = $this->oImapClient->FolderSubscribeList($sPrevFolderFullName, '*');
|
||||||
foreach ($aSubscribeFolders as /* @var $oFolder \MailSo\Imap\Folder */ $oFolder)
|
foreach ($aSubscribeFolders as /* @var $oFolder \MailSo\Imap\Folder */ $oFolder)
|
||||||
{
|
{
|
||||||
$this->oImapClient->FolderUnSubscribe($oFolder->FullName());
|
$this->oImapClient->FolderUnSubscribe($oFolder->FullName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sNewFolderFullNameRaw = \MailSo\Base\Utils::ConvertEncoding($sNextFolderNameInUtf,
|
|
||||||
\MailSo\Base\Enumerations\Charset::UTF_8,
|
|
||||||
\MailSo\Base\Enumerations\Charset::UTF_7_IMAP);
|
|
||||||
|
|
||||||
if ($bRename)
|
if ($bRename)
|
||||||
{
|
{
|
||||||
if (\strlen($sDelimiter) && false !== \strpos($sNewFolderFullNameRaw, $sDelimiter))
|
if (\strlen($sDelimiter) && false !== \strpos($sNewFolderFullName, $sDelimiter))
|
||||||
{
|
{
|
||||||
// TODO: Translate
|
// TODO: Translate
|
||||||
throw new Exceptions\RuntimeException('New folder name contains delimiter.');
|
throw new Exceptions\RuntimeException('New folder name contains delimiter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sFolderParentFullNameRaw = false === $iLast ? '' : \substr($sPrevFolderFullNameRaw, 0, $iLast + 1);
|
$sFolderParentFullName = false === $iLast ? '' : \substr($sPrevFolderFullName, 0, $iLast + 1);
|
||||||
$sNewFolderFullNameRaw = $sFolderParentFullNameRaw.$sNewFolderFullNameRaw;
|
$sNewFolderFullName = $sFolderParentFullName.$sNewFolderFullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oImapClient->FolderRename($sPrevFolderFullNameRaw, $sNewFolderFullNameRaw);
|
$this->oImapClient->FolderRename($sPrevFolderFullName, $sNewFolderFullName);
|
||||||
|
|
||||||
foreach ($aSubscribeFolders as /* @var $oFolder \MailSo\Imap\Folder */ $oFolder)
|
foreach ($aSubscribeFolders as /* @var $oFolder \MailSo\Imap\Folder */ $oFolder)
|
||||||
{
|
{
|
||||||
$sFolderFullNameRawForResubscrine = $oFolder->FullName();
|
$sFolderFullNameForResubscrine = $oFolder->FullName();
|
||||||
if (0 === \strpos($sFolderFullNameRawForResubscrine, $sPrevFolderFullNameRaw))
|
if (0 === \strpos($sFolderFullNameForResubscrine, $sPrevFolderFullName))
|
||||||
{
|
{
|
||||||
$sNewFolderFullNameRawForResubscrine = $sNewFolderFullNameRaw.
|
$sNewFolderFullNameForResubscrine = $sNewFolderFullName.
|
||||||
\substr($sFolderFullNameRawForResubscrine, \strlen($sPrevFolderFullNameRaw));
|
\substr($sFolderFullNameForResubscrine, \strlen($sPrevFolderFullName));
|
||||||
|
|
||||||
$this->oImapClient->FolderSubscribe($sNewFolderFullNameRawForResubscrine);
|
$this->oImapClient->FolderSubscribe($sNewFolderFullNameForResubscrine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1459,14 +1451,14 @@ class MailClient
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
* @throws \MailSo\Mail\Exceptions\RuntimeException
|
* @throws \MailSo\Mail\Exceptions\RuntimeException
|
||||||
*/
|
*/
|
||||||
public function FolderDelete(string $sFolderFullNameRaw, bool $bUnsubscribeOnDeletion = true) : self
|
public function FolderDelete(string $sFolderFullName, bool $bUnsubscribeOnDeletion = true) : self
|
||||||
{
|
{
|
||||||
if (!\strlen($sFolderFullNameRaw) || 'INBOX' === $sFolderFullNameRaw)
|
if (!\strlen($sFolderFullName) || 'INBOX' === $sFolderFullName)
|
||||||
{
|
{
|
||||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oImapClient->FolderExamine($sFolderFullNameRaw);
|
$this->oImapClient->FolderExamine($sFolderFullName);
|
||||||
|
|
||||||
$aIndexOrUids = $this->oImapClient->MessageSimpleSearch('ALL');
|
$aIndexOrUids = $this->oImapClient->MessageSimpleSearch('ALL');
|
||||||
if (\count($aIndexOrUids))
|
if (\count($aIndexOrUids))
|
||||||
|
|
@ -1478,10 +1470,10 @@ class MailClient
|
||||||
|
|
||||||
if ($bUnsubscribeOnDeletion)
|
if ($bUnsubscribeOnDeletion)
|
||||||
{
|
{
|
||||||
$this->oImapClient->FolderUnSubscribe($sFolderFullNameRaw);
|
$this->oImapClient->FolderUnSubscribe($sFolderFullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oImapClient->FolderDelete($sFolderFullNameRaw);
|
$this->oImapClient->FolderDelete($sFolderFullName);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -1489,9 +1481,9 @@ class MailClient
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function FolderClear(string $sFolderFullNameRaw) : self
|
public function FolderClear(string $sFolderFullName) : self
|
||||||
{
|
{
|
||||||
$this->oImapClient->FolderSelect($sFolderFullNameRaw);
|
$this->oImapClient->FolderSelect($sFolderFullName);
|
||||||
|
|
||||||
$oFolderInformation = $this->oImapClient->FolderCurrentInformation();
|
$oFolderInformation = $this->oImapClient->FolderCurrentInformation();
|
||||||
if ($oFolderInformation && 0 < $oFolderInformation->MESSAGES)
|
if ($oFolderInformation && 0 < $oFolderInformation->MESSAGES)
|
||||||
|
|
@ -1510,14 +1502,14 @@ class MailClient
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function FolderSubscribe(string $sFolderFullNameRaw, bool $bSubscribe) : self
|
public function FolderSubscribe(string $sFolderFullName, bool $bSubscribe) : self
|
||||||
{
|
{
|
||||||
if (!\strlen($sFolderFullNameRaw))
|
if (!\strlen($sFolderFullName))
|
||||||
{
|
{
|
||||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oImapClient->{($bSubscribe) ? 'FolderSubscribe' : 'FolderUnSubscribe'}($sFolderFullNameRaw);
|
$this->oImapClient->{$bSubscribe ? 'FolderSubscribe' : 'FolderUnSubscribe'}($sFolderFullName);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ class Message implements \JsonSerializable
|
||||||
$oHeaders->SetParentCharset($sCharset);
|
$oHeaders->SetParentCharset($sCharset);
|
||||||
}
|
}
|
||||||
|
|
||||||
$bCharsetAutoDetect = 0 === \strlen($sCharset);
|
$bCharsetAutoDetect = !\strlen($sCharset);
|
||||||
|
|
||||||
$this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
|
$this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
|
||||||
$this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
|
$this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
|
||||||
|
|
@ -386,11 +386,11 @@ class Message implements \JsonSerializable
|
||||||
// Priority
|
// Priority
|
||||||
$this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::NORMAL;
|
$this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::NORMAL;
|
||||||
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY);
|
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY);
|
||||||
if (0 === \strlen($sPriority))
|
if (!\strlen($sPriority))
|
||||||
{
|
{
|
||||||
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IMPORTANCE);
|
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IMPORTANCE);
|
||||||
}
|
}
|
||||||
if (0 === \strlen($sPriority))
|
if (!\strlen($sPriority))
|
||||||
{
|
{
|
||||||
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_PRIORITY);
|
$sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
@ -514,13 +514,13 @@ class Message implements \JsonSerializable
|
||||||
}
|
}
|
||||||
else if ($oFetchResponse->GetEnvelope())
|
else if ($oFetchResponse->GetEnvelope())
|
||||||
{
|
{
|
||||||
if (0 === \strlen($sCharset) && $oBodyStructure)
|
if (!\strlen($sCharset) && $oBodyStructure)
|
||||||
{
|
{
|
||||||
$sCharset = $oBodyStructure->SearchCharset();
|
$sCharset = $oBodyStructure->SearchCharset();
|
||||||
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
|
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === \strlen($sCharset))
|
if (!\strlen($sCharset))
|
||||||
{
|
{
|
||||||
$sCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1;
|
$sCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1;
|
||||||
}
|
}
|
||||||
|
|
@ -559,7 +559,7 @@ class Message implements \JsonSerializable
|
||||||
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
|
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
|
||||||
if ($aTextParts)
|
if ($aTextParts)
|
||||||
{
|
{
|
||||||
if (0 === \strlen($sCharset))
|
if (!\strlen($sCharset))
|
||||||
{
|
{
|
||||||
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
|
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1370,7 +1370,7 @@ class Actions
|
||||||
{
|
{
|
||||||
$oAccount = $this->initMailClientConnection();
|
$oAccount = $this->initMailClientConnection();
|
||||||
|
|
||||||
$sFolderFullNameRaw = $this->GetActionParam('Folder', '');
|
$sFolderFullName = $this->GetActionParam('Folder', '');
|
||||||
|
|
||||||
$_FILES = isset($_FILES) ? $_FILES : null;
|
$_FILES = isset($_FILES) ? $_FILES : null;
|
||||||
if ($oAccount &&
|
if ($oAccount &&
|
||||||
|
|
@ -1378,15 +1378,15 @@ class Actions
|
||||||
isset($_FILES, $_FILES['AppendFile'], $_FILES['AppendFile']['name'],
|
isset($_FILES, $_FILES['AppendFile'], $_FILES['AppendFile']['name'],
|
||||||
$_FILES['AppendFile']['tmp_name'], $_FILES['AppendFile']['size'])) {
|
$_FILES['AppendFile']['tmp_name'], $_FILES['AppendFile']['size'])) {
|
||||||
if (is_string($_FILES['AppendFile']['tmp_name']) && \strlen($_FILES['AppendFile']['tmp_name'])) {
|
if (is_string($_FILES['AppendFile']['tmp_name']) && \strlen($_FILES['AppendFile']['tmp_name'])) {
|
||||||
if (\UPLOAD_ERR_OK === (int)$_FILES['AppendFile']['error'] && !empty($sFolderFullNameRaw)) {
|
if (\UPLOAD_ERR_OK === (int)$_FILES['AppendFile']['error'] && !empty($sFolderFullName)) {
|
||||||
$sSavedName = 'append-post-' . md5($sFolderFullNameRaw . $_FILES['AppendFile']['name'] . $_FILES['AppendFile']['tmp_name']);
|
$sSavedName = 'append-post-' . md5($sFolderFullName . $_FILES['AppendFile']['name'] . $_FILES['AppendFile']['tmp_name']);
|
||||||
|
|
||||||
if ($this->FilesProvider()->MoveUploadedFile($oAccount,
|
if ($this->FilesProvider()->MoveUploadedFile($oAccount,
|
||||||
$sSavedName, $_FILES['AppendFile']['tmp_name'])) {
|
$sSavedName, $_FILES['AppendFile']['tmp_name'])) {
|
||||||
$iMessageStreamSize = $this->FilesProvider()->FileSize($oAccount, $sSavedName);
|
$iMessageStreamSize = $this->FilesProvider()->FileSize($oAccount, $sSavedName);
|
||||||
$rMessageStream = $this->FilesProvider()->GetFile($oAccount, $sSavedName);
|
$rMessageStream = $this->FilesProvider()->GetFile($oAccount, $sSavedName);
|
||||||
|
|
||||||
$this->MailClient()->MessageAppendStream($rMessageStream, $iMessageStreamSize, $sFolderFullNameRaw);
|
$this->MailClient()->MessageAppendStream($rMessageStream, $iMessageStreamSize, $sFolderFullName);
|
||||||
|
|
||||||
$this->FilesProvider()->Clear($oAccount, $sSavedName);
|
$this->FilesProvider()->Clear($oAccount, $sSavedName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,15 +125,13 @@ trait Folders
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sFullNameToCheck = \MailSo\Base\Utils::ConvertEncoding($mFolderNameToCreate,
|
$sFullNameToCheck = $mFolderNameToCreate;
|
||||||
\MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::UTF_7_IMAP);
|
|
||||||
|
|
||||||
if (\strlen(\trim($sParent)))
|
if (\strlen(\trim($sParent)))
|
||||||
{
|
{
|
||||||
$sFullNameToCheck = $sParent.$sDelimiter.$sFullNameToCheck;
|
$sFullNameToCheck = $sParent.$sDelimiter.$sFullNameToCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$oFolderCollection->GetByFullNameRaw($sFullNameToCheck))
|
if (!$oFolderCollection->GetByFullName($sFullNameToCheck))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -182,9 +180,9 @@ trait Folders
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$sFolderNameInUtf = $this->GetActionParam('Folder', '');
|
$sFolderNameInUtf = $this->GetActionParam('Folder', '');
|
||||||
$sFolderParentFullNameRaw = $this->GetActionParam('Parent', '');
|
$sFolderParentFullName = $this->GetActionParam('Parent', '');
|
||||||
|
|
||||||
$this->MailClient()->FolderCreate($sFolderNameInUtf, $sFolderParentFullNameRaw,
|
$this->MailClient()->FolderCreate($sFolderNameInUtf, $sFolderParentFullName,
|
||||||
!!$this->Config()->Get('labs', 'use_imap_list_subscribe', true));
|
!!$this->Config()->Get('labs', 'use_imap_list_subscribe', true));
|
||||||
}
|
}
|
||||||
catch (\Throwable $oException)
|
catch (\Throwable $oException)
|
||||||
|
|
@ -198,10 +196,10 @@ trait Folders
|
||||||
public function DoFolderSetMetadata() : array
|
public function DoFolderSetMetadata() : array
|
||||||
{
|
{
|
||||||
$this->initMailClientConnection();
|
$this->initMailClientConnection();
|
||||||
$sFolderFullNameRaw = $this->GetActionParam('Folder');
|
$sFolderFullName = $this->GetActionParam('Folder');
|
||||||
$sMetadataKey = $this->GetActionParam('Key');
|
$sMetadataKey = $this->GetActionParam('Key');
|
||||||
if ($sFolderFullNameRaw && $sMetadataKey) {
|
if ($sFolderFullName && $sMetadataKey) {
|
||||||
$this->MailClient()->FolderSetMetadata($sFolderFullNameRaw, [
|
$this->MailClient()->FolderSetMetadata($sFolderFullName, [
|
||||||
$sMetadataKey => $this->GetActionParam('Value') ?: null
|
$sMetadataKey => $this->GetActionParam('Value') ?: null
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -212,12 +210,12 @@ trait Folders
|
||||||
{
|
{
|
||||||
$this->initMailClientConnection();
|
$this->initMailClientConnection();
|
||||||
|
|
||||||
$sFolderFullNameRaw = $this->GetActionParam('Folder', '');
|
$sFolderFullName = $this->GetActionParam('Folder', '');
|
||||||
$bSubscribe = '1' === (string) $this->GetActionParam('Subscribe', '0');
|
$bSubscribe = '1' === (string) $this->GetActionParam('Subscribe', '0');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->MailClient()->FolderSubscribe($sFolderFullNameRaw, $bSubscribe);
|
$this->MailClient()->FolderSubscribe($sFolderFullName, $bSubscribe);
|
||||||
}
|
}
|
||||||
catch (\Throwable $oException)
|
catch (\Throwable $oException)
|
||||||
{
|
{
|
||||||
|
|
@ -238,7 +236,7 @@ trait Folders
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken();
|
$oAccount = $this->getAccountFromToken();
|
||||||
|
|
||||||
$sFolderFullNameRaw = $this->GetActionParam('Folder', '');
|
$sFolderFullName = $this->GetActionParam('Folder', '');
|
||||||
$bCheckable = '1' === (string) $this->GetActionParam('Checkable', '0');
|
$bCheckable = '1' === (string) $this->GetActionParam('Checkable', '0');
|
||||||
|
|
||||||
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
||||||
|
|
@ -253,14 +251,14 @@ trait Folders
|
||||||
|
|
||||||
if ($bCheckable)
|
if ($bCheckable)
|
||||||
{
|
{
|
||||||
$aCheckableFolder[] = $sFolderFullNameRaw;
|
$aCheckableFolder[] = $sFolderFullName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aCheckableFolderNew = array();
|
$aCheckableFolderNew = array();
|
||||||
foreach ($aCheckableFolder as $sFolder)
|
foreach ($aCheckableFolder as $sFolder)
|
||||||
{
|
{
|
||||||
if ($sFolder !== $sFolderFullNameRaw)
|
if ($sFolder !== $sFolderFullName)
|
||||||
{
|
{
|
||||||
$aCheckableFolderNew[] = $sFolder;
|
$aCheckableFolderNew[] = $sFolder;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue