Skip to content

Commit 5d1bd3f

Browse files
committed
Implement different move strategy when MOVE capability isn't available
1 parent 3bcf947 commit 5d1bd3f

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

src/Message.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use BackedEnum;
66
use DirectoryTree\ImapEngine\Enums\ImapFlag;
7+
use DirectoryTree\ImapEngine\Exceptions\ImapCapabilityException;
78
use DirectoryTree\ImapEngine\Support\Str;
89
use Illuminate\Contracts\Support\Arrayable;
910
use JsonSerializable;
@@ -292,12 +293,31 @@ public function copy(string $folder): void
292293
*/
293294
public function move(string $folder, bool $expunge = false): void
294295
{
295-
$this->folder->mailbox()
296-
->connection()
297-
->move($folder, $this->uid);
296+
$mailbox = $this->folder->mailbox();
298297

299-
if ($expunge) {
300-
$this->folder->expunge();
298+
$capabilities = $mailbox->capabilities();
299+
300+
switch (true) {
301+
case in_array('MOVE', $capabilities):
302+
$mailbox->connection()->move($folder, $this->uid);
303+
304+
if ($expunge) {
305+
$this->folder->expunge();
306+
}
307+
308+
return;
309+
310+
case in_array('UIDPLUS', $capabilities):
311+
$this->copy($folder);
312+
313+
$this->delete($expunge);
314+
315+
return;
316+
317+
default:
318+
throw new ImapCapabilityException(
319+
'Unable to move message. Server does not support MOVE or UIDPLUS capabilities.'
320+
);
301321
}
302322
}
303323

0 commit comments

Comments
 (0)