From 600bb156f79908e0ca72a039c6ad290146a2eb4e Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 04 Jan 2011 06:16:54 -0500
Subject: [PATCH] - Use improved get_capability() syntax, saves CAPABILITY call in some cases

---
 program/steps/settings/edit_folder.inc |    4 +---
 program/include/rcube_imap.php         |    8 ++++----
 program/steps/mail/func.inc            |    8 ++------
 program/steps/settings/func.inc        |    8 +++-----
 program/include/rcube_imap_generic.php |   20 +++++++++-----------
 5 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 24c361c..2697504 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -470,12 +470,12 @@
     {
         $this->threading = false;
 
-        if ($enable) {
-            if ($this->get_capability('THREAD=REFS'))
+        if ($enable && ($caps = $this->get_capability('THREAD'))) {
+            if (in_array('REFS', $caps))
                 $this->threading = 'REFS';
-            else if ($this->get_capability('THREAD=REFERENCES'))
+            else if (in_array('REFERENCES', $caps))
                 $this->threading = 'REFERENCES';
-            else if ($this->get_capability('THREAD=ORDEREDSUBJECT'))
+            else if (in_array('ORDEREDSUBJECT', $caps))
                 $this->threading = 'ORDEREDSUBJECT';
         }
 
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index b5fd968..b11266f 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -764,18 +764,14 @@
 
         // check for supported auth methods
         if ($auth_method == 'CHECK') {
-            if ($this->getCapability('AUTH=DIGEST-MD5')) {
-                $auth_methods[] = 'DIGEST-MD5';
-            }
-            if ($this->getCapability('AUTH=CRAM-MD5') || $this->getCapability('AUTH=CRAM_MD5')) {
-                $auth_methods[] = 'CRAM-MD5';
-            }
-            if ($this->getCapability('AUTH=PLAIN')) {
-                $auth_methods[] = 'PLAIN';
+            if ($auth_caps = $this->getCapability('AUTH')) {
+                $auth_methods = $auth_caps;
             }
             // RFC 2595 (LOGINDISABLED) LOGIN disabled when connection is not secure
-            if (!$this->getCapability('LOGINDISABLED')) {
-                $auth_methods[] = 'LOGIN';
+            if (($key = array_search('LOGIN', $auth_methods)) !== false
+                && $this->getCapability('LOGINDISABLED')
+            ) {
+                unset($auth_methods[$key]);
             }
         }
         else {
@@ -795,8 +791,10 @@
         // Authenticate
         foreach ($auth_methods as $method) {
             switch ($method) {
-            case 'DIGEST-MD5':
+            case 'CRAM_MD5':
+                $method = 'CRAM-MD5';
             case 'CRAM-MD5':
+            case 'DIGEST-MD5':
             case 'PLAIN':
                 $result = $this->authenticate($user, $password, $method);
                 break;
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index d4e250b..abf1122 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -102,14 +102,10 @@
   // set current mailbox and some other vars in client environment
   $OUTPUT->set_env('mailbox', $mbox_name);
   $OUTPUT->set_env('pagesize', $IMAP->page_size);
-  $OUTPUT->set_env('quota', $IMAP->get_capability('quota'));
+  $OUTPUT->set_env('quota', $IMAP->get_capability('QUOTA'));
   $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
   $OUTPUT->set_env('threading', (bool) $IMAP->threading);
-  $OUTPUT->set_env('threads', $IMAP->threading
-	|| $IMAP->get_capability('thread=references')
-        || $IMAP->get_capability('thread=orderedsubject')
-        || $IMAP->get_capability('thread=refs')  
-  );
+  $OUTPUT->set_env('threads', $IMAP->threading || $IMAP->get_capability('THREAD'));
 
   if ($CONFIG['flag_for_deletion'])
     $OUTPUT->set_env('flag_for_deletion', true);
diff --git a/program/steps/settings/edit_folder.inc b/program/steps/settings/edit_folder.inc
index ca07b04..2842b35 100644
--- a/program/steps/settings/edit_folder.inc
+++ b/program/steps/settings/edit_folder.inc
@@ -39,9 +39,7 @@
     $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
     $special   = (strlen($mbox_imap) && in_array($mbox_imap, (array) $RCMAIL->config->get('default_imap_folders')));
     $protected = ($special && $RCMAIL->config->get('protect_default_folders'));
-    $threading_supported = $RCMAIL->imap->get_capability('thread=references')
-        || $RCMAIL->imap->get_capability('thread=orderedsubject')
-        || $RCMAIL->imap->get_capability('thread=refs');
+    $threading_supported = $RCMAIL->imap->get_capability('THREAD');
 
     // Get mailbox stats (messages count, etc.), mailbox name and parent
     if (strlen($mbox)) {
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index daa9faf..fb48e92 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -334,9 +334,7 @@
     }
 
     $RCMAIL->imap_connect();
-    $threading_supported = $RCMAIL->imap->get_capability('thread=references')
-      || $RCMAIL->imap->get_capability('thread=orderedsubject')
-      || $RCMAIL->imap->get_capability('thread=refs');
+    $threading_supported = $RCMAIL->imap->get_capability('THREAD');
 
     if (!isset($no_override['autoexpand_threads']) && $threading_supported) {
       $field_id = 'rcmfd_autoexpand_threads';
@@ -346,8 +344,8 @@
       $select_autoexpand_threads->add(rcube_label('expand_only_unread'), 2);
 
       $blocks['main']['options']['autoexpand_threads'] = array(
-	'title' => html::label($field_id, Q(rcube_label('autoexpand_threads'))),
-	'content' => $select_autoexpand_threads->show($config['autoexpand_threads']),
+        'title' => html::label($field_id, Q(rcube_label('autoexpand_threads'))),
+        'content' => $select_autoexpand_threads->show($config['autoexpand_threads']),
       );
     }
 

--
Gitblit v1.9.1