Changeset 19cc5b9 in github
- Timestamp:
- May 30, 2012 5:22:18 AM (12 months ago)
- Branches:
- master, HEAD, dev-browser-capabilities, pdo
- Children:
- d901205
- Parents:
- b9854b8
- Files:
-
- 5 edited
-
CHANGELOG (modified) (1 diff)
-
program/include/rcube_image.php (modified) (6 diffs)
-
program/steps/mail/func.inc (modified) (3 diffs)
-
program/steps/mail/get.inc (modified) (3 diffs)
-
program/steps/mail/show.inc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CHANGELOG
rb9854b8 r19cc5b9 2 2 =========================== 3 3 4 - Display Tiff as Jpeg in browsers without Tiff support (#1488452) 4 5 - Don't display Pdf/Tiff/Flash attachments inline without browser support (#1488452, #1487929) 5 6 - Fix html2text conversion of strong|b|a|th|h tags when used in upper case -
program/include/rcube_image.php
r041c93c r19cc5b9 14 14 | | 15 15 | PURPOSE: | 16 | Image resizer |16 | Image resizer and converter | 17 17 | | 18 18 +-----------------------------------------------------------------------+ … … 25 25 { 26 26 private $image_file; 27 28 const TYPE_GIF = 1; 29 const TYPE_JPG = 2; 30 const TYPE_PNG = 3; 31 const TYPE_TIF = 4; 32 33 public static $extensions = array( 34 self::TYPE_GIF => 'gif', 35 self::TYPE_JPG => 'jpg', 36 self::TYPE_PNG => 'png', 37 self::TYPE_TIF => 'tif', 38 ); 39 27 40 28 41 function __construct($filename) … … 67 80 * @param string $filename Output filename 68 81 * 69 * @return Success of convert as true/false82 * @return bool True on success, False on failure 70 83 */ 71 84 public function resize($size, $filename = null) … … 96 109 97 110 if (in_array($type, explode(',', $p['types']))) { // Valid type? 98 $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === '';99 } 100 101 if ($result ) {111 $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p); 112 } 113 114 if ($result === '') { 102 115 return true; 103 116 } … … 149 162 } 150 163 164 // @TODO: print error to the log? 165 return false; 166 } 167 168 /** 169 * Convert image to a given type 170 * 171 * @param int $type Destination file type (see class constants) 172 * @param string $filename Output filename (if empty, original file will be used 173 * and filename extension will be modified) 174 * 175 * @return bool True on success, False on failure 176 */ 177 public function convert($type, $filename = null) 178 { 179 $rcube = rcube::get_instance(); 180 $convert = $rcube->config->get('im_convert_path', false); 181 182 if (!$filename) { 183 $filename = $this->image_file; 184 185 // modify extension 186 if ($extension = self::$extensions[$type]) { 187 $filename = preg_replace('/\.[^.]+$/', '', $filename) . '.' . $extension; 188 } 189 } 190 191 // use ImageMagick 192 if ($convert) { 193 $p['in'] = $this->image_file; 194 $p['out'] = $filename; 195 $p['type'] = self::$extensions[$type]; 196 197 $result = rcube::exec($convert . ' 2>&1 -colorspace RGB -quality 75 {in} {type}:{out}', $p); 198 199 if ($result === '') { 200 return true; 201 } 202 } 203 204 // use GD extension (TIFF isn't supported) 205 $props = $this->props(); 206 $gd_types = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG); 207 208 if ($props['gd_type'] && in_array($props['gd_type'], $gd_types)) { 209 if ($props['gd_type'] == IMAGETYPE_JPEG) { 210 $image = imagecreatefromjpeg($this->image_file); 211 } 212 else if ($props['gd_type'] == IMAGETYPE_GIF) { 213 $image = imagecreatefromgif($this->image_file); 214 } 215 else if ($props['gd_type'] == IMAGETYPE_PNG) { 216 $image = imagecreatefrompng($this->image_file); 217 } 218 219 if ($type == self::TYPE_JPG) { 220 $result = imagejpeg($image, $filename, 75); 221 } 222 else if ($type == self::TYPE_GIF) { 223 $result = imagegif($image, $filename); 224 } 225 else if ($type == self::TYPE_PNG) { 226 $result = imagepng($image, $filename, 6, PNG_ALL_FILTERS); 227 } 228 } 151 229 152 230 // @TODO: print error to the log? … … 170 248 } 171 249 } 250 172 251 } -
program/steps/mail/func.inc
r7c1231a r19cc5b9 1098 1098 } 1099 1099 1100 // Skip TIFF images if browser doesn't support this format1101 // @TODO: we could convert TIFF to JPEG and display it1102 $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']);1103 $mime_regex = $tiff_support ? '/^image\//i' : '/^image\/(?!tif)/i';1104 $ext_regex = '/\.(jpg|jpeg|png|gif|bmp' . ($tiff_support ? '|tif|tiff' : '') .')$/i';1105 1106 1100 // list images after mail body 1107 1101 if ($CONFIG['inline_images'] && !empty($MESSAGE->attachments)) { … … 1113 1107 1114 1108 // Content-Type: image/*... 1115 if (preg_match($mime_regex, $attach_prop->mimetype) || 1116 // ...or known file extension: many clients are using application/octet-stream 1117 ($attach_prop->filename && 1118 preg_match('/^application\/octet-stream$/i', $attach_prop->mimetype) && 1119 preg_match($ext_regex, $attach_prop->filename)) 1120 ) { 1109 if (rcmail_part_image_type($attach_prop)) { 1121 1110 $out .= html::tag('hr') . html::p(array('align' => "center"), 1122 1111 html::img(array( … … 1136 1125 } 1137 1126 1127 function rcmail_part_image_type($part) 1128 { 1129 $rcmail = rcmail::get_instance(); 1130 1131 // Skip TIFF images if browser doesn't support this format... 1132 $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']); 1133 // until we can convert them to JPEG 1134 $tiff_support = $tiff_support || $rcmail->config->get('im_convert_path'); 1135 1136 // Content-type regexp 1137 $mime_regex = $tiff_support ? '/^image\//i' : '/^image\/(?!tif)/i'; 1138 1139 // Content-Type: image/*... 1140 if (preg_match($mime_regex, $part->mimetype)) { 1141 return $part->mimetype; 1142 } 1143 1144 // Many clients use application/octet-stream, we'll detect mimetype 1145 // by checking filename extension 1146 1147 // Supported image filename extensions to image type map 1148 $types = array( 1149 'jpg' => 'image/jpeg', 1150 'jpeg' => 'image/jpeg', 1151 'png' => 'image/png', 1152 'gif' => 'image/gif', 1153 'bmp' => 'image/bmp', 1154 ); 1155 if ($tiff_support) { 1156 $types['tif'] = 'image/tiff'; 1157 $types['tiff'] = 'image/tiff'; 1158 } 1159 1160 if ($part->filename 1161 && preg_match('/^application\/octet-stream$/i', $part->mimetype) 1162 && preg_match('/\.([^.])$/i', $part->filename, $m) 1163 && ($extension = strtolower($m[1])) 1164 && isset($types[$extension]) 1165 ) { 1166 return $types[$extension]; 1167 } 1168 } 1138 1169 1139 1170 /** -
program/steps/mail/get.inc
r041c93c r19cc5b9 23 23 // show loading page 24 24 if (!empty($_GET['_preload'])) { 25 $url = preg_replace('/ [&?]+_preload=1/', '', $_SERVER['REQUEST_URI']);25 $url = preg_replace('/([&?]+)_preload=/', '\\1_embed=', $_SERVER['REQUEST_URI']); 26 26 $message = rcube_label('loadingdata'); 27 27 … … 77 77 // overwrite modified vars from plugin 78 78 $mimetype = $plugin['mimetype']; 79 80 // TIFF to JPEG conversion, if needed 81 $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tif']); 82 if (!empty($_REQUEST['_embed']) && !$tiff_support 83 && $RCMAIL->config->get('im_convert_path') 84 && rcmail_part_image_type($part) == 'image/tiff' 85 ) { 86 $tiff2jpeg = true; 87 $mimetype = 'image/jpeg'; 88 } 89 79 90 list($ctype_primary, $ctype_secondary) = explode('/', $mimetype); 80 91 if ($plugin['body']) … … 151 162 header("Content-Disposition: $disposition; filename=\"$filename\""); 152 163 164 // handle tiff to jpeg conversion 165 if (!empty($tiff2jpeg)) { 166 $temp_dir = unslashify($RCMAIL->config->get('temp_dir')); 167 $file_path = tempnam($temp_dir, 'rcmAttmnt'); 168 169 // write content to temp file 170 if ($part->body) { 171 $saved = file_put_contents($file_path, $part->body); 172 } 173 else if ($part->size) { 174 $fd = fopen($file_path, 'w'); 175 $saved = $RCMAIL->storage->get_message_part($MESSAGE->uid, $part->mime_id, $part, false, $fd); 176 fclose($fd); 177 } 178 179 // convert image to jpeg and send it to the browser 180 if ($saved) { 181 $image = new rcube_image($file_path); 182 if ($image->convert(rcube_image::TYPE_JPG, $file_path)) { 183 header("Content-Length: " . filesize($file_path)); 184 readfile($file_path); 185 } 186 unlink($file_path); 187 } 188 } 153 189 // do content filtering to avoid XSS through fake images 154 if (!empty($_REQUEST['_embed']) && $browser->ie && $browser->ver <= 8) {190 else if (!empty($_REQUEST['_embed']) && $browser->ie && $browser->ver <= 8) { 155 191 if ($part->body) { 156 192 echo preg_match('/<(script|iframe|object)/i', $part->body) ? '' : $part->body; -
program/steps/mail/show.inc
rb9854b8 r19cc5b9 62 62 63 63 // mimetypes supported by the browser (default settings) 64 $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,image/ tiff,application/x-javascript,application/pdf,application/x-shockwave-flash');64 $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,image/bmp,image/tiff,application/x-javascript,application/pdf,application/x-shockwave-flash'); 65 65 $mimetypes = is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes; 66 66 … … 73 73 unset($mimetypes[$key]); 74 74 } 75 // @TODO: we could convert TIFF to JPEG and display it76 75 if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) { 77 unset($mimetypes[$key]); 76 // we can convert tiff to jpeg 77 if (!$RCMAIL->config->get('im_convert_path')) { 78 unset($mimetypes[$key]); 79 } 78 80 } 79 81
Note: See TracChangeset
for help on using the changeset viewer.
