IMAP INBOX synchronization begins but it does not finish

Nextcloud version: 25.0.2
Operating system and version: docker on Synology DSM 6.2.4
Apache or nginx version: Apache/2.4.54 (Debian)
PHP version: 8.1.14

Situation

I have installed Nextcloud on Synology using this docker compose file (that relies on the official Docker Nextcloud image). Additionally, I configured a reverse proxy for HTTPS access. A configuration of my Nextcloud instance is available in config.php.

Problem and symptoms

When I set up an IMAP account for a user (in the Nextcloud Mail App) and navigate to the Mail App, Nextcloud starts IMAP synchronization. It successfully synchronizes all remote folders but INBOX. The INBOX content (1868 messages) does not appear in the Mail App GUI even after a few hours. Content of other IMAP folders is visible in the Mail App GUI.

horde_imap.log states: OK UID FETCH Completed, while nextcloud.log contains these errors:

  1. Undefined array key 3 at /var/www/html/custom_apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php#3530
  2. Undefined array key 2 at /var/www/html/custom_apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php#3531
  3. Undefined array key 3 at /var/www/html/custom_apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php#3530
  4. Undefined array key 2 at /var/www/html/custom_apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php#3531
  5. Undefined array key 3 at /var/www/html/custom_apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php#3530
  6. Undefined array key 2 at /var/www/html/custom_apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php#3531
  7. Sync failed for 4:INBOX: Undefined constant Horde_Imap_Client_Interaction_Server::1

Synchronizing the same IMAP account works fine in Thunderbird.

Steps to replicate it:

  1. install Nextcloud
  2. set up a Nextcloud user
  3. configure IMAP and SMTP for the user
  4. the user visits the Mail App GUI in Nextcloud

Please, help me to resolve the problem described above.