Author: Michael Slusarz (slusarz@horde.org)
Example #1
0
 /**
  */
 public function avatarImg($email)
 {
     global $injector, $registry;
     if ($registry->hasMethod('contacts/search')) {
         $contacts = $injector->getInstance('IMP_Contacts');
         try {
             $res = $registry->call('contacts/search', array($email, array('customStrict' => array('email'), 'fields' => array_fill_keys($contacts->sources, array('email')), 'returnFields' => array('photo', 'phototype'), 'sources' => $contacts->sources)));
             if (isset($res[$email][0]['photo'])) {
                 try {
                     $img = $injector->getInstance('Horde_Core_Factory_Image')->create();
                     $img->loadString($res[$email][0]['photo']['load']['data']);
                     $img->resize(80, 80, true);
                     $data = $img->raw(true);
                     $type = $img->getContentType();
                 } catch (Horde_Exception $e) {
                     $data = $res[$email][0]['photo']['load']['data'];
                     $type = $res[$email][0]['phototype'];
                 }
                 return array('desc' => '', 'url' => Horde_Url_Data::create($type, $data));
             }
         } catch (Horde_Exception $e) {
         }
     }
     return null;
 }
Example #2
0
 public function testIsData()
 {
     $this->assertFalse(Horde_Url_Data::isData(new Horde_Url()));
     $this->assertFalse(Horde_Url_Data::isData('foo'));
     $this->assertFalse(Horde_Url_Data::isData(333));
     $this->assertFalse(Horde_Url_Data::isData(array(new Horde_Url_Data())));
     $this->assertTrue(Horde_Url_Data::isData(new Horde_Url_Data()));
     $this->assertTrue(Horde_Url_Data::isData('data:text/plain,Foo'));
 }
Example #3
0
 /**
  */
 public function avatarImg($email)
 {
     if (class_exists('Horde_Service_Gravatar')) {
         $gravatar = new Horde_Service_Gravatar(Horde_Service_Gravatar::STANDARD, $GLOBALS['injector']->getInstance('Horde_Http_Client'));
         $data = $gravatar->fetchAvatar($email, array('default' => 404, 'size' => 80));
         if (!is_null($data)) {
             rewind($data);
             $img_data = stream_get_contents($data);
             if (strlen($img_data)) {
                 return array('desc' => '', 'url' => Horde_Url_Data::create('image/jpeg', $img_data));
             }
         }
     }
     return null;
 }
Example #4
0
 /**
  * Constructor.
  *
  * @param string $sig  HTML signature data.
  *
  * @throws IMP_Exception
  */
 public function __construct($sig)
 {
     global $conf, $injector;
     /* Scrub HTML. */
     $this->dom = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($sig, 'Xss', array('charset' => 'UTF-8', 'return_dom' => true, 'strip_style_attributes' => false));
     $img_limit = intval($conf['compose']['htmlsig_img_size']);
     $xpath = new DOMXPath($this->dom->dom);
     foreach ($xpath->query('//*[@src]') as $node) {
         $src = $node->getAttribute('src');
         if (Horde_Url_Data::isData($src)) {
             if (strcasecmp($node->tagName, 'IMG') === 0) {
                 $data_url = new Horde_Url_Data($src);
                 if ($img_limit && ($img_limit -= strlen($data_url->data)) < 0) {
                     throw new IMP_Exception(_("The total size of your HTML signature image data has exceeded the maximum allowed."));
                 }
                 $node->setAttribute(self::HTMLSIG_ATTR, 1);
             } else {
                 /* Don't allow any other non-image data URLs. */
                 $node->removeAttribute('src');
             }
         }
     }
 }
Example #5
0
 /**
  */
 protected function _node($doc, $node)
 {
     parent::_node($doc, $node);
     if (empty($this->_imptmp) || !$node instanceof DOMElement) {
         if ($node instanceof DOMText && $node->length > 1) {
             /* Filter bad language. */
             $text = IMP::filterText($node->data);
             if ($node->data != $text) {
                 $node->replaceData(0, $node->length, $text);
             }
         }
         return;
     }
     $tag = Horde_String::lower($node->tagName);
     /* Remove 'height' styles from HTML messages, because it can break
      * sizing of IFRAME. */
     foreach ($node->attributes as $key => $val) {
         if ($key == 'style') {
             /* Do simplistic style parsing here. */
             $parts = array_filter(explode(';', $val->value));
             foreach ($parts as $k2 => $v2) {
                 if (preg_match("/^\\s*height:\\s*/i", $v2)) {
                     unset($parts[$k2]);
                 }
             }
             $val->value = implode(';', $parts);
         }
     }
     switch ($tag) {
         case 'a':
         case 'area':
             /* Convert links to open in new windows. Ignore mailto: links and
              * links that already have a target. */
             if ($node->hasAttribute('href')) {
                 $url = parse_url($node->getAttribute('href'));
                 if (isset($url['scheme']) && $url['scheme'] == 'mailto') {
                     /* We don't include HordePopup in IFRAME, so need to use
                      * 'simple' links. */
                     $clink = new IMP_Compose_Link($node->getAttribute('href'));
                     $node->setAttribute('href', $clink->link(true));
                     $node->removeAttribute('target');
                 } elseif (!empty($this->_imptmp['inline']) && isset($url['fragment']) && empty($url['path']) && $GLOBALS['browser']->isBrowser('mozilla')) {
                     /* See Bug #8695: internal anchors are broken in
                      * Mozilla. */
                     $node->removeAttribute('href');
                 } elseif (empty($url)) {
                     /* Empty URL - remove href/target so the link is not
                      * clickable. */
                     $node->removeAttribute('href');
                     $node->removeAttribute('target');
                 } else {
                     $node->setAttribute('target', strval(new Horde_Support_Randomid()));
                 }
             }
             break;
         case 'body':
             $style = $node->hasAttribute('style') ? rtrim($node->getAttribute('style'), ';') . ';' : '';
             $node->setAttribute('style', $style . 'width:auto !important');
             break;
         case 'img':
         case 'input':
             if ($node->hasAttribute('src')) {
                 $val = $node->getAttribute('src');
                 /* Multipart/related. */
                 if ($tag == 'img' && ($id = $this->_cidSearch($val))) {
                     $val = $this->getConfigParam('imp_contents')->urlView(null, 'view_attach', array('params' => array('ctype' => 'image/*', 'id' => $id, 'imp_img_view' => 'data')));
                 }
                 /* Block images.*/
                 if ($this->_imgBlock()) {
                     if (Horde_Url_Data::isData($val)) {
                         $url = new Horde_Url_Data($val);
                     } else {
                         /* Check for relative URLs. These won't be loaded and
                          * will cause unnecessary 404 hits to the local web
                          * server. */
                         $parsed_url = parse_url($val);
                         if (isset($parsed_url['host'])) {
                             $url = new Horde_Url($val);
                             $url->setScheme();
                         } else {
                             $url = null;
                         }
                     }
                     if ($url) {
                         $node->setAttribute(self::IMGBLOCK, $url);
                         $node->setAttribute('src', $this->_imgBlockImg());
                         $this->_imptmp['imgblock'] = true;
                     } else {
                         $node->parentNode->removeChild($node);
                         $this->_imptmp['imgbroken'] = true;
                     }
                 } else {
                     $node->removeAttribute('src');
                     $node->setAttribute('data-src', $val);
                 }
             }
             /* IMG only */
             if ($tag == 'img' && $this->_imgBlock() && $node->hasAttribute('srcset')) {
                 $node->setAttribute(self::SRCSETBLOCK, $node->getAttribute('srcset'));
                 $node->setAttribute('srcset', '');
                 $this->_imptmp['imgblock'] = true;
             }
             break;
         case 'link':
             /* Block all link tags that reference foreign URLs, other than
              * CSS. There's no inherently wrong with linking to a foreign
              * CSS file other than privacy concerns. Therefore, block
              * linking until requested by the user. */
             $delete_link = true;
             switch (Horde_String::lower($node->getAttribute('type'))) {
                 case 'text/css':
                     if ($node->hasAttribute('href')) {
                         $tmp = $node->getAttribute('href');
                         if ($id = $this->_cidSearch($tmp, false)) {
                             $this->_imptmp['style'][] = $this->getConfigParam('imp_contents')->getMIMEPart($id)->getContents();
                         } elseif ($this->_imgBlock()) {
                             $node->setAttribute(self::CSSBLOCK, $node->getAttribute('href'));
                             $node->removeAttribute('href');
                             $this->_imptmp['cssblock'] = true;
                             $delete_link = false;
                         }
                     }
                     break;
             }
             if ($delete_link && $node->hasAttribute('href') && $node->parentNode) {
                 $node->parentNode->removeChild($node);
             }
             break;
         case 'style':
             switch (Horde_String::lower($node->getAttribute('type'))) {
                 case 'text/css':
                     $this->_imptmp['style'][] = str_replace(array('<!--', '-->'), '', $node->nodeValue);
                     $node->parentNode->removeChild($node);
                     break;
             }
             break;
         case 'table':
             /* If displaying inline (in IFRAME), tables with 100% height seems
              * to confuse many browsers re: the IFRAME internal height. */
             if (!empty($this->_imptmp['inline']) && $node->hasAttribute('height') && $node->getAttribute('height') == '100%') {
                 $node->removeAttribute('height');
             }
             // Fall-through
         // Fall-through
         case 'body':
         case 'td':
             if ($node->hasAttribute('background')) {
                 $val = $node->getAttribute('background');
                 /* Multipart/related. */
                 if ($id = $this->_cidSearch($val)) {
                     $val = $this->getConfigParam('imp_contents')->urlView(null, 'view_attach', array('params' => array('id' => $id, 'imp_img_view' => 'data')));
                     $node->setAttribute('background', $val);
                 }
                 /* Block images.*/
                 if ($this->_imgBlock()) {
                     $node->setAttribute(self::IMGBLOCK, $val);
                     $node->setAttribute('background', $this->_imgBlockImg());
                     $this->_imptmp['imgblock'] = true;
                 }
             }
             break;
     }
     $remove = array();
     foreach ($node->attributes as $val) {
         /* Catch random mailto: strings in attributes that will cause
          * problems with e-mail linking. */
         if (stripos($val->value, 'mailto:') === 0) {
             $remove[] = $val->name;
         }
     }
     foreach ($remove as $val) {
         $node->removeAttribute($val);
     }
     if ($node->hasAttribute('style')) {
         if (strpos($node->getAttribute('style'), 'content:') !== false) {
             // TODO: Figure out way to unblock?
             $node->removeAttribute('style');
         } elseif (!empty($this->_imptmp['cid']) || $this->_imgBlock()) {
             $this->_imptmp['node'] = $node;
             $style = preg_replace_callback(self::CSS_BG_PREG, array($this, '_styleCallback'), $node->getAttribute('style'), -1, $matches);
             if ($matches) {
                 $node->setAttribute('style', $style);
             }
         }
     }
 }
