Mail Sync Broken for Mailbox (Argument exceeds maximum length of 4096 bytes.)

Hello All,

I’m currently using the latest versions of Nextcloud Mail and Stalwart Mail Server. One of my users can no longer access their Inbox properly. When clicking on an email, the message body simply displays “Not found”.

Side note: Other (Web-)Mail Clients working fine. (e.g. Roundcube/Thunderbird).

I’ve also tried to move all new messages into a folder, but the Inbox is still not accessible. Mails from other folders can be opened.

I would be grateful for any tips!

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 32.0.6
  • Operating system and version (e.g., Ubuntu 24.04):
    • Debian 13.3
  • Web server and version (e.g, Apache 2.4.25):
    • NGinx
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • No
  • PHP version (e.g, 8.3):
    • 8.4.16
  • Is this the first time you’ve seen this error? (Yes / No):
    • Yes
  • When did this problem seem to first start?
    • Few days ago
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Download Package
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No

Summary of the issue you are facing:

Sync for a user mailbox seems to be broken. Tried a manual sync via CLI.

nextcloud@web2:~/htdocs$ php occ mail:account:sync 2 -vvv
[debug] account is up to date, skipping mailbox sync
[debug] Skipping mailbox sync for 461
[debug] Skipping mailbox sync for 169
[debug] Skipping mailbox sync for 467
[debug] Skipping mailbox sync for 405
[debug] Skipping mailbox sync for 421
[debug] Skipping mailbox sync for 404
[debug] Skipping mailbox sync for 429
[debug] Skipping mailbox sync for 473
[debug] Skipping mailbox sync for 407
[debug] Skipping mailbox sync for 406
[debug] Syncing 81
[debug] Locking mailbox 81 for new messages sync
[debug] Locking mailbox 81 for changed messages sync
[debug] Locking mailbox 81 for vanished messages sync
[debug] Running partial sync for 81 with criteria 42
[debug] partial sync 2:INBOX - get all known UIDs took 0s. 37/38MB memory used
[debug] Unlocking mailbox 81 from vanished messages sync
[debug] Unlocking mailbox 81 from changed messages sync
[debug] Unlocking mailbox 81 from new messages sync

In ImapToDbSynchronizer.php line 288:

  [OCA\Mail\Exception\ServiceException]
  Sync failed for 2:INBOX: The mail server was unable to parse the contents of the mail message: Argument exceeds maximum length of 4096 bytes.


Exception trace:
  at /var/www/nextcloud/htdocs/apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php:288
 OCA\Mail\Service\Sync\ImapToDbSynchronizer->sync() at /var/www/nextcloud/htdocs/apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php:134
 OCA\Mail\Service\Sync\ImapToDbSynchronizer->syncAccount() at /var/www/nextcloud/htdocs/apps/mail/lib/Command/SyncAccount.php:88
 OCA\Mail\Command\SyncAccount->sync() at /var/www/nextcloud/htdocs/apps/mail/lib/Command/SyncAccount.php:72
 OCA\Mail\Command\SyncAccount->execute() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Application.php:1083
 Symfony\Component\Console\Application->doRunCommand() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /var/www/nextcloud/htdocs/lib/private/Console/Application.php:187
 OC\Console\Application->run() at /var/www/nextcloud/htdocs/console.php:90
 require_once() at /var/www/nextcloud/htdocs/occ:33

In Socket.php line 4858:

  [Horde_Imap_Client_Exception_ServerResponse (6)]
  The mail server was unable to parse the contents of the mail message: Argument exceeds maximum length of 4096 bytes.


Exception trace:
  at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php:4858
 Horde_Imap_Client_Socket->_responseCode() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php:4586
 Horde_Imap_Client_Socket->_getLine() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php:4319
 Horde_Imap_Client_Socket->_sendCmdChunk() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php:4243
 Horde_Imap_Client_Socket->_sendCmd() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php:1236
 Horde_Imap_Client_Socket->_openMailbox() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php:1066
 Horde_Imap_Client_Base->openMailbox() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php:2247
 Horde_Imap_Client_Base->search() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Data/Sync.php:186
 Horde_Imap_Client_Data_Sync->__construct() at /var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php:3643
 Horde_Imap_Client_Base->sync() at /var/www/nextcloud/htdocs/apps/mail/lib/IMAP/Sync/Synchronizer.php:99
 OCA\Mail\IMAP\Sync\Synchronizer->doCombinedSync() at /var/www/nextcloud/htdocs/apps/mail/lib/IMAP/Sync/Synchronizer.php:69
 OCA\Mail\IMAP\Sync\Synchronizer->sync() at /var/www/nextcloud/htdocs/apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php:413
 OCA\Mail\Service\Sync\ImapToDbSynchronizer->runPartialSync() at /var/www/nextcloud/htdocs/apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php:269
 OCA\Mail\Service\Sync\ImapToDbSynchronizer->sync() at /var/www/nextcloud/htdocs/apps/mail/lib/Service/Sync/ImapToDbSynchronizer.php:134
 OCA\Mail\Service\Sync\ImapToDbSynchronizer->syncAccount() at /var/www/nextcloud/htdocs/apps/mail/lib/Command/SyncAccount.php:88
 OCA\Mail\Command\SyncAccount->sync() at /var/www/nextcloud/htdocs/apps/mail/lib/Command/SyncAccount.php:72
 OCA\Mail\Command\SyncAccount->execute() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Application.php:1083
 Symfony\Component\Console\Application->doRunCommand() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /var/www/nextcloud/htdocs/3rdparty/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /var/www/nextcloud/htdocs/lib/private/Console/Application.php:187
 OC\Console\Application->run() at /var/www/nextcloud/htdocs/console.php:90
 require_once() at /var/www/nextcloud/htdocs/occ:33

