From 8fd826d459df175ad328947c28d8b6f6661e0019 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 13 Sep 2025 19:00:28 -0400 Subject: [PATCH 1/2] Add ability to provide key => value pairs in Str::list --- src/Support/Str.php | 12 +++++++++--- tests/Unit/Support/StrTest.php | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Support/Str.php b/src/Support/Str.php index 579bbf7..9a8c991 100644 --- a/src/Support/Str.php +++ b/src/Support/Str.php @@ -13,12 +13,18 @@ public static function list(array $list): string { $values = []; - foreach ($list as $value) { + foreach ($list as $key => $value) { if (is_array($value)) { - $values[] = static::list($value); + $token = static::list($value); } else { - $values[] = $value; + $token = $value; } + + if (is_string($key)) { + $token = $key.' '.$token; + } + + $values[] = $token; } return sprintf('(%s)', implode(' ', $values)); diff --git a/tests/Unit/Support/StrTest.php b/tests/Unit/Support/StrTest.php index ba61b5d..7dcef7c 100644 --- a/tests/Unit/Support/StrTest.php +++ b/tests/Unit/Support/StrTest.php @@ -65,6 +65,11 @@ expect(Str::list([]))->toBe('()'); }); +test('list returns a properly formatted parenthesized list for an array with string keys', function () { + expect(Str::list(['a' => '"b"', 'c' => '"d"']))->toBe('(a "b" c "d")'); + expect(Str::list(['a' => ['"b"', '"c"'], 'd' => '"e"']))->toBe('(a ("b" "c") d "e")'); +}); + test('enums returns value for a single backed enum', function () { $result = Str::enums(ImapFlag::Seen); From 1b5218dbccefbeb5848843abbc3d062a75ab091e Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 13 Sep 2025 19:20:06 -0400 Subject: [PATCH 2/2] Add ability to set query fetch modifiers --- src/Connection/ConnectionInterface.php | 2 +- src/Connection/ImapConnection.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Connection/ConnectionInterface.php b/src/Connection/ConnectionInterface.php index 93f111b..8455572 100644 --- a/src/Connection/ConnectionInterface.php +++ b/src/Connection/ConnectionInterface.php @@ -181,7 +181,7 @@ public function flags(int|array $ids): ResponseCollection; * * @see https://datatracker.ietf.org/doc/html/rfc9051#name-fetch-command */ - public function fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ResponseCollection; + public function fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid, array|string $modifiers = []): ResponseCollection; /** * Send a "RFC822.SIZE" command. diff --git a/src/Connection/ImapConnection.php b/src/Connection/ImapConnection.php index e41484d..48736de 100644 --- a/src/Connection/ImapConnection.php +++ b/src/Connection/ImapConnection.php @@ -602,13 +602,14 @@ protected function write(string $data): void /** * Fetch one or more items for one or more messages. */ - public function fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ResponseCollection + public function fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid, array|string $modifiers = []): ResponseCollection { $prefix = ($identifier === ImapFetchIdentifier::Uid) ? 'UID' : ''; $this->send(trim($prefix.' FETCH'), [ Str::set($from, $to), Str::list((array) $items), + Str::list((array) $modifiers), ], $tag); $this->assertTaggedResponse($tag);