nojb / ocaml-imap

Lwt-compatible IMAP4rev1 client library for OCaml
https://nojb.github.io/ocaml-imap/imap
Other
40 stars 17 forks source link

Parsing error #35

Open CGenie opened 5 years ago

CGenie commented 5 years ago

Hello, I'm trying to run a simple Imap.uid_search followed by Imap.uid_fetch for a Imap.Fetch.Request.body_section. Hover I'm getting this error:

Fatal error: exception Parsing error:
* 1 FETCH (UID 5 BODY[TEXT] {52}
                          ^

Any idea what's wrong here?

nojb commented 5 years ago

Are you using master?

CGenie commented 5 years ago

Yes, I'm using master, I liked the Lwt code more than the socket mangling as in the .1.1.1 release.

CGenie commented 5 years ago

I'm aware it's a WIP, however I hoped for a minimal working version here, or at least small thing that can get fixed :)

nojb commented 5 years ago

Can you tell which commit are you using? The current master has a completely different API which is not yet working.

CGenie commented 5 years ago

I'm using the latest master with small fixes on top of it: https://github.com/CGenie/ocaml-imap/tree/master-fix

CGenie commented 5 years ago

My code looks like this:

  Lwt_main.run begin
  Imap.connect ~host:host ~port:port ~username:username ~password:password >>= fun imap ->
  Imap.examine imap imap_cfg.mbox >>= fun () ->
  Imap.uid_search imap Imap.Search.all >>= fun (uids, _) ->
  (* Lwt_list.iter_s (fun (uid : Imap.uid) -> Lwt_io.printf "UID: %ld\n" uid) uids *)
  Lwt_list.iter_s (fun (uid: Imap.uid) ->
    let mime = Imap.MIME.Section.TEXT in
    let msg = Imap.uid_fetch imap [uid] [Imap.Fetch.Request.body_section ~peek:true ~section:([], Some mime) ()] in
    msg (fun resp ->
      match resp with
      | {Imap.Fetch.Response.body_section = [_, s]; _} ->
          Utils.log_with_header "UID: %ld\nBody: %s" uid s
      | _ ->
          Utils.log_with_header "Error fetching message %ld\n" uid
    )
  ) uids
  >>= fun () -> Imap.disconnect imap
nojb commented 5 years ago

Probably due to https://github.com/CGenie/ocaml-imap/blob/master-fix/lib/parser.ml#L1156-L1161. You can try uncommenting that and seeing if it works. It may need some small changes to compile, not sure.

I can take a look but not right now, probably later in the day (no promises! :))

CGenie commented 5 years ago

I'll try. Ah no hurry, your response is the fastest I've seen on github yet :)