Skip to content
Merged
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/MessageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function get(): MessageCollection
public function append(string $message, mixed $flags = null): int
{
$response = $this->connection()->append(
$this->folder->path(), $message, Str::enums($flags),
$this->folder->path(), $message, (array) Str::enums($flags),
);

return (int) $response // TAG4 OK [APPENDUID <uidvalidity> <uid>] APPEND completed.
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/MessageQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use DirectoryTree\ImapEngine\Connection\ImapConnection;
use DirectoryTree\ImapEngine\Connection\ImapQueryBuilder;
use DirectoryTree\ImapEngine\Connection\Streams\FakeStream;
use DirectoryTree\ImapEngine\Enums\ImapFlag;
use DirectoryTree\ImapEngine\Folder;
use DirectoryTree\ImapEngine\Mailbox;
use DirectoryTree\ImapEngine\MessageQuery;
Expand Down Expand Up @@ -181,3 +182,25 @@ function query(?Mailbox $mailbox = null): MessageQuery
// Should only process the first chunk (page 1)
expect($processedChunks)->toBe([1]);
});

test('append with single flag converts to array', function (mixed $flag) {
$stream = new FakeStream;
$stream->open();

$stream->feed([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
'TAG2 OK [APPENDUID 1234567890 1] APPEND completed',
]);

$mailbox = Mailbox::make();
$mailbox->connect(new ImapConnection($stream));

$folder = new Folder($mailbox, 'INBOX');
$query = new MessageQuery($folder, new ImapQueryBuilder);

$uid = $query->append('Hello world', $flag);

expect($uid)->toBe(1);
$stream->assertWritten('TAG2 APPEND "INBOX" (\\Seen) "Hello world"');
})->with([ImapFlag::Seen, '\\Seen']);