Mail loads forever, floods with error warnings

Hi! I just installed a fresh Nextcloud instance, so everything is up to date with the newest stable releases (23.0.1)

When I open the mail tab, it shows “instancing emails” forever. The admin log is flooded with the error below, there are hundreds of these errors there. Any idea what might be going on?

The output of your Nextcloud log in Admin > Logging:

Error: Undefined array key -1 at /var/www/html/custom_apps/mail/lib/IMAP/MessageMapper.php#186
/var/www/html/custom_apps/mail/lib/IMAP/MessageMapper.php - line 186:

OC\Log\ErrorHandler::onError(2, "Undefined array key -1", "/var/www/ht ... p", 186)

/var/www/html/custom_apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php - line 294:

OCA\Mail\IMAP\MessageMapper->findAll(Horde_Imap_C ... e}, "INBOX", 5000, 6030)

/var/www/html/custom_apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php - line 226:

OCA\Mail\Service\Sync\ImapToDbSynchronizer->runInitialSync(OCA\Mail\Account {}, OCA\Mail\Db\Mailbox { id: 42}, OC\AppFramew ... {})

/var/www/html/custom_apps/mail/lib/Service/Sync/SyncService.php - line 127:

OCA\Mail\Service\Sync\ImapToDbSynchronizer->sync(OCA\Mail\Account {}, OCA\Mail\Db\Mailbox { id: 42}, OC\AppFramew ... {}, 42, [ 6029,6030], true)

/var/www/html/custom_apps/mail/lib/Controller/MailboxesController.php - line 161:

OCA\Mail\Service\Sync\SyncService->syncMailbox(OCA\Mail\Account {}, OCA\Mail\Db\Mailbox { id: 42}, 42, [ 33,32], false, "is:pi-other")

/var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 217:

OCA\Mail\Controller\MailboxesController->sync(42, [ 33,32], true, "is:pi-other")

/var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 126:

OC\AppFramework\Http\Dispatcher->executeController(OCA\Mail\Con ... {}, "sync")

/var/www/html/lib/private/AppFramework/App.php - line 157:

OC\AppFramework\Http\Dispatcher->dispatch(OCA\Mail\Con ... {}, "sync")

/var/www/html/lib/private/Route/Router.php - line 302:

OC\AppFramework\App::main("OCA\\Mail\\ ... r", "sync", OC\AppFramew ... {}, { id: "42",_ ... "})

/var/www/html/lib/base.php - line 1006:

OC\Route\Router->match("/apps/mail/ ... c")

/var/www/html/index.php - line 36:

OC::handleRequest()

Found an issue on github that seems to address this very problem: https://github.com/nextcloud/mail/pull/5976