From ed3e51f1b41d818ae757220fd41cdf0b093b20f6 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 02 Jul 2013 08:49:48 -0400
Subject: [PATCH] Make possible to disable some (broken) IMAP extensions with imap_disable_caps option (#1489184) Add some notes in INSTALL about broken ESEARCH in uw-imap.

---
 program/lib/Roundcube/rcube.php              |    1 +
 CHANGELOG                                    |    1 +
 INSTALL                                      |   11 +++++++++--
 program/lib/Roundcube/rcube_imap_generic.php |    8 ++++++++
 config/main.inc.php.dist                     |    8 ++++++++
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 14dc4c7..d1e8ff7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Make possible to disable some (broken) IMAP extensions with imap_disable_caps option (#1489184)
 - Contacts drag-n-drop default action is to move contacts (#1488751)
 - Added possibility to choose to move or copy contacts from drag-n-drop menu (#1488751)
 - Fix messages list sorting with THREAD=REFS
diff --git a/INSTALL b/INSTALL
index 3876f63..a4e8aa3 100644
--- a/INSTALL
+++ b/INSTALL
@@ -52,7 +52,8 @@
 4. Point your browser to http://url-to-roundcube/installer/
 5. Follow the instructions of the install script (or see MANUAL CONFIGURATION)
 6. After creating and testing the configuration, remove the installer directory
-7. Done!
+7. Check Known Issues section of this file
+8. Done!
 
 
 CONFIGURATION HINTS
@@ -135,7 +136,6 @@
 To keep your database slick and clean we recommend to periodically execute
 bin/cleandb.sh which finally removes all records that are marked as deleted.
 Best solution is to install a cronjob running this script daily.
-
 
 
 MANUAL CONFIGURATION
@@ -233,3 +233,10 @@
 
     compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml", "image/gif", "image/png")
 }
+
+
+KNOWN ISSUES
+============
+
+Installations with uw-imap server should set imap_disabled_caps = array('ESEARCH')
+in main configuration file. ESEARCH implementation in this server is broken (#1489184).
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index f24f51f..1d1eb9d 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -107,12 +107,20 @@
 // extension if available. Some servers (dovecot 1.x) returns wrong results
 // for shared namespaces in this case. http://trac.roundcube.net/ticket/1486225
 // Enable this option to force LSUB command usage instead.
+// Deprecated: Use imap_disabled_caps = array('LIST-EXTENDED')
 $rcmail_config['imap_force_lsub'] = false;
 
 // Some server configurations (e.g. Courier) doesn't list folders in all namespaces
 // Enable this option to force listing of folders in all namespaces
 $rcmail_config['imap_force_ns'] = false;
 
+// List of disabled imap extensions.
+// Use if your IMAP server has broken implementation of some feature
+// and you can't remove it from CAPABILITY string on server-side.
+// For example UW-IMAP server has broken ESEARCH.
+// Note: Because the list is cached, re-login is required after change.
+$rcmail_config['imap_disabled_caps'] = array();
+
 // IMAP connection timeout, in seconds. Default: 0 (no limit)
 $rcmail_config['imap_timeout'] = 0;
 
diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php
index 6543a39..05a94f3 100644
--- a/program/lib/Roundcube/rcube.php
+++ b/program/lib/Roundcube/rcube.php
@@ -377,6 +377,7 @@
             'auth_pw'     => $this->config->get("{$driver}_auth_pw"),
             'debug'       => (bool) $this->config->get("{$driver}_debug"),
             'force_caps'  => (bool) $this->config->get("{$driver}_force_caps"),
+            'disabled_caps' => $this->config->get("{$driver}_disabled_caps"),
             'timeout'     => (int) $this->config->get("{$driver}_timeout"),
             'skip_deleted' => (bool) $this->config->get('skip_deleted'),
             'driver'      => $driver,
diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php
index 1928c70..ae390a0 100644
--- a/program/lib/Roundcube/rcube_imap_generic.php
+++ b/program/lib/Roundcube/rcube_imap_generic.php
@@ -715,6 +715,10 @@
             $auth_method = 'CHECK';
         }
 
+        if (!empty($this->prefs['disabled_caps'])) {
+            $this->prefs['disabled_caps'] = array_map('strtoupper', (array)$this->prefs['disabled_caps']);
+        }
+
         $result = false;
 
         // initialize connection
@@ -3686,6 +3690,10 @@
 
         $this->capability = explode(' ', strtoupper($str));
 
+        if (!empty($this->prefs['disabled_caps'])) {
+            $this->capability = array_diff($this->capability, $this->prefs['disabled_caps']);
+        }
+
         if (!isset($this->prefs['literal+']) && in_array('LITERAL+', $this->capability)) {
             $this->prefs['literal+'] = true;
         }

--
Gitblit v1.9.1