refactor: use new mail interface desing

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-14 22:44:28 -04:00
parent b37da945f5
commit ca646eec3c
9 changed files with 311 additions and 200 deletions

View File

@@ -15,42 +15,21 @@ final class FetchOptions
public static function default(): self
{
return self::message();
}
public static function summary(): self
{
return new self([
'UID',
'FLAGS',
'INTERNALDATE',
'RFC822.SIZE',
]);
return (new self([]))
->withUid()
->withFlags()
->withInternalDate()
->withSize();
}
public static function message(): self
{
return self::summary()
return self::default()
->withHeaders()
->withEnvelope()
->withBodyStructure();
}
public static function fullMessage(): self
{
return self::message()->withBodyText();
}
public function withBodySection(string $section): self
{
$section = strtoupper(trim($section));
if ($section === '') {
return $this;
}
return $this->with(sprintf('BODY[%s]', $section));
}
public static function of(string ...$items): self
{
return new self(self::normalize($items));
@@ -76,6 +55,25 @@ final class FetchOptions
return $this->with('RFC822.SIZE');
}
public function withHeaders(): self
{
return $this->with('BODY[HEADER]');
}
public function withHeader(string ...$fields): self
{
$fields = array_values(array_filter(array_map(
static fn (string $field): string => strtoupper(trim($field)),
$fields,
), static fn (string $field): bool => $field !== ''));
if ($fields === []) {
return $this;
}
return $this->with(sprintf('BODY.PEEK[HEADER.FIELDS (%s)]', implode(' ', $fields)));
}
public function withEnvelope(): self
{
return $this->with('ENVELOPE');
@@ -88,21 +86,18 @@ final class FetchOptions
public function withBodyText(): self
{
return $this->withBodySection('TEXT');
return $this->with('BODY[TEXT]');
}
public function withHeaderFields(string ...$fields): self
public function withBodySection(string $section): self
{
$fields = array_values(array_filter(array_map(
static fn (string $field): string => strtoupper(trim($field)),
$fields,
), static fn (string $field): bool => $field !== ''));
$section = strtoupper(trim($section));
if ($fields === []) {
if ($section === '') {
return $this;
}
return $this->with(sprintf('BODY.PEEK[HEADER.FIELDS (%s)]', implode(' ', $fields)));
return $this->with(sprintf('BODY[%s]', $section));
}
public function with(string $item): self