changeset 22:303b85d5b561

More cleaning up php8 Warnings/deprecations
author Charlie Root
date Wed, 15 Oct 2025 14:06:27 -0400
parents 73124dd49283
children 929c05ba3b2f
files program/include/rcmail.php program/include/rcmail_output_html.php program/lib/Roundcube/html.php program/lib/Roundcube/rcube_config.php program/lib/Roundcube/rcube_imap.php program/lib/Roundcube/rcube_imap_generic.php program/lib/Roundcube/rcube_message.php program/lib/Roundcube/rcube_message_header.php program/lib/Roundcube/rcube_message_part.php program/lib/Roundcube/rcube_result_index.php program/lib/Roundcube/rcube_result_set.php program/lib/Roundcube/rcube_text2html.php program/lib/Roundcube/rcube_utils.php program/lib/Roundcube/rcube_vcard.php program/lib/Roundcube/rcube_washtml.php program/steps/mail/func.inc program/steps/mail/search.inc
diffstat 17 files changed, 98 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/program/include/rcmail.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/include/rcmail.php	Wed Oct 15 14:06:27 2025 -0400
@@ -105,7 +105,7 @@
         $this->session_init();
 
         // create user object
-        $this->set_user(new rcube_user($_SESSION['user_id']));
+        $this->set_user(new rcube_user($_SESSION['user_id']??null));
 
         // set task and action properties
         $this->set_task(rcube_utils::get_input_value('_task', rcube_utils::INPUT_GPC));
@@ -116,7 +116,7 @@
             // we reset list page when switching to another task
             // but only to the main task interface - empty action (#1489076, #1490116)
             // this will prevent from unintentional page reset on cross-task requests
