Skip to content

Commit e781f74

Browse files
committed
Move messages through Protocol::moveMessage() instead of copy / delete
1 parent 09eb28d commit e781f74

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/Message.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ public function copy($folder) {
671671

672672
/**
673673
* Move the current Messages to a mailbox
674-
* @param $folder
674+
* @param string $folder_path
675675
* @param boolean $expunge
676676
*
677677
* @return Message|null
@@ -683,17 +683,32 @@ public function copy($folder) {
683683
* @throws MessageHeaderFetchingException
684684
* @throws Exceptions\EventNotFoundException
685685
*/
686-
public function move($folder, $expunge = false) {
687-
$message = $this->copy($folder);
688-
if ($message !== null) {
689-
$this->delete($expunge);
686+
public function move($folder_path, $expunge = false) {
687+
$this->client->openFolder($folder_path);
688+
$status = $this->client->getConnection()->examineFolder($folder_path);
690689

691-
$event = $this->getEvent("message", "moved");
692-
$event::dispatch($this, $message);
693-
}
690+
if (isset($status["uidnext"])) {
691+
$next_uid = $status["uidnext"];
692+
693+
/** @var Folder $folder */
694+
$folder = $this->client->getFolder($folder_path);
695+
696+
$this->client->openFolder($this->folder_path);
697+
if ($this->client->getConnection()->moveMessage($folder->path, $this->msgn) == true) {
698+
if($expunge) $this->client->expunge();
694699

700+
$this->client->openFolder($folder->path);
701+
$message_num = $this->client->getConnection()->getMessageNumber($next_uid);
695702

696-
return $message;
703+
$message = $folder->query()->getMessage($message_num);
704+
$event = $this->getEvent("message", "moved");
705+
$event::dispatch($this, $message);
706+
707+
return $message;
708+
}
709+
}
710+
711+
return null;
697712
}
698713

699714
/**

0 commit comments

Comments
 (0)