changeset 19:b6a96bdd6b29

More cleaning up php8 Warnings/deprecations
author Charlie Root
date Wed, 08 Oct 2025 08:50:44 -0400
parents b631c1c7a3ce
children 4aec5e272733
files program/include/rcmail.php program/lib/Roundcube/html.php program/lib/Roundcube/rcube_config.php program/lib/Roundcube/rcube_db.php program/lib/Roundcube/rcube_db_pgsql.php program/lib/Roundcube/rcube_imap.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_output.php program/lib/Roundcube/rcube_plugin.php program/lib/Roundcube/rcube_plugin_api.php program/lib/Roundcube/rcube_result_thread.php program/lib/Roundcube/rcube_session.php program/lib/Roundcube/rcube_text2html.php program/steps/mail/func.inc program/steps/mail/list.inc
diffstat 17 files changed, 81 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/program/include/rcmail.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/include/rcmail.php	Wed Oct 08 08:50:44 2025 -0400
@@ -488,7 +488,7 @@
         }
 
         // restore skin selection after logout
-        if ($_SESSION['temp'] && !empty($_SESSION['skin'])) {
+        if (!empty($_SESSION['temp']) && !empty($_SESSION['skin'])) {
             $this->config->set('skin', $_SESSION['skin']);
         }
     }
@@ -823,7 +823,7 @@
         }
 
         $pre = array();
-        $task = ($p['_task']??null) ?: ($p['task'] ?: $this->task);
+        $task = ($p['_task']??null) ?: (($p['task']??null) ?: $this->task);
         $pre['_task'] = $task;
         unset($p['task'], $p['_task']);
 
@@ -1805,7 +1805,7 @@
         $quota_result['type']   = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : '';
         $quota_result['folder'] = $folder !== null && $folder !== '' ? $folder : 'INBOX';
 
