(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) module Value = struct type t = { value : string; is_encoding_problem : bool; is_truncated : bool; } let value t = t.value let is_encoding_problem t = t.is_encoding_problem let is_truncated t = t.is_truncated let make value is_encoding_problem is_truncated = { value; is_encoding_problem; is_truncated } let jsont = let kind = "EmailBodyValue" in Jsont.Object.map ~kind make |> Jsont.Object.mem "value" Jsont.string ~enc:value |> Jsont.Object.mem "isEncodingProblem" Jsont.bool ~dec_absent:false ~enc:is_encoding_problem ~enc_omit:(fun b -> not b) |> Jsont.Object.mem "isTruncated" Jsont.bool ~dec_absent:false ~enc:is_truncated ~enc_omit:(fun b -> not b) |> Jsont.Object.finish end module Part = struct type t = { part_id : string option; blob_id : Proto_id.t option; size : int64 option; headers : Mail_header.t list option; name : string option; type_ : string; charset : string option; disposition : string option; cid : string option; language : string list option; location : string option; sub_parts : t list option; } let part_id t = t.part_id let blob_id t = t.blob_id let size t = t.size let headers t = t.headers let name t = t.name let type_ t = t.type_ let charset t = t.charset let disposition t = t.disposition let cid t = t.cid let language t = t.language let location t = t.location let sub_parts t = t.sub_parts let rec jsont = let kind = "EmailBodyPart" in let make part_id blob_id size headers name type_ charset disposition cid language location sub_parts = { part_id; blob_id; size; headers; name; type_; charset; disposition; cid; language; location; sub_parts } in (* Many fields can be null per RFC 8621 Section 4.1.4 *) lazy ( Jsont.Object.map ~kind make |> Jsont.Object.mem "partId" Jsont.(option string) ~dec_absent:None ~enc_omit:Option.is_none ~enc:part_id |> Jsont.Object.mem "blobId" Jsont.(option Proto_id.jsont) ~dec_absent:None ~enc_omit:Option.is_none ~enc:blob_id |> Jsont.Object.opt_mem "size" Proto_int53.Unsigned.jsont ~enc:size |> Jsont.Object.opt_mem "headers" (Jsont.list Mail_header.jsont) ~enc:headers |> Jsont.Object.mem "name" Jsont.(option string) ~dec_absent:None ~enc_omit:Option.is_none ~enc:name |> Jsont.Object.mem "type" Jsont.string ~enc:type_ |> Jsont.Object.mem "charset" Jsont.(option string) ~dec_absent:None ~enc_omit:Option.is_none ~enc:charset |> Jsont.Object.mem "disposition" Jsont.(option string) ~dec_absent:None ~enc_omit:Option.is_none ~enc:disposition |> Jsont.Object.mem "cid" Jsont.(option string) ~dec_absent:None ~enc_omit:Option.is_none ~enc:cid |> Jsont.Object.opt_mem "language" (Jsont.list Jsont.string) ~enc:language |> Jsont.Object.mem "location" Jsont.(option string) ~dec_absent:None ~enc_omit:Option.is_none ~enc:location |> Jsont.Object.opt_mem "subParts" (Jsont.list (Jsont.rec' jsont)) ~enc:sub_parts |> Jsont.Object.finish ) let jsont = Lazy.force jsont end