From 8bc134c284d4c12478ac37fec87d07b47a4f2bc2 Mon Sep 17 00:00:00 2001 From: Hideki Sakamoto Date: Wed, 10 Aug 2016 14:37:30 +0900 Subject: [PATCH] Convert charset wieh file based backend. --- .../squirrelmail_usercopy/config.inc.php.dist | 5 +++- .../squirrelmail_usercopy.php | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/plugins/squirrelmail_usercopy/config.inc.php.dist b/plugins/squirrelmail_usercopy/config.inc.php.dist index 03ec1cb86..97ac0cd4d 100644 --- a/plugins/squirrelmail_usercopy/config.inc.php.dist +++ b/plugins/squirrelmail_usercopy/config.inc.php.dist @@ -7,6 +7,9 @@ $config['squirrelmail_driver'] = 'sql'; $config['squirrelmail_data_dir'] = ''; $config['squirrelmail_data_dir_hash_level'] = 0; +// file charset - e.g. 'EUC-JP'. Leave empty for ASCII. +$config['squirrelmail_file_charset'] = ''; + // 'mysql://dbuser:dbpass@localhost/database' $config['squirrelmail_dsn'] = 'mysql://user:password@localhost/webmail'; $config['squirrelmail_db_charset'] = 'iso-8859-1'; @@ -22,4 +25,4 @@ $config['squirrelmail_identities_level'] = null; // Set to false if you don't want the email address of the default identity // (squirrelmail preference "email_address") to be saved as alias. // Recommended: set to false if your squirrelmail config setting $edit_identity has been true. -$config['squirrelmail_set_alias'] = true; \ No newline at end of file +$config['squirrelmail_set_alias'] = true; diff --git a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php index 9047efdd2..bbee4ef4f 100644 --- a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php +++ b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php @@ -162,6 +162,7 @@ class squirrelmail_usercopy extends rcube_plugin if (($hash_level = $rcmail->config->get('squirrelmail_data_dir_hash_level')) > 0) { $srcdir = slashify($srcdir).chunk_split(substr(base_convert(crc32($uname), 10, 16), 0, $hash_level), 1, '/'); } + $file_charset = $rcmail->config->get('squirrelmail_file_charset'); $prefsfile = slashify($srcdir) . $uname . '.pref'; $abookfile = slashify($srcdir) . $uname . '.abook'; @@ -172,19 +173,31 @@ class squirrelmail_usercopy extends rcube_plugin $this->prefs = array(); foreach (file($prefsfile) as $line) { list($key, $value) = explode('=', $line); - $this->prefs[$key] = utf8_encode(rtrim($value)); + if (empty($file_charset)) { + $this->prefs[$key] = utf8_encode(rtrim($value)); + } else { + $this->prefs[$key] = rcube_charset::convert(rtrim($value), $file_charset, "UTF-8"); + } } // also read signature file if exists if (is_readable($sigfile)) { - $this->prefs['___signature___'] = utf8_encode(file_get_contents($sigfile)); + if (empty($file_charset)) { + $this->prefs['___signature___'] = utf8_encode(file_get_contents($sigfile)); + } else { + $this->prefs['___signature___'] = rcube_charset::convert(file_get_contents($sigfile), $file_charset, "UTF-8"); + } } if (isset($this->prefs['identities']) && $this->prefs['identities'] > 1) { for ($i=1; $i < $this->prefs['identities']; $i++) { // read signature file if exists if (is_readable($sigbase.$i)) { - $this->prefs['___sig'.$i.'___'] = utf8_encode(file_get_contents($sigbase.$i)); + if (empty($file_charset)) { + $this->prefs['___sig'.$i.'___'] = utf8_encode(file_get_contents($sigbase.$i)); + } else { + $this->prefs['___sig'.$i.'___'] = rcube_charset::convert(file_get_contents($sigbase.$i), $file_charset, "UTF-8"); + } } } } @@ -192,7 +205,11 @@ class squirrelmail_usercopy extends rcube_plugin // parse addres book file if (filesize($abookfile)) { foreach(file($abookfile) as $line) { - list($rec['name'], $rec['firstname'], $rec['surname'], $rec['email']) = explode('|', utf8_encode(rtrim($line))); + if (empty($file_charset)) { + list($rec['name'], $rec['firstname'], $rec['surname'], $rec['email']) = explode('|', utf8_encode(rtrim($line))); + } else { + list($rec['name'], $rec['firstname'], $rec['surname'], $rec['email']) = explode('|', rcube_charset::convert(rtrim($line), $file_charset, "UTF-8")); + } if ($rec['name'] && $rec['email']) { $this->abook[] = $rec; }