mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-09 06:28:28 +03:00
Made IMAP THREAD command iterable
This commit is contained in:
parent
1c267a0030
commit
1ef7ea3f27
4 changed files with 13 additions and 18 deletions
|
|
@ -402,12 +402,12 @@ trait Messages
|
|||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
*/
|
||||
public function MessageSimpleThread(string $sSearchCriterias = 'ALL', bool $bReturnUid = true) : array
|
||||
public function MessageSimpleThread(string $sSearchCriterias = 'ALL', bool $bReturnUid = true) : iterable
|
||||
{
|
||||
$oThread = new \MailSo\Imap\Requests\THREAD($this);
|
||||
$oThread->sCriterias = $sSearchCriterias;
|
||||
$oThread->bUid = $bReturnUid;
|
||||
return $oThread->SendRequestGetResponse();
|
||||
yield from $oThread->SendRequestIterateResponse();
|
||||
}
|
||||
|
||||
private function getSimpleESearchOrESortResult(bool $bReturnUid) : array
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ namespace MailSo\Imap\Enumerations;
|
|||
*/
|
||||
abstract class StoreAction
|
||||
{
|
||||
const SET_FLAGS = 'FLAGS';
|
||||
const SET_FLAGS_SILENT = 'FLAGS.SILENT';
|
||||
// const SET_FLAGS = 'FLAGS';
|
||||
// const SET_FLAGS_SILENT = 'FLAGS.SILENT';
|
||||
const ADD_FLAGS = '+FLAGS';
|
||||
const ADD_FLAGS_SILENT = '+FLAGS.SILENT';
|
||||
const REMOVE_FLAGS = '-FLAGS';
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class THREAD extends Request
|
|||
parent::__construct($oImapClient);
|
||||
}
|
||||
|
||||
public function SendRequestGetResponse() : array
|
||||
public function SendRequestIterateResponse() : iterable
|
||||
{
|
||||
if (!$this->oImapClient->IsSupported(\strtoupper("THREAD={$this->sAlgorithm}"))) {
|
||||
$this->oImapClient->writeLogException(
|
||||
|
|
@ -58,7 +58,6 @@ class THREAD extends Request
|
|||
)
|
||||
);
|
||||
|
||||
$aReturn = array();
|
||||
foreach ($this->oImapClient->yieldUntaggedResponses() as $oResponse) {
|
||||
$iOffset = ($this->bUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'THREAD' === $oResponse->ResponseList[2]) ? 1 : 0;
|
||||
if (('THREAD' === $oResponse->StatusOrIndex || $iOffset)
|
||||
|
|
@ -69,12 +68,11 @@ class THREAD extends Request
|
|||
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
||||
$aNewValue = $this->validateThreadItem($oResponse->ResponseList[$iIndex]);
|
||||
if (\is_array($aNewValue)) {
|
||||
$aReturn[] = $aNewValue;
|
||||
yield $aNewValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -618,10 +618,15 @@ class MailClient
|
|||
|
||||
$this->oImapClient->FolderExamine($sFolderName);
|
||||
|
||||
$aThreadUids = array();
|
||||
$aResult = array();
|
||||
try
|
||||
{
|
||||
$aThreadUids = $this->oImapClient->MessageSimpleThread($sSearchHash);
|
||||
foreach ($this->oImapClient->MessageSimpleThread($sSearchHash) as $mItem) {
|
||||
// Flatten to single level
|
||||
$aMap = [];
|
||||
\array_walk_recursive($mItem, function($a) use (&$aMap) { $aMap[] = $a; });
|
||||
$aResult[] = $aMap;
|
||||
}
|
||||
}
|
||||
catch (\MailSo\Imap\Exceptions\RuntimeException $oException)
|
||||
{
|
||||
|
|
@ -629,14 +634,6 @@ class MailClient
|
|||
unset($oException);
|
||||
}
|
||||
|
||||
// Flatten to single levels
|
||||
$aResult = array();
|
||||
foreach ($aThreadUids as $mItem) {
|
||||
$aMap = [];
|
||||
\array_walk_recursive($mItem, function($a) use (&$aMap) { $aMap[] = $a; });
|
||||
$aResult[] = $aMap;
|
||||
}
|
||||
|
||||
if ($oCacher && $oCacher->IsInited() && !empty($sSerializedHashKey))
|
||||
{
|
||||
$oCacher->Set($sSerializedHashKey, \json_encode(array(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue