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.
This commit is contained in:
Robert Hafner 2013-12-18 16:16:12 -08:00
parent 0e38a10e97
commit 25342a4318

View File

@ -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;
}
}