From 9e4246d9571481fe7b80227b1e23dc013771c5af Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 16 Nov 2014 08:04:53 -0500
Subject: [PATCH] Code improvements and fixes (mostly unused variables and methods)

---
 program/lib/Roundcube/rcube_spellcheck_atd.php |    2 
 program/lib/Roundcube/rcube_vcard.php          |    3 +
 tests/Framework/BaseReplacer.php               |   28 ++++++++++++++
 program/include/rcmail_install.php             |    2 
 program/lib/Roundcube/rcube_db_oracle.php      |    4 +-
 program/lib/Roundcube/rcube_message.php        |    6 ---
 program/lib/Roundcube/rcube_contacts.php       |    4 +-
 program/lib/Roundcube/bootstrap.php            |    4 +-
 program/lib/Roundcube/rcube_ldap.php           |   18 +--------
 program/lib/Roundcube/rcube_content_filter.php |    2 
 program/lib/Roundcube/rcube_imap_generic.php   |    4 +-
 program/lib/Roundcube/rcube_charset.php        |    1 
 program/lib/Roundcube/rcube_imap_search.php    |    2 -
 program/lib/Roundcube/rcube_base_replacer.php  |    9 ++--
 14 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php
index 7877b8e..96e0afb 100644
--- a/program/include/rcmail_install.php
+++ b/program/include/rcmail_install.php
@@ -290,7 +290,7 @@
     $out = $seen = array();
 
     // iterate over the current configuration
