NIOIMAPCore and its tests no longer depend on swift-nio; NIOIMAP declares
the dependency it was getting transitively. Hand edits: Package.swift and
NIOIMAPCore.md. Everything else is the output of, on the parent
commit (zsh):
F=($(grep -rlE '^import ((struct|enum|class|protocol) )?NIO(Core|TestUtils)?(\.[A-Za-z]+)?$' \
Sources/NIOIMAPCore Tests/NIOIMAPCoreTests))
perl -0pi -e 's/^import (?:(?:struct|enum|class|protocol) )?NIO(?:Core|TestUtils)?(?:\.\w+)?\n//mg;
s/\n\n\n+/\n\n/g' $F
Public break: depending on NIOIMAPCore no longer provides swift-nio.
The four raw-payload cases become IMAPBuffer so a large literal can be
handed in and out without a copy: FetchResponse.streamingBytes,
AppendCommand.messageBytes, AppendCommand.CatenateData.bytes,
CommandStreamPart.continuationResponse.
Review focus: writeBytes(IMAPBuffer) keeps payloads by reference
(ZeroCopyWriteTests); the parser's extractBuffer(upTo:) still copies.
Updates IMAPTool and the IMAPCommands append/continuation wrappers.
Public API breaks:
- The four cases above: ByteBuffer -> IMAPBuffer.
Removes the writeBuffer(inout ByteBuffer) shim from "Encode into an
EncoderOutputBuffer sink".
Small fields (mailbox names, atoms, quoted strings, envelope fields,
base64, URLs, the authentication challenge, catenateURL, ...) become
[UInt8]. The four raw-payload cases stay ByteBuffer until "Make payload
cases IMAPBuffer".
The grammar's string productions return [UInt8]. The parser still runs
on ParseBuffer, so its cursor methods copy out of the ByteBuffer for now.
Review focus: the model files' encoders and ModifiedUTF7 on arrays.
Updates IMAPTool and the IMAPCommands catenate-URL wrapper.
Public API breaks:
- ~38 public declarations ByteBuffer -> [UInt8].
- ModifiedUTF7.EncodingRoundtripError.buffer -> .bytes.
- Response.authenticationChallenge and ContinuationRequest.data are
[UInt8]; an empty challenge is [].
Internal: writeBufferAsBase64 -> writeBytesAsBase64; the ByteBuffer
writeIMAPString overload is gone.
Add EncodeBuffer.writeByte / writeDecimal / writeLiteralHeader /
writeRedactedByteCount and use them for every numeric interpolation
in encoders. writeString("…\(x)…") sites become separate writeString
calls; quote-wrapped ones ("\"\(x)\"") stay. writeMailboxStatus
writes each attribute directly instead of building (String, String)
pairs. Output unchanged for valid values; avoids String formatting and
allocation. Invalid (negative) FullDate/FullTime fields now pad after
the sign: -0005, not 00-5.
writeLiteralHeader takes LiteralSynchronization (`{n+}`) and
LiteralKind (`~{n}`) enums.
As EncodeBuffer methods, `self.write(if:) { self.write… }` borrows the
buffer while the closure mutates it, forcing a copy and a CoW on the
first write inside the closure.
Hand edit: Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift, which
defines the free functions. Call sites converted with:
git ls-files -z 'Sources/*.swift' 'Tests/*.swift' | xargs -0 perl -pi -e \
's/\b(?:self\.buffer|self|buffer)\.(writeIfExists\(|write\(if:)/$1/g'
* 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.
With this PR the implementation of `CustomDebugStringConvertible` generally uses new `makeDescription` convenience methods on the three encode buffers, e.g.:
```swift
extension ResponseEncodeBuffer {
static func makeDescription(_ closure: (inout ResponseEncodeBuffer) -> Void) -> String
}
```
such that conformance can be implemented as e.g.
```swift
extension Command: CustomDebugStringConvertible {
public var debugDescription: String {
CommandEncodeBuffer.makeDescription {
$0.writeCommand(self)
}
}
}
```
This also adds `CustomDebugStringConvertible` to `MessageAttribute` and `StreamingKind`.
Resolves#662
Command/Response Encoder can be configured using loggingMode. If turned on then user-sensitive strings won't be encoding, but any metadata will.
For example, 1 LOGIN username password becomes 1 LOGIN "" "", thereby hiding the user's information.
Resolves#634
The majority of types that were Equatable are now Hashable.
Anywhere that we had a custom == and the type was also Hashable we also now have custom hash functions.
In most cases in IMAP it's possible to allow multiple commands to run concurrently. However, in some cases this would lead to undefined behaviour.
In particular, when appending, append is the only command that can be sent/active, as for authenticating, and obviously IDLE.
This PR implements that by tracking the outgoing tags, and the incoming tagged responses.
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.
Resolves#522
Some command names were misleading, they should be better now. Also removed a redundant initialiser.
PartialCommandStream -> SynchronizedCommand
CommandStream -> CommandStreamPart