forked from
anil.recoil.org/ocaml-jmap
this repo has no description
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6module Value = struct
7 type t = {
8 value : string;
9 is_encoding_problem : bool;
10 is_truncated : bool;
11 }
12
13 let value t = t.value
14 let is_encoding_problem t = t.is_encoding_problem
15 let is_truncated t = t.is_truncated
16
17 let make value is_encoding_problem is_truncated =
18 { value; is_encoding_problem; is_truncated }
19
20 let jsont =
21 let kind = "EmailBodyValue" in
22 Jsont.Object.map ~kind make
23 |> Jsont.Object.mem "value" Jsont.string ~enc:value
24 |> Jsont.Object.mem "isEncodingProblem" Jsont.bool ~dec_absent:false
25 ~enc:is_encoding_problem ~enc_omit:(fun b -> not b)
26 |> Jsont.Object.mem "isTruncated" Jsont.bool ~dec_absent:false
27 ~enc:is_truncated ~enc_omit:(fun b -> not b)
28 |> Jsont.Object.finish
29end
30
31module Part = struct
32 type t = {
33 part_id : string option;
34 blob_id : Proto_id.t option;
35 size : int64 option;
36 headers : Mail_header.t list option;
37 name : string option;
38 type_ : string;
39 charset : string option;
40 disposition : string option;
41 cid : string option;
42 language : string list option;
43 location : string option;
44 sub_parts : t list option;
45 }
46
47 let part_id t = t.part_id
48 let blob_id t = t.blob_id
49 let size t = t.size
50 let headers t = t.headers
51 let name t = t.name
52 let type_ t = t.type_
53 let charset t = t.charset
54 let disposition t = t.disposition
55 let cid t = t.cid
56 let language t = t.language
57 let location t = t.location
58 let sub_parts t = t.sub_parts
59
60 let rec jsont =
61 let kind = "EmailBodyPart" in
62 let make part_id blob_id size headers name type_ charset disposition
63 cid language location sub_parts =
64 { part_id; blob_id; size; headers; name; type_; charset; disposition;
65 cid; language; location; sub_parts }
66 in
67 (* Many fields can be null per RFC 8621 Section 4.1.4 *)
68 lazy (
69 Jsont.Object.map ~kind make
70 |> Jsont.Object.mem "partId" Jsont.(option string)
71 ~dec_absent:None ~enc_omit:Option.is_none ~enc:part_id
72 |> Jsont.Object.mem "blobId" Jsont.(option Proto_id.jsont)
73 ~dec_absent:None ~enc_omit:Option.is_none ~enc:blob_id
74 |> Jsont.Object.opt_mem "size" Proto_int53.Unsigned.jsont ~enc:size
75 |> Jsont.Object.opt_mem "headers" (Jsont.list Mail_header.jsont) ~enc:headers
76 |> Jsont.Object.mem "name" Jsont.(option string)
77 ~dec_absent:None ~enc_omit:Option.is_none ~enc:name
78 |> Jsont.Object.mem "type" Jsont.string ~enc:type_
79 |> Jsont.Object.mem "charset" Jsont.(option string)
80 ~dec_absent:None ~enc_omit:Option.is_none ~enc:charset
81 |> Jsont.Object.mem "disposition" Jsont.(option string)
82 ~dec_absent:None ~enc_omit:Option.is_none ~enc:disposition
83 |> Jsont.Object.mem "cid" Jsont.(option string)
84 ~dec_absent:None ~enc_omit:Option.is_none ~enc:cid
85 |> Jsont.Object.opt_mem "language" (Jsont.list Jsont.string) ~enc:language
86 |> Jsont.Object.mem "location" Jsont.(option string)
87 ~dec_absent:None ~enc_omit:Option.is_none ~enc:location
88 |> Jsont.Object.opt_mem "subParts" (Jsont.list (Jsont.rec' jsont)) ~enc:sub_parts
89 |> Jsont.Object.finish
90 )
91
92 let jsont = Lazy.force jsont
93end