Add IMAP integration test suite and fix protocol bugs
Adds a comprehensive integration test suite for ocaml-imap inspired by
Dovecot's imaptest tool. The suite tests against a real IMAP server with
both scripted deterministic tests and randomized stress tests.
Test suite structure:
- imaptest_config.ml: CLI configuration via Cmdliner
- imaptest_output.ml: Colored terminal output
- imaptest_state.ml: State tracking for violation detection
- imaptest_utils.ml: Test helpers and RFC 5322 sample messages
- imaptest_scripted.ml: 36 deterministic tests across categories
- imaptest_stress.ml: Randomized stress tests with state tracking
- imaptest.ml: Combined runner with subcommands
Bug fixes discovered during testing:
1. APPEND literal synchronization (write.ml)
- Changed from synchronizing literal {size} to non-synchronizing
literal {size+} (LITERAL+ extension, RFC 7888)
- Without this, APPEND hangs waiting for continuation response
that was already sent
2. SEARCH response not implemented (response.ml, read.ml, client.ml)
- Added Response.Search type for traditional SEARCH responses
- Added parser for "* SEARCH n1 n2 n3..." format
- Fixed search/uid_search functions which were stubs returning []
References:
- RFC 9051: IMAP4rev2 protocol specification
- RFC 7888: LITERAL+ extension for non-synchronizing literals
- RFC 5322: Internet Message Format (test message format)
- Dovecot imaptest: https://dovecot.github.io/imaptest/
Test results: 30 passed, 2 failed (BODY/BODYSTRUCTURE parsing bugs
in core library), 4 skipped (server capability dependent)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add SORT and CONDSTORE extensions to ocaml-imap
Implement RFC 5256 SORT and RFC 7162 CONDSTORE extensions for the
IMAP client library.
- Add Sort module with sort keys (Arrival, Cc, Date, From, Size,
Subject, To) and criterion type with reverse flag
- Add Sort and Uid_sort commands to Command module
- Add sort() and uid_sort() client functions requiring SORT capability
- Add SORT response parsing in read.ml
- Add Sort response type to Response module
- Add changedsince parameter to Fetch and Uid_fetch commands
- Add unchangedsince parameter to Store and Uid_store commands
- Add MODSEQ fetch item parsing
- Add modseq field to message_info and Fetch.message types
- Update fetch/uid_fetch/store/uid_store client functions
- Add test_sort_by_date testing SORT with ARRIVAL key and REVERSE
- Add test_condstore testing STORE with UNCHANGEDSINCE modifier
- Expand test suite from 65 to 98 tests covering FETCH variants,
SEARCH criteria, envelope parsing, and multi-message operations
- Fix keyword flag parsing to avoid double $ prefix
- Fix capability cache population in test setup
- Update API call sites for new optional parameters
- RFC 5256: Internet Message Access Protocol - SORT and THREAD Extensions
https://datatracker.ietf.org/doc/html/rfc5256
- RFC 7162: IMAP Extensions: Quick Flag Changes Resynchronization
(CONDSTORE) and Quick Mailbox Resynchronization (QRESYNC)
https://datatracker.ietf.org/doc/html/rfc7162
- RFC 9051: Internet Message Access Protocol (IMAP) - Version 4rev2
https://datatracker.ietf.org/doc/html/rfc9051
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>