#1038441 Horde uses obsolete each() function throughout its code.

#1038441#5
Date:
2023-06-18 10:31:18 UTC
From:
To:
Hi,

Horde still uses the obsolete each() function.
https://www.php.net/manual/en/function.each.php

Example from /usr/share/horde/imp/lib/Ajax/Application/ListMessages.php,
line 438:

        while (list(,$ob) = each($overview['overview'])) {
             ...
        }

This function has been deprecated since 7.2, and has now been removed
completely in php-8.2 (as shipped by Debian 12).

Which means that horde is basically unusable right now.

What makes this hard to debug is that most instances of it only leave a
mysterious "Error when communication with the server" error. Some
occurrences fortunately then leave additional details in
/var/log/horde.log . Others however have *only* the "Error when
communication with the server" without any further details elsewhere.

N.B. The problem occurs right after log in, when Horde / IMP attempts to
display mailbox, so is really not hard to reproduce!

Thanks for addressing this,

Alain

#1038441#10
Date:
2023-07-20 19:05:22 UTC
From:
To:
#1038441#15
Date:
2023-07-28 13:27:15 UTC
From:
To:
Dear Maintainer,
the bug severity should be grave as Horde IMP web UI does not work at all.

Quick fix below, but there are more bugs - e.g. when clicking on "new message" in IMP.

diff -urp imp-/lib/Ajax/Application/ListMessages.php imp/lib/Ajax/Application/ListMessages.php
--- imp-/lib/Ajax/Application/ListMessages.php  2023-02-03 19:10:03.000000000 +0100
+++ imp/lib/Ajax/Application/ListMessages.php   2023-07-28 15:04:24.994178543 +0200
@@ -434,8 +434,7 @@ class IMP_Ajax_Application_ListMessages
         ));

         /* Display message information. */
-        reset($overview['overview']);
-        while (list(,$ob) = each($overview['overview'])) {
+        foreach ($overview['overview'] as $ob) {
             /* Get all the flag information. */
             $msg = array(
                 'flag' => $flags
diff -urp imp-/lib/Basic/Mailbox.php imp/lib/Basic/Mailbox.php
--- imp-/lib/Basic/Mailbox.php  2023-02-03 19:10:03.000000000 +0100
+++ imp/lib/Basic/Mailbox.php   2023-07-28 14:55:46.286208770 +0200
@@ -843,7 +843,7 @@ class IMP_Basic_Mailbox extends IMP_Basi
         $search_view = clone $view;
         $summary_view = clone $view;

-        while (list(,$ob) = each($mbox_info['overview'])) {
+        foreach ($mbox_info['overview'] as $ob) {
             if ($search_mbox) {
                 if (empty($lastMbox) || ($ob['mailbox'] != $lastMbox)) {
                     if (!empty($lastMbox)) {
diff -urp imp-/lib/Contents.php imp/lib/Contents.php
--- imp-/lib/Contents.php       2023-02-03 19:10:03.000000000 +0100
+++ imp/lib/Contents.php        2023-07-28 15:13:17.486162022 +0200
@@ -1480,8 +1480,7 @@ class IMP_Contents
                 continue;
             }

-            reset($render_part);
-            while (list($id, $info) = each($render_part)) {
+            foreach ($render_part as $id => $info) {
                 $display_ids[$id] = 1;

                 if (empty($info)) {
@@ -1534,8 +1533,7 @@ class IMP_Contents
             uksort($msgtext, 'strnatcmp');
         }

-        reset($msgtext);
-        while (list($id, $part) = each($msgtext)) {
+        foreach ($msgtext as $id => $part) {
             while (!empty($wrap_ids) &&
                    !Horde_Mime::isChild(end($wrap_ids), $id)) {
                 array_pop($wrap_ids);
diff -urp imp-/lib/Mime/Viewer/Plain.php imp/lib/Mime/Viewer/Plain.php
--- imp-/lib/Mime/Viewer/Plain.php      2023-02-03 19:10:03.000000000 +0100
+++ imp/lib/Mime/Viewer/Plain.php       2023-07-28 15:02:40.726183385 +0200
@@ -277,8 +277,7 @@ class IMP_Mime_Viewer_Plain extends Hord
         $text_part->setContents(preg_replace("/begin [0-7]{3} .+\r?\n.+\r?\nend/Us", "\n", $text));
         $new_part->addPart($text_part);

-        reset($files);
-        while (list(,$file) = each($files)) {
+        foreach ($files as $file) {
             $uupart = new Horde_Mime_Part();
             $uupart->setType('application/octet-stream');
             $uupart->setContents($file['data']);
diff -urp imp-/lib/Minimal/Mailbox.php imp/lib/Minimal/Mailbox.php
--- imp-/lib/Minimal/Mailbox.php        2023-02-03 19:10:03.000000000 +0100
+++ imp/lib/Minimal/Mailbox.php 2023-07-28 14:54:34.266214279 +0200
@@ -123,7 +123,7 @@ class IMP_Minimal_Mailbox extends IMP_Mi
         $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('headers' => true));
         $msgs = array();

-        while (list(,$ob) = each($mbox_info['overview'])) {
+        foreach ($mbox_info['overview'] as $ob) {
             /* Initialize the header fields. */
             $msg = array(
                 'buid' => $imp_mailbox->getBuid($ob['mailbox'], $ob['uid']),
diff -urp kronolith-/lib/FreeBusy/View.php kronolith/lib/FreeBusy/View.php
--- kronolith-/lib/FreeBusy/View.php    2023-01-03 07:33:57.000000000 +0100
+++ kronolith/lib/FreeBusy/View.php     2023-07-28 15:22:13.650136020 +0200
@@ -305,9 +305,7 @@ abstract class Kronolith_FreeBusy_View
         $template = $GLOBALS['injector']->createInstance('Horde_Template');
         $template->set('label', $label);

-        reset($periods);
-        list($periodStart, $periodEnd) = each($periods);
-
+        foreach ($periods as $periodStart => $periodEnd) {
         $blocks = '';
         foreach ($this->_timeBlocks as $span) {
             /* Horde_Icalendar_Vfreebusy only supports timestamps at the
@@ -343,6 +341,7 @@ abstract class Kronolith_FreeBusy_View
                 $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/emptyblock.html');
             }
         }
+        }

         return $blocks;
     }