From b541216c53f8fd286ccb0e9e6172ffdcce8f2592 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 07 Jun 2008 14:48:59 -0400
Subject: [PATCH] -added encoding detection for attachment names when message part hasn't got charset definition (#1484969)

---
 program/include/rcube_shared.inc |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index 8e9d3dd..801dac7 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -581,4 +581,33 @@
     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;
+}
+
+?>

--
Gitblit v1.9.1