From 19a61851ae7bc9492504c4884db8a53afa5d06c5 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 29 Jul 2015 14:39:07 -0400
Subject: [PATCH] Fix so imap folder attribute comparisons are case-insensitive (#1490466) + make in_array_nocase() much faster for ASCII strings
---
CHANGELOG | 1 +
program/lib/Roundcube/bootstrap.php | 24 +++++++++++++++++-------
program/include/rcmail.php | 2 +-
program/lib/Roundcube/rcube_imap.php | 4 ++--
4 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index d79694e..68751f8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,6 +17,7 @@
- Fix so *-request@ addresses in Sender: header are also ignored on reply-all (#1490452)
- Update to TinyMCE 4.1.10 (#1490405)
- Fix draft removal after a message is sent and storing sent message is disabled (#1490467)
+- Fix so imap folder attribute comparisons are case-insensitive (#1490466)
RELEASE 1.1.2
-------------
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 0bcedeb..be395be 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -1584,7 +1584,7 @@
// skip folders in which it isn't possible to create subfolders
if (!empty($opts['skip_noinferiors'])) {
$attrs = $this->storage->folder_attributes($folder['id']);
- if ($attrs && in_array('\\Noinferiors', $attrs)) {
+ if ($attrs && in_array_nocase('\\Noinferiors', $attrs)) {
continue;
}
}
diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php
index f9505c3..0509c6b 100644
--- a/program/lib/Roundcube/bootstrap.php
+++ b/program/lib/Roundcube/bootstrap.php
@@ -104,19 +104,29 @@
/**
- * Similar function as in_array() but case-insensitive
+ * Similar function as in_array() but case-insensitive with multibyte support.
*
- * @param string $needle Needle value
- * @param array $heystack Array to search in
+ * @param string $needle Needle value
+ * @param array $heystack Array to search in
*
* @return boolean True if found, False if not
*/
function in_array_nocase($needle, $haystack)
{
- $needle = mb_strtolower($needle);
- foreach ((array)$haystack as $value) {
- if ($needle === mb_strtolower($value)) {
- return true;
+ // use much faster method for ascii
+ if (is_ascii($needle)) {
+ foreach ((array) $haystack as $value) {
+ if (strcasecmp($value, $needle) === 0) {
+ return true;
+ }
+ }
+ }
+ else {
+ $needle = mb_strtolower($needle);
+ foreach ((array) $haystack as $value) {
+ if ($needle === mb_strtolower($value)) {
+ return true;
+ }
}
}
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index d17b33f..6f58fdc 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -2871,7 +2871,7 @@
if (is_array($a_folders) && $name == '*' && !empty($this->conn->data['LIST'])) {
foreach ($a_folders as $idx => $folder) {
if (($opts = $this->conn->data['LIST'][$folder])
- && in_array('\\NonExistent', $opts)
+ && in_array_nocase('\\NonExistent', $opts)
) {
$this->conn->unsubscribe($folder);
unset($a_folders[$idx]);
@@ -3408,7 +3408,7 @@
if ($subscription) {
// It's possible we already called LIST command, check LIST data
if (!empty($this->conn->data['LIST']) && !empty($this->conn->data['LIST'][$folder])
- && in_array('\\Subscribed', $this->conn->data['LIST'][$folder])
+ && in_array_nocase('\\Subscribed', $this->conn->data['LIST'][$folder])
) {
$a_folders = array($folder);
}
--
Gitblit v1.9.1