···
1
-
# JMAP Library Architecture - TODO List
1
+
# JMAP Implementation TODO - Missing Fields and Incomplete Parsers/Serializers
3
-
## **Major Architecture Update (January 2025)**
3
+
**Status**: Analysis completed January 2025. While the codebase has excellent architectural foundations, there are significant gaps between the current implementation and full RFC compliance. **Approximately 30-40% of critical functionality is missing**, primarily in advanced parsing, envelope handling, and method response integration.
5
-
### 🔄 **Architecture Pivot: From DSL to ADT-based Design**
7
-
The library has undergone a significant architectural change, moving from a complex GADT-based DSL to a simpler ADT-based approach with abstract types and constructor functions.
9
-
**Previous Architecture (REMOVED)**:
10
-
- `jmap-dsl` module with GADT-based method chaining
11
-
- Complex type-level programming with `@>` operators
12
-
- Automatic method execution and response deserialization
14
-
**New Architecture (IMPLEMENTED)**:
15
-
- ADT-based method construction with `Jmap_method` module
16
-
- Type-safe response parsing with `Jmap_response` module
17
-
- High-level request building with `Jmap_request` module
18
-
- Constructor functions with optional arguments and sensible defaults
19
-
- Abstract types for better encapsulation
7
+
Based on systematic analysis of JMAP specifications (RFC 8620/8621) against current implementation, this document tracks all missing fields and incomplete implementations that need to be addressed for full JMAP compliance.
23
-
## **✅ Completed in This Refactoring**
11
+
## **1. Missing Fields by Module**
25
-
### 1. **Core ADT Infrastructure**
26
-
- [x] Removed `jmap-dsl` module completely
27
-
- [x] Created `Jmap_method` module with:
28
-
- Abstract type `t` for methods
29
-
- Constructor functions for all JMAP methods
30
-
- Optional arguments with sensible defaults
31
-
- Internal JSON serialization
32
-
- Basic jmap-sigs METHOD_ARGS integration
33
-
- [x] Created `Jmap_response` module with:
34
-
- Abstract type `t` for responses
35
-
- Pattern matching support via `response_type`
36
-
- Typed accessor modules for each method
37
-
- Safe extraction functions with Result types
38
-
- Full jmap-sigs METHOD_RESPONSE signature compliance
39
-
- [x] Created `Jmap_request` module with:
40
-
- Type-safe request building
41
-
- Method management and call ID generation
42
-
- Result reference support
43
-
- Wire protocol conversion
13
+
### **Core Session Management** ✅ **LARGELY COMPLETE**
14
+
**File:** `jmap/session.ml`
15
+
- [x] **Complete**: Session object with all required RFC fields
16
+
- [x] **Complete**: Core_capability with all limits
17
+
- [x] **Complete**: Account object structure
18
+
- [ ] **Minor Gap**: Collation algorithm validation logic missing
45
-
### 2. **Method Constructors Implemented**
47
-
- [x] Email/query, Email/get, Email/set, Email/changes, Email/copy, Email/import, Email/parse
48
-
- [x] Mailbox/query, Mailbox/get, Mailbox/set, Mailbox/changes
49
-
- [x] Thread/get, Thread/changes
50
-
- [x] Identity/get, Identity/set, Identity/changes
51
-
- [x] EmailSubmission/set, EmailSubmission/query, EmailSubmission/get, EmailSubmission/changes
52
-
- [x] VacationResponse/get, VacationResponse/set
53
-
- [x] SearchSnippet/get
20
+
### **Email Objects** ❌ **CRITICAL GAPS**
21
+
**File:** `jmap-email/email.ml`
55
-
### 3. **Response Parsers Implemented**
56
-
- [x] All method response types with typed accessors
57
-
- [x] Error response handling
58
-
- [x] Pattern matching support for response type discrimination
23
+
**Missing Fields (2 critical):**
24
+
- [ ] `bodyHeaders` - Map of partId → raw headers for each body part
25
+
- [ ] Enhanced `references` validation
60
-
### 4. **jmap-sigs Integration & Code Quality**
61
-
- [x] Fixed all build warnings by implementing missing parser cases
62
-
- [x] Removed unused opens and cleaned up code structure
63
-
- [x] Applied jmap-sigs METHOD_RESPONSE signature to all response modules
64
-
- [x] Simplified interface files using signature includes
65
-
- [x] Consistent error handling with Jmap_error.error throughout
66
-
- [x] ~29% reduction in jmap_response.mli interface size (364 → 259 lines)
67
-
- [x] Clean builds with no warnings: `opam exec -- dune build @check`
68
-
- [x] Documentation builds successfully: `opam exec -- dune build @doc`
27
+
**Missing Advanced Parsers (8 critical):**
28
+
- [ ] Header `asRaw` access pattern
29
+
- [ ] Header `asText` access pattern
30
+
- [ ] Header `asAddresses` access pattern
31
+
- [ ] Header `asGroupedAddresses` access pattern
32
+
- [ ] Header `asMessageIds` access pattern
33
+
- [ ] Header `asDate` access pattern
34
+
- [ ] Header `asURLs` access pattern
35
+
- [ ] RFC 2047 encoded header decoding
70
-
### 5. **Complete Module Restructuring with `type t` Pattern (NEW)**
71
-
- [x] **Core Type Modules**: Restructured `jmap_types` into focused modules:
72
-
- `jmap_id.mli/ml` - JMAP Id type with base64url validation and JSONABLE
73
-
- `jmap_date.mli/ml` - JMAP Date type with RFC 3339 support and JSONABLE
74
-
- `jmap_uint.mli/ml` - JMAP UnsignedInt type with range validation and JSONABLE
75
-
- `jmap_patch.mli/ml` - JMAP Patch Object for property updates and JSONABLE
76
-
- All with abstract `type t` and complete JSON serialization/deserialization
37
+
### **EmailBodyPart Objects** ❌ **PARSER GAPS**
38
+
**File:** `jmap-email/body.ml`
78
-
- [x] **Email Type Modules**: Broke up `jmap_email_types` into focused modules:
79
-
- `jmap_email_address.mli/ml` - Email addresses with Group submodule and JSONABLE
80
-
- `jmap_email_keywords.mli/ml` - Email keywords/flags with set operations and JSONABLE
81
-
- `jmap_email_property.mli/ml` - Property selection variants with string conversion
82
-
- `jmap_email_header.mli/ml` - Email header fields with JSONABLE
83
-
- `jmap_email_body.mli/ml` - MIME body parts with Value submodule and JSONABLE
84
-
- `jmap_email.mli/ml` - Main Email object with Property/Patch submodules and JSONABLE
85
-
- All following canonical `type t` pattern with proper encapsulation
40
+
**Missing Fields (1):**
41
+
- [ ] Self-referential `bodyStructure` for complex nested parts
87
-
- [x] **JMAP Object Modules**: Completely rewrote all JMAP object modules:
88
-
- `jmap_mailbox.mli/ml` - Mailbox with Role, Rights, Property, method submodules
89
-
- `jmap_identity.mli/ml` - Identity with Create, Update, method submodules
90
-
- `jmap_submission.mli/ml` - EmailSubmission with Envelope, DeliveryStatus submodules
91
-
- `jmap_vacation.mli/ml` - VacationResponse with Update, method submodules
92
-
- All with abstract `type t`, full JSONABLE, and complete JMAP method support
43
+
**Incomplete Implementations:**
44
+
- [ ] Multipart/* vs single part validation
45
+
- [ ] MIME type parameter parsing
46
+
- [ ] Character set conversion logic
47
+
- [ ] Content-Transfer-Encoding handling
94
-
- [x] **Module Pattern Consistency**: Every module follows canonical patterns:
95
-
- Abstract `type t` as primary type in each module and submodule
96
-
- `include Jmap_sigs.JSONABLE with type t := t` for all wire types
97
-
- Smart constructors with validation using Result-based error handling
98
-
- Comprehensive RFC 8620/8621 documentation with proper hyperlinks
99
-
- Encapsulated accessors instead of direct field access
100
-
- Consistent error handling with `Jmap_error.error` throughout
49
+
### **EmailSubmission Objects** ❌ **MAJOR FUNCTIONALITY GAPS**
50
+
**File:** `jmap-email/submission.ml`
102
-
- [x] **Build System Integration**:
103
-
- Updated all `dune` files for new module structure
104
-
- Added module aliases in `jmap.mli` (Id, Date, UInt, Patch modules)
105
-
- Fixed all build errors and module reference issues
106
-
- Added comprehensive Set_error JSON serialization support
107
-
- Core libraries build cleanly: `opam exec -- dune build jmap/ jmap-sigs/`
52
+
**Critical Stubbed Functions (7 locations):**
53
+
- [ ] Line 239: `envelope_to_json` - Returns placeholder
54
+
- [ ] Line 243: `delivery_status_to_json` - Returns placeholder
55
+
- [ ] Line 327: `envelope_of_json` - Returns empty envelope
56
+
- [ ] Line 331: `delivery_status_of_json` - Returns empty status
57
+
- [ ] Line 376: `delivery_status_list_to_json` - Returns null
58
+
- [ ] Line 437: Full envelope JSON serialization stubbed
59
+
- [ ] Line 461: Full delivery status JSON serialization stubbed
61
+
**Impact**: EmailSubmission create/update operations completely non-functional
111
-
## **🚨 CRITICAL ARCHITECTURAL ISSUES IDENTIFIED (January 2025)**
63
+
### **Mailbox Objects** ✅ **NEARLY COMPLETE**
64
+
**File:** `jmap-email/mailbox.ml`
113
-
### **Issue 1: Eio Dependency Leakage in jmap-email** 🔴
66
+
**Missing Fields (1 minor):**
67
+
- [ ] `sharedWith` - Sharing permissions for shared mailboxes
115
-
**Problem**: The `jmap-email` library incorrectly depends on `Eio_unix.Stdenv.base` in several modules, violating the layered architecture.
69
+
**Complete**: All other 11 required fields including MailboxRights
117
-
**Files Affected**:
118
-
- `jmap-email/jmap_email_methods.mli` - 5+ functions taking `env:Eio_unix.Stdenv.base`
119
-
- `jmap-email/jmap_email_query.mli` - 2 functions with Eio parameters
120
-
- `jmap-email/jmap_email_batch.mli` - 5+ functions with Eio parameters
71
+
### **Thread Objects** ⚠️ **BASIC IMPLEMENTATION**
72
+
**File:** `jmap-email/thread.ml`
123
-
- ❌ Makes `jmap-email` non-portable (should be platform-agnostic)
124
-
- ❌ Creates circular dependency risk between `jmap-email` and `jmap-unix`
125
-
- ❌ Violates clean architecture principles
74
+
**Fields Complete (2/2)**: id, emailIds
127
-
**Solution**: Move all Eio-dependent functions to `jmap-unix`, keeping `jmap-email` pure.
76
+
**Missing Functionality:**
77
+
- [ ] Thread reconstruction algorithms
78
+
- [ ] Conversation relationship handling
79
+
- [ ] Thread state management
129
-
### **Issue 2: Property Type Duplication** 🔴
81
+
### **Identity Objects** ✅ **COMPLETE**
82
+
**File:** `jmap-email/identity.ml`
83
+
- [x] **All 8 required fields implemented**
84
+
- [x] **JSON serialization working**
131
-
**Problem**: Email properties are defined in TWO incompatible formats:
86
+
### **VacationResponse Objects** ✅ **COMPLETE**
87
+
**File:** `jmap-email/vacation.ml`
88
+
- [x] **All 7 required fields implemented**
89
+
- [x] **Full singleton pattern implementation**
133
-
1. **Regular Variants** in `jmap_email_property.mli`:
135
-
type t = ReceivedAt | MessageId | Size | ...
138
-
2. **Polymorphic Variants** in `jmap_email_query.mli`:
140
-
type property = [`ReceivedAt | `MessageId | `Size | ...]
93
+
## **2. Method Infrastructure Gaps**
144
-
- ❌ Code duplication and maintenance burden
145
-
- ❌ Type incompatibility between modules
146
-
- ❌ API confusion for developers
147
-
- ❌ Potential for divergence over time
95
+
### **Missing Method Implementations:**
149
-
**Solution**: Unify on a single property representation with conversion functions.
97
+
**Not Implemented (5 methods):**
98
+
- [ ] `Email/import` - Email import from external sources
99
+
- [ ] `Email/parse` - Parse raw MIME messages
100
+
- [ ] `SearchSnippet/get` - Search result highlighting
101
+
- [ ] `Blob/get` - Binary data retrieval
102
+
- [ ] `Blob/copy` - Cross-account blob copying
151
-
### **Issue 3: Inconsistent Module Architecture** 🟡
104
+
**Partially Implemented (3 methods):**
105
+
- [ ] `Email/queryChanges` - Basic structure only
106
+
- [ ] `Mailbox/queryChanges` - Minimal implementation
107
+
- [ ] `Thread/queryChanges` - Minimal implementation
153
-
**Problem**: Mixed architectural patterns across the codebase:
154
-
- Some modules use abstract `type t` correctly
155
-
- Others expose implementation details
156
-
- Inconsistent use of JSONABLE signatures
157
-
- Method integration varies by module
109
+
### **Response Parser Gaps:**
110
+
**Most methods have working `to_json` but incomplete `of_json`**
159
-
**Solution**: Standardize on canonical `type t` pattern throughout.
113
+
- [ ] Result reference resolution
114
+
- [ ] Error response integration
115
+
- [ ] Method chaining support
163
-
## **🏗️ COMPREHENSIVE ARCHITECTURAL REARRANGEMENT PLAN (January 2025)**
119
+
## **3. Validation and Error Handling Gaps**
165
-
### **📋 Clean Layered Architecture Design**
121
+
### **Missing Validation Rules:**
168
-
┌─────────────────────────────────────┐
169
-
│ User Applications │ <- bin/, examples/
170
-
│ (Business Logic Layer) │ Uses high-level APIs
171
-
├─────────────────────────────────────┤
172
-
│ jmap-unix │ <- All I/O operations
173
-
│ (Platform I/O Layer) │ Eio, TLS, HTTP, networking
174
-
│ Dependencies: all below │ Connection management
175
-
├─────────────────────────────────────┤
176
-
│ jmap-email │ <- Email-specific types/logic
177
-
│ (Email Extensions Layer) │ Pure OCaml, no I/O
178
-
│ Dependencies: jmap, jmap-sigs │ Portable across platforms
179
-
├─────────────────────────────────────┤
180
-
│ jmap │ <- Core JMAP protocol
181
-
│ (Core Protocol Layer) │ Pure OCaml, foundation
182
-
│ Dependencies: jmap-sigs only │ Wire format, base types
183
-
├─────────────────────────────────────┤
184
-
│ jmap-sigs │ <- Shared interfaces
185
-
│ (Interface Layer) │ Type signatures only
186
-
│ Dependencies: none │ Platform-agnostic contracts
187
-
└─────────────────────────────────────┘
124
+
- [ ] Keywords format validation (lowercase, ASCII)
125
+
- [ ] MailboxIds boolean map validation
126
+
- [ ] Size constraints validation
190
-
### **🔒 Strict Dependency Rules**
191
-
1. **jmap-sigs**: No dependencies (pure signatures)
192
-
2. **jmap**: Only standard library + jmap-sigs
193
-
3. **jmap-email**: Only jmap + jmap-sigs + yojson/uri (NO Eio)
194
-
4. **jmap-unix**: All layers + Eio/TLS/HTTP libraries
195
-
5. **Applications**: Primarily use jmap-unix, import others for types only
128
+
**Mailbox Object:**
129
+
- [ ] Role uniqueness validation (one per account)
130
+
- [ ] Hierarchy cycle detection
131
+
- [ ] Name collision validation
199
-
## **🚨 PHASE 1: Critical Architecture Fixes (IMMEDIATE - January 2025)**
133
+
**EmailSubmission:**
134
+
- [ ] SMTP envelope validation
135
+
- [ ] Send-time constraint validation
136
+
- [ ] Identity permission validation
201
-
### **Phase 1A: Resolve Eio Dependency Leakage** ✅
202
-
**Priority: CRITICAL - Breaks architectural integrity**
138
+
### **Error Handling Gaps:**
139
+
- [ ] Method-specific error context incomplete
140
+
- [ ] SetError detailed properties missing
141
+
- [ ] Validation error details insufficient
204
-
**Files Requiring Migration:**
205
-
- [x] **jmap_email_methods.mli**: Moved `execute`, `query_and_fetch`, `get_emails_by_ids`, `get_mailboxes`, `find_mailbox_by_role` → `jmap-unix`
206
-
- [x] **jmap_email_query.mli**: Moved `execute_query`, `execute_with_fetch` → `jmap-unix`
207
-
- [x] **jmap_email_batch.mli**: Moved `execute`, `process_inbox`, `cleanup_old_emails`, `organize_by_sender`, `execute_with_progress` → `jmap-unix`
209
-
**Clean Separation Actions:**
210
-
- [x] **Removed all `env:Eio_unix.Stdenv.base` parameters** from jmap-email modules
211
-
- [x] **Created unified jmap-unix client interface** with all I/O operations in `Email_methods`, `Email_query`, `Email_batch` modules
212
-
- [x] **Kept pure builders/constructors** in jmap-email (query builders, filters, batch builders)
213
-
- [x] **Verified jmap-email/dune** has no Eio dependency (libraries: jmap yojson uri only)
214
-
- [x] **Verified clean build**: `opam exec -- dune build jmap-email/` works without Eio
215
-
- [x] **Zero Eio references**: `grep -r "Eio" jmap-email/` returns no matches
145
+
## **4. Priority Implementation Roadmap**
217
-
### **Phase 1B: Unify Property Type Systems** ✅
218
-
**Priority: CRITICAL - Eliminates duplication and confusion**
147
+
### **🔴 CRITICAL PRIORITY (Blocks Core Functionality)**
220
-
**Decision: Standardized on polymorphic variants** (more flexible, JMAP-like)
149
+
#### **Task 1: EmailSubmission Envelope/DeliveryStatus Implementation**
151
+
- `jmap-email/submission.ml` lines 239, 243, 327, 331, 376, 437, 461
222
-
**Actions Completed:**
223
-
- [x] **Replaced ALL property systems** with canonical `Jmap_email_property.t` using polymorphic variants
224
-
- [x] **Unified FOUR duplicate systems**: `jmap_email_types`, `jmap_email_property`, `jmap_email_query`, `jmap_email` Property modules
225
-
- [x] **Updated all property usage** across modules through delegation pattern
226
-
- [x] **Added enhanced property builders** for common use cases (minimal, preview, detailed, composition)
227
-
- [x] **Maintained backward compatibility** through delegation and clear deprecation guidance
228
-
- [x] **Verified end-to-end**: Property selection works from type-safe variants to JSON strings
229
-
- [x] **Updated examples**: `bin/fastmail_connect.ml` demonstrates polymorphic variant usage
153
+
**Status:** ✅ COMPLETED - All envelope and delivery status serialization/deserialization functions implemented
231
-
**Target Pattern:**
233
-
(** Unified email property system *)
235
-
| `Id | `BlobId | `ThreadId | `MailboxIds | `Keywords
236
-
| `Size | `ReceivedAt | `MessageId | `From | `To | `Subject
237
-
| (* ... all other properties ... *)
157
+
(* Replace stub implementations *)
158
+
let envelope_to_json env = (* Real SMTP envelope JSON *)
159
+
let delivery_status_to_json status = (* Real delivery status JSON *)
160
+
let envelope_of_json json = (* Parse SMTP parameters *)
163
+
**Impact**: Fixes email sending functionality entirely
243
-
## **🏗️ PHASE 2: jmap-sigs Integration & Layer Separation (HIGH PRIORITY)**
165
+
#### **Task 2: Header Processing Enhancement**
166
+
**Files to Enhance:**
167
+
- `jmap-email/header.ml` - Add structured parsing
168
+
- `jmap-email/email.ml` - Add header access patterns
245
-
### **Phase 2A: Systematic jmap-sigs Integration** ⭐
246
-
**Priority: HIGH - Major simplification opportunity**
248
-
**Signature Application Strategy:**
249
-
- [ ] **JSONABLE**: Apply systematically to ALL wire protocol types
250
-
- [ ] **METHOD_ARGS**: Standardize all method argument types
251
-
- [ ] **METHOD_RESPONSE**: Unify all method response patterns
252
-
- [ ] **JMAP_OBJECT**: Apply to Email, Mailbox, Thread, Identity, etc.
253
-
- [ ] **WIRE_TYPE**: Use for complete protocol conformance
254
-
- [ ] **RFC_COMPLIANT**: Add RFC section tracking to all modules
170
+
**Status:** ✅ COMPLETED - All RFC 8621 header access patterns implemented with structured parsing
256
-
**Target Module Pattern:**
258
-
(** Email object following JMAP specification *)
261
-
include Jmap_sigs.JMAP_OBJECT with type t := t
262
-
include Jmap_sigs.RFC_COMPLIANT with type t := t
264
-
module Property : sig
265
-
type t = [`Id | `BlobId | `ThreadId | ...]
266
-
include Jmap_sigs.JSONABLE with type t := t
174
+
(* Add to Header module *)
175
+
val parse_addresses : string -> Address.t list
176
+
val parse_date : string -> Jmap.Date.t option
177
+
val parse_message_ids : string -> string list
178
+
val decode_rfc2047 : string -> string
270
-
### **Phase 2B: Establish Clean Layer Separation**
271
-
**Priority: HIGH - Architectural integrity**
273
-
**Layer Responsibility Definition:**
274
-
- [ ] **jmap**: Core types (Id, Date, UInt, Patch), basic protocol, session management
275
-
- [ ] **jmap-email**: Email objects, queries, filters, batch operations (PURE, no I/O)
276
-
- [ ] **jmap-unix**: Connection management, request execution, I/O operations
181
+
#### **Task 3: BodyStructure Advanced Parsing**
182
+
**Files to Enhance:**
183
+
- `jmap-email/body.ml` - Nested multipart handling
278
-
**Clean Interface Design:**
279
-
- [ ] **jmap.mli**: Export portable foundation types with proper aliases
280
-
- [ ] **jmap-email.mli**: Export email functionality without any I/O dependencies
281
-
- [ ] **jmap-unix.mli**: Export complete client interface for applications
185
+
**Status:** ✅ COMPLETED - Advanced MIME parsing, content encoding, and body structure flattening implemented
285
-
## **⚙️ PHASE 3: Module Dependencies & Build System (MEDIUM PRIORITY)**
189
+
### **🟡 HIGH PRIORITY (Major Feature Completion)**
287
-
### **Phase 3A: Update dune Files for Clean Architecture**
288
-
**Priority: MEDIUM - Build system alignment**
191
+
#### **Task 4: Missing Email Fields Implementation**
192
+
- [x] Add `bodyHeaders` field and parsing logic
193
+
- [x] Enhanced `references` field validation
290
-
**Target Dependency Structure:**
292
-
; jmap-sigs: Pure signatures, no dependencies
293
-
(library (name jmap_sigs) (public_name jmap-sigs))
195
+
**Status:** ✅ COMPLETED - Message-ID validation, keyword validation, and comprehensive Email field validation implemented
295
-
; jmap: Core protocol, foundation layer
299
-
(libraries jmap-sigs yojson uri))
301
-
; jmap-email: Email extensions, pure business logic
304
-
(public_name jmap-email)
305
-
(libraries jmap jmap-sigs yojson uri))
197
+
#### **Task 5: Method Response Integration**
198
+
- [x] Complete `of_json` implementations for all responses
199
+
- [x] Add result reference resolution
200
+
- [x] Add comprehensive error handling
307
-
; jmap-unix: I/O operations, complete client
310
-
(public_name jmap-unix)
311
-
(libraries jmap jmap-email jmap-sigs eio tls-eio cohttp-eio))
202
+
**Status:** ✅ COMPLETED - Enhanced error context, result reference system, and batch processing implemented
314
-
### **Phase 3B: Module Aliases & Public APIs**
315
-
**Priority: MEDIUM - Developer experience**
204
+
#### **Task 6: Missing Method Implementations**
205
+
- [ ] Implement `SearchSnippet/get` for search highlighting
206
+
- [ ] Implement `Email/import` and `Email/parse` methods
317
-
**Clean Export Strategy:**
318
-
- [ ] **jmap/jmap.mli**: Expose core types with clear module aliases
319
-
- [ ] **jmap-email/jmap_email.mli**: Expose email types without I/O
320
-
- [ ] **jmap-unix/jmap_unix.mli**: Expose unified client interface
321
-
- [ ] **Create example usage** showing proper layer usage
208
+
**Status:** ❌ Not Started
325
-
## **✅ PHASE 4: Validation & Integrity (CONTINUOUS)**
212
+
### **🟢 MEDIUM PRIORITY (Polish and Completeness)**
327
-
### **Phase 4A: Build System Integrity**
328
-
**Priority: ONGOING - Quality assurance**
214
+
#### **Task 7: Thread Functionality Enhancement**
215
+
- [ ] Thread reconstruction algorithms
216
+
- [ ] Conversation relationship management
330
-
**Continuous Validation:**
331
-
- [ ] **Clean Builds**: `opam exec -- dune build @check` passes throughout
332
-
- [ ] **Documentation**: `opam exec -- dune build @doc` generates proper docs
333
-
- [ ] **Layer Isolation**: jmap-email builds independently without Eio
334
-
- [ ] **Interface Consistency**: All modules follow jmap-sigs patterns
218
+
**Status:** ❌ Not Started
336
-
### **Phase 4B: Update Examples & Documentation**
337
-
**Priority: HIGH - Demonstrates clean architecture**
220
+
#### **Task 8: Validation Rule Implementation**
221
+
- [ ] Keywords format validation
222
+
- [ ] Mailbox role uniqueness
223
+
- [ ] Complete SetError properties
339
-
**Example Updates:**
340
-
- [ ] **Fix bin/fastmail_connect.ml** to use jmap-unix layer properly
341
-
- [ ] **Remove manual JSON parsing** and use proper library functions
342
-
- [ ] **Demonstrate unified property system** in all examples
343
-
- [ ] **Show architectural best practices** for each use case
225
+
**Status:** ❌ Not Started
347
-
## **🎯 Key Benefits of Clean Architecture**
229
+
### **🔵 LOW PRIORITY (Nice-to-Have)**
349
-
### **1. Separation of Concerns**
350
-
- **jmap**: Portable foundation works on any OCaml platform
351
-
- **jmap-email**: Business logic without I/O, testable and reusable
352
-
- **jmap-unix**: Modern I/O using Eio, production-ready networking
231
+
#### **Task 9: Mailbox Sharing**
232
+
- [ ] Implement `sharedWith` field for shared mailboxes
354
-
### **2. Systematic jmap-sigs Integration**
355
-
- **Consistent APIs**: All modules follow same signature patterns
356
-
- **Reduced Duplication**: Share common functionality through signatures
357
-
- **RFC Compliance**: Built-in tracking of specification adherence
234
+
**Status:** ❌ Not Started
359
-
### **3. Dependency Safety**
360
-
- **No Circular Dependencies**: Strict layered approach prevents cycles
361
-
- **Minimal Dependencies**: Each layer has exactly what it needs
362
-
- **Platform Flexibility**: Core layers work without Unix-specific code
236
+
#### **Task 10: Performance Optimization**
237
+
- [ ] Connection pooling
238
+
- [ ] Request batching
239
+
- [ ] Response caching
364
-
### **4. Developer Experience**
365
-
- **Clear Usage Patterns**: Obvious where to find functionality
366
-
- **Type Safety**: Strong guarantees through signature constraints
367
-
- **Easy Extension**: Well-defined extension points for new features
241
+
**Status:** ❌ Not Started
371
-
## **⚡ IMMEDIATE EXECUTION PLAN**
373
-
**Phase 1 Execution Order:**
374
-
1. **🔥 Fix Eio Leakage** (Phase 1A) - Move I/O functions to proper layer
375
-
2. **🔥 Unify Properties** (Phase 1B) - Eliminate type system duplication
376
-
3. **⭐ Verify Builds** - Ensure repository builds throughout changes
377
-
4. **📋 Update TODO.md** - Document completion and next steps
379
-
**Success Criteria for Phase 1:**
380
-
- ✅ `jmap-email` builds without any Eio dependencies
381
-
- ✅ Single unified property type system used consistently
382
-
- ✅ All builds pass: `opam exec -- dune build @check`
383
-
- ✅ Clean architectural layer separation maintained
385
-
## **🎉 PHASE 1 COMPLETED (January 2025)**
387
-
**Status: ✅ COMPLETE** - All critical architectural issues resolved successfully!
389
-
### **✅ Architecture Cleanup Achievements**
245
+
## **5. Critical Code Locations Requiring Immediate Attention**
391
-
1. **🔥 Eio Dependency Leakage FIXED**
392
-
- **Clean Separation**: jmap-email is now pure OCaml without I/O dependencies
393
-
- **Proper Layering**: All I/O functions migrated to jmap-unix layer
394
-
- **Build Verification**: `opam exec -- dune build jmap-email/` works standalone
395
-
- **Zero Contamination**: No Eio references remain in jmap-email
397
-
2. **🔥 Property Type Duplication ELIMINATED**
398
-
- **Single Source of Truth**: Canonical `Jmap_email_property.t` with polymorphic variants
399
-
- **Four Systems Unified**: Eliminated duplicate property definitions across modules
400
-
- **Enhanced Developer Experience**: Type-safe builders for common use cases
401
-
- **Full Backward Compatibility**: Existing code continues to work through delegation
403
-
3. **⭐ Build Integrity MAINTAINED**
404
-
- **Clean Builds**: `opam exec -- dune build @check` passes throughout
405
-
- **Documentation**: `opam exec -- dune build @doc` generates successfully
406
-
- **Layer Independence**: Each library builds correctly in isolation
407
-
- **Type Safety**: All interfaces match implementations perfectly
409
-
### **🏗️ Architectural Foundation Achieved**
247
+
### **EmailSubmission Module - 7 Stubbed Functions:**
412
-
┌─────────────────────────────────────┐
413
-
│ User Applications │ ✅ Clean APIs
414
-
├─────────────────────────────────────┤
415
-
│ jmap-unix │ ✅ I/O operations only
416
-
│ (Platform I/O Layer) │ Eio, TLS, networking
417
-
├─────────────────────────────────────┤
418
-
│ jmap-email │ ✅ Pure OCaml
419
-
│ (Email Extensions Layer) │ No I/O dependencies
420
-
├─────────────────────────────────────┤ Portable types/builders
421
-
│ jmap │ ✅ Core protocol
422
-
│ (Core Protocol Layer) │ Foundation types
423
-
├─────────────────────────────────────┤
424
-
│ jmap-sigs │ ✅ Interface contracts
425
-
│ (Interface Layer) │ Type signatures
426
-
└─────────────────────────────────────┘
249
+
/workspace/jmap/jmap-email/submission.ml:239 envelope_to_json
250
+
/workspace/jmap/jmap-email/submission.ml:243 delivery_status_to_json
251
+
/workspace/jmap/jmap-email/submission.ml:327 envelope_of_json
252
+
/workspace/jmap/jmap-email/submission.ml:331 delivery_status_of_json
253
+
/workspace/jmap/jmap-email/submission.ml:376 delivery_status_list_to_json
254
+
/workspace/jmap/jmap-email/submission.ml:437 Full envelope serialization
255
+
/workspace/jmap/jmap-email/submission.ml:461 Full delivery status serialization
429
-
**Result**: **Production-ready foundation** with excellent type safety, clean separation of concerns, and maintainable architecture aligned with JMAP RFC specifications.
431
-
## **🚀 IMPLEMENTATION COMPLETION UPDATE (January 2025)**
433
-
### **✅ Production-Quality jmap-unix Implementation COMPLETED**
435
-
Following the architectural cleanup, **all stub functions in jmap-unix have been replaced with production-quality implementations**:
437
-
#### **Email_methods Module - COMPLETE**
438
-
- **✅ RequestBuilder**: Full request construction with proper JMAP JSON generation
439
-
- `email_query`, `email_get`, `email_set` - Complete method call builders
440
-
- `execute` - Real request execution using existing infrastructure
441
-
- `get_response` - Proper response extraction and parsing
442
-
- **✅ High-Level Operations**: Production-ready email operations
443
-
- `query_and_fetch` - Chain Email/query + Email/get with result references
444
-
- `get_emails_by_ids` - Direct Email/get operations
445
-
- `get_mailboxes` - Mailbox query and retrieval
446
-
- `find_mailbox_by_role` - Role-based mailbox discovery
447
-
- **✅ Response Parsing**: Complete JSON response processing
448
-
- `parse_email_query`, `parse_email_get`, `parse_thread_get`, `parse_mailbox_get`
450
-
#### **Email_query Module - COMPLETE**
451
-
- **✅ `execute_query`**: Execute Email/query operations with proper result extraction
452
-
- **✅ `execute_with_fetch`**: Automatic query + get chaining with result references
454
-
#### **Email_batch Module - COMPLETE**
455
-
- **✅ `execute`**: Process batch operations using Email/set method calls
456
-
- **✅ Workflow Functions**:
457
-
- `process_inbox` - Batch inbox processing
458
-
- `cleanup_old_emails` - Age-based email cleanup
459
-
- `organize_by_sender` - Sender-based organization
460
-
- **✅ `execute_with_progress`**: Progress-tracked batch execution
462
-
#### **Build & Integration Verification**
463
-
- **✅ Clean Builds**: `opam exec -- dune build @check` passes
464
-
- **✅ Example Applications**: `bin/fastmail_connect.ml` builds and integrates properly
465
-
- **✅ Type Safety**: All implementations match interface signatures exactly
466
-
- **✅ Error Handling**: Proper JMAP error propagation using Result types
468
-
### **🎯 Final Architecture State**
258
+
### **Header Module - Missing Core Functionality:**
471
-
┌─────────────────────────────────────┐
472
-
│ User Applications │ ✅ Complete APIs
473
-
├─────────────────────────────────────┤ Production examples
474
-
│ jmap-unix │ ✅ Full implementation
475
-
│ (Platform I/O Layer) │ Real JMAP operations
476
-
├─────────────────────────────────────┤ Eio-based networking
477
-
│ jmap-email │ ✅ Pure OCaml types
478
-
│ (Email Extensions Layer) │ Clean builders/filters
479
-
├─────────────────────────────────────┤ Zero I/O dependencies
480
-
│ jmap │ ✅ Core protocol
481
-
│ (Core Protocol Layer) │ Solid foundation
482
-
├─────────────────────────────────────┤
483
-
│ jmap-sigs │ ✅ Interface contracts
484
-
│ (Interface Layer) │ Type signatures
485
-
└─────────────────────────────────────┘
260
+
/workspace/jmap/jmap-email/header.ml - Add structured parsing
261
+
/workspace/jmap/jmap-email/email.ml - Add header access patterns
488
-
**Status: PRODUCTION READY** 🎉
490
-
The JMAP library now provides a **complete, production-quality implementation** with:
491
-
- **Real JMAP Operations**: All functions perform actual protocol operations
492
-
- **Clean Architecture**: Perfect separation of concerns across all layers
493
-
- **Type Safety**: Comprehensive OCaml type system usage
494
-
- **RFC Compliance**: Direct implementation of JMAP specifications
495
-
- **Developer Experience**: High-level APIs eliminate manual JSON handling
497
-
This architecture provides a **production-ready foundation** with excellent type safety, clean separation of concerns, and maintainable code that directly implements JMAP RFC specifications.
501
-
## **📋 ORIGINAL ARCHITECTURAL PLAN (SUPERSEDED)**
266
+
## **6. Overall Completion Status**
503
-
### **PHASE 1: Fix Critical Architecture Issues (URGENT)**
268
+
| **Component** | **Fields Complete** | **Functionality** | **RFC Compliance** |
269
+
|---------------|--------------------|--------------------|-------------------|
270
+
| Session | ✅ 100% | ✅ 95% | ✅ Complete |
271
+
| Email | ✅ 92% | ❌ 60% | ⚠️ Major gaps |
272
+
| Mailbox | ✅ 92% | ✅ 90% | ✅ Nearly complete |
273
+
| Thread | ✅ 100% | ❌ 40% | ❌ Basic only |
274
+
| Identity | ✅ 100% | ✅ 100% | ✅ Complete |
275
+
| EmailSubmission | ✅ 91% | ❌ 30% | ❌ Critical gaps |
276
+
| VacationResponse | ✅ 100% | ✅ 100% | ✅ Complete |
505
-
#### 1A. **Resolve Eio Dependency Leakage** 🔴
506
-
- [x] **Move Eio functions** from `jmap-email/jmap_email_methods.mli` to `jmap-unix/jmap_unix.mli`
507
-
- [x] **Move Eio functions** from `jmap-email/jmap_email_query.mli` to `jmap-unix/jmap_unix.mli`
508
-
- [x] **Move Eio functions** from `jmap-email/jmap_email_batch.mli` to `jmap-unix/jmap_unix.mli`
509
-
- [x] **Remove all Eio imports** from `jmap-email/` modules
510
-
- [x] **Update `jmap-email/dune`** to remove any Eio-related dependencies
511
-
- [x] **Test clean separation**: Verify `jmap-email` builds without Eio dependencies
513
-
#### 1B. **Unify Property Type Systems** 🔴
514
-
- [x] **Choose canonical format**: Decided on polymorphic variants for flexibility
515
-
- [x] **Consolidate definitions**: Removed duplicate property definitions
516
-
- [x] **Update all references**: Fixed modules using the deprecated format
517
-
- [x] **Add conversion functions**: Added for backward compatibility where needed
518
-
- [x] **Test full integration**: Ensured property selection works end-to-end
520
-
### **PHASE 2: Strengthen Module Architecture** 🟡
522
-
#### 2A. **Standardize Type Patterns**
523
-
- [ ] **Audit all modules** for consistent `type t` usage
524
-
- [ ] **Fix abstract type leaks** where implementation is exposed
525
-
- [ ] **Standardize JSONABLE usage** across all wire types
526
-
- [ ] **Ensure consistent error handling** with `Jmap_error.error`
528
-
#### 2B. **Complete Method Integration**
529
-
- [ ] **Move method implementations** from `jmap-email` to `jmap-unix` where needed
530
-
- [ ] **Create high-level client interface** in `jmap-unix` that combines all functionality
531
-
- [ ] **Implement connection management** using Eio's structured concurrency
532
-
- [ ] **Add proper authentication handling** (OAuth2, bearer tokens)
534
-
### **PHASE 3: Example Applications & Usage** ✨
536
-
#### 3A. **Update Example Applications**
537
-
- [ ] **Fix Eio dependency usage** in `bin/fastmail_connect.ml`
538
-
- [ ] **Remove manual JSON parsing** and use proper `of_json` functions
539
-
- [ ] **Demonstrate unified property system** in examples
540
-
- [ ] **Show best practices** for each architectural layer
542
-
#### 3B. **Create High-Level API**
543
-
- [ ] **Design client interface** that hides architectural complexity
544
-
- [ ] **Implement common operations** (list emails, send email, manage folders)
545
-
- [ ] **Add helper functions** for typical use cases
546
-
- [ ] **Document usage patterns** with comprehensive examples
548
-
### **PHASE 4: Testing & Documentation** 📚
550
-
#### 4A. **Comprehensive Testing**
551
-
- [ ] **Unit tests** for all modules with proper `type t` encapsulation
552
-
- [ ] **Integration tests** across architectural layers
553
-
- [ ] **Real server testing** against JMAP providers
554
-
- [ ] **Performance benchmarks** comparing old vs new approaches
556
-
#### 4B. **Documentation & Migration**
557
-
- [ ] **Update architectural documentation** explaining the layered design
558
-
- [ ] **Create migration guide** for users of previous versions
559
-
- [ ] **Document best practices** for each use case
560
-
- [ ] **Create comprehensive API reference** with examples
278
+
**Overall Assessment**: The codebase has **excellent architectural foundations** but requires **significant implementation work** to achieve full JMAP compliance. The most critical gap is in EmailSubmission envelope handling, which blocks core email sending functionality.
564
-
## **🏗️ RECOMMENDED ARCHITECTURE DESIGN**
566
-
### **Clean Layered Architecture**
284
+
- **2025-01-05**: Initial comprehensive analysis completed
285
+
- **2025-01-05**: TODO.md created with full roadmap
286
+
- **2025-01-05**: ✅ **CRITICAL PRIORITY TASKS COMPLETED**
287
+
- **Task 1**: EmailSubmission Envelope/DeliveryStatus Implementation ✅ COMPLETED
288
+
- **Task 2**: Header Processing Enhancement ✅ COMPLETED
289
+
- **Task 3**: BodyStructure Advanced Parsing ✅ COMPLETED
290
+
- **2025-01-05**: ✅ **HIGH PRIORITY TASKS COMPLETED**
291
+
- **Task 4**: Missing Email Fields Implementation ✅ COMPLETED
292
+
- **Task 5**: Method Response Integration ✅ COMPLETED
569
-
┌─────────────────────────────────────┐
570
-
│ User Applications │ <- Examples, user code
571
-
├─────────────────────────────────────┤
572
-
│ jmap-unix │ <- Eio, TLS, HTTP, networking
573
-
│ (Platform-specific) │ Connection management
574
-
├─────────────────────────────────────┤
575
-
│ jmap-email │ <- Email objects, methods
576
-
│ (Email Extensions) │ Pure OCaml, no I/O
577
-
├─────────────────────────────────────┤
578
-
│ jmap │ <- Core protocol, types
579
-
│ (Core Protocol) │ Pure OCaml, portable
580
-
├─────────────────────────────────────┤
581
-
│ jmap-sigs │ <- Shared interfaces
582
-
│ (Module Signatures) │ Type signatures only
583
-
└─────────────────────────────────────┘
294
+
## **Implementation Status Summary**
586
-
### **Dependency Rules**
587
-
1. **jmap-sigs**: No dependencies (signatures only)
588
-
2. **jmap**: Only depends on jmap-sigs + standard library
589
-
3. **jmap-email**: Depends on jmap + jmap-sigs (NO Eio/networking)
590
-
4. **jmap-unix**: Depends on all above + Eio/TLS/HTTP libraries
591
-
5. **Applications**: Use jmap-unix for I/O, can import others for types
296
+
### **🔴 CRITICAL PRIORITY** - ✅ **ALL COMPLETED**
297
+
All critical blocking functionality has been implemented:
298
+
- EmailSubmission email sending functionality now works
299
+
- Complete RFC 8621 header access patterns implemented
300
+
- Advanced MIME parsing with content encoding support
593
-
### **Type System Design**
594
-
- **Unified Properties**: Single property type system across all modules
595
-
- **Abstract Types**: Consistent `type t` with smart constructors
596
-
- **JSONABLE**: Complete serialization for all wire types
597
-
- **Error Handling**: Structured errors using `Jmap_error.error` throughout
302
+
### **🟡 HIGH PRIORITY** - ✅ **MAJOR COMPONENTS COMPLETED**
303
+
Major feature completion achieved:
304
+
- Email object validation and missing fields added
305
+
- Comprehensive method response integration completed
306
+
- Production-ready error handling and result reference resolution
308
+
### **🟢 MEDIUM PRIORITY** - Available for future enhancement
309
+
- Task 6: Missing Method Implementations (SearchSnippet, Email/import, Email/parse)
310
+
- Task 7: Thread Functionality Enhancement
311
+
- Task 8: Validation Rule Implementation
601
-
## **⚡ IMMEDIATE ACTION ITEMS**
603
-
1. **🔥 Priority 1**: Fix Eio dependency leakage (breaks clean architecture)
604
-
2. **🔥 Priority 2**: Unify property type systems (eliminates confusion)
605
-
3. **🔧 Priority 3**: Update examples to use corrected architecture
606
-
4. **📋 Priority 4**: Complete method integration with proper layer separation
608
-
**Success Criteria**:
609
-
- `jmap-email` builds without any Eio dependencies
610
-
- Single property type system used consistently
611
-
- Examples demonstrate clean layered usage
612
-
- All layers respect dependency boundaries
616
-
## **🏆 Major Accomplishments Summary**
618
-
This refactoring represents a **comprehensive transformation** of the JMAP library architecture:
620
-
### **Before (Complex & Inconsistent)**
621
-
- Mixed type patterns (some `type t`, some direct types)
622
-
- Manual JSON handling scattered throughout examples
623
-
- Inconsistent error handling (strings vs structured errors)
624
-
- Large monolithic modules (`jmap_types`, `jmap_email_types`)
625
-
- GADT-based DSL that was complex to use and maintain
627
-
### **After (Clean & Consistent)**
628
-
- **Universal `type t` Pattern**: Every module/submodule uses canonical `type t`
629
-
- **Complete JSONABLE**: All wire types have `to_json`/`of_json` with Result-based errors
630
-
- **Focused Modules**: Each module has a single, clear responsibility
631
-
- **Abstract Types**: Proper encapsulation with smart constructors and validators
632
-
- **RFC Compliance**: Direct mapping to JMAP specification structure with hyperlinks
633
-
- **jmap-sigs Integration**: Consistent signatures across all modules
634
-
- **Production Ready**: Clean builds, comprehensive docs, proper error handling
637
-
- **Developer Experience**: Predictable, discoverable APIs with excellent type safety
638
-
- **Maintainability**: Modular structure makes adding features and fixing bugs easier
639
-
- **Standards Compliance**: Direct implementation of RFC 8620/8621 specifications
640
-
- **Error Handling**: Comprehensive error management with structured JMAP errors
641
-
- **Documentation**: Complete OCamldoc with RFC hyperlinks and usage examples
643
-
The library now provides a **solid foundation** for building production JMAP applications with excellent type safety, comprehensive functionality, and clean architecture.
647
-
## **Implementation Strategy**
649
-
### Phase 1: **Object Serialization** (Highest Priority)
650
-
Focus on implementing `of_json`/`to_json` for all JMAP objects. This will eliminate the most manual JSON handling in examples.
652
-
### Phase 2: **Complete ADT Integration**
653
-
Ensure all filters, comparators, and patch operations work seamlessly with the ADT approach.
655
-
### Phase 3: **Example Migration**
656
-
Update all examples to demonstrate the new API, showing best practices and common patterns.
658
-
### Phase 4: **Documentation**
659
-
- Update module documentation with examples
660
-
- Create a migration guide from DSL to ADT
661
-
- Write a comprehensive README showing the new approach
663
-
### Phase 5: **Testing & Validation**
664
-
- Implement comprehensive test suite
665
-
- Validate against real JMAP servers
666
-
- Performance benchmarking
670
-
## **Benefits of New Architecture**
672
-
1. **Simpler API**: Constructor functions are more intuitive than DSL operators
673
-
2. **Better IDE Support**: Autocomplete works better with regular functions
674
-
3. **Easier Debugging**: No complex type-level computations to trace through
675
-
4. **More Flexible**: Users can build requests in any order or pattern they prefer
676
-
5. **Maintainable**: Straightforward code that's easier to extend and modify
680
-
## **Migration Guide Summary**
682
-
**Old DSL Approach**:
685
-
email_query ~account_id ~filter () @>
686
-
email_get ~account_id ~ids:[] () @>
690
-
**New ADT Approach**:
693
-
Jmap_request.create ~using:[...] ()
694
-
|> Jmap_request.add_method
695
-
(Jmap_method.email_query ~account_id ~filter ())
696
-
|> Jmap_request.add_method_with_ref
697
-
(Jmap_method.email_get ~account_id ())
698
-
~reference:("#call-1", "/ids")
701
-
The new approach is more verbose but significantly clearer and more flexible.
313
+
### **🔵 LOW PRIORITY** - Available for future enhancement
314
+
- Task 9: Mailbox Sharing (sharedWith field)
315
+
- Task 10: Performance Optimization