My agentic slop goes here. Not intended for anyone else!
1(** Email response parsing using core JMAP parsers.
2
3 This module provides type-safe response parsing for Email method responses,
4 leveraging the core JMAP response parsers to eliminate manual JSON parsing.
5
6 @see <https://www.rfc-editor.org/rfc/rfc8621.html> RFC 8621 *)
7
8open Jmap.Methods
9
10(** {1 Response Parsers} *)
11
12(** Parse Email/get response using core parsers.
13 @param from_json Function to parse individual email JSON
14 @param json The JSON response from Email/get
15 @return Parsed Get_response or error *)
16val parse_get_response : from_json:(Yojson.Safe.t -> 'email) -> Yojson.Safe.t -> ('email Get_response.t, Jmap.Error.error) result
17
18(** Parse Email/query response using core parsers.
19 @param json The JSON response from Email/query
20 @return Parsed Query_response or error *)
21val parse_query_response : Yojson.Safe.t -> (Query_response.t, Jmap.Error.error) result
22
23(** Parse Email/changes response using core parsers.
24 @param json The JSON response from Email/changes
25 @return Parsed Changes_response or error *)
26val parse_changes_response : Yojson.Safe.t -> (Changes_response.t, Jmap.Error.error) result
27
28(** Parse Email/set response using core parsers.
29 @param json The JSON response from Email/set
30 @return Parsed Set_response or error *)
31val parse_set_response :
32 Yojson.Safe.t ->
33 ((Yojson.Safe.t, Yojson.Safe.t) Set_response.t, Jmap.Error.error) result
34
35(** {1 Response Data Extractors} *)
36
37(** Extract email list from a Get_response.
38 @param response The parsed Get_response
39 @return List of Email objects *)
40val emails_from_get_response : 'email Get_response.t -> 'email list
41
42(** Extract IDs from a Query_response.
43 @param response The parsed Query_response
44 @return List of Email IDs *)
45val ids_from_query_response : Query_response.t -> Jmap.Id.t list
46
47(** Check if there are more changes in a Changes_response.
48 @param response The parsed Changes_response
49 @return True if there are more changes to fetch *)
50val has_more_changes : Changes_response.t -> bool
51
52(** Get created IDs from a Changes_response.
53 @param response The parsed Changes_response
54 @return List of newly created Email IDs *)
55val created_ids : Changes_response.t -> Jmap.Id.t list
56
57(** Get updated IDs from a Changes_response.
58 @param response The parsed Changes_response
59 @return List of updated Email IDs *)
60val updated_ids : Changes_response.t -> Jmap.Id.t list
61
62(** Get destroyed IDs from a Changes_response.
63 @param response The parsed Changes_response
64 @return List of destroyed Email IDs *)
65val destroyed_ids : Changes_response.t -> Jmap.Id.t list
66
67(** {1 Batch Response Handling} *)
68
69(** Module for handling batched JMAP responses with multiple method calls *)
70module Batch : sig
71 (** Container for multiple method responses in a single JMAP response *)
72 type 'email batch_response = {
73 get_responses : (string * 'email Get_response.t) list;
74 query_responses : (string * Query_response.t) list;
75 set_responses : (string * (Yojson.Safe.t, Yojson.Safe.t) Set_response.t) list;
76 changes_responses : (string * Changes_response.t) list;
77 }
78
79 (** Empty batch response *)
80 val empty : 'email batch_response
81
82 (** Add a Get response to the batch *)
83 val add_get_response :
84 method_call_id:string ->
85 'email Get_response.t ->
86 'email batch_response ->
87 'email batch_response
88
89 (** Add a Query response to the batch *)
90 val add_query_response :
91 method_call_id:string ->
92 Query_response.t ->
93 'email batch_response ->
94 'email batch_response
95
96 (** Add a Set response to the batch *)
97 val add_set_response :
98 method_call_id:string ->
99 (Yojson.Safe.t, Yojson.Safe.t) Set_response.t ->
100 'email batch_response ->
101 'email batch_response
102
103 (** Add a Changes response to the batch *)
104 val add_changes_response :
105 method_call_id:string ->
106 Changes_response.t ->
107 'email batch_response ->
108 'email batch_response
109
110 (** Parse a full JMAP response with multiple method calls.
111 Automatically identifies and parses Email/get, Email/query, Email/set,
112 and Email/changes responses.
113 @param from_json Function to parse individual email JSON
114 @param json The full JMAP response JSON
115 @return Batch response with all parsed method responses *)
116 val parse_response : from_json:(Yojson.Safe.t -> 'email) -> Yojson.Safe.t -> 'email batch_response
117end