Changeset 104e2353 in github


Ignore:
Timestamp:
Oct 23, 2011 4:49:35 AM (19 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
0324621
Parents:
b9787b3
Message:
  • Improve handling of malformed charset specification in HTML messages (#1488093)
File:
1 edited

Legend:

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

    rbba2529 r104e2353  
    591591 
    592592  // charset was converted to UTF-8 in rcube_imap::get_message_part(), 
    593   // -> change charset specification in HTML accordingly 
    594   $charset_pattern = '(<meta\s+[^>]*content=)[\'"]?(\w+\/\w+;\s*charset=)([a-z0-9-_]+[\'"]?)'; 
    595   if (preg_match("/$charset_pattern/Ui", $html)) { 
    596     $html = preg_replace("/$charset_pattern/i", '\\1"\\2'.RCMAIL_CHARSET.'"', $html); 
    597   } 
    598   else { 
    599     // add meta content-type to malformed messages, washtml cannot work without that 
    600     if (!preg_match('/<head[^>]*>(.*)<\/head>/Uims', $html)) 
    601       $html = '<head></head>'. $html; 
    602     $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '<head>')+6), 0); 
     593  // change/add charset specification in HTML accordingly, 
     594  // washtml cannot work without that 
     595  $meta = '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />'; 
     596 
     597  // remove old meta tag and add the new one, making sure 
     598  // that it is placed in the head (#1488093) 
     599  $html = preg_replace('/<meta[^>]+charset=[a-z0-9-_]+[^>]*>/Ui', '', $html); 
     600  $html = preg_replace('/(<head[^>]*>)/Ui', '\\1'.$meta, $html, -1, $rcount); 
     601  if (!$rcount) { 
     602    $html = '<head>' . $meta . '</head>' . $html; 
    603603  } 
    604604 
Note: See TracChangeset for help on using the changeset viewer.