mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Move ResponseCollection functions to their command functions
This commit is contained in:
parent
299ec7faf8
commit
afcd76adbf
4 changed files with 269 additions and 276 deletions
|
|
@ -0,0 +1,180 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of MailSo.
|
||||||
|
*
|
||||||
|
* (c) 2014 Usenko Timur
|
||||||
|
* (c) 2021 DJMaze
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace MailSo\Imap\Commands;
|
||||||
|
|
||||||
|
use MailSo\Imap\ResponseCollection;
|
||||||
|
use MailSo\Imap\Enumerations\ResponseType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category MailSo
|
||||||
|
* @package Imap
|
||||||
|
*/
|
||||||
|
trait Messages
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* See https://tools.ietf.org/html/rfc5256
|
||||||
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function MessageSimpleSort(array $aSortTypes, string $sSearchCriterias = 'ALL', bool $bReturnUid = true) : array
|
||||||
|
{
|
||||||
|
$oSort = new \MailSo\Imap\Requests\SORT($this);
|
||||||
|
$oSort->sCriterias = $sSearchCriterias;
|
||||||
|
$oSort->bUid = $bReturnUid;
|
||||||
|
$oSort->aSortTypes = $aSortTypes;
|
||||||
|
$oResponseCollection = $oSort->SendRequestGetResponse();
|
||||||
|
$aReturn = array();
|
||||||
|
foreach ($oResponseCollection as $oResponse) {
|
||||||
|
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'SORT' === $oResponse->ResponseList[2]) ? 1 : 0;
|
||||||
|
if (ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||||
|
&& ('SORT' === $oResponse->StatusOrIndex || $iOffset)
|
||||||
|
&& \is_array($oResponse->ResponseList)
|
||||||
|
&& 2 < \count($oResponse->ResponseList))
|
||||||
|
{
|
||||||
|
$iLen = \count($oResponse->ResponseList);
|
||||||
|
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
||||||
|
$aReturn[] = (int) $oResponse->ResponseList[$iIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function MessageSimpleESearch(string $sSearchCriterias = 'ALL', array $aSearchReturn = null, bool $bReturnUid = true, string $sCharset = '', string $sLimit = '') : array
|
||||||
|
{
|
||||||
|
$oESearch = new \MailSo\Imap\Requests\ESEARCH($this);
|
||||||
|
$oESearch->sCriterias = $sSearchCriterias;
|
||||||
|
$oESearch->aReturn = $aSearchReturn;
|
||||||
|
$oESearch->bUid = $bReturnUid;
|
||||||
|
$oESearch->sLimit = $sLimit;
|
||||||
|
$oESearch->sCharset = $sCharset;
|
||||||
|
return $this->getSimpleESearchOrESortResult($oESearch->SendRequestGetResponse(), $bReturnUid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function MessageSimpleESort(array $aSortTypes, string $sSearchCriterias = 'ALL', array $aSearchReturn = ['ALL'], bool $bReturnUid = true, string $sLimit = '') : array
|
||||||
|
{
|
||||||
|
$oSort = new \MailSo\Imap\Requests\SORT($this);
|
||||||
|
$oSort->sCriterias = $sSearchCriterias;
|
||||||
|
$oSort->bUid = $bReturnUid;
|
||||||
|
$oSort->aSortTypes = $aSortTypes;
|
||||||
|
$oSort->aReturn = $aSearchReturn ?: ['ALL'];
|
||||||
|
$oSort->sLimit = $sLimit;
|
||||||
|
return $this->getSimpleESearchOrESortResult($oSort->SendRequestGetResponse(), $bReturnUid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function MessageSimpleSearch(string $sSearchCriterias = 'ALL', bool $bReturnUid = true, string $sCharset = '') : array
|
||||||
|
{
|
||||||
|
$aRequest = array();
|
||||||
|
if (\strlen($sCharset)) {
|
||||||
|
$aRequest[] = 'CHARSET';
|
||||||
|
$aRequest[] = \strtoupper($sCharset);
|
||||||
|
}
|
||||||
|
|
||||||
|
$aRequest[] = !\strlen($sSearchCriterias) || '*' === $sSearchCriterias ? 'ALL' : $sSearchCriterias;
|
||||||
|
|
||||||
|
$sCont = $this->SendRequest($bReturnUid ? 'UID SEARCH' : 'SEARCH', $aRequest, true);
|
||||||
|
$oResult = $this->getResponse();
|
||||||
|
if ('' !== $sCont) {
|
||||||
|
$oItem = $oResult->getLast();
|
||||||
|
if ($oItem && ResponseType::CONTINUATION === $oItem->ResponseType) {
|
||||||
|
$aParts = \explode("\r\n", $sCont);
|
||||||
|
foreach ($aParts as $sLine) {
|
||||||
|
$this->sendRaw($sLine);
|
||||||
|
$oResult = $this->getResponse();
|
||||||
|
$oItem = $oResult->getLast();
|
||||||
|
if ($oItem && ResponseType::CONTINUATION === $oItem->ResponseType) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$aReturn = array();
|
||||||
|
foreach ($oResult as $oResponse) {
|
||||||
|
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'SEARCH' === $oResponse->ResponseList[2]) ? 1 : 0;
|
||||||
|
if (ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||||
|
&& ('SEARCH' === $oResponse->StatusOrIndex || $iOffset)
|
||||||
|
&& \is_array($oResponse->ResponseList)
|
||||||
|
&& 2 < \count($oResponse->ResponseList))
|
||||||
|
{
|
||||||
|
$iLen = \count($oResponse->ResponseList);
|
||||||
|
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
||||||
|
$aReturn[] = (int) $oResponse->ResponseList[$iIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return \array_reverse($aReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function MessageSimpleThread(string $sSearchCriterias = 'ALL', bool $bReturnUid = true, string $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8) : array
|
||||||
|
{
|
||||||
|
$oThread = new \MailSo\Imap\Requests\THREAD($this);
|
||||||
|
$oThread->sCriterias = $sSearchCriterias;
|
||||||
|
$oThread->sCharset = $sCharset;
|
||||||
|
$oThread->bUid = $bReturnUid;
|
||||||
|
return $oThread->SendRequestGetResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSimpleESearchOrESortResult(ResponseCollection $oResponseCollection, bool $bReturnUid) : array
|
||||||
|
{
|
||||||
|
$sRequestTag = $this->getCurrentTag();
|
||||||
|
$aResult = array();
|
||||||
|
foreach ($oResponseCollection as $oResponse) {
|
||||||
|
if (ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||||
|
&& ('ESEARCH' === $oResponse->StatusOrIndex || 'SORT' === $oResponse->StatusOrIndex)
|
||||||
|
&& \is_array($oResponse->ResponseList)
|
||||||
|
&& isset($oResponse->ResponseList[2][1])
|
||||||
|
&& 'TAG' === $oResponse->ResponseList[2][0] && $sRequestTag === $oResponse->ResponseList[2][1]
|
||||||
|
&& (!$bReturnUid || (!empty($oResponse->ResponseList[3]) && 'UID' === $oResponse->ResponseList[3]))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$i = \count($oResponse->ResponseList) - 1;
|
||||||
|
while (3 < --$i) {
|
||||||
|
$sItem = $oResponse->ResponseList[$i];
|
||||||
|
switch ($sItem)
|
||||||
|
{
|
||||||
|
case 'ALL':
|
||||||
|
case 'MAX':
|
||||||
|
case 'MIN':
|
||||||
|
case 'COUNT':
|
||||||
|
$aResult[$sItem] = $oResponse->ResponseList[$i + 1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
{
|
{
|
||||||
use Traits\ResponseParser;
|
use Traits\ResponseParser;
|
||||||
// use Commands\ACL;
|
// use Commands\ACL;
|
||||||
|
use Commands\Messages;
|
||||||
use Commands\Metadata;
|
use Commands\Metadata;
|
||||||
use Commands\Quota;
|
use Commands\Quota;
|
||||||
|
|
||||||
|
|
@ -333,13 +334,22 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
*/
|
*/
|
||||||
public function GetNamespace() : ?NamespaceResult
|
public function GetNamespace() : ?NamespaceResult
|
||||||
{
|
{
|
||||||
if (!$this->IsSupported('NAMESPACE'))
|
if (!$this->IsSupported('NAMESPACE')) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->SendRequestGetResponse('NAMESPACE')->getNamespaceResult();
|
$oResponseCollection = $this->SendRequestGetResponse('NAMESPACE');
|
||||||
|
foreach ($oResponseCollection as $oResponse) {
|
||||||
|
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||||
|
&& 'NAMESPACE' === $oResponse->StatusOrIndex)
|
||||||
|
{
|
||||||
|
$oReturn = new NamespaceResult;
|
||||||
|
$oReturn->InitByImapResponse($oResponse);
|
||||||
|
return $oReturn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exceptions\ResponseException;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::ERROR);
|
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::ERROR);
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|
@ -489,7 +499,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
*/
|
*/
|
||||||
private function specificFolderList(bool $bIsSubscribeList, string $sParentFolderName = '', string $sListPattern = '*', bool $bUseListStatus = false) : array
|
protected function specificFolderList(bool $bIsSubscribeList, string $sParentFolderName = '', string $sListPattern = '*', bool $bUseListStatus = false) : array
|
||||||
{
|
{
|
||||||
$sCmd = 'LIST';
|
$sCmd = 'LIST';
|
||||||
|
|
||||||
|
|
@ -815,114 +825,17 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
$this->aFetchCallbacks = array();
|
$this->aFetchCallbacks = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $oResult->getFetchResult($this->oLogger);
|
$aReturn = array();
|
||||||
}
|
foreach ($oResult as $oResponse) {
|
||||||
|
if (FetchResponse::IsValidFetchImapResponse($oResponse)) {
|
||||||
/**
|
if (FetchResponse::IsNotEmptyFetchImapResponse($oResponse)) {
|
||||||
* See https://tools.ietf.org/html/rfc5256
|
$aReturn[] = new FetchResponse($oResponse);
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
} else if ($this->oLogger) {
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse->ToLine().']', \MailSo\Log\Enumerations\Type::NOTICE);
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
|
||||||
*/
|
|
||||||
public function MessageSimpleSort(array $aSortTypes, string $sSearchCriterias = 'ALL', bool $bReturnUid = true) : array
|
|
||||||
{
|
|
||||||
$oSort = new Requests\SORT($this);
|
|
||||||
$oSort->sCriterias = $sSearchCriterias;
|
|
||||||
$oSort->bUid = $bReturnUid;
|
|
||||||
$oSort->aSortTypes = $aSortTypes;
|
|
||||||
return $oSort->SendRequestGetResponse()
|
|
||||||
->getMessageSimpleSortResult($bReturnUid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
|
||||||
*/
|
|
||||||
public function MessageSimpleESearch(string $sSearchCriterias = 'ALL', array $aSearchReturn = null, bool $bReturnUid = true, string $sCharset = '', string $sLimit = '') : array
|
|
||||||
{
|
|
||||||
$oESearch = new Requests\ESEARCH($this);
|
|
||||||
$oESearch->sCriterias = $sSearchCriterias;
|
|
||||||
$oESearch->aReturn = $aSearchReturn;
|
|
||||||
$oESearch->bUid = $bReturnUid;
|
|
||||||
$oESearch->sLimit = $sLimit;
|
|
||||||
$oESearch->sCharset = $sCharset;
|
|
||||||
return $oESearch->SendRequestGetResponse()
|
|
||||||
->getSimpleESearchOrESortResult($this->getCurrentTag(), $bReturnUid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
|
||||||
*/
|
|
||||||
public function MessageSimpleESort(array $aSortTypes, string $sSearchCriterias = 'ALL', array $aSearchReturn = ['ALL'], bool $bReturnUid = true, string $sLimit = '') : array
|
|
||||||
{
|
|
||||||
$oSort = new Requests\SORT($this);
|
|
||||||
$oSort->sCriterias = $sSearchCriterias;
|
|
||||||
$oSort->bUid = $bReturnUid;
|
|
||||||
$oSort->aSortTypes = $aSortTypes;
|
|
||||||
$oSort->aReturn = $aSearchReturn ?: ['ALL'];
|
|
||||||
$oSort->sLimit = $sLimit;
|
|
||||||
return $oSort->SendRequestGetResponse()
|
|
||||||
->getSimpleESearchOrESortResult($this->getCurrentTag(), $bReturnUid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
|
||||||
*/
|
|
||||||
public function MessageSimpleSearch(string $sSearchCriterias = 'ALL', bool $bReturnUid = true, string $sCharset = '') : array
|
|
||||||
{
|
|
||||||
$aRequest = array();
|
|
||||||
if (\strlen($sCharset))
|
|
||||||
{
|
|
||||||
$aRequest[] = 'CHARSET';
|
|
||||||
$aRequest[] = \strtoupper($sCharset);
|
|
||||||
}
|
|
||||||
|
|
||||||
$aRequest[] = !\strlen($sSearchCriterias) || '*' === $sSearchCriterias ? 'ALL' : $sSearchCriterias;
|
|
||||||
|
|
||||||
$sCont = $this->SendRequest($bReturnUid ? 'UID SEARCH' : 'SEARCH', $aRequest, true);
|
|
||||||
$oResult = $this->getResponse();
|
|
||||||
if ('' !== $sCont)
|
|
||||||
{
|
|
||||||
$oItem = $oResult->getLast();
|
|
||||||
|
|
||||||
if ($oItem && Enumerations\ResponseType::CONTINUATION === $oItem->ResponseType)
|
|
||||||
{
|
|
||||||
$aParts = explode("\r\n", $sCont);
|
|
||||||
foreach ($aParts as $sLine)
|
|
||||||
{
|
|
||||||
$this->sendRaw($sLine);
|
|
||||||
|
|
||||||
$oResult = $this->getResponse();
|
|
||||||
$oItem = $oResult->getLast();
|
|
||||||
if ($oItem && Enumerations\ResponseType::CONTINUATION === $oItem->ResponseType)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $aReturn;
|
||||||
return $oResult->getMessageSimpleSearchResult($bReturnUid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
|
||||||
*/
|
|
||||||
public function MessageSimpleThread(string $sSearchCriterias = 'ALL', bool $bReturnUid = true, string $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8) : array
|
|
||||||
{
|
|
||||||
$oThread = new Requests\THREAD($this);
|
|
||||||
$oThread->sCriterias = $sSearchCriterias;
|
|
||||||
$oThread->sCharset = $sCharset;
|
|
||||||
$oThread->bUid = $bReturnUid;
|
|
||||||
return $oThread->SendRequestGetResponse()
|
|
||||||
->getMessageSimpleThreadResult($bReturnUid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1115,7 +1028,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function secureRequestParams(string $sCommand, array $aParams) : ?array
|
protected function secureRequestParams(string $sCommand, array $aParams) : ?array
|
||||||
{
|
{
|
||||||
if ('LOGIN' === $sCommand && isset($aParams[1])) {
|
if ('LOGIN' === $sCommand && isset($aParams[1])) {
|
||||||
$aParams[1] = '"********"';
|
$aParams[1] = '"********"';
|
||||||
|
|
@ -1135,7 +1048,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
return $this->getResponse();
|
return $this->getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getResponseValue(ResponseCollection $oResponseCollection, int $type = 0) : string
|
protected function getResponseValue(ResponseCollection $oResponseCollection, int $type = 0) : string
|
||||||
{
|
{
|
||||||
$oResponse = $oResponseCollection->getLast();
|
$oResponse = $oResponseCollection->getLast();
|
||||||
if ($oResponse && (!$type || $type === $oResponse->ResponseType)) {
|
if ($oResponse && (!$type || $type === $oResponse->ResponseType)) {
|
||||||
|
|
@ -1161,7 +1074,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
* @throws \MailSo\Imap\Exceptions\InvalidResponseException
|
* @throws \MailSo\Imap\Exceptions\InvalidResponseException
|
||||||
* @throws \MailSo\Imap\Exceptions\NegativeResponseException
|
* @throws \MailSo\Imap\Exceptions\NegativeResponseException
|
||||||
*/
|
*/
|
||||||
private function streamResponse(string $sEndTag = null) : void
|
protected function streamResponse(string $sEndTag = null) : void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (\is_resource($this->ConnectionResource())) {
|
if (\is_resource($this->ConnectionResource())) {
|
||||||
|
|
@ -1184,7 +1097,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getResponse(string $sEndTag = null) : ResponseCollection
|
protected function getResponse(string $sEndTag = null) : ResponseCollection
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$oResult = new ResponseCollection;
|
$oResult = new ResponseCollection;
|
||||||
|
|
@ -1225,7 +1138,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
return $oResult;
|
return $oResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareParamLine(array $aParams = array()) : string
|
protected function prepareParamLine(array $aParams = array()) : string
|
||||||
{
|
{
|
||||||
$sReturn = '';
|
$sReturn = '';
|
||||||
foreach ($aParams as $mParamItem)
|
foreach ($aParams as $mParamItem)
|
||||||
|
|
@ -1242,13 +1155,13 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
return $sReturn;
|
return $sReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNewTag() : string
|
protected function getNewTag() : string
|
||||||
{
|
{
|
||||||
++$this->iTagCount;
|
++$this->iTagCount;
|
||||||
return $this->getCurrentTag();
|
return $this->getCurrentTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCurrentTag() : string
|
protected function getCurrentTag() : string
|
||||||
{
|
{
|
||||||
return self::TAG_PREFIX.$this->iTagCount;
|
return self::TAG_PREFIX.$this->iTagCount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,22 +36,23 @@ class THREAD extends Request
|
||||||
$this->sAlgorithm = 'ORDEREDSUBJECT';
|
$this->sAlgorithm = 'ORDEREDSUBJECT';
|
||||||
} else {
|
} else {
|
||||||
$oImapClient->writeLogException(
|
$oImapClient->writeLogException(
|
||||||
new RuntimeException('THREAD is not supported'),
|
new \MailSo\Imap\Exceptions\RuntimeException('THREAD is not supported'),
|
||||||
Type::ERROR, true);
|
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||||
}
|
}
|
||||||
parent::__construct($oImapClient);
|
parent::__construct($oImapClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SendRequestGetResponse() : \MailSo\Imap\ResponseCollection
|
public function SendRequestGetResponse() : array
|
||||||
{
|
{
|
||||||
if (!$this->oImapClient->IsSupported(\strtoupper("THREAD={$this->sAlgorithm}"))) {
|
if (!$this->oImapClient->IsSupported(\strtoupper("THREAD={$this->sAlgorithm}"))) {
|
||||||
$this->oImapClient->writeLogException(
|
$this->oImapClient->writeLogException(
|
||||||
new Exceptions\RuntimeException("THREAD={$this->sAlgorithm} is not supported"),
|
new \MailSo\Imap\Exceptions\RuntimeException("THREAD={$this->sAlgorithm} is not supported"),
|
||||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$aRequest = array();
|
$aRequest = array(
|
||||||
$aRequest[] = $this->sAlgorithm;
|
$this->sAlgorithm
|
||||||
|
);
|
||||||
|
|
||||||
$sSearchCriterias = (\strlen($this->sCriterias) && '*' !== $this->sCriterias) ? $this->sCriterias : 'ALL';
|
$sSearchCriterias = (\strlen($this->sCriterias) && '*' !== $this->sCriterias) ? $this->sCriterias : 'ALL';
|
||||||
|
|
||||||
|
|
@ -62,9 +63,61 @@ class THREAD extends Request
|
||||||
$aRequest[] = \strtoupper($this->sCharset);
|
$aRequest[] = \strtoupper($this->sCharset);
|
||||||
$aRequest[] = $sSearchCriterias;
|
$aRequest[] = $sSearchCriterias;
|
||||||
|
|
||||||
return $this->oImapClient->SendRequestGetResponse(
|
$oResponseCollection = $this->oImapClient->SendRequestGetResponse(
|
||||||
($this->bUid ? 'UID THREAD' : 'THREAD'),
|
($this->bUid ? 'UID THREAD' : 'THREAD'),
|
||||||
$aRequest
|
$aRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$aReturn = array();
|
||||||
|
foreach ($oResponseCollection as $oResponse) {
|
||||||
|
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'THREAD' === $oResponse->ResponseList[2]) ? 1 : 0;
|
||||||
|
if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||||
|
&& ('THREAD' === $oResponse->StatusOrIndex || $iOffset)
|
||||||
|
&& \is_array($oResponse->ResponseList)
|
||||||
|
&& 2 < \count($oResponse->ResponseList))
|
||||||
|
{
|
||||||
|
$iLen = \count($oResponse->ResponseList);
|
||||||
|
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
||||||
|
$aNewValue = $this->validateThreadItem($oResponse->ResponseList[$iIndex]);
|
||||||
|
if (\is_array($aNewValue)) {
|
||||||
|
$aReturn[] = $aNewValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $mValue
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function validateThreadItem($mValue)
|
||||||
|
{
|
||||||
|
$mResult = false;
|
||||||
|
if (\is_numeric($mValue)) {
|
||||||
|
$mResult = (int) $mValue;
|
||||||
|
if (0 >= $mResult) {
|
||||||
|
$mResult = false;
|
||||||
|
}
|
||||||
|
} else if (\is_array($mValue)) {
|
||||||
|
if (1 === \count($mValue) && \is_numeric($mValue[0])) {
|
||||||
|
$mResult = (int) $mValue[0];
|
||||||
|
if (0 >= $mResult) {
|
||||||
|
$mResult = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$mResult = array();
|
||||||
|
foreach ($mValue as $mValueItem) {
|
||||||
|
$mTemp = $this->validateThreadItem($mValueItem);
|
||||||
|
if (false !== $mTemp) {
|
||||||
|
$mResult[] = $mTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,21 +73,6 @@ class ResponseCollection extends \MailSo\Base\Collection
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFetchResult($oLogger) : array
|
|
||||||
{
|
|
||||||
$aReturn = array();
|
|
||||||
foreach ($this as $oResponse) {
|
|
||||||
if (FetchResponse::IsValidFetchImapResponse($oResponse)) {
|
|
||||||
if (FetchResponse::IsNotEmptyFetchImapResponse($oResponse)) {
|
|
||||||
$aReturn[] = new FetchResponse($oResponse);
|
|
||||||
} else if ($oLogger) {
|
|
||||||
$oLogger->Write('Skipped Imap Response! ['.$oResponse->ToLine().']', \MailSo\Log\Enumerations\Type::NOTICE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $aReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFoldersResult(string $sStatus, ImapClient $oImapClient) : array
|
public function getFoldersResult(string $sStatus, ImapClient $oImapClient) : array
|
||||||
{
|
{
|
||||||
$aReturn = array();
|
$aReturn = array();
|
||||||
|
|
@ -159,142 +144,4 @@ class ResponseCollection extends \MailSo\Base\Collection
|
||||||
return $aReturn;
|
return $aReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMessageSimpleSearchResult(bool $bReturnUid) : array
|
|
||||||
{
|
|
||||||
$aReturn = array();
|
|
||||||
foreach ($this as $oResponse) {
|
|
||||||
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'SEARCH' === $oResponse->ResponseList[2]) ? 1 : 0;
|
|
||||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
|
||||||
&& ('SEARCH' === $oResponse->StatusOrIndex || $iOffset)
|
|
||||||
&& \is_array($oResponse->ResponseList)
|
|
||||||
&& 2 < \count($oResponse->ResponseList))
|
|
||||||
{
|
|
||||||
$iLen = \count($oResponse->ResponseList);
|
|
||||||
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
|
||||||
$aReturn[] = (int) $oResponse->ResponseList[$iIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return \array_reverse($aReturn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMessageSimpleSortResult(bool $bReturnUid) : array
|
|
||||||
{
|
|
||||||
$aReturn = array();
|
|
||||||
foreach ($this as $oResponse) {
|
|
||||||
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'SORT' === $oResponse->ResponseList[2]) ? 1 : 0;
|
|
||||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
|
||||||
&& ('SORT' === $oResponse->StatusOrIndex || $iOffset)
|
|
||||||
&& \is_array($oResponse->ResponseList)
|
|
||||||
&& 2 < \count($oResponse->ResponseList))
|
|
||||||
{
|
|
||||||
$iLen = \count($oResponse->ResponseList);
|
|
||||||
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
|
||||||
$aReturn[] = (int) $oResponse->ResponseList[$iIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $aReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMessageSimpleThreadResult(bool $bReturnUid) : array
|
|
||||||
{
|
|
||||||
$aReturn = array();
|
|
||||||
foreach ($this as $oResponse) {
|
|
||||||
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && 'THREAD' === $oResponse->ResponseList[2]) ? 1 : 0;
|
|
||||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
|
||||||
&& ('THREAD' === $oResponse->StatusOrIndex || $iOffset)
|
|
||||||
&& \is_array($oResponse->ResponseList)
|
|
||||||
&& 2 < \count($oResponse->ResponseList))
|
|
||||||
{
|
|
||||||
$iLen = \count($oResponse->ResponseList);
|
|
||||||
for ($iIndex = 2 + $iOffset; $iIndex < $iLen; ++$iIndex) {
|
|
||||||
$aNewValue = $this->validateThreadItem($oResponse->ResponseList[$iIndex]);
|
|
||||||
if (\is_array($aNewValue)) {
|
|
||||||
$aReturn[] = $aNewValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $aReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNamespaceResult() : NamespaceResult
|
|
||||||
{
|
|
||||||
foreach ($this as $oResponse) {
|
|
||||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType &&
|
|
||||||
'NAMESPACE' === $oResponse->StatusOrIndex)
|
|
||||||
{
|
|
||||||
$oReturn = new NamespaceResult;
|
|
||||||
$oReturn->InitByImapResponse($oResponse);
|
|
||||||
return $oReturn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Exceptions\ResponseException;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSimpleESearchOrESortResult(string $sRequestTag, bool $bReturnUid) : array
|
|
||||||
{
|
|
||||||
$aResult = array();
|
|
||||||
foreach ($this as $oResponse) {
|
|
||||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
|
||||||
&& ('ESEARCH' === $oResponse->StatusOrIndex || 'SORT' === $oResponse->StatusOrIndex)
|
|
||||||
&& \is_array($oResponse->ResponseList)
|
|
||||||
&& isset($oResponse->ResponseList[2][1])
|
|
||||||
&& 'TAG' === $oResponse->ResponseList[2][0] && $sRequestTag === $oResponse->ResponseList[2][1]
|
|
||||||
&& (!$bReturnUid || (!empty($oResponse->ResponseList[3]) && 'UID' === $oResponse->ResponseList[3]))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$i = \count($oResponse->ResponseList) - 1;
|
|
||||||
while (3 < --$i) {
|
|
||||||
$sItem = $oResponse->ResponseList[$i];
|
|
||||||
switch ($sItem)
|
|
||||||
{
|
|
||||||
case 'ALL':
|
|
||||||
case 'MAX':
|
|
||||||
case 'MIN':
|
|
||||||
case 'COUNT':
|
|
||||||
$aResult[$sItem] = $oResponse->ResponseList[$i + 1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $aResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $mValue
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function validateThreadItem($mValue)
|
|
||||||
{
|
|
||||||
$mResult = false;
|
|
||||||
if (\is_numeric($mValue)) {
|
|
||||||
$mResult = (int) $mValue;
|
|
||||||
if (0 >= $mResult) {
|
|
||||||
$mResult = false;
|
|
||||||
}
|
|
||||||
} else if (\is_array($mValue)) {
|
|
||||||
if (1 === \count($mValue) && \is_numeric($mValue[0])) {
|
|
||||||
$mResult = (int) $mValue[0];
|
|
||||||
if (0 >= $mResult) {
|
|
||||||
$mResult = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$mResult = array();
|
|
||||||
foreach ($mValue as $mValueItem) {
|
|
||||||
$mTemp = $this->validateThreadItem($mValueItem);
|
|
||||||
if (false !== $mTemp) {
|
|
||||||
$mResult[] = $mTemp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $mResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue