Changeset 1490 in subversion


Ignore:
Timestamp:
Jun 7, 2008 2:48:59 PM (5 years ago)
Author:
alec
Message:

-added encoding detection for attachment names when message part hasn't got charset definition (#1484969)

Location:
trunk/roundcubemail/program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_imap.php

    r1480 r1490  
    11601160        $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); 
    11611161      } 
    1162        
     1162 
    11631163    // normalize filename property 
    11641164    if ($filename_mime = $struct->d_parameters['filename'] ? $struct->d_parameters['filename'] : $struct->ctype_parameters['name']) 
    1165       $struct->filename = rcube_imap::decode_mime_string($filename_mime, $this->default_charset); 
     1165    { 
     1166      $struct->filename = rcube_imap::decode_mime_string($filename_mime,  
     1167            $struct->charset ? $struct->charset : rc_detect_encoding($filename_mime, $this->default_charset)); 
     1168    } 
    11661169    else if ($filename_encoded = $struct->d_parameters['filename*'] ? $struct->d_parameters['filename*'] : $struct->ctype_parameters['name*']) 
    11671170    { 
     
    11711174    } 
    11721175    else if (!empty($struct->headers['content-description'])) 
    1173       $struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'], $this->default_charset); 
     1176      $struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'], 
     1177            $struct->charset ? $struct->charset : rc_detect_encoding($struct->headers['content-description'],$this->default_charset)); 
    11741178       
    11751179    return $struct; 
  • trunk/roundcubemail/program/include/rcube_shared.inc

    r1360 r1490  
    582582} 
    583583 
     584 
     585/** 
     586 * A method to guess encoding of a string. 
     587 * 
     588 * @param string $string        String. 
     589 * @param string $failover      Default result for failover. 
     590 * 
     591 * @return string 
     592 */ 
     593function rc_detect_encoding($string, $failover='') 
     594{ 
     595    if (!function_exists('mb_detect_encoding')) { 
     596        return $failover; 
     597    } 
     598 
     599    // FIXME: the order is important, because sometimes  
     600    // iso string is detected as euc-jp and etc. 
     601    $enc = array( 
     602        'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 
     603        'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 
     604        'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', 
     605        'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R' 
     606    ); 
     607 
     608    $result = mb_detect_encoding($string, join(',', $enc)); 
     609 
     610    return $result ? $result : $failover; 
     611} 
     612 
    584613?> 
Note: See TracChangeset for help on using the changeset viewer.