generated from Nodarx/template
feat: initial version
Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
10
lib/Client/Protocol/Command/Argument/Argument.php
Normal file
10
lib/Client/Protocol/Command/Argument/Argument.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
interface Argument
|
||||
{
|
||||
public function __toString(): string;
|
||||
}
|
||||
24
lib/Client/Protocol/Command/Argument/Date.php
Normal file
24
lib/Client/Protocol/Command/Argument/Date.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
readonly class Date implements Argument
|
||||
{
|
||||
public function __construct(private DateTimeInterface $value)
|
||||
{
|
||||
}
|
||||
|
||||
public static function tryFrom(?DateTimeInterface $value): ?self
|
||||
{
|
||||
return is_null($value) ? null : new self($value);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value->format('d-M-Y');
|
||||
}
|
||||
}
|
||||
24
lib/Client/Protocol/Command/Argument/DateTime.php
Normal file
24
lib/Client/Protocol/Command/Argument/DateTime.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
readonly class DateTime implements Argument
|
||||
{
|
||||
public function __construct(private DateTimeInterface $value)
|
||||
{
|
||||
}
|
||||
|
||||
public static function tryFrom(?DateTimeInterface $value): ?self
|
||||
{
|
||||
return is_null($value) ? null : new self($value);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return '"'.$this->value->format('d-M-Y H:i:s O').'"';
|
||||
}
|
||||
}
|
||||
28
lib/Client/Protocol/Command/Argument/ParenthesizedList.php
Normal file
28
lib/Client/Protocol/Command/Argument/ParenthesizedList.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
final readonly class ParenthesizedList implements Argument
|
||||
{
|
||||
/**
|
||||
* @param list<string> $items
|
||||
*/
|
||||
public function __construct(public array $items)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $items
|
||||
*/
|
||||
public static function tryFrom(?array $items): ?self
|
||||
{
|
||||
return empty($items) ? null : new self($items);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('(%s)', implode(' ', $this->items));
|
||||
}
|
||||
}
|
||||
17
lib/Client/Protocol/Command/Argument/QuotedString.php
Normal file
17
lib/Client/Protocol/Command/Argument/QuotedString.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
final readonly class QuotedString implements Argument
|
||||
{
|
||||
public function __construct(private string $value)
|
||||
{
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('"%s"', $this->value);
|
||||
}
|
||||
}
|
||||
13
lib/Client/Protocol/Command/Argument/Search/All.php
Normal file
13
lib/Client/Protocol/Command/Argument/Search/All.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Search;
|
||||
|
||||
class All implements Criteria
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'ALL';
|
||||
}
|
||||
}
|
||||
15
lib/Client/Protocol/Command/Argument/Search/Before.php
Normal file
15
lib/Client/Protocol/Command/Argument/Search/Before.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Search;
|
||||
|
||||
use Gricob\IMAP\Protocol\Command\Argument\Date;
|
||||
|
||||
readonly class Before extends Date implements Criteria
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'BEFORE '.parent::__toString();
|
||||
}
|
||||
}
|
||||
11
lib/Client/Protocol/Command/Argument/Search/Criteria.php
Normal file
11
lib/Client/Protocol/Command/Argument/Search/Criteria.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Search;
|
||||
|
||||
use Gricob\IMAP\Protocol\Command\Argument\Argument;
|
||||
|
||||
interface Criteria extends Argument
|
||||
{
|
||||
}
|
||||
19
lib/Client/Protocol/Command/Argument/Search/Header.php
Normal file
19
lib/Client/Protocol/Command/Argument/Search/Header.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Search;
|
||||
|
||||
use Gricob\IMAP\Protocol\Command\Argument\QuotedString;
|
||||
|
||||
class Header implements Criteria
|
||||
{
|
||||
public function __construct(
|
||||
private string $fieldName,
|
||||
private string $value,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('HEADER %s %s', $this->fieldName, new QuotedString($this->value));
|
||||
}
|
||||
}
|
||||
17
lib/Client/Protocol/Command/Argument/Search/Not.php
Normal file
17
lib/Client/Protocol/Command/Argument/Search/Not.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Search;
|
||||
|
||||
final readonly class Not implements Criteria
|
||||
{
|
||||
public function __construct(private Criteria $criteria)
|
||||
{
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'NOT ('.$this->criteria.')';
|
||||
}
|
||||
}
|
||||
15
lib/Client/Protocol/Command/Argument/Search/Since.php
Normal file
15
lib/Client/Protocol/Command/Argument/Search/Since.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Search;
|
||||
|
||||
use Gricob\IMAP\Protocol\Command\Argument\Date;
|
||||
|
||||
readonly class Since extends Date implements Criteria
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'SINCE '.parent::__toString();
|
||||
}
|
||||
}
|
||||
36
lib/Client/Protocol/Command/Argument/SequenceSet.php
Normal file
36
lib/Client/Protocol/Command/Argument/SequenceSet.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
final class SequenceSet implements Argument
|
||||
{
|
||||
/**
|
||||
* @var array<int>
|
||||
*/
|
||||
private array $numbers;
|
||||
private ?string $range;
|
||||
|
||||
public function __construct(int ...$numbers)
|
||||
{
|
||||
$this->numbers = $numbers;
|
||||
$this->range = null;
|
||||
}
|
||||
|
||||
public static function range(int $from, int $to): self
|
||||
{
|
||||
$set = new self();
|
||||
$set->range = $from . ':' . $to;
|
||||
return $set;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
if ($this->range !== null) {
|
||||
return $this->range;
|
||||
}
|
||||
|
||||
return implode(',', $this->numbers);
|
||||
}
|
||||
}
|
||||
30
lib/Client/Protocol/Command/Argument/Store/Flags.php
Normal file
30
lib/Client/Protocol/Command/Argument/Store/Flags.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument\Store;
|
||||
|
||||
use Gricob\IMAP\Protocol\Command\Argument\Argument;
|
||||
|
||||
final readonly class Flags implements Argument
|
||||
{
|
||||
/**
|
||||
* @param list<string> $flags
|
||||
*/
|
||||
public function __construct(
|
||||
private array $flags,
|
||||
private string $modifier = '',
|
||||
private bool $silent = true,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf(
|
||||
'%sFLAGS%s (%s)',
|
||||
$this->modifier,
|
||||
$this->silent ? '.SILENT' : '',
|
||||
implode(' ', $this->flags),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Command\Argument;
|
||||
|
||||
final readonly class SynchronizingLiteral implements Argument
|
||||
{
|
||||
public function __construct(private string $value)
|
||||
{
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf(
|
||||
'{%s}',
|
||||
strlen($this->value)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user