···505012. DONE Extend the fastmail-list to filter messages displays by email address of the
5151 sender. This may involve adding logic to parse email addresses; if so, add
5252 this logic into the Jmap_mail library.
5353-13. Add a new feature to save messages matching specific criteria to a file for offline reading.
+3-44
lib/jmap_mail.ml
···11991199let mailbox_of_json json =
12001200 try
12011201 let open Ezjsonm in
12021202- Printf.printf "Parsing mailbox JSON\n";
12031203-12041202 let id = get_string (find json ["id"]) in
12051205- Printf.printf "Got id: %s\n" id;
12061206-12071203 let name = get_string (find json ["name"]) in
12081208- Printf.printf "Got name: %s\n" name;
12091209-12101204 (* Handle parentId which can be null *)
12111205 let parent_id =
12121206 match find_opt json ["parentId"] with
···12151209 | None -> None
12161210 | _ -> None
12171211 in
12181218- Printf.printf "Got parent_id: %s\n" (match parent_id with Some p -> p | None -> "None");
12191219-12201212 (* Handle role which might be null *)
12211213 let role =
12221214 match find_opt json ["role"] with
···12251217 | None -> None
12261218 | _ -> None
12271219 in
12281228- Printf.printf "Got role\n";
12291229-12301220 let sort_order = get_int (find json ["sortOrder"]) in
12311231- Printf.printf "Got sort_order: %d\n" sort_order;
12321232-12331221 let total_emails = get_int (find json ["totalEmails"]) in
12341234- Printf.printf "Got total_emails: %d\n" total_emails;
12351235-12361222 let unread_emails = get_int (find json ["unreadEmails"]) in
12371237- Printf.printf "Got unread_emails: %d\n" unread_emails;
12381238-12391223 let total_threads = get_int (find json ["totalThreads"]) in
12401240- Printf.printf "Got total_threads: %d\n" total_threads;
12411241-12421224 let unread_threads = get_int (find json ["unreadThreads"]) in
12431243- Printf.printf "Got unread_threads: %d\n" unread_threads;
12441244-12451225 let is_subscribed = get_bool (find json ["isSubscribed"]) in
12461246- Printf.printf "Got is_subscribed: %b\n" is_subscribed;
12471247-12481226 let rights_json = find json ["myRights"] in
12491249- Printf.printf "Got rights_json\n";
12501250-12511227 let my_rights = {
12521228 Types.may_read_items = get_bool (find rights_json ["mayReadItems"]);
12531229 may_add_items = get_bool (find rights_json ["mayAddItems"]);
···12591235 may_delete = get_bool (find rights_json ["mayDelete"]);
12601236 may_submit = get_bool (find rights_json ["maySubmit"]);
12611237 } in
12621262- Printf.printf "Constructed my_rights\n";
12631263-12641238 let result = {
12651239 Types.id;
12661240 name;
···12741248 is_subscribed;
12751249 my_rights;
12761250 } in
12771277- Printf.printf "Constructed mailbox result\n";
12781278-12791251 Ok (result)
12801252 with
12811281- | Not_found as e ->
12821282- Printf.printf "Not_found error: %s\n" (Printexc.to_string e);
12831283- Printexc.print_backtrace stdout;
12531253+ | Not_found ->
12841254 Error (Parse_error "Required field not found in mailbox object")
12851255 | Invalid_argument msg ->
12861286- Printf.printf "Invalid_argument error: %s\n" msg;
12871256 Error (Parse_error msg)
12881257 | e ->
12891289- Printf.printf "Unknown error: %s\n" (Printexc.to_string e);
12901258 Error (Parse_error (Printexc.to_string e))
1291125912921260(** Convert JSON email object to OCaml type *)
12931261let email_of_json json =
12941262 try
12951263 let open Ezjsonm in
12961296- Printf.printf "Parsing email JSON\n";
1297126412981265 let id = get_string (find json ["id"]) in
12991299- Printf.printf "Got email id: %s\n" id;
13001300-13011266 let blob_id = get_string (find json ["blobId"]) in
13021267 let thread_id = get_string (find json ["threadId"]) in
13031268···14061371 let has_attachment = parse_bool_opt "hasAttachment" in
14071372 let preview = parse_string_opt "preview" in
1408137314091409- (* Body parts parsing would go here - omitting for brevity *)
14101410- Printf.printf "Email parsed successfully\n";
14111411-13741374+ (* TODO Body parts parsing would go here - omitting for brevity *)
14121375 Ok ({
14131376 Types.id;
14141377 blob_id;
···14371400 headers = None;
14381401 })
14391402 with
14401440- | Not_found as e ->
14411441- Printf.printf "Email parse error - Not_found: %s\n" (Printexc.to_string e);
14421442- Printexc.print_backtrace stdout;
14031403+ | Not_found ->
14431404 Error (Parse_error "Required field not found in email object")
14441405 | Invalid_argument msg ->
14451445- Printf.printf "Email parse error - Invalid_argument: %s\n" msg;
14461406 Error (Parse_error msg)
14471407 | e ->
14481448- Printf.printf "Email parse error - Unknown: %s\n" (Printexc.to_string e);
14491408 Error (Parse_error (Printexc.to_string e))
1450140914511410(** Login to a JMAP server and establish a connection