nextcloud / nextcloud/mail

"Argument exceeds maximum length of 4096 bytes" while mail:account:sync for some accounts

Open
#12,487 4 comments 1 reaction 1 assignee View on GitHub

@kesselb is already working on this.

Since Feb 27, 2026.

1. to develop bug
Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
12h 28m
Merged PRs (30d)
91

Description

Forum discussion: https://help.nextcloud.com/t/mail-sync-broken-for-mailbox-argument-exceeds-maximum-length-of-4096-bytes/240891

Steps to reproduce
  1. Take a mailbox with a large inbox that is highly fragmented.
  2. Run php ./occ mail:account:sync -vvv
  3. You get an exception (you can also see this in the log during cron imap:sync): "Message":"Sync failed for :INBOX: The mail server was unable to parse the contents of the mail message: Argument exceeds maximum length of 4096 bytes."
  4. Now you look in the Stalwart Log and see: 2026-02-26T08:02:54Z DEBUG IMAP error occurred (imap.error) listenerId = "imap", localPort = 143, remoteIp = , remotePort = 45630, details = "Argument exceeds maximum length of 4096 bytes.", id = "10", type = "BAD", code = "PARSE"
  5. This has to do with QRESYNC, which appears to be limited to 4096 bytes in Stalwart 0.15.5.
Expected behavior

Sync without errors

Actual behavior

nextcloud.log
Message":"Sync failed for :INBOX: The mail server was unable to parse the contents of the mail message: Argument exceeds maximum length of 4096 bytes.

stalwart.log
2026-02-26T08:02:54Z DEBUG IMAP error occurred (imap.error) listenerId = "imap", localPort = 143, remoteIp = , remotePort = 45630, details = "Argument exceeds maximum length of 4096 bytes.", id = "10", type = "BAD", code = "PARSE"

Mail app version

5.7.1

Nextcloud version

32.0.6

Mailserver or service

Stalwart Mailserver 0.15.5

Operating system

Ubuntu 24.04 LTS

PHP engine version

PHP 8.3

Nextcloud memory caching

memcache.local, memcache.distributed, memcache.locking

Web server

Nginx

Database

MariaDB

Additional info

The reason is a false assumption in the
apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php

1185 /* Check for extra long UID string. Assume that any
1186 * server that can handle QRESYNC can also handle long
1187 * input strings (at least 8 KB), so 7 KB is as good as
1188 * any guess as to an upper limit. If this occurs, provide
1189 * a range string (min -> max) instead. */

Unfortunately, this is not the case with the Stalwart mail server (at least in version 0.15.5). There, the limit is 4096 bytes.

The fixed value:

1190 if (strlen($uid_str = $uids->tostring_sort) > 7000) {

Corrected:

1190 if (strlen($uid_str = $uids->tostring_sort) > 4000) {

Or make the value configurable.
Or perhaps there is also a technical option to ask the IMAP server what it can do. But I don't know that.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.