Skip to content

Commit

Permalink
Merge pull request #5392 from tsnr/sqml_fenc
Browse files Browse the repository at this point in the history
Convert charset with file based backend.
  • Loading branch information
alecpl committed Aug 12, 2016
2 parents 0836b21 + 8bc134c commit 6dbbf0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
5 changes: 4 additions & 1 deletion plugins/squirrelmail_usercopy/config.inc.php.dist
Expand Up @@ -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';
Expand All @@ -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;
$config['squirrelmail_set_alias'] = true;
25 changes: 21 additions & 4 deletions plugins/squirrelmail_usercopy/squirrelmail_usercopy.php
Expand Up @@ -162,6 +162,7 @@ private function read_squirrel_prefs($uname)
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';
Expand All @@ -172,27 +173,43 @@ private function read_squirrel_prefs($uname)
$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");
}
}
}
}

// 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;
}
Expand Down

0 comments on commit 6dbbf0e

Please sign in to comment.