IMAP in OCaml

metadata

+214 -46
+14 -12
.gitignore
··· 1 + # OCaml build artifacts 1 2 _build/ 2 - _opam/ 3 3 *.install 4 4 *.merlin 5 - .merlin 6 - *.byte 7 - *.native 8 - *.cmo 9 - *.cmi 10 - *.cma 11 - *.cmx 12 - *.cmxa 13 - *.o 14 - *.a 15 - *.so 5 + 6 + # Third-party sources (fetch locally with opam source) 7 + third_party/ 8 + 9 + # Editor and OS files 10 + .DS_Store 11 + *.swp 12 + *~ 13 + .vscode/ 14 + .idea/ 15 + 16 + # Opam local switch 17 + _opam/
+1
.ocamlformat
··· 1 + version=0.28.1
+54
.tangled/workflows/build.yml
··· 1 + when: 2 + - event: ["push", "pull_request"] 3 + branch: ["main"] 4 + 5 + engine: nixery 6 + 7 + dependencies: 8 + nixpkgs: 9 + - shell 10 + - stdenv 11 + - findutils 12 + - binutils 13 + - libunwind 14 + - ncurses 15 + - opam 16 + - git 17 + - gawk 18 + - gnupatch 19 + - gnum4 20 + - gnumake 21 + - gnutar 22 + - gnused 23 + - gnugrep 24 + - diffutils 25 + - gzip 26 + - bzip2 27 + - gcc 28 + - ocaml 29 + - pkg-config 30 + - linux-pam 31 + 32 + steps: 33 + - name: opam 34 + command: | 35 + opam init --disable-sandboxing -a -y 36 + - name: repo 37 + command: | 38 + opam repo add aoah https://tangled.org/anil.recoil.org/aoah-opam-repo.git 39 + - name: switch 40 + command: | 41 + opam install . --confirm-level=unsafe-yes --deps-only 42 + - name: build 43 + command: | 44 + opam exec -- dune build 45 + - name: switch-test 46 + command: | 47 + opam install . --confirm-level=unsafe-yes --deps-only --with-test 48 + - name: test 49 + command: | 50 + opam exec -- dune runtest --verbose 51 + - name: doc 52 + command: | 53 + opam install -y odoc 54 + opam exec -- dune build @doc
+15
LICENSE.md
··· 1 + ISC License 2 + 3 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org> 4 + 5 + Permission to use, copy, modify, and distribute this software for any 6 + purpose with or without fee is hereby granted, provided that the above 7 + copyright notice and this permission notice appear in all copies. 8 + 9 + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+2 -2
README.md
··· 212 212 213 213 ## License 214 214 215 - [License to be determined] 215 + ISC License. See [LICENSE.md](LICENSE.md) for details. 216 216 217 217 ## Contributing 218 218 219 - Report bugs at https://github.com/mtelvers/imapd/issues 219 + Report bugs at https://tangled.org/@anil.recoil.org/ocaml-imap/issues
+5
bin/imap_client.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Client - List recent emails with subject and date 2 7 3 8 A simple IMAP client that connects over TLS, logs in, and lists
+5
bin/main.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Server Entry Point 2 7 3 8 Implements {{:https://datatracker.ietf.org/doc/html/rfc9051}RFC 9051} IMAP4rev2 server.
+4
dune
··· 1 + ; Root dune file 2 + 3 + ; Ignore third_party directory (for fetched dependency sources) 4 + (data_only_dirs third_party)
+16 -18
dune-project
··· 1 - (lang dune 3.0) 1 + (lang dune 3.20) 2 2 3 3 (name imapd) 4 4 5 5 (generate_opam_files true) 6 6 7 7 (using menhir 2.1) 8 - 9 - (source 10 - (github mtelvers/imapd)) 11 - 12 - (authors "Mark Maybury") 13 - 14 - (maintainers "Mark Maybury") 15 8 16 9 (license ISC) 17 - 18 - (documentation https://github.com/mtelvers/imapd) 10 + (authors "Anil Madhavapeddy") 11 + (homepage "https://tangled.org/@anil.recoil.org/ocaml-imap") 12 + (maintainers "Anil Madhavapeddy <anil@recoil.org>") 13 + (bug_reports "https://tangled.org/@anil.recoil.org/ocaml-imap/issues") 14 + (maintenance_intent "(latest)") 19 15 20 16 (package 21 17 (name imapd) 22 - (synopsis "IMAP4rev2 server implemented in OCaml with EIO") 18 + (synopsis "IMAP4rev2 server implemented in OCaml with Eio") 23 19 (description 24 - "A modular IMAP4rev2 server (RFC 9051) implemented in OCaml using EIO for networking. Features pluggable storage backends (Memory, Maildir) and PAM authentication.") 20 + "A modular IMAP4rev2 server (RFC 9051) implemented in OCaml using Eio \ 21 + for networking. Features pluggable storage backends (Memory, Maildir) \ 22 + and PAM authentication.") 25 23 (depends 26 - (ocaml (>= 5.1)) 27 - (dune (>= 3.0)) 24 + (ocaml (>= 5.1.0)) 28 25 (menhir (>= 20230608)) 29 26 (eio (>= 1.0)) 30 27 (eio_main (>= 1.0)) 31 - (tls-eio (>= 0.15)) 32 - (tls (>= 0.15)) 28 + (tls-eio (>= 1.0)) 29 + (tls (>= 1.0)) 33 30 (faraday (>= 0.8)) 34 - (cmdliner (>= 1.2)) 31 + (cmdliner (>= 1.2.0)) 35 32 (conf-libpam :build) 36 - (alcotest (and (>= 1.7) :with-test)))) 33 + (odoc :with-doc) 34 + (alcotest (and :with-test (>= 1.7.0)))))
+13 -14
imapd.opam
··· 1 1 # This file is generated by dune, edit dune-project instead 2 2 opam-version: "2.0" 3 - synopsis: "IMAP4rev2 server implemented in OCaml with EIO" 3 + synopsis: "IMAP4rev2 server implemented in OCaml with Eio" 4 4 description: 5 - "A modular IMAP4rev2 server (RFC 9051) implemented in OCaml using EIO for networking. Features pluggable storage backends (Memory, Maildir) and PAM authentication." 6 - maintainer: ["Mark Maybury"] 7 - authors: ["Mark Maybury"] 5 + "A modular IMAP4rev2 server (RFC 9051) implemented in OCaml using Eio for networking. Features pluggable storage backends (Memory, Maildir) and PAM authentication." 6 + maintainer: ["Anil Madhavapeddy <anil@recoil.org>"] 7 + authors: ["Anil Madhavapeddy"] 8 8 license: "ISC" 9 - homepage: "https://github.com/mtelvers/imapd" 10 - doc: "https://github.com/mtelvers/imapd" 11 - bug-reports: "https://github.com/mtelvers/imapd/issues" 9 + homepage: "https://tangled.org/@anil.recoil.org/ocaml-imap" 10 + bug-reports: "https://tangled.org/@anil.recoil.org/ocaml-imap/issues" 12 11 depends: [ 13 - "ocaml" {>= "5.1"} 14 - "dune" {>= "3.0" & >= "3.0"} 12 + "dune" {>= "3.20"} 13 + "ocaml" {>= "5.1.0"} 15 14 "menhir" {>= "20230608"} 16 15 "eio" {>= "1.0"} 17 16 "eio_main" {>= "1.0"} 18 - "tls-eio" {>= "0.15"} 19 - "tls" {>= "0.15"} 17 + "tls-eio" {>= "1.0"} 18 + "tls" {>= "1.0"} 20 19 "faraday" {>= "0.8"} 21 - "cmdliner" {>= "1.2"} 20 + "cmdliner" {>= "1.2.0"} 22 21 "conf-libpam" {build} 23 - "alcotest" {>= "1.7" & with-test} 24 22 "odoc" {with-doc} 23 + "alcotest" {with-test & >= "1.7.0"} 25 24 ] 26 25 build: [ 27 26 ["dune" "subst"] {dev} ··· 37 36 "@doc" {with-doc} 38 37 ] 39 38 ] 40 - dev-repo: "git+https://github.com/mtelvers/imapd.git" 39 + x-maintenance-intent: ["(latest)"]
+5
lib/imap_auth/imap_auth.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP Authentication Module 2 7 3 8 Implements {{:https://datatracker.ietf.org/doc/html/rfc9051#section-6.2.3}RFC 9051 Section 6.2.3}
+5
lib/imap_auth/imap_auth.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP Authentication Module 2 7 3 8 This module provides authentication backends for the IMAP server.
+5
lib/imap_parser/imap_grammar.mly
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP Grammar - RFC 9051 Section 9 ABNF 2 7 3 8 Menhir grammar for IMAP4rev2 protocol parsing.
+5
lib/imap_parser/imap_lexer.mll
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP Lexer - RFC 9051 Section 9 ABNF 2 7 3 8 Implements lexical analysis for IMAP4rev2 protocol.
+5
lib/imap_parser/imap_parser.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Parser 2 7 3 8 Implements {{:https://datatracker.ietf.org/doc/html/rfc9051#section-9}RFC 9051 Section 9} Formal Syntax.
+5
lib/imap_parser/imap_parser.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Parser 2 7 3 8 Implements {{:https://datatracker.ietf.org/doc/html/rfc9051#section-9}RFC 9051 Section 9} Formal Syntax.
+5
lib/imap_server/imap_server.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Server 2 7 3 8 Implements {{:https://datatracker.ietf.org/doc/html/rfc9051}RFC 9051} state machine. *)
+5
lib/imap_server/imap_server.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Server 2 7 3 8 This module implements the IMAP server connection handler and state machine
+5
lib/imap_storage/imap_storage.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP Storage Backends 2 7 3 8 Implements storage for {{:https://datatracker.ietf.org/doc/html/rfc9051}RFC 9051}. *)
+5
lib/imap_storage/imap_storage.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP Storage Backends 2 7 3 8 This module provides pluggable storage backends for the IMAP server.
+5
lib/imap_types/imap_types.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Core Types 2 7 3 8 Implements types from {{:https://datatracker.ietf.org/doc/html/rfc9051}RFC 9051}. *)
+5
lib/imap_types/imap_types.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** IMAP4rev2 Core Types 2 7 3 8 This module defines the core types for the IMAP4rev2 protocol as specified in
+5
test/test_auth.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** Tests for imap_auth module *) 2 7 3 8 open Imap_auth
+5
test/test_parser.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** Tests for imap_parser module *) 2 7 3 8 open Imap_parser
+5
test/test_server.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** Integration tests for imap_server module *) 2 7 3 8 (* Note: Full connection handling tests require EIO mock flows which are complex to set up.
+5
test/test_storage.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** Tests for imap_storage module *) 2 7 3 8 open Imap_storage
+5
test/test_types.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 1 6 (** Tests for imap_types module *) 2 7 3 8 open Imap_types