Example #6
0
 /**
  * Output an image tag.
  *
  * @param string $type  The view type.
  * @param string $alt   The ALT text.
  *
  * @return string  An image tag.
  */
 protected function _outputImgTag($type, $alt)
 {
     global $browser;
     switch ($type) {
         case 'view_thumbnail':
             if ($this->getConfigParam('thumbnails_dataurl') && $browser->getFeature('dataurl')) {
                 $thumb = $this->_viewConvert(true);
                 $thumb = reset($thumb);
                 $src = Horde_Url_Data::create($thumb['type'], $thumb['data']);
                 break;
             }
         default:
             $src = $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach', array('params' => array('imp_img_view' => $type)));
             break;
     }
     return '<img src="' . $src . '" alt="' . htmlspecialchars($alt, ENT_COMPAT, $this->getConfigParam('charset')) . '" />';
 }
Example #7
0
 /**
  * Return information about the current attachment(s) for a message.
  *
  * @param mixed $ob      If an IMP_Compose object, return info on all
  *                       attachments. If an IMP_Compose_Attachment object,
  *                       only return information on that object.
  * @param integer $type  The compose type.
  */
 public function attachment($ob, $type = IMP_Compose::COMPOSE)
 {
     global $injector;
     $parts = $ob instanceof IMP_Compose ? iterator_to_array($ob) : array($ob);
     $viewer = $injector->getInstance('IMP_Factory_MimeViewer');
     foreach ($parts as $val) {
         $mime = $val->getPart();
         $mtype = $mime->getType();
         $tmp = array('icon' => strval(Horde_Url_Data::create('image/png', file_get_contents($viewer->getIcon($mtype)->fs))), 'name' => $mime->getName(true), 'num' => $val->id, 'type' => $mtype, 'size' => IMP::sizeFormat($mime->getBytes()));
         if ($viewer->create($mime)->canRender('full')) {
             $tmp['url'] = strval($val->viewUrl()->setRaw(true));
             $tmp['view'] = intval(!in_array($type, array(IMP_Compose::FORWARD_ATTACH, IMP_Compose::FORWARD_BOTH)) && $mtype != 'application/octet-stream');
         }
         $this->_atc[] = $tmp;
     }
 }