mail:account:sync [-f|--force] [--] <account-id>

nextcloud@web2:~/htdocs$

Mail Server is Stalwart 0.15.5 Docker

Steps to replicate it (hint: details matter!)

Not possible

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

{"reqId":"RVn5Ka51cJPFGaugFbGp","level":3,"time":"2026-02-24T12:46:34+00:00","remoteAddr":"2001:a61:xxx","user":"f2ecf2a0-0883-1033-80fb-67e436cc4ccc","app":"mail","method":"GET","url":"/apps/mail/api/messages/106889/body","scriptName":"/index.php","message":"Could not load message","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36","version":"32.0.6.1","exception":{"Exception":"OCA\\Mail\\Exception\\ServiceException","Message":"Could not load message","Code":6,"Trace":[{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/Controller/MessagesController.php","line":233,"function":"getImapMessage","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":204,"function":"getBody","class":"OCA\\Mail\\Controller\\MessagesController","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":118,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/App.php","line":153,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/Route/Router.php","line":321,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/htdocs/lib/base.php","line":1091,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/htdocs/index.php","line":25,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/htdocs/apps/mail/lib/Service/MailManager.php","Line":194,"Previous":{"Exception":"Horde_Imap_Client_Exception_ServerResponse","Message":"The mail server was unable to parse the contents of the mail message: Argument exceeds maximum length of 4096 bytes.","Code":6,"Trace":[{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":4586,"function":"_responseCode","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":4319,"function":"_getLine","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":4243,"function":"_sendCmdChunk","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":1236,"function":"_sendCmd","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php","line":1066,"function":"_openMailbox","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php","line":2526,"function":"openMailbox","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php","line":2493,"function":"_fetchWrapper","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/IMAP/MessageMapper.php","line":298,"function":"fetch","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/IMAP/MessageMapper.php","line":78,"function":"findByIds","class":"OCA\\Mail\\IMAP\\MessageMapper","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/Service/MailManager.php","line":186,"function":"find","class":"OCA\\Mail\\IMAP\\MessageMapper","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/Controller/MessagesController.php","line":233,"function":"getImapMessage","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":204,"function":"getBody","class":"OCA\\Mail\\Controller\\MessagesController","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":118,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/App.php","line":153,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/Route/Router.php","line":321,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/htdocs/lib/base.php","line":1091,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/htdocs/index.php","line":25,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","Line":4858},"message":"Could not load message","exception":{},"CustomMessage":"Could not load message"}}PASTE HERE

Web Browser

If the problem is related to the Web interface, open your browser inspector Console and Network tabs while refreshing (reloading) and reproducing the problem. Provide any relevant output/errors here that appear.

{"reqId":"RVn5Ka51cJPFGaugFbGp","level":3,"time":"2026-02-24T12:46:34+00:00","remoteAddr":"2001:a61:a11:f401:xxx","user":"f2ecf2a0-0883-1033-80fb-67e436cc4ccc","app":"mail","method":"GET","url":"/apps/mail/api/messages/106889/body","scriptName":"/index.php","message":"Could not load message","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36","version":"32.0.6.1","exception":{"Exception":"OCA\\Mail\\Exception\\ServiceException","Message":"Could not load message","Code":6,"Trace":[{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/Controller/MessagesController.php","line":233,"function":"getImapMessage","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":204,"function":"getBody","class":"OCA\\Mail\\Controller\\MessagesController","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":118,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/App.php","line":153,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/Route/Router.php","line":321,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/htdocs/lib/base.php","line":1091,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/htdocs/index.php","line":25,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/htdocs/apps/mail/lib/Service/MailManager.php","Line":194,"Previous":{"Exception":"Horde_Imap_Client_Exception_ServerResponse","Message":"The mail server was unable to parse the contents of the mail message: Argument exceeds maximum length of 4096 bytes.","Code":6,"Trace":[{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":4586,"function":"_responseCode","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":4319,"function":"_getLine","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":4243,"function":"_sendCmdChunk","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","line":1236,"function":"_sendCmd","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php","line":1066,"function":"_openMailbox","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php","line":2526,"function":"openMailbox","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php","line":2493,"function":"_fetchWrapper","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/IMAP/MessageMapper.php","line":298,"function":"fetch","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/IMAP/MessageMapper.php","line":78,"function":"findByIds","class":"OCA\\Mail\\IMAP\\MessageMapper","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/Service/MailManager.php","line":186,"function":"find","class":"OCA\\Mail\\IMAP\\MessageMapper","type":"->"},{"file":"/var/www/nextcloud/htdocs/apps/mail/lib/Controller/MessagesController.php","line":233,"function":"getImapMessage","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":204,"function":"getBody","class":"OCA\\Mail\\Controller\\MessagesController","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/Http/Dispatcher.php","line":118,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/AppFramework/App.php","line":153,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/htdocs/lib/private/Route/Router.php","line":321,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/htdocs/lib/base.php","line":1091,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/htdocs/index.php","line":25,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/htdocs/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php","Line":4858},"message":"Could not load message","exception":{},"CustomMessage":"Could not load message"}}

Web server / Reverse Proxy

The output of your Apache/nginx/system log in /var/log/____:

None

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

{
    "system": {
        "cache_path": "\/home\/nextcloud\/cache",
        "tempdirectory": "\/home\/nextcloud\/tmp",
        "updatedirectory": "\/home\/nextcloud\/update-dir",
        "logfile": "\/var\/www\/nextcloud\/logs\/nextcloud.log",
        "logfile_audit": "\/var\/www\/nextcloud\/logs\/nextcloud-audit.log",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "32.0.6.1",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "forcessl": true,
        "ldapIgnoreNamingRules": false,
        "theme": "",
        "maintenance": false,
        "trusted_domains": [
            "nextcloud.xxx.com"
        ],
        "maintenance_window_start": 1,
        "loglevel": 2,
        "secret": "***REMOVED SENSITIVE VALUE***",
        "share_folder": "\/Shared",
        "trashbin_retention_obligation": "auto",
        "ldapProviderFactory": "\\OCA\\User_LDAP\\LDAPProviderFactory",
        "overwrite.cli.url": "https:\/\/nextcloud.xxx.com",
        "mysql.utf8mb4": true,
        "app_install_overwrite": [
            "keeweb"
        ],
        "twofactor_enforced": "false",
        "twofactor_enforced_groups": [],
        "twofactor_enforced_excluded_groups": [],
        "mail_smtpmode": "sendmail",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "25",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "app.mail.attachment-size-limit": 0,
        "updater.release.channel": "stable",
        "updater.secret": "***REMOVED SENSITIVE VALUE***"
    }
}

Apps

The output of occ app:list (if possible).

  • Mail

Tips for increasing the likelihood of a response

  • Use the preformatted text formatting option in the editor for all log entries and configuration output.
  • If screenshots are useful, feel free to include them.
    • If possible, also include key error output in text form so it can be searched for.
  • Try to edit log output only minimally (if at all) so that it can be ran through analyzers / formatters by those trying to help you.

This is somewhat outside my wheelhouse, but I was curious when I read your post so I poked around a bit at the implementations.

This looks like Stalwart enforcing a 4096-byte per-argument limit (there isn’t a universal standard for this AFAIK). With large mailboxes, the UID list can exceed that limit.

In non‑QRESYNC mode the Mail app already chunks UID lists to minimize the chance of this happening (though it too is a higher limit of 10,000 bytes at the moment; and appears to have been reduced several times previously), but this appears to be happening during QRESYNC, where the known‑UID list is sent as a single argument, so it’s trickier to handle.

Can you report your situation here? GitHub - nextcloud/mail: 💌 Mail app for Nextcloud

The problem is an outdated assumption in the following file: apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php

It says:

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. */

And stalwart Mailserver (which I also use in one place in version 0.15.5) is unfortunately not (any longer?) one of “any server” :thinking:

and therefore the following line (which have a hardcoded value) causes the problem:

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

I have now changed this in Socket.php to:

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

And now it works.

Could you please set the value to 4000 in the next version or make the value configurable?

Thank you and best regards,

Dirk

2 Likes

Good finding, Thanks a lot!

I assume the limit of 7000 comes from RFC 2683: IMAP4 Implementation Recommendations .

Hey guys,

thank you for the feedback & help!

After manually changing the limit to 4000, the sync (including CLI) worked perfectly again.

Should I open an issue for this? If so, where is the best place?

  • Stalwart - Since the server issues the 4096-byte limit error.

  • Horde IMAP - The hardcoded limit seems to be in their IMAP Client package.

  • Nextcloud Mail - To update the Horde IMAP lib?

Best wishes

Luke

Hello Luke,

I have opened this issue today:

I can’t say whether it’s worth opening a ticket with Stalwart and pointing them to RFC 2683 regarding the QRESYNC limit.

Great thanks!