Bug 449184

Summary: Connection fails because the CAPABILITY command is sent before the server greeting arrived
Product: [Frameworks and Libraries] kimap Reporter: Fabian Vogt <fabian>
Component: generalAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED FIXED    
Severity: major CC: kfunk
Priority: NOR    
Version: git   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:

Description Fabian Vogt 2022-01-26 09:57:06 UTC
Since yesterday, IMAP connections to imap.1und1.de fail:

org.kde.pim.kimap: KIMAP::LoginJob(0x564b0931c4d0)
org.kde.pim.kimap: Connecting to IMAP server with no proxy
org.kde.pim.kimap: connectToHost "imap.1und1.de" 993
org.kde.pim.kimap: TLS negotiation done, the negotiated protocol is "TLSv1.3"
C: A000001 CAPABILITY
S: * BYE out-of-sync data before server greeting
org.kde.pim.kimap: Received BYE:  "out-of-sync data before server greeting "
org.kde.pim.kimap: close
org.kde.pim.kimap: close
org.kde.pim.kimap: Connection to server lost  QAbstractSocket::RemoteHostClosedError
org.kde.pim.kimap: KIMAP::LoginJob(0x564b0931c4d0)

The issue is that LoginJob sends the CAPABILITY command before the server greeting arrived.

Apparently this also affects some other mail clients: https://www.batboard.net/thread/15020-bye-out-of-sync-data-before-server-greeting/
Comment 1 Bug Janitor Service 2022-01-26 10:33:31 UTC
A possibly relevant merge request was started @ https://invent.kde.org/pim/kimap/-/merge_requests/11
Comment 2 Fabian Vogt 2022-01-27 19:24:45 UTC
Git commit dbcedd5aaab1a4e691966d1e37de1a0b413ca605 by Fabian Vogt.
Committed on 27/01/2022 at 13:23.
Pushed by fvogt into branch 'release/21.12'.

Handle pure SSL/TLS negotation in Session instead of LoginJob

Previously, LoginJob started the SSL negotiation and immediately sent the
CAPABILITY command once it completed, without waiting for the server greeting
first. Some servers don't like this any close the connection with
* BYE out-of-sync data before server greeting

Avoid this by starting the encryption in Session directly, which then starts
LoginJob after the server greeting arrived. Adjust LoginJob for this by
treating an already encrypted connection like a successful negotation, and
avoid handling the encryptionNegotiationResult signal before the job was
started.

M  +7    -5    src/loginjob.cpp
M  +1    -1    src/session.cpp

https://invent.kde.org/pim/kimap/commit/dbcedd5aaab1a4e691966d1e37de1a0b413ca605