public function getSummary($id, $mask = 0)
{
$autodetect_link = false;
$param_array = array();
$this->_buildMessage();
$part = array('bytes' => null, 'download' => null, 'download_url' => null, 'id' => $id, 'img_save' => null, 'size' => null, 'strip' => null);
$mime_part = $this->getMimePart($id, array('nocontents' => true));
if (!$mime_part) {
return $part;
}
$mime_type = $mime_part->getType();
/* If this is an attachment that has no specific MIME type info, see
* if we can guess a rendering type. */
if (in_array($mime_type, array('application/octet-stream', 'application/base64'))) {
$mime_type = Horde_Mime_Magic::filenameToMIME($mime_part->getName());
if ($mime_type == $mime_part->getType()) {
$autodetect_link = true;
} else {
$mime_part = clone $mime_part;
$mime_part->setType($mime_type);
$param_array['ctype'] = $mime_type;
}
}
$part['type'] = $mime_type;
/* Is this part an attachment? */
$is_atc = $mime_part->isAttachment();
/* Get bytes/size information. */
if ($mask & self::SUMMARY_BYTES || $mask & self::SUMMARY_SIZE) {
$part['bytes'] = $size = $mime_part->getBytes();
$part['size'] = $size > 1048576 ? sprintf(_("%s MB"), IMP::numberFormat($size / 1048576, 1)) : sprintf(_("%s KB"), max(round($size / 1024), 1));
}
/* Get part's icon. */
if ($mask & self::SUMMARY_ICON || $mask & self::SUMMARY_ICON_RAW) {
$part['icon'] = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->getIcon($mime_type);
if ($mask & self::SUMMARY_ICON) {
$part['icon'] = Horde_Themes_Image::tag($part['icon'], array('attr' => array('title' => $mime_type)));
}
} else {
$part['icon'] = null;
}
/* Get part's description. */
$description = $this->getPartName($mime_part, true);
if ($mask & self::SUMMARY_DESCRIP_LINK) {
if (($can_d = $this->canDisplay($mime_part, self::RENDER_FULL)) || $autodetect_link) {
$part['description'] = $this->linkViewJS($mime_part, 'view_attach', htmlspecialchars($description), array('jstext' => sprintf(_("View %s"), $description), 'params' => array_filter(array_merge($param_array, array('autodetect' => !$can_d)))));
} else {
$part['description'] = htmlspecialchars($description);
}
}
if ($mask & self::SUMMARY_DESCRIP) {
$part['description_raw'] = $description;
}
/* Download column. */
if ($is_atc && $mask & self::SUMMARY_DOWNLOAD) {
$part['download'] = $this->linkView($mime_part, 'download_attach', '', array('attr' => array('download' => $mime_part->getName(true) ?: $mime_part->getPrimaryType()), 'class' => 'iconImg downloadAtc', 'jstext' => _("Download")));
$part['download_url'] = $this->urlView($mime_part, 'download_attach');
}
/* Display the image save link if the required registry calls are
* present. */
if ($mask & self::SUMMARY_IMAGE_SAVE && $GLOBALS['registry']->hasMethod('images/selectGalleries') && $mime_part->getPrimaryType() == 'image') {
$part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'iconImg saveImgAtc', null, Horde::popupJs(IMP_Basic_Saveimage::url(), array('params' => array('muid' => strval($this->getIndicesOb()), 'id' => $id), 'height' => 200, 'width' => 450, 'urlencode' => true)) . 'return false;') . '</a>';
}
/* Add print link? */
if (($mask & self::SUMMARY_PRINT || $mask & self::SUMMARY_PRINT_STUB) && $this->canDisplay($id, self::RENDER_FULL)) {
$part['print'] = $mask & self::SUMMARY_PRINT ? $this->linkViewJS($mime_part, 'print_attach', '', array('css' => 'iconImg printAtc', 'jstext' => _("Print"), 'onload' => 'IMP_JS.printWindow', 'params' => $param_array)) : Horde::link('#', _("Print"), 'iconImg printAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
}
/* Strip Attachment? Allow stripping of base parts other than the
* base multipart and the base text (body) part. */
if ($mask & self::SUMMARY_STRIP && $id != 0 && intval($id) != 1 && strpos($id, '.') === false) {
$part['strip'] = Horde::link(Horde::selfUrlParams()->add(array('actionID' => 'strip_attachment', 'imapid' => $id, 'muid' => strval($this->getIndicesOb()), 'token' => $GLOBALS['session']->getToken())), _("Strip Attachment"), 'iconImg deleteImg stripAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
}
return $part;
}