Replace "$IndexRange, bool $bIndexIsUid" with new SequenceSet class

This commit is contained in:
djmaze 2022-01-05 11:09:36 +01:00
parent 46317b5007
commit 64858d285d
6 changed files with 183 additions and 200 deletions

View file

@ -1037,52 +1037,6 @@ abstract class Utils
return $aResult;
}
public static function PrepareFetchSequence(array $aSequence) : string
{
$aResult = array();
if (\count($aSequence))
{
$iStart = null;
$iPrev = null;
foreach ($aSequence as $sItem)
{
// simple protection
if (false !== \strpos($sItem, ':'))
{
$aResult[] = $sItem;
continue;
}
$iItem = (int) $sItem;
if (null === $iStart || null === $iPrev)
{
$iStart = $iItem;
$iPrev = $iItem;
continue;
}
if ($iPrev === $iItem - 1)
{
$iPrev = $iItem;
}
else
{
$aResult[] = $iStart === $iPrev ? $iStart : $iStart.':'.$iPrev;
$iStart = $iItem;
$iPrev = $iItem;
}
}
if (null !== $iStart && null !== $iPrev)
{
$aResult[] = $iStart === $iPrev ? $iStart : $iStart.':'.$iPrev;
}
}
return \implode(',', $aResult);
}
/**
* @param resource $fResource
*/

View file

