`imap://h/INBOX/;UID=1/;SECTION=1/` parsed with section `1`, so
`EncodedSection("1/")` didn't round-trip: the parser dropped the `/`
even when no `;PARTIAL=` followed it. Drop it only when one does.
`IMAPServer(host: "h] x\r\n* BYE")` was written verbatim in the bare URL
of `[REFERRAL …]`, injecting a response. `imap://[::1]/` parsed as host
`::1` and re-encoded as `imap://::1/`. A negative port encoded as `:-1`.
RFC 3986: `host = IP-literal / IPv4address / reg-name`. New nested
`IMAPServer.Host` replaces the `String`: `init?(_:)` validates IPv6,
IPvFuture and reg-name (IPv4 is a subset), literals trap. The parser
keeps the brackets, accepts all of reg-name, and validates via `init?`;
its unreachable IPv4 branch is gone. `port` is now `UInt16?`.
`EncodedAuthenticatedURL(data: "x\r\n* BYE")` was written verbatim at the
end of a URLAUTH URL, injecting a response.
RFC 4467: `enc-urlauth = 32*HEXDIG`. `init(data:)` and the public `var`
become `init?(_:)`; literals trap; `String.init` reads. The parser read
exactly 32 digits, so longer tokens didn't round-trip; it now reads all.
`EncodedMailbox(mailbox: "x] x\r\n* BYE")` was written verbatim inside
the bare URL of `[REFERRAL …]`, injecting a response; likewise
`EncodedUser`, `EncodedAuthenticationType`, `EncodedSearch`,
`EncodedSection`.
RFC 5092: `enc-user`/`enc-auth-type = 1*achar`, `enc-mailbox`/
`enc-search`/`enc-section = 1*bchar`. Each type's public `var` and
labelled init become `init?(_:)`, literals trap, `String.init` reads.
One helper validates by character class and `pct-encoded` triplet, and
uppercases hex digits as the parser does, so values round-trip.
`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.
`.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.
`.sort(…, charset: "UTF-8 ALL\r\nA2 DELETE INBOX\r\nA3 SEARCH", …)` was
written verbatim, injecting a command into SORT / SEARCH / ESEARCH.
`.badCharset(["a)] x\r\n* BYE"])` injected a response. Quoted names
also didn't round-trip: `"a b"` parsed, then encoded bare.
RFC 3501: `charset = atom / quoted`. New `CharacterSetName` replaces
`String`; valid = non-empty `TEXT-CHAR`. Written as an atom where it is
one (`CHARSET UTF-8` unchanged), quoted otherwise, never a literal. The
parser rejects quoted names it couldn't write back.
`.standard("X)\r\nA2 DELETE INBOX\r\nA3 LIST (")` was written verbatim,
injecting a command into LIST select/return options. Same for
`.vendor(KeyValue<String, String>)`.
RFC 5258: `option-standard-tag = atom`, `option-vendor-tag =
vendor-token "-" atom`. New `OptionExtensionKind.Standard` and
`.Vendor` replace the payloads; `init?(_:)` validates, literals trap.
`Vendor` stores `ACME-SORT` and derives `token` / `name`.
`Capability("X\r\nA2 DELETE INBOX")` was written verbatim, injecting a
command into ENABLE, or (`"X\r\n* OK [ALERT] hi"`) a response into
CAPABILITY / ENABLED. Same for the kinds a capability is built from,
e.g. `.context(.init("X\r\n…"))`.
RFC 3501: `capability = ("AUTH=" auth-type) / atom`. `init(_:)` becomes
`init?(_:)` for `Capability` and each kind (kinds validate after
uppercasing); literals trap on invalid input. Storage is `let`. Add
`String.init(_:)` for the kinds.
`.compress(.init("DEFLATE\r\nA2 DELETE INBOX"))` was written verbatim,
injecting a command after COMPRESS.
RFC 4978: `algorithm = "DEFLATE"`, an atom. `init(_:)` becomes
`init?(_:)`, validating after uppercasing; literals trap on invalid
input. Add `String.init(_:)`.
`.filter("x\r\nA2 DELETE INBOX")` was written verbatim, injecting a
command into SEARCH.
RFC 5466: `filter-name = 1*<any ATOM-CHAR except "/">`. New `FilterName`
type replaces the `String` payload of `SearchKey.filter`; `init?(_:)`
validates, literals trap on invalid input.
`AttributeFlag("x\" all 1\r\nA2 DELETE INBOX\r\nA3 NOOP \"")` was
written verbatim inside SEARCH MODSEQ "/flags/…", injecting a command.
RFC 7162: `attr-flag = "\\" atom / atom`, where `"\\"` is two literal
backslashes (the stored form is already escaped). `init(_:)` becomes
`init?(_:)`, validating after lowercasing; literals trap on invalid
input. Fix docs that claimed casing is preserved.
`MailboxInfo.Attribute("\\X)\r\n* BYE")` was written verbatim, injecting
an untagged response into LIST. It also feeds CREATE … USE via
`UseAttribute(_:)`.
RFC 3501: `mbx-list-flag` is `"\" atom` in every branch. `init(_:)`
becomes `init?(_:)`; literals trap on invalid input. Constants become
`static let` literals; storage is `let`. Fix the `String.init` doc,
which claimed lowercase storage.
The quoted-special cases were swapped: `\` encoded as `"\"`
(unterminated), `"` as `"\\"` (a backslash). `pathSeparator: "\n"` was
written as a raw LF inside `"…"`, and NUL silently became NIL.
`(DQUOTE QUOTED-CHAR DQUOTE / nil)`, `QUOTED-CHAR = <TEXT-CHAR except
quoted-specials> / "\" quoted-specials`. Swap the cases; parse the
escaped forms; `MailboxPath.init` throws for CR, LF, CRLF, NUL.
`SearchCorrelator(tag: "a\") * BYE")` was spliced into `"…"` unescaped,
so ESEARCH / UIDBATCHES responses could carry injected data.
RFC 4466: `tag-string = string`. Use `writeIMAPString`, and parse a
`string` rather than `"` tag `"` so every tag round-trips.
* Separate resources in QUOTA responses with spaces
RFC 2087 defines quota_list as "(" #quota_resource ")", with a single
space as the delimiter. writeQuotaResources concatenated resources with
no separator, producing e.g. (STORAGE 10 512MESSAGE 1 100).
* Support zero or more quota roots in QUOTAROOT responses
RFC 2087 defines quotaroot_response as "QUOTAROOT" SP astring
*(SP astring): a mailbox has zero or more quota roots. The parser
required exactly one, so `* QUOTAROOT comp.mail.mime` (the RFC's own
example) failed to parse and any roots after the first were dropped.
ResponsePayload.quotaRoot now carries [QuotaRoot]. This is a source-
breaking change to the public API.
* NIOIMAPCore: import the Android overlay module, not Bionic
#826 added a `canImport(Bionic)` / `import Bionic` arm to NIOIMAPCore's
per-file libc-import guards. Switch it to the `Android` umbrella module,
which re-exports Bionic plus the Swift overlay, so the import is the more
complete/idiomatic libc surface on the Swift Android SDK. No functional
change — both resolve the libc symbols (isalnum/isalpha) used here.
* CI: enable InlineAlways experimental feature for Android nightly build
swift-collections 1.6.0 guards `@inline(always)` with `#if compiler(>=6.3)`,
but that attribute is still behind the experimental `InlineAlways` feature in
the nightly `main` toolchain the Android Swift SDK job builds with, so the build
fails with "'@inline(always)' is an experimental feature". Pass
`-enable-experimental-feature InlineAlways` to swift build until the upstream
guard is fixed (cf. apple/swift-collections #580/#584).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
### Motivation:
NIOIMAPCore's parser guards the libc import per file with
Darwin/Glibc/Musl/Windows and otherwise falls into
`#else let badOS = { fatalError("unsupported OS") }()`. On the Swift
Android SDK none of those arms match, so every guarded file takes the
`#else` branch and the module fails to build with "invalid redeclaration
of 'badOS'" (the symbol is declared at file scope in ~17 sources).
### Modifications:
Add an `#elseif canImport(Android)` arm importing `Android` to the per-file
libc-import guards in NIOIMAPCore. For `UInt8+ParseTypeMembership.swift`,
which imports specific ctype functions, add `import func Android.isalnum` /
`import func Android.isalpha`.
### Result:
NIOIMAPCore compiles for Android. No change on any other platform.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>