Changeset 2802 in subversion


Ignore:
Timestamp:
Jul 28, 2009 4:41:50 AM (4 years ago)
Author:
alec
Message:
  • Fix displaying of HTML messages with unknown/malformed tags (#1486003)
  • Some other changes for styled HTML display
Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r2779 r2802  
    22=========================== 
    33 
     4- Fix displaying of HTML messages with unknown/malformed tags (#1486003) 
     5 
     6RELEASE 0.3-RC1 
     7--------------- 
    48- Fix import of vCard entries with params (#1485453) 
    59- Fix HTML messages output with empty block elements (#1485974) 
  • trunk/roundcubemail/program/lib/washtml.php

    r2759 r2802  
    7070 *  - Dont alter data on a GET: '<img src="http://yourhost/mail?action=delete&uid=3267" />' 
    7171 *  - ... 
     72 * 
     73 * Roundcube Changes: 
     74 * - added $block_elements 
     75 * - changed $ignore_elements behaviour 
    7276 */ 
    7377 
     
    7781  static $html_elements = array('a', 'abbr', 'acronym', 'address', 'area', 'b', 'basefont', 'bdo', 'big', 'blockquote', 'br', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'ins', 'label', 'legend', 'li', 'map', 'menu', 'nobr', 'ol', 'p', 'pre', 'q', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'wbr', 'img'); 
    7882   
    79   /* Ignore these HTML tags but process their content */ 
    80   static $ignore_elements = array('html', 'head', 'body'); 
     83  /* Ignore these HTML tags and their content */ 
     84  static $ignore_elements = array('script', 'applet', 'embed', 'object', 'style'); 
    8185   
    8286  /* Allowed HTML attributes */ 
     
    210214          $content = $this->dumpHtml($node); 
    211215          $dump .= '<' . $tagName . $this->wash_attribs($node) . 
    212 //            ($content?">$content</$tagName>":' />'); 
    213 // Roundcube Trac: #1485974 
    214216            ($content || isset($this->_block_elements[$tagName]) ? ">$content</$tagName>" : ' />'); 
    215217        } else if(isset($this->_ignore_elements[$tagName])) { 
     218          $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' not allowed -->'; 
     219        } else { 
    216220          $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' ignored -->'; 
    217           $dump .= $this->dumpHtml($node); //Just ignored 
    218         } else 
    219           $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' not allowed -->'; 
     221          $dump .= $this->dumpHtml($node); // ignore tags not its content 
     222        } 
    220223        break; 
    221224      case XML_CDATA_SECTION_NODE: 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r2776 r2802  
    429429        $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show'; 
    430430        $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid'; 
    431         $cont = abbreviate_string(trim($IMAP->decode_header($header->$col)), 160); 
     431        $cont = trim($IMAP->decode_header($header->$col)); 
     432        if ($browser->ie) 
     433          $cont = rc_utf8_clean($cont); 
     434        $cont = abbreviate_string($cont, 160); 
    432435        if (!$cont) $cont = rcube_label('nosubject'); 
    433436        $cont = $browser->ie ? Q($cont) : sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), Q($cont)); 
     
    669672   
    670673  $p += array('safe' => false, 'inline_html' => true); 
    671    
     674 
    672675  // special replacements (not properly handled by washtml class) 
    673676  $html_search = array( 
    674677    '/(<\/nobr>)(\s+)(<nobr>)/i',       // space(s) between <NOBR> 
    675     '/(<[\/]*st1:[^>]+>)/i',            // Microsoft's Smart Tags <ST1> 
    676     '/<\/?rte_text>/i',                 // Rich Text Editor tags (#1485647) 
    677     '/<\/?broadcast[^>]*>/i',           // invoices from the Apple Store contains <broadcast> tags (#1485962) 
    678678    '/<title>.*<\/title>/i',            // PHP bug #32547 workaround: remove title tag 
    679     '/<html[^>]*>/im',                  // malformed html: remove html tags (#1485139) 
    680     '/<\/html>/i',                      // malformed html: remove html tags (#1485139) 
    681679    '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/',    // byte-order mark (only outlook?) 
    682680  ); 
     
    685683    '', 
    686684    '', 
    687     '', 
    688     '', 
    689     '', 
    690     '', 
    691     '', 
    692685  ); 
    693686  $html = preg_replace($html_search, $html_replace, $html); 
     687 
     688  // fix (unknown/malformed) HTML tags before "wash" 
     689  $html = preg_replace_callback('/(<[\/!]*)([^ >]+)/', 'rcmail_html_tag_callback', $html); 
    694690 
    695691  // charset was converted to UTF-8 in rcube_imap::get_message_part() -> change charset specification in HTML accordingly 
     
    697693  if (preg_match($charset_pattern, $html)) { 
    698694    $html = preg_replace($charset_pattern, '\\1='.RCMAIL_CHARSET, $html); 
    699   } 
    700   else { 
     695  } else { 
    701696    // add head for malformed messages, washtml cannot work without that 
    702697    if (!preg_match('/<head[^>]*>(.*)<\/head>/Uims', $html)) 
     
    729724  $washer->add_callback('form', 'rcmail_washtml_callback'); 
    730725 
    731   if ($p['safe']) {  // allow CSS styles, will be sanitized by rcmail_washtml_callback() 
    732     $washer->add_callback('style', 'rcmail_washtml_callback'); 
    733   } 
     726  // allow CSS styles, will be sanitized by rcmail_washtml_callback() 
     727  $washer->add_callback('style', 'rcmail_washtml_callback'); 
    734728     
    735729  $html = $washer->wash($html); 
     
    884878 
    885879/** 
     880 * Callback function for HTML tags fixing 
     881 */ 
     882function rcmail_html_tag_callback($matches) 
     883{ 
     884  $tagname = $matches[2]; 
     885 
     886  $tagname = preg_replace(array( 
     887    '/:.*$/',           // Microsoft's Smart Tags <st1:xxxx> 
     888    '/[^a-z0-9_-]/i',   // forbidden characters 
     889    ), '', $tagname); 
     890 
     891  return $matches[1].$tagname; 
     892} 
     893 
     894 
     895/** 
    886896 * return table with message headers 
    887897 */ 
Note: See TracChangeset for help on using the changeset viewer.