File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55use BackedEnum ;
66use DirectoryTree \ImapEngine \Enums \ImapFlag ;
7+ use DirectoryTree \ImapEngine \Exceptions \ImapCapabilityException ;
78use DirectoryTree \ImapEngine \Support \Str ;
89use Illuminate \Contracts \Support \Arrayable ;
910use 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
You can’t perform that action at this time.
0 commit comments