Example #8
0
 /**
  * Return the rendered inline version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  */
 protected function _renderInline()
 {
     $browser = $this->getConfigParam('browser');
     $notification = $this->getConfigParam('notification');
     $prefs = $this->getConfigParam('prefs');
     $registry = $this->getConfigParam('registry');
     $data = $this->_mimepart->getContents();
     $html = '';
     $title = Horde_Core_Translation::t("vCard");
     $iCal = new Horde_Icalendar();
     if (!$iCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) {
         $notification->push(Horde_Core_Translation::t("There was an error reading the contact data."), 'horde.error');
     }
     if (Horde_Util::getFormData('import') && Horde_Util::getFormData('source') && $registry->hasMethod('contacts/import')) {
         $source = Horde_Util::getFormData('source');
         $count = 0;
         foreach ($iCal->getComponents() as $c) {
             if ($c->getType() == 'vcard') {
                 try {
                     $registry->call('contacts/import', array($c, null, $source));
                     ++$count;
                 } catch (Horde_Exception $e) {
                     $notification->push(Horde_Core_Translation::t("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error');
                 }
             }
         }
         $notification->push(sprintf(Horde_Core_Translation::ngettext("%d contact was successfully added to your address book.", "%d contacts were successfully added to your address book.", $count), $count), 'horde.success');
     }
     $html .= '<table class="horde-table" style="width:100%">';
     foreach ($iCal->getComponents() as $i => $vc) {
         if ($i > 0) {
             $html .= '<tr><td colspan="2">&nbsp;</td></tr>';
         }
         $addresses = $vc->getAllAttributes('EMAIL');
         $html .= '<tr><td colspan="2" class="header">';
         if (($fullname = $vc->getAttributeDefault('FN', false)) === false) {
             $fullname = count($addresses) ? $addresses[0]['value'] : Horde_Core_Translation::t("[No Label]");
         }
         $html .= htmlspecialchars($fullname) . '</td></tr>';
         $n = $vc->printableName();
         if (!empty($n)) {
             $html .= $this->_row(Horde_Core_Translation::t("Name"), $n);
         }
         try {
             $html .= $this->_row(Horde_Core_Translation::t("Alias"), implode("\n", $vc->getAttributeValues('ALIAS')));
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $birthdays = $vc->getAttributeValues('BDAY');
             $birthday = new Horde_Date($birthdays[0]);
             $html .= $this->_row(Horde_Core_Translation::t("Birthday"), $birthday->strftime($prefs->getValue('date_format')));
         } catch (Horde_Icalendar_Exception $e) {
         }
         $photos = $vc->getAllAttributes('PHOTO');
         foreach ($photos as $p => $photo) {
             if (isset($photo['params']['VALUE']) && Horde_String::upper($photo['params']['VALUE']) == 'URI') {
                 $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . htmlspecialchars($photo['value']) . '" />', false);
             } elseif (isset($photo['params']['ENCODING']) && Horde_String::upper($photo['params']['ENCODING']) == 'B' && isset($photo['params']['TYPE'])) {
                 if ($browser->hasFeature('datauri') === true || $browser->hasFeature('datauri') >= strlen($photo['value'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . Horde_Url_Data::create($photo['params']['TYPE'], base64_decode($photo['value'])) . '" />', false);
                 } elseif ($this->_imageUrl) {
                     $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . $this->_imageUrl->add(array('c' => $i, 'p' => $p)) . '" />', false);
                 }
             }
         }
         $labels = $vc->getAllAttributes('LABEL');
         foreach ($labels as $label) {
             if (isset($label['params']['TYPE'])) {
                 if (!is_array($label['params']['TYPE'])) {
                     $label['params']['TYPE'] = array($label['params']['TYPE']);
                 }
             } else {
                 $label['params']['TYPE'] = array_keys($label['params']);
             }
             $types = array();
             foreach ($label['params']['TYPE'] as $type) {
                 switch (Horde_String::upper($type)) {
                     case 'HOME':
                         $types[] = Horde_Core_Translation::t("Home Address");
                         break;
                     case 'WORK':
                         $types[] = Horde_Core_Translation::t("Work Address");
                         break;
                     case 'DOM':
                         $types[] = Horde_Core_Translation::t("Domestic Address");
                         break;
                     case 'INTL':
                         $types[] = Horde_Core_Translation::t("International Address");
                         break;
                     case 'POSTAL':
                         $types[] = Horde_Core_Translation::t("Postal Address");
                         break;
                     case 'PARCEL':
                         $types[] = Horde_Core_Translation::t("Parcel Address");
                         break;
                     case 'PREF':
                         $types[] = Horde_Core_Translation::t("Preferred Address");
                         break;
                 }
             }
             if (!count($types)) {
                 $types = array(Horde_Core_Translation::t("Address"));
             }
             $html .= $this->_row(implode('/', $types), $label['value']);
         }
         $adrs = $vc->getAllAttributes('ADR');
         foreach ($adrs as $item) {
             if (isset($item['params']['TYPE'])) {
                 if (!is_array($item['params']['TYPE'])) {
                     $item['params']['TYPE'] = array($item['params']['TYPE']);
                 }
             } else {
                 $item['params']['TYPE'] = array_keys($item['params']);
             }
             $address = $item['values'];
             $a = array();
             $a_list = array(Horde_Icalendar_Vcard::ADR_STREET, Horde_Icalendar_Vcard::ADR_LOCALITY, Horde_Icalendar_Vcard::ADR_REGION, Horde_Icalendar_Vcard::ADR_POSTCODE, Horde_Icalendar_Vcard::ADR_COUNTRY);
             foreach ($a_list as $val) {
                 if (isset($address[$val])) {
                     $a[] = $address[$val];
                 }
             }
             $types = array();
             foreach ($item['params']['TYPE'] as $type) {
                 switch (Horde_String::upper($type)) {
                     case 'HOME':
                         $types[] = Horde_Core_Translation::t("Home Address");
                         break;
                     case 'WORK':
                         $types[] = Horde_Core_Translation::t("Work Address");
                         break;
                     case 'DOM':
                         $types[] = Horde_Core_Translation::t("Domestic Address");
                         break;
                     case 'INTL':
                         $types[] = Horde_Core_Translation::t("International Address");
                         break;
                     case 'POSTAL':
                         $types[] = Horde_Core_Translation::t("Postal Address");
                         break;
                     case 'PARCEL':
                         $types[] = Horde_Core_Translation::t("Parcel Address");
                         break;
                     case 'PREF':
                         $types[] = Horde_Core_Translation::t("Preferred Address");
                         break;
                 }
             }
             if (!count($types)) {
                 $types = array(Horde_Core_Translation::t("Address"));
             }
             $html .= $this->_row(implode('/', $types), implode("\n", $a));
         }
         $numbers = $vc->getAllAttributes('TEL');
         foreach ($numbers as $number) {
             if (isset($number['params']['TYPE'])) {
                 if (!is_array($number['params']['TYPE'])) {
                     $number['params']['TYPE'] = array($number['params']['TYPE']);
                 }
                 foreach ($number['params']['TYPE'] as $type) {
                     $number['params'][Horde_String::upper($type)] = true;
                 }
             }
             if (isset($number['params']['FAX'])) {
                 $html .= $this->_row(Horde_Core_Translation::t("Fax"), $number['value']);
             } else {
                 if (isset($number['params']['HOME'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Home Phone"), $number['value']);
                 } elseif (isset($number['params']['WORK'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Work Phone"), $number['value']);
                 } elseif (isset($number['params']['CELL'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Cell Phone"), $number['value']);
                 } else {
                     $html .= $this->_row(Horde_Core_Translation::t("Phone"), $number['value']);
                 }
             }
         }
         $emails = array();
         foreach ($addresses as $address) {
             if (isset($address['params']['TYPE'])) {
                 if (!is_array($address['params']['TYPE'])) {
                     $address['params']['TYPE'] = array($address['params']['TYPE']);
                 }
                 foreach ($address['params']['TYPE'] as $type) {
                     $address['params'][Horde_String::upper($type)] = true;
                 }
             }
             $email = '<a href="';
             if ($registry->hasMethod('mail/compose')) {
                 $email .= $registry->call('mail/compose', array(array('to' => $address['value'])));
             } else {
                 $email .= 'mailto:' . htmlspecialchars($address['value']);
             }
             $email .= '">' . htmlspecialchars($address['value']) . '</a>';
             if (isset($address['params']['PREF'])) {
                 array_unshift($emails, $email);
             } else {
                 $emails[] = $email;
             }
         }
         if (count($emails)) {
             $html .= $this->_row(Horde_Core_Translation::t("Email"), implode("\n", $emails), false);
         }
         try {
             $title = $vc->getAttributeValues('TITLE');
             $html .= $this->_row(Horde_Core_Translation::t("Title"), $title[0]);
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $role = $vc->getAttributeValues('ROLE');
             $html .= $this->_row(Horde_Core_Translation::t("Role"), $role[0]);
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $org = $vc->getAttributeValues('ORG');
             $html .= $this->_row(Horde_Core_Translation::t("Company"), $org[0]);
             if (isset($org[1])) {
                 $html .= $this->_row(Horde_Core_Translation::t("Department"), $org[1]);
             }
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $notes = $vc->getAttributeValues('NOTE');
             $html .= $this->_row(Horde_Core_Translation::t("Notes"), $notes[0]);
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $url = $vc->getAttributeValues('URL');
             $html .= $this->_row(Horde_Core_Translation::t("URL"), '<a href="' . htmlspecialchars($url[0]) . '" target="_blank">' . htmlspecialchars($url[0]) . '</a>', false);
         } catch (Horde_Icalendar_Exception $e) {
         }
     }
     $html .= '</table>';
     if ($registry->hasMethod('contacts/import') && $registry->hasMethod('contacts/sources')) {
         $html .= '<div class="horde-form-buttons"><form action="' . Horde::selfUrl() . '" method="get" name="vcard_import" id="vcard_import">' . Horde_Util::formInput();
         foreach ($_GET as $key => $val) {
             $html .= '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />';
         }
         $sources = $registry->call('contacts/sources', array(true));
         if (count($sources) > 1) {
             $html .= '<input type="submit" class="horde-default" name="import" value="' . Horde_Core_Translation::t("Add to address book:") . '" />' . ' <label for="add_source" class="hidden">' . Horde_Core_Translation::t("Address Book") . '</label>' . '<select id="add_source" name="source">';
             foreach ($sources as $key => $label) {
                 $selected = $key == $prefs->getValue('add_source') ? ' selected="selected"' : '';
                 $html .= '<option value="' . htmlspecialchars($key) . '"' . $selected . '>' . htmlspecialchars($label) . '</option>';
             }
             $html .= '</select>';
         } else {
             reset($sources);
             $html .= '<input type="submit" class="horde-default" name="import" value="' . Horde_Core_Translation::t("Add to my address book") . '" />' . '<input type="hidden" name="source" value="' . htmlspecialchars(key($sources)) . '" />';
         }
         $html .= '</form></div>';
     }
     Horde::startBuffer();
     $notification->notify(array('listeners' => 'status'));
     return $this->_renderReturn(Horde::endBuffer() . $html, 'text/html; charset=' . $this->getConfigParam('charset'));
 }
Example #9
0
File: Api.php Project: Gomez/horde
 /**
  */
 protected function _getContactImageUrl($obj)
 {
     if ($photo = $obj->getValue('photo')) {
         try {
             $img = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create();
             $img->loadString($photo['load']['data']);
             $img->resize(50, 50, true);
             $data = $img->raw(true);
             $type = $img->getContentType();
         } catch (Horde_Image_Exception $e) {
             $data = $photo['load']['data'];
             $type = $obj->getValue('phototype');
         }
         return Horde_Url_Data::create($type, $data);
     }
 }
Example #10
0
 /**
  */
 protected function _init()
 {
     global $conf, $injector, $notification, $page_output, $prefs, $registry, $session;
     $mailbox = $this->indices->mailbox;
     $imp_imap = $mailbox->imp_imap;
     /* We know we are going to be exclusively dealing with this mailbox,
      * so select it on the IMAP server (saves some STATUS calls). Open R/W
      * to clear the RECENT flag. */
     $imp_imap->openMailbox($mailbox, Horde_Imap_Client::OPEN_READWRITE);
     /* Make sure we have a valid index. */
     $imp_mailbox = $mailbox->list_ob;
     $imp_mailbox->setIndex($this->indices);
     if (!$imp_mailbox->isValidIndex()) {
         $this->_returnToMailbox(null, 'message_missing');
         return;
     }
     $imp_flags = $injector->getInstance('IMP_Flags');
     $imp_identity = $injector->getInstance('IMP_Identity');
     $imp_message = $injector->getInstance('IMP_Message');
     $imp_ui = $injector->getInstance('IMP_Message_Ui');
     /* Run through action handlers. */
     if ($this->vars->actionID) {
         try {
             $session->getToken($this->vars->token);
         } catch (Horde_Exception $e) {
             $notification->push($e);
             $this->vars->actionID = null;
         }
     }
     $readonly = $mailbox->readonly;
     $peek = false;
     switch ($this->vars->actionID) {
         case 'blacklist':
         case 'whitelist':
             if ($this->vars->actionID == 'blacklist') {
                 $injector->getInstance('IMP_Filter')->blacklistMessage($this->indices);
             } else {
                 $injector->getInstance('IMP_Filter')->whitelistMessage($this->indices);
             }
             break;
         case 'delete_message':
             $imp_message->delete($this->indices, array('mailboxob' => $imp_mailbox));
             if ($prefs->getValue('mailbox_return')) {
                 $this->_returnToMailbox($imp_mailbox->getIndex());
                 return;
             }
             if ($imp_ui->moveAfterAction($mailbox)) {
                 $imp_mailbox->setIndex(1);
             }
             break;
         case 'undelete_message':
             $imp_message->undelete($this->indices);
             break;
         case 'move_message':
         case 'copy_message':
             if (isset($this->vars->targetMbox) && (!$readonly || $this->vars->actionID == 'copy_message')) {
                 if ($this->vars->newMbox) {
                     $targetMbox = IMP_Mailbox::prefFrom($this->vars->targetMbox);
                     $newMbox = true;
                 } else {
                     $targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox);
                     $newMbox = false;
                 }
                 $imp_message->copy($targetMbox, $this->vars->actionID == 'move_message' ? 'move' : 'copy', $this->indices, array('create' => $newMbox, 'mailboxob' => $imp_mailbox));
                 if ($prefs->getValue('mailbox_return')) {
                     $this->_returnToMailbox($imp_mailbox->getIndex());
                     return;
                 }
             }
             break;
         case 'innocent_report':
         case 'spam_report':
             $res = $injector->getInstance('IMP_Factory_Spam')->create($this->vars->actionID == 'spam_report' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices, array('mailbox' => $imp_mailbox));
             switch ($res) {
                 case 1:
                     if ($imp_ui->moveAfterAction($mailbox)) {
                         $imp_mailbox->setIndex(1);
                     }
                     break;
             }
             if ($prefs->getValue('mailbox_return')) {
                 $this->_returnToMailbox($imp_mailbox->getIndex());
                 return;
             }
             break;
         case 'flag_message':
             if (!$readonly && isset($this->vars->flag) && count($this->indices)) {
                 $peek = true;
                 $flag = $imp_flags->parseFormId($this->vars->flag);
                 $imp_message->flag(array($flag['set'] ? 'add' : 'remove' => array($flag['flag'])), $this->indices);
                 if ($prefs->getValue('mailbox_return')) {
                     $this->_returnToMailbox($imp_mailbox->getIndex());
                     return;
                 }
             }
             break;
         case 'add_address':
             try {
                 $contact_link = $injector->getInstance('IMP_Contacts')->addAddress($this->vars->address, $this->vars->name);
                 $notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
             } catch (Horde_Exception $e) {
                 $notification->push($e);
             }
             break;
         case 'strip_all':
         case 'strip_attachment':
             if (!$readonly) {
                 try {
                     $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $imp_message->stripPart($this->indices, $this->vars->actionID == 'strip_all' ? null : $this->vars->imapid, array('mailboxob' => $imp_mailbox)));
                     $notification->push(_("Attachment successfully stripped."), 'horde.success');
                 } catch (Horde_Exception $e) {
                     $notification->push($e);
                 }
             }
             break;
     }
     /* We may have done processing that has taken us past the end of the
      * message array, so we will return to the mailbox. */
     if (!$imp_mailbox->isValidIndex()) {
         $this->_returnToMailbox(count($imp_mailbox));
         return;
     }
     /* Now that we are done processing, get the index and array index of
      * the current message. */
     $msg_index = $imp_mailbox[$imp_mailbox->getIndex()];
     /* Parse the message. */
     try {
         $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imp_mailbox));
     } catch (IMP_Exception $e) {
         $imp_mailbox->removeMsgs(true);
         $this->_returnToMailbox(null, 'message_missing');
         return;
     }
     /* Get envelope/flag/header information. */
     try {
         /* Need to fetch flags before HEADERTEXT, because SEEN flag might
          * be set before we can grab it. */
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->flags();
         $flags_ret = $imp_imap->fetch($msg_index['m'], $query, array('ids' => $imp_imap->getIdsOb($msg_index['u'])));
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->envelope();
         $fetch_ret = $imp_imap->fetch($msg_index['m'], $query, array('ids' => $imp_imap->getIdsOb($msg_index['u'])));
     } catch (IMP_Imap_Exception $e) {
         $this->_returnToMailbox(null, 'message_missing');
         return;
     }
     $envelope = $fetch_ret->first()->getEnvelope();
     $flags = $flags_ret->first()->getFlags();
     $mime_headers = $peek ? $imp_contents->getHeader() : $imp_contents->getHeaderAndMarkAsSeen();
     /* Get the title/mailbox label of the mailbox page. */
     $page_label = $mailbox->label;
     /* Generate the link to ourselves. */
     $buid = $imp_mailbox->getBuid($msg_index['m'], $msg_index['u']);
     $msgindex = $imp_mailbox->getIndex();
     $message_url = Horde::url('basic.php')->add('page', 'message');
     $token = $session->getToken();
     $self_link = self::url(array('buid' => $buid, 'mailbox' => $mailbox))->add(array('token' => $token, 'start' => $msgindex));
     /* Develop the list of headers to display. */
     $basic_headers = $imp_ui->basicHeaders();
     $display_headers = $msgAddresses = array();
     $date_ob = new IMP_Message_Date($envelope->date);
     if ($format_date = $date_ob->format($date_ob::DATE_LOCAL)) {
         $display_headers['date'] = $format_date;
     }
     /* Build From address links. */
     $display_headers['from'] = $imp_ui->buildAddressLinks($envelope->from, $self_link);
     /* Add country/flag image. */
     if (!empty($envelope->from)) {
         $contacts_img = new IMP_Contacts_Image($envelope->from[0]);
         try {
             $res = $contacts_img->getImage($contacts_img::FLAG);
             $display_headers['from'] .= '&nbsp;' . Horde_Themes_Image::tag($res['url'], array('alt' => $res['desc'], 'fullsrc' => true));
         } catch (IMP_Exception $e) {
         }
     }
     /* Look for Face information. */
     if ($face = $mime_headers->getValue('face')) {
         $display_headers['from'] .= '&nbsp;<img src="' . Horde_Url_Data::create('image/png', base64_decode($face)) . '">';
     }
     /* Build To/Cc/Bcc links. */
     foreach (array('to', 'cc', 'bcc') as $val) {
         $msgAddresses[] = $mime_headers->getValue($val);
         if ($val == 'to' || count($envelope->{$val})) {
             $display_headers[$val] = $imp_ui->buildAddressLinks($envelope->{$val}, $self_link);
         }
     }
     /* Process the subject now. */
     if ($subject = $mime_headers->getValue('subject')) {
         $this->title = sprintf(_("%s: %s"), $page_label, $subject);
         $shortsub = Horde_String::truncate($subject, 100);
     } else {
         $shortsub = _("[No Subject]");
         $this->title = sprintf(_("%s: %s"), $page_label, $shortsub);
     }
     /* See if the priority has been set. */
     switch ($injector->getInstance('IMP_Mime_Headers')->getPriority($mime_headers)) {
         case 'high':
             $basic_headers['priority'] = _("Priority");
             $display_headers['priority'] = '<div class="iconImg msgflags flagHighpriority" title="' . htmlspecialchars(_("High Priority")) . '"></div>&nbsp;' . _("High");
             break;
         case 'low':
             $basic_headers['priority'] = _("Priority");
             $display_headers['priority'] = '<div class="iconImg msgflags flagLowpriority" title="' . htmlspecialchars(_("Low Priority")) . '"></div>&nbsp;' . _("Low");
             break;
     }
     /* Build Reply-To address link. */
     if (!empty($envelope->reply_to) && $envelope->from[0]->bare_address != $envelope->reply_to[0]->bare_address && ($reply_to = $imp_ui->buildAddressLinks($envelope->reply_to, $self_link))) {
         $display_headers['reply-to'] = $reply_to;
     }
     /* Determine if all/list/user-requested headers needed. */
     $all_headers = $this->vars->show_all_headers;
     $user_hdrs = $imp_ui->getUserHeaders();
     /* Check for the presence of mailing list information. */
     $list_info = $imp_ui->getListInformation($mime_headers);
     /* Display all headers or, optionally, the user-specified headers for
      * the current identity. */
     $full_headers = array();
     if ($all_headers) {
         $header_array = $mime_headers->toArray();
         foreach ($header_array as $head => $val) {
             $lc_head = strtolower($head);
             /* Skip the header if we have already dealt with it. */
             if (!isset($display_headers[$lc_head]) && (!in_array($lc_head, array('importance', 'x-priority')) || !isset($display_headers['priority']))) {
                 $full_headers[$lc_head] = $val;
             }
         }
     } elseif (!empty($user_hdrs)) {
         foreach ($user_hdrs as $user_hdr) {
             $user_val = $mime_headers->getValue($user_hdr);
             if (!empty($user_val)) {
                 $full_headers[$user_hdr] = $user_val;
             }
         }
     }
     ksort($full_headers);
     /* For the self URL link, we can't trust the index in the query string
      * as it may have changed if we deleted/copied/moved messages. We may
      * need other stuff in the query string, so we need to do an
      * add/remove of uid info. */
     $selfURL = $mailbox->url(Horde::selfUrlParams()->remove(array('actionID')), $buid)->add('token', $token);
     $headersURL = $selfURL->copy()->remove(array('show_all_headers'));
     /* Generate previous/next links. */
     $prev_msg = $imp_mailbox[$imp_mailbox->getIndex() - 1];
     if ($prev_msg) {
         $prev_url = self::url(array('buid' => $imp_mailbox->getBuid($prev_msg['m'], $prev_msg['u']), 'mailbox' => $mailbox))->setRaw(true);
         $page_output->addLinkTag(array('href' => $prev_url, 'id' => 'prev', 'rel' => 'Previous', 'type' => null));
     } else {
         $prev_url = null;
     }
     $next_msg = $imp_mailbox[$imp_mailbox->getIndex() + 1];
     if ($next_msg) {
         $next_url = self::url(array('buid' => $imp_mailbox->getBuid($next_msg['m'], $next_msg['u']), 'mailbox' => $mailbox))->setRaw(true);
         $page_output->addLinkTag(array('href' => $next_url, 'id' => 'next', 'rel' => 'Next', 'type' => null));
     } else {
         $next_url = null;
     }
     /* Generate the mailbox link. */
     $mailbox_url = $mailbox->url('mailbox')->add('start', $msgindex);
     /* Everything below here is related to preparing the output. */
     $js_vars = array('ImpMessage.text' => array('innocent_report' => _("Are you sure you wish to report this message as innocent?"), 'moveconfirm' => _("Are you sure you want to move the message(s)? (Some message information might get lost, like message headers, text formatting or attachments!)"), 'newmbox' => _("You are copying/moving to a new mailbox.") . "\n" . _("Please enter a name for the new mailbox:") . "\n", 'spam_report' => _("Are you sure you wish to report this message as spam?"), 'target_mbox' => _("You must select a target mailbox first.")));
     /* Set the status information of the message. */
     $msgAddresses[] = $mime_headers->getValue('from');
     $identity = $match_identity = $imp_identity->getMatchingIdentity($msgAddresses);
     if (is_null($identity)) {
         $identity = $imp_identity->getDefault();
     }
     $flag_parse = $imp_flags->parse(array('flags' => $flags, 'personal' => $match_identity));
     $status = '';
     foreach ($flag_parse as $val) {
         if ($val instanceof IMP_Flag_User) {
             $status .= '<span class="' . $val->css . '" style="' . ($val->bgdefault ? '' : 'background:' . htmlspecialchars($val->bgcolor) . ';') . 'color:' . htmlspecialchars($val->fgcolor) . '">' . htmlspecialchars($val->label) . '</span>';
         } else {
             $status .= $val->span;
         }
     }
     /* If this is a search mailbox, display a link to the parent mailbox
      * of the message in the header. */
     $h_page_label = htmlspecialchars($page_label);
     $header_label = $h_page_label;
     if ($mailbox->search) {
         $header_label .= ' [' . $msg_index['m']->url('mailbox')->link() . $msg_index['m']->display_html . '</a>]';
     }
     /* Prepare the navbar top template. */
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/message'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $t_view = clone $view;
     $t_view->buid = $buid;
     $t_view->message_url = $message_url;
     $t_view->mailbox = $mailbox->form_to;
     $t_view->start = $msgindex;
     $t_view->token = $token;
     /* Prepare the navbar navigate template. */
     $n_view = clone $view;
     $n_view->readonly = $readonly;
     $n_view->id = 1;
     if ($mailbox->access_flags) {
         $n_view->mailbox = $mailbox->form_to;
         $args = array('imap' => true, 'mailbox' => $mailbox);
         $form_set = $form_unset = array();
         foreach ($imp_flags->getList($args) as $val) {
             if ($val->canset) {
                 $form_set[] = array('f' => $val->form_set, 'l' => $val->label);
                 $form_unset[] = array('f' => $val->form_unset, 'l' => $val->label);
             }
         }
         $n_view->flaglist_set = $form_set;
         $n_view->flaglist_unset = $form_unset;
     }
     if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
         $n_view->move = Horde::widget(array('url' => '#', 'class' => 'moveAction', 'title' => _("Move"), 'nocheck' => true));
         $n_view->copy = Horde::widget(array('url' => '#', 'class' => 'copyAction', 'title' => _("Copy"), 'nocheck' => true));
         $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
         $iterator->add($iterator::NONIMAP);
         $n_view->options = new IMP_Ftree_Select(array('heading' => _("This message to"), 'inc_tasklists' => true, 'inc_notepads' => true, 'iterator' => $iterator, 'new_mbox' => true));
     }
     $n_view->back_to = Horde::widget(array('url' => $mailbox_url, 'title' => sprintf(_("Bac_k to %s"), $h_page_label), 'nocheck' => true));
     if ($prev_url) {
         $n_view->prev = Horde::link($prev_url, _("Previous Message"));
         $n_view->prev_img = 'navleftImg';
     } else {
         $n_view->prev_img = 'navleftgreyImg';
     }
     if ($next_url) {
         $n_view->next = Horde::link($next_url, _("Next Message"));
         $n_view->next_img = 'navrightImg';
     } else {
         $n_view->next_img = 'navrightgreyImg';
     }
     /* Prepare the navbar actions template. */
     $a_view = clone $view;
     $compose_params = array('buid' => $buid, 'identity' => $identity, 'mailbox' => IMP_Mailbox::formTo($mailbox));
     if (!$prefs->getValue('compose_popup')) {
         $compose_params['start'] = $msgindex;
     }
     if ($msg_index['m']->access_deletemsgs) {
         if (in_array(Horde_Imap_Client::FLAG_DELETED, $flags)) {
             $a_view->delete = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'undelete_message'), 'title' => _("Undelete"), 'nocheck' => true));
         } else {
             $a_view->delete = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'delete_message'), 'title' => _("_Delete"), 'nocheck' => true));
             if (!$msg_index['m']->is_imap) {
                 $js_vars['ImpMessage.pop3delete'] = _("Are you sure you want to PERMANENTLY delete these messages?");
             }
         }
     }
     $disable_compose = !IMP_Compose::canCompose();
     if (!$disable_compose) {
         $clink_ob = new IMP_Compose_Link();
         $clink = $clink_ob->link()->add($compose_params);
         $a_view->reply = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply_auto')), 'class' => 'horde-hasmenu', 'title' => _("_Reply"), 'nocheck' => true));
         $a_view->reply_sender = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply')), 'title' => _("To Sender"), 'nocheck' => true));
         if ($list_info['reply_list']) {
             $a_view->reply_list = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply_list')), 'title' => _("To _List"), 'nocheck' => true));
         }
         $addr_ob = clone $envelope->to;
         $addr_ob->add($envelope->cc);
         $addr_ob->setIteratorFilter(0, $imp_identity->getAllFromAddresses());
         if (count($addr_ob)) {
             $a_view->show_reply_all = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply_all')), 'title' => _("To _All"), 'nocheck' => true));
         }
         $fwd_locked = $prefs->isLocked('forward_default');
         $a_view->forward = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_auto')), 'class' => $fwd_locked ? '' : ' horde-hasmenu', 'title' => _("Fo_rward"), 'nocheck' => true));
         if (!$fwd_locked) {
             $a_view->forward_attach = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_attach')), 'title' => _("As Attachment"), 'nocheck' => true));
             $a_view->forward_body = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_body')), 'title' => _("In Body Text"), 'nocheck' => true));
             $a_view->forward_both = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_both')), 'title' => _("Attachment and Body Text"), 'nocheck' => true));
         }
         $a_view->redirect = Horde::widget(array('url' => $clink->add(array('actionID' => 'redirect_compose')), 'title' => _("Redirec_t"), 'nocheck' => true));
         $a_view->editasnew = Horde::widget(array('url' => $clink->add(array('actionID' => 'editasnew')), 'title' => _("Edit as New"), 'nocheck' => true));
     }
     if ($mailbox->access_sortthread) {
         $a_view->show_thread = Horde::widget(array('url' => $mailbox->url(IMP_Basic_Thread::url(), $buid)->add(array('start' => $msgindex)), 'title' => _("_View Thread"), 'nocheck' => true));
     }
     if (!$readonly && $registry->hasMethod('mail/blacklistFrom')) {
         $a_view->blacklist = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'blacklist'), 'title' => _("_Blacklist"), 'nocheck' => true));
     }
     if (!$readonly && $registry->hasMethod('mail/whitelistFrom')) {
         $a_view->whitelist = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'whitelist'), 'title' => _("_Whitelist"), 'nocheck' => true));
     }
     if (!empty($conf['user']['allow_view_source'])) {
         $a_view->view_source = $imp_contents->linkViewJS($imp_contents->getMIMEMessage(), 'view_source', _("_Message Source"), array('css' => '', 'jstext' => _("Message Source"), 'widget' => true));
     }
     if (!$disable_compose && (in_array(Horde_Imap_Client::FLAG_DRAFT, $flags) || $msg_index['m']->drafts)) {
         $a_view->resume = Horde::widget(array('url' => $clink->add(array('actionID' => 'draft')), 'title' => _("Resume"), 'nocheck' => true));
     }
     $imp_params = $mailbox->urlParams($buid);
     $a_view->save_as = Horde::widget(array('url' => IMP_Contents_View::downloadUrl($subject, array_merge(array('actionID' => 'save_message'), $imp_params)), 'title' => _("Sa_ve as"), 'nocheck' => true));
     if ($msg_index['m']->spam_show) {
         $a_view->spam = Horde::widget(array('url' => '#', 'class' => 'spamAction', 'title' => _("Report as Spam"), 'nocheck' => true));
     }
     if ($msg_index['m']->innocent_show) {
         $a_view->innocent = Horde::widget(array('url' => '#', 'class' => 'innocentAction', 'title' => _("Report as Innocent"), 'nocheck' => true));
     }
     if (!$disable_compose) {
         $a_view->redirect = Horde::widget(array('url' => $clink->add(array('actionID' => 'redirect_compose')), 'title' => _("Redirec_t"), 'nocheck' => true));
     }
     $a_view->headers = Horde::widget(array('url' => '#', 'class' => 'horde-hasmenu', 'title' => _("Headers"), 'nocheck' => true));
     if ($all_headers) {
         $a_view->common_headers = Horde::widget(array('url' => $headersURL, 'title' => _("Show Common Headers"), 'nocheck' => true));
     }
     if (!$all_headers) {
         $a_view->all_headers = Horde::widget(array('url' => $headersURL->copy()->add('show_all_headers', 1), 'title' => _("Show All Headers"), 'nocheck' => true));
     }
     if ($list_info['exists']) {
         $a_view->list_headers = Horde::widget(array('onclick' => Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $mailbox)), array('urlencode' => true)), 'title' => _("Show Mailing List Information"), 'nocheck' => true));
     }
     $hdrs = array();
     /* Prepare the main message template. */
     if (!$all_headers) {
         foreach ($display_headers as $head => $val) {
             $hdrs[] = array('name' => $basic_headers[$head], 'val' => $val);
         }
     }
     foreach ($full_headers as $head => $val) {
         if (is_array($val)) {
             $hdrs[] = array('name' => $head, 'val' => '<ul style="margin:0;padding-left:15px"><li>' . implode("</li>\n<li>", array_map('htmlspecialchars', $val)) . '</li></ul>');
         } else {
             $hdrs[] = array('name' => $head, 'val' => htmlspecialchars($val));
         }
     }
     /* Determine the fields that will appear in the MIME info entries. */
     $part_info = $part_info_display = array('icon', 'description', 'size');
     $part_info_action = array('download', 'download_zip', 'img_save', 'strip');
     $part_info_bodyonly = array('print');
     $show_parts = isset($this->vars->show_parts) ? $this->vars->show_parts : $prefs->getValue('parts_display');
     $part_info_display = array_merge($part_info_display, $part_info_action, $part_info_bodyonly);
     $contents_mask = IMP_Contents::SUMMARY_BYTES | IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_DESCRIP_LINK | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_DOWNLOAD_ZIP | IMP_Contents::SUMMARY_IMAGE_SAVE | IMP_Contents::SUMMARY_PRINT;
     /* Do MDN processing now. */
     $mdntext = $imp_ui->MDNCheck(new IMP_Indices($msg_index['m'], $buid), $mime_headers, $this->vars->mdn_confirm) ? strval(new IMP_Mime_Status(array(_("The sender of this message is requesting a notification from you when you have read this message."), sprintf(_("Click %s to send the notification message."), Horde::link($selfURL->copy()->add('mdn_confirm', 1)) . _("HERE") . '</a>')))) : '';
     /* Build body text. This needs to be done before we build the
      * attachment list that lives in the header. */
     $inlineout = $imp_contents->getInlineOutput(array('mask' => $contents_mask, 'part_info_display' => $part_info_display, 'show_parts' => $show_parts));
     /* Build the Attachments menu. */
     $show_atc = false;
     switch ($show_parts) {
         case 'atc':
             $a_view->show_parts_all = Horde::widget(array('url' => $headersURL->copy()->add(array('show_parts' => 'all')), 'title' => _("Show All Parts"), 'nocheck' => true));
             $show_atc = true;
             break;
         case 'all':
             if ($prefs->getValue('strip_attachments')) {
                 $js_vars['ImpMessage.text']['stripwarn'] = _("Are you sure you wish to PERMANENTLY delete this attachment?");
             }
             break;
     }
     if (count($inlineout['atc_parts']) > 2) {
         $a_view->download_all = Horde::widget(array('url' => $imp_contents->urlView($imp_contents->getMIMEMessage(), 'download_all'), 'title' => _("Download All Attachments (in .zip file)"), 'nocheck' => true));
         if ($prefs->getValue('strip_attachments')) {
             $a_view->strip_all = Horde::widget(array('url' => Horde::selfUrlParams()->add(array('actionID' => 'strip_all', 'token' => $token)), 'class' => 'stripAllAtc', 'title' => _("Strip All Attachments"), 'nocheck' => true));
             $js_vars['ImpMessage.text']['stripallwarn'] = _("Are you sure you want to PERMANENTLY delete all attachments?");
         }
         $show_atc = true;
     }
     if ($show_atc) {
         $a_view->atc = Horde::widget(array('url' => '#', 'class' => 'horde-hasmenu', 'title' => _("Attachments"), 'nocheck' => true));
     }
     /* Show attachment information in headers? 'atc_parts' will be empty if
      * 'parts_display' pref is 'none'. */
     if (!empty($inlineout['atc_parts'])) {
         if ($show_parts == 'all') {
             $val = $imp_contents->getTree()->getTree(true);
         } else {
             $tmp = array();
             foreach ($inlineout['atc_parts'] as $id) {
                 $summary = $imp_contents->getSummary($id, $contents_mask);
                 $tmp[] = '<tr>';
                 foreach ($part_info as $val) {
                     $tmp[] = '<td>' . $summary[$val] . '</td>';
                 }
                 $tmp[] = '<td>';
                 foreach ($part_info_action as $val) {
                     $tmp[] = $summary[$val];
                 }
                 $tmp[] = '</td></tr>';
             }
             $val = '<table>' . implode('', $tmp) . '</table>';
         }
         $hdrs[] = array('class' => 'msgheaderParts', 'name' => $show_parts == 'all' ? _("Parts") : _("Attachments"), 'val' => $val);
     }
     $m_view = clone $view;
     $m_view->label = $shortsub;
     $m_view->headers = $hdrs;
     $m_view->msgtext = $mdntext . $inlineout['msgtext'];
     $subinfo = new IMP_View_Subinfo(array('mailbox' => $mailbox));
     $subinfo->label = $header_label;
     $subinfo->value = sprintf(_("(%d of %d)"), $msgindex, count($imp_mailbox)) . $status;
     $injector->getInstance('Horde_View_Topbar')->subinfo = $subinfo->render();
     /* Output message page now. */
     $page_output->addInlineJsVars($js_vars, array('top' => true));
     $page_output->addScriptFile('scriptaculous/effects.js', 'horde');
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('message.js');
     $page_output->addScriptFile('stripe.js', 'horde');
     $page_output->addScriptPackage('IMP_Script_Package_Imp');
     if (!empty($conf['tasklist']['use_notepad']) || !empty($conf['tasklist']['use_tasklist'])) {
         $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
     }
     $page_output->noDnsPrefetch();
     Horde::startBuffer();
     foreach ($injector->getInstance('IMP_Maillog')->getLog(new IMP_Maillog_Message($this->indices, array('mdn'))) as $val) {
         $notification->push($val->message, 'imp.' . $val->action);
     }
     $this->output = Horde::endBuffer();
     $this->output .= $t_view->render('navbar_top') . $n_view->render('navbar_navigate') . $a_view->render('navbar_actions') . $m_view->render('message') . $a_view->render('navbar_actions');
     $n_view->id = 2;
     $n_view->isbottom = true;
     $this->output .= $n_view->render('navbar_navigate');
 }
