this repo has no description

manual fixes

Changed files
+3 -45
lib
-1
AGENT.md
···
12. DONE Extend the fastmail-list to filter messages displays by email address of the
sender. This may involve adding logic to parse email addresses; if so, add
this logic into the Jmap_mail library.
-
13. Add a new feature to save messages matching specific criteria to a file for offline reading.
···
12. DONE Extend the fastmail-list to filter messages displays by email address of the
sender. This may involve adding logic to parse email addresses; if so, add
this logic into the Jmap_mail library.
+3 -44
lib/jmap_mail.ml
···
let mailbox_of_json json =
try
let open Ezjsonm in
-
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 *)
let parent_id =
match find_opt json ["parentId"] with
···
| None -> None
| _ -> None
in
-
Printf.printf "Got parent_id: %s\n" (match parent_id with Some p -> p | None -> "None");
-
(* Handle role which might be null *)
let role =
match find_opt json ["role"] with
···
| None -> None
| _ -> None
in
-
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";
-
let my_rights = {
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"]);
} in
-
Printf.printf "Constructed my_rights\n";
-
let result = {
Types.id;
name;
···
is_subscribed;
my_rights;
} in
-
Printf.printf "Constructed mailbox result\n";
-
Ok (result)
with
-
| Not_found as e ->
-
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;
Error (Parse_error msg)
| e ->
-
Printf.printf "Unknown error: %s\n" (Printexc.to_string e);
Error (Parse_error (Printexc.to_string e))
(** Convert JSON email object to OCaml type *)
let email_of_json json =
try
let open Ezjsonm in
-
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";
-
Ok ({
Types.id;
blob_id;
···
headers = None;
})
with
-
| Not_found as e ->
-
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;
Error (Parse_error msg)
| e ->
-
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
···
let mailbox_of_json json =
try
let open Ezjsonm in
let id = get_string (find json ["id"]) in
let name = get_string (find json ["name"]) in
(* Handle parentId which can be null *)
let parent_id =
match find_opt json ["parentId"] with
···
| None -> None
| _ -> None
in
(* Handle role which might be null *)
let role =
match find_opt json ["role"] with
···
| None -> None
| _ -> None
in
let sort_order = get_int (find json ["sortOrder"]) in
let total_emails = get_int (find json ["totalEmails"]) in
let unread_emails = get_int (find json ["unreadEmails"]) in
let total_threads = get_int (find json ["totalThreads"]) in
let unread_threads = get_int (find json ["unreadThreads"]) in
let is_subscribed = get_bool (find json ["isSubscribed"]) in
let rights_json = find json ["myRights"] in
let my_rights = {
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"]);
} in
let result = {
Types.id;
name;
···
is_subscribed;
my_rights;
} in
Ok (result)
with
+
| Not_found ->
Error (Parse_error "Required field not found in mailbox object")
| Invalid_argument msg ->
Error (Parse_error msg)
| e ->
Error (Parse_error (Printexc.to_string e))
(** Convert JSON email object to OCaml type *)
let email_of_json json =
try
let open Ezjsonm in
let id = get_string (find json ["id"]) in
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
+
(* TODO Body parts parsing would go here - omitting for brevity *)
Ok ({
Types.id;
blob_id;
···
headers = None;
})
with
+
| Not_found ->
Error (Parse_error "Required field not found in email object")
| Invalid_argument msg ->
Error (Parse_error msg)
| e ->
Error (Parse_error (Printexc.to_string e))
(** Login to a JMAP server and establish a connection