Skip to content

Commit 19affcc

Browse files
committed
Potential message moving / copying problem fixed Webklex#29
1 parent e781f74 commit 19affcc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Message.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ public function getFolder(){
636636

637637
/**
638638
* Copy the current Messages to a mailbox
639-
* @param string $folder
639+
* @param string $folder_path
640+
* @param boolean $expunge
640641
*
641642
* @return null|Message
642643
* @throws Exceptions\ConnectionFailedException
@@ -647,14 +648,20 @@ public function getFolder(){
647648
* @throws MessageHeaderFetchingException
648649
* @throws Exceptions\EventNotFoundException
649650
*/
650-
public function copy($folder) {
651-
$this->client->openFolder($this->folder_path);
652-
$status = $this->client->getConnection()->examineFolder($folder);
653-
/** @var Folder $folder */
654-
$folder = $this->client->getFolder($folder);
655-
if (isset($status["uidnext"]) && $folder !== null) {
651+
public function copy($folder_path, $expunge = false) {
652+
$this->client->openFolder($folder_path);
653+
$status = $this->client->getConnection()->examineFolder($folder_path);
654+
655+
if (isset($status["uidnext"])) {
656656
$next_uid = $status["uidnext"];
657+
658+
/** @var Folder $folder */
659+
$folder = $this->client->getFolder($folder_path);
660+
661+
$this->client->openFolder($this->folder_path);
657662
if ($this->client->getConnection()->copyMessage($folder->path, $this->msgn) == true) {
663+
if($expunge) $this->client->expunge();
664+
658665
$this->client->openFolder($folder->path);
659666
$message_num = $this->client->getConnection()->getMessageNumber($next_uid);
660667

0 commit comments

Comments
 (0)