Added: ResponseCollection::getCapabilityResult()

Bugfix: ResponseCollection $oResult => $this
Removed safe_mode detection
Speedup: ImapClient::partialParseResponseBranch() and partialResponseLiteralCallbackCallable()
This commit is contained in:
djmaze 2020-03-24 14:45:09 +01:00
parent b9c019e05c
commit cd3d8b94b2
6 changed files with 177 additions and 234 deletions

View file

@ -325,14 +325,11 @@ class Http
static public function DetectAndHackFollowLocationUrl(string $sUrl, array &$aOptions, ?\MailSo\Log\Logger $oLogger = null) : string static public function DetectAndHackFollowLocationUrl(string $sUrl, array &$aOptions, ?\MailSo\Log\Logger $oLogger = null) : string
{ {
$sSafeMode = \strtolower(\trim(\ini_get('safe_mode')));
$bSafeMode = 'on' === $sSafeMode || '1' === $sSafeMode;
$sNewUrl = null; $sNewUrl = null;
$sUrl = isset($aOptions[CURLOPT_URL]) ? $aOptions[CURLOPT_URL] : $sUrl; $sUrl = isset($aOptions[CURLOPT_URL]) ? $aOptions[CURLOPT_URL] : $sUrl;
if (isset($aOptions[CURLOPT_FOLLOWLOCATION]) && $aOptions[CURLOPT_FOLLOWLOCATION] && 0 < \strlen($sUrl) && if (isset($aOptions[CURLOPT_FOLLOWLOCATION]) && $aOptions[CURLOPT_FOLLOWLOCATION] && 0 < \strlen($sUrl) &&
($bSafeMode || \ini_get('open_basedir') !== '')) \ini_get('open_basedir') !== '')
{ {
$aOptions[CURLOPT_FOLLOWLOCATION] = false; $aOptions[CURLOPT_FOLLOWLOCATION] = false;

View file

@ -985,10 +985,7 @@ END;
{ {
$iResetTimer = 0; $iResetTimer = 0;
$sSafeMode = \strtolower(\trim(\ini_get('safe_mode'))); $bValidateAction = static::FunctionExistsAndEnabled('set_time_limit');
$bSafeMode = 'on' === $sSafeMode || '1' === $sSafeMode || 'true' === $sSafeMode;
$bValidateAction = !$bSafeMode && static::FunctionExistsAndEnabled('set_time_limit');
} }
if ($bValidateAction && $iTimeToReset < $iTime - $iResetTimer) if ($bValidateAction && $iTimeToReset < $iTime - $iResetTimer)

View file

@ -23,19 +23,19 @@ class ResponseException extends \MailSo\Imap\Exceptions\Exception
*/ */
private $oResponses; private $oResponses;
public function __construct(?ResponseCollection $oResponses = null, string $sMessage = '', int $iCode = 0, ?\Throwable $oPrevious = null) public function __construct(?\MailSo\Imap\ResponseCollection $oResponses = null, string $sMessage = '', int $iCode = 0, ?\Throwable $oPrevious = null)
{ {
parent::__construct($sMessage, $iCode, $oPrevious); parent::__construct($sMessage, $iCode, $oPrevious);
$this->oResponses = $oResponses; $this->oResponses = $oResponses;
} }
public function GetResponses() : ?ResponseCollection public function GetResponses() : ?\MailSo\Imap\ResponseCollection
{ {
return $this->oResponses; return $this->oResponses;
} }
public function GetLastResponse() : ?Response public function GetLastResponse() : ?\MailSo\Imap\Response
{ {
if ($this->oResponses && \count($this->oResponses)) { if ($this->oResponses && \count($this->oResponses)) {
return $this->oResponses[count($this->oResponses) - 1]; return $this->oResponses[count($this->oResponses) - 1];

View file

@ -89,8 +89,6 @@ class ImapClient extends \MailSo\Net\NetClient
$this->iTagCount = 0; $this->iTagCount = 0;
$this->aCapabilityItems = null; $this->aCapabilityItems = null;
$this->oCurrentFolderInfo = null; $this->oCurrentFolderInfo = null;
$this->aFetchCallbacks = null;
$this->iResponseBufParsedPos = 0;
$this->oLastResponse = new ResponseCollection(); $this->oLastResponse = new ResponseCollection();
$this->bNeedNext = true; $this->bNeedNext = true;
@ -130,7 +128,7 @@ class ImapClient extends \MailSo\Net\NetClient
parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned, $sClientCert); parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned, $sClientCert);
$this->getResponse('*', true); $this->aCapabilityItems = $this->getResponse('*')->getCapabilityResult();
if (\MailSo\Net\Enumerations\ConnectionSecurityType::UseStartTLS( if (\MailSo\Net\Enumerations\ConnectionSecurityType::UseStartTLS(
$this->IsSupported('STARTTLS'), $this->iSecurityType)) $this->IsSupported('STARTTLS'), $this->iSecurityType))
@ -272,7 +270,7 @@ class ImapClient extends \MailSo\Net\NetClient
if ($this->bIsLoggined) if ($this->bIsLoggined)
{ {
$this->bIsLoggined = false; $this->bIsLoggined = false;
$this->SendRequestGetResponse('LOGOUT', array()); $this->SendRequestGetResponse('LOGOUT');
} }
return $this; return $this;
@ -294,7 +292,8 @@ class ImapClient extends \MailSo\Net\NetClient
*/ */
public function Capability() : ?array public function Capability() : ?array
{ {
$this->SendRequestGetResponse('CAPABILITY', array(), true); $this->aCapabilityItems = $this->SendRequestGetResponse('CAPABILITY')
->getCapabilityResult();
return $this->aCapabilityItems; return $this->aCapabilityItems;
} }
@ -509,7 +508,7 @@ class ImapClient extends \MailSo\Net\NetClient
throw new \MailSo\Base\Exceptions\InvalidArgumentException(); throw new \MailSo\Base\Exceptions\InvalidArgumentException();
} }
$this->oCurrentFolderInfo = $this->SendRequestGetResponse(($bIsWritable) ? 'SELECT' : 'EXAMINE', $this->oCurrentFolderInfo = $this->SendRequestGetResponse($bIsWritable ? 'SELECT' : 'EXAMINE',
array($this->EscapeString($sFolderName))) array($this->EscapeString($sFolderName)))
->getCurrentFolderInformation($sFolderName, $bIsWritable); ->getCurrentFolderInformation($sFolderName, $bIsWritable);
@ -560,7 +559,6 @@ class ImapClient extends \MailSo\Net\NetClient
*/ */
public function Fetch(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : array public function Fetch(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : array
{ {
$sIndexRange = (string) $sIndexRange;
if (!strlen(\trim($sIndexRange))) if (!strlen(\trim($sIndexRange)))
{ {
$this->writeLogException( $this->writeLogException(
@ -568,24 +566,22 @@ class ImapClient extends \MailSo\Net\NetClient
\MailSo\Log\Enumerations\Type::ERROR, true); \MailSo\Log\Enumerations\Type::ERROR, true);
} }
$this->aFetchCallbacks = array();
try {
$aFetchItems = Enumerations\FetchType::ChangeFetchItemsBefourRequest($aInputFetchItems); $aFetchItems = Enumerations\FetchType::ChangeFetchItemsBefourRequest($aInputFetchItems);
foreach ($aFetchItems as $sName => $mItem) foreach ($aFetchItems as $sName => $mItem)
{ {
if (0 < \strlen($sName) && '' !== $mItem) if (0 < \strlen($sName) && '' !== $mItem)
{ {
if (null === $this->aFetchCallbacks)
{
$this->aFetchCallbacks = array();
}
$this->aFetchCallbacks[$sName] = $mItem; $this->aFetchCallbacks[$sName] = $mItem;
} }
} }
$oResult = $this->SendRequestGetResponse(($bIndexIsUid ? 'UID ' : '').'FETCH', $oResult = $this->SendRequestGetResponse(($bIndexIsUid ? 'UID ' : '').'FETCH',
array($sIndexRange, \array_keys($aFetchItems))); array($sIndexRange, \array_keys($aFetchItems)));
} finally {
$this->aFetchCallbacks = null; $this->aFetchCallbacks = array();
}
return $oResult->getFetchResult(); return $oResult->getFetchResult();
} }
@ -1011,10 +1007,10 @@ 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
*/ */
public function SendRequestGetResponse(string $sCommand, array $aParams = array(), bool $bFindCapa = false) : ResponseCollection public function SendRequestGetResponse(string $sCommand, array $aParams = array()) : ResponseCollection
{ {
$this->SendRequest($sCommand, $aParams); $this->SendRequest($sCommand, $aParams);
return $this->getResponse(null, $bFindCapa); return $this->getResponse();
} }
public function GetLastResponse() : ResponseCollection public function GetLastResponse() : ResponseCollection
@ -1022,36 +1018,31 @@ class ImapClient extends \MailSo\Net\NetClient
return $this->oLastResponse; return $this->oLastResponse;
} }
protected function parseResponse(string $sEndTag = null, bool $bFindCapa = false) : ?ResponseCollection /**
* @throws \MailSo\Imap\Exceptions\ResponseNotFoundException
* @throws \MailSo\Imap\Exceptions\InvalidResponseException
* @throws \MailSo\Imap\Exceptions\NegativeResponseException
*/
private function getResponse(string $sEndTag = null) : ResponseCollection
{ {
$oResponseCollection = new ResponseCollection(); try {
$oResult = new ResponseCollection();
if (\is_resource($this->rConnect)) if (\is_resource($this->rConnect)) {
{
$oImapResponse = null;
$sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag; $sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag;
while (true) while (true) {
{ $oResponse = Response::NewInstance();
$oImapResponse = Response::NewInstance();
$this->partialParseResponseBranch($oImapResponse); $this->partialParseResponseBranch($oResponse);
if (Enumerations\ResponseType::UNKNOWN === $oImapResponse->ResponseType) if (Enumerations\ResponseType::UNKNOWN === $oResponse->ResponseType) {
{ throw new Exceptions\ResponseNotFoundException();
return null;
} }
if ($bFindCapa) $oResult->append($oResponse);
{ if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) {
$this->initCapabilityImapResponse($oImapResponse); if (isset($this->aTagTimeouts[$sEndTag])) {
}
$oResponseCollection->append($oImapResponse);
if ($sEndTag === $oImapResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oImapResponse->ResponseType)
{
if (isset($this->aTagTimeouts[$sEndTag]))
{
$this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')',
\MailSo\Log\Enumerations\Type::TIME); \MailSo\Log\Enumerations\Type::TIME);
@ -1061,29 +1052,14 @@ class ImapClient extends \MailSo\Net\NetClient
break; break;
} }
unset($oImapResponse); unset($oResponse);
} }
} }
$this->iResponseBufParsedPos = 0; $this->oLastResponse = $oResult;
$this->oLastResponse = $oResponseCollection;
return $this->oLastResponse;
}
/**
* @throws \MailSo\Imap\Exceptions\ResponseNotFoundException
* @throws \MailSo\Imap\Exceptions\InvalidResponseException
* @throws \MailSo\Imap\Exceptions\NegativeResponseException
*/
private function getResponse(string $sEndTag = null, bool $bFindCapa = false) : ResponseCollection
{
$oResult = $this->parseResponse($sEndTag, $bFindCapa);
try {
if (!$oResult) {
throw new Exceptions\ResponseNotFoundException();
}
$oResult->validate(); $oResult->validate();
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); $this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING);
throw $e; throw $e;
@ -1092,50 +1068,26 @@ class ImapClient extends \MailSo\Net\NetClient
return $oResult; return $oResult;
} }
private function initCapabilityImapResponse(Response $oImapResponse) : void
{
if (Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
&& \is_array($oImapResponse->ResponseList))
{
$aList = null;
if (isset($oImapResponse->ResponseList[1]) && \is_string($oImapResponse->ResponseList[1]) &&
'CAPABILITY' === \strtoupper($oImapResponse->ResponseList[1]))
{
$aList = \array_slice($oImapResponse->ResponseList, 2);
}
else if ($oImapResponse->OptionalResponse && \is_array($oImapResponse->OptionalResponse) &&
1 < \count($oImapResponse->OptionalResponse) && \is_string($oImapResponse->OptionalResponse[0]) &&
'CAPABILITY' === \strtoupper($oImapResponse->OptionalResponse[0]))
{
$aList = \array_slice($oImapResponse->OptionalResponse, 1);
}
if (\is_array($aList) && 0 < \count($aList))
{
$this->aCapabilityItems = \array_map('strtoupper', $aList);
}
}
}
/** /**
* @return array|string * @return array|string
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
*/ */
private function partialParseResponseBranch(?Response $oImapResponse, int $iStackIndex = -1, private function partialParseResponseBranch(?Response $oImapResponse,
bool $bTreatAsAtom = false, string $sParentToken = '', string $sOpenBracket = '') bool $bTreatAsAtom = false, string $sParentToken = '', string $sOpenBracket = '')
{ {
++$iStackIndex; if ($oImapResponse) {
$this->iResponseBufParsedPos = 0;
$this->bNeedNext = true;
}
$iPos = $this->iResponseBufParsedPos; $iPos = $this->iResponseBufParsedPos;
$sPreviousAtomUpperCase = null; $sPreviousAtomUpperCase = null;
$bIsEndOfList = false; $sClosingBracket = ')';
$bIsClosingBracketSquare = false;
$iLiteralLen = 0; $iLiteralLen = 0;
$iBufferEndIndex = 0; $iBufferEndIndex = 0;
$iDebugCount = 0; $iDebugCount = 0;
$rImapLiteralStream = null;
$bIsGotoDefault = false; $bIsGotoDefault = false;
$bIsGotoLiteral = false; $bIsGotoLiteral = false;
$bIsGotoLiteralEnd = false; $bIsGotoLiteralEnd = false;
@ -1147,12 +1099,12 @@ class ImapClient extends \MailSo\Net\NetClient
$sAtomBuilder = $bTreatAsAtom ? '' : null; $sAtomBuilder = $bTreatAsAtom ? '' : null;
$aList = array(); $aList = array();
if (null !== $oImapResponse) if ($oImapResponse)
{ {
$aList =& $oImapResponse->ResponseList; $aList =& $oImapResponse->ResponseList;
} }
while (!$bIsEndOfList) while (true)
{ {
if (100000 === ++$iDebugCount) if (100000 === ++$iDebugCount)
{ {
@ -1179,7 +1131,7 @@ class ImapClient extends \MailSo\Net\NetClient
$bIsGotoLiteralEnd = true; $bIsGotoLiteralEnd = true;
if ($this->partialResponseLiteralCallbackCallable( if ($this->partialResponseLiteralCallbackCallable(
$sParentToken, null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), $this->rConnect, $iLiteralLen)) $sParentToken, null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), $iLiteralLen))
{ {
if (!$bTreatAsAtom) if (!$bTreatAsAtom)
{ {
@ -1238,7 +1190,6 @@ class ImapClient extends \MailSo\Net\NetClient
} }
else if ($bIsGotoLiteralEnd) else if ($bIsGotoLiteralEnd)
{ {
$rImapLiteralStream = null;
$sPreviousAtomUpperCase = null; $sPreviousAtomUpperCase = null;
$this->bNeedNext = true; $this->bNeedNext = true;
$bIsGotoLiteralEnd = false; $bIsGotoLiteralEnd = false;
@ -1249,12 +1200,13 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
if ($bTreatAsAtom) if ($bTreatAsAtom)
{ {
$sAtomBlock = $this->partialParseResponseBranch(null, $iStackIndex, true, $sAtomBlock = $this->partialParseResponseBranch(null, true,
null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), $sOpenBracket); null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase),
$sOpenBracket);
$sAtomBuilder .= $sAtomBlock; $sAtomBuilder .= $sAtomBlock;
$iPos = $this->iResponseBufParsedPos; $iPos = $this->iResponseBufParsedPos;
$sAtomBuilder .= ($bIsClosingBracketSquare) ? ']' : ')'; $sAtomBuilder .= $sClosingBracket;
} }
$sPreviousAtomUpperCase = null; $sPreviousAtomUpperCase = null;
@ -1264,13 +1216,14 @@ class ImapClient extends \MailSo\Net\NetClient
} }
else if ($bIsGotoNotAtomBracket) else if ($bIsGotoNotAtomBracket)
{ {
$aSubItems = $this->partialParseResponseBranch(null, $iStackIndex, false, $aSubItems = $this->partialParseResponseBranch(null, false,
null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), $sOpenBracket); null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase),
$sOpenBracket);
$aList[] = $aSubItems; $aList[] = $aSubItems;
$iPos = $this->iResponseBufParsedPos; $iPos = $this->iResponseBufParsedPos;
$sPreviousAtomUpperCase = null; $sPreviousAtomUpperCase = null;
if (null !== $oImapResponse && $oImapResponse->IsStatusResponse) if ($oImapResponse && $oImapResponse->IsStatusResponse)
{ {
$oImapResponse->OptionalResponse = $aSubItems; $oImapResponse->OptionalResponse = $aSubItems;
@ -1285,7 +1238,6 @@ class ImapClient extends \MailSo\Net\NetClient
else else
{ {
$iBufferEndIndex = \strlen($this->sResponseBuffer) - 3; $iBufferEndIndex = \strlen($this->sResponseBuffer) - 3;
$this->bResponseBufferChanged = false;
if ($iPos > $iBufferEndIndex) if ($iPos > $iBufferEndIndex)
{ {
@ -1298,15 +1250,10 @@ class ImapClient extends \MailSo\Net\NetClient
switch (true) switch (true)
{ {
case ']' === $sChar: case ']' === $sChar:
++$iPos;
$sPreviousAtomUpperCase = null;
$bIsEndOfList = true;
break;
case ')' === $sChar: case ')' === $sChar:
++$iPos; ++$iPos;
$sPreviousAtomUpperCase = null; $sPreviousAtomUpperCase = null;
$bIsEndOfList = true; break 2;
break;
case ' ' === $sChar: case ' ' === $sChar:
if ($bTreatAsAtom) if ($bTreatAsAtom)
{ {
@ -1315,30 +1262,19 @@ class ImapClient extends \MailSo\Net\NetClient
++$iPos; ++$iPos;
break; break;
case '[' === $sChar: case '[' === $sChar:
$bIsClosingBracketSquare = true;
case '(' === $sChar: case '(' === $sChar:
if ('(' === $sChar) $sOpenBracket = $sChar;
{ $sClosingBracket = '[' === $sChar ? ']' : ')';
$bIsClosingBracketSquare = false;
}
if ($bTreatAsAtom)
{
$sAtomBuilder .= $bIsClosingBracketSquare ? '[' : '(';
}
++$iPos;
$this->iResponseBufParsedPos = $iPos;
if ($bTreatAsAtom) if ($bTreatAsAtom)
{ {
$sAtomBuilder .= $sChar;
$bIsGotoAtomBracket = true; $bIsGotoAtomBracket = true;
$sOpenBracket = $bIsClosingBracketSquare ? '[' : '(';
} }
else else
{ {
$bIsGotoNotAtomBracket = true; $bIsGotoNotAtomBracket = true;
$sOpenBracket = $bIsClosingBracketSquare ? '[' : '(';
} }
$this->iResponseBufParsedPos = ++$iPos;
break; break;
case '{' === $sChar: case '{' === $sChar:
$bIsLiteralParsed = false; $bIsLiteralParsed = false;
@ -1417,7 +1353,6 @@ class ImapClient extends \MailSo\Net\NetClient
} }
else else
{ {
// $iSkipClosingPos = 0;
$bIsQuotedParsed = true; $bIsQuotedParsed = true;
if ($bTreatAsAtom) if ($bTreatAsAtom)
{ {
@ -1451,7 +1386,7 @@ class ImapClient extends \MailSo\Net\NetClient
default: default:
$iCharBlockStartPos = $iPos; $iCharBlockStartPos = $iPos;
if (null !== $oImapResponse && $oImapResponse->IsStatusResponse) if ($oImapResponse && $oImapResponse->IsStatusResponse)
{ {
$iPos = $iBufferEndIndex; $iPos = $iBufferEndIndex;
@ -1478,8 +1413,9 @@ class ImapClient extends \MailSo\Net\NetClient
++$iPos; ++$iPos;
$this->iResponseBufParsedPos = $iPos; $this->iResponseBufParsedPos = $iPos;
$sListBlock = $this->partialParseResponseBranch(null, $iStackIndex, true, $sListBlock = $this->partialParseResponseBranch(null, true,
null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), '['); null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase),
'[');
if (null !== $sListBlock) if (null !== $sListBlock)
{ {
@ -1520,7 +1456,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
if (null !== $oImapResponse) if ($oImapResponse)
{ {
// if (1 === \count($aList)) // if (1 === \count($aList))
if (!$bCountOneInited && 1 === \count($aList)) if (!$bCountOneInited && 1 === \count($aList))
@ -1577,11 +1513,6 @@ class ImapClient extends \MailSo\Net\NetClient
} }
$this->iResponseBufParsedPos = $iPos; $this->iResponseBufParsedPos = $iPos;
if (null !== $oImapResponse)
{
$this->bNeedNext = true;
$this->iResponseBufParsedPos = 0;
}
if (100000 < $iDebugCount) if (100000 < $iDebugCount)
{ {
@ -1591,11 +1522,12 @@ class ImapClient extends \MailSo\Net\NetClient
return $bTreatAsAtom ? $sAtomBuilder : $aList; return $bTreatAsAtom ? $sAtomBuilder : $aList;
} }
/** private function partialResponseLiteralCallbackCallable(string $sParent, string $sLiteralAtomUpperCase, int $iLiteralLen) : bool
* @param resource $rImapStream
*/
private function partialResponseLiteralCallbackCallable(string $sParent, string $sLiteralAtomUpperCase, $rImapStream, int $iLiteralLen) : bool
{ {
if (!$this->aFetchCallbacks) {
return false;
}
$sLiteralAtomUpperCasePeek = ''; $sLiteralAtomUpperCasePeek = '';
if (0 === \strpos($sLiteralAtomUpperCase, 'BODY')) if (0 === \strpos($sLiteralAtomUpperCase, 'BODY'))
{ {
@ -1603,8 +1535,6 @@ class ImapClient extends \MailSo\Net\NetClient
} }
$sFetchKey = ''; $sFetchKey = '';
if (\is_array($this->aFetchCallbacks))
{
if (0 < \strlen($sLiteralAtomUpperCasePeek) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCasePeek])) if (0 < \strlen($sLiteralAtomUpperCasePeek) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCasePeek]))
{ {
$sFetchKey = $sLiteralAtomUpperCasePeek; $sFetchKey = $sLiteralAtomUpperCasePeek;
@ -1613,16 +1543,14 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$sFetchKey = $sLiteralAtomUpperCase; $sFetchKey = $sLiteralAtomUpperCase;
} }
if (empty($this->aFetchCallbacks[$sFetchKey]) || !\is_callable($this->aFetchCallbacks[$sFetchKey])) {
return false;
} }
$bResult = false;
if (0 < \strlen($sFetchKey) && '' !== $this->aFetchCallbacks[$sFetchKey] &&
\is_callable($this->aFetchCallbacks[$sFetchKey]))
{
$rImapLiteralStream = $rImapLiteralStream =
\MailSo\Base\StreamWrappers\Literal::CreateStream($rImapStream, $iLiteralLen); \MailSo\Base\StreamWrappers\Literal::CreateStream($this->rConnect, $iLiteralLen);
$bResult = true;
$this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. $this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase.
' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE); ' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE);
@ -1639,7 +1567,7 @@ class ImapClient extends \MailSo\Net\NetClient
$this->writeLogException($oException); $this->writeLogException($oException);
} }
if (\is_resource($rImapLiteralStream)) if ($rImapLiteralStream)
{ {
$iNotReadLiteralLen = 0; $iNotReadLiteralLen = 0;
@ -1662,16 +1590,13 @@ class ImapClient extends \MailSo\Net\NetClient
$iNotReadLiteralLen += \strlen($sBuf); $iNotReadLiteralLen += \strlen($sBuf);
} }
if (\is_resource($rImapLiteralStream) && !\feof($rImapLiteralStream)) if (!\feof($rImapLiteralStream))
{ {
\stream_get_contents($rImapLiteralStream); \stream_get_contents($rImapLiteralStream);
} }
} }
if (\is_resource($rImapLiteralStream))
{
\fclose($rImapLiteralStream); \fclose($rImapLiteralStream);
}
if ($iNotReadLiteralLen > 0) if ($iNotReadLiteralLen > 0)
{ {
@ -1688,9 +1613,8 @@ class ImapClient extends \MailSo\Net\NetClient
\MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen); \MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen);
$this->bRunningCallback = false; $this->bRunningCallback = false;
}
return $bResult; return true;
} }
private function prepareParamLine(array $aParams = array()) : string private function prepareParamLine(array $aParams = array()) : string

View file

@ -54,6 +54,33 @@ class ResponseCollection extends \MailSo\Base\Collection
return $this; return $this;
} }
public function getCapabilityResult() : ?array
{
foreach ($this as $oResponse) {
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
&& \is_array($oResponse->ResponseList))
{
$aList = null;
if (isset($oResponse->ResponseList[1]) && \is_string($oResponse->ResponseList[1]) &&
'CAPABILITY' === \strtoupper($oResponse->ResponseList[1]))
{
$aList = \array_slice($oResponse->ResponseList, 2);
}
else if ($oResponse->OptionalResponse && \is_array($oResponse->OptionalResponse) &&
1 < \count($oResponse->OptionalResponse) && \is_string($oResponse->OptionalResponse[0]) &&
'CAPABILITY' === \strtoupper($oResponse->OptionalResponse[0]))
{
$aList = \array_slice($oResponse->OptionalResponse, 1);
}
if (\is_array($aList) && 0 < \count($aList)) {
return \array_map('strtoupper', $aList);
}
}
}
return null;
}
public function getFetchResult() : array public function getFetchResult() : array
{ {
$aReturn = array(); $aReturn = array();
@ -174,7 +201,7 @@ class ResponseCollection extends \MailSo\Base\Collection
public function getMessageSimpleSortResult(string $sStatus, bool $bReturnUid) : array public function getMessageSimpleSortResult(string $sStatus, bool $bReturnUid) : array
{ {
$aReturn = array(); $aReturn = array();
foreach ($oResult as $oResponse) { foreach ($this as $oResponse) {
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && $sStatus === $oResponse->ResponseList[2]) ? 1 : 0; $iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && $sStatus === $oResponse->ResponseList[2]) ? 1 : 0;
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
&& ($sStatus === $oResponse->StatusOrIndex || $iOffset) && ($sStatus === $oResponse->StatusOrIndex || $iOffset)
@ -193,7 +220,7 @@ class ResponseCollection extends \MailSo\Base\Collection
public function getMessageSimpleThreadResult($sStatus, $bReturnUid) : array public function getMessageSimpleThreadResult($sStatus, $bReturnUid) : array
{ {
$aReturn = array(); $aReturn = array();
foreach ($aResult as $oResponse) { foreach ($this as $oResponse) {
$iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && $sStatus === $oResponse->ResponseList[2]) ? 1 : 0; $iOffset = ($bReturnUid && 'UID' === $oResponse->StatusOrIndex && !empty($oResponse->ResponseList[2]) && $sStatus === $oResponse->ResponseList[2]) ? 1 : 0;
if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
&& ($sStatus === $oResponse->StatusOrIndex || $iOffset) && ($sStatus === $oResponse->StatusOrIndex || $iOffset)

View file

@ -471,10 +471,8 @@ class Client {
// TODO rainloop // TODO rainloop
$curl = curl_init($url); $curl = curl_init($url);
$sSafeMode = strtolower(trim(@ini_get('safe_mode')));
$bSafeMode = 'on' === $sSafeMode || '1' === $sSafeMode;
if (!$bSafeMode && ini_get('open_basedir') === '') if (ini_get('open_basedir') === '')
{ {
curl_setopt_array($curl, $settings); curl_setopt_array($curl, $settings);
$data = curl_exec($curl); $data = curl_exec($curl);