From b59b72cc3028cc0514e951f135d8bfe7efcaaa6f Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 26 Feb 2015 12:04:03 -0500
Subject: [PATCH] Fix "Non-static method PEAR::isError() should not be called statically" errors (#1490281)

---
 program/lib/Roundcube/rcube.php                          |   15 +++--
 program/lib/Roundcube/rcube_smtp.php                     |   14 ++--
 CHANGELOG                                                |    1 
 plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php |    5 +
 plugins/password/drivers/ldap.php                        |    6 +-
 plugins/password/drivers/vpopmaild.php                   |    9 +-
 plugins/managesieve/lib/Roundcube/rcube_sieve.php        |   93 +++++++++++++++++++++---------
 program/steps/mail/sendmail.inc                          |    7 +-
 plugins/password/drivers/poppassd.php                    |    2 
 9 files changed, 99 insertions(+), 53 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 72ccf70..4855f2c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,6 +17,7 @@
 - Fix cursor position on reply below the quote in HTML mode (#1490263)
 - Fix so "over quota" errors are displayed also in message compose page
 - Fix duplicate entries supression in autocomplete result (#1490290)
+- Fix "Non-static method PEAR::isError() should not be called statically" errors (#1490281)
 
 RELEASE 1.1.0
 -------------
diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php
index 389c850..59a7bc1 100644
--- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php
+++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php
@@ -68,7 +68,9 @@
             $this->sieve->setDebug(true, array($this, 'debug_handler'));
         }
 
-        if (PEAR::isError($this->sieve->connect($host, $port, $options, $usetls))) {
+        $result = $this->sieve->connect($host, $port, $options, $usetls);
+
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_CONNECTION);
         }
 
@@ -78,9 +80,9 @@
             $password = $auth_pw;
         }
 
-        if (PEAR::isError($this->sieve->login($username, $password,
-            $auth_type ? strtoupper($auth_type) : null, $authz))
-        ) {
+        $result = $this->sieve->login($username, $password, $auth_type ? strtoupper($auth_type) : null, $authz);
+
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_LOGIN);
         }
 
@@ -115,22 +117,28 @@
      */
     public function save($name = null)
     {
-        if (!$this->sieve)
+        if (!$this->sieve) {
             return $this->_set_error(self::ERROR_INTERNAL);
+        }
 
-        if (!$this->script)
+        if (!$this->script) {
             return $this->_set_error(self::ERROR_INTERNAL);
+        }
 
-        if (!$name)
+        if (!$name) {
             $name = $this->current;
+        }
 
         $script = $this->script->as_text();
 
-        if (!$script)
+        if (!$script) {
             $script = '/* empty script */';
+        }
 
-        if (PEAR::isError($this->sieve->installScript($name, $script)))
+        $result = $this->sieve->installScript($name, $script);
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_INSTALL);
+        }
 
         return true;
     }
@@ -140,14 +148,19 @@
      */
     public function save_script($name, $content = null)
     {
-        if (!$this->sieve)
+        if (!$this->sieve) {
             return $this->_set_error(self::ERROR_INTERNAL);
+        }
 
-        if (!$content)
+        if (!$content) {
             $content = '/* empty script */';
+        }
 
-        if (PEAR::isError($this->sieve->installScript($name, $content)))
+        $result = $this->sieve->installScript($name, $content);
+
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_INSTALL);
+        }
 
         return true;
     }
@@ -157,14 +170,19 @@
      */
     public function activate($name = null)
     {
-        if (!$this->sieve)
+        if (!$this->sieve) {
             return $this->_set_error(self::ERROR_INTERNAL);
+        }
 
-        if (!$name)
+        if (!$name) {
             $name = $this->current;
+        }
 
-        if (PEAR::isError($this->sieve->setActive($name)))
+        $result = $this->sieve->setActive($name);
+
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_ACTIVATE);
+        }
 
         return true;
     }
@@ -174,11 +192,15 @@
      */
     public function deactivate()
     {
-        if (!$this->sieve)
+        if (!$this->sieve) {
             return $this->_set_error(self::ERROR_INTERNAL);
+        }
 
-        if (PEAR::isError($this->sieve->setActive('')))
+        $result = $this->sieve->setActive('');
+
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_DEACTIVATE);
+        }
 
         return true;
     }
@@ -188,22 +210,32 @@
      */
     public function remove($name = null)
     {
-        if (!$this->sieve)
+        if (!$this->sieve) {
             return $this->_set_error(self::ERROR_INTERNAL);
+        }
 
-        if (!$name)
+        if (!$name) {
             $name = $this->current;
+        }
 
         // script must be deactivated first
-        if ($name == $this->sieve->getActive())
-            if (PEAR::isError($this->sieve->setActive('')))
+        if ($name == $this->sieve->getActive()) {
+            $result = $this->sieve->setActive('');
+
+            if (is_a($result, 'PEAR_Error')) {
                 return $this->_set_error(self::ERROR_DELETE);
+            }
+        }
 
-        if (PEAR::isError($this->sieve->removeScript($name)))
+        $result = $this->sieve->removeScript($name);
+
+        if (is_a($result, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_DELETE);
+        }
 
-        if ($name == $this->current)
+        if ($name == $this->current) {
             $this->current = null;
+        }
 
         return true;
     }
