# sexfrance/imap-server architecture

> Architecture diagram of the GitHub repository sexfrance/imap-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sexfrance/imap-server
- Repository: https://github.com/sexfrance/imap-server

## Overview

Cybertemp IMAP Server accepts standard IMAP clients, authenticates access, and serves mailbox operations and filtered email from PostgreSQL. The principal flow is connection handling → login and subscription validation → mailbox selection and command execution → email retrieval, filtering, and response. The README also documents inbox management and cached domain checks. Runtime logic is concentrated in `src/main.rs`; excerpts show PostgreSQL authentication/email queries, Supabase ban requests, and optional at-rest decryption. Other documented command wiring is not fully visible in the sampled source.

Main entry points: [`src/main.rs`](https://github.com/sexfrance/imap-server/blob/main/src/main.rs) (IMAP commands), [`SQL/schema.sql`](https://github.com/sexfrance/imap-server/blob/main/SQL/schema.sql) (PostgreSQL), [`src/encryption.rs`](https://github.com/sexfrance/imap-server/blob/main/src/encryption.rs) (At-rest encryption)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["IMAP runtime"]
  node_listener["Connection listener<br/>[main.rs]"]
  node_connection["Connection handler<br/>[main.rs]"]
  node_imap["IMAP commands<br/>[main.rs]"]
end

subgraph group_access["Access controls"]
  node_auth["Token authentication<br/>[main.rs]"]
  node_subscription["Subscription check<br/>[main.rs]"]
  node_domain["Domain validation<br/>[main.rs]"]
  node_bans["Ban enforcement<br/>[main.rs]"]
  node_cache["Domain cache<br/>[main.rs]"]
end

subgraph group_mail["Mailbox and mail"]
  node_inbox["Inbox management<br/>[main.rs]"]
  node_retrieval["Email retrieval<br/>[main.rs]"]
  node_filter["Email filtering<br/>[main.rs]"]
  node_mime["MIME extraction<br/>[main.rs]"]
  node_crypto["At-rest encryption<br/>[encryption.rs]"]
end

node_client(("IMAP client"))
node_postgres[("PostgreSQL<br/>[schema.sql]")]
node_supabase["Supabase API"]

node_client -->|"connects"| node_listener
node_listener -->|"spawns handler"| node_connection
node_connection -->|"serves IMAP"| node_client
node_connection -->|"checks login"| node_auth
node_auth -->|"queries tokens"| node_postgres
node_auth -->|"validates access"| node_subscription
node_subscription -->|"reads user status"| node_postgres
node_connection -->|"dispatches commands"| node_imap
node_imap -->|"manages mailboxes"| node_inbox
node_imap -->|"checks domains"| node_domain
node_domain -->|"uses cached domains"| node_cache
node_domain -.->|"fetches domains"| node_supabase
node_imap -->|"checks bans"| node_bans
node_bans -.->|"queries bans"| node_supabase
node_bans -.->|"uses local bans"| node_postgres
node_imap -->|"loads mailbox"| node_retrieval
node_retrieval -->|"reads emails"| node_postgres
node_retrieval -->|"decrypts payloads"| node_crypto
node_imap -->|"filters results"| node_filter
node_imap -->|"extracts text"| node_mime

click node_listener "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_connection "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_imap "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_auth "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_subscription "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_domain "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_bans "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_cache "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_inbox "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_retrieval "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_filter "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_mime "https://github.com/sexfrance/imap-server/blob/main/src/main.rs"
click node_crypto "https://github.com/sexfrance/imap-server/blob/main/src/encryption.rs"
click node_postgres "https://github.com/sexfrance/imap-server/blob/main/SQL/schema.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_listener,node_connection,node_imap,node_client toneBlue
class node_auth,node_subscription,node_domain,node_bans,node_cache,node_postgres toneAmber
class node_inbox,node_retrieval,node_filter,node_mime,node_crypto,node_supabase toneMint
```

## Components

### IMAP runtime

- [Connection listener](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Connection handler](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [IMAP commands](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`

### Access controls

- [Token authentication](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Subscription check](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Domain validation](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Ban enforcement](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Domain cache](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`

### Mailbox and mail

- [Inbox management](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Email retrieval](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [Email filtering](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [MIME extraction](https://github.com/sexfrance/imap-server/blob/main/src/main.rs): `src/main.rs`
- [At-rest encryption](https://github.com/sexfrance/imap-server/blob/main/src/encryption.rs): `src/encryption.rs`

### Other components

- **IMAP client**
- [PostgreSQL](https://github.com/sexfrance/imap-server/blob/main/SQL/schema.sql): `SQL/schema.sql`
- **Supabase API**

## Connections

- IMAP client → Connection listener: connects
- Connection listener → Connection handler: spawns handler
- Connection handler → IMAP client: serves IMAP
- Connection handler → Token authentication: checks login
- Token authentication → PostgreSQL: queries tokens
- Token authentication → Subscription check: validates access
- Subscription check → PostgreSQL: reads user status
- Connection handler → IMAP commands: dispatches commands
- IMAP commands → Inbox management: manages mailboxes
- IMAP commands → Domain validation: checks domains
- Domain validation → Domain cache: uses cached domains
- Domain validation → Supabase API: fetches domains
- IMAP commands → Ban enforcement: checks bans
- Ban enforcement → Supabase API: queries bans
- Ban enforcement → PostgreSQL: uses local bans
- IMAP commands → Email retrieval: loads mailbox
- Email retrieval → PostgreSQL: reads emails
- Email retrieval → At-rest encryption: decrypts payloads
- IMAP commands → Email filtering: filters results
- IMAP commands → MIME extraction: extracts text
