diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-06-07 18:48:59 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-06-07 18:48:59 +0000 |
| commit | eb64fd9b275f5367ca5bbce8626467a3e338a99e (patch) | |
| tree | 31a8e981c8d61a0b27806dd84bf657f6cc8e9822 /roundcubemail/program/include/rcube_shared.inc | |
| parent | f91adb2e30eae548dd457327a6ca50217dfc909e (diff) | |
-added encoding detection for attachment names when message part hasn't got charset definition (#1484969)
git-svn-id: https://svn.roundcube.net/trunk@1490 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcube_shared.inc')
| -rw-r--r-- | roundcubemail/program/include/rcube_shared.inc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/roundcubemail/program/include/rcube_shared.inc b/roundcubemail/program/include/rcube_shared.inc index 8e9d3dd1c..801dac7fe 100644 --- a/roundcubemail/program/include/rcube_shared.inc +++ b/roundcubemail/program/include/rcube_shared.inc @@ -581,4 +581,33 @@ function rc_mime_content_type($path, $failover = 'unknown/unknown') return $mime_type; } -?>
\ No newline at end of file + +/** + * A method to guess encoding of a string. + * + * @param string $string String. + * @param string $failover Default result for failover. + * + * @return string + */ +function rc_detect_encoding($string, $failover='') +{ + if (!function_exists('mb_detect_encoding')) { + return $failover; + } + + // FIXME: the order is important, because sometimes + // iso string is detected as euc-jp and etc. + $enc = array( + 'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', + 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', + 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', + 'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R' + ); + + $result = mb_detect_encoding($string, join(',', $enc)); + + return $result ? $result : $failover; +} + +?> |
