From 25342a43182700bde355c0677effd1ef09d23755 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Wed, 18 Dec 2013 16:16:12 -0800 Subject: [PATCH] Rewrote "moveToMailbox" code to deal with some potential bugs Basically if the server isn't in the same box as the message it causes issues, so this switches to that box then back to where the server was. --- src/Fetch/Message.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index ce37345..f61eddf 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -155,6 +155,13 @@ class Message */ protected $attachments = array(); + /** + * Contains the mailbox that the message resides in. + * + * @var string + */ + protected $mailbox; + /** * This value defines the encoding we want the email message to use. * @@ -162,6 +169,7 @@ class Message */ public static $charset = 'UTF-8//TRANSLIT'; + /** * This constructor takes in the uid for the message and the Imap class representing the mailbox the * message should be opened from. This constructor should generally not be called directly, but rather retrieved @@ -170,9 +178,10 @@ class Message * @param int $messageUniqueId * @param Server $mailbox */ - public function __construct($messageUniqueId, Server $mailbox) + public function __construct($messageUniqueId, Server $connection) { - $this->imapConnection = $mailbox; + $this->imapConnection = $connection; + $this->mailbox = $connection->getMailBox(); $this->uid = $messageUniqueId; $this->imapStream = $this->imapConnection->getImapStream(); if($this->loadMessage() !== true) @@ -658,9 +667,16 @@ class Message */ public function moveToMailBox($mailbox) { + $currentBox = $this->imapConnection->getMailBox(); + $this->imapConnection->setMailBox($this->mailbox); + $returnValue = imap_mail_copy($this->imapStream, $this->uid, $mailbox, CP_UID | CP_MOVE); imap_expunge($this->imapStream); + $this->mailbox = $mailbox; + + $this->imapConnection->setMailBox($currentBox); + return $returnValue; } }