From 890eae675828e4d7e6ecbffc613f1eace87717fa Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 09 Feb 2011 06:33:49 -0500
Subject: [PATCH] - Use IMAP's ID extension (RFC2971) to print more info into debug log 

---
 CHANGELOG                              |    1 +
 program/include/rcube_imap.php         |   11 ++++++++++-
 program/include/rcube_imap_generic.php |   43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 9a008e9..ccc7b18 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Use IMAP's ID extension (RFC2971) to print more info into debug log
 - Security: add optional referer check to prevent CSRF in GET requests
 - Fix email_dns_check setting not used for identities/contacts (#1487740)
 - Fix ICANN example addresses doesn't validate (#1487742)
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index a4e67e1..f5a9368 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -148,9 +148,18 @@
 
         $this->options['port'] = $port;
 
-        if ($this->options['debug'])
+        if ($this->options['debug']) {
             $this->conn->setDebug(true, array($this, 'debug_handler'));
 
+            $this->options['ident'] = array(
+                'name' => 'Roundcube Webmail',
+                'version' => RCMAIL_VERSION,
+                'php' => PHP_VERSION,
+                'os' => PHP_OS,
+                'command' => $_SERVER['REQUEST_URI'],
+            );
+        }
+
         $attempt = 0;
         do {
             $data = rcmail::get_instance()->plugins->exec_hook('imap_connect',
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 41f704d..dace4ef 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -759,6 +759,11 @@
             }
         }
 
+        // Send ID info
+        if (!empty($this->prefs['ident']) && $this->getCapability('ID')) {
+            $this->id($this->prefs['ident']);
+        }
+
         $auth_methods = array();
         $result       = null;
 
@@ -1157,6 +1162,44 @@
         return false;
     }
 
+    /**
+     * Executes ID command (RFC2971)
+     *
+     * @param array $items Client identification information key/value hash
+     *
+     * @return array Server identification information key/value hash
+     * @access public
+     * @since 0.6
+     */
+    function id($items=array())
+    {
+        if (is_array($items) && !empty($items)) {
+            foreach ($items as $key => $value) {
+                $args[] = $this->escape($key);
+                $args[] = $this->escape($value);
+            }
+        }
+
+        list($code, $response) = $this->execute('ID', array(
+            !empty($args) ? '(' . implode(' ', (array) $args) . ')' : $this->escape(null)
+        ));
+
+
+        if ($code == self::ERROR_OK && preg_match('/\* ID /i', $response)) {
+            $response = substr($response, 5); // remove prefix "* ID "
+            $items    = $this->tokenizeResponse($response);
+            $result   = null;
+
+            for ($i=0, $len=count($items); $i<$len; $i += 2) {
+                $result[$items[$i]] = $items[$i+1];
+            }
+
+            return $result;
+        }
+
+        return false;
+    }
+
     function sort($mailbox, $field, $add='', $is_uid=FALSE, $encoding = 'US-ASCII')
     {
         $field = strtoupper($field);

--
Gitblit v1.9.1