Skip to content

Commit e3d4e99

Browse files
authored
Merge pull request #124 from DirectoryTree/bug-123
Cast `$flags` to array when appending new message
2 parents 85d751d + cc2768e commit e3d4e99

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/MessageQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function get(): MessageCollection
7575
public function append(string $message, mixed $flags = null): int
7676
{
7777
$response = $this->connection()->append(
78-
$this->folder->path(), $message, Str::enums($flags),
78+
$this->folder->path(), $message, (array) Str::enums($flags),
7979
);
8080

8181
return (int) $response // TAG4 OK [APPENDUID <uidvalidity> <uid>] APPEND completed.

tests/Unit/MessageQueryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use DirectoryTree\ImapEngine\Connection\ImapConnection;
44
use DirectoryTree\ImapEngine\Connection\ImapQueryBuilder;
55
use DirectoryTree\ImapEngine\Connection\Streams\FakeStream;
6+
use DirectoryTree\ImapEngine\Enums\ImapFlag;
67
use DirectoryTree\ImapEngine\Folder;
78
use DirectoryTree\ImapEngine\Mailbox;
89
use DirectoryTree\ImapEngine\MessageQuery;
@@ -181,3 +182,25 @@ function query(?Mailbox $mailbox = null): MessageQuery
181182
// Should only process the first chunk (page 1)
182183
expect($processedChunks)->toBe([1]);
183184
});
185+
186+
test('append with single flag converts to array', function (mixed $flag) {
187+
$stream = new FakeStream;
188+
$stream->open();
189+
190+
$stream->feed([
191+
'* OK Welcome to IMAP',
192+
'TAG1 OK Logged in',
193+
'TAG2 OK [APPENDUID 1234567890 1] APPEND completed',
194+
]);
195+
196+
$mailbox = Mailbox::make();
197+
$mailbox->connect(new ImapConnection($stream));
198+
199+
$folder = new Folder($mailbox, 'INBOX');
200+
$query = new MessageQuery($folder, new ImapQueryBuilder);
201+
202+
$uid = $query->append('Hello world', $flag);
203+
204+
expect($uid)->toBe(1);
205+
$stream->assertWritten('TAG2 APPEND "INBOX" (\\Seen) "Hello world"');
206+
})->with([ImapFlag::Seen, '\\Seen']);

0 commit comments

Comments
 (0)