protected function _resumeDraft($indices, $type, $opts)
{
global $injector, $notification, $prefs;
$contents_factory = $injector->getInstance('IMP_Factory_Contents');
try {
$contents = $contents_factory->create($indices);
} catch (IMP_Exception $e) {
throw new IMP_Compose_Exception($e);
}
$headers = $contents->getHeader();
$imp_draft = false;
if ($draft_url = $headers[self::DRAFT_REPLY]) {
if (is_null($type) && !($type = $headers[self::DRAFT_REPLY_TYPE])) {
$type = self::REPLY;
}
$imp_draft = self::REPLY;
} elseif ($draft_url = $headers[self::DRAFT_FWD]) {
$imp_draft = self::FORWARD;
if (is_null($type)) {
$type = self::FORWARD;
}
} elseif (isset($headers[self::DRAFT_HDR])) {
$imp_draft = self::COMPOSE;
}
if (!empty($opts['format'])) {
$compose_html = $opts['format'] == 'html';
} elseif ($prefs->getValue('compose_html')) {
$compose_html = true;
} else {
switch ($type) {
case self::EDITASNEW:
case self::FORWARD:
case self::FORWARD_BODY:
case self::FORWARD_BOTH:
$compose_html = $prefs->getValue('forward_format');
break;
case self::REPLY:
case self::REPLY_ALL:
case self::REPLY_LIST:
case self::REPLY_SENDER:
$compose_html = $prefs->getValue('reply_format');
break;
case self::TEMPLATE:
$compose_html = true;
break;
default:
/* If this is an draft saved by IMP, we know 100% for sure
* that if an HTML part exists, the user was composing in
* HTML. */
$compose_html = $imp_draft !== false;
break;
}
}
$msg_text = $this->_getMessageText($contents, array('html' => $compose_html, 'imp_msg' => $imp_draft, 'toflowed' => false));
if (empty($msg_text)) {
$body = '';
$format = 'text';
$text_id = 0;
} else {
/* Use charset at time of initial composition if this is an IMP
* draft. */
if ($imp_draft !== false) {
$this->charset = $msg_text['charset'];
}
$body = $msg_text['text'];
$format = $msg_text['mode'];
$text_id = $msg_text['id'];
}
$mime_message = $contents->getMIMEMessage();
/* Add attachments. */
$parts = array();
if ($mime_message->getPrimaryType() == 'multipart' && $mime_message->getType() != 'multipart/alternative') {
for ($i = 1;; ++$i) {
if (intval($text_id) == $i) {
continue;
}
if ($part = $contents->getMimePart($i)) {
$parts[] = $part;
} else {
break;
}
}
} elseif ($mime_message->getDisposition() == 'attachment') {
$parts[] = $contents->getMimePart('1');
}
foreach ($parts as $val) {
try {
$this->addAttachmentFromPart($val);
} catch (IMP_Compose_Exception $e) {
$notification->push($e, 'horde.warning');
}
}
$alist = new Horde_Mail_Rfc822_List();
$addr = array('to' => clone $alist, 'cc' => clone $alist, 'bcc' => clone $alist);
if ($type != self::EDITASNEW) {
foreach (array('to', 'cc', 'bcc') as $val) {
if ($h = $headers[$val]) {
$addr[$val] = $h->getAddressList(true);
}
}
if ($val = $headers['References']) {
$this->_setMetadata('references', $val->getIdentificationOb()->ids);
if ($val = $headers['In-Reply-To']) {
$this->_setMetadata('in_reply_to', $val);
}
}
if ($draft_url) {
$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
$indices = new IMP_Indices();
foreach (explode(',', $draft_url->value_single) as $val) {
$imap_url = new Horde_Imap_Client_Url(rtrim(ltrim($val, '<'), '>'));
try {
if ($imap_url->protocol == ($imp_imap->isImap() ? 'imap' : 'pop') && $imap_url->username == $imp_imap->getParam('username') && IMP_Mailbox::get($imap_url->mailbox)->uidvalid == $imap_url->uidvalidity && $contents_factory->create(new IMP_Indices($imap_url->mailbox, $imap_url->uid))) {
$indices->add($imap_url->mailbox, $imap_url->uid);
}
} catch (Exception $e) {
}
}
if (count($indices)) {
$this->_setMetadata('indices', $indices);
$this->_replytype = $type;
}
}
}
$mdn = new Horde_Mime_Mdn($headers);
$readreceipt = (bool) $mdn->getMdnReturnAddr();
$this->changed = 'changed';
return array('addr' => $addr, 'body' => $body, 'format' => $format, 'identity' => $this->_getMatchingIdentity($headers, array('from')), 'priority' => $injector->getInstance('IMP_Mime_Headers')->getPriority($headers), 'readreceipt' => $readreceipt, 'subject' => strval($headers['Subject']), 'type' => $type);
}