@@ -221,7 +253,7 @@
 
         $ext = $this->sieve->getExtensions();
 
-        if (PEAR::isError($ext)) {
+        if (is_a($ext, 'PEAR_Error')) {
             return array();
         }
 
@@ -250,8 +282,9 @@
 
             $list = $this->sieve->listScripts();
 
-            if (PEAR::isError($list))
+            if (is_a($list, 'PEAR_Error')) {
                 return $this->_set_error(self::ERROR_OTHER);
+            }
 
             $this->list = $list;
         }
@@ -283,8 +316,9 @@
 
         $script = $this->sieve->getScript($name);
 
-        if (PEAR::isError($script))
+        if (is_a($script, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_OTHER);
+        }
 
         // try to parse from Roundcube format
         $this->script = $this->_parse($script);
@@ -349,8 +383,9 @@
 
         $content = $this->sieve->getScript($name);
 
-        if (PEAR::isError($content))
+        if (is_a($content, 'PEAR_Error')) {
             return $this->_set_error(self::ERROR_OTHER);
+        }
 
         return $content;
     }
@@ -366,10 +401,12 @@
         if ($copy) {
             $content = $this->sieve->getScript($copy);
 
-            if (PEAR::isError($content))
+            if (is_a($content, 'PEAR_Error')) {
                 return $this->_set_error(self::ERROR_OTHER);
+            }
         }
 
+
         return $this->save_script($name, $content);
     }
 
diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
index 69ae4b8..98c4c95 100644
--- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
+++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
@@ -390,10 +390,11 @@
             }
             else if ($action == 'setget') {
                 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true);
-                $script = $this->sieve->get_script($script_name);
+                $script      = $this->sieve->get_script($script_name);
 
-                if (PEAR::isError($script))
+                if (is_a($script, 'PEAR_Error')) {
                     exit;
+                }
 
                 $browser = new rcube_browser;
 
diff --git a/plugins/password/drivers/ldap.php b/plugins/password/drivers/ldap.php
index c18ff0f..a11c38d 100644
--- a/plugins/password/drivers/ldap.php
+++ b/plugins/password/drivers/ldap.php
@@ -75,7 +75,7 @@
         $ldap = Net_LDAP2::connect($ldapConfig);
 
         // Checking for connection error