Example #11
0
 /**
  */
 protected function _minify($data)
 {
     $out = '';
     foreach ($data as $uri => $file) {
         if (!is_readable($file)) {
             $this->_opts['logger']->log(sprintf('Could not open CSS file %s.', $file), Horde_Log::ERR);
             continue;
         }
         $css = file_get_contents($file);
         try {
             $parser = new Horde_Css_Parser($css);
         } catch (Exception $e) {
             /* If the CSS is broken, log error and output as-is. */
             $this->_opts['logger']->log($e, Horde_Log::ERR);
             $out .= $css;
             continue;
         }
         if (!empty($this->_opts['import'])) {
             foreach ($parser->doc->getContents() as $val) {
                 if ($val instanceof Sabberworm\CSS\Property\Import) {
                     $res = call_user_func($this->_opts['import'], dirname($uri) . '/' . $val->getLocation()->getURL()->getString());
                     $out .= $this->_minify(array($res[0] => $res[1]));
                     $parser->doc->remove($val);
                 }
             }
         }
         $url = array();
         foreach ($parser->doc->getAllRuleSets() as $val) {
             foreach (array_merge($val->getRules('background-'), $val->getRules('src')) as $val2) {
                 $item = $val2->getValue();
                 if ($item instanceof Sabberworm\CSS\Value\URL) {
                     $url[] = $item;
                 } elseif ($item instanceof Sabberworm\CSS\Value\RuleValueList) {
                     foreach ($item->getListComponents() as $val3) {
                         if ($val3 instanceof Sabberworm\CSS\Value\URL) {
                             $url[] = $val3;
                         } elseif ($val3 instanceof Sabberworm\CSS\Value\RuleValueList) {
                             foreach ($val3->getListComponents() as $val4) {
                                 if ($val4 instanceof Sabberworm\CSS\Value\URL) {
                                     $url[] = $val4;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         foreach ($url as $val) {
             $url_ob = $val->getURL();
             $url_str = ltrim($url_ob->getString());
             if (stripos($url_str, 'http') !== 0 && !Horde_Url_Data::isData($url_str)) {
                 $url_str = dirname($uri) . '/' . $url_str;
                 if (!empty($this->_opts['dataurl'])) {
                     $url_str = call_user_func($this->_opts['dataurl'], $url_str);
                 }
             }
             $url_ob->setString($url_str);
         }
         $out .= $parser->compress();
     }
     return $out;
 }
Example #12
0
 /**
  * Clean outgoing HTML (remove unexpected data URLs).
  *
  * @param Horde_Domhtml $html  The HTML data.
  */
 protected function _cleanHtmlOutput(Horde_Domhtml $html)
 {
     global $registry;
     $xpath = new DOMXPath($html->dom);
     foreach ($xpath->query('//*[@src]') as $node) {
         $src = $node->getAttribute('src');
         /* Check for attempts to sneak data URL information into the
          * output. */
         if (Horde_Url_Data::isData($src)) {
             if (IMP_Compose_HtmlSignature::isSigImage($node, true)) {
                 /* This is HTML signature image data. Convert to an
                  * attachment. */
                 $sig_img = new Horde_Url_Data($src);
                 if ($sig_img->data) {
                     $data_part = new Horde_Mime_Part();
                     $data_part->setContents($sig_img->data);
                     $data_part->setType($sig_img->type);
                     try {
                         $this->addRelatedAttachment($this->addAttachmentFromPart($data_part), $node, 'src');
                     } catch (IMP_Compose_Exception $e) {
                         // Remove image on error.
                     }
                 }
             }
             $node->removeAttribute('src');
         } elseif (strcasecmp($node->tagName, 'IMG') === 0) {
             /* Check for smileys. They live in the JS directory, under
              * the base ckeditor directory, so search for that and replace
              * with the filesystem information if found (Request
              * #13051). Need to ignore other image links that may have
              * been explicitly added by the user. */
             $js_path = strval(Horde::url($registry->get('jsuri', 'horde'), true));
             if (stripos($src, $js_path . '/ckeditor') === 0) {
                 $file = str_replace($js_path, $registry->get('jsfs', 'horde'), $src);
                 if (is_readable($file)) {
                     $data_part = new Horde_Mime_Part();
                     $data_part->setContents(file_get_contents($file));
                     $data_part->setName(basename($file));
                     try {
                         $this->addRelatedAttachment($this->addAttachmentFromPart($data_part), $node, 'src');
                     } catch (IMP_Compose_Exception $e) {
                         // Keep existing data on error.
                     }
                 }
             }
         }
     }
 }
Example #13
0
 /**
  * Output an image tag.
  *
  * @param string $type  The view type.
  * @param string $alt   The ALT text.
  *
  * @return string  An image tag.
  */
 protected function _outputImgTag($type, $alt)
 {
     global $browser;
     $view = null;
     switch ($type) {
         case 'view_thumbnail':
             if ($this->getConfigParam('thumbnails_dataurl') && $browser->getFeature('dataurl')) {
                 $thumb = $this->_viewConvert(true);
                 $thumb = reset($thumb);
                 $src = Horde_Url_Data::create($thumb['type'], $thumb['data']);
                 break;
             }
             $view = 'view_thumbnail';
             // Fall-through
         // Fall-through
         default:
             $src = $this->_imgDataUrl($view);
             break;
     }
     return '<img src="' . $src . '" alt="' . htmlspecialchars($alt, ENT_COMPAT, $this->getConfigParam('charset')) . '" />';
 }
Example #14
0
 public static function base64ImgData($in, $limit = null)
 {
     if (!($dataurl = $GLOBALS['browser']->hasFeature('dataurl'))) {
         return $in;
     }
     if (!is_null($limit) && (is_bool($dataurl) || $limit < $dataurl)) {
         $dataurl = $limit;
     }
     /* Only encode image files if they are below the dataurl limit. */
     if (!$in instanceof Horde_Themes_Image) {
         $in = self::fromUri($in);
     }
     if (!file_exists($in->fs)) {
         return $in->uri;
     }
     /* Delete approx. 50 chars from the limit to account for the various
      * data/base64 header text.  Multiply by 0.75 to determine the
      * base64 encoded size. */
     return $dataurl === true || filesize($in->fs) <= $dataurl * 0.75 - 50 ? strval(Horde_Url_Data::create(Horde_Mime_Magic::extToMime(substr($in->uri, strrpos($in->uri, '.') + 1)), file_get_contents($in->fs))) : $in->uri;
 }