Ticket #241: iconv.patch

File iconv.patch, 6.1 kB (added by dmorton, 6 years ago)

initial stab at using iconv to display other charsets in utf-8

  • php/cache.php

    === php/cache.php
    ==================================================================
     
    514514                    } 
    515515                    $rows[$count]['recipient_email'] = $rectmp; 
    516516 
    517            $subject = trim(htmlentities($magic_quotes ? stripslashes($row['subject']) : $row['subject'])); 
     517           $subject = $magic_quotes ? stripslashes($row['subject']) : $row['subject']; 
    518518           if ($subject == "") { 
    519519              $subject = "(" . $lang['text_no_subject'] . ")"; 
    520520           }else{ 
    521                  $subject = decode_header($subject, $html_charset); 
     521                 $subject = htmlspecialchars(iconv_mime_decode($subject, 2, 'utf-8'), ENT_COMPAT, 'UTF-8'); 
    522522           } 
    523523                  $rows[$count]['subject'] = $subject; 
    524524                  $count++; 
  • php/mime.php

    === php/mime.php
    ==================================================================
     
    8989   { 
    9090      global $lang; 
    9191        
    92        
    9392      $ret = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">\n"; 
    9493 
    9594      if (isset($structure->headers["from"])) { 
    9695         $ret .= "<tr><td class=\"mailheader\" align=\"left\" valign=\"top\">\n"; 
    9796         $ret .= "<font color=\"red\">FROM:</font></td>"; 
    98          $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . trim(htmlentities($structure->headers["from"])) . "</td></tr>"; 
     97         $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . htmlspecialchars(iconv_mime_decode($structure->headers["from"],2, 'utf-8'), ENT_QUOTES, 'utf-8') . "</td></tr>"; 
    9998      } 
    10099      if (isset($structure->headers["to"])) { 
    101100         $ret .= "<tr><td class=\"mailheader\" align=\"left\" valign=\"top\">\n"; 
    102101         $ret .= "<font color=\"red\">TO:</font></td>"; 
    103          $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . trim(htmlentities($structure->headers["to"])) . "</td></tr>"; 
     102         $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . htmlspecialchars(iconv_mime_decode($structure->headers["to"],2, 'utf-8'), ENT_QUOTES, 'utf-8') . "</td></tr>"; 
    104103      } 
    105104      if (isset($structure->headers["subject"])) { 
    106105         $ret .= "<tr><td class=\"mailheader\" align=\"left\" valign=\"top\">\n"; 
    107106         $ret .= "<font color=\"red\">SUBJECT:</font></td>"; 
    108          $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . trim(htmlentities($structure->headers["subject"])) . "</td></tr>"; 
     107         $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . htmlspecialchars(iconv_mime_decode($structure->headers["subject"],2, 'utf-8'), ENT_QUOTES, 'utf-8') . "</td></tr>"; 
    109108      } 
    110109      $primary = strtolower(trim($structure->ctype_primary)); 
    111110      $secondary = strtolower(trim($structure->ctype_secondary)); 
    112111      $ctype = $primary . "/" . $secondary; 
     112      $message_charset = $structure->ctype_parameters['charset']; 
     113       
    113114      $ret .= "<tr><td class=\"mailheader\" align=\"left\" valign=\"top\" width=\"150\">\n"; 
    114115      $ret .= "<font color=\"red\">CONTENT-TYPE:</font></td>"; 
    115116      $ret .= "<td class=\"mailheader\" align=\"left\" valign=\"top\">" . $ctype . "</td></tr>"; 
     
    140141               // a sane width. 
    141142               case "plain": 
    142143 
    143                   $ret .= "<pre>" . sanitize_html(wordwrap($structure->body, 70)) . "</pre>"; 
     144                  $ret .= "<pre>" . sanitize_html(wordwrap(iconv($message_charset, 'utf-8',  $structure->body), 70)) . "</pre>"; 
    144145                  break; 
    145146 
    146147               // HTML content, clean it up a bit and display it. 
    147148               case "html": 
    148149 
    149                   $ret .= sanitize_html($structure->body); 
     150                  $ret .= sanitize_html(iconv($message_charset, 'utf-8',  $structure->body)); 
    150151                  break; 
    151152 
    152153               // Some other odd text format we don't support, ignore it. 
  • php/smarty.php

    === php/smarty.php
    ==================================================================
     
    195195    $smarty->assign('MAIA_VERSION', MAIA_VERSION); 
    196196    $smarty->assign('display_language', $display_language); 
    197197    $smarty->assign('html_charset', $html_charset); 
     198    header("Content-Type: text/html; $html_charset"); 
    198199    $smarty->assign("msid", $msid); 
    199200    $smarty->assign("sid", $sid); 
    200201    $smarty->assign('banner_title', $banner_title); 
  • php/themes/desert_sand/templates/list-cache.tpl

    === php/themes/desert_sand/templates/list-cache.tpl
    ==================================================================
     
    8181</b></td> 
    8282<td align="left"> 
    8383<a id="link_{$row[hamloop].id}" class="thickbox HelpTipAnchor" href="view.php{$msid}mail_id={$row[hamloop].id}&amp;cache_type={$cache_type}&amp;address_id={$row[hamloop].address_id}"> 
    84 {$row[hamloop].subject|truncate:$truncate_subject:"...":true|escape:'htmlall'} 
    85 </a><span id="cluetip_link_{$row[hamloop].id}"  class="HelpTip">{$row[hamloop].subject|escape:'htmlall'}</span></td> 
     84{$row[hamloop].subject|truncate:$truncate_subject:"...":true|escape} 
     85</a><span id="cluetip_link_{$row[hamloop].id}"  class="HelpTip">{$row[hamloop].subject}</span></td> 
    8686<td align="center"> 
    8787<span class="HelpTipAnchor" id="received_date{$row[hamloop].id}">{$row[hamloop].received_date|truncate:$truncate_subject:"...":true|escape}</span> 
    8888<span class="HelpTip" id="cluetip_received_date{$row[hamloop].id}">{$row[hamloop].received_date|escape:"javascript"|escape}</span> 
  • php/view.php

    === php/view.php
    ==================================================================
     
    214214          $mail = new Mail_mimeDecode((get_magic_quotes_gpc() ? stripslashes($contents) : $contents)); 
    215215          $args['include_bodies'] = true; 
    216216          $args['decode_bodies'] = true; 
    217           $args['decode_headers'] = true; 
     217          $args['decode_headers'] = false;  // the inconv decoding will handle the headers 
    218218          $structure = $mail->decode($args); 
    219219          $smarty->assign("message", display_parts($structure)); 
    220220