The handlers stage reads in an IMAPInputBuffer (IMAPInputProcessor) instead of NIOSingleStepByteToMessageProcessor's coalesced ByteBuffer, so a FETCH/APPEND literal piece of at least 1 KiB within one read of at least 1 KiB is delivered as a reference to the received bytes. Shorter pieces are copied; bytes from smaller reads are copied twice, into a tail on arrival and out of it on delivery. The decoders keep their ByteBuffer entry point for ByteToMessageHandler and the decoder verifier; that path copies. A decoder error or PayloadTooLargeError is final: the buffer is dropped and later reads rethrow it without decoding (ByteToMessageHandler also stops decoding, but fires dataReceivedInErrorState). Keeping the unparsed bytes would make every later read append, fail on the same bytes and copy all of them into IMAPDecoderError.buffer: unbounded memory and quadratic copying, past the maximumBufferSize check. Errors thrown by the message receiver (e.g. UnexpectedResponse) pass through and are not final. Reads under 1 KiB are copied into IMAPInputBuffer's tails, so 1-byte reads cost a region per KiB and pin no receive buffers. A larger read still pins its whole receive buffer, which maximumBufferSize does not count. Review focus: IMAPInputProcessor. Behavior changes: - A stream whose input failed to parse stays failed. - IMAPDecoderError.buffer holds the bytes waiting to be parsed when the error was thrown. - Leftover literal bytes followed by a read that starts a new region reach the handler's consumer as two .streamingBytes events, not one. Every read of at least 1 KiB starts a region; a smaller one does when the last region is a retained read, or a tail it does not fit or that is not uniquely referenced. ParseInput.extractBuffer(upTo:) takes bytes from the current region only, where the old code took min(remaining, readable) across the whole buffer. Legal, but observable. A caller passing a multi-region buffer to the stream parsers directly sees this from the previous commit on.
Examples
This directory contains example and tool projects built on top of swift-nio-imap.
Each subdirectory is its own standalone Swift package that depends on the library
in the repository root via a local path dependency (.package(path: "../..")).
Keeping them out of the root package means the library's own dependency graph stays
smaller — consumers don't resolve example-only dependencies such as ArgumentParser.
(Dependencies that the library products themselves use — for example swift-log, which
IMAPCommands depends on — remain part of the root package's graph.)
| Example | What it is |
|---|---|
IMAPTool |
Command-line IMAP debugging tool (imap-tool) built on the IMAPToolLib library product. |
CLI |
A smaller command-line interface plus its supporting CLILib (with tests). |
Proxy |
An IMAP proxy that logs the traffic flowing through it. |
Fuzzer |
Fuzzing harness for the IMAP parser (NIOIMAPFuzzer). |
PerformanceTester |
Parser and encoder benchmarks, built on ordo-one/benchmark. |
Building and running
Each example builds independently. From the repository root:
swift build --package-path Examples/IMAPTool
swift run --package-path Examples/IMAPTool imap-tool --help
Because they are separate packages, swift build / swift test at the repository
root builds only the library targets — not these examples. CI builds them in the
Build examples job; PerformanceTester has its own Build benchmarks job.