forked from
anil.recoil.org/ocaml-imap
IMAP in OCaml
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Sequence Sets
7
8 IMAP sequence sets for addressing messages by sequence number or UID.
9 See RFC 9051 Section 9. *)
10
11type range =
12 | Single of int (** A single message number *)
13 | Range of int * int (** An inclusive range [a:b] *)
14 | From of int (** From n to the end [n:*] *)
15 | All (** All messages [*] *)
16
17let pp_range ppf = function
18 | Single n -> Fmt.int ppf n
19 | Range (a, b) -> Fmt.pf ppf "%d:%d" a b
20 | From n -> Fmt.pf ppf "%d:*" n
21 | All -> Fmt.string ppf "*"
22
23type t = range list
24
25let pp ppf set = Fmt.(list ~sep:comma pp_range) ppf set
26let to_string set = Fmt.str "%a" pp set
27
28let single n = [ Single n ]
29let range a b = [ Range (a, b) ]
30let from n = [ From n ]
31let all = [ All ]