/**
* Add message data to output.
*
* @param IMP_Indices $indices Index of the message.
* @param array $opts Additional options:
* <pre>
* - is_list: (boolean) Do list check?
* - peek: (boolean) Don't set seen flag?
* - user_headers: (boolean) Add user headers?
* </pre>
*/
public function message(IMP_Indices $indices, array $opts = array())
{
global $page_output;
try {
$show_msg = new IMP_Contents_Message($indices, !empty($opts['peek']));
$msg = (object) $show_msg->showMessage();
foreach (array('from', 'to', 'cc', 'bcc') as $val) {
if ($tmp = $show_msg->getAddressHeader($val)) {
$msg->{$val} = $tmp;
}
}
$subject = $show_msg->getSubject();
$msg->subject = $subject['subject'];
if ($subject['subject'] !== $subject['title']) {
$msg->title = $subject['title'];
}
if (isset($subject['subjectlink'])) {
$msg->subjectlink = $subject['subjectlink'];
}
if ($date = $show_msg->getDateOb()) {
$msg->datestamp = $date->format($date::DATE_ISO_8601);
$msg->localdate = $date->format($date::DATE_LOCAL);
}
if ($resent = $show_msg->getResentData()) {
$msg->resent = array();
foreach ($resent as $val) {
$msg->resent[] = array('date' => $val['date']->format($val['date']::DATE_LOCAL), 'from' => $show_msg->getAddressHeader($val['from']));
}
}
$this->maillog($indices);
$show_msg->addChangedFlag();
if (!empty($opts['user_headers'])) {
$msg->headers = $show_msg->getUserHeaders();
}
if (!empty($opts['is_list'])) {
$list_info = $show_msg->contents->getListInformation();
if (!empty($list_info['exists'])) {
$msg->is_list = true;
}
}
$msg->save_as = strval($show_msg->getSaveAs()->setRaw(true));
/* Need to grab cached inline scripts. */
Horde::startBuffer();
$page_output->outputInlineScript(true);
if ($js_inline = Horde::endBuffer()) {
$msg->js = array($js_inline);
}
if ($indices instanceof IMP_Indices_Mailbox) {
$indices = $indices->buids;
}
} catch (Exception $e) {
Horde::log($e, 'DEBUG');
}
foreach ($indices as $val) {
foreach ($val->uids as $val2) {
$ob = new stdClass();
$ob->buid = $val2;
if (isset($msg)) {
$ob->data = $msg;
} else {
$e = new IMP_Ajax_Application_Viewport_Error($val->mbox);
$ob->data = $e->toObject();
}
$ob->mbox = $val->mbox->form_to;
$this->_messages[] = $ob;
}
}
}