From 0106a25421134e74ab8cfc514492077d22c9dfc4 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 1 Mar 2010 16:06:16 +0100 Subject: [PATCH] Show photos in vcard attachments, even if they don't fit into a data: url. --- framework/Mime/lib/Horde/Mime/Viewer/Vcard.php | 30 +++++++---- imp/config/mime_drivers.php.dist | 15 +++++- imp/lib/Mime/Viewer/Vcard.php | 72 +++++++++++++++++++++++++ imp/themes/graphics/mime/vcard.png | Bin 0 -> 331 bytes imp/themes/silver/graphics/mime/vcard.png | Bin 0 -> 533 bytes imp/themes/tango-blue/graphics/mime/vcard.png | Bin 0 -> 564 bytes 6 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 imp/lib/Mime/Viewer/Vcard.php create mode 100644 imp/themes/graphics/mime/vcard.png create mode 100644 imp/themes/silver/graphics/mime/vcard.png create mode 100644 imp/themes/tango-blue/graphics/mime/vcard.png diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php b/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php index 01c569ca6..8f636a5c7 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php @@ -25,6 +25,13 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver ); /** + * URL that can be used as a callback for displaying images. + * + * @var Horde_Url + */ + protected $_imageUrl; + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See Horde_Mime_Viewer_Driver::render(). @@ -86,12 +93,10 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver $html .= ''; - $i = 0; - foreach ($iCal->getComponents() as $vc) { + foreach ($iCal->getComponents() as $i => $vc) { if ($i > 0) { $html .= ''; } - ++$i; $html .= '
 