-        if ($quota['total'] > 0) {
+        if (($quota['total']??0) > 0) {
             if (!isset($quota['percent'])) {
                 $quota_result['percent'] = min(100, round(($quota['used']/max(1,$quota['total']))*100));
             }
--- a/program/lib/Roundcube/html.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/html.php	Wed Oct 08 08:50:44 2025 -0400
@@ -757,7 +757,7 @@
         }
 
        $this->rows[$this->rowindex]->cells[$this->colindex] = $cell;
-        $this->colindex += max(1, intval($attr['colspan']));
+        $this->colindex += max(1, intval($attr['colspan']??null));
 
         if ($this->attrib['cols'] && $this->colindex >= $this->attrib['cols']) {
             $this->add_row();
--- a/program/lib/Roundcube/rcube_config.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_config.php	Wed Oct 08 08:50:44 2025 -0400
@@ -317,7 +317,7 @@
                 include($fpath);
                 ob_end_clean();
 
-                if (is_array($config)) {
+                if (is_array($config??null)) {
                     $this->merge($config);
                     $success = true;
                 }
@@ -453,7 +453,7 @@
         }
 
         // larry is the new default skin :-)
-        if ($prefs['skin'] == 'default') {
+        if (($prefs['skin']??null) == 'default') {
             $prefs['skin'] = self::DEFAULT_SKIN;
         }
 
--- a/program/lib/Roundcube/rcube_db.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_db.php	Wed Oct 08 08:50:44 2025 -0400
@@ -131,7 +131,7 @@
         $this->db_error_msg = null;
 
         // return existing handle
-        if ($this->dbhs[$mode]) {
+        if (!empty($this->dbhs[$mode])) {
             $this->dbh = $this->dbhs[$mode];
             $this->db_mode = $mode;
             return $this->dbh;
@@ -438,7 +438,7 @@
 
         if (count($params)) {
             while ($pos = strpos($query, '?', $pos)) {
-                if ($query[$pos+1] == '?') {  // skip escaped '?'
+	      if (($query[$pos+1]??null) == '?') {  // skip escaped '?'
                     $pos += 2;
                 }
                 else {
--- a/program/lib/Roundcube/rcube_db_pgsql.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_db_pgsql.php	Wed Oct 08 08:50:44 2025 -0400
@@ -217,7 +217,7 @@
             $params[] = 'port=' . $dsn['port'];
         }
 
-        if ($dsn['database']) {
+        if (!empty($dsn['database'])) {
             $params[] = 'dbname=' . $dsn['database'];
         }
 
--- a/program/lib/Roundcube/rcube_imap.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_imap.php	Wed Oct 08 08:50:44 2025 -0400
@@ -74,6 +74,7 @@
     protected $threading = false;
     protected $connect_done;
     protected $sort_folder_collator;
+    protected $msg_uid;
 
     /**
      * Object constructor.
@@ -2039,7 +2040,7 @@
                 }
                 $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1;
                 $struct->parts[] = $this->structure_part($part[$i], ++$count, $struct->mime_id,
-                    $mime_part_headers[$tmp_part_id]);
+		 $mime_part_headers ? $mime_part_headers[$tmp_part_id] : null);
             }
 
             return $struct;
@@ -3742,7 +3743,7 @@
             $headers = array();
         }
 
-        if ($this->messages_caching || $this->options['all_headers']) {
+        if ($this->messages_caching || !empty($this->options['all_headers'])) {
             $headers = array_merge($headers, $this->all_headers);
         }
 
--- a/program/lib/Roundcube/rcube_message.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_message.php	Wed Oct 08 08:50:44 2025 -0400
@@ -930,7 +930,7 @@
         if (strlen($part->mime_id))
             $this->mime_parts[$part->mime_id] = &$part;
 
-        if (is_array($part->parts))
+        if (is_array($part->parts??null))
             for ($i=0; $i<count($part->parts); $i++)
                 $this->get_mime_numbers($part->parts[$i]);
     }
--- a/program/lib/Roundcube/rcube_message_header.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_message_header.php	Wed Oct 08 08:50:44 2025 -0400
@@ -142,6 +142,13 @@
     public $bodystructure;
 
     /**
+     * IMAP structure
+     *
+     * @var rcube_message_part
+     */
+    public $structure;
+
+    /**
      * IMAP internal date
      *
      * @var string
--- a/program/lib/Roundcube/rcube_message_part.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_message_part.php	Wed Oct 08 08:50:44 2025 -0400
@@ -69,7 +69,8 @@
      * @var array
      */
     public $headers = array();
-
+    public $body;
+    public $type;
     public $disposition  = '';
     public $filename     = '';
     public $encoding     = '8bit';
--- a/program/lib/Roundcube/rcube_output.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_output.php	Wed Oct 08 08:50:44 2025 -0400
@@ -100,7 +100,7 @@
      */
     public function get_env($name)
     {
-        return $this->env[$name];
+      return ($this->env[$name]??null);
     }
 
     /**
--- a/program/lib/Roundcube/rcube_plugin.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_plugin.php	Wed Oct 08 08:50:44 2025 -0400
@@ -376,7 +376,7 @@
         if ($this->api->output->type == 'html') {
             // fix relative paths
             foreach (array('imagepas', 'imageact', 'imagesel') as $key) {
-                if ($p[$key]) {
+                if ($p[$key]??null) {
                     $p[$key] = $this->api->url . $this->resource_url($p[$key]);
                 }
             }
--- a/program/lib/Roundcube/rcube_plugin_api.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_plugin_api.php	Wed Oct 08 08:50:44 2025 -0400
@@ -212,7 +212,7 @@
 
         if ($plugin = $this->plugins[$plugin_name]) {
             // init a plugin only if $force is set or if we're called after initialization
-            if (($force || $this->initialized) && !$this->plugins_initialized[$plugin_name] && ($force || !$this->filter($plugin))) {
+	  if (($force || $this->initialized) && empty($this->plugins_initialized[$plugin_name]) && ($force || empty($this->filter($plugin)))) {
                 $plugin->init();
                 $this->plugins_initialized[$plugin_name] = $plugin;
             }
@@ -571,7 +571,7 @@
      */
     public function is_plugin_task($task)
     {
-        return $this->tasks[$task] ? true : false;
+      return ($this->tasks[$task]??null) ? true : false;
     }
 
     /**
@@ -654,7 +654,7 @@
     protected function template_container_hook($attrib)
     {
         $container = $attrib['name'];
-        return array('content' => $attrib['content'] . $this->template_contents[$container]);
+        return array('content' => ($attrib['content']??'') . $this->template_contents[$container]);
     }
 
     /**
--- a/program/lib/Roundcube/rcube_result_thread.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_result_thread.php	Wed Oct 08 08:50:44 2025 -0400
@@ -109,9 +109,9 @@
      */
     public function count()
     {
-        if ($this->meta['count'] !== null)
+      if (!empty($this->meta['count'])) {
             return $this->meta['count'];
-
+      }
         if (empty($this->raw_data)) {
             $this->meta['count'] = 0;
         }
@@ -603,7 +603,12 @@
             foreach ($messages as $msg) {
                 if ($msg) {
                     $node .= ($depth ? self::SEPARATOR_ITEM.$depth.self::SEPARATOR_LEVEL : '').$msg;
-                    $this->meta['messages']++;
+                    if (isset($this->meta['messages'])) {
+                        $this->meta['messages']++;
+                    }
+                    else {
+                        $this->meta['messages'] = 1;
+		    }
                     $depth++;
                 }
             }
--- a/program/lib/Roundcube/rcube_session.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_session.php	Wed Oct 08 08:50:44 2025 -0400
@@ -302,7 +302,7 @@
             $cache = null;
         }
         // use internal data for fast requests (up to 0.5 sec.)
-        else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) {
+        else if ($key == $this->key && (!$this->vars || microtime(true) - $this->start < 0.5)) {
             $cache = $this->vars;
         }
         else { // else read data again
--- a/program/lib/Roundcube/rcube_text2html.php	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/lib/Roundcube/rcube_text2html.php	Wed Oct 08 08:50:44 2025 -0400
@@ -66,6 +66,13 @@
         'nobr_end'   => '</span>',
     );
 
+    /**
+     * Indicates whether content in the $text variable has been converted yet.
+     *
+     * @var boolean $_converted
+     * @see $html, $text
+     */
+    protected $_converted = false;
 
     /**
      * Constructor.
@@ -174,7 +181,7 @@
                 $text[$n] = substr($text[$n], 1);
             }
 
-            if ($text[$n][0] == '>' && preg_match('/^(>+ {0,1})+/', $text[$n], $regs)) {
+            if ($text[$n] && $text[$n][0] == '>' && preg_match('/^(>+ {0,1})+/', $text[$n], $regs)) {
                 $q        = substr_count($regs[0], '>');
                 $text[$n] = substr($text[$n], strlen($regs[0]));
                 $text[$n] = $this->_convert_line($text[$n], $flowed || $this->config['wrap']);
--- a/program/steps/mail/func.inc	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/steps/mail/func.inc	Wed Oct 08 08:50:44 2025 -0400
@@ -78,7 +78,7 @@
     // set current mailbox and some other vars in client environment
     $OUTPUT->set_env('mailbox', $mbox_name);
     $OUTPUT->set_env('pagesize', $RCMAIL->storage->get_pagesize());
-    $OUTPUT->set_env('current_page', max(1, $_SESSION['page']));
+    $OUTPUT->set_env('current_page', max(1, ($_SESSION['page']??0)));
     $OUTPUT->set_env('delimiter', $delimiter);
     $OUTPUT->set_env('threading', $threading);
     $OUTPUT->set_env('threads', $threading || $RCMAIL->storage->get_capability('THREAD'));
@@ -163,22 +163,20 @@
     $message_sort_order = $RCMAIL->config->get('message_sort_order');
 
     // set imap properties and session vars
-    if (!strlen($mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true))) {
-        $mbox = strlen($_SESSION['mbox']) ? $_SESSION['mbox'] : 'INBOX';
-    }
+    $mbox = (rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true)??null) ?: (!empty($_SESSION['mbox']) ? $_SESSION['mbox'] : 'INBOX');
 
     // we handle 'page' argument on 'list' and 'getunread' to prevent from
     // race condition and unintentional page overwrite in session
     if ($RCMAIL->action == 'list' || $RCMAIL->action == 'getunread') {
-        if (!($page = intval($_GET['_page']))) {
-            $page = $_SESSION['page'] ?: 1;
+        if (!($page = intval($_GET['_page']??null))) {
+	  $page = ($_SESSION['page']??null) ?: 1;
         }
 
         $_SESSION['page'] = $page;
     }
 
     $RCMAIL->storage->set_folder($_SESSION['mbox'] = $mbox);
-    $RCMAIL->storage->set_page($_SESSION['page']);
+    $RCMAIL->storage->set_page($_SESSION['page']??null);
 
     // set default sort col/order to session
     if (!isset($_SESSION['sort_col'])) {
@@ -380,7 +378,7 @@
 
     $table = new html_table($attrib);
 
-    if (!$attrib['noheader']) {
+    if (empty($attrib['noheader'])) {
         foreach (rcmail_message_list_head($attrib, $a_show_cols) as $cell)
             $table->add_header(array('class' => $cell['className'], 'id' => $cell['id']), $cell['html']);
     }
@@ -459,7 +457,7 @@
         }
     }
 
-    $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL;
+    $thead = !empty($head_replace) ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL;
 
     // get name of smart From/To column in folder context
     if (array_search('fromto', $a_show_cols) !== false) {
@@ -701,7 +699,7 @@
 {
     global $RCMAIL;
 
-    if (!$attrib['id']) {
+    if (empty($attrib['id'])) {
         $attrib['id'] = 'rcmcountdisplay';
     }
 
@@ -786,7 +784,7 @@
     // @TODO: this data is doubled (session and cache tables) if caching is enabled
 
     // Make sure we have an array here (#1487066)
-    if (!is_array($_SESSION['unseen_count'])) {
+    if (!is_array($_SESSION['unseen_count']??null)) {
         $_SESSION['unseen_count'] = array();
     }
 
@@ -795,7 +793,7 @@
 
 function rcmail_get_unseen_count($mbox_name)
 {
-    if (is_array($_SESSION['unseen_count']) && array_key_exists($mbox_name, $_SESSION['unseen_count'])) {
+    if (is_array($_SESSION['unseen_count']??null) && array_key_exists($mbox_name, $_SESSION['unseen_count'])) {
         return $_SESSION['unseen_count'][$mbox_name];
     }
 }
@@ -968,8 +966,8 @@
 
     // plaintext postprocessing
     if ($part->ctype_secondary == 'plain') {
-        $flowed = $part->ctype_parameters['format'] == 'flowed';
-        $delsp = $part->ctype_parameters['delsp'] == 'yes';
+      $flowed = ($part->ctype_parameters['format']??null) == 'flowed';
+        $delsp = ($part->ctype_parameters['delsp']??null) == 'yes';
         $body = rcmail_plain_body($body, $flowed, $delsp);
     }
 
@@ -1046,7 +1044,7 @@
     static $sa_attrib;
 
     // keep header table attrib
-    if (is_array($attrib) && !$sa_attrib && !$attrib['valueof']) {
+    if (is_array($attrib) && !$sa_attrib && empty($attrib['valueof'])) {
         $sa_attrib = $attrib;
     }
     else if (!is_array($attrib) && is_array($sa_attrib)) {
@@ -1073,15 +1071,15 @@
     // show these headers
     $standard_headers = array('subject', 'from', 'sender', 'to', 'cc', 'bcc', 'replyto',
         'mail-reply-to', 'mail-followup-to', 'date', 'priority');
-    $exclude_headers = $attrib['exclude'] ? explode(',', $attrib['exclude']) : array();
+    $exclude_headers = !empty($attrib['exclude']) ? explode(',', $attrib['exclude']) : array();
     $output_headers  = array();
 
     foreach ($standard_headers as $hkey) {
-        if ($headers[$hkey])
+        if ($headers[$hkey]??null)
             $value = $headers[$hkey];
-        else if ($headers['others'][$hkey])
+        else if ($headers['others'][$hkey]??null)
             $value = $headers['others'][$hkey];
-        else if (!$attrib['valueof'])
+        else if (empty($attrib['valueof']))
             continue;
 
         if (in_array($hkey, $exclude_headers))
@@ -1107,8 +1105,8 @@
         }
         else if ($hkey == 'replyto') {
             if ($headers['replyto'] != $headers['from']) {
-                $header_value = rcmail_address_string($value, $attrib['max'], true,
-                    $attrib['addicon'], $headers['charset'], $header_title);
+                $header_value = rcmail_address_string($value, $attrib['max']??null, true,
+                    $attrib['addicon']??null, $headers['charset'], $header_title);
                 $ishtml = true;
             }
             else {
@@ -1116,11 +1114,11 @@
             }
         }
         else if ($hkey == 'mail-reply-to') {
-            if ($headers['mail-replyto'] != $headers['replyto']
+	  if (($headers['mail-replyto']??null) != $headers['replyto']
                 && $headers['replyto'] != $headers['from']
             ) {
-                $header_value = rcmail_address_string($value, $attrib['max'], true,
-                    $attrib['addicon'], $headers['charset'], $header_title);
+                $header_value = rcmail_address_string($value, $attrib['max']??null, true,
+                    $attrib['addicon']??null, $headers['charset'], $header_title);
                 $ishtml = true;
             }
             else {
@@ -1128,9 +1126,9 @@
             }
         }
         else if ($hkey == 'sender') {
-            if ($headers['sender'] != $headers['from']) {
-                $header_value = rcmail_address_string($value, $attrib['max'], true,
-                    $attrib['addicon'], $headers['charset'], $header_title);
+	  if (($headers['sender']??null) != $headers['from']) {
+                $header_value = rcmail_address_string($value, $attrib['max']??null, true,
+                    $attrib['addicon']??null, $headers['charset'], $header_title);
                 $ishtml = true;
             }
             else {
@@ -1138,13 +1136,14 @@
             }
         }
         else if ($hkey == 'mail-followup-to') {
-            $header_value = rcmail_address_string($value, $attrib['max'], true,
-                $attrib['addicon'], $headers['charset'], $header_title);
+            $header_value = rcmail_address_string($value, $attrib['max']??null,
+						  true,
+                $attrib['addicon']??null, $headers['charset'], $header_title);
             $ishtml = true;
         }
         else if (in_array($hkey, array('from', 'to', 'cc', 'bcc'))) {
-            $header_value = rcmail_address_string($value, $attrib['max'], true,
-                $attrib['addicon'], $headers['charset'], $header_title);
+            $header_value = rcmail_address_string($value, $attrib['max']??null, true,
+                $attrib['addicon']??null, $headers['charset'], $header_title);
             $ishtml = true;
         }
         else if ($hkey == 'subject' && empty($value)) {
@@ -1205,7 +1204,7 @@
         '5' => 'lowest',
     );
 
-    if ($value && $labels_map[$value]) {
+    if ($value && !empty($labels_map[$value])) {
         return $RCMAIL->gettext($labels_map[$value]);
     }
 
@@ -1249,7 +1248,7 @@
     if (!$attrib['id'])
         $attrib['id'] = 'rcmailMsgBody';
 
-    $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
+    $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']??null);
     $out       = '';
     $part_no   = 0;
 
@@ -1267,7 +1266,7 @@
             }
             else if ($part->type == 'content') {
                 // unsupported (e.g. encrypted)
-                if ($part->realtype) {
+                if ($part->realtype??null) {
                     if ($part->realtype == 'multipart/encrypted' || $part->realtype == 'application/pkcs7-mime') {
                         if (!empty($_SESSION['browser_caps']['pgpmime']) && ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part())) {
                             $out .= html::span('part-notice', $RCMAIL->gettext('externalmessagedecryption'));
@@ -2136,7 +2135,7 @@
 
     $RCMAIL->output->add_gui_object('search_filter', $attrib['id']);
 
-    return $select->show($_REQUEST['_search'] ? $_SESSION['search_filter'] : 'ALL');
+    return $select->show(($_REQUEST['_search']??null) ? $_SESSION['search_filter'] : 'ALL');
 }
 
 function rcmail_search_interval($attrib)
@@ -2156,7 +2155,7 @@
 
     $RCMAIL->output->add_gui_object('search_interval', $attrib['id']);
 
-    return $select->show($_REQUEST['_search'] ? $_SESSION['search_interval'] : '');
+    return $select->show(($_REQUEST['_search']??null) ? $_SESSION['search_interval'] : '');
 }
 
 function rcmail_message_error()
--- a/program/steps/mail/list.inc	Tue Oct 07 11:20:40 2025 -0400
+++ b/program/steps/mail/list.inc	Wed Oct 08 08:50:44 2025 -0400
@@ -111,7 +111,7 @@
 rcmail_js_message_list($a_headers, false, $cols);
 
 if (isset($a_headers) && count($a_headers)) {
-    if ($search_request) {
+  if (!empty($search_request)) {
         $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
     }
 
@@ -141,7 +141,7 @@
 }
 
 if ($page == 1) {
-    $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $multifolder ? 'INBOX' : $mbox_name));
+  $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, empty($multifolder) ? $mbox_name : 'INBOX'));
 }
 
 // send response