Changeset 19cc5b9 in github for program/steps/mail/func.inc


Ignore:
Timestamp:
May 30, 2012 5:22:18 AM (12 months ago)
Author:
Aleksander Machniak <alec@…>
Branches:
master, HEAD, dev-browser-capabilities, pdo
Children:
d901205
Parents:
b9854b8
Message:

Display Tiff as Jpeg in browsers without Tiff support (#1488452)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/steps/mail/func.inc

    r7c1231a r19cc5b9  
    10981098  } 
    10991099 
    1100   // Skip TIFF images if browser doesn't support this format 
    1101   // @TODO: we could convert TIFF to JPEG and display it 
    1102   $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  
    11061100  // list images after mail body 
    11071101  if ($CONFIG['inline_images'] && !empty($MESSAGE->attachments)) { 
     
    11131107 
    11141108      // 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)) { 
    11211110        $out .= html::tag('hr') . html::p(array('align' => "center"), 
    11221111          html::img(array( 
     
    11361125} 
    11371126 
     1127function 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} 
    11381169 
    11391170/** 
Note: See TracChangeset for help on using the changeset viewer.