protected function _saveDraftMsg($headers, $message, $opts)
{
global $injector, $registry;
$has_session = (bool) $registry->getAuth();
/* Set up the base message now. */
$base = $this->_createMimeMessage($message, array('html' => !empty($opts['html']), 'noattach' => !$has_session, 'nofinal' => true));
$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
$recip_list = $this->recipientList($headers);
if (!empty($opts['verify_email'])) {
foreach ($recip_list['list'] as $val) {
try {
/* For draft messages, the key is whether the IMAP server
* supports EAI addresses. */
$utf8 = $imp_imap->client_ob->capability->query('UTF8', 'ACCEPT');
IMP::parseAddressList($val->writeAddress(true), array('validate' => $utf8 ? 'eai' : true));
} catch (Horde_Mail_Exception $e) {
throw new IMP_Compose_Exception(sprintf(_("Saving the message failed because it contains an invalid e-mail address: %s."), strval($val), $e->getMessage()), $e->getCode());
}
}
}
$headers = array_merge($headers, $recip_list['header']);
/* Initalize a header object for the draft. */
$draft_headers = $this->_prepareHeaders($headers, $opts);
/* Add information necessary to log replies/forwards when finally
* sent. */
if ($this->_replytype) {
try {
$indices = $this->getMetadata('indices');
$imap_url = new Horde_Imap_Client_Url();
$imap_url->hostspec = $imp_imap->getParam('hostspec');
$imap_url->protocol = $imp_imap->isImap() ? 'imap' : 'pop';
$imap_url->username = $imp_imap->getParam('username');
$urls = array();
foreach ($indices as $val) {
$imap_url->mailbox = $val->mbox;
$imap_url->uidvalidity = $val->mbox->uidvalid;
foreach ($val->uids as $val2) {
$imap_url->uid = $val2;
$urls[] = '<' . strval($imap_url) . '>';
}
}
switch ($this->replyType(true)) {
case self::FORWARD:
$draft_headers->addHeader(self::DRAFT_FWD, implode(', ', $urls));
break;
case self::REPLY:
$draft_headers->addHeader(self::DRAFT_REPLY, implode(', ', $urls));
$draft_headers->addHeader(self::DRAFT_REPLY_TYPE, $this->_replytype);
break;
}
} catch (Horde_Exception $e) {
}
} else {
$draft_headers->addHeader(self::DRAFT_HDR, 'Yes');
}
return $base->toString(array('defserver' => $has_session ? $imp_imap->config->maildomain : null, 'headers' => $draft_headers));
}