Testing a Gemini codegen run
at main 3.9 kB view raw
1(** JMAP Client Library Interface (RFC 8620 & RFC 8621) 2 3 This library provides OCaml types and function signatures for interacting 4 with a JMAP server. 5 6 Modules: 7 - {!Jmap.Types}: Basic data types (Id, Date, etc.). 8 - {!Jmap.Error}: Error types (ProblemDetails, MethodError, SetError). 9 - {!Jmap.Wire}: Request and Response structures. 10 - {!Jmap.Session}: Session object and discovery. 11 - {!Jmap.Methods}: Standard method patterns (/get, /set, etc.) and Core/echo. 12 - {!Jmap.Binary}: Binary data upload/download types. 13 - {!Jmap.Push}: Push notification types (StateChange, PushSubscription). 14 - {!Jmap.Email}: Mail extension (RFC 8621) types and methods. 15 16 @see <https://www.rfc-editor.org/rfc/rfc8620.html> RFC 8620: Core JMAP 17 @see <https://www.rfc-editor.org/rfc/rfc8621.html> RFC 8621: JMAP for Mail 18*) 19 20(** {1 Core JMAP Types and Modules} *) 21 22module Types = Jmap_types 23module Error = Jmap_error 24module Wire = Jmap_wire 25module Session = Jmap_session 26module Methods = Jmap_methods 27module Binary = Jmap_binary 28module Push = Jmap_push 29module Vacation = Jmap_vacation 30 31(** 32{[ 33 (* OCaml 5.1 required for Lwt let operators *) 34 open Lwt.Syntax 35 open Jmap 36 open Jmap.Types 37 open Jmap.Wire 38 open Jmap.Methods 39 open Jmap.Email 40 41 let list_unread_from_sender ctx session sender_email = 42 (* Find the primary mail account *) 43 let primary_mail_account_id = 44 Hashtbl.find session.primary_accounts capability_mail 45 in 46 (* Construct the filter *) 47 let filter : filter = 48 Filter_operator (Filter_operator.v 49 ~operator:`AND 50 ~conditions:[ 51 Filter_condition (Yojson.Safe.to_basic (`Assoc [ 52 ("from", `String sender_email); 53 ])); 54 Filter_condition (Yojson.Safe.to_basic (`Assoc [ 55 ("hasKeyword", `String keyword_seen); 56 ("value", `Bool false); 57 ])); 58 ] 59 ()) 60 in 61 (* Prepare the Email/query invocation *) 62 let query_args = Query_args.v 63 ~account_id:primary_mail_account_id 64 ~filter 65 ~sort:[ 66 Comparator.v 67 ~property:"receivedAt" 68 ~is_ascending:false 69 () 70 ] 71 ~position:0 72 ~limit:20 (* Get latest 20 *) 73 ~calculate_total:false 74 ~collapse_threads:false 75 () 76 in 77 let query_invocation = Invocation.v 78 ~method_name:"Email/query" 79 ~arguments:(* Yojson conversion of query_args needed here *) 80 ~method_call_id:"q1" 81 () 82 in 83 84 (* Prepare the Email/get invocation using a back-reference *) 85 let get_args = Get_args.v 86 ~account_id:primary_mail_account_id 87 ~properties:["id"; "subject"; "receivedAt"; "from"] 88 () 89 in 90 let get_invocation = Invocation.v 91 ~method_name:"Email/get" 92 ~arguments:(* Yojson conversion of get_args, with ids replaced by a ResultReference to q1 needed here *) 93 ~method_call_id:"g1" 94 () 95 in 96 97 (* Prepare the JMAP request *) 98 let request = Request.v 99 ~using:[ capability_core; Email.capability_mail ] 100 ~method_calls:[ query_invocation; get_invocation ] 101 () 102 in 103 104 (* Send the request *) 105 let* response = Jmap.Unix.request ctx request in 106 107 (* Process the response (extract Email/get results) *) 108 (* ... Omitted: find the Email/get response in response.method_responses ... *) 109 Lwt.return_unit 110 111 let main () = 112 (* Authentication details are placeholder *) 113 let credentials = "my_auth_token" in 114 let* (ctx, session) = Jmap.Unix.connect ~host:"jmap.example.com" ~credentials in 115 let* () = list_unread_from_sender ctx session "boss@example.com" in 116 Jmap.Unix.close ctx 117 118 (* Lwt_main.run (main ()) *) 119]} *) 120 121(** Capability URI for JMAP Core. 122 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-2> RFC 8620, Section 2 *) 123val capability_core : string