From dc97e0c56a87d17bdf388c3e4038859dcf45e519 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 12 Mar 2009 23:20:37 -0600 Subject: [PATCH] Work around some browser limitations regarding RFC 2397 --- imp/lib/IMP.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 143189c9e..e020b32a1 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1719,8 +1719,16 @@ class IMP */ public function base64ImgData($file) { - $data = file_get_contents(realpath($GLOBALS['registry']->get('fileroot', 'horde')) . preg_replace('/^' . preg_quote($GLOBALS['registry']->get('webroot', 'horde'), '/') . '/', '', $file)); - return 'data:image/' . substr($file, strrpos($file, '.') + 1) . ';base64,' . base64_encode($data); + /* Only encode image files if they are below 3,000 bytes. RFC 2397 + * only requires support of up to 1,024 characters (base64 encoded, + * not the size of the image). However, browsers that support data + * URLs generally support more. Opera seems to have the smallest + * allowance - 4100 characters - so use Opera as a limit. */ + $filename = realpath($GLOBALS['registry']->get('fileroot', 'horde')) . preg_replace('/^' . preg_quote($GLOBALS['registry']->get('webroot', 'horde'), '/') . '/', '', $file); + + return (filesize($filename) <= 3000) + ? 'data:image/' . substr($file, strrpos($file, '.') + 1) . ';base64,' . base64_encode(file_get_contents($filename)) + : $file; } /** -- 2.11.0