···
let mailbox_of_json json =
-
Printf.printf "Parsing mailbox JSON\n";
let id = get_string (find json ["id"]) in
-
Printf.printf "Got id: %s\n" id;
let name = get_string (find json ["name"]) in
-
Printf.printf "Got name: %s\n" name;
(* Handle parentId which can be null *)
match find_opt json ["parentId"] with
···
-
Printf.printf "Got parent_id: %s\n" (match parent_id with Some p -> p | None -> "None");
(* Handle role which might be null *)
match find_opt json ["role"] with
···
-
Printf.printf "Got role\n";
let sort_order = get_int (find json ["sortOrder"]) in
-
Printf.printf "Got sort_order: %d\n" sort_order;
let total_emails = get_int (find json ["totalEmails"]) in
-
Printf.printf "Got total_emails: %d\n" total_emails;
let unread_emails = get_int (find json ["unreadEmails"]) in
-
Printf.printf "Got unread_emails: %d\n" unread_emails;
let total_threads = get_int (find json ["totalThreads"]) in
-
Printf.printf "Got total_threads: %d\n" total_threads;
let unread_threads = get_int (find json ["unreadThreads"]) in
-
Printf.printf "Got unread_threads: %d\n" unread_threads;
let is_subscribed = get_bool (find json ["isSubscribed"]) in
-
Printf.printf "Got is_subscribed: %b\n" is_subscribed;
let rights_json = find json ["myRights"] in
-
Printf.printf "Got rights_json\n";
Types.may_read_items = get_bool (find rights_json ["mayReadItems"]);
may_add_items = get_bool (find rights_json ["mayAddItems"]);
···
may_delete = get_bool (find rights_json ["mayDelete"]);
may_submit = get_bool (find rights_json ["maySubmit"]);
-
Printf.printf "Constructed my_rights\n";
···
-
Printf.printf "Constructed mailbox result\n";
-
Printf.printf "Not_found error: %s\n" (Printexc.to_string e);
-
Printexc.print_backtrace stdout;
Error (Parse_error "Required field not found in mailbox object")
| Invalid_argument msg ->
-
Printf.printf "Invalid_argument error: %s\n" msg;
-
Printf.printf "Unknown error: %s\n" (Printexc.to_string e);
Error (Parse_error (Printexc.to_string e))
(** Convert JSON email object to OCaml type *)
-
Printf.printf "Parsing email JSON\n";
let id = get_string (find json ["id"]) in
-
Printf.printf "Got email id: %s\n" id;
let blob_id = get_string (find json ["blobId"]) in
let thread_id = get_string (find json ["threadId"]) in
···
let has_attachment = parse_bool_opt "hasAttachment" in
let preview = parse_string_opt "preview" in
-
(* Body parts parsing would go here - omitting for brevity *)
-
Printf.printf "Email parsed successfully\n";
···
-
Printf.printf "Email parse error - Not_found: %s\n" (Printexc.to_string e);
-
Printexc.print_backtrace stdout;
Error (Parse_error "Required field not found in email object")
| Invalid_argument msg ->
-
Printf.printf "Email parse error - Invalid_argument: %s\n" msg;
-
Printf.printf "Email parse error - Unknown: %s\n" (Printexc.to_string e);
Error (Parse_error (Printexc.to_string e))
(** Login to a JMAP server and establish a connection