From b0f7e4207c140567959b633d9e579c7538acb070 Mon Sep 17 00:00:00 2001 From: dchisolm Date: Mon, 4 Mar 2019 11:08:33 +0000 Subject: [PATCH] Parse abook entries more reliably (#6646) * Update the squirrelmail_user_copy plugin to use the same method of parsing abook entries as squirrelmail uses. If a user has entered something that has been quoted such as double quotes or pipes, this will parse the address book entry better than exploding on the pipe alone * Noticed undefined variable $sig in convert charset --- .../squirrelmail_usercopy.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php index 89db8eb5b..d8bab8990 100644 --- a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php +++ b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php @@ -163,7 +163,6 @@ class squirrelmail_usercopy extends rcube_plugin $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'; $sigfile = slashify($srcdir) . $uname . '.sig'; @@ -194,9 +193,20 @@ class squirrelmail_usercopy extends rcube_plugin // parse address book file if (filesize($abookfile)) { + foreach (file($abookfile) as $line) { + $line = $this->convert_charset(rtrim($line), $file_charset); - list($rec['name'], $rec['firstname'], $rec['surname'], $rec['email']) = explode('|', $line); + $line = str_getcsv($line, "|"); + + $rec = array( + 'name' => $line[0], + 'firstname' => $line[1], + 'surname' => $line[2], + 'email' => $line[3], + 'notes' => $line[4], + ); + if ($rec['name'] && $rec['email']) { $this->abook[] = $rec; } @@ -252,7 +262,7 @@ class squirrelmail_usercopy extends rcube_plugin private function convert_charset($str, $charset = null) { if (!$charset) { - return utf8_encode($sig); + return utf8_encode($str); } return rcube_charset::convert($str, $charset, RCUBE_CHARSET);