* did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Andrew Coleman <*****@*****.**> * @author Michael Slusarz <*****@*****.**> * @category Horde * @copyright 2004-2007 Andrew Coleman * @copyright 2008-2016 Horde LLC * @license http://www.horde.org/licenses/gpl GPL * @package IMP */ /* We do not need to be authenticated to get the file. */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('imp', array('authentication' => 'none', 'session_control' => 'none', 'timezone' => true)); $vars = $injector->getInstance('Horde_Variables'); /* This will throw exception if VFS/linked attachments are not available. */ $linked_atc = new IMP_Compose_LinkedAttachment($vars->u, $vars->id); /* Check for old linked attachment data, and convert if necessary. * Deprecated parameters: * - f: (string) Filename * - t: (string) Timestamp */ if (isset($vars->t)) { $linked_atc->convert($vars->t, $vars->f); } /* Check for delete request. */ if ($vars->d) { if ($fname = $linked_atc->delete($vars->d)) { printf(_("Attachment %s deleted."), htmlspecialchars($fname)); } else { print _("Attachment doesn't exist."); }
/** */ public function gc() { if (!($keep = IMP_Compose_LinkedAttachment::keepDate(true))) { return; } $changed = false; $this->_getMetadata(); foreach ($this->_md as $key => $val) { $md = new IMP_Compose_Attachment_Linked_Metadata(); $md->data = $val; if ($md->time < $keep) { try { $this->_vfs->deleteFile($this->_vfspath, $key); } catch (Exception $e) { } unset($this->_md[$key]); $changed = true; } } if ($changed) { $this->_saveMetadata(); } }
/** * Adds linked attachments to message. * * @param string &$body Plaintext data. * @param mixed $html HTML data (Horde_Domhtml) or null. * * @throws IMP_Compose_Exception */ protected function _linkAttachments(&$body, $html) { global $conf; if (empty($conf['compose']['link_attachments'])) { return; } $link_all = false; $linked = array(); if (!empty($conf['compose']['link_attach_size_hard'])) { $limit = intval($conf['compose']['link_attach_size_hard']); foreach ($this as $val) { if (($limit -= $val->getPart()->getBytes()) < 0) { $link_all = true; break; } } } foreach (iterator_to_array($this) as $key => $val) { if ($link_all && !$val->linked) { $val = new IMP_Compose_Attachment($this, $val->getPart(), $val->storage->getTempFile()); $val->forceLinked = true; unset($this[$key]); $this[$key] = $val; } if ($val->linked && !$val->related) { $linked[] = $val; } } if (empty($linked)) { return; } if ($del_time = IMP_Compose_LinkedAttachment::keepDate(false)) { /* Subtract 1 from time to get the last day of the previous * month. */ $expire = ' (' . sprintf(_("links will expire on %s"), strftime('%x', $del_time - 1)) . ')'; } $body .= "\n-----\n" . _("Attachments") . $expire . ":\n"; if ($html) { $body = $html->getBody(); $dom = $html->dom; $body->appendChild($dom->createElement('HR')); $body->appendChild($div = $dom->createElement('DIV')); $div->appendChild($dom->createElement('H4', _("Attachments") . $expire . ':')); $div->appendChild($ol = $dom->createElement('OL')); } $i = 0; foreach ($linked as $val) { $apart = $val->getPart(); $name = $apart->getName(true); $size = IMP::sizeFormat($apart->getBytes()); $url = strval($val->link_url->setRaw(true)); $body .= "\n" . ++$i . '. ' . $name . ' (' . $size . ') [' . $apart->getType() . "]\n" . sprintf(_("Download link: %s"), $url) . "\n"; if ($html) { $ol->appendChild($li = $dom->createElement('LI')); $li->appendChild($dom->createElement('STRONG', $name)); $li->appendChild($dom->createTextNode(' (' . $size . ') [' . htmlspecialchars($apart->getType()) . ']')); $li->appendChild($dom->createElement('BR')); $li->appendChild($dom->createTextNode(_("Download link") . ': ')); $li->appendChild($a = $dom->createElement('A', htmlspecialchars($url))); $a->setAttribute('href', $url); } } }