Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/Connection/ImapConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,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);
Expand Down
12 changes: 9 additions & 3 deletions src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Support/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading