changeset 16:1866b439e6d3

Slowly cleaning up more php8 Warnings/deprecations
author Charlie Root
date Mon, 06 Oct 2025 10:34:51 -0400
parents 85a746e95663
children dd5ed6ef69c9
files program/lib/Roundcube/html.php program/lib/Roundcube/rcube_imap.php program/lib/Roundcube/rcube_imap_generic.php program/lib/Roundcube/rcube_message_header.php program/steps/mail/func.inc
diffstat 5 files changed, 116 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/program/lib/Roundcube/html.php	Sat Sep 20 12:16:50 2025 -0400
+++ b/program/lib/Roundcube/html.php	Mon Oct 06 10:34:51 2025 -0400
@@ -77,11 +77,11 @@
         }
 
         $inline_tags = array('a','span','img');
-        $suffix = $attrib['nl'] || ($content && $attrib['nl'] !== false && !in_array($tagname, $inline_tags)) ? "\n" : '';
+        $suffix = ($attrib['nl']??null) || ($content && ($attrib['nl']??false) !== false && !in_array($tagname, $inline_tags)) ? "\n" : '';
 
         $tagname = self::$lc_tags ? strtolower($tagname) : $tagname;
         if (isset($content) || in_array($tagname, self::$containers)) {
-            $suffix = $attrib['noclose'] ? $suffix : '</' . $tagname . '>' . $suffix;
+	  $suffix = ($attrib['noclose']??null) ? $suffix : '</' . $tagname . '>' . $suffix;
             unset($attrib['noclose'], $attrib['nl']);
             return '<' . $tagname  . self::attrib_string($attrib, $allowed) . '>' . $content . $suffix;
         }
--- a/program/lib/Roundcube/rcube_imap.php	Sat Sep 20 12:16:50 2025 -0400
+++ b/program/lib/Roundcube/rcube_imap.php	Mon Oct 06 10:34:51 2025 -0400
@@ -663,50 +663,51 @@
         // of all messages in a folder also when search is active and with
         // any skip_deleted setting
 
-        $a_folder_cache = $this->get_cache('messagecount');
-
-        // return cached value
-        if (!$force && is_array($a_folder_cache[$folder]) && isset($a_folder_cache[$folder][$mode])) {
+        if ($this->caching) {
+	  $a_folder_cache = $this->get_cache('messagecount');
+
+	  // return cached value
+	  if (!$force && is_array($a_folder_cache[$folder]) && isset($a_folder_cache[$folder][$mode])) {
             return $a_folder_cache[$folder][$mode];
-        }
-
-        if (!is_array($a_folder_cache[$folder])) {
+	  }
+
+	  if (!is_array($a_folder_cache[$folder])) {
             $a_folder_cache[$folder] = array();
-        }
-
-        if ($mode == 'THREADS') {
+	  }
+	}
+	  if ($mode == 'THREADS') {
             $res   = $this->threads($folder);
             $count = $res->count();
 
             if ($status) {
-                $msg_count = $res->count_messages();
-                $this->set_folder_stats($folder, 'cnt', $msg_count);
-                $this->set_folder_stats($folder, 'maxuid', $msg_count ? $this->id2uid($msg_count, $folder) : 0);
+	      $msg_count = $res->count_messages();
+	      $this->set_folder_stats($folder, 'cnt', $msg_count);
+	      $this->set_folder_stats($folder, 'maxuid', $msg_count ? $this->id2uid($msg_count, $folder) : 0);
             }
-        }
-        // Need connection here
-        else if (!$this->check_connection()) {
+	  }
+	  // Need connection here
+	  else if (!$this->check_connection()) {
             return 0;
-        }
-        // RECENT count is fetched a bit different
-        else if ($mode == 'RECENT') {
+	  }
+	  // RECENT count is fetched a bit different
+	  else if ($mode == 'RECENT') {
             $count = $this->conn->countRecent($folder);
-        }
-        // use SEARCH for message counting
-        else if ($mode != 'EXISTS' && !empty($this->options['skip_deleted'])) {
+	  }
+	  // use SEARCH for message counting
+	  else if ($mode != 'EXISTS' && !empty($this->options['skip_deleted'])) {
             $search_str = "ALL UNDELETED";
             $keys       = array('COUNT');
 
             if ($mode == 'UNSEEN') {
-                $search_str .= " UNSEEN";
+	      $search_str .= " UNSEEN";
             }
             else {
-                if ($this->messages_caching) {
-                    $keys[] = 'ALL';
-                }
-                if ($status) {
-                    $keys[] = 'MAX';
-                }
+	      if ($this->messages_caching) {
+		$keys[] = 'ALL';
+	      }
+	      if ($status) {
+		$keys[] = 'MAX';
+	      }
             }
 
             // @TODO: if $mode == 'ALL' we could try to use cache index here
@@ -717,32 +718,34 @@
             $count = $index->count();
 
             if ($mode == 'ALL') {
-                // Cache index data, will be used in index_direct()
-                $this->icache['undeleted_idx'] = $index;
-
-                if ($status) {
-                    $this->set_folder_stats($folder, 'cnt', $count);
-                    $this->set_folder_stats($folder, 'maxuid', $index->max());
-                }
+	      // Cache index data, will be used in index_direct()
+	      $this->icache['undeleted_idx'] = $index;
+
+	      if ($status) {
+		$this->set_folder_stats($folder, 'cnt', $count);
+		$this->set_folder_stats($folder, 'maxuid', $index->max());
+	      }
             }
-        }
-        else {
+	  }
+	  else {
             if ($mode == 'UNSEEN') {
-                $count = $this->conn->countUnseen($folder);
+	      $count = $this->conn->countUnseen($folder);
             }
             else {
-                $count = $this->conn->countMessages($folder);
-                if ($status && $mode == 'ALL') {
-                    $this->set_folder_stats($folder, 'cnt', $count);
-                    $this->set_folder_stats($folder, 'maxuid', $count ? $this->id2uid($count, $folder) : 0);
-                }
+	      $count = $this->conn->countMessages($folder);
+	      if ($status && $mode == 'ALL') {
+		$this->set_folder_stats($folder, 'cnt', $count);
+		$this->set_folder_stats($folder, 'maxuid', $count ? $this->id2uid($count, $folder) : 0);
+	      }
             }
-        }
-
-        $a_folder_cache[$folder][$mode] = (int)$count;
-
-        // write back to cache
-        $this->update_cache('messagecount', $a_folder_cache);
+	  }
+
+        if ($this->caching) {
+	  $a_folder_cache[$folder][$mode] = (int)$count;
+
+	  // write back to cache
+	  $this->update_cache('messagecount', $a_folder_cache);
+	}
 
         return (int)$count;
     }
