mguessan / davmail

DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
http://davmail.sourceforge.net
GNU General Public License v2.0
558 stars 82 forks source link

IMAP Select unexpected response #343

Closed ecoutinho closed 3 months ago

ecoutinho commented 3 months ago

While connected to a Davmail server (davmail-6.1.0-1.mga8.x86_64) using getmail, which uses imaplib.py, I got the following error:

SimpleIMAPSSLRetriever:xxx@xxx:993: xxx: operation error (IMAP error (command: SELECT => unexpected response: b'* 3064 EXISTS'))

Notice that there are two spaces in '* 3064', not one as it was expected.

Debug logs at the server:

2024-03-22 17:09:29,935 DEBUG [ImapConnection-55410] davmail.exchange.FolderLoadThread - Still loading INBOX (3064 messages) 2024-03-22 17:09:29,938 DEBUG [ImapConnection-55410] davmail - > 3064 EXISTS 2024-03-22 17:09:29,938 DEBUG [ImapConnection-55410] davmail - > * 3 RECENT

According to RFC 3501, the grammar for a response is:

response-data = "*" SP (resp-cond-state / resp-cond-bye / mailbox-data / message-data / capability-data) CRLF

(2) In all cases, SP refers to exactly one space. It is NOT permitted to substitute TAB, insert additional spaces, or otherwise treat SP as being equivalent to LWSP.

This happens after moving more than 1000 mails back into the Inbox. If there are less than 1000 mails, the error does not occur.

mguessan commented 3 months ago

That's correct, and the limit is at 500. In order to avoid timeout issues loading large folders DavMail sends additional spaces. As there is not native keepalive mechanism in IMAP this is the best workaround I could find.

To make DavMail RFC compliant, just change enableKeepAlive flag:

davmail.enableKeepAlive=false
ecoutinho commented 3 months ago

Thanks! It has worked.