···
let mailbox_of_json json =
1202
-
Printf.printf "Parsing mailbox JSON\n";
let id = get_string (find json ["id"]) in
1205
-
Printf.printf "Got id: %s\n" id;
let name = get_string (find json ["name"]) in
1208
-
Printf.printf "Got name: %s\n" name;
(* Handle parentId which can be null *)
match find_opt json ["parentId"] with
···
1218
-
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
···
1228
-
Printf.printf "Got role\n";
let sort_order = get_int (find json ["sortOrder"]) in
1231
-
Printf.printf "Got sort_order: %d\n" sort_order;
let total_emails = get_int (find json ["totalEmails"]) in
1234
-
Printf.printf "Got total_emails: %d\n" total_emails;
let unread_emails = get_int (find json ["unreadEmails"]) in
1237
-
Printf.printf "Got unread_emails: %d\n" unread_emails;
let total_threads = get_int (find json ["totalThreads"]) in
1240
-
Printf.printf "Got total_threads: %d\n" total_threads;
let unread_threads = get_int (find json ["unreadThreads"]) in
1243
-
Printf.printf "Got unread_threads: %d\n" unread_threads;
let is_subscribed = get_bool (find json ["isSubscribed"]) in
1246
-
Printf.printf "Got is_subscribed: %b\n" is_subscribed;
let rights_json = find json ["myRights"] in
1249
-
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"]);
1262
-
Printf.printf "Constructed my_rights\n";
···
1277
-
Printf.printf "Constructed mailbox result\n";
1281
-
| Not_found as e ->
1282
-
Printf.printf "Not_found error: %s\n" (Printexc.to_string e);
1283
-
Printexc.print_backtrace stdout;
Error (Parse_error "Required field not found in mailbox object")
| Invalid_argument msg ->
1286
-
Printf.printf "Invalid_argument error: %s\n" msg;
1289
-
Printf.printf "Unknown error: %s\n" (Printexc.to_string e);
Error (Parse_error (Printexc.to_string e))
(** Convert JSON email object to OCaml type *)
1296
-
Printf.printf "Parsing email JSON\n";
let id = get_string (find json ["id"]) in
1299
-
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
1409
-
(* Body parts parsing would go here - omitting for brevity *)
1410
-
Printf.printf "Email parsed successfully\n";
1374
+
(* TODO Body parts parsing would go here - omitting for brevity *)
···
1440
-
| Not_found as e ->
1441
-
Printf.printf "Email parse error - Not_found: %s\n" (Printexc.to_string e);
1442
-
Printexc.print_backtrace stdout;
Error (Parse_error "Required field not found in email object")
| Invalid_argument msg ->
1445
-
Printf.printf "Email parse error - Invalid_argument: %s\n" msg;
1448
-
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