generated from Nodarx/template
refactor: unify quotes encoding
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
use KTXM\ProviderImap\Client\Protocol\Response\ContinuationResponse;
|
||||
@@ -57,7 +58,7 @@ final class AppendCommand implements CommandInterface
|
||||
|
||||
return new RequestFrame(sprintf(
|
||||
'APPEND %s %s{%d}',
|
||||
$this->quote($this->mailbox),
|
||||
StringEncoder::quote($this->mailbox),
|
||||
$flagSegment,
|
||||
strlen($this->literal),
|
||||
));
|
||||
@@ -86,10 +87,6 @@ final class AppendCommand implements CommandInterface
|
||||
throw new ImapException('APPEND did not receive a tagged completion response.');
|
||||
}
|
||||
|
||||
private function quote(string $mailbox): string
|
||||
{
|
||||
return '"' . addcslashes($mailbox, "\\\"") . '"';
|
||||
}
|
||||
|
||||
private function parseAppendUid(string $text): ?int
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command\Argument;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
|
||||
|
||||
use DateTimeInterface;
|
||||
@@ -190,8 +191,8 @@ final class SearchCriteriaBuilder
|
||||
{
|
||||
return $this->pushExpression(sprintf(
|
||||
'HEADER %s %s',
|
||||
$this->formatString($name),
|
||||
$this->formatString($value),
|
||||
StringEncoder::quote($name),
|
||||
StringEncoder::quote($value),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -287,7 +288,7 @@ final class SearchCriteriaBuilder
|
||||
return $this->pushExpression(sprintf(
|
||||
'%s %s',
|
||||
$key,
|
||||
$quote ? $this->formatString($value) : $value,
|
||||
$quote ? StringEncoder::quote($value) : $value,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -371,9 +372,4 @@ final class SearchCriteriaBuilder
|
||||
default => SequenceSet::parse($value)->toCommand(),
|
||||
};
|
||||
}
|
||||
|
||||
private function formatString(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
@@ -38,7 +39,7 @@ final class CreateCommand implements CommandInterface
|
||||
{
|
||||
unset($tag, $context);
|
||||
|
||||
return new RequestFrame(sprintf('CREATE %s', $this->quote($this->mailbox)));
|
||||
return new RequestFrame(sprintf('CREATE %s', StringEncoder::quote($this->mailbox)));
|
||||
}
|
||||
|
||||
public function handle(ResponseStream $responses, SessionContext $context): CommandStatusResult
|
||||
@@ -57,9 +58,4 @@ final class CreateCommand implements CommandInterface
|
||||
|
||||
throw new ImapException('CREATE did not receive a tagged completion response.');
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
@@ -38,7 +39,7 @@ final class DeleteCommand implements CommandInterface
|
||||
{
|
||||
unset($tag, $context);
|
||||
|
||||
return new RequestFrame(sprintf('DELETE %s', $this->quote($this->mailbox)));
|
||||
return new RequestFrame(sprintf('DELETE %s', StringEncoder::quote($this->mailbox)));
|
||||
}
|
||||
|
||||
public function handle(ResponseStream $responses, SessionContext $context): CommandStatusResult
|
||||
@@ -60,9 +61,4 @@ final class DeleteCommand implements CommandInterface
|
||||
|
||||
throw new ImapException('DELETE did not receive a tagged completion response.');
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Protocol\Parser\ListResponseParser;
|
||||
use KTXM\ProviderImap\Client\Protocol\Parser\StatusResponseParser;
|
||||
use Generator;
|
||||
@@ -66,8 +67,8 @@ final class ListCommand implements CommandInterface
|
||||
|
||||
$command .= sprintf(
|
||||
' %s %s',
|
||||
$this->quote($this->reference),
|
||||
$this->quote($this->pattern),
|
||||
StringEncoder::quote($this->reference),
|
||||
StringEncoder::quote($this->pattern),
|
||||
);
|
||||
|
||||
$returnOptions = $this->returnOptions->toCommand();
|
||||
@@ -158,9 +159,4 @@ final class ListCommand implements CommandInterface
|
||||
$mailbox->readOnly(),
|
||||
);
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
@@ -38,8 +39,8 @@ final class LoginCommand implements CommandInterface
|
||||
|
||||
return new RequestFrame(sprintf(
|
||||
'LOGIN %s %s',
|
||||
$this->quote($this->username),
|
||||
$this->quote($this->password),
|
||||
StringEncoder::quote($this->username),
|
||||
StringEncoder::quote($this->password),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -59,9 +60,4 @@ final class LoginCommand implements CommandInterface
|
||||
|
||||
throw new ImapException('LOGIN did not receive a tagged completion response.');
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Result\MessageTransferResult;
|
||||
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
|
||||
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
|
||||
@@ -66,7 +67,7 @@ final class MessageTransferCommand implements CommandInterface
|
||||
$this->identifierMode === IdentifierMode::Uid ? 'UID ' : '',
|
||||
$this->operation,
|
||||
$this->sequenceSet->toCommand(),
|
||||
$this->quote($this->destinationMailbox),
|
||||
StringEncoder::quote($this->destinationMailbox),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -235,9 +236,4 @@ final class MessageTransferCommand implements CommandInterface
|
||||
'text' => trim($matches[3] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
@@ -41,8 +42,8 @@ final class RenameCommand implements CommandInterface
|
||||
|
||||
return new RequestFrame(sprintf(
|
||||
'RENAME %s %s',
|
||||
$this->quote($this->fromMailbox),
|
||||
$this->quote($this->toMailbox),
|
||||
StringEncoder::quote($this->fromMailbox),
|
||||
StringEncoder::quote($this->toMailbox),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -64,9 +65,4 @@ final class RenameCommand implements CommandInterface
|
||||
|
||||
throw new ImapException('RENAME did not receive a tagged completion response.');
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Mailbox;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
@@ -43,7 +44,7 @@ final class SelectCommand implements CommandInterface
|
||||
return new RequestFrame(sprintf(
|
||||
'%s %s',
|
||||
$this->name(),
|
||||
$this->quote($this->mailbox),
|
||||
StringEncoder::quote($this->mailbox),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -116,9 +117,4 @@ final class SelectCommand implements CommandInterface
|
||||
|
||||
return preg_split('/\s+/', $flags) ?: [];
|
||||
}
|
||||
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
|
||||
use KTXM\ProviderImap\Client\Protocol\Parser\StatusResponseParser;
|
||||
use KTXM\ProviderImap\Client\Result\StatusResult;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
@@ -51,7 +52,7 @@ final class StatusCommand implements CommandInterface
|
||||
|
||||
return new RequestFrame(sprintf(
|
||||
'STATUS %s (%s)',
|
||||
$this->quote($this->mailbox),
|
||||
StringEncoder::quote($this->mailbox),
|
||||
implode(' ', $this->normalizeItems($this->items)),
|
||||
));
|
||||
}
|
||||
@@ -112,8 +113,4 @@ final class StatusCommand implements CommandInterface
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
private function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol;
|
||||
|
||||
final class StringEncoder
|
||||
{
|
||||
public static function quote(string $value): string
|
||||
{
|
||||
return '"' . addcslashes($value, "\\\"") . '"';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user