mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-22 04:30:43 +00:00
[CI] Adopt GitHub Actions (#775)
* [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.
This commit is contained in:
1 parent
7328a733b4
commit
2cd1c5582a
306 files changed
+12797
-6417
No files matched your search
@@ -0,0 +1,14 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: SemVer Major
|
||||
labels:
|
||||
- ⚠️ semver/major
|
||||
- title: SemVer Minor
|
||||
labels:
|
||||
- semver/minor
|
||||
- title: SemVer Patch
|
||||
labels:
|
||||
- semver/patch
|
||||
- title: Other Changes
|
||||
labels:
|
||||
- semver/none
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Main
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "0 8,20 * * *"
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
|
||||
cxx-interop:
|
||||
name: Cxx interop
|
||||
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
|
||||
@@ -0,0 +1,26 @@
|
||||
name: PR
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
soundness:
|
||||
name: Soundness
|
||||
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
|
||||
with:
|
||||
license_header_check_project_name: "SwiftNIO"
|
||||
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
|
||||
cxx-interop:
|
||||
name: Cxx interop
|
||||
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
|
||||
@@ -0,0 +1,18 @@
|
||||
name: PR label
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled, unlabeled, opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
semver-label-check:
|
||||
name: Semantic Version label check
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 1
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Check for Semantic Version label
|
||||
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
|
||||
@@ -0,0 +1,34 @@
|
||||
.gitignore
|
||||
**/.gitignore
|
||||
.gitattributes
|
||||
.git-blame-ignore-revs
|
||||
.mailfilter
|
||||
.mailmap
|
||||
.spi.yml
|
||||
.swift-format
|
||||
.editorconfig
|
||||
.github/*
|
||||
*.md
|
||||
*.txt
|
||||
*.yml
|
||||
*.yaml
|
||||
*.json
|
||||
Package.swift
|
||||
**/Package.swift
|
||||
Package@-*.swift
|
||||
**/Package@-*.swift
|
||||
Package.resolved
|
||||
**/Package.resolved
|
||||
Makefile
|
||||
*.modulemap
|
||||
**/*.modulemap
|
||||
**/*.docc/*
|
||||
*.xcprivacy
|
||||
**/*.xcprivacy
|
||||
*.symlink
|
||||
**/*.symlink
|
||||
Dockerfile
|
||||
**/Dockerfile
|
||||
Snippets/*
|
||||
dev/git.commit.template
|
||||
Sources/NIOIMAPCore/Base64
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"fileScopedDeclarationPrivacy" : {
|
||||
"accessLevel" : "private"
|
||||
},
|
||||
"indentation" : {
|
||||
"spaces" : 4
|
||||
},
|
||||
"indentConditionalCompilationBlocks" : false,
|
||||
"indentSwitchCaseLabels" : false,
|
||||
"lineBreakAroundMultilineExpressionChainComponents" : false,
|
||||
"lineBreakBeforeControlFlowKeywords" : false,
|
||||
"lineBreakBeforeEachArgument" : true,
|
||||
"lineBreakBeforeEachGenericRequirement" : true,
|
||||
"lineLength" : 120,
|
||||
"maximumBlankLines" : 1,
|
||||
"prioritizeKeepingFunctionOutputTogether" : true,
|
||||
"respectsExistingLineBreaks" : true,
|
||||
"rules" : {
|
||||
"AllPublicDeclarationsHaveDocumentation" : false,
|
||||
"AlwaysUseLowerCamelCase" : false,
|
||||
"AmbiguousTrailingClosureOverload" : true,
|
||||
"BeginDocumentationCommentWithOneLineSummary" : false,
|
||||
"DoNotUseSemicolons" : true,
|
||||
"DontRepeatTypeInStaticProperties" : true,
|
||||
"FileScopedDeclarationPrivacy" : true,
|
||||
"FullyIndirectEnum" : true,
|
||||
"GroupNumericLiterals" : true,
|
||||
"IdentifiersMustBeASCII" : true,
|
||||
"NeverForceUnwrap" : false,
|
||||
"NeverUseForceTry" : false,
|
||||
"NeverUseImplicitlyUnwrappedOptionals" : false,
|
||||
"NoAccessLevelOnExtensionDeclaration" : true,
|
||||
"NoAssignmentInExpressions" : true,
|
||||
"NoBlockComments" : true,
|
||||
"NoCasesWithOnlyFallthrough" : true,
|
||||
"NoEmptyTrailingClosureParentheses" : true,
|
||||
"NoLabelsInCasePatterns" : false,
|
||||
"NoLeadingUnderscores" : false,
|
||||
"NoParensAroundConditions" : true,
|
||||
"NoVoidReturnOnFunctionSignature" : true,
|
||||
"OneCasePerLine" : true,
|
||||
"OneVariableDeclarationPerLine" : true,
|
||||
"OnlyOneTrailingClosureArgument" : true,
|
||||
"OrderedImports" : false,
|
||||
"ReturnVoidInsteadOfEmptyTuple" : true,
|
||||
"UseEarlyExits" : true,
|
||||
"UseLetInEveryBoundCaseVariable" : false,
|
||||
"UseShorthandTypeNames" : true,
|
||||
"UseSingleLinePropertyGetter" : false,
|
||||
"UseSynthesizedInitializer" : false,
|
||||
"UseTripleSlashForDocumentationComments" : true,
|
||||
"UseWhereClausesInForLoops" : false,
|
||||
"ValidateDocumentationComments" : false
|
||||
},
|
||||
"spacesAroundRangeFormationOperators" : false,
|
||||
"tabWidth" : 4,
|
||||
"version" : 1
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
# file options
|
||||
|
||||
--swiftversion 5.7
|
||||
--exclude .build
|
||||
|
||||
# format options
|
||||
|
||||
--self insert
|
||||
--patternlet inline
|
||||
--stripunusedargs unnamed-only
|
||||
--ifdef no-indent
|
||||
|
||||
# rules
|
||||
--disable redundantParens
|
||||
--decimalgrouping ignore
|
||||
--binarygrouping ignore
|
||||
--octalgrouping ignore
|
||||
--extensionacl on-declarations
|
||||
|
||||
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Debug Proxy",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/debug/Proxy",
|
||||
"preLaunchTask": "swift: Build Debug Proxy"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Release Proxy",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/release/Proxy",
|
||||
"preLaunchTask": "swift: Build Release Proxy"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Debug NIOIMAPPerformanceTester",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/debug/NIOIMAPPerformanceTester",
|
||||
"preLaunchTask": "swift: Build Debug NIOIMAPPerformanceTester"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Release NIOIMAPPerformanceTester",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/release/NIOIMAPPerformanceTester",
|
||||
"preLaunchTask": "swift: Build Release NIOIMAPPerformanceTester"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Debug NIOIMAPFuzzer",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/debug/NIOIMAPFuzzer",
|
||||
"preLaunchTask": "swift: Build Debug NIOIMAPFuzzer"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Release NIOIMAPFuzzer",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/release/NIOIMAPFuzzer",
|
||||
"preLaunchTask": "swift: Build Release NIOIMAPFuzzer"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Debug CLI",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/debug/CLI",
|
||||
"preLaunchTask": "swift: Build Debug CLI"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:swift-nio-imap}",
|
||||
"name": "Release CLI",
|
||||
"program": "${workspaceFolder:swift-nio-imap}/.build/release/CLI",
|
||||
"preLaunchTask": "swift: Build Release CLI"
|
||||
}
|
||||
]
|
||||
}
|
||||
+2
-13
@@ -65,25 +65,14 @@ We require that your commit messages match our template. The easiest way to do t
|
||||
|
||||
The default policy for taking contributions is “Squash and Merge” - because of this the commit message format rule above applies to the PR rather than every commit contained within it.
|
||||
|
||||
### Make sure Tests work on Linux
|
||||
### Run CI checks locally
|
||||
|
||||
SwiftNIO IMAP uses XCTest to run tests on both macOS and Linux. While the macOS version of XCTest is able to use the Objective-C runtime to discover tests at execution time, the Linux version is not (prior to swift 5.1).
|
||||
For this reason, whenever you add new tests **you have to run a script** that generates the hooks needed to run those tests on Linux, or our CI will complain that the tests are not all present on Linux. To do this, merely execute `ruby ./scripts/generate_linux_tests.rb` at the root of the package and check the changes it made.
|
||||
|
||||
### Make sure your patch works for all supported versions of swift
|
||||
|
||||
The CI will do this for you. You can use the docker-compose files included if you wish to check locally. Currently all versions of swift >= 5.4 are supported. For example usage of docker compose see the main [README](./README.md#an-alternative-using-docker-compose)
|
||||
You can run the Github Actions workflows locally using [act](https://github.com/nektos/act). For detailed steps on how to do this please see [https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally](https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally).
|
||||
|
||||
### Make sure your code is performant
|
||||
|
||||
SwiftNIO has been created to be high performance. The integration tests cover some measures of performance including allocations which should be avoided if possible. For help with allocation problems refer to the guide to [allocation debugging](./docs/debugging-allocations.md)
|
||||
|
||||
### Formatting
|
||||
|
||||
Try to keep your lines less than 120 characters long so github can correctly display your changes.
|
||||
|
||||
It is intended SwiftNIO IMAP will use the swift-format tool in the future to bring consistency to code formatting. To follow the discussion on this topic see the swift evolution proposal [SE-250](https://github.com/apple/swift-evolution/blob/main/proposals/0250-swift-style-guide-and-formatter.md)
|
||||
|
||||
### Extensibility
|
||||
|
||||
Try to make sure your code is robust to future extensions. The public interface is very hard to change after release - please refer to the [SwiftNIO API guidelines](https://github.com/apple/swift-nio/blob/main/docs/public-api.md)
|
||||
|
||||
+2
-2
@@ -35,12 +35,12 @@ This product contains "Base64.swift", "DecodingError.swift", and "Chromium.swift
|
||||
* https://github.com/swift-extras/swift-extras-base64
|
||||
|
||||
* LICENSE (BSD 2-Clause):
|
||||
* https://github.com/lemire/fastbase64/blob/master/LICENSE
|
||||
* https://github.com/lemire/fastbase64/blob/63ed168854875c065bad6c1e6023fbc71f4211df/LICENSE
|
||||
* HOMEPAGE:
|
||||
* https://github.com/lemire/fastbase64
|
||||
|
||||
* LICENSE (The MIT License):
|
||||
* https://github.com/client9/stringencoders/blob/master/LICENSE
|
||||
* https://github.com/client9/stringencoders/blob/7755852327c06a17d95a978dcd013d6789323ded/LICENSE
|
||||
* HOMEPAGE:
|
||||
* https://github.com/client9/stringencoders
|
||||
|
||||
|
||||
+7
-6
@@ -6,25 +6,26 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "swift-nio-imap",
|
||||
products: [
|
||||
.library(name: "NIOIMAP", targets: ["NIOIMAP"]),
|
||||
], dependencies: [
|
||||
.library(name: "NIOIMAP", targets: ["NIOIMAP"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-nio", from: "2.64.0"),
|
||||
.package(url: "https://github.com/apple/swift-nio-ssl", from: "2.24.0"),
|
||||
.package(url: "https://github.com/apple/swift-log", from: "1.4.4"),
|
||||
.package(url: "https://github.com/apple/swift-se0270-range-set.git", from: "1.0.1"),
|
||||
.package(url: "https://github.com/apple/swift-collections.git", "1.1.0" ..< "2.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-collections.git", "1.1.0"..<"2.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "NIOIMAPPerformanceTester",
|
||||
dependencies: [
|
||||
"NIOIMAP",
|
||||
"NIOIMAP"
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "NIOIMAP",
|
||||
dependencies: [
|
||||
"NIOIMAPCore",
|
||||
"NIOIMAPCore"
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
@@ -57,7 +58,7 @@ let package = Package(
|
||||
.executableTarget(
|
||||
name: "CLI",
|
||||
dependencies: [
|
||||
"CLILib",
|
||||
"CLILib"
|
||||
]
|
||||
),
|
||||
.target(
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ResponseRoundtripHandler: ChannelInboundHandler {
|
||||
public typealias InboundIn = ByteBuffer
|
||||
public typealias InboundOut = ByteBuffer
|
||||
|
||||
// let processor = NIOSingleStepByteToMessageProcessor(ResponseDecoder())
|
||||
// let processor = NIOSingleStepByteToMessageProcessor(ResponseDecoder())
|
||||
let logger: Logger
|
||||
private var parser = ResponseParser()
|
||||
|
||||
@@ -33,41 +33,41 @@ public class ResponseRoundtripHandler: ChannelInboundHandler {
|
||||
}
|
||||
|
||||
public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
|
||||
// var buffer = self.unwrapInboundIn(data)
|
||||
// let originalString = String(buffer: buffer)
|
||||
//
|
||||
// var responses = [ResponseOrContinuationRequest]()
|
||||
// do {
|
||||
// try self.processor.process(buffer: buffer) { (response) in
|
||||
// responses.append(response)
|
||||
// }
|
||||
// } catch {
|
||||
// self.logger.error("Response parsing error: \(error)")
|
||||
// self.logger.error("Response: \(originalString)")
|
||||
// context.fireErrorCaught(error)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// buffer.clear()
|
||||
// var encodeBuffer = ResponseEncodeBuffer(buffer: buffer, capabilities: self.capabilities)
|
||||
// for response in responses {
|
||||
// switch response {
|
||||
// case .response(let response):
|
||||
// encodeBuffer.writeResponse(response)
|
||||
// case .continuationRequest(let req):
|
||||
// encodeBuffer.writeContinuationRequest(req)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let roundtripString = String(buffer: encodeBuffer.bytes)
|
||||
// if originalString != roundtripString {
|
||||
// self.logger.warning("Input response vs roundtrip output is different")
|
||||
// self.logger.warning("Response (original):\n\(originalString)")
|
||||
// self.logger.warning("Response (roundtrip):\n\(roundtripString)")
|
||||
// } else {
|
||||
// self.logger.info("\(originalString)")
|
||||
// }
|
||||
//
|
||||
// context.fireChannelRead(self.wrapInboundOut(buffer))
|
||||
// var buffer = self.unwrapInboundIn(data)
|
||||
// let originalString = String(buffer: buffer)
|
||||
//
|
||||
// var responses = [ResponseOrContinuationRequest]()
|
||||
// do {
|
||||
// try self.processor.process(buffer: buffer) { (response) in
|
||||
// responses.append(response)
|
||||
// }
|
||||
// } catch {
|
||||
// self.logger.error("Response parsing error: \(error)")
|
||||
// self.logger.error("Response: \(originalString)")
|
||||
// context.fireErrorCaught(error)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// buffer.clear()
|
||||
// var encodeBuffer = ResponseEncodeBuffer(buffer: buffer, capabilities: self.capabilities)
|
||||
// for response in responses {
|
||||
// switch response {
|
||||
// case .response(let response):
|
||||
// encodeBuffer.writeResponse(response)
|
||||
// case .continuationRequest(let req):
|
||||
// encodeBuffer.writeContinuationRequest(req)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let roundtripString = String(buffer: encodeBuffer.bytes)
|
||||
// if originalString != roundtripString {
|
||||
// self.logger.warning("Input response vs roundtrip output is different")
|
||||
// self.logger.warning("Response (original):\n\(originalString)")
|
||||
// self.logger.warning("Response (roundtrip):\n\(roundtripString)")
|
||||
// } else {
|
||||
// self.logger.info("\(originalString)")
|
||||
// }
|
||||
//
|
||||
// context.fireChannelRead(self.wrapInboundOut(buffer))
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,9 @@ public class CommandRoundtripHandler: ChannelOutboundHandler {
|
||||
var originalBuffer = self.unwrapOutboundIn(data)
|
||||
do {
|
||||
var originalBufferCopy = originalBuffer
|
||||
guard let commandStream = try parser.parseCommandStream(buffer: &originalBufferCopy), let command = commandStream.commandPart else {
|
||||
guard let commandStream = try parser.parseCommandStream(buffer: &originalBufferCopy),
|
||||
let command = commandStream.commandPart
|
||||
else {
|
||||
// this is fine because the command is input by the user, so *should* be valid
|
||||
throw CommandRoundtripError.incompleteCommand
|
||||
}
|
||||
@@ -53,8 +55,12 @@ public class CommandRoundtripHandler: ChannelOutboundHandler {
|
||||
|
||||
if originalBuffer != roundtripBuffer {
|
||||
self.logger.warning("Input command vs roundtrip output is different")
|
||||
self.logger.warning("Command (original):\n\(originalBuffer.readString(length: originalBuffer.readableBytes)!)")
|
||||
self.logger.warning("Command (roundtrip):\n\(roundtripBuffer.readString(length: roundtripBuffer.readableBytes)!)")
|
||||
self.logger.warning(
|
||||
"Command (original):\n\(originalBuffer.readString(length: originalBuffer.readableBytes)!)"
|
||||
)
|
||||
self.logger.warning(
|
||||
"Command (roundtrip):\n\(roundtripBuffer.readString(length: roundtripBuffer.readableBytes)!)"
|
||||
)
|
||||
}
|
||||
|
||||
context.write(data, promise: promise)
|
||||
|
||||
@@ -57,7 +57,8 @@ extension ClientStateMachine {
|
||||
|
||||
var hasCatenatedAtLeastOneObject: Bool {
|
||||
switch self.state {
|
||||
case .started, .waitingForAppendContinuationRequest, .sendingMessageBytes, .waitingForCatenateContinuationRequest, .sendingCatenateBytes, .waitingForTaggedResponse, .finished:
|
||||
case .started, .waitingForAppendContinuationRequest, .sendingMessageBytes,
|
||||
.waitingForCatenateContinuationRequest, .sendingCatenateBytes, .waitingForTaggedResponse, .finished:
|
||||
return false
|
||||
case .catenating(sentFirstObject: let sentFirstObject):
|
||||
return sentFirstObject
|
||||
@@ -69,7 +70,7 @@ extension ClientStateMachine {
|
||||
mutating func receiveResponse(_ response: Response) throws -> Bool {
|
||||
switch self.state {
|
||||
case .started, .waitingForAppendContinuationRequest, .sendingMessageBytes, .catenating,
|
||||
.waitingForCatenateContinuationRequest, .sendingCatenateBytes, .finished:
|
||||
.waitingForCatenateContinuationRequest, .sendingCatenateBytes, .finished:
|
||||
throw UnexpectedContinuationRequest()
|
||||
case .waitingForTaggedResponse:
|
||||
break
|
||||
@@ -87,7 +88,7 @@ extension ClientStateMachine {
|
||||
mutating func receiveContinuationRequest(_: ContinuationRequest) throws {
|
||||
switch self.state {
|
||||
case .started, .sendingMessageBytes, .catenating,
|
||||
.sendingCatenateBytes, .finished, .waitingForTaggedResponse:
|
||||
.sendingCatenateBytes, .finished, .waitingForTaggedResponse:
|
||||
throw UnexpectedContinuationRequest()
|
||||
case .waitingForAppendContinuationRequest:
|
||||
self.state = .sendingMessageBytes
|
||||
@@ -108,7 +109,8 @@ extension ClientStateMachine {
|
||||
}
|
||||
|
||||
switch self.state {
|
||||
case .waitingForTaggedResponse, .waitingForAppendContinuationRequest, .waitingForCatenateContinuationRequest, .finished:
|
||||
case .waitingForTaggedResponse, .waitingForAppendContinuationRequest,
|
||||
.waitingForCatenateContinuationRequest, .finished:
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
case .started:
|
||||
return self.sendCommand_startedState(appendCommand)
|
||||
@@ -157,14 +159,15 @@ extension ClientStateMachine.Append {
|
||||
case .endMessage:
|
||||
self.state = .started(canFinish: true)
|
||||
case .messageBytes:
|
||||
self.state = .sendingMessageBytes // continue sending bytes until we're told to stop
|
||||
self.state = .sendingMessageBytes // continue sending bytes until we're told to stop
|
||||
}
|
||||
}
|
||||
|
||||
/// `true` if a continuation is required, otherwise `false`
|
||||
private mutating func sendCommand_catenatingState(_ command: AppendCommand) -> Bool {
|
||||
switch command {
|
||||
case .start, .beginMessage, .beginCatenate, .messageBytes, .endMessage, .finish, .catenateData(.bytes), .catenateData(.end):
|
||||
case .start, .beginMessage, .beginCatenate, .messageBytes, .endMessage, .finish, .catenateData(.bytes),
|
||||
.catenateData(.end):
|
||||
preconditionFailure("Invalid command for state: \(self.state)")
|
||||
case .catenateURL:
|
||||
self.state = .catenating(sentFirstObject: true)
|
||||
@@ -181,12 +184,13 @@ extension ClientStateMachine.Append {
|
||||
/// `true` if a continuation is required, otherwise `false`
|
||||
private mutating func sendCommand_sendingCatenateBytesState(_ command: AppendCommand) {
|
||||
switch command {
|
||||
case .start, .beginMessage, .beginCatenate, .endMessage, .catenateURL, .messageBytes, .finish, .endCatenate, .catenateData(.begin):
|
||||
case .start, .beginMessage, .beginCatenate, .endMessage, .catenateURL, .messageBytes, .finish, .endCatenate,
|
||||
.catenateData(.begin):
|
||||
preconditionFailure("Invalid command for state: \(self.state)")
|
||||
case .catenateData(.end):
|
||||
self.state = .catenating(sentFirstObject: true)
|
||||
case .catenateData(.bytes):
|
||||
self.state = .sendingCatenateBytes // continue sending bytes until we're told to stop
|
||||
self.state = .sendingCatenateBytes // continue sending bytes until we're told to stop
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,9 @@ public struct FramingParser: Hashable, Sendable {
|
||||
/// - returns: An array of frames.
|
||||
/// - throws: `InvalidFrame` if a frame was found to be unparsable.
|
||||
/// - throws: `LiteralSizeParsingError` if when parsing a literal header we found an invalid size field.
|
||||
@_spi(NIOIMAPInternal) public mutating func appendAndFrameBuffer(_ buffer: inout ByteBuffer) throws -> [FramingResult] {
|
||||
@_spi(NIOIMAPInternal) public mutating func appendAndFrameBuffer(
|
||||
_ buffer: inout ByteBuffer
|
||||
) throws -> [FramingResult] {
|
||||
// fast paths should be fast
|
||||
guard buffer.readableBytes > 0 else {
|
||||
return []
|
||||
@@ -160,7 +162,9 @@ public struct FramingParser: Hashable, Sendable {
|
||||
return try self.adjustBufferAndParseFrames()
|
||||
}
|
||||
|
||||
@_spi(NIOIMAPInternal) public mutating func appendAndFrameBytes(_ bytes: UnsafeRawBufferPointer) throws -> [FramingResult] {
|
||||
@_spi(NIOIMAPInternal) public mutating func appendAndFrameBytes(
|
||||
_ bytes: UnsafeRawBufferPointer
|
||||
) throws -> [FramingResult] {
|
||||
// fast paths should be fast
|
||||
guard !bytes.isEmpty else {
|
||||
return []
|
||||
@@ -247,12 +251,11 @@ public struct FramingParser: Hashable, Sendable {
|
||||
|
||||
case .insideLiteral(lineFeedStrategy: let lfs, remaining: let remaining):
|
||||
self.readByte_state_insideLiteral(lineFeedStrategy: lfs, remainingLiteralBytes: remaining)
|
||||
if self.frameLength > 0 {
|
||||
let buffer = self.readFrame()
|
||||
return .insideLiteral(buffer, remainingBytes: remaining - UInt64(buffer.readableBytes))
|
||||
} else {
|
||||
guard self.frameLength > 0 else {
|
||||
return .incomplete(self.generateIncompleteFramingResult())
|
||||
}
|
||||
let buffer = self.readFrame()
|
||||
return .insideLiteral(buffer, remainingBytes: remaining - UInt64(buffer.readableBytes))
|
||||
}
|
||||
}
|
||||
return .incomplete(self.generateIncompleteFramingResult())
|
||||
@@ -276,27 +279,27 @@ public struct FramingParser: Hashable, Sendable {
|
||||
private func generateIncompleteFramingResult() -> Int {
|
||||
switch self.state {
|
||||
case .normalTraversal:
|
||||
return 2 // we need the CRLF (not strictly _need_ as we're lenient)
|
||||
return 2 // we need the CRLF (not strictly _need_ as we're lenient)
|
||||
case .insideQuoted:
|
||||
return 3 // we need the last quote + CRLF
|
||||
return 3 // we need the last quote + CRLF
|
||||
case .foundCR:
|
||||
return 0
|
||||
case .searchingForLiteralHeader(let substate):
|
||||
switch substate {
|
||||
case .findingBinaryFlag:
|
||||
return 4 // <size(1 byte minimum)> + } + CRLF
|
||||
return 4 // <size(1 byte minimum)> + } + CRLF
|
||||
case .findingSize(let buffer):
|
||||
// if we have some size bytes already we don't strictly _need_ more
|
||||
return buffer.readableBytes > 0 ? 3 : 4
|
||||
case .findingLiteralExtension:
|
||||
return 3 // } + CRLF
|
||||
return 3 // } + CRLF
|
||||
case .findingClosingCurly:
|
||||
return 3 // } + CRLF
|
||||
return 3 // } + CRLF
|
||||
case .findingCR:
|
||||
return 2 // CRLF
|
||||
return 2 // CRLF
|
||||
}
|
||||
case .insideLiteral:
|
||||
return 1 // always forward on bytes instantly
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +309,8 @@ public struct FramingParser: Hashable, Sendable {
|
||||
defer {
|
||||
self.frameLength &+= 1
|
||||
}
|
||||
return self.buffer.getInteger(at: self.buffer.readerIndex + self.frameLength)! // we've asserted this is ok
|
||||
// we've asserted this is ok
|
||||
return self.buffer.getInteger(at: self.buffer.readerIndex + self.frameLength)!
|
||||
}
|
||||
|
||||
private mutating func maybeReadByte() -> UInt8? {
|
||||
@@ -329,7 +333,8 @@ public struct FramingParser: Hashable, Sendable {
|
||||
guard self.frameLength < self.buffer.readableBytes else {
|
||||
return nil
|
||||
}
|
||||
return self.buffer.getInteger(at: self.buffer.readerIndex + self.frameLength, as: UInt8.self)! // we've asserted this is ok
|
||||
// we've asserted this is ok
|
||||
return self.buffer.getInteger(at: self.buffer.readerIndex + self.frameLength, as: UInt8.self)!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +450,10 @@ extension FramingParser {
|
||||
return try self.readByte_state_searchingForLiteralHeader_findingSize(sizeBuffer: sizeBuffer)
|
||||
}
|
||||
|
||||
private mutating func readByte_state_insideLiteral(lineFeedStrategy: LineFeedByteStrategy, remainingLiteralBytes: UInt64) {
|
||||
private mutating func readByte_state_insideLiteral(
|
||||
lineFeedStrategy: LineFeedByteStrategy,
|
||||
remainingLiteralBytes: UInt64
|
||||
) {
|
||||
switch lineFeedStrategy {
|
||||
case .ignoreFirst:
|
||||
if let byte = self.peekByte(), byte == LF {
|
||||
@@ -461,17 +469,22 @@ extension FramingParser {
|
||||
self.state = .normalTraversal(.includeInFrame)
|
||||
} else {
|
||||
self.frameLength &+= bytesAvailable
|
||||
self.state = .insideLiteral(lineFeedStrategy: .includeInFrame, remaining: remainingLiteralBytes - UInt64(bytesAvailable))
|
||||
self.state = .insideLiteral(
|
||||
lineFeedStrategy: .includeInFrame,
|
||||
remaining: remainingLiteralBytes - UInt64(bytesAvailable)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingSize(sizeBuffer: ByteBuffer) throws -> FrameStatus {
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingSize(
|
||||
sizeBuffer: ByteBuffer
|
||||
) throws -> FrameStatus {
|
||||
var sizeBuffer = sizeBuffer
|
||||
|
||||
// First scan for the end of the literal size
|
||||
while let byte = self.maybeReadByte() {
|
||||
switch byte {
|
||||
case DIGIT_0 ... DIGIT_9:
|
||||
case DIGIT_0...DIGIT_9:
|
||||
sizeBuffer.writeInteger(byte)
|
||||
guard sizeBuffer.readableBytes <= UInt64.maximumAllowedCharacters else {
|
||||
throw LiteralSizeParsingError(buffer: sizeBuffer)
|
||||
@@ -497,7 +510,9 @@ extension FramingParser {
|
||||
return .continueParsing
|
||||
}
|
||||
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingLiteralExtension(_ size: UInt64) throws -> FrameStatus {
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingLiteralExtension(
|
||||
_ size: UInt64
|
||||
) throws -> FrameStatus {
|
||||
guard let byte = self.maybeReadByte() else {
|
||||
return .continueParsing
|
||||
}
|
||||
@@ -514,17 +529,18 @@ extension FramingParser {
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingClosingCurly(_ size: UInt64) throws -> FrameStatus {
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingClosingCurly(
|
||||
_ size: UInt64
|
||||
) throws -> FrameStatus {
|
||||
guard let byte = self.maybeReadByte() else {
|
||||
return .continueParsing
|
||||
}
|
||||
|
||||
if byte == LITERAL_HEADER_END {
|
||||
self.state = .searchingForLiteralHeader(.findingCR(size))
|
||||
return try self.readByte_state_searchingForLiteralHeader_findingCR(size)
|
||||
} else {
|
||||
guard byte == LITERAL_HEADER_END else {
|
||||
throw InvalidFrame()
|
||||
}
|
||||
self.state = .searchingForLiteralHeader(.findingCR(size))
|
||||
return try self.readByte_state_searchingForLiteralHeader_findingCR(size)
|
||||
}
|
||||
|
||||
private mutating func readByte_state_searchingForLiteralHeader_findingCR(_ size: UInt64) throws -> FrameStatus {
|
||||
|
||||
@@ -57,7 +57,8 @@ struct OutgoingChunk: Equatable {
|
||||
var shouldSucceedPromise: Bool
|
||||
|
||||
static func == (lhs: OutgoingChunk, rhs: OutgoingChunk) -> Bool {
|
||||
lhs.shouldSucceedPromise == rhs.shouldSucceedPromise && lhs.bytes == rhs.bytes && lhs.promise?.futureResult === rhs.promise?.futureResult
|
||||
lhs.shouldSucceedPromise == rhs.shouldSucceedPromise && lhs.bytes == rhs.bytes
|
||||
&& lhs.promise?.futureResult === rhs.promise?.futureResult
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +92,10 @@ struct ClientStateMachine {
|
||||
return .init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: !chunk.waitForContinuation)
|
||||
}
|
||||
|
||||
static func == (lhs: ClientStateMachine.ActiveEncodeContext, rhs: ClientStateMachine.ActiveEncodeContext) -> Bool {
|
||||
static func == (
|
||||
lhs: ClientStateMachine.ActiveEncodeContext,
|
||||
rhs: ClientStateMachine.ActiveEncodeContext
|
||||
) -> Bool {
|
||||
lhs.buffer == rhs.buffer && lhs.promise?.futureResult == rhs.promise?.futureResult
|
||||
}
|
||||
}
|
||||
@@ -138,7 +142,9 @@ struct ClientStateMachine {
|
||||
|
||||
// We mark where we should write up to at the next opportunity
|
||||
// using the `flush` method called from the channel handler.
|
||||
private var queuedCommands: MarkedCircularBuffer<(CommandStreamPart, EventLoopPromise<Void>?)> = .init(initialCapacity: 16)
|
||||
private var queuedCommands: MarkedCircularBuffer<(CommandStreamPart, EventLoopPromise<Void>?)> = .init(
|
||||
initialCapacity: 16
|
||||
)
|
||||
|
||||
init(encodingOptions: CommandEncodingOptions) {
|
||||
self.encodingOptions = encodingOptions
|
||||
@@ -231,7 +237,10 @@ struct ClientStateMachine {
|
||||
|
||||
/// Tells the state machine that the client would like to send a command.
|
||||
/// We then return any chunks that can be written.
|
||||
mutating func sendCommand(_ command: CommandStreamPart, promise: EventLoopPromise<Void>? = nil) throws -> OutgoingChunk? {
|
||||
mutating func sendCommand(
|
||||
_ command: CommandStreamPart,
|
||||
promise: EventLoopPromise<Void>? = nil
|
||||
) throws -> OutgoingChunk? {
|
||||
precondition(self.state != .error, "Already in error state, make sure to handle appropriately")
|
||||
|
||||
if let tag = command.tag {
|
||||
@@ -288,8 +297,11 @@ struct ClientStateMachine {
|
||||
// MARK: - Receive
|
||||
|
||||
extension ClientStateMachine {
|
||||
private mutating func receiveContinuationRequest_appending(request: ContinuationRequest) throws -> ContinuationRequestAction {
|
||||
guard case .appending(var appendingStateMachine, pendingContinuation: let pendingContinuation) = self.state else {
|
||||
private mutating func receiveContinuationRequest_appending(
|
||||
request: ContinuationRequest
|
||||
) throws -> ContinuationRequestAction {
|
||||
guard case .appending(var appendingStateMachine, pendingContinuation: let pendingContinuation) = self.state
|
||||
else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
guard pendingContinuation else {
|
||||
@@ -313,7 +325,7 @@ extension ClientStateMachine {
|
||||
|
||||
// safe to bang as if we've successfully received a
|
||||
// continuation request then MUST be something to send
|
||||
if let nextContext = result.nextContext { // we've found another continuation
|
||||
if let nextContext = result.nextContext { // we've found another continuation
|
||||
self.state = .expectingLiteralContinuationRequest(nextContext)
|
||||
} else {
|
||||
self.state = .expectingNormalResponse
|
||||
@@ -321,7 +333,9 @@ extension ClientStateMachine {
|
||||
return .sendChunks(result.chunks)
|
||||
}
|
||||
|
||||
private mutating func receiveContinuationRequest_authenticating(request: ContinuationRequest) throws -> ContinuationRequestAction {
|
||||
private mutating func receiveContinuationRequest_authenticating(
|
||||
request: ContinuationRequest
|
||||
) throws -> ContinuationRequestAction {
|
||||
guard case .authenticating(var authenticatingStateMachine) = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -338,7 +352,9 @@ extension ClientStateMachine {
|
||||
return .fireAuthenticationChallenge
|
||||
}
|
||||
|
||||
private mutating func receiveContinuationRequest_idle(request: ContinuationRequest) throws -> ContinuationRequestAction {
|
||||
private mutating func receiveContinuationRequest_idle(
|
||||
request: ContinuationRequest
|
||||
) throws -> ContinuationRequestAction {
|
||||
guard case .idle(var idleStateMachine) = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -353,7 +369,10 @@ extension ClientStateMachine {
|
||||
// MARK: - Send
|
||||
|
||||
extension ClientStateMachine {
|
||||
private mutating func sendTaggedCommand(_ command: TaggedCommand, promise: EventLoopPromise<Void>?) -> SendableChunks {
|
||||
private mutating func sendTaggedCommand(
|
||||
_ command: TaggedCommand,
|
||||
promise: EventLoopPromise<Void>?
|
||||
) -> SendableChunks {
|
||||
guard case .expectingNormalResponse = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -374,18 +393,20 @@ extension ClientStateMachine {
|
||||
let chunk = context.nextChunk()
|
||||
|
||||
// if we're meant to succeed the promise then there can't be any next context
|
||||
if chunk.shouldSucceedPromise {
|
||||
precondition(context.nextChunk().bytes.readableBytes == 0)
|
||||
self.state = .expectingNormalResponse
|
||||
return .init(chunks: [chunk], nextContext: nil)
|
||||
} else {
|
||||
guard chunk.shouldSucceedPromise else {
|
||||
self.state = .expectingLiteralContinuationRequest(context)
|
||||
return .init(chunks: [chunk], nextContext: context)
|
||||
}
|
||||
precondition(context.nextChunk().bytes.readableBytes == 0)
|
||||
self.state = .expectingNormalResponse
|
||||
return .init(chunks: [chunk], nextContext: nil)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func sendAppendCommand(_ command: AppendCommand, promise: EventLoopPromise<Void>?) -> SendableChunks {
|
||||
private mutating func sendAppendCommand(
|
||||
_ command: AppendCommand,
|
||||
promise: EventLoopPromise<Void>?
|
||||
) -> SendableChunks {
|
||||
guard case .expectingNormalResponse = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -412,12 +433,11 @@ extension ClientStateMachine {
|
||||
var results: [OutgoingChunk] = []
|
||||
if var currentContext = currentContext {
|
||||
let chunk = currentContext.nextChunk()
|
||||
if chunk.shouldSucceedPromise {
|
||||
results.append(chunk)
|
||||
} else {
|
||||
guard chunk.shouldSucceedPromise else {
|
||||
self.state = .expectingLiteralContinuationRequest(currentContext)
|
||||
return .init(chunks: [chunk], nextContext: currentContext)
|
||||
}
|
||||
results.append(chunk)
|
||||
}
|
||||
|
||||
while self.queuedCommands.hasMark, let sendableChunk = self.sendNextCommand() {
|
||||
@@ -483,7 +503,10 @@ extension ClientStateMachine {
|
||||
/// command we want to send may require a continuation itself. We begin by writing the command to
|
||||
/// an encode buffer to isolate any required continuations, and then send every chunk until we run out of chunks
|
||||
/// to send, or we find a chunk that requires a continuation request.
|
||||
private mutating func sendNextCommand_expectingNormalResponse(command: CommandStreamPart, promise: EventLoopPromise<Void>?) -> SendableChunks {
|
||||
private mutating func sendNextCommand_expectingNormalResponse(
|
||||
command: CommandStreamPart,
|
||||
promise: EventLoopPromise<Void>?
|
||||
) -> SendableChunks {
|
||||
guard case .expectingNormalResponse = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -501,7 +524,10 @@ extension ClientStateMachine {
|
||||
/// When idle we need to first defer to the idle state machine to make sure we can send the
|
||||
/// the next part of the authentication. If we can, then just send the message. There's no need
|
||||
/// to wait for a continuation request.
|
||||
private mutating func sendNextCommand_idle(command: CommandStreamPart, promise: EventLoopPromise<Void>?) -> SendableChunks {
|
||||
private mutating func sendNextCommand_idle(
|
||||
command: CommandStreamPart,
|
||||
promise: EventLoopPromise<Void>?
|
||||
) -> SendableChunks {
|
||||
guard case .idle(var idleStateMachine) = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -514,13 +540,19 @@ extension ClientStateMachine {
|
||||
var encodeBuffer = self.makeEncodeBuffer(command)
|
||||
let chunk = encodeBuffer.buffer.nextChunk()
|
||||
precondition(!chunk.waitForContinuation)
|
||||
return .init(chunks: [.init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: true)], nextContext: nil)
|
||||
return .init(
|
||||
chunks: [.init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: true)],
|
||||
nextContext: nil
|
||||
)
|
||||
}
|
||||
|
||||
/// When authenticating we need to first defer to the authentication state machine to make sure
|
||||
/// can send the next part of the authentication. If we can, then just send the message. There's
|
||||
/// no need to wait for a continuation request.
|
||||
private mutating func sendNextCommand_authenticating(command: CommandStreamPart, promise: EventLoopPromise<Void>?) -> SendableChunks {
|
||||
private mutating func sendNextCommand_authenticating(
|
||||
command: CommandStreamPart,
|
||||
promise: EventLoopPromise<Void>?
|
||||
) -> SendableChunks {
|
||||
guard case .authenticating(var authenticatingStateMachine) = self.state else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
@@ -533,15 +565,22 @@ extension ClientStateMachine {
|
||||
var encodeBuffer = self.makeEncodeBuffer(.continuationResponse(data))
|
||||
let chunk = encodeBuffer.buffer.nextChunk()
|
||||
precondition(!chunk.waitForContinuation)
|
||||
return .init(chunks: [.init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: true)], nextContext: nil)
|
||||
return .init(
|
||||
chunks: [.init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: true)],
|
||||
nextContext: nil
|
||||
)
|
||||
}
|
||||
|
||||
/// When appending we need to first defer to the appending state machine to see if we can actually
|
||||
/// send a command given our current state. If we can then we need to check what kind of command
|
||||
/// is being sent. If we're beginning an append or catenation then we need to wait for a continuation
|
||||
/// request, otherwise we can send the command and continue.
|
||||
private mutating func sendNextCommand_appending(command: CommandStreamPart, promise: EventLoopPromise<Void>?) -> SendableChunks? {
|
||||
guard case .appending(var appendingStateMachine, pendingContinuation: let pendingContinuation) = self.state else {
|
||||
private mutating func sendNextCommand_appending(
|
||||
command: CommandStreamPart,
|
||||
promise: EventLoopPromise<Void>?
|
||||
) -> SendableChunks? {
|
||||
guard case .appending(var appendingStateMachine, pendingContinuation: let pendingContinuation) = self.state
|
||||
else {
|
||||
preconditionFailure("Invalid state: \(self.state)")
|
||||
}
|
||||
guard case .append(let command) = command else {
|
||||
@@ -568,6 +607,9 @@ extension ClientStateMachine {
|
||||
|
||||
// We always need append commands to be sent instantly so we can receive continuations
|
||||
// so the write promise should always be succeeded.
|
||||
return .init(chunks: [.init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: true)], nextContext: nil)
|
||||
return .init(
|
||||
chunks: [.init(bytes: chunk.bytes, promise: promise, shouldSucceedPromise: true)],
|
||||
nextContext: nil
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,11 @@ class CommandEncoder: MessageToByteEncoder {
|
||||
}
|
||||
|
||||
func encode(data: CommandStreamPart, out: inout ByteBuffer) {
|
||||
var encodeBuffer = CommandEncodeBuffer(buffer: out, capabilities: self.capabilities, loggingMode: self.loggingMode)
|
||||
var encodeBuffer = CommandEncodeBuffer(
|
||||
buffer: out,
|
||||
capabilities: self.capabilities,
|
||||
loggingMode: self.loggingMode
|
||||
)
|
||||
encodeBuffer.writeCommandStream(data)
|
||||
out = encodeBuffer.buffer.nextChunk().bytes
|
||||
}
|
||||
|
||||
@@ -42,9 +42,17 @@ public final class IMAPClientHandler: ChannelDuplexHandler {
|
||||
/// capabilities.
|
||||
var encodingChangeCallback: (OrderedDictionary<String, String?>, inout CommandEncodingOptions) -> Void
|
||||
|
||||
public init(encodingChangeCallback: @escaping (OrderedDictionary<String, String?>, inout CommandEncodingOptions) -> Void = { _, _ in }) {
|
||||
public init(
|
||||
encodingChangeCallback: @escaping (OrderedDictionary<String, String?>, inout CommandEncodingOptions) -> Void = {
|
||||
_,
|
||||
_ in
|
||||
}
|
||||
) {
|
||||
self.state = .init(encodingOptions: CommandEncodingOptions(capabilities: self.lastKnownCapabilities))
|
||||
self.decoder = NIOSingleStepByteToMessageProcessor(ResponseDecoder(), maximumBufferSize: IMAPDefaults.lineLengthLimit)
|
||||
self.decoder = NIOSingleStepByteToMessageProcessor(
|
||||
ResponseDecoder(),
|
||||
maximumBufferSize: IMAPDefaults.lineLengthLimit
|
||||
)
|
||||
self.encodingChangeCallback = encodingChangeCallback
|
||||
self.lastKnownCapabilities = []
|
||||
}
|
||||
@@ -74,7 +82,10 @@ public final class IMAPClientHandler: ChannelDuplexHandler {
|
||||
context.fireChannelActive()
|
||||
}
|
||||
|
||||
private func handleResponseOrContinuationRequest(_ response: ResponseOrContinuationRequest, context: ChannelHandlerContext) throws {
|
||||
private func handleResponseOrContinuationRequest(
|
||||
_ response: ResponseOrContinuationRequest,
|
||||
context: ChannelHandlerContext
|
||||
) throws {
|
||||
switch response {
|
||||
case .continuationRequest(let continuationRequest):
|
||||
let action = try self.state.receiveContinuationRequest(continuationRequest)
|
||||
@@ -95,7 +106,11 @@ public final class IMAPClientHandler: ChannelDuplexHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private func handleContinuationRequestAction(_ action: ClientStateMachine.ContinuationRequestAction, request: ContinuationRequest, context: ChannelHandlerContext) {
|
||||
private func handleContinuationRequestAction(
|
||||
_ action: ClientStateMachine.ContinuationRequestAction,
|
||||
request: ContinuationRequest,
|
||||
context: ChannelHandlerContext
|
||||
) {
|
||||
switch action {
|
||||
case .sendChunks(let chunks):
|
||||
self.writeChunks(chunks, context: context)
|
||||
@@ -107,7 +122,9 @@ public final class IMAPClientHandler: ChannelDuplexHandler {
|
||||
switch request {
|
||||
case .responseText:
|
||||
// No valid base64, so forward on an empty BB
|
||||
context.fireChannelRead(self.wrapInboundOut(.authenticationChallenge(context.channel.allocator.buffer(capacity: 0))))
|
||||
context.fireChannelRead(
|
||||
self.wrapInboundOut(.authenticationChallenge(context.channel.allocator.buffer(capacity: 0)))
|
||||
)
|
||||
case .data(let byteBuffer):
|
||||
context.fireChannelRead(self.wrapInboundOut(.authenticationChallenge(byteBuffer)))
|
||||
}
|
||||
@@ -131,7 +148,7 @@ public final class IMAPClientHandler: ChannelDuplexHandler {
|
||||
chunks.forEach { chunk in
|
||||
self.writeChunk(chunk, context: context)
|
||||
}
|
||||
context.flush() // we wouldn't reach this point if we hadn't already flushed
|
||||
context.flush() // we wouldn't reach this point if we hadn't already flushed
|
||||
}
|
||||
|
||||
private func writeChunk(_ chunk: OutgoingChunk, context: ChannelHandlerContext) {
|
||||
|
||||
@@ -55,12 +55,22 @@ public final class IMAPServerHandler: ChannelDuplexHandler {
|
||||
private var numberOfOutstandingContinuationRequests = 0
|
||||
private var continuationRequestBytes: ByteBuffer
|
||||
|
||||
private var responseEncodeBuffer = ResponseEncodeBuffer(buffer: ByteBuffer(string: ""), options: .init(), loggingMode: false)
|
||||
private var responseEncodeBuffer = ResponseEncodeBuffer(
|
||||
buffer: ByteBuffer(string: ""),
|
||||
options: .init(),
|
||||
loggingMode: false
|
||||
)
|
||||
|
||||
public var capabilities: [Capability] = []
|
||||
|
||||
public init(continuationRequest: ContinuationRequest = .responseText(ResponseText(text: "OK")), literalSizeLimit: Int = IMAPDefaults.literalSizeLimit) {
|
||||
self.decoder = NIOSingleStepByteToMessageProcessor(CommandDecoder(literalSizeLimit: literalSizeLimit), maximumBufferSize: IMAPDefaults.lineLengthLimit)
|
||||
public init(
|
||||
continuationRequest: ContinuationRequest = .responseText(ResponseText(text: "OK")),
|
||||
literalSizeLimit: Int = IMAPDefaults.literalSizeLimit
|
||||
) {
|
||||
self.decoder = NIOSingleStepByteToMessageProcessor(
|
||||
CommandDecoder(literalSizeLimit: literalSizeLimit),
|
||||
maximumBufferSize: IMAPDefaults.lineLengthLimit
|
||||
)
|
||||
self._continuationRequest = continuationRequest
|
||||
let buffer = ByteBufferAllocator().buffer(capacity: 16)
|
||||
var encodeBuffer = ResponseEncodeBuffer(buffer: buffer, capabilities: self.capabilities, loggingMode: false)
|
||||
@@ -77,7 +87,7 @@ public final class IMAPServerHandler: ChannelDuplexHandler {
|
||||
return
|
||||
}
|
||||
|
||||
for _ in 0 ..< outstanding {
|
||||
for _ in 0..<outstanding {
|
||||
context.write(self.wrapOutboundOut(self.continuationRequestBytes), promise: nil)
|
||||
}
|
||||
context.flush()
|
||||
|
||||
@@ -1,3 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// swift-format-ignore: NoBlockComments
|
||||
// This base64 implementation is heavily inspired by:
|
||||
// https://github.com/lemire/fastbase64/blob/master/src/chromiumbase64.c ignore-unacceptable-language
|
||||
/*
|
||||
Copyright (c) 2015-2016, Wojciech Muła, Alfred Klomp, Daniel Lemire
|
||||
(Unless otherwise stated in the source code)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// https://github.com/client9/stringencoders/blob/master/src/modp_b64.c ignore-unacceptable-language
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Nick Galbreath
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// https://github.com/swift-extras/swift-extras-base64
|
||||
|
||||
// minor modifications to remove public attributes
|
||||
@@ -40,8 +112,7 @@ enum Base64 {
|
||||
extension String {
|
||||
@usableFromInline
|
||||
init<Buffer: Collection>(base64Encoding bytes: Buffer, options: Base64.EncodingOptions = [])
|
||||
where Buffer.Element == UInt8
|
||||
{
|
||||
where Buffer.Element == UInt8 {
|
||||
self = Base64.encodeString(bytes: bytes, options: options)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This base64 implementation is heavily inspired by:
|
||||
// swift-format-ignore: NoBlockComments
|
||||
// https://github.com/lemire/fastbase64/blob/master/src/chromiumbase64.c ignore-unacceptable-language
|
||||
|
||||
/*
|
||||
Copyright (c) 2015-2016, Wojciech Muła, Alfred Klomp, Daniel Lemire
|
||||
(Unless otherwise stated in the source code)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// https://github.com/client9/stringencoders/blob/master/src/modp_b64.c ignore-unacceptable-language
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Nick Galbreath
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// https://github.com/swift-extras/swift-extras-base64
|
||||
|
||||
// minor modifications to remove public attributes
|
||||
|
||||
// https://github.com/lemire/fastbase64/blob/master/src/chromiumbase64.c
|
||||
// https://github.com/lemire/fastbase64/blob/1bdf8fdd8d1182a7c5c29ec24ea38aa46da11f64/src/chromiumbase64.c
|
||||
|
||||
// MARK: - Encoding -
|
||||
|
||||
@@ -12,126 +85,233 @@ extension Base64 {
|
||||
|
||||
@usableFromInline
|
||||
static let encoding0: [UInt8] = [
|
||||
UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "C"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"),
|
||||
UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "H"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "M"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"),
|
||||
UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "R"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "W"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"),
|
||||
UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "b"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "g"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"),
|
||||
UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "l"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "q"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"),
|
||||
UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "v"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "0"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"),
|
||||
UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "5"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "+"),
|
||||
UInt8(ascii: "+"), UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "/"), UInt8(ascii: "/"), UInt8(ascii: "/"),
|
||||
UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "B"),
|
||||
UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "C"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "D"),
|
||||
UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"),
|
||||
UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "G"),
|
||||
UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "H"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "I"),
|
||||
UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "L"),
|
||||
UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "M"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "N"),
|
||||
UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"),
|
||||
UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "Q"),
|
||||
UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "R"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "S"),
|
||||
UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "V"),
|
||||
UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "W"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "X"),
|
||||
UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"),
|
||||
UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "a"),
|
||||
UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "b"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "c"),
|
||||
UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "f"),
|
||||
UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "g"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "h"),
|
||||
UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"),
|
||||
UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "k"),
|
||||
UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "l"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "m"),
|
||||
UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "p"),
|
||||
UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "q"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "r"),
|
||||
UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"),
|
||||
UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "u"),
|
||||
UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "v"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "w"),
|
||||
UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "z"),
|
||||
UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "0"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "1"),
|
||||
UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"),
|
||||
UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "4"),
|
||||
UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "5"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "6"),
|
||||
UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "9"),
|
||||
UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "+"),
|
||||
UInt8(ascii: "+"), UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "/"), UInt8(ascii: "/"),
|
||||
UInt8(ascii: "/"),
|
||||
]
|
||||
|
||||
@usableFromInline
|
||||
static let encoding1: [UInt8] = [
|
||||
UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"),
|
||||
UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"),
|
||||
UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"),
|
||||
UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"),
|
||||
UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"),
|
||||
UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"),
|
||||
UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "A"), UInt8(ascii: "B"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"),
|
||||
UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "/"),
|
||||
UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"),
|
||||
UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"),
|
||||
UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"),
|
||||
UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"),
|
||||
UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"),
|
||||
UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"),
|
||||
UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "A"),
|
||||
UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"),
|
||||
UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"),
|
||||
UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"),
|
||||
UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"),
|
||||
UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"),
|
||||
UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"),
|
||||
UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"),
|
||||
UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"),
|
||||
UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"),
|
||||
UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"),
|
||||
UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"),
|
||||
UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"),
|
||||
UInt8(ascii: "9"), UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "A"), UInt8(ascii: "B"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"),
|
||||
UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"),
|
||||
UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"),
|
||||
UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"),
|
||||
UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"),
|
||||
UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"),
|
||||
UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"),
|
||||
UInt8(ascii: "+"), UInt8(ascii: "/"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"),
|
||||
UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"),
|
||||
UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"),
|
||||
UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"),
|
||||
UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"),
|
||||
UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"),
|
||||
UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "+"),
|
||||
UInt8(ascii: "/"),
|
||||
]
|
||||
|
||||
@usableFromInline
|
||||
static let encoding0url: [UInt8] = [
|
||||
UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "C"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"),
|
||||
UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "H"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "M"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"),
|
||||
UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "R"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "W"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"),
|
||||
UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "b"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "g"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"),
|
||||
UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "l"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "q"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"),
|
||||
UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "v"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "0"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"),
|
||||
UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "5"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "-"),
|
||||
UInt8(ascii: "-"), UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "_"), UInt8(ascii: "_"), UInt8(ascii: "_"),
|
||||
UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "A"), UInt8(ascii: "B"),
|
||||
UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "C"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "D"), UInt8(ascii: "D"),
|
||||
UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"), UInt8(ascii: "E"),
|
||||
UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "F"), UInt8(ascii: "G"),
|
||||
UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "H"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "I"), UInt8(ascii: "I"),
|
||||
UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "K"), UInt8(ascii: "L"),
|
||||
UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "M"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "N"), UInt8(ascii: "N"),
|
||||
UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"), UInt8(ascii: "O"),
|
||||
UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "P"), UInt8(ascii: "Q"),
|
||||
UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "R"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "S"), UInt8(ascii: "S"),
|
||||
UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "U"), UInt8(ascii: "V"),
|
||||
UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "W"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "X"), UInt8(ascii: "X"),
|
||||
UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"), UInt8(ascii: "Y"),
|
||||
UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "Z"), UInt8(ascii: "a"),
|
||||
UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "b"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "c"), UInt8(ascii: "c"),
|
||||
UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "e"), UInt8(ascii: "f"),
|
||||
UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "g"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "h"), UInt8(ascii: "h"),
|
||||
UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"), UInt8(ascii: "i"),
|
||||
UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "j"), UInt8(ascii: "k"),
|
||||
UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "l"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "m"), UInt8(ascii: "m"),
|
||||
UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "o"), UInt8(ascii: "p"),
|
||||
UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "q"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "r"), UInt8(ascii: "r"),
|
||||
UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"), UInt8(ascii: "s"),
|
||||
UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "t"), UInt8(ascii: "u"),
|
||||
UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "v"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "w"), UInt8(ascii: "w"),
|
||||
UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "y"), UInt8(ascii: "z"),
|
||||
UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "0"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "1"), UInt8(ascii: "1"),
|
||||
UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"), UInt8(ascii: "2"),
|
||||
UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "3"), UInt8(ascii: "4"),
|
||||
UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "5"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "6"), UInt8(ascii: "6"),
|
||||
UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "8"), UInt8(ascii: "9"),
|
||||
UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "-"),
|
||||
UInt8(ascii: "-"), UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "_"), UInt8(ascii: "_"),
|
||||
UInt8(ascii: "_"),
|
||||
]
|
||||
|
||||
@usableFromInline
|
||||
static let encoding1url: [UInt8] = [
|
||||
UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"),
|
||||
UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"),
|
||||
UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"),
|
||||
UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"),
|
||||
UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"),
|
||||
UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"),
|
||||
UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "A"), UInt8(ascii: "B"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"),
|
||||
UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "_"),
|
||||
UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"),
|
||||
UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"),
|
||||
UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"),
|
||||
UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"),
|
||||
UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"),
|
||||
UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"),
|
||||
UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"),
|
||||
UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"),
|
||||
UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"),
|
||||
UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"),
|
||||
UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"),
|
||||
UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"),
|
||||
UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "A"),
|
||||
UInt8(ascii: "B"), UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"),
|
||||
UInt8(ascii: "G"), UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"),
|
||||
UInt8(ascii: "L"), UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"),
|
||||
UInt8(ascii: "Q"), UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"),
|
||||
UInt8(ascii: "V"), UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"),
|
||||
UInt8(ascii: "a"), UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"),
|
||||
UInt8(ascii: "f"), UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"),
|
||||
UInt8(ascii: "k"), UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"),
|
||||
UInt8(ascii: "p"), UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"),
|
||||
UInt8(ascii: "u"), UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"),
|
||||
UInt8(ascii: "z"), UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"),
|
||||
UInt8(ascii: "4"), UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"),
|
||||
UInt8(ascii: "9"), UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "A"), UInt8(ascii: "B"),
|
||||
UInt8(ascii: "C"), UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"),
|
||||
UInt8(ascii: "H"), UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"),
|
||||
UInt8(ascii: "M"), UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"),
|
||||
UInt8(ascii: "R"), UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"),
|
||||
UInt8(ascii: "W"), UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"),
|
||||
UInt8(ascii: "b"), UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"),
|
||||
UInt8(ascii: "g"), UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"),
|
||||
UInt8(ascii: "l"), UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"),
|
||||
UInt8(ascii: "q"), UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"),
|
||||
UInt8(ascii: "v"), UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"),
|
||||
UInt8(ascii: "0"), UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"),
|
||||
UInt8(ascii: "5"), UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"),
|
||||
UInt8(ascii: "-"), UInt8(ascii: "_"), UInt8(ascii: "A"), UInt8(ascii: "B"), UInt8(ascii: "C"),
|
||||
UInt8(ascii: "D"), UInt8(ascii: "E"), UInt8(ascii: "F"), UInt8(ascii: "G"), UInt8(ascii: "H"),
|
||||
UInt8(ascii: "I"), UInt8(ascii: "J"), UInt8(ascii: "K"), UInt8(ascii: "L"), UInt8(ascii: "M"),
|
||||
UInt8(ascii: "N"), UInt8(ascii: "O"), UInt8(ascii: "P"), UInt8(ascii: "Q"), UInt8(ascii: "R"),
|
||||
UInt8(ascii: "S"), UInt8(ascii: "T"), UInt8(ascii: "U"), UInt8(ascii: "V"), UInt8(ascii: "W"),
|
||||
UInt8(ascii: "X"), UInt8(ascii: "Y"), UInt8(ascii: "Z"), UInt8(ascii: "a"), UInt8(ascii: "b"),
|
||||
UInt8(ascii: "c"), UInt8(ascii: "d"), UInt8(ascii: "e"), UInt8(ascii: "f"), UInt8(ascii: "g"),
|
||||
UInt8(ascii: "h"), UInt8(ascii: "i"), UInt8(ascii: "j"), UInt8(ascii: "k"), UInt8(ascii: "l"),
|
||||
UInt8(ascii: "m"), UInt8(ascii: "n"), UInt8(ascii: "o"), UInt8(ascii: "p"), UInt8(ascii: "q"),
|
||||
UInt8(ascii: "r"), UInt8(ascii: "s"), UInt8(ascii: "t"), UInt8(ascii: "u"), UInt8(ascii: "v"),
|
||||
UInt8(ascii: "w"), UInt8(ascii: "x"), UInt8(ascii: "y"), UInt8(ascii: "z"), UInt8(ascii: "0"),
|
||||
UInt8(ascii: "1"), UInt8(ascii: "2"), UInt8(ascii: "3"), UInt8(ascii: "4"), UInt8(ascii: "5"),
|
||||
UInt8(ascii: "6"), UInt8(ascii: "7"), UInt8(ascii: "8"), UInt8(ascii: "9"), UInt8(ascii: "-"),
|
||||
UInt8(ascii: "_"),
|
||||
]
|
||||
|
||||
@inlinable
|
||||
static func encodeBytes<Buffer: Collection>(bytes: Buffer, options: EncodingOptions = [])
|
||||
static func encodeBytes<Buffer: Collection>(
|
||||
bytes: Buffer,
|
||||
options: EncodingOptions = []
|
||||
)
|
||||
-> [UInt8] where Buffer.Element == UInt8
|
||||
{
|
||||
let newCapacity = ((bytes.count + 2) / 3) * 4
|
||||
@@ -148,27 +328,29 @@ extension Base64 {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func encodeString<Buffer: Collection>(bytes: Buffer, options: EncodingOptions = [])
|
||||
static func encodeString<Buffer: Collection>(
|
||||
bytes: Buffer,
|
||||
options: EncodingOptions = []
|
||||
)
|
||||
-> String where Buffer.Element == UInt8
|
||||
{
|
||||
#if swift(>=5.3)
|
||||
let newCapacity = ((bytes.count + 2) / 3) * 4
|
||||
if #available(OSX 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) {
|
||||
if let result = bytes.withContiguousStorageIfAvailable({ (input) -> String in
|
||||
String(unsafeUninitializedCapacity: newCapacity) { (buffer) -> Int in
|
||||
var length = newCapacity
|
||||
Self._encodeChromium(input: input, buffer: buffer, length: &length, options: options)
|
||||
return length
|
||||
}
|
||||
}) {
|
||||
return result
|
||||
}
|
||||
|
||||
return self.encodeString(bytes: Array(bytes), options: options)
|
||||
} else {
|
||||
guard #available(OSX 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) else {
|
||||
let bytes: [UInt8] = self.encodeBytes(bytes: bytes, options: options)
|
||||
return String(decoding: bytes, as: Unicode.UTF8.self)
|
||||
}
|
||||
if let result = bytes.withContiguousStorageIfAvailable({ (input) -> String in
|
||||
String(unsafeUninitializedCapacity: newCapacity) { (buffer) -> Int in
|
||||
var length = newCapacity
|
||||
Self._encodeChromium(input: input, buffer: buffer, length: &length, options: options)
|
||||
return length
|
||||
}
|
||||
}) {
|
||||
return result
|
||||
}
|
||||
|
||||
return self.encodeString(bytes: Array(bytes), options: options)
|
||||
#else
|
||||
let bytes: [UInt8] = self.encodeBytes(bytes: bytes, options: options)
|
||||
return String(decoding: bytes, as: Unicode.UTF8.self)
|
||||
@@ -176,7 +358,12 @@ extension Base64 {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func _encodeChromium(input: UnsafeBufferPointer<UInt8>, buffer: UnsafeMutableBufferPointer<UInt8>, length: inout Int, options: EncodingOptions) {
|
||||
static func _encodeChromium(
|
||||
input: UnsafeBufferPointer<UInt8>,
|
||||
buffer: UnsafeMutableBufferPointer<UInt8>,
|
||||
length: inout Int,
|
||||
options: EncodingOptions
|
||||
) {
|
||||
let omitPaddingCharacter = options.contains(.omitPaddingCharacter)
|
||||
|
||||
Self.withUnsafeEncodingTablesAsBufferPointers(options: options) { e0, e1 in
|
||||
@@ -231,7 +418,10 @@ extension Base64 {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func withUnsafeEncodingTablesAsBufferPointers<R>(options: Base64.EncodingOptions, _ body: (UnsafeBufferPointer<UInt8>, UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R {
|
||||
static func withUnsafeEncodingTablesAsBufferPointers<R>(
|
||||
options: Base64.EncodingOptions,
|
||||
_ body: (UnsafeBufferPointer<UInt8>, UnsafeBufferPointer<UInt8>) throws -> R
|
||||
) rethrows -> R {
|
||||
let encoding0 = options.contains(.base64UrlAlphabet) ? Self.encoding0url : Self.encoding0
|
||||
let encoding1 = options.contains(.base64UrlAlphabet) ? Self.encoding1url : Self.encoding1
|
||||
|
||||
@@ -275,7 +465,8 @@ extension Base64 {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func decode<Buffer: Collection>(bytes: Buffer, options: DecodingOptions = []) throws -> [UInt8] where Buffer.Element == UInt8 {
|
||||
static func decode<Buffer: Collection>(bytes: Buffer, options: DecodingOptions = []) throws -> [UInt8]
|
||||
where Buffer.Element == UInt8 {
|
||||
// needed to add this to fix a crash
|
||||
guard bytes.count > 0 else {
|
||||
return []
|
||||
@@ -323,7 +514,7 @@ extension Base64 {
|
||||
try Self.withUnsafeDecodingTablesAsBufferPointers(options: options) { d0, d1, d2, d3 in
|
||||
var outIndex = 0
|
||||
if fullchunks > 0 {
|
||||
for chunk in 0 ..< fullchunks {
|
||||
for chunk in 0..<fullchunks {
|
||||
let inIndex = chunk * 4
|
||||
let a0 = inBuffer[inIndex]
|
||||
let a1 = inBuffer[inIndex + 1]
|
||||
@@ -386,7 +577,13 @@ extension Base64 {
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
static func withUnsafeDecodingTablesAsBufferPointers<R>(options: Base64.DecodingOptions, _ body: (UnsafeBufferPointer<UInt32>, UnsafeBufferPointer<UInt32>, UnsafeBufferPointer<UInt32>, UnsafeBufferPointer<UInt32>) throws -> R) rethrows -> R {
|
||||
static func withUnsafeDecodingTablesAsBufferPointers<R>(
|
||||
options: Base64.DecodingOptions,
|
||||
_ body: (
|
||||
UnsafeBufferPointer<UInt32>, UnsafeBufferPointer<UInt32>, UnsafeBufferPointer<UInt32>,
|
||||
UnsafeBufferPointer<UInt32>
|
||||
) throws -> R
|
||||
) rethrows -> R {
|
||||
let decoding0 = options.contains(.base64UrlAlphabet) ? Self.decoding0url : Self.decoding0
|
||||
let decoding1 = options.contains(.base64UrlAlphabet) ? Self.decoding1url : Self.decoding1
|
||||
let decoding2 = options.contains(.base64UrlAlphabet) ? Self.decoding2url : Self.decoding2
|
||||
@@ -601,22 +798,22 @@ extension Base64 {
|
||||
|
||||
@usableFromInline
|
||||
static let decoding0url: [UInt32] = [
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_00F8, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0000_00D0, 0x0000_00D4, 0x0000_00D8, 0x0000_00DC, 0x0000_00E0, 0x0000_00E4, // 48
|
||||
0x0000_00E8, 0x0000_00EC, 0x0000_00F0, 0x0000_00F4, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0000_0004, 0x0000_0008, 0x0000_000C, 0x0000_0010, 0x0000_0014, 0x0000_0018, // 66
|
||||
0x0000_001C, 0x0000_0020, 0x0000_0024, 0x0000_0028, 0x0000_002C, 0x0000_0030, // 72
|
||||
0x0000_0034, 0x0000_0038, 0x0000_003C, 0x0000_0040, 0x0000_0044, 0x0000_0048, // 78
|
||||
0x0000_004C, 0x0000_0050, 0x0000_0054, 0x0000_0058, 0x0000_005C, 0x0000_0060, // 84
|
||||
0x0000_0064, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_00FC, // 90
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_00F8, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0000_00D0, 0x0000_00D4, 0x0000_00D8, 0x0000_00DC, 0x0000_00E0, 0x0000_00E4, // 48
|
||||
0x0000_00E8, 0x0000_00EC, 0x0000_00F0, 0x0000_00F4, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0000_0004, 0x0000_0008, 0x0000_000C, 0x0000_0010, 0x0000_0014, 0x0000_0018, // 66
|
||||
0x0000_001C, 0x0000_0020, 0x0000_0024, 0x0000_0028, 0x0000_002C, 0x0000_0030, // 72
|
||||
0x0000_0034, 0x0000_0038, 0x0000_003C, 0x0000_0040, 0x0000_0044, 0x0000_0048, // 78
|
||||
0x0000_004C, 0x0000_0050, 0x0000_0054, 0x0000_0058, 0x0000_005C, 0x0000_0060, // 84
|
||||
0x0000_0064, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_00FC, // 90
|
||||
0x01FF_FFFF, 0x0000_0068, 0x0000_006C, 0x0000_0070, 0x0000_0074, 0x0000_0078,
|
||||
0x0000_007C, 0x0000_0080, 0x0000_0084, 0x0000_0088, 0x0000_008C, 0x0000_0090,
|
||||
0x0000_0094, 0x0000_0098, 0x0000_009C, 0x0000_00A0, 0x0000_00A4, 0x0000_00A8,
|
||||
@@ -648,22 +845,22 @@ extension Base64 {
|
||||
|
||||
@usableFromInline
|
||||
static let decoding1url: [UInt32] = [
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_E003, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0000_4003, 0x0000_5003, 0x0000_6003, 0x0000_7003, 0x0000_8003, 0x0000_9003, // 48
|
||||
0x0000_A003, 0x0000_B003, 0x0000_C003, 0x0000_D003, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0000_1000, 0x0000_2000, 0x0000_3000, 0x0000_4000, 0x0000_5000, 0x0000_6000, // 66
|
||||
0x0000_7000, 0x0000_8000, 0x0000_9000, 0x0000_A000, 0x0000_B000, 0x0000_C000, // 72
|
||||
0x0000_D000, 0x0000_E000, 0x0000_F000, 0x0000_0001, 0x0000_1001, 0x0000_2001, // 78
|
||||
0x0000_3001, 0x0000_4001, 0x0000_5001, 0x0000_6001, 0x0000_7001, 0x0000_8001, // 84
|
||||
0x0000_9001, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_F003, // 90
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_E003, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0000_4003, 0x0000_5003, 0x0000_6003, 0x0000_7003, 0x0000_8003, 0x0000_9003, // 48
|
||||
0x0000_A003, 0x0000_B003, 0x0000_C003, 0x0000_D003, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0000_1000, 0x0000_2000, 0x0000_3000, 0x0000_4000, 0x0000_5000, 0x0000_6000, // 66
|
||||
0x0000_7000, 0x0000_8000, 0x0000_9000, 0x0000_A000, 0x0000_B000, 0x0000_C000, // 72
|
||||
0x0000_D000, 0x0000_E000, 0x0000_F000, 0x0000_0001, 0x0000_1001, 0x0000_2001, // 78
|
||||
0x0000_3001, 0x0000_4001, 0x0000_5001, 0x0000_6001, 0x0000_7001, 0x0000_8001, // 84
|
||||
0x0000_9001, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_F003, // 90
|
||||
0x01FF_FFFF, 0x0000_A001, 0x0000_B001, 0x0000_C001, 0x0000_D001, 0x0000_E001,
|
||||
0x0000_F001, 0x0000_0002, 0x0000_1002, 0x0000_2002, 0x0000_3002, 0x0000_4002,
|
||||
0x0000_5002, 0x0000_6002, 0x0000_7002, 0x0000_8002, 0x0000_9002, 0x0000_A002,
|
||||
@@ -695,22 +892,22 @@ extension Base64 {
|
||||
|
||||
@usableFromInline
|
||||
static let decoding2url: [UInt32] = [
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0080_0F00, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0000_0D00, 0x0040_0D00, 0x0080_0D00, 0x00C0_0D00, 0x0000_0E00, 0x0040_0E00, // 48
|
||||
0x0080_0E00, 0x00C0_0E00, 0x0000_0F00, 0x0040_0F00, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0040_0000, 0x0080_0000, 0x00C0_0000, 0x0000_0100, 0x0040_0100, 0x0080_0100, // 66
|
||||
0x00C0_0100, 0x0000_0200, 0x0040_0200, 0x0080_0200, 0x00C0_0200, 0x0000_0300, // 72
|
||||
0x0040_0300, 0x0080_0300, 0x00C0_0300, 0x0000_0400, 0x0040_0400, 0x0080_0400, // 78
|
||||
0x00C0_0400, 0x0000_0500, 0x0040_0500, 0x0080_0500, 0x00C0_0500, 0x0000_0600, // 84
|
||||
0x0040_0600, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x00C0_0F00, // 90
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0080_0F00, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0000_0D00, 0x0040_0D00, 0x0080_0D00, 0x00C0_0D00, 0x0000_0E00, 0x0040_0E00, // 48
|
||||
0x0080_0E00, 0x00C0_0E00, 0x0000_0F00, 0x0040_0F00, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0040_0000, 0x0080_0000, 0x00C0_0000, 0x0000_0100, 0x0040_0100, 0x0080_0100, // 66
|
||||
0x00C0_0100, 0x0000_0200, 0x0040_0200, 0x0080_0200, 0x00C0_0200, 0x0000_0300, // 72
|
||||
0x0040_0300, 0x0080_0300, 0x00C0_0300, 0x0000_0400, 0x0040_0400, 0x0080_0400, // 78
|
||||
0x00C0_0400, 0x0000_0500, 0x0040_0500, 0x0080_0500, 0x00C0_0500, 0x0000_0600, // 84
|
||||
0x0040_0600, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x00C0_0F00, // 90
|
||||
0x01FF_FFFF, 0x0080_0600, 0x00C0_0600, 0x0000_0700, 0x0040_0700, 0x0080_0700,
|
||||
0x00C0_0700, 0x0000_0800, 0x0040_0800, 0x0080_0800, 0x00C0_0800, 0x0000_0900,
|
||||
0x0040_0900, 0x0080_0900, 0x00C0_0900, 0x0000_0A00, 0x0040_0A00, 0x0080_0A00,
|
||||
@@ -742,22 +939,22 @@ extension Base64 {
|
||||
|
||||
@usableFromInline
|
||||
static let decoding3url: [UInt32] = [
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x003E_0000, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0034_0000, 0x0035_0000, 0x0036_0000, 0x0037_0000, 0x0038_0000, 0x0039_0000, // 48
|
||||
0x003A_0000, 0x003B_0000, 0x003C_0000, 0x003D_0000, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0001_0000, 0x0002_0000, 0x0003_0000, 0x0004_0000, 0x0005_0000, 0x0006_0000, // 66
|
||||
0x0007_0000, 0x0008_0000, 0x0009_0000, 0x000A_0000, 0x000B_0000, 0x000C_0000, // 72
|
||||
0x000D_0000, 0x000E_0000, 0x000F_0000, 0x0010_0000, 0x0011_0000, 0x0012_0000, // 78
|
||||
0x0013_0000, 0x0014_0000, 0x0015_0000, 0x0016_0000, 0x0017_0000, 0x0018_0000, // 84
|
||||
0x0019_0000, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x003F_0000, // 90
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 0
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 6
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 12
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 18
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 24
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 30
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, // 36
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x003E_0000, 0x01FF_FFFF, 0x01FF_FFFF, // 42
|
||||
0x0034_0000, 0x0035_0000, 0x0036_0000, 0x0037_0000, 0x0038_0000, 0x0039_0000, // 48
|
||||
0x003A_0000, 0x003B_0000, 0x003C_0000, 0x003D_0000, 0x01FF_FFFF, 0x01FF_FFFF, // 54
|
||||
0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x0000_0000, // 60
|
||||
0x0001_0000, 0x0002_0000, 0x0003_0000, 0x0004_0000, 0x0005_0000, 0x0006_0000, // 66
|
||||
0x0007_0000, 0x0008_0000, 0x0009_0000, 0x000A_0000, 0x000B_0000, 0x000C_0000, // 72
|
||||
0x000D_0000, 0x000E_0000, 0x000F_0000, 0x0010_0000, 0x0011_0000, 0x0012_0000, // 78
|
||||
0x0013_0000, 0x0014_0000, 0x0015_0000, 0x0016_0000, 0x0017_0000, 0x0018_0000, // 84
|
||||
0x0019_0000, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x01FF_FFFF, 0x003F_0000, // 90
|
||||
0x01FF_FFFF, 0x001A_0000, 0x001B_0000, 0x001C_0000, 0x001D_0000, 0x001E_0000,
|
||||
0x001F_0000, 0x0020_0000, 0x0021_0000, 0x0022_0000, 0x0023_0000, 0x0024_0000,
|
||||
0x0025_0000, 0x0026_0000, 0x0027_0000, 0x0028_0000, 0x0029_0000, 0x002A_0000,
|
||||
|
||||
@@ -1,3 +1,77 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This base64 implementation is heavily inspired by:
|
||||
|
||||
// swift-format-ignore: NoBlockComments
|
||||
// https://github.com/lemire/fastbase64/blob/master/src/chromiumbase64.c ignore-unacceptable-language
|
||||
|
||||
/*
|
||||
Copyright (c) 2015-2016, Wojciech Muła, Alfred Klomp, Daniel Lemire
|
||||
(Unless otherwise stated in the source code)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// https://github.com/client9/stringencoders/blob/master/src/modp_b64.c ignore-unacceptable-language
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Nick Galbreath
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// https://github.com/swift-extras/swift-extras-base64
|
||||
|
||||
// minor modifications to remove public attributes
|
||||
|
||||
@@ -97,11 +97,10 @@ extension EncodeBuffer {
|
||||
return .clientSynchronizingLiteral
|
||||
}
|
||||
case .server(_, options: let options):
|
||||
if options.useQuotedString, canUseQuotedString(for: bytes) {
|
||||
return .quotedString
|
||||
} else {
|
||||
guard options.useQuotedString, canUseQuotedString(for: bytes) else {
|
||||
return .serverLiteral
|
||||
}
|
||||
return .quotedString
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,9 +127,7 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeLiteral8<T: Collection>(_ bytes: T) -> Int where T.Element == UInt8 {
|
||||
let length = "~{\(bytes.count)}\r\n"
|
||||
return
|
||||
self.writeString(length) +
|
||||
self.markStopPoint() +
|
||||
self.writeBytes(bytes)
|
||||
self.writeString(length) + self.markStopPoint() + self.writeBytes(bytes)
|
||||
}
|
||||
|
||||
/// Writes the string `"NIL"` to self.
|
||||
@@ -154,29 +151,35 @@ extension EncodeBuffer {
|
||||
/// - parenthesis: Writes `(` immediately before the first element, and `)` immediately after the last. Enabled by default.
|
||||
/// - writer: The closure to call for each element that writes the element.
|
||||
/// - returns: The number of bytes written.
|
||||
@discardableResult mutating func writeArray<C, T>(_ collection: C, prefix: String = "", separator: String = " ", suffix: String = "", parenthesis: Bool = true, _ writer: (T, inout EncodeBuffer) -> Int) -> Int where C: RandomAccessCollection, C.Element == T {
|
||||
@discardableResult mutating func writeArray<C, T>(
|
||||
_ collection: C,
|
||||
prefix: String = "",
|
||||
separator: String = " ",
|
||||
suffix: String = "",
|
||||
parenthesis: Bool = true,
|
||||
_ writer: (T, inout EncodeBuffer) -> Int
|
||||
) -> Int where C: RandomAccessCollection, C.Element == T {
|
||||
// TODO: This should probably check
|
||||
// collection.count != 0
|
||||
// such that an empty collection gets encoded as "()".
|
||||
self.write(if: collection.count > 0) {
|
||||
self.writeString(prefix)
|
||||
} +
|
||||
self.write(if: parenthesis) { () -> Int in
|
||||
}
|
||||
+ self.write(if: parenthesis) { () -> Int in
|
||||
self.writeString("(")
|
||||
} +
|
||||
collection.enumerated().reduce(0) { (size, row) in
|
||||
}
|
||||
+ collection.enumerated().reduce(0) { (size, row) in
|
||||
let (i, element) = row
|
||||
return
|
||||
size +
|
||||
writer(element, &self) +
|
||||
self.write(if: i < collection.count - 1) { () -> Int in
|
||||
size + writer(element, &self)
|
||||
+ self.write(if: i < collection.count - 1) { () -> Int in
|
||||
self.writeString(separator)
|
||||
}
|
||||
} +
|
||||
self.write(if: parenthesis) { () -> Int in
|
||||
}
|
||||
+ self.write(if: parenthesis) { () -> Int in
|
||||
self.writeString(")")
|
||||
} +
|
||||
self.write(if: collection.count > 0) {
|
||||
}
|
||||
+ self.write(if: collection.count > 0) {
|
||||
self.writeString(suffix)
|
||||
}
|
||||
}
|
||||
@@ -190,29 +193,35 @@ extension EncodeBuffer {
|
||||
/// - parenthesis: Writes `(` immediately before the first element, and `)` immediately after the last. Enabled by default.
|
||||
/// - writer: The closure to call for each element that writes the element.
|
||||
/// - returns: The number of bytes written.
|
||||
@discardableResult mutating func writeOrderedDictionary<K, V>(_ values: OrderedDictionary<K, V>, prefix: String = "", separator: String = " ", suffix: String = "", parenthesis: Bool = true, _ writer: (KeyValue<K, V>, inout EncodeBuffer) -> Int) -> Int {
|
||||
@discardableResult mutating func writeOrderedDictionary<K, V>(
|
||||
_ values: OrderedDictionary<K, V>,
|
||||
prefix: String = "",
|
||||
separator: String = " ",
|
||||
suffix: String = "",
|
||||
parenthesis: Bool = true,
|
||||
_ writer: (KeyValue<K, V>, inout EncodeBuffer) -> Int
|
||||
) -> Int {
|
||||
// TODO: This should probably check
|
||||
// collection.count != 0
|
||||
// such that an empty collection gets encoded as "()".
|
||||
self.write(if: values.count > 0) {
|
||||
self.writeString(prefix)
|
||||
} +
|
||||
self.write(if: parenthesis) { () -> Int in
|
||||
}
|
||||
+ self.write(if: parenthesis) { () -> Int in
|
||||
self.writeString("(")
|
||||
} +
|
||||
values.enumerated().reduce(0) { (size, row) in
|
||||
}
|
||||
+ values.enumerated().reduce(0) { (size, row) in
|
||||
let (i, element) = row
|
||||
return
|
||||
size +
|
||||
writer(.init(key: element.0, value: element.1), &self) +
|
||||
self.write(if: i < values.count - 1) { () -> Int in
|
||||
size + writer(.init(key: element.0, value: element.1), &self)
|
||||
+ self.write(if: i < values.count - 1) { () -> Int in
|
||||
self.writeString(separator)
|
||||
}
|
||||
} +
|
||||
self.write(if: parenthesis) { () -> Int in
|
||||
}
|
||||
+ self.write(if: parenthesis) { () -> Int in
|
||||
self.writeString(")")
|
||||
} +
|
||||
self.write(if: values.count > 0) {
|
||||
}
|
||||
+ self.write(if: values.count > 0) {
|
||||
self.writeString(suffix)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,12 @@ public struct CommandEncodeBuffer: Hashable, Sendable {
|
||||
/// Creates a new `CommandEncodeBuffer` from a given initial `ByteBuffer` and configuration options.
|
||||
/// - parameter buffer: The initial `ByteBuffer` to build upon.
|
||||
/// - parameter options: The options to use when writing commands and data.
|
||||
public init(buffer: ByteBuffer, options: CommandEncodingOptions, encodedAtLeastOneCatenateElement: Bool = false, loggingMode: Bool) {
|
||||
public init(
|
||||
buffer: ByteBuffer,
|
||||
options: CommandEncodingOptions,
|
||||
encodedAtLeastOneCatenateElement: Bool = false,
|
||||
loggingMode: Bool
|
||||
) {
|
||||
self.buffer = .clientEncodeBuffer(buffer: buffer, options: options, loggingMode: loggingMode)
|
||||
self.encodedAtLeastOneCatenateElement = encodedAtLeastOneCatenateElement
|
||||
}
|
||||
@@ -35,7 +40,9 @@ extension CommandEncodeBuffer {
|
||||
/// The options used when writing commands and data.
|
||||
public var options: CommandEncodingOptions {
|
||||
get {
|
||||
guard case .client(let options) = buffer.mode else { preconditionFailure("Command encoder mode must be 'client'.") }
|
||||
guard case .client(let options) = buffer.mode else {
|
||||
preconditionFailure("Command encoder mode must be 'client'.")
|
||||
}
|
||||
return options
|
||||
}
|
||||
set {
|
||||
@@ -46,7 +53,12 @@ extension CommandEncodeBuffer {
|
||||
/// Creates a new `CommandEncodeBuffer` from a given initial `ByteBuffer` and configuration options.
|
||||
/// - parameter buffer: The initial `ByteBuffer` to build upon.
|
||||
/// - parameter capabilities: Capabilities to use when writing commands and data. Will be converted to `CommandEncodingOptions`.
|
||||
public init(buffer: ByteBuffer, capabilities: [Capability], encodedAtLeastOneCatenateElement: Bool = false, loggingMode: Bool) {
|
||||
public init(
|
||||
buffer: ByteBuffer,
|
||||
capabilities: [Capability],
|
||||
encodedAtLeastOneCatenateElement: Bool = false,
|
||||
loggingMode: Bool
|
||||
) {
|
||||
self.buffer = .clientEncodeBuffer(buffer: buffer, capabilities: capabilities, loggingMode: loggingMode)
|
||||
self.encodedAtLeastOneCatenateElement = encodedAtLeastOneCatenateElement
|
||||
}
|
||||
|
||||
@@ -46,7 +46,11 @@ extension EncodeBuffer {
|
||||
/// - parameter buffer: An initial `ByteBuffer` to write to. Note that this is copied and not taken as `inout`.
|
||||
/// - parameter options: Configuration to use when writing.
|
||||
/// - returns: A new `EncodeBuffer` configured for client use.
|
||||
static func clientEncodeBuffer(buffer: ByteBuffer, options: CommandEncodingOptions, loggingMode: Bool) -> EncodeBuffer {
|
||||
static func clientEncodeBuffer(
|
||||
buffer: ByteBuffer,
|
||||
options: CommandEncodingOptions,
|
||||
loggingMode: Bool
|
||||
) -> EncodeBuffer {
|
||||
EncodeBuffer(buffer, mode: .client(options: options), loggingMode: loggingMode)
|
||||
}
|
||||
|
||||
@@ -55,14 +59,22 @@ extension EncodeBuffer {
|
||||
/// - parameter options: Configuration to use when writing.
|
||||
/// - returns: A new `EncodeBuffer` configured for client use.
|
||||
static func clientEncodeBuffer(buffer: ByteBuffer, capabilities: [Capability], loggingMode: Bool) -> EncodeBuffer {
|
||||
clientEncodeBuffer(buffer: buffer, options: CommandEncodingOptions(capabilities: capabilities), loggingMode: loggingMode)
|
||||
clientEncodeBuffer(
|
||||
buffer: buffer,
|
||||
options: CommandEncodingOptions(capabilities: capabilities),
|
||||
loggingMode: loggingMode
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a new `EncodeBuffer` suitable for a client to write commands.
|
||||
/// - parameter buffer: An initial `ByteBuffer` to write to. Note that this is copied and not taken as `inout`.
|
||||
/// - parameter options: Configuration to use when writing.
|
||||
/// - returns: A new `EncodeBuffer` configured for server use.
|
||||
static func serverEncodeBuffer(buffer: ByteBuffer, options: ResponseEncodingOptions, loggingMode: Bool) -> EncodeBuffer {
|
||||
static func serverEncodeBuffer(
|
||||
buffer: ByteBuffer,
|
||||
options: ResponseEncodingOptions,
|
||||
loggingMode: Bool
|
||||
) -> EncodeBuffer {
|
||||
EncodeBuffer(buffer, mode: .server(streamingAttributes: false, options: options), loggingMode: loggingMode)
|
||||
}
|
||||
|
||||
@@ -71,7 +83,11 @@ extension EncodeBuffer {
|
||||
/// - parameter options: Configuration to use when writing.
|
||||
/// - returns: A new `EncodeBuffer` configured for server use.
|
||||
static func serverEncodeBuffer(buffer: ByteBuffer, capabilities: [Capability], loggingMode: Bool) -> EncodeBuffer {
|
||||
serverEncodeBuffer(buffer: buffer, options: ResponseEncodingOptions(capabilities: capabilities), loggingMode: loggingMode)
|
||||
serverEncodeBuffer(
|
||||
buffer: buffer,
|
||||
options: ResponseEncodingOptions(capabilities: capabilities),
|
||||
loggingMode: loggingMode
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,13 +132,17 @@ extension EncodeBuffer {
|
||||
@_spi(NIOIMAPInternal) public mutating func nextChunk(allowEmptyChunk: Bool) -> Chunk {
|
||||
switch self.mode {
|
||||
case .client:
|
||||
if let stopPoint = self.stopPoints.popFirst() {
|
||||
return .init(bytes: self.buffer.readSlice(length: stopPoint - self.buffer.readerIndex)!,
|
||||
waitForContinuation: stopPoint != self.buffer.writerIndex)
|
||||
} else {
|
||||
guard let stopPoint = self.stopPoints.popFirst() else {
|
||||
precondition(allowEmptyChunk || self.buffer.readableBytes > 0, "No next chunk to send.")
|
||||
return .init(bytes: self.buffer.readSlice(length: self.buffer.readableBytes)!, waitForContinuation: false)
|
||||
return .init(
|
||||
bytes: self.buffer.readSlice(length: self.buffer.readableBytes)!,
|
||||
waitForContinuation: false
|
||||
)
|
||||
}
|
||||
return .init(
|
||||
bytes: self.buffer.readSlice(length: stopPoint - self.buffer.readerIndex)!,
|
||||
waitForContinuation: stopPoint != self.buffer.writerIndex
|
||||
)
|
||||
case .server:
|
||||
return .init(bytes: self.buffer.readSlice(length: self.buffer.readableBytes)!, waitForContinuation: false)
|
||||
}
|
||||
@@ -154,11 +174,10 @@ extension EncodeBuffer {
|
||||
@discardableResult
|
||||
@inlinable
|
||||
public mutating func writeBytes<Bytes: Sequence>(_ bytes: Bytes) -> Int where Bytes.Element == UInt8 {
|
||||
if loggingMode {
|
||||
return self.buffer.writeString("[\(Array(bytes).count) bytes]")
|
||||
} else {
|
||||
guard loggingMode else {
|
||||
return self.buffer.writeBytes(bytes)
|
||||
}
|
||||
return self.buffer.writeString("[\(Array(bytes).count) bytes]")
|
||||
}
|
||||
|
||||
/// Writes a `ByteBuffer` to the buffer.
|
||||
@@ -167,11 +186,10 @@ extension EncodeBuffer {
|
||||
@discardableResult
|
||||
@inlinable
|
||||
public mutating func writeBuffer(_ buffer: inout ByteBuffer) -> Int {
|
||||
if loggingMode {
|
||||
return self.buffer.writeString("[\(buffer.readableBytes) bytes]")
|
||||
} else {
|
||||
guard loggingMode else {
|
||||
return self.buffer.writeBuffer(&buffer)
|
||||
}
|
||||
return self.buffer.writeString("[\(buffer.readableBytes) bytes]")
|
||||
}
|
||||
|
||||
/// Erases all data from the buffer.
|
||||
|
||||
@@ -28,8 +28,8 @@ public struct AbsoluteMessagePath: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAbsoluteMessagePath(_ path: AbsoluteMessagePath) -> Int {
|
||||
self.writeString("/") +
|
||||
self.writeIfExists(path.command) { command in
|
||||
self.writeString("/")
|
||||
+ self.writeIfExists(path.command) { command in
|
||||
self.writeURLCommand(command)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@ public struct AppendData: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAppendData(_ data: AppendData) -> Int {
|
||||
guard case .client(let options) = mode else { preconditionFailure("Trying to send command, but not in 'client' mode.") }
|
||||
guard case .client(let options) = mode else {
|
||||
preconditionFailure("Trying to send command, but not in 'client' mode.")
|
||||
}
|
||||
switch (options.useNonSynchronizingLiteralPlus, data.withoutContentTransferEncoding) {
|
||||
case (true, true):
|
||||
return self.writeString("~{\(data.byteCount)+}\r\n")
|
||||
|
||||
@@ -38,8 +38,6 @@ extension EncodeBuffer {
|
||||
/// - parameter `message`: The `AppendMessage` to write.
|
||||
/// - returns: The number of bytes written.
|
||||
@discardableResult mutating func writeAppendMessage(_ message: AppendMessage) -> Int {
|
||||
self.writeAppendOptions(message.options) +
|
||||
self.writeSpace() +
|
||||
self.writeAppendData(message.data)
|
||||
self.writeAppendOptions(message.options) + self.writeSpace() + self.writeAppendData(message.data)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,11 @@ public struct AppendOptions: Hashable, Sendable {
|
||||
/// - parameter flagList: Flags that will be added to the message. Defaults to `[]`.
|
||||
/// - parameter internalDate: An optional date to be associated with the message, typically representing the date of delivery. Defaults to `nil`.
|
||||
/// - parameter extensions: Any additional pieces of information to be associated with the message. Implemented as a "catch-all" to support future extensions. Defaults to `[:]`.
|
||||
public init(flagList: [Flag] = [], internalDate: ServerMessageDate? = nil, extensions: OrderedDictionary<String, ParameterValue> = [:]) {
|
||||
public init(
|
||||
flagList: [Flag] = [],
|
||||
internalDate: ServerMessageDate? = nil,
|
||||
extensions: OrderedDictionary<String, ParameterValue> = [:]
|
||||
) {
|
||||
self.flagList = flagList
|
||||
self.internalDate = internalDate
|
||||
self.extensions = extensions
|
||||
@@ -47,12 +51,11 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAppendOptions(_ options: AppendOptions) -> Int {
|
||||
self.write(if: options.flagList.count >= 1) {
|
||||
self.writeSpace() + self.writeFlags(options.flagList)
|
||||
} +
|
||||
self.writeIfExists(options.internalDate) { (internalDate) -> Int in
|
||||
self.writeSpace() +
|
||||
self.writeInternalDate(internalDate)
|
||||
} +
|
||||
self.writeOrderedDictionary(options.extensions, prefix: " ", parenthesis: false) { (ext, self) -> Int in
|
||||
}
|
||||
+ self.writeIfExists(options.internalDate) { (internalDate) -> Int in
|
||||
self.writeSpace() + self.writeInternalDate(internalDate)
|
||||
}
|
||||
+ self.writeOrderedDictionary(options.extensions, prefix: " ", parenthesis: false) { (ext, self) -> Int in
|
||||
self.writeTaggedExtension(ext)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ public struct AuthenticatedURL: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeIAuthenticatedURL(_ data: AuthenticatedURL) -> Int {
|
||||
self.writeAuthenticatedURLRump(data.authenticatedURL) +
|
||||
self.writeAuthenticatedURLVerifier(data.verifier)
|
||||
self.writeAuthenticatedURLRump(data.authenticatedURL) + self.writeAuthenticatedURLVerifier(data.verifier)
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,6 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAuthenticatedURLRump(_ data: AuthenticatedURLRump) -> Int {
|
||||
self.writeIfExists(data.expire) { expire in
|
||||
self.writeExpire(expire)
|
||||
} +
|
||||
self.writeString(";URLAUTH=") +
|
||||
self.writeAccess(data.access)
|
||||
} + self.writeString(";URLAUTH=") + self.writeAccess(data.access)
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,7 @@ public struct AuthenticatedURLVerifier: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAuthenticatedURLVerifier(_ data: AuthenticatedURLVerifier) -> Int {
|
||||
self.writeString(":") +
|
||||
self.writeURLAuthenticationMechanism(data.urlAuthenticationMechanism) +
|
||||
self.writeString(":") +
|
||||
self.writeEncodedAuthenticationURL(data.encodedAuthenticationURL)
|
||||
self.writeString(":") + self.writeURLAuthenticationMechanism(data.urlAuthenticationMechanism)
|
||||
+ self.writeString(":") + self.writeEncodedAuthenticationURL(data.encodedAuthenticationURL)
|
||||
}
|
||||
}
|
||||
@@ -178,9 +178,12 @@ extension BodyStructure {
|
||||
try self.recursiveEnumerateParts(parent: [], closure)
|
||||
}
|
||||
|
||||
private func recursiveEnumerateParts(parent: SectionSpecifier.Part, _ closure: (SectionSpecifier.Part, BodyStructure) throws -> Void) rethrows {
|
||||
private func recursiveEnumerateParts(
|
||||
parent: SectionSpecifier.Part,
|
||||
_ closure: (SectionSpecifier.Part, BodyStructure) throws -> Void
|
||||
) rethrows {
|
||||
guard self.subpartCount > 0 else { return }
|
||||
for part in 1 ... self.subpartCount {
|
||||
for part in 1...self.subpartCount {
|
||||
let spec = SectionSpecifier.Part(Array(parent) + [part])
|
||||
let bs = self[[part]]
|
||||
try closure(spec, bs)
|
||||
|
||||
@@ -46,9 +46,11 @@ extension BodyStructure {
|
||||
|
||||
/// Attempts to find and convert the value for the common field "SIZE". If the field doesn't exist or is not a valid integer then `nil` is returned.
|
||||
public var size: Int? {
|
||||
guard let value = self.parameters.first(where: { (pair) -> Bool in
|
||||
pair.0.lowercased() == "size"
|
||||
})?.1 else {
|
||||
guard
|
||||
let value = self.parameters.first(where: { (pair) -> Bool in
|
||||
pair.0.lowercased() == "size"
|
||||
})?.1
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
return Int(value)
|
||||
@@ -78,10 +80,7 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
return
|
||||
self.writeString("(") +
|
||||
self.writeIMAPString(dsp.kind.rawValue) +
|
||||
self.writeSpace() +
|
||||
self.writeBodyParameterPairs(dsp.parameters) +
|
||||
self.writeString(")")
|
||||
self.writeString("(") + self.writeIMAPString(dsp.kind.rawValue) + self.writeSpace()
|
||||
+ self.writeBodyParameterPairs(dsp.parameters) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,9 @@ extension BodyStructure {
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeBodyDispositionAndLanguage(_ desc: BodyStructure.DispositionAndLanguage) -> Int {
|
||||
self.writeSpace() +
|
||||
self.writeBodyDisposition(desc.disposition)
|
||||
@discardableResult mutating func writeBodyDispositionAndLanguage(
|
||||
_ desc: BodyStructure.DispositionAndLanguage
|
||||
) -> Int {
|
||||
self.writeSpace() + self.writeBodyDisposition(desc.disposition)
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,13 @@ extension BodyStructure {
|
||||
/// - parameter description: A string giving the content description as defined in MIME-IMB
|
||||
/// - parameter encoding: The string giving the content transfer encoding as defined in MIME-IMB
|
||||
/// - parameter octetCount: The size of the body in octets. Note that this is in the encoded state, before any decoding takes place.
|
||||
public init(parameters: OrderedDictionary<String, String>, id: String?, contentDescription: String?, encoding: BodyStructure.Encoding?, octetCount: Int) {
|
||||
public init(
|
||||
parameters: OrderedDictionary<String, String>,
|
||||
id: String?,
|
||||
contentDescription: String?,
|
||||
encoding: BodyStructure.Encoding?,
|
||||
octetCount: Int
|
||||
) {
|
||||
self.parameters = parameters
|
||||
self.id = id
|
||||
self.contentDescription = contentDescription
|
||||
@@ -53,13 +59,8 @@ extension BodyStructure {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeBodyFields(_ fields: BodyStructure.Fields) -> Int {
|
||||
self.writeBodyParameterPairs(fields.parameters) +
|
||||
self.writeSpace() +
|
||||
self.writeNString(fields.id) +
|
||||
self.writeSpace() +
|
||||
self.writeNString(fields.contentDescription) +
|
||||
self.writeSpace() +
|
||||
self.writeBodyEncoding(fields.encoding) +
|
||||
self.writeString(" \(fields.octetCount)")
|
||||
self.writeBodyParameterPairs(fields.parameters) + self.writeSpace() + self.writeNString(fields.id)
|
||||
+ self.writeSpace() + self.writeNString(fields.contentDescription) + self.writeSpace()
|
||||
+ self.writeBodyEncoding(fields.encoding) + self.writeString(" \(fields.octetCount)")
|
||||
}
|
||||
}
|
||||
@@ -37,9 +37,8 @@ extension BodyStructure {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeBodyFieldLanguageLocation(_ langLoc: BodyStructure.LanguageLocation) -> Int {
|
||||
self.writeSpace() +
|
||||
self.writeBodyLanguages(langLoc.languages) +
|
||||
self.writeIfExists(langLoc.location) { (location) -> Int in
|
||||
self.writeSpace() + self.writeBodyLanguages(langLoc.languages)
|
||||
+ self.writeIfExists(langLoc.location) { (location) -> Int in
|
||||
self.writeBodyLocationAndExtensions(location)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,12 @@ extension BodyStructure {
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeBodyLocationAndExtensions(_ locationExtension: BodyStructure.LocationAndExtensions) -> Int {
|
||||
self.writeSpace() +
|
||||
self.writeNString(locationExtension.location) +
|
||||
self.write(if: !locationExtension.extensions.isEmpty) {
|
||||
self.writeSpace() +
|
||||
self.writeBodyExtensions(locationExtension.extensions)
|
||||
@discardableResult mutating func writeBodyLocationAndExtensions(
|
||||
_ locationExtension: BodyStructure.LocationAndExtensions
|
||||
) -> Int {
|
||||
self.writeSpace() + self.writeNString(locationExtension.location)
|
||||
+ self.write(if: !locationExtension.extensions.isEmpty) {
|
||||
self.writeSpace() + self.writeBodyExtensions(locationExtension.extensions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,7 @@ extension EncodeBuffer {
|
||||
return self.writeNil()
|
||||
}
|
||||
return self.writeOrderedDictionary(params) { (element, self) in
|
||||
self.writeIMAPString(element.key) +
|
||||
self.writeSpace() +
|
||||
self.writeIMAPString(element.value)
|
||||
self.writeIMAPString(element.key) + self.writeSpace() + self.writeIMAPString(element.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,10 @@ extension BodyStructure.Multipart {
|
||||
/// Creates a new `Multipart.Extension`.
|
||||
/// - parameter parameters : An array of *key/value* pairs.
|
||||
/// - parameter dispositionAndLanguage: A disposition paired to an array of languages.
|
||||
public init(parameters: OrderedDictionary<String, String>, dispositionAndLanguage: BodyStructure.DispositionAndLanguage?) {
|
||||
public init(
|
||||
parameters: OrderedDictionary<String, String>,
|
||||
dispositionAndLanguage: BodyStructure.DispositionAndLanguage?
|
||||
) {
|
||||
self.parameters = parameters
|
||||
self.dispositionAndLanguage = dispositionAndLanguage
|
||||
}
|
||||
@@ -66,18 +69,15 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeBodyMultipart(_ part: BodyStructure.Multipart) -> Int {
|
||||
part.parts.reduce(into: 0) { (result, body) in
|
||||
result += self.writeBody(body)
|
||||
} +
|
||||
self.writeSpace() +
|
||||
self.writeMediaSubtype(part.mediaSubtype) +
|
||||
self.writeIfExists(part.extension) { (ext) -> Int in
|
||||
self.writeSpace() +
|
||||
self.writeBodyExtensionMultipart(ext)
|
||||
} + self.writeSpace() + self.writeMediaSubtype(part.mediaSubtype)
|
||||
+ self.writeIfExists(part.extension) { (ext) -> Int in
|
||||
self.writeSpace() + self.writeBodyExtensionMultipart(ext)
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeBodyExtensionMultipart(_ ext: BodyStructure.Multipart.Extension) -> Int {
|
||||
self.writeBodyParameterPairs(ext.parameters) +
|
||||
self.writeIfExists(ext.dispositionAndLanguage) { (dspLanguage) -> Int in
|
||||
self.writeBodyParameterPairs(ext.parameters)
|
||||
+ self.writeIfExists(ext.dispositionAndLanguage) { (dspLanguage) -> Int in
|
||||
self.writeBodyDispositionAndLanguage(dspLanguage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,35 +137,33 @@ extension EncodeBuffer {
|
||||
return size
|
||||
}
|
||||
|
||||
@discardableResult private mutating func writeBodyKindText(_ body: BodyStructure.Singlepart.Text, fields: BodyStructure.Fields) -> Int {
|
||||
self.writeString(#""TEXT" "#) +
|
||||
self.writeMediaSubtype(body.mediaSubtype) +
|
||||
self.writeSpace() +
|
||||
self.writeBodyFields(fields) +
|
||||
self.writeString(" \(body.lineCount)")
|
||||
@discardableResult private mutating func writeBodyKindText(
|
||||
_ body: BodyStructure.Singlepart.Text,
|
||||
fields: BodyStructure.Fields
|
||||
) -> Int {
|
||||
self.writeString(#""TEXT" "#) + self.writeMediaSubtype(body.mediaSubtype) + self.writeSpace()
|
||||
+ self.writeBodyFields(fields) + self.writeString(" \(body.lineCount)")
|
||||
}
|
||||
|
||||
@discardableResult private mutating func writeBodyKindMessage(_ message: BodyStructure.Singlepart.Message, fields: BodyStructure.Fields) -> Int {
|
||||
self.writeString(#""MESSAGE" "#) +
|
||||
self.writeMediaSubtype(message.message) +
|
||||
self.writeSpace() +
|
||||
self.writeBodyFields(fields) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelope(message.envelope) +
|
||||
self.writeSpace() +
|
||||
self.writeBody(message.body) +
|
||||
self.writeString(" \(message.lineCount)")
|
||||
@discardableResult private mutating func writeBodyKindMessage(
|
||||
_ message: BodyStructure.Singlepart.Message,
|
||||
fields: BodyStructure.Fields
|
||||
) -> Int {
|
||||
self.writeString(#""MESSAGE" "#) + self.writeMediaSubtype(message.message) + self.writeSpace()
|
||||
+ self.writeBodyFields(fields) + self.writeSpace() + self.writeEnvelope(message.envelope)
|
||||
+ self.writeSpace() + self.writeBody(message.body) + self.writeString(" \(message.lineCount)")
|
||||
}
|
||||
|
||||
@discardableResult private mutating func writeBodyKindBasic(mediaType: Media.MediaType, fields: BodyStructure.Fields) -> Int {
|
||||
self.writeMediaType(mediaType) +
|
||||
self.writeSpace() +
|
||||
self.writeBodyFields(fields)
|
||||
@discardableResult private mutating func writeBodyKindBasic(
|
||||
mediaType: Media.MediaType,
|
||||
fields: BodyStructure.Fields
|
||||
) -> Int {
|
||||
self.writeMediaType(mediaType) + self.writeSpace() + self.writeBodyFields(fields)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeBodyExtensionSinglePart(_ ext: BodyStructure.Singlepart.Extension) -> Int {
|
||||
self.writeNString(ext.digest) +
|
||||
self.writeIfExists(ext.dispositionAndLanguage) { (dsp) -> Int in
|
||||
self.writeNString(ext.digest)
|
||||
+ self.writeIfExists(ext.dispositionAndLanguage) { (dsp) -> Int in
|
||||
self.writeBodyDispositionAndLanguage(dsp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeByteRange(_ data: ByteRange) -> Int {
|
||||
self.writeString("\(data.offset)") +
|
||||
self.writeIfExists(data.length) { length in
|
||||
self.writeString("\(data.offset)")
|
||||
+ self.writeIfExists(data.length) { length in
|
||||
self.writeString(".\(length)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,10 @@ extension MessagePath {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeMessagePathByteRange(_ data: MessagePath.ByteRange) -> Int {
|
||||
self.writeString("/;PARTIAL=") +
|
||||
self.writeByteRange(data.range)
|
||||
self.writeString("/;PARTIAL=") + self.writeByteRange(data.range)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessagePathByteRangeOnly(_ data: MessagePath.ByteRange) -> Int {
|
||||
self.writeString(";PARTIAL=") +
|
||||
self.writeByteRange(data.range)
|
||||
self.writeString(";PARTIAL=") + self.writeByteRange(data.range)
|
||||
}
|
||||
}
|
||||
@@ -403,11 +403,10 @@ extension Capability {
|
||||
/// - parameter type: The `SortKind`.
|
||||
/// - returns: A new `Capability`.
|
||||
public static func sort(_ type: SortKind?) -> Self {
|
||||
if let type = type {
|
||||
return Self("SORT=\(type.rawValue)")
|
||||
} else {
|
||||
guard let type = type else {
|
||||
return Self("SORT")
|
||||
}
|
||||
return Self("SORT=\(type.rawValue)")
|
||||
}
|
||||
|
||||
/// Creates a new *UTF8* capability.
|
||||
@@ -462,8 +461,8 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeCapabilityData(_ data: [Capability]) -> Int {
|
||||
self.writeString("CAPABILITY") +
|
||||
self.writeArray(data, prefix: " ", parenthesis: false) { (capability, self) -> Int in
|
||||
self.writeString("CAPABILITY")
|
||||
+ self.writeArray(data, prefix: " ", parenthesis: false) { (capability, self) -> Int in
|
||||
self.writeCapability(capability)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,9 +218,19 @@ extension CommandEncodeBuffer {
|
||||
case .examine(let mailbox, let params):
|
||||
return self.writeCommandKind_examine(mailbox: mailbox, parameters: params)
|
||||
case .list(let selectOptions, let mailbox, let mailboxPatterns, let returnOptions):
|
||||
return self.writeCommandKind_list(selectOptions: selectOptions, mailbox: mailbox, mailboxPatterns: mailboxPatterns, returnOptions: returnOptions)
|
||||
return self.writeCommandKind_list(
|
||||
selectOptions: selectOptions,
|
||||
mailbox: mailbox,
|
||||
mailboxPatterns: mailboxPatterns,
|
||||
returnOptions: returnOptions
|
||||
)
|
||||
case .listIndependent(let selectOptions, let mailbox, let mailboxPatterns, let returnOptions):
|
||||
return self.writeCommandKind_listIndependent(selectOptions: selectOptions, mailbox: mailbox, mailboxPatterns: mailboxPatterns, returnOptions: returnOptions)
|
||||
return self.writeCommandKind_listIndependent(
|
||||
selectOptions: selectOptions,
|
||||
mailbox: mailbox,
|
||||
mailboxPatterns: mailboxPatterns,
|
||||
returnOptions: returnOptions
|
||||
)
|
||||
case .lsub(let mailbox, let listMailbox):
|
||||
return self.writeCommandKind_lsub(mailbox: mailbox, listMailbox: listMailbox)
|
||||
case .rename(let from, let to, let params):
|
||||
@@ -303,24 +313,27 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_urlFetch(urls: [ByteBuffer]) -> Int {
|
||||
self.buffer.writeString("URLFETCH") +
|
||||
self.buffer.writeArray(urls, prefix: " ", parenthesis: false) { url, buffer in
|
||||
self.buffer.writeString("URLFETCH")
|
||||
+ self.buffer.writeArray(urls, prefix: " ", parenthesis: false) { url, buffer in
|
||||
buffer.writeBytes(url.readableBytesView)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_generateAuthorizedURL(mechanisms: [RumpURLAndMechanism]) -> Int {
|
||||
self.buffer.writeString("GENURLAUTH") +
|
||||
self.buffer.writeArray(mechanisms, prefix: " ", parenthesis: false) { mechanism, buffer in
|
||||
self.buffer.writeString("GENURLAUTH")
|
||||
+ self.buffer.writeArray(mechanisms, prefix: " ", parenthesis: false) { mechanism, buffer in
|
||||
buffer.writeURLRumpMechanism(mechanism)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_resetKey(mailbox: MailboxName?, mechanisms: [URLAuthenticationMechanism]) -> Int {
|
||||
self.buffer.writeString("RESETKEY") +
|
||||
self.buffer.writeIfExists(mailbox) { mailbox in
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
private mutating func writeCommandKind_resetKey(
|
||||
mailbox: MailboxName?,
|
||||
mechanisms: [URLAuthenticationMechanism]
|
||||
) -> Int {
|
||||
self.buffer.writeString("RESETKEY")
|
||||
+ self.buffer.writeIfExists(mailbox) { mailbox in
|
||||
self.buffer.writeSpace() + self.buffer.writeMailbox(mailbox)
|
||||
+
|
||||
|
||||
self.buffer.writeArray(mechanisms, prefix: " ", parenthesis: false) { mechanism, buffer in
|
||||
buffer.writeURLAuthenticationMechanism(mechanism)
|
||||
@@ -328,22 +341,24 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_getMetadata(options: [MetadataOption], mailbox: MailboxName, entries: [MetadataEntryName]) -> Int {
|
||||
self.buffer.writeString("GETMETADATA") +
|
||||
self.buffer.write(if: options.count >= 1) {
|
||||
private mutating func writeCommandKind_getMetadata(
|
||||
options: [MetadataOption],
|
||||
mailbox: MailboxName,
|
||||
entries: [MetadataEntryName]
|
||||
) -> Int {
|
||||
self.buffer.writeString("GETMETADATA")
|
||||
+ self.buffer.write(if: options.count >= 1) {
|
||||
buffer.writeSpace() + buffer.writeMetadataOptions(options)
|
||||
} +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeEntries(entries)
|
||||
} + self.buffer.writeSpace() + self.buffer.writeMailbox(mailbox) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeEntries(entries)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_setMetadata(mailbox: MailboxName, entries: OrderedDictionary<MetadataEntryName, MetadataValue>) -> Int {
|
||||
self.buffer.writeString("SETMETADATA ") +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeEntryValues(entries)
|
||||
private mutating func writeCommandKind_setMetadata(
|
||||
mailbox: MailboxName,
|
||||
entries: OrderedDictionary<MetadataEntryName, MetadataValue>
|
||||
) -> Int {
|
||||
self.buffer.writeString("SETMETADATA ") + self.buffer.writeMailbox(mailbox) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeEntryValues(entries)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_capability() -> Int {
|
||||
@@ -359,99 +374,91 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_create(mailbox: MailboxName, parameters: [CreateParameter]) -> Int {
|
||||
self.buffer.writeString("CREATE ") +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.write(if: parameters.count > 0) {
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeArray(parameters, separator: "", parenthesis: true) { (param, buffer) -> Int in
|
||||
self.buffer.writeString("CREATE ") + self.buffer.writeMailbox(mailbox)
|
||||
+ self.buffer.write(if: parameters.count > 0) {
|
||||
self.buffer.writeSpace()
|
||||
+ self.buffer.writeArray(parameters, separator: "", parenthesis: true) { (param, buffer) -> Int in
|
||||
buffer.writeCreateParameter(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_delete(mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("DELETE ") +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("DELETE ") + self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_examine(mailbox: MailboxName, parameters: [SelectParameter]) -> Int {
|
||||
self.buffer.writeString("EXAMINE ") +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSelectParameters(parameters)
|
||||
self.buffer.writeString("EXAMINE ") + self.buffer.writeMailbox(mailbox)
|
||||
+ self.buffer.writeSelectParameters(parameters)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_list(selectOptions: ListSelectOptions?, mailbox: MailboxName, mailboxPatterns: MailboxPatterns, returnOptions: [ReturnOption]) -> Int {
|
||||
self.buffer.writeString("LIST") +
|
||||
self.buffer.writeIfExists(selectOptions) { (options) -> Int in
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeListSelectOptions(options)
|
||||
} +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailboxPatterns(mailboxPatterns) +
|
||||
self.buffer.write(if: returnOptions.count >= 1) {
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeListReturnOptions(returnOptions)
|
||||
private mutating func writeCommandKind_list(
|
||||
selectOptions: ListSelectOptions?,
|
||||
mailbox: MailboxName,
|
||||
mailboxPatterns: MailboxPatterns,
|
||||
returnOptions: [ReturnOption]
|
||||
) -> Int {
|
||||
self.buffer.writeString("LIST")
|
||||
+ self.buffer.writeIfExists(selectOptions) { (options) -> Int in
|
||||
self.buffer.writeSpace() + self.buffer.writeListSelectOptions(options)
|
||||
} + self.buffer.writeSpace() + self.buffer.writeMailbox(mailbox) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailboxPatterns(mailboxPatterns)
|
||||
+ self.buffer.write(if: returnOptions.count >= 1) {
|
||||
self.buffer.writeSpace() + self.buffer.writeListReturnOptions(returnOptions)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_listIndependent(selectOptions: [ListSelectIndependentOption], mailbox: MailboxName, mailboxPatterns: MailboxPatterns, returnOptions: [ReturnOption]) -> Int {
|
||||
self.buffer.writeString("LIST") +
|
||||
self.buffer.write(if: selectOptions.count >= 1) {
|
||||
private mutating func writeCommandKind_listIndependent(
|
||||
selectOptions: [ListSelectIndependentOption],
|
||||
mailbox: MailboxName,
|
||||
mailboxPatterns: MailboxPatterns,
|
||||
returnOptions: [ReturnOption]
|
||||
) -> Int {
|
||||
self.buffer.writeString("LIST")
|
||||
+ self.buffer.write(if: selectOptions.count >= 1) {
|
||||
self.buffer.writeArray(selectOptions) { element, buffer in
|
||||
buffer.writeListSelectIndependentOption(element)
|
||||
}
|
||||
} +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailboxPatterns(mailboxPatterns) +
|
||||
self.buffer.write(if: returnOptions.count >= 1) {
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeListReturnOptions(returnOptions)
|
||||
} + self.buffer.writeSpace() + self.buffer.writeMailbox(mailbox) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailboxPatterns(mailboxPatterns)
|
||||
+ self.buffer.write(if: returnOptions.count >= 1) {
|
||||
self.buffer.writeSpace() + self.buffer.writeListReturnOptions(returnOptions)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_lsub(mailbox: MailboxName, listMailbox: ByteBuffer) -> Int {
|
||||
self.buffer.writeString("LSUB ") +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeIMAPString(listMailbox)
|
||||
self.buffer.writeString("LSUB ") + self.buffer.writeMailbox(mailbox) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeIMAPString(listMailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_rename(from: MailboxName, to: MailboxName, parameters: OrderedDictionary<String, ParameterValue?>) -> Int {
|
||||
self.buffer.writeString("RENAME ") +
|
||||
self.buffer.writeMailbox(from) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(to) +
|
||||
self.buffer.writeIfExists(parameters) { (params) -> Int in
|
||||
private mutating func writeCommandKind_rename(
|
||||
from: MailboxName,
|
||||
to: MailboxName,
|
||||
parameters: OrderedDictionary<String, ParameterValue?>
|
||||
) -> Int {
|
||||
self.buffer.writeString("RENAME ") + self.buffer.writeMailbox(from) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailbox(to)
|
||||
+ self.buffer.writeIfExists(parameters) { (params) -> Int in
|
||||
self.buffer.writeParameters(params)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_select(mailbox: MailboxName, parameters: [SelectParameter]) -> Int {
|
||||
self.buffer.writeString("SELECT ") +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeSelectParameters(parameters)
|
||||
self.buffer.writeString("SELECT ") + self.buffer.writeMailbox(mailbox)
|
||||
+ self.buffer.writeSelectParameters(parameters)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_status(mailbox: MailboxName, attributes: [MailboxAttribute]) -> Int {
|
||||
self.buffer.writeString("STATUS ") +
|
||||
self.buffer.writeMailbox(mailbox) +
|
||||
self.buffer.writeString(" (") +
|
||||
self.buffer.writeMailboxAttributes(attributes) +
|
||||
self.buffer.writeString(")")
|
||||
self.buffer.writeString("STATUS ") + self.buffer.writeMailbox(mailbox) + self.buffer.writeString(" (")
|
||||
+ self.buffer.writeMailboxAttributes(attributes) + self.buffer.writeString(")")
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_subscribe(mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("SUBSCRIBE ") +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("SUBSCRIBE ") + self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_unsubscribe(mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("UNSUBSCRIBE ") +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("UNSUBSCRIBE ") + self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_compress(kind: Capability.CompressionKind) -> Int {
|
||||
@@ -459,16 +466,18 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_custom(name: String, payloads: [Command.CustomCommandPayload]) -> Int {
|
||||
self.buffer.writeString("\(name)") +
|
||||
self.buffer.writeArray(payloads, prefix: " ", separator: "", parenthesis: false) { (payload, self) in
|
||||
self.buffer.writeString("\(name)")
|
||||
+ self.buffer.writeArray(payloads, prefix: " ", separator: "", parenthesis: false) { (payload, self) in
|
||||
self.writeCustomCommandPayload(payload)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_authenticate(mechanism: AuthenticationMechanism, initialResponse: InitialResponse?) -> Int {
|
||||
self.buffer.writeString("AUTHENTICATE ") +
|
||||
self.buffer.writeAuthenticationMechanism(mechanism) +
|
||||
self.buffer.writeIfExists(initialResponse) { resp in
|
||||
private mutating func writeCommandKind_authenticate(
|
||||
mechanism: AuthenticationMechanism,
|
||||
initialResponse: InitialResponse?
|
||||
) -> Int {
|
||||
self.buffer.writeString("AUTHENTICATE ") + self.buffer.writeAuthenticationMechanism(mechanism)
|
||||
+ self.buffer.writeIfExists(initialResponse) { resp in
|
||||
var c = self.buffer.writeSpace()
|
||||
if self.buffer.loggingMode {
|
||||
c += self.buffer.writeString("∅")
|
||||
@@ -480,10 +489,8 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_login(userID: String, password: String) -> Int {
|
||||
self.buffer.writeString("LOGIN ") +
|
||||
self.buffer.writeIMAPString(userID) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeIMAPString(password)
|
||||
self.buffer.writeString("LOGIN ") + self.buffer.writeIMAPString(userID) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeIMAPString(password)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_startTLS() -> Int {
|
||||
@@ -503,8 +510,7 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_uidExpunge(_ set: LastCommandSet<UID>) -> Int {
|
||||
self.buffer.writeString("EXPUNGE ") +
|
||||
self.buffer.writeLastCommandSet(set)
|
||||
self.buffer.writeString("EXPUNGE ") + self.buffer.writeLastCommandSet(set)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_unselect() -> Int {
|
||||
@@ -520,96 +526,98 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_enable(capabilities: [Capability]) -> Int {
|
||||
self.buffer.writeString("ENABLE ") +
|
||||
self.buffer.writeArray(capabilities, parenthesis: false) { (element, self) in
|
||||
self.buffer.writeString("ENABLE ")
|
||||
+ self.buffer.writeArray(capabilities, parenthesis: false) { (element, self) in
|
||||
self.writeCapability(element)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_copy(set: LastCommandSet<SequenceNumber>, mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("COPY ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("COPY ") + self.buffer.writeLastCommandSet(set) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_uidCopy(set: LastCommandSet<UID>, mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("UID COPY ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("UID COPY ") + self.buffer.writeLastCommandSet(set) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_fetch(set: LastCommandSet<SequenceNumber>, atts: [FetchAttribute], modifiers: [FetchModifier]) -> Int {
|
||||
self.buffer.writeString("FETCH ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeFetchAttributeList(atts) +
|
||||
self.buffer.writeFetchModifiers(modifiers)
|
||||
private mutating func writeCommandKind_fetch(
|
||||
set: LastCommandSet<SequenceNumber>,
|
||||
atts: [FetchAttribute],
|
||||
modifiers: [FetchModifier]
|
||||
) -> Int {
|
||||
self.buffer.writeString("FETCH ") + self.buffer.writeLastCommandSet(set) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeFetchAttributeList(atts) + self.buffer.writeFetchModifiers(modifiers)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_uidFetch(set: LastCommandSet<UID>, atts: [FetchAttribute], modifiers: [FetchModifier]) -> Int {
|
||||
self.buffer.writeString("UID FETCH ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeFetchAttributeList(atts) +
|
||||
self.buffer.writeFetchModifiers(modifiers)
|
||||
private mutating func writeCommandKind_uidFetch(
|
||||
set: LastCommandSet<UID>,
|
||||
atts: [FetchAttribute],
|
||||
modifiers: [FetchModifier]
|
||||
) -> Int {
|
||||
self.buffer.writeString("UID FETCH ") + self.buffer.writeLastCommandSet(set) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeFetchAttributeList(atts) + self.buffer.writeFetchModifiers(modifiers)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_store(set: LastCommandSet<SequenceNumber>, modifiers: [StoreModifier], data: StoreData) -> Int {
|
||||
self.buffer.writeString("STORE ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.write(if: modifiers.count >= 1) {
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeArray(modifiers) { (element, buffer) -> Int in
|
||||
private mutating func writeCommandKind_store(
|
||||
set: LastCommandSet<SequenceNumber>,
|
||||
modifiers: [StoreModifier],
|
||||
data: StoreData
|
||||
) -> Int {
|
||||
self.buffer.writeString("STORE ") + self.buffer.writeLastCommandSet(set)
|
||||
+ self.buffer.write(if: modifiers.count >= 1) {
|
||||
self.buffer.writeSpace()
|
||||
+ self.buffer.writeArray(modifiers) { (element, buffer) -> Int in
|
||||
buffer.writeStoreModifier(element)
|
||||
}
|
||||
} +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeStoreData(data)
|
||||
} + self.buffer.writeSpace() + self.buffer.writeStoreData(data)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_uidStore(set: LastCommandSet<UID>, modifiers: [StoreModifier], data: StoreData) -> Int {
|
||||
self.buffer.writeString("UID STORE ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.write(if: modifiers.count >= 1) {
|
||||
private mutating func writeCommandKind_uidStore(
|
||||
set: LastCommandSet<UID>,
|
||||
modifiers: [StoreModifier],
|
||||
data: StoreData
|
||||
) -> Int {
|
||||
self.buffer.writeString("UID STORE ") + self.buffer.writeLastCommandSet(set)
|
||||
+ self.buffer.write(if: modifiers.count >= 1) {
|
||||
self.buffer.writeStoreModifiers(modifiers)
|
||||
} +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeStoreData(data)
|
||||
} + self.buffer.writeSpace() + self.buffer.writeStoreData(data)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_search(key: SearchKey, charset: String? = nil, returnOptions: [SearchReturnOption] = []) -> Int {
|
||||
self.buffer.writeString("SEARCH") +
|
||||
self.buffer.writeIfExists(returnOptions) { (options) -> Int in
|
||||
private mutating func writeCommandKind_search(
|
||||
key: SearchKey,
|
||||
charset: String? = nil,
|
||||
returnOptions: [SearchReturnOption] = []
|
||||
) -> Int {
|
||||
self.buffer.writeString("SEARCH")
|
||||
+ self.buffer.writeIfExists(returnOptions) { (options) -> Int in
|
||||
self.buffer.writeSearchReturnOptions(options)
|
||||
} +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.write(if: key.usesString) {
|
||||
} + self.buffer.writeSpace()
|
||||
+ self.buffer.write(if: key.usesString) {
|
||||
self.buffer.writeIfExists(charset) { (charset) -> Int in
|
||||
self.buffer.writeString("CHARSET \(charset) ")
|
||||
}
|
||||
} +
|
||||
self.buffer.writeSearchKey(key)
|
||||
} + self.buffer.writeSearchKey(key)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_uidSearch(key: SearchKey, charset: String? = nil, returnOptions: [SearchReturnOption] = []) -> Int {
|
||||
self.buffer.writeString("UID ") +
|
||||
self.writeCommandKind_search(key: key, charset: charset, returnOptions: returnOptions)
|
||||
private mutating func writeCommandKind_uidSearch(
|
||||
key: SearchKey,
|
||||
charset: String? = nil,
|
||||
returnOptions: [SearchReturnOption] = []
|
||||
) -> Int {
|
||||
self.buffer.writeString("UID ")
|
||||
+ self.writeCommandKind_search(key: key, charset: charset, returnOptions: returnOptions)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_move(set: LastCommandSet<SequenceNumber>, mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("MOVE ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("MOVE ") + self.buffer.writeLastCommandSet(set) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_uidMove(set: LastCommandSet<UID>, mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("UID MOVE ") +
|
||||
self.buffer.writeLastCommandSet(set) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("UID MOVE ") + self.buffer.writeLastCommandSet(set) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_namespace() -> Int {
|
||||
@@ -617,32 +625,26 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeCommandKind_id(_ id: OrderedDictionary<String, String?>) -> Int {
|
||||
self.buffer.writeString("ID ") +
|
||||
self.buffer.writeIDParameters(id)
|
||||
self.buffer.writeString("ID ") + self.buffer.writeIDParameters(id)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_getQuota(quotaRoot: QuotaRoot) -> Int {
|
||||
self.buffer.writeString("GETQUOTA ") +
|
||||
self.buffer.writeQuotaRoot(quotaRoot)
|
||||
self.buffer.writeString("GETQUOTA ") + self.buffer.writeQuotaRoot(quotaRoot)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_getQuotaRoot(mailbox: MailboxName) -> Int {
|
||||
self.buffer.writeString("GETQUOTAROOT ") +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("GETQUOTAROOT ") + self.buffer.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_setQuota(quotaRoot: QuotaRoot, resourceLimits: [QuotaLimit]) -> Int {
|
||||
self.buffer.writeString("SETQUOTA ") +
|
||||
self.buffer.writeQuotaRoot(quotaRoot) +
|
||||
self.buffer.writeSpace() +
|
||||
self.buffer.writeArray(resourceLimits) { (limit, self) in
|
||||
self.buffer.writeString("SETQUOTA ") + self.buffer.writeQuotaRoot(quotaRoot) + self.buffer.writeSpace()
|
||||
+ self.buffer.writeArray(resourceLimits) { (limit, self) in
|
||||
self.writeQuotaLimit(limit)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_extendedSearch(options: ExtendedSearchOptions) -> Int {
|
||||
self.buffer.writeString("ESEARCH") +
|
||||
self.buffer.writeExtendedSearchOptions(options)
|
||||
self.buffer.writeString("ESEARCH") + self.buffer.writeExtendedSearchOptions(options)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,7 +681,8 @@ extension Command {
|
||||
/// - parameter attributes: Which attributes to retrieve.
|
||||
/// - parameter modifiers: Fetch modifiers.
|
||||
/// - returns: `nil` if `messages` is empty, otherwise a `Command`.
|
||||
public static func uidFetch(messages: UIDSet, attributes: [FetchAttribute], modifiers: [FetchModifier]) -> Command? {
|
||||
public static func uidFetch(messages: UIDSet, attributes: [FetchAttribute], modifiers: [FetchModifier]) -> Command?
|
||||
{
|
||||
guard let set = MessageIdentifierSetNonEmpty(set: messages) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ public enum AppendCommand: Hashable, Sendable {
|
||||
case .start(let tag, _):
|
||||
return tag
|
||||
case .beginMessage, .messageBytes, .endMessage,
|
||||
.beginCatenate, .catenateURL, .catenateData,
|
||||
.endCatenate, .finish:
|
||||
.beginCatenate, .catenateURL, .catenateData,
|
||||
.endCatenate, .finish:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -171,8 +171,7 @@ extension CommandEncodeBuffer {
|
||||
switch command {
|
||||
case .start(tag: let tag, appendingTo: let mailbox):
|
||||
return
|
||||
self.buffer.writeString("\(tag) APPEND ") +
|
||||
self.buffer.writeMailbox(mailbox)
|
||||
self.buffer.writeString("\(tag) APPEND ") + self.buffer.writeMailbox(mailbox)
|
||||
case .beginMessage(message: let message):
|
||||
return self.buffer.writeAppendMessage(message)
|
||||
case .messageBytes(var bytes):
|
||||
@@ -184,19 +183,18 @@ extension CommandEncodeBuffer {
|
||||
}
|
||||
return 0
|
||||
case .beginCatenate(options: let options):
|
||||
return self.buffer.writeAppendOptions(options) +
|
||||
self.buffer.writeString(" CATENATE (")
|
||||
return self.buffer.writeAppendOptions(options) + self.buffer.writeString(" CATENATE (")
|
||||
case .catenateURL(let url):
|
||||
defer {
|
||||
self.encodedAtLeastOneCatenateElement = true
|
||||
}
|
||||
|
||||
return self.buffer.write(if: self.encodedAtLeastOneCatenateElement) { self.buffer.writeSpace() } +
|
||||
self.buffer.writeString("URL ") +
|
||||
self.buffer.writeIMAPString(url)
|
||||
return self.buffer.write(if: self.encodedAtLeastOneCatenateElement) { self.buffer.writeSpace() }
|
||||
+ self.buffer.writeString("URL ") + self.buffer.writeIMAPString(url)
|
||||
case .catenateData(.begin(let size)):
|
||||
var written = self.buffer.write(if: self.encodedAtLeastOneCatenateElement) { self.buffer.writeSpace() } +
|
||||
self.buffer.writeString("TEXT ")
|
||||
var written =
|
||||
self.buffer.write(if: self.encodedAtLeastOneCatenateElement) { self.buffer.writeSpace() }
|
||||
+ self.buffer.writeString("TEXT ")
|
||||
|
||||
if self.options.useNonSynchronizingLiteralPlus {
|
||||
written += self.buffer.writeString("{\(size)+}\r\n")
|
||||
|
||||
@@ -29,8 +29,8 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeCreateParameter(_ parameter: CreateParameter) -> Int {
|
||||
switch parameter {
|
||||
case .attributes(let attributes):
|
||||
return self.writeString("USE ") +
|
||||
self.writeArray(attributes) { (att, buffer) -> Int in
|
||||
return self.writeString("USE ")
|
||||
+ self.writeArray(attributes) { (att, buffer) -> Int in
|
||||
buffer.writeUseAttribute(att)
|
||||
}
|
||||
case .labelled(let parameter):
|
||||
|
||||
@@ -44,7 +44,15 @@ public struct ServerMessageDate: Hashable, Sendable {
|
||||
let zoneMinutes = Int(zoneValue) * ((zoneIsNegative == 0) ? 1 : -1)
|
||||
|
||||
// safe to bang as we can't have an invalid `ServerMessageDate`
|
||||
return Components(year: year, month: month, day: day, hour: hour, minute: minute, second: second, timeZoneMinutes: zoneMinutes)!
|
||||
return Components(
|
||||
year: year,
|
||||
month: month,
|
||||
day: day,
|
||||
hour: hour,
|
||||
minute: minute,
|
||||
second: second,
|
||||
timeZoneMinutes: zoneMinutes
|
||||
)!
|
||||
}
|
||||
|
||||
/// Creates a new `ServerMessageDate` from a given collection of `Components`
|
||||
@@ -105,13 +113,13 @@ extension ServerMessageDate {
|
||||
/// - parameter zoneMinutes: The timezone as an offset in minutes from UTC.
|
||||
public init?(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int, timeZoneMinutes: Int) {
|
||||
guard
|
||||
(1 ... 31).contains(day),
|
||||
(1 ... 12).contains(month),
|
||||
(0 ... 23).contains(hour),
|
||||
(0 ... 59).contains(minute),
|
||||
(0 ... 60).contains(second),
|
||||
((-24 * 60) ... (24 * 60)).contains(timeZoneMinutes),
|
||||
(1 ... Int(UInt16.max)).contains(year)
|
||||
(1...31).contains(day),
|
||||
(1...12).contains(month),
|
||||
(0...23).contains(hour),
|
||||
(0...59).contains(minute),
|
||||
(0...60).contains(second),
|
||||
((-24 * 60)...(24 * 60)).contains(timeZoneMinutes),
|
||||
(1...Int(UInt16.max)).contains(year)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
@@ -180,11 +188,8 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
return
|
||||
self.writeString("\"\(p.0.day)-\(monthName)-\(p.0.year) ") +
|
||||
self.writeTime(p.1) +
|
||||
self.writeSpace() +
|
||||
self.writeTimezone(p.2) +
|
||||
self.writeString("\"")
|
||||
self.writeString("\"\(p.0.day)-\(monthName)-\(p.0.year) ") + self.writeTime(p.1) + self.writeSpace()
|
||||
+ self.writeTimezone(p.2) + self.writeString("\"")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,14 +52,12 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeExtendedSearchOptions(_ options: ExtendedSearchOptions) -> Int {
|
||||
self.writeIfExists(options.sourceOptions) { (options) -> Int in
|
||||
self.writeSpace() + self.writeExtendedSearchSourceOptions(options)
|
||||
} +
|
||||
self.writeIfExists(options.returnOptions) { (options) -> Int in
|
||||
}
|
||||
+ self.writeIfExists(options.returnOptions) { (options) -> Int in
|
||||
self.writeSearchReturnOptions(options)
|
||||
} +
|
||||
self.writeSpace() +
|
||||
self.writeIfExists(options.charset) { (charset) -> Int in
|
||||
} + self.writeSpace()
|
||||
+ self.writeIfExists(options.charset) { (charset) -> Int in
|
||||
self.writeString("CHARSET \(charset) ")
|
||||
} +
|
||||
self.writeSearchKey(options.key)
|
||||
} + self.writeSearchKey(options.key)
|
||||
}
|
||||
}
|
||||
@@ -38,15 +38,12 @@ public struct ExtendedSearchSourceOptions: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeExtendedSearchSourceOptions(_ options: ExtendedSearchSourceOptions) -> Int {
|
||||
self.writeString("IN (") +
|
||||
self.writeArray(options.sourceMailbox, parenthesis: false) { (filter, buffer) -> Int in
|
||||
self.writeString("IN (")
|
||||
+ self.writeArray(options.sourceMailbox, parenthesis: false) { (filter, buffer) -> Int in
|
||||
buffer.writeMailboxFilter(filter)
|
||||
} +
|
||||
self.writeIfExists(options.scopeOptions) { scopeOptions in
|
||||
self.writeString(" (") +
|
||||
self.writeExtendedSearchScopeOptions(scopeOptions) +
|
||||
self.writeString(")")
|
||||
} +
|
||||
self.writeString(")")
|
||||
}
|
||||
+ self.writeIfExists(options.scopeOptions) { scopeOptions in
|
||||
self.writeString(" (") + self.writeExtendedSearchScopeOptions(scopeOptions) + self.writeString(")")
|
||||
} + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -46,14 +46,8 @@ public struct EmailAddress: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeEmailAddress(_ address: EmailAddress) -> Int {
|
||||
self.writeString("(") +
|
||||
self.writeNString(address.personName) +
|
||||
self.writeSpace() +
|
||||
self.writeNString(address.sourceRoot) +
|
||||
self.writeSpace() +
|
||||
self.writeNString(address.mailbox) +
|
||||
self.writeSpace() +
|
||||
self.writeNString(address.host) +
|
||||
self.writeString(")")
|
||||
self.writeString("(") + self.writeNString(address.personName) + self.writeSpace()
|
||||
+ self.writeNString(address.sourceRoot) + self.writeSpace() + self.writeNString(address.mailbox)
|
||||
+ self.writeSpace() + self.writeNString(address.host) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ import struct NIO.ByteBuffer
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeEnableData(_ data: [Capability]) -> Int {
|
||||
self.writeString("ENABLED") +
|
||||
data.reduce(0) { (result, capability) in
|
||||
self.writeString("ENABLED")
|
||||
+ data.reduce(0) { (result, capability) in
|
||||
result + self.writeSpace() + self.writeCapability(capability)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ public struct EncodedSearchQuery: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeEncodedSearchQuery(_ ref: EncodedSearchQuery) -> Int {
|
||||
self.writeEncodedMailboxUIDValidity(ref.mailboxUIDValidity) +
|
||||
self.writeIfExists(ref.encodedSearch) { search in
|
||||
self.writeEncodedMailboxUIDValidity(ref.mailboxUIDValidity)
|
||||
+ self.writeIfExists(ref.encodedSearch) { search in
|
||||
self.writeString("?") + self.writeEncodedSearch(search)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ import struct OrderedCollections.OrderedDictionary
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeEntry(_ entry: KeyValue<MetadataEntryName, MetadataValue>) -> Int {
|
||||
self.writeIMAPString(String(entry.key)) +
|
||||
self.writeSpace() +
|
||||
self.writeMetadataValue(entry.value)
|
||||
self.writeIMAPString(String(entry.key)) + self.writeSpace() + self.writeMetadataValue(entry.value)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeEntryValues(_ array: OrderedDictionary<MetadataEntryName, MetadataValue>) -> Int {
|
||||
@discardableResult mutating func writeEntryValues(
|
||||
_ array: OrderedDictionary<MetadataEntryName, MetadataValue>
|
||||
) -> Int {
|
||||
self.writeOrderedDictionary(array) { element, buffer in
|
||||
buffer.writeEntry(element)
|
||||
}
|
||||
|
||||
@@ -92,11 +92,10 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
return
|
||||
self.writeString("(") +
|
||||
self.writeArray(addresses, separator: "", parenthesis: false) { (aog, self) -> Int in
|
||||
self.writeString("(")
|
||||
+ self.writeArray(addresses, separator: "", parenthesis: false) { (aog, self) -> Int in
|
||||
self.writeEmailAddressOrGroup(aog)
|
||||
} +
|
||||
self.writeString(")")
|
||||
} + self.writeString(")")
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeOptionalMessageID(_ id: MessageID?) -> Int {
|
||||
@@ -107,26 +106,13 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeEnvelope(_ envelope: Envelope) -> Int {
|
||||
self.writeString("(") +
|
||||
self.writeNString(envelope.date?.value) +
|
||||
self.writeSpace() +
|
||||
self.writeNString(envelope.subject) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelopeAddresses(envelope.from) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelopeAddresses(envelope.sender) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelopeAddresses(envelope.reply) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelopeAddresses(envelope.to) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelopeAddresses(envelope.cc) +
|
||||
self.writeSpace() +
|
||||
self.writeEnvelopeAddresses(envelope.bcc) +
|
||||
self.writeSpace() +
|
||||
self.writeOptionalMessageID(envelope.inReplyTo) +
|
||||
self.writeSpace() +
|
||||
self.writeOptionalMessageID(envelope.messageID) +
|
||||
self.writeString(")")
|
||||
self.writeString("(") + self.writeNString(envelope.date?.value) + self.writeSpace()
|
||||
+ self.writeNString(envelope.subject) + self.writeSpace() + self.writeEnvelopeAddresses(envelope.from)
|
||||
+ self.writeSpace() + self.writeEnvelopeAddresses(envelope.sender) + self.writeSpace()
|
||||
+ self.writeEnvelopeAddresses(envelope.reply) + self.writeSpace() + self.writeEnvelopeAddresses(envelope.to)
|
||||
+ self.writeSpace() + self.writeEnvelopeAddresses(envelope.cc) + self.writeSpace()
|
||||
+ self.writeEnvelopeAddresses(envelope.bcc) + self.writeSpace()
|
||||
+ self.writeOptionalMessageID(envelope.inReplyTo) + self.writeSpace()
|
||||
+ self.writeOptionalMessageID(envelope.messageID) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ public struct Expire: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeExpire(_ data: Expire) -> Int {
|
||||
self.writeString(";EXPIRE=") +
|
||||
self.writeFullDateTime(data.dateTime)
|
||||
self.writeString(";EXPIRE=") + self.writeFullDateTime(data.dateTime)
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,9 @@ extension Array where Element == FetchAttribute {
|
||||
public static let fast: [Element] = [.flags, .internalDate, .rfc822Size]
|
||||
|
||||
/// Macro equivalent to `[.flags, .internalDate, .rfc822Size, envelope, body]`
|
||||
public static let full: [Element] = [.flags, .internalDate, .rfc822Size, .envelope, .bodyStructure(extensions: false)]
|
||||
public static let full: [Element] = [
|
||||
.flags, .internalDate, .rfc822Size, .envelope, .bodyStructure(extensions: false),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Encoding
|
||||
@@ -109,7 +111,9 @@ extension EncodeBuffer {
|
||||
if atts.count == 4, atts.contains(.rfc822Size), atts.contains(.envelope) {
|
||||
return self.writeString("ALL")
|
||||
}
|
||||
if atts.count == 5, atts.contains(.rfc822Size), atts.contains(.envelope), atts.contains(.bodyStructure(extensions: false)) {
|
||||
if atts.count == 5, atts.contains(.rfc822Size), atts.contains(.envelope),
|
||||
atts.contains(.bodyStructure(extensions: false))
|
||||
{
|
||||
return self.writeString("FULL")
|
||||
}
|
||||
}
|
||||
@@ -200,26 +204,31 @@ extension EncodeBuffer {
|
||||
self.writeString(extensions ? "BODYSTRUCTURE" : "BODY")
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeFetchAttribute_body(peek: Bool, section: SectionSpecifier?, partial: ClosedRange<UInt32>?) -> Int {
|
||||
self.writeString(peek ? "BODY.PEEK" : "BODY") +
|
||||
self.writeSection(section) +
|
||||
self.writeIfExists(partial) { (partial) -> Int in
|
||||
@discardableResult mutating func writeFetchAttribute_body(
|
||||
peek: Bool,
|
||||
section: SectionSpecifier?,
|
||||
partial: ClosedRange<UInt32>?
|
||||
) -> Int {
|
||||
self.writeString(peek ? "BODY.PEEK" : "BODY") + self.writeSection(section)
|
||||
+ self.writeIfExists(partial) { (partial) -> Int in
|
||||
self.writeByteRange(partial)
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeFetchAttribute_binarySize(_ section: SectionSpecifier.Part) -> Int {
|
||||
self.writeString("BINARY.SIZE") +
|
||||
self.writeSectionBinary(section)
|
||||
self.writeString("BINARY.SIZE") + self.writeSectionBinary(section)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeFetchAttribute_binary(peek: Bool, section: SectionSpecifier.Part, partial: ClosedRange<UInt32>?) -> Int {
|
||||
self.writeString("BINARY") +
|
||||
self.write(if: peek) {
|
||||
@discardableResult mutating func writeFetchAttribute_binary(
|
||||
peek: Bool,
|
||||
section: SectionSpecifier.Part,
|
||||
partial: ClosedRange<UInt32>?
|
||||
) -> Int {
|
||||
self.writeString("BINARY")
|
||||
+ self.write(if: peek) {
|
||||
self.writeString(".PEEK")
|
||||
} +
|
||||
self.writeSectionBinary(section) +
|
||||
self.writeIfExists(partial) { (partial) -> Int in
|
||||
} + self.writeSectionBinary(section)
|
||||
+ self.writeIfExists(partial) { (partial) -> Int in
|
||||
self.writeByteRange(partial)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ public struct FetchModificationResponse: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeFetchModificationResponse(_ resp: FetchModificationResponse) -> Int {
|
||||
self.writeString("MODSEQ (") +
|
||||
self.writeModificationSequenceValue(resp.modificationSequenceValue) +
|
||||
self.writeString(")")
|
||||
self.writeString("MODSEQ (") + self.writeModificationSequenceValue(resp.modificationSequenceValue)
|
||||
+ self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -45,8 +45,8 @@ extension EncodeBuffer {
|
||||
if a.isEmpty {
|
||||
return 0
|
||||
}
|
||||
return self.writeSpace() +
|
||||
self.writeArray(a) { (modifier, self) in
|
||||
return self.writeSpace()
|
||||
+ self.writeArray(a) { (modifier, self) in
|
||||
self.writeFetchModifier(modifier)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,11 @@ extension Flag {
|
||||
init(unchecked string: String) {
|
||||
/// RFC 3501 defines `flag-keyword` as `atom`,
|
||||
/// but Gmail sends flags with `[` and `]` in them.
|
||||
assert(string.utf8.allSatisfy { (c) -> Bool in
|
||||
c.isAtomChar || c.isResponseSpecial
|
||||
})
|
||||
assert(
|
||||
string.utf8.allSatisfy { (c) -> Bool in
|
||||
c.isAtomChar || c.isResponseSpecial
|
||||
}
|
||||
)
|
||||
self.rawValue = string
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +108,7 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeStoreAttributeFlags(_ flags: StoreFlags) -> Int {
|
||||
let silentString = flags.silent ? ".SILENT" : ""
|
||||
return
|
||||
self.writeString("\(flags.operation.rawValue)FLAGS\(silentString) ") +
|
||||
self.writeFlags(flags.flags)
|
||||
self.writeString("\(flags.operation.rawValue)FLAGS\(silentString) ") + self.writeFlags(flags.flags)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeStoreData(_ data: StoreData) -> Int {
|
||||
@@ -124,7 +123,7 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeStoreGmailLabels(_ labels: StoreGmailLabels) -> Int {
|
||||
let silentString = labels.silent ? ".SILENT" : ""
|
||||
return
|
||||
self.writeString("\(labels.operation.rawValue)X-GM-LABELS\(silentString) ") +
|
||||
self.writeGmailLabels(labels.gmailLabels)
|
||||
self.writeString("\(labels.operation.rawValue)X-GM-LABELS\(silentString) ")
|
||||
+ self.writeGmailLabels(labels.gmailLabels)
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ public struct FullAuthenticatedURL: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAuthIMAPURLFull(_ data: FullAuthenticatedURL) -> Int {
|
||||
self.writeAuthenticatedURL(data.networkMessagePath) +
|
||||
self.writeIAuthenticatedURL(data.authenticatedURL)
|
||||
self.writeAuthenticatedURL(data.networkMessagePath) + self.writeIAuthenticatedURL(data.authenticatedURL)
|
||||
}
|
||||
}
|
||||
@@ -86,9 +86,7 @@ public struct FullTime: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeFullDateTime(_ data: FullDateTime) -> Int {
|
||||
self.writeFullDate(data.date) +
|
||||
self.writeString("T") +
|
||||
self.writeFullTime(data.time)
|
||||
self.writeFullDate(data.date) + self.writeString("T") + self.writeFullTime(data.time)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeFullDate(_ data: FullDate) -> Int {
|
||||
@@ -102,18 +100,17 @@ extension EncodeBuffer {
|
||||
let hour = self.padInteger(data.hour, minimum: 2)
|
||||
let minute = self.padInteger(data.minute, minimum: 2)
|
||||
let second = self.padInteger(data.second, minimum: 2)
|
||||
return self.writeString("\(hour):\(minute):\(second)") +
|
||||
self.writeIfExists(data.fraction) { fraction in
|
||||
return self.writeString("\(hour):\(minute):\(second)")
|
||||
+ self.writeIfExists(data.fraction) { fraction in
|
||||
self.writeString(".\(fraction)")
|
||||
}
|
||||
}
|
||||
|
||||
func padInteger(_ int: Int, minimum: Int) -> String {
|
||||
let short = "\(int)"
|
||||
if short.count < minimum {
|
||||
return String(repeating: "0", count: (minimum - short.count)) + short
|
||||
} else {
|
||||
guard short.count < minimum else {
|
||||
return short
|
||||
}
|
||||
return String(repeating: "0", count: (minimum - short.count)) + short
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,14 @@ extension EncodeBuffer {
|
||||
}
|
||||
return self.withoutLoggingMode { buffer in
|
||||
buffer.writeOrderedDictionary(values) { (e, buffer) in
|
||||
buffer.writeIMAPString(e.key) +
|
||||
buffer.writeSpace() +
|
||||
buffer.writeNString(e.value)
|
||||
buffer.writeIMAPString(e.key) + buffer.writeSpace() + buffer.writeNString(e.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeIDResponse(_ response: OrderedDictionary<String, String?>) -> Int {
|
||||
self.withoutLoggingMode {
|
||||
$0.writeString("ID ") +
|
||||
$0.writeIDParameters(response)
|
||||
$0.writeString("ID ") + $0.writeIDParameters(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,8 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeIMAPServer(_ server: IMAPServer) -> Int {
|
||||
self.writeIfExists(server.userAuthenticationMechanism) { authMechanism in
|
||||
self.writeUserAuthenticationMechanism(authMechanism) + self.writeString("@")
|
||||
} +
|
||||
self.writeString("\(server.host)") +
|
||||
self.writeIfExists(server.port) { port in
|
||||
} + self.writeString("\(server.host)")
|
||||
+ self.writeIfExists(server.port) { port in
|
||||
self.writeString(":\(port)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,8 @@ public struct IMAPURL: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeIMAPURL(_ url: IMAPURL) -> Int {
|
||||
self.writeString("imap://") +
|
||||
self.writeIMAPServer(url.server) +
|
||||
self.writeString("/") +
|
||||
self.writeIfExists(url.command) { command in
|
||||
self.writeString("imap://") + self.writeIMAPServer(url.server) + self.writeString("/")
|
||||
+ self.writeIfExists(url.command) { command in
|
||||
self.writeURLCommand(command)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ public enum IMAPURLAuthenticationMechanism: Hashable, Sendable {
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeIMAPURLAuthenticationMechanism(_ data: IMAPURLAuthenticationMechanism) -> Int {
|
||||
@discardableResult mutating func writeIMAPURLAuthenticationMechanism(_ data: IMAPURLAuthenticationMechanism) -> Int
|
||||
{
|
||||
switch data {
|
||||
case .any:
|
||||
return self.writeString(";AUTH=*")
|
||||
|
||||
@@ -34,11 +34,10 @@ public struct InitialResponse: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeInitialResponse(_ resp: InitialResponse) -> Int {
|
||||
if resp.data.readableBytes == 0 {
|
||||
return self.writeString("=")
|
||||
} else {
|
||||
guard resp.data.readableBytes == 0 else {
|
||||
let encoded = Base64.encodeBytes(bytes: resp.data.readableBytesView)
|
||||
return self.writeBytes(encoded)
|
||||
}
|
||||
return self.writeString("=")
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,11 @@ import struct NIO.ByteBuffer
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeListReturnOptions(_ options: [ReturnOption]) -> Int {
|
||||
self.writeString("RETURN ") +
|
||||
self.writeString("(") +
|
||||
self.write(if: options.count >= 1) {
|
||||
self.writeString("RETURN ") + self.writeString("(")
|
||||
+ self.write(if: options.count >= 1) {
|
||||
self.writeArray(options, parenthesis: false) { (option, self) in
|
||||
self.writeReturnOption(option)
|
||||
}
|
||||
} +
|
||||
self.writeString(")")
|
||||
} + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,6 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeListSelectBaseOptionQuoted(_ option: ListSelectBaseOption) -> Int {
|
||||
self.writeString("\"") +
|
||||
self.writeListSelectBaseOption(option) +
|
||||
self.writeString("\"")
|
||||
self.writeString("\"") + self.writeListSelectBaseOption(option) + self.writeString("\"")
|
||||
}
|
||||
}
|
||||
@@ -71,14 +71,11 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeListSelectOptions(_ options: ListSelectOptions?) -> Int {
|
||||
self.writeString("(") +
|
||||
self.writeIfExists(options) { (optionsData) -> Int in
|
||||
self.writeString("(")
|
||||
+ self.writeIfExists(options) { (optionsData) -> Int in
|
||||
self.writeArray(optionsData.options, separator: "", parenthesis: false) { (option, self) -> Int in
|
||||
self.writeListSelectOption(option) +
|
||||
self.writeSpace()
|
||||
} +
|
||||
self.writeListSelectBaseOption(optionsData.baseOption)
|
||||
} +
|
||||
self.writeString(")")
|
||||
self.writeListSelectOption(option) + self.writeSpace()
|
||||
} + self.writeListSelectBaseOption(optionsData.baseOption)
|
||||
} + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -129,8 +129,8 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMailboxOptions(_ option: [MailboxAttribute]) -> Int {
|
||||
self.writeString("STATUS ") +
|
||||
self.writeArray(option) { (att, self) in
|
||||
self.writeString("STATUS ")
|
||||
+ self.writeArray(option) { (att, self) in
|
||||
self.writeMailboxAttribute(att)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,15 +70,12 @@ extension MailboxData {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeMailboxDataSearchSort(_ data: MailboxData.SearchSort?) -> Int {
|
||||
self.writeString("SEARCH") +
|
||||
self.writeIfExists(data) { (data) -> Int in
|
||||
self.writeString("SEARCH")
|
||||
+ self.writeIfExists(data) { (data) -> Int in
|
||||
self.writeArray(data.identifiers, prefix: " ", parenthesis: false) { (element, buffer) -> Int in
|
||||
buffer.writeString("\(element)")
|
||||
} +
|
||||
self.writeSpace() +
|
||||
self.writeString("(MODSEQ ") +
|
||||
self.writeModificationSequenceValue(data.modificationSequence) +
|
||||
self.writeString(")")
|
||||
} + self.writeSpace() + self.writeString("(MODSEQ ")
|
||||
+ self.writeModificationSequenceValue(data.modificationSequence) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,38 +104,33 @@ extension EncodeBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeMailboxData_search(_ list: [UnknownMessageIdentifier], modificationSequence: ModificationSequenceValue?) -> Int {
|
||||
self.writeString("SEARCH") +
|
||||
self.writeArray(list, prefix: " ", separator: " ", parenthesis: false) { (id, buffer) -> Int in
|
||||
private mutating func writeMailboxData_search(
|
||||
_ list: [UnknownMessageIdentifier],
|
||||
modificationSequence: ModificationSequenceValue?
|
||||
) -> Int {
|
||||
self.writeString("SEARCH")
|
||||
+ self.writeArray(list, prefix: " ", separator: " ", parenthesis: false) { (id, buffer) -> Int in
|
||||
buffer.writeMessageIdentifier(id)
|
||||
} +
|
||||
self.writeIfExists(modificationSequence) { value -> Int in
|
||||
self.writeString(" (MODSEQ ") +
|
||||
self.writeModificationSequenceValue(value) +
|
||||
self.writeString(")")
|
||||
}
|
||||
+ self.writeIfExists(modificationSequence) { value -> Int in
|
||||
self.writeString(" (MODSEQ ") + self.writeModificationSequenceValue(value) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func writeMailboxData_flags(_ flags: [Flag]) -> Int {
|
||||
self.writeString("FLAGS ") +
|
||||
self.writeFlags(flags)
|
||||
self.writeString("FLAGS ") + self.writeFlags(flags)
|
||||
}
|
||||
|
||||
private mutating func writeMailboxData_list(_ list: MailboxInfo) -> Int {
|
||||
self.writeString("LIST ") +
|
||||
self.writeMailboxInfo(list)
|
||||
self.writeString("LIST ") + self.writeMailboxInfo(list)
|
||||
}
|
||||
|
||||
private mutating func writeMailboxData_lsub(_ list: MailboxInfo) -> Int {
|
||||
self.writeString("LSUB ") +
|
||||
self.writeMailboxInfo(list)
|
||||
self.writeString("LSUB ") + self.writeMailboxInfo(list)
|
||||
}
|
||||
|
||||
private mutating func writeMailboxData_status(mailbox: MailboxName, status: MailboxStatus) -> Int {
|
||||
self.writeString("STATUS ") +
|
||||
self.writeMailbox(mailbox) +
|
||||
self.writeString(" (") +
|
||||
self.writeMailboxStatus(status) +
|
||||
self.writeString(")")
|
||||
self.writeString("STATUS ") + self.writeMailbox(mailbox) + self.writeString(" (")
|
||||
+ self.writeMailboxStatus(status) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -49,22 +49,25 @@ public indirect enum EmailAddressListElement: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeEmailAddressGroup(_ group: EmailAddressGroup) -> Int {
|
||||
self.writeEmailAddress(.init(
|
||||
personName: nil,
|
||||
sourceRoot: group.sourceRoot,
|
||||
mailbox: group.groupName,
|
||||
host: nil
|
||||
)
|
||||
) +
|
||||
self.writeArray(group.children, prefix: "", separator: "", suffix: "", parenthesis: false) { (child, self) in
|
||||
self.writeEmailAddressOrGroup(child)
|
||||
} +
|
||||
self.writeEmailAddress(.init(
|
||||
self.writeEmailAddress(
|
||||
.init(
|
||||
personName: nil,
|
||||
sourceRoot: group.sourceRoot,
|
||||
mailbox: nil,
|
||||
mailbox: group.groupName,
|
||||
host: nil
|
||||
)
|
||||
)
|
||||
+ self.writeArray(group.children, prefix: "", separator: "", suffix: "", parenthesis: false) {
|
||||
(child, self) in
|
||||
self.writeEmailAddressOrGroup(child)
|
||||
}
|
||||
+ self.writeEmailAddress(
|
||||
.init(
|
||||
personName: nil,
|
||||
sourceRoot: group.sourceRoot,
|
||||
mailbox: nil,
|
||||
host: nil
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,11 @@ public struct MailboxInfo: Hashable, Sendable {
|
||||
/// - parameter attributes: An array of mailbox attributes.
|
||||
/// - parameter path: The mailbox path.
|
||||
/// - parameter extensions: A catch-all to support any attributes added in future extensions.
|
||||
public init(attributes: [Attribute] = [], path: MailboxPath, extensions: OrderedDictionary<ByteBuffer, ParameterValue>) {
|
||||
public init(
|
||||
attributes: [Attribute] = [],
|
||||
path: MailboxPath,
|
||||
extensions: OrderedDictionary<ByteBuffer, ParameterValue>
|
||||
) {
|
||||
self.attributes = attributes
|
||||
self.path = path
|
||||
self.extensions = extensions
|
||||
@@ -111,14 +115,11 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMailboxInfo(_ list: MailboxInfo) -> Int {
|
||||
self.writeString("(") +
|
||||
self.writeIfExists(list.attributes) { (flags) -> Int in
|
||||
self.writeString("(")
|
||||
+ self.writeIfExists(list.attributes) { (flags) -> Int in
|
||||
self.writeMailboxListFlags(flags)
|
||||
} +
|
||||
self.writeString(") ") +
|
||||
self.writeMailboxPathSeparator(list.path.pathSeparator) +
|
||||
self.writeSpace() +
|
||||
self.writeMailbox(list.path.name)
|
||||
} + self.writeString(") ") + self.writeMailboxPathSeparator(list.path.pathSeparator) + self.writeSpace()
|
||||
+ self.writeMailbox(list.path.name)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMailboxListFlags(_ flags: [MailboxInfo.Attribute]) -> Int {
|
||||
|
||||
@@ -211,9 +211,8 @@ public struct MailboxName: Sendable {
|
||||
/// `true` if the internal storage reads "INBOX"
|
||||
/// otherwise `false`
|
||||
public var isInbox: Bool {
|
||||
self.hashValue == MailboxName.inboxHashValue &&
|
||||
self.bytes.count == 5 &&
|
||||
self.bytes.map { $0 & 0xDF }.elementsEqual("INBOX".utf8)
|
||||
self.hashValue == MailboxName.inboxHashValue && self.bytes.count == 5
|
||||
&& self.bytes.map { $0 & 0xDF }.elementsEqual("INBOX".utf8)
|
||||
}
|
||||
|
||||
private static let inboxHashValue: Int = MailboxName.inbox.hashValue
|
||||
|
||||
@@ -34,8 +34,8 @@ public struct MailboxUIDValidity: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeEncodedMailboxUIDValidity(_ ref: MailboxUIDValidity) -> Int {
|
||||
self.writeEncodedMailbox(ref.encodedMailbox) +
|
||||
self.writeIfExists(ref.uidValidity) { value in
|
||||
self.writeEncodedMailbox(ref.encodedMailbox)
|
||||
+ self.writeIfExists(ref.uidValidity) { value in
|
||||
self.writeString(";UIDVALIDITY=") + self.writeUIDValidity(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,9 @@ public struct MechanismBase64: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeMechanismBase64(_ data: MechanismBase64) -> Int {
|
||||
self.writeURLAuthenticationMechanism(data.mechanism) +
|
||||
self.writeIfExists(data.base64) { base64 in
|
||||
self.writeString("=") +
|
||||
self.writeBuffer(&base64)
|
||||
self.writeURLAuthenticationMechanism(data.mechanism)
|
||||
+ self.writeIfExists(data.base64) { base64 in
|
||||
self.writeString("=") + self.writeBuffer(&base64)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,9 +163,7 @@ extension BodyStructure {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeMediaType(_ media: Media.MediaType) -> Int {
|
||||
self.writeMediaTopLevelType(media.topLevel) +
|
||||
self.writeSpace() +
|
||||
self.writeMediaSubtype(media.sub)
|
||||
self.writeMediaTopLevelType(media.topLevel) + self.writeSpace() + self.writeMediaSubtype(media.sub)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMediaTopLevelType(_ type: Media.TopLevelType) -> Int {
|
||||
@@ -173,8 +171,6 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMediaSubtype(_ type: Media.Subtype) -> Int {
|
||||
self.writeString("\"") +
|
||||
self.writeString(String(type).uppercased()) +
|
||||
self.writeString("\"")
|
||||
self.writeString("\"") + self.writeString(String(type).uppercased()) + self.writeString("\"")
|
||||
}
|
||||
}
|
||||
@@ -56,11 +56,10 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeGmailLabel(_ label: GmailLabel) -> Int {
|
||||
if label.buffer.getInteger(at: label.buffer.readerIndex) == UInt8(ascii: "\\") {
|
||||
var stringValue = label.buffer
|
||||
return self.writeBuffer(&stringValue)
|
||||
} else {
|
||||
guard label.buffer.getInteger(at: label.buffer.readerIndex) == UInt8(ascii: "\\") else {
|
||||
return self.writeIMAPString(label.buffer)
|
||||
}
|
||||
var stringValue = label.buffer
|
||||
return self.writeBuffer(&stringValue)
|
||||
}
|
||||
}
|
||||
@@ -114,78 +114,70 @@ extension EncodeBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_binarySize(section: SectionSpecifier.Part, number: Int) -> Int {
|
||||
self.writeString("BINARY.SIZE") +
|
||||
self.writeSectionBinary(section) +
|
||||
self.writeString(" \(number)")
|
||||
@discardableResult mutating func writeMessageAttribute_binarySize(
|
||||
section: SectionSpecifier.Part,
|
||||
number: Int
|
||||
) -> Int {
|
||||
self.writeString("BINARY.SIZE") + self.writeSectionBinary(section) + self.writeString(" \(number)")
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttributeFlags(_ atts: [Flag]) -> Int {
|
||||
self.writeString("FLAGS ") +
|
||||
self.writeArray(atts) { (element, self) in
|
||||
self.writeString("FLAGS ")
|
||||
+ self.writeArray(atts) { (element, self) in
|
||||
self.writeFlag(element)
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttributeNilBody(_ kind: StreamingKind) -> Int {
|
||||
self.writeStreamingKind(kind) +
|
||||
self.writeSpace() +
|
||||
self.writeNil()
|
||||
self.writeStreamingKind(kind) + self.writeSpace() + self.writeNil()
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_envelope(_ env: Envelope) -> Int {
|
||||
self.writeString("ENVELOPE ") +
|
||||
self.writeEnvelope(env)
|
||||
self.writeString("ENVELOPE ") + self.writeEnvelope(env)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_internalDate(_ date: ServerMessageDate) -> Int {
|
||||
self.writeString("INTERNALDATE ") +
|
||||
self.writeInternalDate(date)
|
||||
self.writeString("INTERNALDATE ") + self.writeInternalDate(date)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_rfc822(_ string: ByteBuffer?) -> Int {
|
||||
self.writeString("RFC822") +
|
||||
self.writeSpace() +
|
||||
self.writeNString(string)
|
||||
self.writeString("RFC822") + self.writeSpace() + self.writeNString(string)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_rfc822Text(_ string: ByteBuffer?) -> Int {
|
||||
self.writeString("RFC822.TEXT") +
|
||||
self.writeSpace() +
|
||||
self.writeNString(string)
|
||||
self.writeString("RFC822.TEXT") + self.writeSpace() + self.writeNString(string)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_rfc822Header(_ string: ByteBuffer?) -> Int {
|
||||
self.writeString("RFC822.HEADER") +
|
||||
self.writeSpace() +
|
||||
self.writeNString(string)
|
||||
self.writeString("RFC822.HEADER") + self.writeSpace() + self.writeNString(string)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_body(_ body: MessageAttribute.BodyStructure, hasExtensionData: Bool) -> Int {
|
||||
self.writeString("BODY") +
|
||||
self.write(if: hasExtensionData) { () -> Int in
|
||||
@discardableResult mutating func writeMessageAttribute_body(
|
||||
_ body: MessageAttribute.BodyStructure,
|
||||
hasExtensionData: Bool
|
||||
) -> Int {
|
||||
self.writeString("BODY")
|
||||
+ self.write(if: hasExtensionData) { () -> Int in
|
||||
self.writeString("STRUCTURE")
|
||||
} +
|
||||
self.writeSpace() +
|
||||
self.writeBody(body)
|
||||
} + self.writeSpace() + self.writeBody(body)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_bodySection(_ section: SectionSpecifier?, number: Int?, string: ByteBuffer?) -> Int {
|
||||
self.writeString("BODY") +
|
||||
self.writeSection(section) +
|
||||
self.writeIfExists(number) { (number) -> Int in
|
||||
@discardableResult mutating func writeMessageAttribute_bodySection(
|
||||
_ section: SectionSpecifier?,
|
||||
number: Int?,
|
||||
string: ByteBuffer?
|
||||
) -> Int {
|
||||
self.writeString("BODY") + self.writeSection(section)
|
||||
+ self.writeIfExists(number) { (number) -> Int in
|
||||
self.writeString("<\(number)>")
|
||||
} +
|
||||
self.writeSpace() +
|
||||
self.writeNString(string)
|
||||
} + self.writeSpace() + self.writeNString(string)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_bodySectionText(number: Int?, size: Int) -> Int {
|
||||
self.writeString("BODY[TEXT]") +
|
||||
self.writeIfExists(number) { (number) -> Int in
|
||||
self.writeString("BODY[TEXT]")
|
||||
+ self.writeIfExists(number) { (number) -> Int in
|
||||
self.writeString("<\(number)>")
|
||||
} +
|
||||
self.writeString(" {\(size)}\r\n")
|
||||
} + self.writeString(" {\(size)}\r\n")
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_gmailMessageID(_ id: UInt64) -> Int {
|
||||
@@ -197,16 +189,13 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_gmailLabels(_ labels: [GmailLabel]) -> Int {
|
||||
self.writeString("X-GM-LABELS") +
|
||||
self.writeSpace() +
|
||||
self.writeArray(labels) { label, buffer in
|
||||
self.writeString("X-GM-LABELS") + self.writeSpace()
|
||||
+ self.writeArray(labels) { label, buffer in
|
||||
buffer.writeGmailLabel(label)
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMessageAttribute_preview(_ previewText: PreviewText?) -> Int {
|
||||
self.writeString("PREVIEW") +
|
||||
self.writeSpace() +
|
||||
self.writeNString(previewText.map { String($0) })
|
||||
self.writeString("PREVIEW") + self.writeSpace() + self.writeNString(previewText.map { String($0) })
|
||||
}
|
||||
}
|
||||
@@ -51,13 +51,13 @@ extension EncodeBuffer {
|
||||
case .vanishedEarlier(let set):
|
||||
return self.writeString("VANISHED (EARLIER) ") + self.writeUIDSet(set)
|
||||
case .generateAuthorizedURL(let array):
|
||||
return self.writeString("GENURLAUTH") +
|
||||
self.writeArray(array, prefix: " ", parenthesis: false) { data, buffer in
|
||||
return self.writeString("GENURLAUTH")
|
||||
+ self.writeArray(array, prefix: " ", parenthesis: false) { data, buffer in
|
||||
buffer.writeIMAPString(data)
|
||||
}
|
||||
case .urlFetch(let array):
|
||||
return self.writeString("URLFETCH") +
|
||||
self.writeArray(array) { data, buffer in
|
||||
return self.writeString("URLFETCH")
|
||||
+ self.writeArray(array) { data, buffer in
|
||||
buffer.writeURLFetchData(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,12 @@ public struct MessagePath: Hashable, Sendable {
|
||||
/// - parameter iUID: The UID of the message in question.
|
||||
/// - parameter IMAPURLSection: An optional section of the message in question.
|
||||
/// - parameter iPartial: A specific range of bytes of the message/section in question.
|
||||
public init(mailboxReference: MailboxUIDValidity, iUID: IUID, section: URLMessageSection? = nil, range: MessagePath.ByteRange? = nil) {
|
||||
public init(
|
||||
mailboxReference: MailboxUIDValidity,
|
||||
iUID: IUID,
|
||||
section: URLMessageSection? = nil,
|
||||
range: MessagePath.ByteRange? = nil
|
||||
) {
|
||||
self.mailboxReference = mailboxReference
|
||||
self.iUID = iUID
|
||||
self.section = section
|
||||
@@ -43,12 +48,11 @@ public struct MessagePath: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeMessagePath(_ data: MessagePath) -> Int {
|
||||
self.writeEncodedMailboxUIDValidity(data.mailboxReference) +
|
||||
self.writeIUID(data.iUID) +
|
||||
self.writeIfExists(data.section) { section in
|
||||
self.writeEncodedMailboxUIDValidity(data.mailboxReference) + self.writeIUID(data.iUID)
|
||||
+ self.writeIfExists(data.section) { section in
|
||||
self.writeURLMessageSection(section)
|
||||
} +
|
||||
self.writeIfExists(data.range) { partial in
|
||||
}
|
||||
+ self.writeIfExists(data.range) { partial in
|
||||
self.writeMessagePathByteRange(partial)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,11 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeMetadataResponse(_ resp: MetadataResponse) -> Int {
|
||||
switch resp {
|
||||
case .values(values: let values, mailbox: let mailbox):
|
||||
return self.writeString("METADATA ") +
|
||||
self.writeMailbox(mailbox) +
|
||||
self.writeSpace() +
|
||||
self.writeEntryValues(values)
|
||||
return self.writeString("METADATA ") + self.writeMailbox(mailbox) + self.writeSpace()
|
||||
+ self.writeEntryValues(values)
|
||||
case .list(list: let list, mailbox: let mailbox):
|
||||
return self.writeString("METADATA ") +
|
||||
self.writeMailbox(mailbox) +
|
||||
self.writeSpace() +
|
||||
self.writeEntryList(list)
|
||||
return self.writeString("METADATA ") + self.writeMailbox(mailbox) + self.writeSpace()
|
||||
+ self.writeEntryList(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,16 @@ import struct NIO.ByteBuffer
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeNString(_ string: ByteBuffer?) -> Int {
|
||||
if let string = string {
|
||||
return self.writeIMAPString(string)
|
||||
} else {
|
||||
guard let string = string else {
|
||||
return self.writeNil()
|
||||
}
|
||||
return self.writeIMAPString(string)
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeNString(_ string: String?) -> Int {
|
||||
if let string = string {
|
||||
return self.writeIMAPString(string)
|
||||
} else {
|
||||
guard let string = string else {
|
||||
return self.writeNil()
|
||||
}
|
||||
return self.writeIMAPString(string)
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,11 @@ public struct NamespaceDescription: Hashable, Sendable {
|
||||
/// - parameter string: The full namespace string.
|
||||
/// - parameter char: A hierarchy delimiter.
|
||||
/// - parameter responseExtensions: A catch-all to provide support fo future extensions.
|
||||
public init(string: ByteBuffer, char: Character? = nil, responseExtensions: OrderedDictionary<ByteBuffer, [ByteBuffer]>) {
|
||||
public init(
|
||||
string: ByteBuffer,
|
||||
char: Character? = nil,
|
||||
responseExtensions: OrderedDictionary<ByteBuffer, [ByteBuffer]>
|
||||
) {
|
||||
self.string = string
|
||||
self.delimiter = char
|
||||
self.responseExtensions = responseExtensions
|
||||
|
||||
@@ -30,7 +30,11 @@ public struct NamespaceResponse: Hashable, Sendable {
|
||||
/// - parameter userNamespace: Descriptions of the current user's namespaces.
|
||||
/// - parameter otherUserNamespace: Descriptions of other user's namespaces.
|
||||
/// - parameter sharedNamespace: Descriptions of shared namespaces.
|
||||
public init(userNamespace: [NamespaceDescription], otherUserNamespace: [NamespaceDescription], sharedNamespace: [NamespaceDescription]) {
|
||||
public init(
|
||||
userNamespace: [NamespaceDescription],
|
||||
otherUserNamespace: [NamespaceDescription],
|
||||
sharedNamespace: [NamespaceDescription]
|
||||
) {
|
||||
self.userNamespace = userNamespace
|
||||
self.otherUserNamespace = otherUserNamespace
|
||||
self.sharedNamespace = sharedNamespace
|
||||
@@ -41,11 +45,8 @@ public struct NamespaceResponse: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeNamespaceResponse(_ response: NamespaceResponse) -> Int {
|
||||
self.writeString("NAMESPACE ") +
|
||||
self.writeNamespace(response.userNamespace) +
|
||||
self.writeSpace() +
|
||||
self.writeNamespace(response.otherUserNamespace) +
|
||||
self.writeSpace() +
|
||||
self.writeNamespace(response.sharedNamespace)
|
||||
self.writeString("NAMESPACE ") + self.writeNamespace(response.userNamespace) + self.writeSpace()
|
||||
+ self.writeNamespace(response.otherUserNamespace) + self.writeSpace()
|
||||
+ self.writeNamespace(response.sharedNamespace)
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,13 @@ import struct OrderedCollections.OrderedDictionary
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeNamespaceResponseExtensions(_ extensions: OrderedDictionary<ByteBuffer, [ByteBuffer]>) -> Int {
|
||||
@discardableResult mutating func writeNamespaceResponseExtensions(
|
||||
_ extensions: OrderedDictionary<ByteBuffer, [ByteBuffer]>
|
||||
) -> Int {
|
||||
extensions.reduce(into: 0) { (res, ext) in
|
||||
res += self.writeSpace() +
|
||||
self.writeIMAPString(ext.0) +
|
||||
self.writeSpace() +
|
||||
self.writeArray(ext.1) { (string, self) in
|
||||
res +=
|
||||
self.writeSpace() + self.writeIMAPString(ext.0) + self.writeSpace()
|
||||
+ self.writeArray(ext.1) { (string, self) in
|
||||
self.writeIMAPString(string)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ public struct NetworkMessagePath: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAuthenticatedURL(_ data: NetworkMessagePath) -> Int {
|
||||
self.writeString("imap://") +
|
||||
self.writeIMAPServer(data.server) +
|
||||
self.writeString("/") +
|
||||
self.writeMessagePath(data.messagePath)
|
||||
self.writeString("imap://") + self.writeIMAPServer(data.server) + self.writeString("/")
|
||||
+ self.writeMessagePath(data.messagePath)
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,8 @@ public struct NetworkPath: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeNetworkPath(_ path: NetworkPath) -> Int {
|
||||
self.writeString("//") +
|
||||
self.writeIMAPServer(path.server) +
|
||||
self.writeString("/") +
|
||||
self.writeIfExists(path.command) { command in
|
||||
self.writeString("//") + self.writeIMAPServer(path.server) + self.writeString("/")
|
||||
+ self.writeIfExists(path.command) { command in
|
||||
self.writeURLCommand(command)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ public enum OptionExtensionKind: Hashable, Sendable {
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeOptionExtension(_ option: KeyValue<OptionExtensionKind, OptionValueComp?>) -> Int {
|
||||
@discardableResult mutating func writeOptionExtension(
|
||||
_ option: KeyValue<OptionExtensionKind, OptionValueComp?>
|
||||
) -> Int {
|
||||
var size = 0
|
||||
switch option.key {
|
||||
case .standard(let atom):
|
||||
@@ -43,8 +45,6 @@ extension EncodeBuffer {
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeOptionVendorTag(_ tag: KeyValue<String, String>) -> Int {
|
||||
self.writeString(tag.key) +
|
||||
self.writeString("-") +
|
||||
self.writeString(tag.value)
|
||||
self.writeString(tag.key) + self.writeString("-") + self.writeString(tag.value)
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,7 @@ extension OptionValueComp: ExpressibleByArrayLiteral {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeOptionValue(_ value: OptionValueComp) -> Int {
|
||||
self.writeString("(") +
|
||||
self.writeOptionValueComp(value) +
|
||||
self.writeString(")")
|
||||
self.writeString("(") + self.writeOptionValueComp(value) + self.writeString(")")
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeOptionValueComp(_ option: OptionValueComp) -> Int {
|
||||
|
||||
@@ -34,14 +34,11 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writePartialRange(_ range: PartialRange) -> Int {
|
||||
switch range {
|
||||
case .first(let r):
|
||||
return self.writeSequenceNumberOrWildcard(r.range.lowerBound) +
|
||||
self.writeString(":") +
|
||||
self.writeSequenceNumberOrWildcard(r.range.upperBound)
|
||||
return self.writeSequenceNumberOrWildcard(r.range.lowerBound) + self.writeString(":")
|
||||
+ self.writeSequenceNumberOrWildcard(r.range.upperBound)
|
||||
case .last(let r):
|
||||
return self.writeString("-") +
|
||||
self.writeSequenceNumberOrWildcard(r.range.lowerBound) +
|
||||
self.writeString(":-") +
|
||||
self.writeSequenceNumberOrWildcard(r.range.upperBound)
|
||||
return self.writeString("-") + self.writeSequenceNumberOrWildcard(r.range.lowerBound)
|
||||
+ self.writeString(":-") + self.writeSequenceNumberOrWildcard(r.range.upperBound)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,6 @@ public struct QuotaLimit: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeQuotaLimit(_ quotaLimit: QuotaLimit) -> Int {
|
||||
self.writeAtom(quotaLimit.resourceName) +
|
||||
self.writeSpace() +
|
||||
self.writeString("\(quotaLimit.limit)")
|
||||
self.writeAtom(quotaLimit.resourceName) + self.writeSpace() + self.writeString("\(quotaLimit.limit)")
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,6 @@ public struct QuotaResource: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeQuotaResource(_ quotaDetails: QuotaResource) -> Int {
|
||||
self.writeAtom(quotaDetails.resourceName) +
|
||||
self.writeString(" \(quotaDetails.usage) \(quotaDetails.limit)")
|
||||
self.writeAtom(quotaDetails.resourceName) + self.writeString(" \(quotaDetails.usage) \(quotaDetails.limit)")
|
||||
}
|
||||
}
|
||||
@@ -18,15 +18,12 @@ import struct NIO.ByteBuffer
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeQuotaResponse(quotaRoot: QuotaRoot, resources: [QuotaResource]) -> Int {
|
||||
self.writeString("QUOTA ") +
|
||||
self.writeQuotaRoot(quotaRoot) +
|
||||
self.writeSpace() +
|
||||
self.writeQuotaResources(resources)
|
||||
self.writeString("QUOTA ") + self.writeQuotaRoot(quotaRoot) + self.writeSpace()
|
||||
+ self.writeQuotaResources(resources)
|
||||
}
|
||||
|
||||
mutating func writeQuotaResources(_ resources: [QuotaResource]) -> Int {
|
||||
self.writeString("(") +
|
||||
resources.map { resource in self.writeQuotaResource(resource) }.reduce(0, +) +
|
||||
self.writeString(")")
|
||||
self.writeString("(") + resources.map { resource in self.writeQuotaResource(resource) }.reduce(0, +)
|
||||
+ self.writeString(")")
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,6 @@ import struct NIO.ByteBuffer
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeQuotaRootResponse(mailbox: MailboxName, quotaRoot: QuotaRoot) -> Int {
|
||||
self.writeString("QUOTAROOT ") +
|
||||
self.writeMailbox(mailbox) +
|
||||
self.writeSpace() +
|
||||
self.writeQuotaRoot(quotaRoot)
|
||||
self.writeString("QUOTAROOT ") + self.writeMailbox(mailbox) + self.writeSpace() + self.writeQuotaRoot(quotaRoot)
|
||||
}
|
||||
}
|
||||
@@ -85,12 +85,10 @@ extension ExtendedSearchResponse {
|
||||
returnData.lazy.compactMap { data -> MessageIdentifierSet<UnknownMessageIdentifier>? in
|
||||
guard case .all(.set(let set)) = data else { return nil }
|
||||
return set.set
|
||||
}.first ??
|
||||
returnData.lazy.compactMap {
|
||||
guard case .partial(_, let set) = $0 else { return nil }
|
||||
return set
|
||||
}.first ??
|
||||
MessageIdentifierSet()
|
||||
}.first ?? returnData.lazy.compactMap {
|
||||
guard case .partial(_, let set) = $0 else { return nil }
|
||||
return set
|
||||
}.first ?? MessageIdentifierSet()
|
||||
}
|
||||
|
||||
/// Returns the count value in the response.
|
||||
@@ -154,17 +152,17 @@ extension ExtendedSearchResponse {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeExtendedSearchResponse(_ response: ExtendedSearchResponse) -> Int {
|
||||
self.writeString("ESEARCH") +
|
||||
self.writeIfExists(response.correlator) { (correlator) -> Int in
|
||||
self.writeString("ESEARCH")
|
||||
+ self.writeIfExists(response.correlator) { (correlator) -> Int in
|
||||
self.writeSearchCorrelator(correlator)
|
||||
} +
|
||||
self.write(if: response.kind == .uid) {
|
||||
}
|
||||
+ self.write(if: response.kind == .uid) {
|
||||
self.writeString(" UID")
|
||||
} +
|
||||
self.write(if: response.returnData.count > 0) {
|
||||
}
|
||||
+ self.write(if: response.returnData.count > 0) {
|
||||
self.writeSpace()
|
||||
} +
|
||||
self.writeArray(response.returnData, parenthesis: false) { (data, self) in
|
||||
}
|
||||
+ self.writeArray(response.returnData, parenthesis: false) { (data, self) in
|
||||
self.writeSearchReturnData(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public struct ResponseCodeAppend: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeResponseCodeAppend(_ data: ResponseCodeAppend) -> Int {
|
||||
self.writeString("APPENDUID \(data.uidValidity.rawValue) ") +
|
||||
self.writeUIDSet(data.uids)
|
||||
self.writeString("APPENDUID \(data.uidValidity.rawValue) ") + self.writeUIDSet(data.uids)
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,8 @@ public struct ResponseCodeCopy: Hashable, Sendable {
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeResponseCodeCopy(_ data: ResponseCodeCopy) -> Int {
|
||||
self.writeString("COPYUID \(data.destinationUIDValidity.rawValue) ") +
|
||||
self.writeUIDRangeArray(data.sourceUIDs) +
|
||||
self.writeSpace() +
|
||||
self.writeUIDRangeArray(data.destinationUIDs)
|
||||
self.writeString("COPYUID \(data.destinationUIDValidity.rawValue) ") + self.writeUIDRangeArray(data.sourceUIDs)
|
||||
+ self.writeSpace() + self.writeUIDRangeArray(data.destinationUIDs)
|
||||
}
|
||||
|
||||
@discardableResult private mutating func writeUIDRangeArray(_ array: [UIDRange]) -> Int {
|
||||
|
||||
Loaded 100 of 306 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user