/** * Saves message to a specific folder. The method is primarily used for saving drafts. * * @param CAccount $oAccount Account object. * @param \MailSo\Mime\Message $oMessage Object representing message to be saved. * @param string $sDraftFolder Folder the message is saved to. * @param string $sDraftUid = ''. UID of the message to be replaced; saving new draft removes the previous version. * * @return array|bool Array containing name of the folder and UID of the message stored, or bool in case of failure. * * @throws CApiInvalidArgumentException */ public function saveMessage($oAccount, $oMessage, $sDraftFolder, $sDraftUid = '') { if (!$oAccount || !$oMessage || 0 === strlen($sDraftFolder)) { throw new CApiInvalidArgumentException(); } $oImapClient =& $this->_getImapClient($oAccount); $rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource(); $iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(), array($rMessageStream), 8192, true, true); $mResult = false; if (false !== $iMessageStreamSize && is_resource($rMessageStream)) { rewind($rMessageStream); $iNewUid = 0; $oImapClient->MessageAppendStream($sDraftFolder, $rMessageStream, $iMessageStreamSize, array(\MailSo\Imap\Enumerations\MessageFlag::SEEN), $iNewUid); if (null === $iNewUid || 0 === $iNewUid) { $sMessageId = $oMessage->MessageId(); if (0 < strlen($sMessageId)) { $iNewUid = $this->getMessageUid($oAccount, $sDraftFolder, $sMessageId); } } $mResult = true; if (0 < strlen($sDraftFolder) && 0 < strlen($sDraftUid)) { $this->deleteMessage($oAccount, $sDraftFolder, array($sDraftUid)); } if (null !== $iNewUid && 0 < $iNewUid) { $mResult = array('NewFolder' => $sDraftFolder, 'NewUid' => $iNewUid); } } return $mResult; }