this repo has no description
at main 3.5 kB view raw
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 let nullable_string = Jsont.(option string) in 69 let nullable_id = Jsont.(option Proto_id.jsont) in 70 lazy ( 71 Jsont.Object.map ~kind make 72 |> Jsont.Object.mem "partId" nullable_string 73 ~dec_absent:None ~enc_omit:Option.is_none ~enc:part_id 74 |> Jsont.Object.mem "blobId" nullable_id 75 ~dec_absent:None ~enc_omit:Option.is_none ~enc:blob_id 76 |> Jsont.Object.opt_mem "size" Proto_int53.Unsigned.jsont ~enc:size 77 |> Jsont.Object.opt_mem "headers" (Jsont.list Mail_header.jsont) ~enc:headers 78 |> Jsont.Object.mem "name" nullable_string 79 ~dec_absent:None ~enc_omit:Option.is_none ~enc:name 80 |> Jsont.Object.mem "type" Jsont.string ~enc:type_ 81 |> Jsont.Object.mem "charset" nullable_string 82 ~dec_absent:None ~enc_omit:Option.is_none ~enc:charset 83 |> Jsont.Object.mem "disposition" nullable_string 84 ~dec_absent:None ~enc_omit:Option.is_none ~enc:disposition 85 |> Jsont.Object.mem "cid" nullable_string 86 ~dec_absent:None ~enc_omit:Option.is_none ~enc:cid 87 |> Jsont.Object.opt_mem "language" (Jsont.list Jsont.string) ~enc:language 88 |> Jsont.Object.mem "location" nullable_string 89 ~dec_absent:None ~enc_omit:Option.is_none ~enc:location 90 |> Jsont.Object.opt_mem "subParts" (Jsont.list (Jsont.rec' jsont)) ~enc:sub_parts 91 |> Jsont.Object.finish 92 ) 93 94 let jsont = Lazy.force jsont 95end