-            if ($this->session && $_SESSION['task'] != $this->task && empty($this->action)) {
+	  if ($this->session && ($_SESSION['task']??null) != $this->task && empty($this->action)) {
                 $this->session->remove('page');
 
                 // set current task to session
@@ -483,7 +483,7 @@
         parent::session_init();
 
         // set initial session vars
-        if (!$_SESSION['user_id']) {
+        if (empty($_SESSION['user_id'])) {
             $_SESSION['temp'] = true;
         }
 
@@ -968,9 +968,8 @@
     private function fix_namespace_settings($user)
     {
         $prefix     = $this->storage->get_namespace('prefix');
-        $prefix_len = strlen($prefix);
 
-        if (!$prefix_len) {
+        if (empty($prefix)) {
             return;
         }
 
--- a/program/include/rcmail_output_html.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/include/rcmail_output_html.php	Wed Oct 15 14:06:27 2025 -0400
@@ -1978,7 +1978,7 @@
         $out .= $input_url->show();
         $out .= $table->show();
 
-        if ($hide_host) {
+        if (isset($hide_host)) {
             $out .= $input_host->show();
         }
 
--- a/program/lib/Roundcube/html.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/html.php	Wed Oct 15 14:06:27 2025 -0400
@@ -752,7 +752,7 @@
         $cell->content = $cont;
 
 	// make sure row object exists (#1489094)
-        if (!$this->rows[$this->rowindex]) {
+        if (empty($this->rows[$this->rowindex])) {
             $this->rows[$this->rowindex] = new stdClass;
         }
 
@@ -895,7 +895,7 @@
             }
 
             if ($r < $this->rowindex || count($row->cells)) {
-                $tbody .= self::tag($this->_row_tagname(), $row->attrib, $rowcontent, parent::$common_attrib);
+                $tbody .= self::tag($this->_row_tagname(), $row->attrib??null, $rowcontent, parent::$common_attrib);
             }
         }
 
--- a/program/lib/Roundcube/rcube_config.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_config.php	Wed Oct 15 14:06:27 2025 -0400
@@ -610,7 +610,7 @@
     private function client_timezone()
     {
         // @TODO: remove this legacy timezone handling in the future
-        $props = $this->fix_legacy_props(array('timezone' => $_SESSION['timezone']));
+        $props = $this->fix_legacy_props(array('timezone' => $_SESSION['timezone']??null));
 
         if (!empty($props['timezone'])) {
             try {
--- a/program/lib/Roundcube/rcube_imap.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_imap.php	Wed Oct 15 14:06:27 2025 -0400
@@ -332,18 +332,18 @@
      */
     public function set_search_set($set)
     {
-        $set = (array)$set;
-
-        $this->search_string     = $set[0];
-        $this->search_set        = $set[1];
-        $this->search_charset    = $set[2];
-        $this->search_sort_field = $set[3];
-        $this->search_sorted     = $set[4];
-        $this->search_threads    = is_a($this->search_set, 'rcube_result_thread');
-
-        if (is_a($this->search_set, 'rcube_result_multifolder')) {
-            $this->set_threading(false);
-        }
+      $set = (array) $set;
+
+      $this->search_string     = $set[0] ?? null;
+      $this->search_set        = $set[1] ?? null;
+      $this->search_charset    = $set[2] ?? null;
+      $this->search_sort_field = $set[3] ?? null;
+      $this->search_sorted     = $set[4] ?? null;
+      $this->search_threads    = is_a($this->search_set, 'rcube_result_thread');
+
+      if (is_a($this->search_set, 'rcube_result_multifolder')) {
+	$this->set_threading(false);
+      }
     }
 
     /**
@@ -3451,7 +3451,7 @@
 
         $key = $subscription ? 'subscribed' : 'existing';
 
-        if (is_array($this->icache[$key]) && in_array($folder, $this->icache[$key])) {
+        if (is_array($this->icache[$key]??null) && in_array($folder, $this->icache[$key])) {
             return true;
         }
 
--- a/program/lib/Roundcube/rcube_imap_generic.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_imap_generic.php	Wed Oct 15 14:06:27 2025 -0400
@@ -3797,7 +3797,7 @@
             // remove spaces from the beginning of the string
             $str = ltrim($str);
 
-            switch ($str[0]) {
+            switch ($str[0]??'') {
 
             // String literal
             case '{':
--- a/program/lib/Roundcube/rcube_message.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_message.php	Wed Oct 15 14:06:27 2025 -0400
@@ -78,6 +78,7 @@
      */
     function __construct($uid, $folder = null, $is_safe = false)
     {
+      $context = null;
         // decode combined UID-folder identifier
         if (preg_match('/^[0-9.]+-.+/', $uid)) {
             list($uid, $folder) = explode('-', $uid, 2);
@@ -104,7 +105,7 @@
             return;
         }
 
-        $this->set_safe($is_safe || $_SESSION['safe_messages'][$this->folder.':'.$uid]);
+        $this->set_safe($is_safe || ($_SESSION['safe_messages'][$this->folder.':'.$uid]??null));
         $this->opt = array(
             'safe'        => $this->is_safe,
             'prefer_html' => $this->app->config->get('prefer_html'),
--- a/program/lib/Roundcube/rcube_message_header.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_message_header.php	Wed Oct 15 14:06:27 2025 -0400
@@ -217,6 +217,8 @@
      * @var array
      */
     public $has_children;
+    public $unread_children = 0;
+    public $flagged_children = 0;
 
     // map header to rcube_message_header object property
     private $obj_headers = array(
--- a/program/lib/Roundcube/rcube_message_part.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_message_part.php	Wed Oct 15 14:06:27 2025 -0400
@@ -77,7 +77,7 @@
     public $charset      = '';
     public $d_parameters = array();
     public $ctype_parameters = array();
-
+    public $replaces = [];
 
     /**
      * Clone handler.
--- a/program/lib/Roundcube/rcube_result_index.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_result_index.php	Wed Oct 15 14:06:27 2025 -0400
@@ -27,6 +27,7 @@
 class rcube_result_index
 {
     public $incomplete = false;
+    public $multi;  # HST: is this ever set anywhere???
 
     protected $raw_data;
     protected $mailbox;
--- a/program/lib/Roundcube/rcube_result_set.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_result_set.php	Wed Oct 15 14:06:27 2025 -0400
@@ -63,7 +63,7 @@
 
     /*** Implement PHP ArrayAccess interface ***/
 
-    public function offsetSet($offset, $value)
+    public function offsetSet(mixed $offset,mixed $value): void
     {
         if (is_null($offset)) {
             $offset = count($this->records);
@@ -74,12 +74,12 @@
         }
     }
 
-    public function offsetExists($offset)
+    public function offsetExists(mixed $offset): bool
     {
         return isset($this->records[$offset]);
     }
 
-    public function offsetUnset($offset)
+    public function offsetUnset(mixed $offset): void
     {
         unset($this->records[$offset]);
     }
@@ -91,27 +91,28 @@
 
     /***  PHP 5 Iterator interface  ***/
 
-    function rewind()
+    function rewind(): void
     {
         $this->current = 0;
     }
 
-    function current()
+    function current(): mixed
     {
         return $this->records[$this->current];
     }
 
-    function key()
+    function key(): mixed
     {
         return $this->current;
     }
 
+    #[ReturnTypeWillChange]
     function next()
     {
         return $this->iterate();
     }
 
-    function valid()
+    function valid(): bool
     {
         return isset($this->records[$this->current]);
     }
--- a/program/lib/Roundcube/rcube_text2html.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_text2html.php	Wed Oct 15 14:06:27 2025 -0400
@@ -249,7 +249,7 @@
         $sig_sep       = "--" . $this->config['space'] . "\n";
         $sig_max_lines = rcube::get_instance()->config->get('sig_max_lines', 15);
 
-        while (($sp = strrpos($text, $sig_sep, $sp ? -$len+$sp-1 : 0)) !== false) {
+        while (($sp = strrpos($text, $sig_sep, isset($sp) ? -$len+$sp-1 : 0)) !== false) {
             if ($sp == 0 || $text[$sp-1] == "\n") {
                 // do not touch blocks with more that X lines
                 if (substr_count($text, "\n", $sp) < $sig_max_lines) {
--- a/program/lib/Roundcube/rcube_utils.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_utils.php	Wed Oct 15 14:06:27 2025 -0400
@@ -572,11 +572,12 @@
         // %d - domain name without first part
         $d = preg_replace('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']);
         // %h - IMAP host
-        $h = $_SESSION['storage_host'] ?: $host;
+        $h = empty($_SESSION['storage_host']) ? $host : $_SESSION['storage_host'];
         // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld
         $z = preg_replace('/^[^\.]+\./', '', $h);
         // %s - domain name after the '@' from e-mail address provided at login screen.
         //      Returns FALSE if an invalid email is provided
+	$s = '';
         if (strpos($name, '%s') !== false) {
             $user_email = self::get_input_value('_user', self::INPUT_POST);
             $user_email = self::idn_convert($user_email, true);
@@ -584,9 +585,10 @@
             if ($matches < 1 || filter_var($s[1]."@".$s[2], FILTER_VALIDATE_EMAIL) === false) {
                 return false;
             }
+	    $s = $s[2];
         }
 
-        return str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s[2]), $name);
+        return str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s), $name);
     }
 
     /**
--- a/program/lib/Roundcube/rcube_vcard.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_vcard.php	Wed Oct 15 14:06:27 2025 -0400
@@ -126,15 +126,20 @@
 
         // find well-known address fields
         $this->displayname  = $this->raw['FN'][0][0];
-        $this->surname      = $this->raw['N'][0][0];
-        $this->firstname    = $this->raw['N'][0][1];
-        $this->middlename   = $this->raw['N'][0][2];
+        if (!empty($this->raw['N'])) {
+	  $this->surname      = $this->raw['N'][0][0];
+	  $this->firstname    = $this->raw['N'][0][1];
+	  $this->middlename   = $this->raw['N'][0][2];
+	}
         $this->nickname     = empty($this->raw['NICKNAME']) ? null : $this->raw['NICKNAME'][0][0];
         $this->organization = empty($this->raw['ORG']) ? null : $this->raw['ORG'][0][0];
-        $this->business     = ($this->raw['X-ABSHOWAS'][0][0] == 'COMPANY') || (join('', (array)$this->raw['N'][0]) == '' && !empty($this->organization));
+       $this->business     = (isset($this->raw['X-ABSHOWAS'][0][0]) && $this->raw['X-ABSHOWAS'][0][0] == 'COMPANY')
+            || (!empty($this->organization) && isset($this->raw['N'][0]) && @implode('', (array) $this->raw['N'][0]) === '');
 
-        foreach ((array)$this->raw['EMAIL'] as $i => $raw_email) {
-            $this->email[$i] = is_array($raw_email) ? $raw_email[0] : $raw_email;
+        if (!empty($this->raw['EMAIL'])) {
+            foreach ((array) $this->raw['EMAIL'] as $i => $raw_email) {
+                $this->email[$i] = is_array($raw_email) ? $raw_email[0] : $raw_email;
+            }
         }
 
         // make the pref e-mail address the first entry in $this->email
@@ -168,11 +173,12 @@
             }
         }
 
-        if ($this->raw['N'][0][3])
+        if (!empty($this->raw['N'])) {
+	  if ($this->raw['N'][0][3])
             $out['prefix'] = $this->raw['N'][0][3];
-        if ($this->raw['N'][0][4])
+	  if ($this->raw['N'][0][4])
             $out['suffix'] = $this->raw['N'][0][4];
-
+	}
         // convert from raw vcard data into associative data for Roundcube
         foreach (array_flip(self::$fieldmap) as $tag => $col) {
 	  if (!empty($this->raw[$tag])) {
@@ -186,21 +192,29 @@
 		  $combined = join(',', self::array_filter((array)$raw['type'], 'internet,pref', true));
 		  $combined = strtoupper($combined);
 
-		  if ($typemap[$combined]) {
+		  if (!empty($typemap[$combined])) {
 		    $subtype = $typemap[$combined];
 		  }
-		  else if ($typemap[$raw['type'][++$k]]) {
+		  else if (!empty($typemap[$raw['type'][++$k]])) {
 		    $subtype = $typemap[$raw['type'][$k]];
 		  }
 		  else {
 		    $subtype = strtolower($raw['type'][$k]);
 		  }
 
-		  while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) {
-		    $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
+                  while ($k < count($raw['type']) && ($subtype == 'interne
+t' || $subtype == 'pref')) {
+		    $k++;
+		    if (!empty($raw['type'][$k])) {
+		      if (!empty($typemap[$raw['type'][$k]])) {
+			$subtype = $typemap[$raw['type'][$k]];
+		      }
+		      else {
+			$subtype = $raw['type'][$k];
+		      }
+		    }
 		  }
 		}
-
 		// read vcard 2.1 subtype
 		if (!$subtype) {
 		  foreach ($raw as $k => $v) {
@@ -241,13 +255,15 @@
 
         // handle special IM fields as used by Apple
         foreach ($this->immap as $tag => $type) {
-            foreach ((array)$this->raw[$tag] as $i => $raw) {
+            if (!empty($this->raw[$tag])) {
+	      foreach ((array)$this->raw[$tag] as $i => $raw) {
                 $out['im:'.$type][] = $raw[0];
-            }
+	      }
+	    }
         }
 
         // copy photo data
-        if ($this->raw['PHOTO']) {
+        if (!empty($this->raw['PHOTO'])) {
             $out['photo'] = $this->raw['PHOTO'][0][0];
         }
 
--- a/program/lib/Roundcube/rcube_washtml.php	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/lib/Roundcube/rcube_washtml.php	Wed Oct 15 14:06:27 2025 -0400
@@ -215,9 +215,9 @@
     public function __construct($p = array())
     {
         $this->_html_elements   = array_flip((array)$p['html_elements']) + array_flip(self::$html_elements);
-        $this->_html_attribs    = array_flip((array)$p['html_attribs']) + array_flip(self::$html_attribs);
-        $this->_ignore_elements = array_flip((array)$p['ignore_elements']) + array_flip(self::$ignore_elements);
-        $this->_void_elements   = array_flip((array)$p['void_elements']) + array_flip(self::$void_elements);
+        $this->_html_attribs    = array_flip((array)$p['html_attribs']??array()) + array_flip(self::$html_attribs);
+        $this->_ignore_elements = array_flip((array)$p['ignore_elements']??array()) + array_flip(self::$ignore_elements);
+        $this->_void_elements   = array_flip((array)$p['void_elements']??array()) + array_flip(self::$void_elements);
 
         unset($p['html_elements'], $p['html_attribs'], $p['ignore_elements'], $p['void_elements']);
 
@@ -366,8 +366,9 @@
      */
     private function wash_uri($uri, $blocked_source = false)
     {
-        if (($src = $this->config['cid_map'][$uri])
-            || ($src = $this->config['cid_map'][$this->config['base_url'].$uri])
+      if (!empty($this->config) &&
+	  (($src = $this->config['cid_map'][$uri])
+	   || ($src = $this->config['cid_map'][$this->config['base_url'].$uri]))
         ) {
             return $src;
         }
@@ -455,7 +456,7 @@
             switch ($node->nodeType) {
             case XML_ELEMENT_NODE: //Check element
                 $tagName = strtolower($node->nodeName);
-                if ($callback = $this->handlers[$tagName]) {
+                if ($callback = $this->handlers[$tagName]??null) {
                     $dump .= call_user_func($callback, $tagName,
                         $this->wash_attribs($node), $this->dumpHtml($node, $level), $this);
                 }
--- a/program/steps/mail/func.inc	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/steps/mail/func.inc	Wed Oct 15 14:06:27 2025 -0400
@@ -890,17 +890,17 @@
     // initialize HTML washer
     $washer = new rcube_washtml($wash_opts);
 
-    if (!$p['skip_washer_form_callback']) {
+    if (empty($p['skip_washer_form_callback'])) {
         $washer->add_callback('form', 'rcmail_washtml_callback');
     }
 
     // allow CSS styles, will be sanitized by rcmail_washtml_callback()
-    if (!$p['skip_washer_style_callback']) {
+    if (empty($p['skip_washer_style_callback'])) {
         $washer->add_callback('style', 'rcmail_washtml_callback');
     }
 
     // modify HTML links to open a new window if clicked
-    if (!$p['skip_washer_link_callback']) {
+    if (empty($p['skip_washer_link_callback'])) {
         $washer->add_callback('a', 'rcmail_washtml_link_callback');
         $washer->add_callback('area', 'rcmail_washtml_link_callback');
 
@@ -1536,7 +1536,7 @@
         }
 
         // handle body styles related to background image
-        if ($style['background-image']) {
+        if (!empty($style['background-image'])) {
             // get body style
             if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) {
                 // get background related style
@@ -1587,11 +1587,13 @@
         $end = ' />';
     }
     else if (preg_match('/^mailto:(.+)/i', $attrib['href'], $mailto)) {
-        list($mailto, $url) = explode('?', html_entity_decode($mailto[1], ENT_QUOTES, 'UTF-8'), 2);
+        $url_parts = explode('?', html_entity_decode($mailto[1], ENT_QUOTES, 'UTF-8'), 2);
+        $mailto    = $url_parts[0];
+        $url       = $url_parts[1] ?? '';
 
         // #6020: use raw encoding for correct "+" character handling as specified in RFC6068
-        $url       = rawurldecode($url);
-        $mailto    = rawurldecode($mailto);
+        $url       = rawurldecode($url??'');
+        $mailto    = rawurldecode($mailto??'');
         $addresses = rcube_mime::decode_address_list($mailto, null, true);
         $mailto    = array();
 
@@ -2050,7 +2052,7 @@
 
     $name = strtolower($name);
 
-    if ($alias = $map[$name]) {
+    if ($alias = ($map[$name]??null)) {
         $name = $alias;
     }
     // Some versions of Outlook create garbage Content-Type:
--- a/program/steps/mail/search.inc	Thu Oct 09 11:31:41 2025 -0400
+++ b/program/steps/mail/search.inc	Wed Oct 15 14:06:27 2025 -0400
@@ -33,7 +33,7 @@
 $imap_charset = RCUBE_CHARSET;
 
 // get search string
-$str     = rcube_utils::get_input_value('_q', rcube_utils::INPUT_GET, true);
+$str     = rcube_utils::get_input_value('_q', rcube_utils::INPUT_GET, true)?:'';
 $mbox    = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GET, true);
 $filter  = rcube_utils::get_input_value('_filter', rcube_utils::INPUT_GET);
 $headers = rcube_utils::get_input_value('_headers', rcube_utils::INPUT_GET);
@@ -73,7 +73,7 @@
     list(,$srch) = explode(":", $str);
     $subject['body'] = "BODY";
 }
-else if (strlen(trim($str))) {
+else if (strlen(trim($str??''))) {
     if ($headers) {
         foreach (explode(',', $headers) as $header) {
             if ($header == 'text') {
@@ -122,6 +122,8 @@
 }
 
 // execute IMAP search
+$mboxes = array();
+$result = null;
 if ($search_str) {
     // search all, current or subfolders folders
     if ($scope == 'all') {
@@ -158,7 +160,7 @@
 $_SESSION['search_filter']   = $filter;
 
 // Get the headers
-if (!$result->incomplete) {
+if (empty($result->incomplete)) {
     $result_h = $RCMAIL->storage->list_messages($mbox, 1, $sort_column, rcmail_sort_order());
 }
 
@@ -215,8 +217,8 @@
     rcmail_send_unread_count($mbox, false, empty($result_h) ? 0 : null);
 }
 
-if (!$result->incomplete) {
-    $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $result->multi ? 'INBOX' : $mbox));
+if (empty($result->incomplete)) {
+  $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, empty($result->multi) ? $mbox : 'INBOX'));
 }
 
 $OUTPUT->send();