-    foreach ($this->config as $prop => $value) {
+    foreach (array_keys($this->config) as $prop) {
       if ($replacement = $this->replaced_config[$prop]) {
         $out['replaced'][] = array('prop' => $prop, 'replacement' => $replacement);
         $seen[$replacement] = true;
diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php
index fe9c389..af87beb 100644
--- a/program/lib/Roundcube/bootstrap.php
+++ b/program/lib/Roundcube/bootstrap.php
@@ -408,7 +408,7 @@
 
 if (!function_exists('idn_to_utf8'))
 {
-    function idn_to_utf8($domain, $flags=null)
+    function idn_to_utf8($domain)
     {
         static $idn, $loaded;
 
@@ -430,7 +430,7 @@
 
 if (!function_exists('idn_to_ascii'))
 {
-    function idn_to_ascii($domain, $flags=null)
+    function idn_to_ascii($domain)
     {
         static $idn, $loaded;
 
diff --git a/program/lib/Roundcube/rcube_base_replacer.php b/program/lib/Roundcube/rcube_base_replacer.php
index fa67647..a306086 100644
--- a/program/lib/Roundcube/rcube_base_replacer.php
+++ b/program/lib/Roundcube/rcube_base_replacer.php
@@ -61,9 +61,6 @@
      */
     public static function absolute_url($path, $base_url)
     {
-        $host_url = $base_url;
-        $abs_path = $path;
-
         // check if path is an absolute URL
         if (preg_match('/^[fhtps]+:\/\//', $path)) {
             return $path;
@@ -73,6 +70,9 @@
         if (strpos($path, 'cid:') === 0) {
             return $path;
         }
+
+        $host_url = $base_url;
+        $abs_path = $path;
 
         // cut base_url to the last directory
         if (strrpos($base_url, '/') > 7) {
@@ -89,7 +89,8 @@
             $path = preg_replace('/^\.\//', '', $path);
 
             if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) {
-                foreach ($matches as $a_match) {
+                $cnt = count($matches);
+                while ($cnt--) {
                     if ($pos = strrpos($base_url, '/')) {
                         $base_url = substr($base_url, 0, $pos);
                     }
diff --git a/program/lib/Roundcube/rcube_charset.php b/program/lib/Roundcube/rcube_charset.php
index 3e2dac1..c15c3ad 100644
--- a/program/lib/Roundcube/rcube_charset.php
+++ b/program/lib/Roundcube/rcube_charset.php
@@ -175,7 +175,6 @@
         static $iconv_options   = null;
         static $mbstring_list   = null;
         static $mbstring_sch    = null;
-        static $conv            = null;
 
         $to   = empty($to) ? RCUBE_CHARSET : $to;
         $from = self::parse_charset($from);
diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php
index bd3a3f8..6ac9fd5 100644
--- a/program/lib/Roundcube/rcube_contacts.php
+++ b/program/lib/Roundcube/rcube_contacts.php
@@ -909,7 +909,7 @@
             $name, $gid, $this->user_id
         );
 
-        return $this->db->affected_rows() ? $name : false;
+        return $this->db->affected_rows($sql_result) ? $name : false;
     }
 
 
@@ -983,7 +983,7 @@
             $group_id
         );
 
-        return $this->db->affected_rows();
+        return $this->db->affected_rows($sql_result);
     }
 
 
diff --git a/program/lib/Roundcube/rcube_content_filter.php b/program/lib/Roundcube/rcube_content_filter.php
index ae6617d..7d3d029 100644
--- a/program/lib/Roundcube/rcube_content_filter.php
+++ b/program/lib/Roundcube/rcube_content_filter.php
@@ -33,7 +33,7 @@
         return true;
     }
 
-    function filter($in, $out, &$consumed, $closing)
+    function filter($in, $out, &$consumed)
     {
         while ($bucket = stream_bucket_make_writeable($in)) {
             $this->buffer .= $bucket->data;
diff --git a/program/lib/Roundcube/rcube_db_oracle.php b/program/lib/Roundcube/rcube_db_oracle.php
index 362beb0..4537464 100644
--- a/program/lib/Roundcube/rcube_db_oracle.php
+++ b/program/lib/Roundcube/rcube_db_oracle.php
@@ -171,7 +171,7 @@
         $mode   = $this->in_transaction ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS;
 
         if ($result) {
-            foreach ($args as $param => $arg) {
+            foreach (array_keys($args) as $param) {
                 oci_bind_by_name($result, $param, $args[$param], -1, SQLT_LNG);
             }
         }
@@ -587,7 +587,7 @@
 
         $this->debug('ROLLBACK TRANSACTION');
 
-        if ($result = @oci_rollback($this->dbh)) {
+        if (@oci_rollback($this->dbh)) {
             $this->in_transaction = false;
         }
         else {
diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php
index d78b526..450dcdc 100644
--- a/program/lib/Roundcube/rcube_imap_generic.php
+++ b/program/lib/Roundcube/rcube_imap_generic.php
@@ -1108,7 +1108,8 @@
             // folder name with spaces. Let's try to handle this situation
             if (!is_array($items) && ($pos = strpos($response, '(')) !== false) {
                 $response = substr($response, $pos);
-                $items = $this->tokenizeResponse($response, 1);
+                $items    = $this->tokenizeResponse($response, 1);
+
                 if (!is_array($items)) {
                     return $result;
                 }
@@ -1704,7 +1705,6 @@
         $encoding  = $encoding ? trim($encoding) : 'US-ASCII';
         $algorithm = $algorithm ? trim($algorithm) : 'REFERENCES';
         $criteria  = $criteria ? 'ALL '.trim($criteria) : 'ALL';
-        $data      = '';
 
         list($code, $response) = $this->execute($return_uid ? 'UID THREAD' : 'THREAD',
             array($algorithm, $encoding, $criteria));
diff --git a/program/lib/Roundcube/rcube_imap_search.php b/program/lib/Roundcube/rcube_imap_search.php
index 365d78f..eac64b0 100644
--- a/program/lib/Roundcube/rcube_imap_search.php
+++ b/program/lib/Roundcube/rcube_imap_search.php
@@ -124,9 +124,7 @@
     private $charset;
     private $sort_field;
     private $threading;
-    private $searchset;
     private $result;
-    private $pagesize = 100;
 
     public function __construct($folder, $str, $charset = null, $sort_field = null, $threading=false)
     {
diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index 6805c49..9d7e6b8 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -64,7 +64,6 @@
 
     private $base_dn        = '';
     private $groups_base_dn = '';
-    private $group_url;
     private $group_data;
     private $group_search_cache;
     private $cache;
@@ -775,7 +774,7 @@
 
             // get all entries of this page and post-filter those that really match the query
             $search = mb_strtolower($value);
-            foreach ($ldap_data as $i => $entry) {
+            foreach ($ldap_data as $entry) {
                 $rec = $this->_ldap2result($entry);
                 foreach ($fields as $f) {
                     foreach ((array)$rec[$f] as $val) {
@@ -1531,7 +1530,6 @@
         return $ldap_data;
     }
 
-
     /**
      * Returns unified attribute name (resolving aliases)
      */
@@ -1563,17 +1561,6 @@
     }
 
     /**
-     * Prints debug info to the log
-     */
-    private function _debug($str)
-    {
-        if ($this->debug) {
-            rcube::write_log('ldap', $str);
-        }
-    }
-
-
-    /**
      * Activate/deactivate debug mode
      *
      * @param boolean $dbg True if LDAP commands should be logged
@@ -1586,7 +1573,6 @@
             $this->ldap->config_set('debug', $dbg);
         }
     }
-
 
     /**
      * Setter for the current group
@@ -1990,7 +1976,7 @@
         $filter = strtr("(|(member=$contact_dn)(uniqueMember=$contact_dn)$add_filter)", array('\\' => '\\\\'));
 
         $ldap_data = $this->ldap->search($base_dn, $filter, 'sub', array('dn', $name_attr));
-        if ($res === false) {
+        if ($ldap_data === false) {
             return array();
         }
 
diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php
index 169d00c..20329a7 100644
--- a/program/lib/Roundcube/rcube_message.php
+++ b/program/lib/Roundcube/rcube_message.php
@@ -550,12 +550,6 @@
         else if ($mimetype == 'multipart/alternative'
             && is_array($structure->parts) && count($structure->parts) > 1
         ) {
-            $plain_part   = null;
-            $html_part    = null;
-            $print_part   = null;
-            $related_part = null;
-            $attach_part  = null;
-
             // get html/plaintext parts, other add to attachments list
             foreach ($structure->parts as $p => $sub_part) {
                 $sub_mimetype = $sub_part->mimetype;
diff --git a/program/lib/Roundcube/rcube_spellcheck_atd.php b/program/lib/Roundcube/rcube_spellcheck_atd.php
index 9f073f5..917ec08 100644
--- a/program/lib/Roundcube/rcube_spellcheck_atd.php
+++ b/program/lib/Roundcube/rcube_spellcheck_atd.php
@@ -127,7 +127,7 @@
             $result = new SimpleXMLElement($response);
         }
         catch (Exception $e) {
-            $thid->error = "Unexpected response from server: " . $store;
+            $this->error = "Unexpected response from server: " . $response;
             return array();
         }
 
diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php
index 96add11..7f6b118 100644
--- a/program/lib/Roundcube/rcube_vcard.php
+++ b/program/lib/Roundcube/rcube_vcard.php
@@ -414,9 +414,10 @@
      * Find index with the '$type' attribute
      *
      * @param string Field name
+     *
      * @return int Field index having $type set
      */
-    private function get_type_index($field, $type = 'pref')
+    private function get_type_index($field)
     {
         $result = 0;
         if ($this->raw[$field]) {
diff --git a/tests/Framework/BaseReplacer.php b/tests/Framework/BaseReplacer.php
index 44a9604..2255e9a 100644
--- a/tests/Framework/BaseReplacer.php
+++ b/tests/Framework/BaseReplacer.php
@@ -31,4 +31,32 @@
 
         $this->assertSame('<A href="http://shouldbethislink.com">Test URL</A>', $response);
     }
+
+    /**
+     * Data for absolute_url() test
+     */
+    function data_absolute_url()
+    {
+        return array(
+            array('', 'http://test', 'http://test/'),
+            array('http://test', 'http://anything', 'http://test'),
+            array('cid:test', 'http://anything', 'cid:test'),
+            array('/test', 'http://test', 'http://test/test'),
+            array('./test', 'http://test', 'http://test/test'),
+            array('../test1', 'http://test/test2', 'http://test1'),
+            array('../test1', 'http://test/test2/', 'http://test/test1'),
+        );
+    }
+
+    /**
+     * Test absolute_url()
+     * @dataProvider data_absolute_url
+     */
+    function test_absolute_url($path, $base, $expected)
+    {
+        $replacer = new rcube_base_replacer('test');
+        $result   = $replacer->absolute_url($path, $base);
+
+        $this->assertSame($expected, $result);
+    }
 }

--
Gitblit v1.9.1