Hello,

From what I've inferred from ocaml-ssl's documentation, its "read" function has Unix-like non-blocking
semantics.

This means that read returns the number of bytes available, not the number of bytes requested.

Hence you need an extra buffering/parsing layer on top of SSL sockets.  However you are using
IMAP, which is line-oriented, I guess Ssl.input_string should do what you want.
--
Berke