-        if (PEAR::isError($ldap)) {
+        if (is_a($ldap, 'PEAR_Error')) {
             return PASSWORD_CONNECT_ERROR;
         }
 
@@ -176,7 +176,7 @@
 
         $ldap = Net_LDAP2::connect($ldapConfig);
 
-        if (PEAR::isError($ldap)) {
+        if (is_a($ldap, 'PEAR_Error')) {
             return '';
         }
 
@@ -189,7 +189,7 @@
 
         $result = $ldap->search($base, $filter, $options);
         $ldap->done();
-        if (PEAR::isError($result) || ($result->count() != 1)) {
+        if (is_a($result, 'PEAR_Error') || ($result->count() != 1)) {
             return '';
         }
 
diff --git a/plugins/password/drivers/poppassd.php b/plugins/password/drivers/poppassd.php
index 8ddbef5..7a28210 100644
--- a/plugins/password/drivers/poppassd.php
+++ b/plugins/password/drivers/poppassd.php
@@ -42,7 +42,7 @@
         $poppassd = new Net_Socket();
 
         $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null);
-        if (PEAR::isError($result)) {
+        if (is_a($result, 'PEAR_Error')) {
             return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage());
         }
         else {
diff --git a/plugins/password/drivers/vpopmaild.php b/plugins/password/drivers/vpopmaild.php
index a7644fc..90fce02 100644
--- a/plugins/password/drivers/vpopmaild.php
+++ b/plugins/password/drivers/vpopmaild.php
@@ -28,12 +28,13 @@
 {
     function save($curpass, $passwd)
     {
-        $rcmail = rcmail::get_instance();
-    //    include('Net/Socket.php');
+        $rcmail    = rcmail::get_instance();
         $vpopmaild = new Net_Socket();
+        $host      = $rcmail->config->get('password_vpopmaild_host');
+        $port      = $rcmail->config->get('password_vpopmaild_port');
 
-        if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'),
-            $rcmail->config->get('password_vpopmaild_port'), null))) {
+        $result = $vpopmaild->connect($hostname, $port, null);
+        if (is_a($result, 'PEAR_Error')) {
             return PASSWORD_CONNECT_ERROR;
         }
 
diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php
index 3aca888..20f509e 100644
--- a/program/lib/Roundcube/rcube.php
+++ b/program/lib/Roundcube/rcube.php
@@ -1681,15 +1681,18 @@
 
             if ($message->getParam('delay_file_io')) {
                 // use common temp dir
-                $temp_dir = $this->config->get('temp_dir');
-                $body_file = tempnam($temp_dir, 'rcmMsg');
-                if (PEAR::isError($mime_result = $message->saveMessageBody($body_file))) {
+                $temp_dir    = $this->config->get('temp_dir');
+                $body_file   = tempnam($temp_dir, 'rcmMsg');
+                $mime_result = $message->saveMessageBody($body_file);
+
+                if (is_a($mime_result, 'PEAR_Error')) {
                     self::raise_error(array('code' => 650, 'type' => 'php',
                         'file' => __FILE__, 'line' => __LINE__,
                         'message' => "Could not create message: ".$mime_result->getMessage()),
-                        TRUE, FALSE);
+                        true, false);
                     return false;
                 }
+
                 $msg_body = fopen($body_file, 'r');
             }
             else {
@@ -1732,11 +1735,11 @@
 
             $msg_body = $message->get();
 
-            if (PEAR::isError($msg_body)) {
+            if (is_a($msg_body, 'PEAR_Error')) {
                 self::raise_error(array('code' => 650, 'type' => 'php',
                     'file' => __FILE__, 'line' => __LINE__,
                     'message' => "Could not create message: ".$msg_body->getMessage()),
-                    TRUE, FALSE);
+                    true, false);
             }
             else {
                 $delim   = $this->config->header_delimiter();
diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php
index b37b444..0322a0d 100644
--- a/program/lib/Roundcube/rcube_smtp.php
+++ b/program/lib/Roundcube/rcube_smtp.php
@@ -126,7 +126,7 @@
         // try to connect to server and exit on failure
         $result = $this->conn->connect($CONFIG['smtp_timeout']);
 
-        if (PEAR::isError($result)) {
+        if (is_a($result, 'PEAR_Error')) {
             $this->response[] = "Connection failed: ".$result->getMessage();
             $this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $this->conn->_code));
             $this->conn  = null;
@@ -159,7 +159,7 @@
 
             $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz);
 
-            if (PEAR::isError($result)) {
+            if (is_a($result, 'PEAR_Error')) {
                 $this->error = array('label' => 'smtpautherror', 'vars' => array('code' => $this->conn->_code));
                 $this->response[] .= 'Authentication failure: ' . $result->getMessage() . ' (Code: ' . $result->getCode() . ')';
                 $this->reset();
@@ -240,7 +240,8 @@
         }
 
         // set From: address
-        if (PEAR::isError($this->conn->mailFrom($from, $from_params))) {
+        $result = $this->conn->mailFrom($from, $from_params);
+        if (is_a($result, 'PEAR_Error')) {
             $err = $this->conn->getResponse();
             $this->error = array('label' => 'smtpfromerror', 'vars' => array(
                 'from' => $from, 'code' => $err[0], 'msg' => $err[1]));
@@ -252,7 +253,7 @@
 
         // prepare list of recipients
         $recipients = $this->_parse_rfc822($recipients);
-        if (PEAR::isError($recipients)) {
+        if (is_a($recipients, 'PEAR_Error')) {
             $this->error = array('label' => 'smtprecipientserror');
             $this->reset();
             return false;
@@ -260,7 +261,8 @@
 
         // set mail recipients
         foreach ($recipients as $recipient) {
-            if (PEAR::isError($this->conn->rcptTo($recipient, $recipient_params))) {
+            $result = $this->conn->rcptTo($recipient, $recipient_params);
+            if (is_a($result, 'PEAR_Error')) {
                 $err = $this->conn->getResponse();
                 $this->error = array('label' => 'smtptoerror', 'vars' => array(
                     'to' => $recipient, 'code' => $err[0], 'msg' => $err[1]));
@@ -289,7 +291,7 @@
 
         // Send the message's headers and the body as SMTP data.
         $result = $this->conn->data($data, $text_headers);
-        if (PEAR::isError($result)) {
+        if (is_a($result, 'PEAR_Error')) {
             $err = $this->conn->getResponse();
             if (!in_array($err[0], array(354, 250, 221))) {
                 $msg = sprintf('[%d] %s', $err[0], $err[1]);
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 08b085c..9e674f7 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -601,8 +601,9 @@
             else {
                 $temp_dir      = $RCMAIL->config->get('temp_dir');
                 $mailbody_file = tempnam($temp_dir, 'rcmMsg');
+                $msg           = $MAIL_MIME->saveMessageBody($mailbody_file);
 
-                if (!PEAR::isError($msg = $MAIL_MIME->saveMessageBody($mailbody_file))) {
+                if (!is_a($msg, 'PEAR_Error')) {
                     $msg = $mailbody_file;
                 }
             }
@@ -612,7 +613,7 @@
             $headers = '';
         }
 
-        if (PEAR::isError($msg)) {
+        if (is_a($msg, 'PEAR_Error')) {
             rcube::raise_error(array('code' => 650, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Could not create message: ".$msg->getMessage()),
@@ -800,7 +801,7 @@
                 if (!in_array($image_name, $included_images)) {
                     // add the image to the MIME message
                     $res = $mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name);
-                    if (PEAR::isError($res)) {
+                    if (is_a($res, 'PEAR_Error')) {
                         $RCMAIL->output->show_message("emoticonerror", 'error');
                         continue;
                     }

--
Gitblit v1.9.1