/**
* Append the current Draft message to the IMAP server.
*
* @return array An array with the following keys:
* - uid: (integer) The new draft message's IMAP UID.
* - atchash: (array) An attachment hash of newly added attachments.
*/
public function append($folderid)
{
// Init
$atc_map = array();
$atc_hash = array();
// Create the wrapper part.
$base = new Horde_Mime_Part();
$base->setType('multipart/mixed');
// Check to see if we have any existing parts to add.
if (!empty($this->_imapMessage)) {
foreach ($this->_imapMessage->getStructure() as $part) {
if ($part->isAttachment() && !in_array($part->getMimeId(), $this->_atcDelete)) {
$base->addPart($this->_imapMessage->getMimePart($part->getMimeId()));
}
}
}
// Add body
$base->addPart($this->_textPart);
// Add Mime headers
$base->addMimeHeaders(array('headers' => $this->_headers));
foreach ($this->_atcAdd as $atc) {
$base->addPart($atc);
$atc_map[$atc->displayname] = $atc->clientid;
}
$stream = $base->toString(array('stream' => true, 'headers' => $this->_headers->toString()));
$new_uid = $this->_imap->appendMessage($folderid, $stream, array('\\draft', '\\seen'));
foreach ($base as $part) {
if ($part->isAttachment() && !empty($atc_map[$part->getName()])) {
$atc_hash['add'][$atc_map[$part->getName()]] = $folderid . ':' . $stat['id'] . ':' . $part->getMimeId();
}
}
// If we pulled down an existing Draft, delete it now since the
// new one will replace it.
if (!empty($this->_imapMessage)) {
$this->_imap->deleteMessages(array($this->_draftUid), $folderid);
}
return array('uid' => $new_uid, 'atchash' => $atc_hash);
}