mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
abstract class ResponseType to enum ResponseType
This commit is contained in:
parent
45de60a7e1
commit
d0dc8c305a
3 changed files with 19 additions and 18 deletions
|
|
@ -16,10 +16,10 @@ namespace MailSo\Imap\Enumerations;
|
|||
* @package Imap
|
||||
* @subpackage Enumerations
|
||||
*/
|
||||
abstract class ResponseType
|
||||
enum ResponseType
|
||||
{
|
||||
const UNKNOWN = 0;
|
||||
const TAGGED = 1;
|
||||
const UNTAGGED = 2;
|
||||
const CONTINUATION = 3;
|
||||
case UNKNOWN;
|
||||
case TAGGED;
|
||||
case UNTAGGED;
|
||||
case CONTINUATION;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace MailSo\Imap;
|
||||
|
||||
use MailSo\Net\Enumerations\ConnectionSecurityType;
|
||||
use MailSo\Imap\Enumerations\ResponseType;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
|
|
@ -159,7 +160,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
if ('CRAM-MD5' === $type)
|
||||
{
|
||||
$oResponse = $this->SendRequestGetResponse('AUTHENTICATE', array($type));
|
||||
$sChallenge = $this->getResponseValue($oResponse, Enumerations\ResponseType::CONTINUATION);
|
||||
$sChallenge = $this->getResponseValue($oResponse, ResponseType::CONTINUATION);
|
||||
$sAuth = $SASL->authenticate($sLogin, $sPassword, $sChallenge);
|
||||
$this->logMask($sAuth);
|
||||
$this->sendRaw($sAuth);
|
||||
|
|
@ -177,11 +178,11 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
$oResponse = $this->getResponse();
|
||||
if ($SASL->hasChallenge()) {
|
||||
$sChallenge = $SASL->challenge($this->getResponseValue($oResponse, Enumerations\ResponseType::CONTINUATION));
|
||||
$sChallenge = $SASL->challenge($this->getResponseValue($oResponse, ResponseType::CONTINUATION));
|
||||
$this->logMask($sChallenge);
|
||||
$this->sendRaw($sChallenge);
|
||||
$oResponse = $this->getResponse();
|
||||
$SASL->verify($this->getResponseValue($oResponse, Enumerations\ResponseType::CONTINUATION));
|
||||
$SASL->verify($this->getResponseValue($oResponse, ResponseType::CONTINUATION));
|
||||
$this->sendRaw('');
|
||||
$oResponse = $this->getResponse();
|
||||
}
|
||||
|
|
@ -192,7 +193,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
$this->logMask($sAuth);
|
||||
$oResponse = $this->SendRequestGetResponse('AUTHENTICATE', array($type, $sAuth));
|
||||
$oR = $oResponse->getLast();
|
||||
if ($oR && Enumerations\ResponseType::CONTINUATION === $oR->ResponseType) {
|
||||
if ($oR && ResponseType::CONTINUATION === $oR->ResponseType) {
|
||||
if (!empty($oR->ResponseList[1]) && \preg_match('/^[a-zA-Z0-9=+\/]+$/', $oR->ResponseList[1])) {
|
||||
$this->logWrite(\base64_decode($oR->ResponseList[1]), \LOG_WARNING);
|
||||
}
|
||||
|
|
@ -203,7 +204,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
else if ($this->hasCapability('LOGINDISABLED'))
|
||||
{
|
||||
$oResponse = $this->SendRequestGetResponse('AUTHENTICATE', array($type));
|
||||
$sB64 = $this->getResponseValue($oResponse, Enumerations\ResponseType::CONTINUATION);
|
||||
$sB64 = $this->getResponseValue($oResponse, ResponseType::CONTINUATION);
|
||||
$this->sendRaw($SASL->authenticate($sLogin, $sPassword, $sB64), true);
|
||||
$this->getResponse();
|
||||
$sPass = $SASL->challenge(''/*UGFzc3dvcmQ6*/);
|
||||
|
|
@ -374,7 +375,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
try {
|
||||
$oResponseCollection = $this->SendRequestGetResponse('NAMESPACE');
|
||||
foreach ($oResponseCollection as $oResponse) {
|
||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||
if (ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||
&& 'NAMESPACE' === $oResponse->StatusOrIndex)
|
||||
{
|
||||
return new NamespaceResult($oResponse);
|
||||
|
|
@ -455,10 +456,10 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
return $this->getResponse();
|
||||
}
|
||||
|
||||
protected function getResponseValue(ResponseCollection $oResponseCollection, int $type = 0) : string
|
||||
protected function getResponseValue(ResponseCollection $oResponseCollection, ResponseType $type) : string
|
||||
{
|
||||
$oResponse = $oResponseCollection->getLast();
|
||||
if ($oResponse && (!$type || $type === $oResponse->ResponseType)) {
|
||||
if ($oResponse && ($type === ResponseType::UNKNOWN || $type === $oResponse->ResponseType)) {
|
||||
$sResult = $oResponse->ResponseList[1] ?? null;
|
||||
if ($sResult) {
|
||||
return $sResult;
|
||||
|
|
@ -512,7 +513,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
$oResult->append($oResponse);
|
||||
|
||||
if ($oResponse->IsStatusResponse
|
||||
&& Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||
&& ResponseType::UNTAGGED === $oResponse->ResponseType
|
||||
&& Enumerations\ResponseStatus::PREAUTH === $oResponse->StatusOrIndex
|
||||
// && (Enumerations\ResponseStatus::PREAUTH === $oResponse->StatusOrIndex || Enumerations\ResponseStatus::BYE === $oResponse->StatusOrIndex)
|
||||
) {
|
||||
|
|
@ -525,7 +526,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
// \SnappyMail\Log::warning('IMAP', "{$oResponse->OptionalResponse[0]}: {$this->lastCommand}");
|
||||
}
|
||||
|
||||
if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) {
|
||||
if ($sEndTag === $oResponse->Tag || ResponseType::CONTINUATION === $oResponse->ResponseType) {
|
||||
if (isset($this->aTagTimeouts[$sEndTag])) {
|
||||
$this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', \LOG_DEBUG);
|
||||
|
||||
|
|
@ -557,7 +558,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
|
||||
while (true) {
|
||||
$oResponse = $this->partialParseResponse();
|
||||
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType) {
|
||||
if (ResponseType::UNTAGGED === $oResponse->ResponseType) {
|
||||
yield $oResponse;
|
||||
} else {
|
||||
$oResult->append($oResponse);
|
||||
|
|
@ -569,7 +570,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
// \SnappyMail\Log::warning('IMAP', "{$oResponse->OptionalResponse[0]}: {$this->lastCommand}");
|
||||
}
|
||||
|
||||
if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) {
|
||||
if ($sEndTag === $oResponse->Tag || ResponseType::CONTINUATION === $oResponse->ResponseType) {
|
||||
if (isset($this->aTagTimeouts[$sEndTag])) {
|
||||
$this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', \LOG_DEBUG);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Response
|
|||
|
||||
public bool $IsStatusResponse = false;
|
||||
|
||||
public int $ResponseType = 0;
|
||||
public ResponseType $ResponseType = ResponseType::UNKNOWN;
|
||||
|
||||
public ?string $Tag = null;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue