ParseInput: a ~Escapable, BitwiseCopyable cursor over a table of region
pointers, with the primitives and combinators as methods. Input buffers:
ParserInputBuffer (+ Consumable, StableRegion refinements), conformances
for ByteBuffer / Array / Data, and IMAPInputBuffer, the staging deque that
can hand out payloads by reference.
IMAPInputBuffer keeps reads of at least copyThreshold (1 KiB) by
reference and copies smaller ones into a 1 KiB tail (an OutputSegment),
so a peer sending a byte per read costs a region per KiB, not a region,
an object and a retained receive buffer per byte. A tail is written
only past its end, only while the buffer holds the sole reference, and
never reallocated; a used-up tail with room is continued by the next
small read into an empty buffer. Only a StableAddressByteRegion (arrays,
ByteBuffer) or an IMAPBuffer over one is kept by reference; any other
large region, e.g. Data, is copied once.
A bare DispatchData.Region is copied too: it points into its
DispatchData without keeping it alive, so it is not a
StableAddressByteRegion. append(contentsOf:) is the zero-copy path for
DispatchData.
Public API additions: IMAPInputBuffer.append(contentsOf: DispatchData)
walks a read's regions with enumerateBytes, so it builds no regions
array; a large region is kept with the DispatchData that owns it (also
the owner a makeDispatchData() donation retains), small ones go to the
tail. append(_:) gains overloads for a StableAddressByteRegion and an
IMAPBuffer, so appending a ByteBuffer, an array or an IMAPBuffer pays no
dynamic cast; IMAPByteStorage.init(_:) gains one for an IMAPBuffer.
Additive; the grammar still runs on ParseBuffer. Review focus: _span(_:)
and RegionSink (the two read-side unsafe seams), the head invariant in
advance(by:), the gather's 64-frame recursion cap,
IMAPInputBuffer.writableTail(fitting:), and DispatchDataRegion, what
append(contentsOf:) keeps: its @unchecked Sendable and its
StableAddressByteRegion (fixed-address) promise.
Temporary: main's SubParser is renamed LegacySubParser so both coexist.
Move BadCommand, ParserError, TooMuchRecursion and IncompleteMessage
out of ParserLibrary.swift. Besides the move: IncompleteMessage.init
goes fileprivate -> internal and gains a doc comment; the new file has
the license header.
* Reject invalid response text when writing
`.no(.init(text: "No mailbox x\r\n* BYE pwned"))` was written verbatim,
injecting an untagged response; likewise tagged, BYE, PREAUTH and
continuation responses.
RFC 9051: `text = 1*(TEXT-CHAR / UTF8-2 / UTF8-3 / UTF8-4)`. `writeText`
now asserts no NUL, CR or LF. Empty stays valid. The parser now accepts
UTF-8 text.
* Add Command.Tag for command and response tags
`TaggedCommand(tag: "A1 NOOP\r\nA2 DELETE INBOX\r\nA3", command: .noop)`
was written verbatim, injecting a command; likewise `APPEND` start.
`TaggedResponse(tag: "* BYE x\r\nA1", …)` injected a response.
RFC 3501: `tag = 1*<any ASTRING-CHAR except "+">`. New `Command.Tag`
replaces the `String` in `TaggedCommand`, `TaggedResponse`, `Response`,
`CommandStreamPart`, `AppendCommand`, `BadCommand` and NIOIMAP's state
machine errors; `init?(_:)` validates, literals trap. The parser already
enforces the production. IMAPCommands converts its numeric tags.
* Validate and escape namespace delimiters
`NamespaceDescription(string: "x", char: "\r\n", …)` wrote a raw CRLF
inside `"…"`, injecting a response. `"\""` encoded as `"""`, and `"\\"`
as `"\"` (unterminated); non-ASCII was accepted.
RFC 2342: `DQUOTE QUOTED-CHAR DQUOTE / nil`. `init(string:delimiter:
responseExtensions:)` (was `char:`) throws `InvalidDelimiterError` for
non-ASCII, CR, LF, NUL; the delimiter is stored as a byte, read-only.
Quoted-specials are escaped on write and parsed when escaped.
* Gate a capturing exit test on Swift 6.3
* [CI] Adopt GitHub Actions
# Motivation
We want to adopt GitHub actions in all of our Swift repositories to replace our current Jenkins CI.
# Modification
This PR adopts the reusable workflows from NIO and the swiftlang organization to ensure soundness and test coverage. Additionally, this PR enables a sematic label check and adds a `release.yml` to make releasing this package easy.
# Result
Modern CI and release flow.
Resolves#556
We've talked quite a bit offline, and decided that for now @_spi is the way to go, as it avoids build system issues. The goal is to remove the number of underscored public types and fields.
We use String(buffer: ByteBuffer) quite a lot. This isn't ideal as it may crash if the bytes are not valid UTF-8. This PR addresses that problem by providing a failable initialiser on String that will handle invalid UTF8 bytes gracefully by returning nil.
* Servers now can send authentication challenges
* Soundness
* Fix tests
* Change to use Response
* Docs
* Soundness
* work around SR-14394
* Update Sources/NIOIMAPCore/Grammar/Response/Response.swift
Co-authored-by: Daniel Eggert <daniel.eggert@hoerbuch.dk>
* Fix compile on 5.2
Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Co-authored-by: Daniel Eggert <daniel.eggert@hoerbuch.dk>
Motivation:
Gmail has a couple of common extensions to the IMAP specification for
Gmail specific features. It'd be good to support them. This patch adds
support for the most important three: Gmail message ID, Gmail thread ID,
and the Gmail label functionality.
Modifications:
- Added new Fetch and Message attributes for the three Gmail extensions.
- Added parsing and serialization support.
Result:
Users can interact with Gmail-specific features.
motivation: use standard format across all of our projects
changes:
* add .swiftformat settings based on what we use in other projects
* validate format in the sanity script
* format