@@ -4089,7 +4092,9 @@
     public function update_cache($key, $data)
     {
         if ($cache = $this->get_cache_engine()) {
+	  
             $cache->set($key, $data);
+	    rcube::write_log('mail',"cache " . !(!$cache) . " for " . $key);
         }
     }
 
@@ -4347,7 +4352,7 @@
      */
     protected function set_messagecount($folder, $mode, $increment)
     {
-        if (!is_numeric($increment)) {
+        if (!is_numeric($increment) || !$this->caching) {
             return false;
         }
 
--- a/program/lib/Roundcube/rcube_imap_generic.php	Sat Sep 20 12:16:50 2025 -0400
+++ b/program/lib/Roundcube/rcube_imap_generic.php	Mon Oct 06 10:34:51 2025 -0400
@@ -144,7 +144,9 @@
         $res = 0;
         if ($parts = preg_split('/(\{[0-9]+\}\r\n)/m', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) {
             for ($i=0, $cnt=count($parts); $i<$cnt; $i++) {
-                if (preg_match('/^\{([0-9]+)\}\r\n$/', $parts[$i+1], $matches)) {
+	      if (($parts[$i+1]??null) &&
+		    preg_match('/^\{([0-9]+)\}\r\n$/',
+			       $parts[$i+1], $matches)) {
                     // LITERAL+ support
                     if ($this->prefs['literal+']) {
                         $parts[$i+1] = sprintf("{%d+}\r\n", $matches[1]);
@@ -199,7 +201,7 @@
 
         do {
             if ($this->eof()) {
-                return $line ?: null;
+	      return $line ?: null;
             }
 
             $buffer = fgets($this->fp, $size);
@@ -1506,6 +1508,9 @@
             $rets        = array_intersect($return_opts, $ext_opts);
             $return_opts = array_diff($return_opts, $rets);
         }
+	else {
+	  $ext_opts = $rets = $return_opts = null;
+	}
 
         if (!empty($return_opts) && $this->getCapability('LIST-STATUS')) {
             $lstatus     = true;
@@ -1521,6 +1526,9 @@
                 $rets = array_merge($rets, $opts);
             }
         }
+	else {
+	  $lstatus = $opts = $status_opts = $rets = null;
+	}
 
         if (!empty($rets)) {
             $args[] = 'RETURN (' . implode(' ', $rets) . ')';
@@ -1617,7 +1625,7 @@
         }
 
         // Check internal cache
-        $cache = $this->data['STATUS:'.$mailbox];
+        $cache = ($this->data['STATUS:'.$mailbox]??null);
         if (!empty($cache) && isset($cache['MESSAGES'])) {
             return (int) $cache['MESSAGES'];
         }
@@ -2163,7 +2171,8 @@
             return null;
         }
 
-        if ($uid = $this->data['UID-MAP'][$id]) {
+        if (($map = ( $this->data['UID-MAP'] ?? null) ) &&
+	    ($uid = ( $map[$id] ?? null ) ) ) {
             return $uid;
         }
 
@@ -2428,7 +2437,9 @@
                 }
 
                 // Tokenize response and assign to object properties
-                while (list($name, $value) = $this->tokenizeResponse($line, 2)) {
+                while ($token = $this->tokenizeResponse($line, 2)) {
+		  list($name, $value) = $token;
+
                     if ($name == 'UID') {
                         $result[$id]->uid = intval($value);
                     }
@@ -2473,7 +2484,7 @@
 
                         if ($name == 'HEADER.FIELDS') {
                             // skip ']' after headers list
-                            $this->tokenizeResponse($line, 1);
+			  $this->tokenizeResponse($line, 1);
                             $headers = $this->tokenizeResponse($line, 1);
                         }
                         else if (strlen($name)) {
@@ -2483,6 +2494,7 @@
                             $result[$id]->body = $value;
                         }
                     }
+
                 }
 
                 // create array with header field:data
--- a/program/lib/Roundcube/rcube_message_header.php	Sat Sep 20 12:16:50 2025 -0400
+++ b/program/lib/Roundcube/rcube_message_header.php	Mon Oct 06 10:34:51 2025 -0400
@@ -23,8 +23,11 @@
  * @package    Framework
  * @subpackage Storage
  * @author     Aleksander Machniak <alec@alec.pl>
+ * HST added the abstraction level below because of plugins/thunderbird_labels
+ * use of a new property 'list_flags'
  */
-class rcube_message_header
+
+abstract class r_m_h_base
 {
     /**
      * Message sequence number
@@ -187,6 +190,27 @@
      */
     public $flags = array();
 
+    /**
+     * Threaded message property, HST added
+     *
+     * @var int
+     */
+    public $parent_uid;
+
+    /**
+     * Threaded message property, HST added
+     *
+     * @var int
+     */
+    public $depth;
+
+    /**
+     * Threaded message property, HST added
+     *
+     * @var array
+     */
+    public $has_children;
+
     // map header to rcube_message_header object property
     private $obj_headers = array(
         'date'      => 'date',
@@ -272,6 +296,15 @@
     }
 }
 
+if (in_array('thunderbird_labels',
+	     (rcube::get_instance()->config->get('plugins'))))
+{
+  class rcube_message_header extends r_m_h_base {
+    public $list_flags = array();
+  }
+} else {
+  class rcube_message_header extends r_m_h_base { }
+ }
 
 /**
  * Class for sorting an array of rcube_message_header objects in a predetermined order.
--- a/program/steps/mail/func.inc	Sat Sep 20 12:16:50 2025 -0400
+++ b/program/steps/mail/func.inc	Mon Oct 06 10:34:51 2025 -0400
@@ -531,7 +531,7 @@
                 $cont = rcube::Q($last_folder_name);
             }
             else
-                $cont = rcube::Q($header->$col);
+                $cont = rcube::Q($header->$col??null);
 
             $a_msg_cols[$col] = $cont;
         }
@@ -541,15 +541,15 @@
             $a_msg_flags['depth'] = $header->depth;
         else if ($header->has_children)
             $roots[] = $header->uid;
-        if ($header->parent_uid)
+        if ($header->parent_uid??null)
             $a_msg_flags['parent_uid'] = $header->parent_uid;
         if ($header->has_children)
             $a_msg_flags['has_children'] = $header->has_children;
-        if ($header->unread_children)
+        if ($header->unread_children??null)
             $a_msg_flags['unread_children'] = $header->unread_children;
-        if ($header->flagged_children)
+        if ($header->flagged_children??null)
             $a_msg_flags['flagged_children'] = $header->flagged_children;
-        if ($header->others['list-post'])
+        if ($header->others['list-post']??null)
             $a_msg_flags['ml'] = 1;
         if ($header->priority)
             $a_msg_flags['prio'] = (int) $header->priority;
@@ -1654,6 +1654,7 @@
     $c   = count($a_parts);
     $j   = 0;
     $out = '';
+    $moreadrs = null;
     $allvalues  = array();
     $show_email = $RCMAIL->config->get('message_show_email');