Ticket #1484961: rcube_imap.patch

File rcube_imap.patch, 1.9 KB (added by alec, 17 months ago)

use rc_detect_encoding()

  • rcube_imap.php

     
    13371336      if ($o_part->ctype_primary=='text' || $o_part->ctype_primary=='message') 
    13381337        { 
    13391338        // assume default if no charset specified 
    1340         if (empty($o_part->charset)) 
    1341           $o_part->charset = $this->default_charset; 
     1339        if (empty($o_part->charset) || preg_match('/us-ascii|x-unknown/i', $o_part->charset)) 
     1340          $o_part->charset = rc_detect_encoding(substr($body, 0, 10000), $this->default_charset); 
    13421341 
    13431342        $body = rcube_charset_convert($body, $o_part->charset); 
    13441343        } 
     
    13641363  function &get_body($uid, $part=1) 
    13651364    { 
    13661365    $headers = $this->get_headers($uid); 
    1367     return rcube_charset_convert( 
    1368       $this->mime_decode($this->get_message_part($uid, $part), 'quoted-printable'), 
    1369       $headers->charset ? $headers->charset : $this->default_charset); 
     1366    $body = $this->mime_decode($this->get_message_part($uid, $part), 'quoted-printable'); 
     1367    return rcube_charset_convert($body, $headers->charset ? $headers->charset 
     1368        : rc_detect_encoding(substr($body, 0, 10000), $this->default_charset)); 
    13701369    } 
    13711370 
    13721371 
     
    24342433   */ 
    24352434  function decode_header($input, $remove_quotes=FALSE) 
    24362435    { 
    2437     $str = rcube_imap::decode_mime_string((string)$input, $this->default_charset); 
     2436    $str = rcube_imap::decode_mime_string((string)$input, rc_detect_encoding($input)); 
    24382437    if ($str{0}=='"' && $remove_quotes) 
    24392438      $str = str_replace('"', '', $str); 
    24402439     
     
    25712570      return rcube_charset_convert($body, $ctype_param['charset']); 
    25722571 
    25732572    // defaults to what is specified in the class header 
    2574     return rcube_charset_convert($body,  $this->default_charset); 
     2573    return rcube_charset_convert($body,  rc_detect_encoding(substr($body, 0, 10000), $this->default_charset)); 
    25752574    } 
    25762575 
    25772576