@ -903,17 +903,17 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageCopy(string $sToFolder, string $sIndexRange, bool $bIndexIsUid) : self
public function MessageCopy(string $sToFolder, SequenceSet $oRange) : self
{
if (!\strlen($sIndexRange))
if (!\count($oRange))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$this->SendRequestGetResponse($bIndexIsUid ? 'UID COPY' : 'COPY',
array($sIndexRange, $this->EscapeFolderName($sToFolder)));
$this->SendRequestGetResponse($oRange->UID ? 'UID COPY' : 'COPY',
array((string) $oRange, $this->EscapeFolderName($sToFolder)));
return $this;
}
@ -922,9 +922,9 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageMove(string $sToFolder, string $sIndexRange, bool $bIndexIsUid) : self
public function MessageMove(string $sToFolder, SequenceSet $oRange) : self
{
if (!\strlen($sIndexRange))
if (!\count($oRange))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException,
@ -938,8 +938,8 @@ class ImapClient extends \MailSo\Net\NetClient
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$this->SendRequestGetResponse($bIndexIsUid ? 'UID MOVE' : 'MOVE',
array($sIndexRange, $this->EscapeFolderName($sToFolder)));
$this->SendRequestGetResponse($oRange->UID ? 'UID MOVE' : 'MOVE',
array((string) $oRange, $this->EscapeFolderName($sToFolder)));
return $this;
}
@ -969,9 +969,9 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageStoreFlag(string $sIndexRange, bool $bIndexIsUid, array $aInputStoreItems, string $sStoreAction) : self
public function MessageStoreFlag(SequenceSet $oRange, array $aInputStoreItems, string $sStoreAction) : self
{
if (!\strlen(\trim($sIndexRange)) ||
if (!\count($oRange) ||
!\strlen(\trim($sStoreAction)) ||
!\count($aInputStoreItems))
{
@ -985,8 +985,8 @@ class ImapClient extends \MailSo\Net\NetClient
*/
$this->SendRequestGetResponse(
$bIndexIsUid ? 'UID STORE' : 'STORE',
array($sIndexRange, $sStoreAction, $aInputStoreItems)
$oRange->UID ? 'UID STORE' : 'STORE',
array((string) $oRange, $sStoreAction, $aInputStoreItems)
);
return $this;
}

View file

@ -0,0 +1,79 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2022 DJ Maze
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Imap;
/**
* @category MailSo
* @package Mail
*/
class SequenceSet /*extends \SplFixedArray*/ implements \Countable
{
public $UID = true;
private $data = [];
public function __construct($mItems, bool $uid = true)
{
if (\is_array($mItems)) {
$this->data = $uid ? \array_filter(\array_map(function($id){
return \preg_match('/^([0-9]+|\\*):([0-9]+|\\*)/', $id, $dummy) ? $id : \intval($id);
}, $mItems)) : $mItems;
} else if (\is_scalar($mItems)) {
$this->data[] = $mItems;
}
$this->UID = $uid;
}
public function count(): int
{
return \count($this->data);
}
public function contains($value): bool
{
return \in_array($value, $this->data);
}
public function __toString(): string
{
$aResult = array();
$iStart = null;
$iPrev = null;
foreach ($this->data as $mItem) {
if (false !== \strpos($mItem, ':')) {
$aResult[] = $mItem;
continue;
}
if (null === $iStart || null === $iPrev) {
$iStart = $mItem;
$iPrev = $mItem;
continue;
}
if ($iPrev === $mItem - 1) {
$iPrev = $mItem;
} else {
$aResult[] = $iStart === $iPrev ? $iStart : $iStart.':'.$iPrev;
$iStart = $mItem;
$iPrev = $mItem;
}
}
if (null !== $iStart && null !== $iPrev) {
$aResult[] = $iStart === $iPrev ? $iStart : $iStart.':'.$iPrev;
}
return \implode(',', $aResult);
}
}

View file

@ -12,6 +12,8 @@
namespace MailSo\Mail;
use MailSo\Imap\Enumerations\FolderResponseStatus;
use MailSo\Imap\Enumerations\StoreAction;
use MailSo\Imap\SequenceSet;
/**
* @category MailSo
@ -66,25 +68,7 @@ class MailClient
return $this->oImapClient->Capability();
}
private function getEnvelopeOrHeadersRequestStringForSimpleList() : string
{
return \MailSo\Imap\Enumerations\FetchType::BuildBodyCustomHeaderRequest(array(
\MailSo\Mime\Enumerations\Header::RETURN_PATH,
\MailSo\Mime\Enumerations\Header::RECEIVED,
\MailSo\Mime\Enumerations\Header::MIME_VERSION,
\MailSo\Mime\Enumerations\Header::FROM_,
\MailSo\Mime\Enumerations\Header::TO_,
\MailSo\Mime\Enumerations\Header::CC,
\MailSo\Mime\Enumerations\Header::SENDER,
\MailSo\Mime\Enumerations\Header::REPLY_TO,
\MailSo\Mime\Enumerations\Header::DATE,
\MailSo\Mime\Enumerations\Header::SUBJECT,
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Header::LIST_UNSUBSCRIBE,
), true);
}
private function getEnvelopeOrHeadersRequestString()
private function getEnvelopeOrHeadersRequestString() : string
{
if (\MailSo\Config::$MessageAllHeaders)
{
@ -138,7 +122,7 @@ class MailClient
* @throws \MailSo\Imap\Exceptions\Exception
* @throws \MailSo\Mail\Exceptions\Exception
*/
public function MessageSetFlagToAll(string $sFolderName, string $sMessageFlag, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false, ?array $aCustomUids = null)
public function MessageSetFlagToAll(string $sFolderName, string $sMessageFlag, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false, ?array $aCustomUids = null) : void
{
$this->oImapClient->FolderSelect($sFolderName);
@ -153,21 +137,18 @@ class MailClient
if ($oFolderInfo && 0 < $oFolderInfo->MESSAGES)
{
$sStoreAction = $bSetAction
? \MailSo\Imap\Enumerations\StoreAction::ADD_FLAGS_SILENT
: \MailSo\Imap\Enumerations\StoreAction::REMOVE_FLAGS_SILENT
;
if (\is_array($aCustomUids))
{
if (\count($aCustomUids))
{
$this->oImapClient->MessageStoreFlag(implode(',', $aCustomUids), true, array($sMessageFlag), $sStoreAction);
$oRange = null;
if (\is_array($aCustomUids)) {
if (\count($aCustomUids)) {
$oRange = new SequenceSet($aCustomUids);
}
} else {
$oRange = new SequenceSet('1:*', false);
}
else
{
$this->oImapClient->MessageStoreFlag('1:*', false, array($sMessageFlag), $sStoreAction);
if ($oRange) {
$sStoreAction = $bSetAction ? StoreAction::ADD_FLAGS_SILENT : StoreAction::REMOVE_FLAGS_SILENT;
$this->oImapClient->MessageStoreFlag($oRange, array($sMessageFlag), $sStoreAction);
}
}
}
@ -178,7 +159,7 @@ class MailClient
* @throws \MailSo\Imap\Exceptions\Exception
* @throws \MailSo\Mail\Exceptions\Exception
*/
public function MessageSetFlag(string $sFolderName, array $aIndexRange, bool $bIndexIsUid, string $sMessageFlag, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false)
public function MessageSetFlag(string $sFolderName, SequenceSet $oRange, string $sMessageFlag, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false) : void
{
$this->oImapClient->FolderSelect($sFolderName);
@ -192,13 +173,8 @@ class MailClient
}
else
{
$sStoreAction = $bSetAction
? \MailSo\Imap\Enumerations\StoreAction::ADD_FLAGS_SILENT
: \MailSo\Imap\Enumerations\StoreAction::REMOVE_FLAGS_SILENT
;
$this->oImapClient->MessageStoreFlag(\MailSo\Base\Utils::PrepareFetchSequence($aIndexRange),
$bIndexIsUid, array($sMessageFlag), $sStoreAction);
$sStoreAction = $bSetAction ? StoreAction::ADD_FLAGS_SILENT : StoreAction::REMOVE_FLAGS_SILENT;
$this->oImapClient->MessageStoreFlag($oRange, array($sMessageFlag), $sStoreAction);
}
}
@ -207,9 +183,9 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageSetFlagged(string $sFolderName, array $aIndexRange, bool $bIndexIsUid, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false) : void
public function MessageSetFlagged(string $sFolderName, SequenceSet $oRange, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false) : void
{
$this->MessageSetFlag($sFolderName, $aIndexRange, $bIndexIsUid,
$this->MessageSetFlag($sFolderName, $oRange,
\MailSo\Imap\Enumerations\MessageFlag::FLAGGED, $bSetAction, $bSkipUnsupportedFlag);
}
@ -228,9 +204,9 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageSetSeen(string $sFolderName, array $aIndexRange, bool $bIndexIsUid, bool $bSetAction = true) : void
public function MessageSetSeen(string $sFolderName, SequenceSet $oRange, bool $bSetAction = true) : void
{
$this->MessageSetFlag($sFolderName, $aIndexRange, $bIndexIsUid,
$this->MessageSetFlag($sFolderName, $oRange,
\MailSo\Imap\Enumerations\MessageFlag::SEEN, $bSetAction, true);
}
@ -400,25 +376,24 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageDelete(string $sFolder, array $aIndexRange, bool $bIndexIsUid, bool $bUseExpunge = true, bool $bExpungeAll = false) : self
public function MessageDelete(string $sFolder, SequenceSet $oRange, bool $bExpungeAll = false) : self
{
if (!\strlen($sFolder) || !\count($aIndexRange))
if (!\strlen($sFolder) || !\count($oRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolder);
$sIndexRange = \MailSo\Base\Utils::PrepareFetchSequence($aIndexRange);
$this->oImapClient->MessageStoreFlag($sIndexRange, $bIndexIsUid,
$this->oImapClient->MessageStoreFlag($oRange,
array(\MailSo\Imap\Enumerations\MessageFlag::DELETED),
\MailSo\Imap\Enumerations\StoreAction::ADD_FLAGS_SILENT
StoreAction::ADD_FLAGS_SILENT
);
if ($bUseExpunge)
{
$this->oImapClient->MessageExpunge($bIndexIsUid ? $sIndexRange : '', $bIndexIsUid, $bExpungeAll);
if ($oRange->UID) {
$this->oImapClient->MessageExpunge((string) $oRange, true, $bExpungeAll);
} else {
$this->oImapClient->MessageExpunge('', false, $bExpungeAll);
}
return $this;
@ -429,9 +404,9 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageMove(string $sFromFolder, string $sToFolder, array $aIndexRange, bool $bIndexIsUid, bool $bUseMoveSupported = false, bool $bExpungeAll = false) : self
public function MessageMove(string $sFromFolder, string $sToFolder, SequenceSet $oRange, bool $bUseMoveSupported = true, bool $bExpungeAll = false) : self
{
if (!$sFromFolder || !$sToFolder || !\count($aIndexRange))
if (!$sFromFolder || !$sToFolder || !\count($oRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
@ -440,15 +415,13 @@ class MailClient
if ($bUseMoveSupported && $this->oImapClient->IsSupported('MOVE'))
{
$this->oImapClient->MessageMove($sToFolder,
\MailSo\Base\Utils::PrepareFetchSequence($aIndexRange), $bIndexIsUid);
$this->oImapClient->MessageMove($sToFolder, $oRange);
}
else
{
$this->oImapClient->MessageCopy($sToFolder,
\MailSo\Base\Utils::PrepareFetchSequence($aIndexRange), $bIndexIsUid);
$this->oImapClient->MessageCopy($sToFolder, $oRange);
$this->MessageDelete($sFromFolder, $aIndexRange, $bIndexIsUid, true, $bExpungeAll);
$this->MessageDelete($sFromFolder, $oRange, $bExpungeAll);
}
return $this;
@ -459,16 +432,15 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageCopy(string $sFromFolder, string $sToFolder, array $aIndexRange, bool $bIndexIsUid) : self
public function MessageCopy(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : self
{
if (!$sFromFolder || !$sToFolder || !\count($aIndexRange))
if (!$sFromFolder || !$sToFolder || !\count($oRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFromFolder);
$this->oImapClient->MessageCopy($sToFolder,
\MailSo\Base\Utils::PrepareFetchSequence($aIndexRange), $bIndexIsUid);
$this->oImapClient->MessageCopy($sToFolder, $oRange);
return $this;
}
@ -637,13 +609,13 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, array $aUids = array()) : array
public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, SequenceSet $oRange = null) : array
{
$aFlags = array();
list($iCount, $iUnseenCount, $iUidNext, $iHighestModSeq, $iAppendLimit, $sMailboxId) = $this->initFolderValues($sFolderName);
if (\count($aUids))
if ($oRange && \count($oRange))
{
$this->oImapClient->FolderSelect($sFolderName);
@ -651,7 +623,7 @@ class MailClient
\MailSo\Imap\Enumerations\FetchType::INDEX,
\MailSo\Imap\Enumerations\FetchType::UID,
\MailSo\Imap\Enumerations\FetchType::FLAGS
), \MailSo\Base\Utils::PrepareFetchSequence($aUids), true);
), (string) $oRange, $oRange->UID);
foreach ($aFetchResponse as $oFetchResponse)
{
@ -793,9 +765,9 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, array $aRequestIndexOrUids, bool $bIndexAsUid, bool $bSimple = false)
protected function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, SequenceSet $oRange) : void
{
if (\count($aRequestIndexOrUids))
if (\count($oRange))
{
$aFetchResponse = $this->oImapClient->Fetch(array(
\MailSo\Imap\Enumerations\FetchType::INDEX,
@ -804,29 +776,18 @@ class MailClient
\MailSo\Imap\Enumerations\FetchType::INTERNALDATE,
\MailSo\Imap\Enumerations\FetchType::FLAGS,
\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE,
$bSimple ?
$this->getEnvelopeOrHeadersRequestStringForSimpleList() :
$this->getEnvelopeOrHeadersRequestString()
), \MailSo\Base\Utils::PrepareFetchSequence($aRequestIndexOrUids), $bIndexAsUid);
$this->getEnvelopeOrHeadersRequestString()
), (string) $oRange, $oRange->UID);
if (\count($aFetchResponse))
{
$aFetchIndexArray = array();
$sFetchType = $oRange->UID ? \MailSo\Imap\Enumerations\FetchType::UID : \MailSo\Imap\Enumerations\FetchType::INDEX;
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem)
{
$aFetchIndexArray[$bIndexAsUid
? $oFetchResponseItem->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID)
: $oFetchResponseItem->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INDEX)
] = $oFetchResponseItem;
}
foreach ($aRequestIndexOrUids as $iFUid)
{
if (isset($aFetchIndexArray[$iFUid]))
{
if ($oRange->contains($oFetchResponseItem->GetFetchValue($sFetchType))) {
$oMessageCollection->append(
Message::NewFetchResponseInstance(
$oMessageCollection->FolderName, $aFetchIndexArray[$iFUid]));
Message::NewFetchResponseInstance($oMessageCollection->FolderName, $oFetchResponseItem)
);
}
}
}
@ -1092,8 +1053,10 @@ class MailClient
if (\count($aUids))
{
$aRequestUids = \array_slice($aUids, $oParams->iOffset, $oParams->iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestUids, true);
$this->MessageListByRequestIndexOrUids(
$oMessageCollection,
new SequenceSet(\array_slice($aUids, $oParams->iOffset, $oParams->iLimit))
);
}
}
else if ($iMessageRealCount)
@ -1112,16 +1075,13 @@ class MailClient
$aUids = $this->GetUids($oParams->oCacher, $sSearch,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash);
if (\count($aUids))
$oMessageCollection->MessageResultCount = \count($aUids);
if ($oMessageCollection->MessageResultCount)
{
$oMessageCollection->MessageResultCount = \count($aUids);
$aRequestUids = \array_slice($aUids, $oParams->iOffset, $oParams->iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestUids, true);
}
else
{
$oMessageCollection->MessageResultCount = 0;
$this->MessageListByRequestIndexOrUids(
$oMessageCollection,
new SequenceSet(\array_slice($aUids, $oParams->iOffset, $oParams->iLimit))
);
}
}
else
@ -1137,7 +1097,7 @@ class MailClient
$aRequestIndexes = \array_slice(array(1), $oParams->iOffset, $oParams->iLimit);
}
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestIndexes, false);
$this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aRequestIndexes, false));
}
}
@ -1425,9 +1385,9 @@ class MailClient
$oFolderInformation = $this->oImapClient->FolderCurrentInformation();
if ($oFolderInformation && 0 < $oFolderInformation->MESSAGES)
{
$this->oImapClient->MessageStoreFlag('1:*', false,
$this->oImapClient->MessageStoreFlag(new SequenceSet('1:*', false),
array(\MailSo\Imap\Enumerations\MessageFlag::DELETED),
\MailSo\Imap\Enumerations\StoreAction::ADD_FLAGS_SILENT
StoreAction::ADD_FLAGS_SILENT
);
$this->oImapClient->MessageExpunge();

View file

@ -389,18 +389,14 @@ trait Folders
*/
public function DoFolderInformation() : array
{
$sFolder = $this->GetActionParam('Folder', '');
$iPrevUidNext = (int) $this->GetActionParam('UidNext', 0);
$aFlagsUids = \array_filter(\array_map('intval', $this->GetActionParam('FlagsUids', []) ?: []));
$this->initMailClientConnection();
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
try
{
$aInboxInformation = $this->MailClient()->FolderInformation(
$sFolder, $iPrevUidNext, $aFlagsUids
$this->GetActionParam('Folder', ''),
(int) $this->GetActionParam('UidNext', 0),
new \MailSo\Imap\SequenceSet($this->GetActionParam('FlagsUids', []))
);
$aInboxInformation['Flags'] = $aInboxInformation['MessagesFlags'];
unset($aInboxInformation['MessagesFlags']);

View file

@ -6,6 +6,7 @@ use RainLoop\Enumerations\Capa;
use RainLoop\Exceptions\ClientException;
use RainLoop\Model\Account;
use RainLoop\Notifications;
use MailSo\Imap\SequenceSet;
trait Messages
{
@ -87,9 +88,6 @@ trait Messages
{
$oAccount = $this->initMailClientConnection();
$sMessageFolder = $this->GetActionParam('MessageFolder', '');
$iMessageUid = $this->GetActionParam('MessageUid', 0);
$sDraftFolder = $this->GetActionParam('SaveFolder', '');
if (!\strlen($sDraftFolder))
{
@ -127,9 +125,11 @@ trait Messages
$mResult = true;
$sMessageFolder = $this->GetActionParam('MessageFolder', '');
$iMessageUid = (int) $this->GetActionParam('MessageUid', 0);
if (\strlen($sMessageFolder) && 0 < $iMessageUid)
{
$this->MailClient()->MessageDelete($sMessageFolder, array($iMessageUid), true, true);
$this->MailClient()->MessageDelete($sMessageFolder, new SequenceSet($iMessageUid));
}
if (null !== $iNewUid && 0 < $iNewUid)
@ -151,8 +151,6 @@ trait Messages
$oConfig = $this->Config();
$sDraftFolder = $this->GetActionParam('MessageFolder', '');
$iDraftUid = $this->GetActionParam('MessageUid', 0);
$sSentFolder = $this->GetActionParam('SaveFolder', '');
$aDraftInfo = $this->GetActionParam('DraftInfo', null);
$bDsn = '1' === (string) $this->GetActionParam('Dsn', '0');
@ -178,7 +176,7 @@ trait Messages
if (\is_array($aDraftInfo) && 3 === \count($aDraftInfo))
{
$sDraftInfoType = $aDraftInfo[0];
$sDraftInfoUid = $aDraftInfo[1];
$iDraftInfoUid = (int) $aDraftInfo[1];
$sDraftInfoFolder = $aDraftInfo[2];
try
@ -187,15 +185,15 @@ trait Messages
{
case 'reply':
case 'reply-all':
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, array($sDraftInfoUid), true,
\MailSo\Imap\Enumerations\MessageFlag::ANSWERED, true);
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, new SequenceSet($iDraftInfoUid),
\MailSo\Imap\Enumerations\MessageFlag::ANSWERED);
break;
case 'forward':
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
if (\strlen($sForwardedFlag))
{
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, array($sDraftInfoUid), true,
$sForwardedFlag, true);
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, new SequenceSet($iDraftInfoUid),
$sForwardedFlag);
}
break;
}
@ -260,11 +258,13 @@ trait Messages
$this->deleteMessageAttachmnets($oAccount);
$sDraftFolder = $this->GetActionParam('MessageFolder', '');
$iDraftUid = (int) $this->GetActionParam('MessageUid', 0);
if (\strlen($sDraftFolder) && 0 < $iDraftUid)
{
try
{
$this->MailClient()->MessageDelete($sDraftFolder, array($iDraftUid), true, true);
$this->MailClient()->MessageDelete($sDraftFolder, new SequenceSet($iDraftUid));
}
catch (\Throwable $oException)
{
@ -364,7 +364,7 @@ trait Messages
{
try
{
$this->MailClient()->MessageSetFlag($sFolderFullName, array($iUid), true, $sReadReceiptFlag, true, true);
$this->MailClient()->MessageSetFlag($sFolderFullName, new SequenceSet($iUid), $sReadReceiptFlag, true, true);
}
catch (\Throwable $oException) {}
}
@ -478,11 +478,9 @@ trait Messages
$sFolder = $this->GetActionParam('Folder', '');
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
$aFilteredUids = \array_filter(\array_map('intval', $aUids));
try
{
$this->MailClient()->MessageDelete($sFolder, $aFilteredUids, true, true,
$this->MailClient()->MessageDelete($sFolder, new SequenceSet($aUids),
!!$this->Config()->Get('labs', 'use_imap_expunge_all_on_delete', false));
}
catch (\Throwable $oException)
@ -526,14 +524,13 @@ trait Messages
$sToFolder = $this->GetActionParam('ToFolder', '');
$bMarkAsRead = !empty($this->GetActionParam('MarkAsRead', '0'));
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
$aFilteredUids = \array_filter(\array_map('intval', $aUids));
$oUids = new SequenceSet(\explode(',', (string) $this->GetActionParam('Uids', '')));
if ($bMarkAsRead)
{
try
{
$this->MailClient()->MessageSetSeen($sFromFolder, $aFilteredUids, true, true);
$this->MailClient()->MessageSetSeen($sFromFolder, $oUids);
}
catch (\Throwable $oException)
{
@ -543,7 +540,7 @@ trait Messages
try
{
$this->MailClient()->MessageMove($sFromFolder, $sToFolder, $aFilteredUids, true,
$this->MailClient()->MessageMove($sFromFolder, $sToFolder, $oUids,
!!$this->Config()->Get('labs', 'use_imap_move', true),
!!$this->Config()->Get('labs', 'use_imap_expunge_all_on_delete', false)
);
@ -585,16 +582,13 @@ trait Messages
{
$this->initMailClientConnection();
$sFromFolder = $this->GetActionParam('FromFolder', '');
$sToFolder = $this->GetActionParam('ToFolder', '');
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
$aFilteredUids = \array_filter(\array_map('intval', $aUids));
try
{
$this->MailClient()->MessageCopy($sFromFolder, $sToFolder,
$aFilteredUids, true);
$this->MailClient()->MessageCopy(
$this->GetActionParam('FromFolder', ''),
$this->GetActionParam('ToFolder', ''),
new SequenceSet(\explode(',', (string) $this->GetActionParam('Uids', '')))
);
}
catch (\Throwable $oException)
{
@ -809,14 +803,14 @@ trait Messages
{
$this->initMailClientConnection();
$sFolder = $this->GetActionParam('Folder', '');
$bSetAction = '1' === (string) $this->GetActionParam('SetAction', '0');
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
$aFilteredUids = \array_filter(\array_map('intval', $aUids));
try
{
$this->MailClient()->{$sActionFunction}($sFolder, $aFilteredUids, true, $bSetAction, true);
$this->MailClient()->{$sActionFunction}(
$this->GetActionParam('Folder', ''),
new SequenceSet(\explode(',', (string) $this->GetActionParam('Uids', ''))),
!empty($this->GetActionParam('SetAction', '0')),
true
);
}
catch (\Throwable $oException)
{