libcURL IMAP UID FETCH

I’m trying to retrieve some data from email server via imap protocol(with RB-libcURL). Unfortunately when I run the command UID FETCH NUMID (FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (Message-Id DATE FROM SUBJECT TO SENDER REPLY-TO CC BCC)])
returns
* 1 FETCH (UID 3780 FLAGS (\Answered \Seen) INTERNALDATE "20-Oct-2020 19:50:23 +0200" RFC822.SIZE 158788 BODY[HEADER.FIELDS (MESSAGE-ID DATE FROM SUBJECT TO SENDER REPLY-TO CC BCC)] {220}

but not the content of the email. If I run the same command from terminal I get the same result but if I use the -v option everything works correctly. If instead I use for example the command fetch 1:* (UID FLAGS) everything works correctly.What am I missing?

curl -v imaps://imap.url.com/INBOX --user "user:pass" -X "UID FETCH 3780  (FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (Message-Id DATE FROM SUBJECT TO SENDER REPLY-TO CC BCC)])"



Var curl As New libcURL.EasyHandle

Call curl.SetOption(libcURL.Opts.SSL_ENABLE_ALPN, False)
Call curl.SetOption(libcURL.Opts.SSL_VERIFYPEER, 0)
Call curl.SetOption(libcURL.Opts.SSL_VERIFYHOST, 0)


Call curl.SetOption(libcURL.Opts.URL, "imaps://imap.url.com/"+cartella)
Call curl.SetOption(libcURL.Opts.USERNAME, "user")
Call curl.SetOption(libcURL.Opts.PASSWORD, "pass")

if _comando <> "" then
  Call curl.SetOption(libcURL.Opts.CUSTOMREQUEST, _Comando)
end if 

Var mb As New MemoryBlock(0)
var bs as new BinaryStream(mb)
curl.DownloadStream = bs
if curl.Perform then

  bs.Close
  curl.DownloadStream = Nil

  Return mb

else
  MsgBox libcURL.FormatError(curl.LastError)
end if

I don’t know anything about IMAP but I suspect that the response you’re looking for is being delivered as headers rather than as content to be downloaded. This would explain why curl -v works: -v, for verbose, prints the response headers.

Try this:

' use cURLClient instead of EasyHandle unless you have a reason not to.
Var curl As New cURLClient 

Call curl.SetOption(libcURL.Opts.SSL_ENABLE_ALPN, False)
Call curl.SetOption(libcURL.Opts.SSL_VERIFYPEER, 0)  ' ?! unsafe
Call curl.SetOption(libcURL.Opts.SSL_VERIFYHOST, 0)  ' ?! unsafe

curl.Username = "user"
curl.Password = "pass"

if _comando <> "" then
  Call curl.SetRequestMethod(_Comando)
end if 

' Head() does a headers-only operation. This may or may not 
' actually be correct (idk about IMAP)
if curl.Head("imaps://imap.url.com/"+cartella) then
  
  Return curl.GetResponseHeaders() ' return an InternetHeaders object
  
else
  MsgBox libcURL.FormatError(curl.LastError)
end if

Thank you so much for the help! You’re right, the data is in the header however I’m not sure if this is correct behavior.