My agentic slop goes here. Not intended for anyone else!
1(** Email object property identifiers implementation.
2
3 This module implements property identification and conversion utilities
4 for Email objects as specified in RFC 8621 Section 4.1.
5
6 @see <https://www.rfc-editor.org/rfc/rfc8621.html#section-4.1> RFC 8621, Section 4.1
7*)
8
9type t = [
10 | `Id
11 | `BlobId
12 | `ThreadId
13 | `MailboxIds
14 | `Keywords
15 | `Size
16 | `ReceivedAt
17 | `MessageId
18 | `InReplyTo
19 | `References
20 | `Sender
21 | `From
22 | `To
23 | `Cc
24 | `Bcc
25 | `ReplyTo
26 | `Subject
27 | `SentAt
28 | `HasAttachment
29 | `Preview
30 | `BodyStructure
31 | `BodyValues
32 | `TextBody
33 | `HtmlBody
34 | `Attachments
35 | `Header of string
36 | `Other of string
37]
38
39let to_string = function
40 | `Id -> "id"
41 | `BlobId -> "blobId"
42 | `ThreadId -> "threadId"
43 | `MailboxIds -> "mailboxIds"
44 | `Keywords -> "keywords"
45 | `Size -> "size"
46 | `ReceivedAt -> "receivedAt"
47 | `MessageId -> "messageId"
48 | `InReplyTo -> "inReplyTo"
49 | `References -> "references"
50 | `Sender -> "sender"
51 | `From -> "from"
52 | `To -> "to"
53 | `Cc -> "cc"
54 | `Bcc -> "bcc"
55 | `ReplyTo -> "replyTo"
56 | `Subject -> "subject"
57 | `SentAt -> "sentAt"
58 | `HasAttachment -> "hasAttachment"
59 | `Preview -> "preview"
60 | `BodyStructure -> "bodyStructure"
61 | `BodyValues -> "bodyValues"
62 | `TextBody -> "textBody"
63 | `HtmlBody -> "htmlBody"
64 | `Attachments -> "attachments"
65 | `Header s -> Printf.sprintf "header:%s" s
66 | `Other s -> s
67
68let of_string = function
69 | "id" -> `Id
70 | "blobId" -> `BlobId
71 | "threadId" -> `ThreadId
72 | "mailboxIds" -> `MailboxIds
73 | "keywords" -> `Keywords
74 | "size" -> `Size
75 | "receivedAt" -> `ReceivedAt
76 | "messageId" -> `MessageId
77 | "inReplyTo" -> `InReplyTo
78 | "references" -> `References
79 | "sender" -> `Sender
80 | "from" -> `From
81 | "to" -> `To
82 | "cc" -> `Cc
83 | "bcc" -> `Bcc
84 | "replyTo" -> `ReplyTo
85 | "subject" -> `Subject
86 | "sentAt" -> `SentAt
87 | "hasAttachment" -> `HasAttachment
88 | "preview" -> `Preview
89 | "bodyStructure" -> `BodyStructure
90 | "bodyValues" -> `BodyValues
91 | "textBody" -> `TextBody
92 | "htmlBody" -> `HtmlBody
93 | "attachments" -> `Attachments
94 | s when String.starts_with ~prefix:"header:" s ->
95 `Header (String.sub s 7 (String.length s - 7))
96 | s -> `Other s
97
98let common_list_properties = [
99 `Id; `ThreadId; `MailboxIds; `Keywords; `From; `To; `Subject;
100 `ReceivedAt; `HasAttachment; `Preview
101]
102
103let detailed_view_properties = [
104 `Id; `BlobId; `ThreadId; `MailboxIds; `Keywords; `Size;
105 `ReceivedAt; `MessageId; `InReplyTo; `References; `Sender;
106 `From; `To; `Cc; `Bcc; `ReplyTo; `Subject; `SentAt;
107 `HasAttachment; `Preview; `TextBody; `HtmlBody; `Attachments
108]
109
110let minimal_properties = [
111 `Id; `ThreadId; `MailboxIds; `ReceivedAt
112]
113
114let to_string_list properties = List.map to_string properties
115
116let of_string_list strings = List.map of_string strings
117
118(* Property Set Builders *)
119
120let with_headers ?(base = common_list_properties) ~headers () =
121 let header_properties = List.map (fun h -> `Header h) headers in
122 base @ header_properties
123
124let minimal_for_query () =
125 [`Id; `ThreadId; `MailboxIds; `ReceivedAt]
126
127let for_preview () =
128 [`Id; `ThreadId; `From; `Subject; `ReceivedAt; `Preview; `Keywords; `HasAttachment]
129
130let for_reading () =
131 [`Id; `BlobId; `ThreadId; `MailboxIds; `Keywords; `Size; `ReceivedAt;
132 `MessageId; `InReplyTo; `References; `Sender; `From; `To; `Cc; `Bcc;
133 `ReplyTo; `Subject; `SentAt; `HasAttachment; `Preview; `BodyStructure;
134 `TextBody; `HtmlBody; `Attachments]
135
136let for_composition () =
137 [`Id; `ThreadId; `MessageId; `InReplyTo; `References; `From; `To; `Cc;
138 `ReplyTo; `Subject; `SentAt; `BodyStructure; `TextBody; `HtmlBody]