'; $fullname = $vc->getAttributeDefault('FN', false); @@ -118,7 +123,7 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver } $photos = $vc->getAllAttributes('PHOTO'); - foreach ($photos as $photo) { + foreach ($photos as $p => $photo) { if (isset($photo['params']['VALUE']) && Horde_String::upper($photo['params']['VALUE']) == 'URI') { $html .= $this->_row(_("Photo"), @@ -126,12 +131,17 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver false); } elseif (isset($photo['params']['ENCODING']) && Horde_String::upper($photo['params']['ENCODING']) == 'B' && - isset($photo['params']['TYPE']) && - ($GLOBALS['browser']->hasFeature('datauri') === true || - $GLOBALS['browser']->hasFeature('datauri') >= strlen($photo['value']))) { - $html .= $this->_row(_("Photo"), - '', - false); + isset($photo['params']['TYPE'])) { + if ($GLOBALS['browser']->hasFeature('datauri') === true || + $GLOBALS['browser']->hasFeature('datauri') >= strlen($photo['value'])) { + $html .= $this->_row(_("Photo"), + '', + false); + } elseif ($this->_imageUrl) { + $html .= $this->_row(_("Photo"), + '', + false); + } } } diff --git a/imp/config/mime_drivers.php.dist b/imp/config/mime_drivers.php.dist index 1b66dbe30..b8dc81601 100644 --- a/imp/config/mime_drivers.php.dist +++ b/imp/config/mime_drivers.php.dist @@ -36,12 +36,13 @@ * smime S/MIME signed/encrypted messages * status Mail delivery status messages * tnef MS-TNEF attachments + * vcard vCards * zip ZIP attachments */ $mime_drivers_map['imp']['registered'] = array( 'alternative', 'appledouble', 'enriched', 'html', 'images', 'itip', 'mdn', 'partial', 'pdf', 'pgp', 'plain', 'related', 'rfc822', 'smil', - 'smime', 'status', 'tnef', 'zip' + 'smime', 'status', 'tnef', 'vcard', 'zip' ); /** @@ -177,6 +178,18 @@ $mime_drivers['imp']['smime'] = array( ); /** + * vCard driver settings + */ +$mime_drivers['imp']['vcard'] = array( + 'handles' => array( + 'text/vcard', 'text/x-vcard', 'text/directory' + ), + 'icons' => array( + 'default' => 'vcard.png' + ) +); + +/** * Zip File Attachments settings */ $mime_drivers['imp']['zip'] = array( diff --git a/imp/lib/Mime/Viewer/Vcard.php b/imp/lib/Mime/Viewer/Vcard.php new file mode 100644 index 000000000..372503dfd --- /dev/null +++ b/imp/lib/Mime/Viewer/Vcard.php @@ -0,0 +1,72 @@ + + * @package IMP + */ +class IMP_Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Vcard +{ + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * URL parameters used by this function: + *
+     * 'c' - (integer) The VCARD component that contains an image.
+     * 'p' - (integer) The index of image inside the component to display.
+     * 
+ * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _render() + { + if (is_null(Horde_Util::getFormData('p'))) { + $this->_imageUrl = $this->_params['contents']->urlView($this->_mimepart, 'download_render'); + return parent::_render(); + } + + /* Send the requested photo. */ + $data = $this->_mimepart->getContents(); + $ical = new Horde_iCalendar(); + if (!$ical->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) { + // TODO: Error reporting + return array(); + } + $components = $ical->getComponents(); + $c = Horde_Util::getFormData('c'); + $p = Horde_Util::getFormData('p'); + if (!isset($components[$c])) { + // TODO: Error reporting + return array(); + } + $name = $components[$c]->getAttributeDefault('FN', false); + if ($name === false) { + $name = $components[$c]->printableName(); + } + if (empty($name)) { + $name = preg_replace('/\..*?$/', '', $this->_mimepart->getName()); + } + + $photos = $components[$c]->getAllAttributes('PHOTO'); + if (!isset($photos[$p])) { + // TODO: Error reporting + return array(); + } + return array( + $this->_mimepart->getMimeId() => array( + 'data' => base64_decode($photos[$p]['value']), + 'name' => $name . '.' . Horde_Mime_Magic::mimeToExt($photos[$p]['params']['TYPE']), + 'status' => array(), + 'type' => $photos[$p]['params']['TYPE'], + ) + ); + } + +} diff --git a/imp/themes/graphics/mime/vcard.png b/imp/themes/graphics/mime/vcard.png new file mode 100644 index 0000000000000000000000000000000000000000..3ac43256c9a93076250c02324deb46397c069b0a GIT binary patch literal 331 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}LV!<*D-)L-lN(c1R#Dn4rfG}T zZQFP3A9D$*-MaT`^1M~M51l@J>GrEvuMVBMV!p?AD$p*$k|4j}|7d_g zb?wX~pk$|~i(^Q|t=KaMg$^n3xL%CN@)p!y!NKJD@4r6x(&ps%O5Mi!OwUASB))$u z|NXZ3fddYE`}sIn*KM66tE~5!|CUDRhkNShmrT8MMcig$)w)j+OEzh4SjCk4aK^-@ zDHG%VvQH97x^Xbg{GpImOvbtcHi;b~%#^24dF_nR2<@_W67)1?cUEu^twUb)isDIFhhds}=iK3R>bPJ|0e?$zQO{gfSb6 zAmw}l&+|y1)FDbOh~LB|8AsbZWx#U1r$+A&&@Nx#xl}^&O@y|4t-qIL8GGyFgudOB zMUBefj6^S-TgKXw9~(9fXO}l9u&h~_&1U!^@!0B?~s|2G5wL<6_)Q&2rqn4Ysi zYDkz=-^k9mUKoqT&@0!tb`xM{bJg4sMG?(rlN1C@+IG7gZnyh)fD-9^wOWPO>qRga zgu~$&m^wiaP%IV^2m}y`M05a#41+*G!W1YTk2ASkP8&9ThNn^~CX>l%T{(BmzyFOt XHe4|Dt4X literal 0 HcmV?d00001 diff --git a/imp/themes/tango-blue/graphics/mime/vcard.png b/imp/themes/tango-blue/graphics/mime/vcard.png new file mode 100644 index 0000000000000000000000000000000000000000..fdbcbe0702a192f2c68e39a67bd67e618233bd8a GIT binary patch literal 564 zcmV-40?Yl0P)k;D5sNE#?nD&o0~DbM60|5SDH0)|bWts6)d&@BLp6}6~M6kgFABUMc=R4;fn80d-{Os!@wG-Qj zam&X3Pn9PY);(Y1IH-p!wRvG0R; z4S3c&c*Ycnk%X%yFnMo85b)x!kM}`(eTe6$=XZcoiej;dN~MCOrA1Uey@jcMgl(D56