Seperate module (#61)

This commit is contained in:
David Evans authored and GitHub committed 2020-04-20 12:41:39 +01:00
1 parent 4036c750ea
commit 19ecdb9576
293 files changed
+568 -440

No files matched your search

+11 -3
View File
@@ -4,9 +4,9 @@
import PackageDescription
let package = Package(
name: "swift-nio-imap",
name: "swift-nio-email",
products: [
.library(name: "NIOIMAP", targets: ["NIOIMAP"])
.library(name: "NIOIMAP", targets: ["NIOIMAP", "NIOIMAPCore"])
], dependencies: [
.package(url: "https://github.com/apple/swift-nio", from: "2.16.0"),
.package(url: "https://github.com/apple/swift-nio-extras", from: "1.4.0"),
@@ -16,6 +16,10 @@ let package = Package(
targets: [
.target(
name: "NIOIMAP",
dependencies: ["NIOIMAPCore"]
),
.target(
name: "NIOIMAPCore",
dependencies: ["NIO"]
),
.target(
@@ -32,7 +36,11 @@ let package = Package(
),
.testTarget(
name: "NIOIMAPTests",
dependencies: ["NIOIMAP", "NIO", "NIOTestUtils"]
dependencies: ["NIOIMAP", "NIOIMAPCore", "NIO", "NIOTestUtils"]
),
.testTarget(
name: "NIOIMAPCoreTests",
dependencies: ["NIOIMAPCore", "NIO", "NIOTestUtils"]
),
.testTarget(
name: "CLILibTests",
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
import NIO
import NIOIMAPCore
extension NIOIMAP {
@@ -45,7 +46,7 @@ extension NIOIMAP {
self.ok = context.channel.allocator.buffer(capacity: 2)
self.ok!.writeString("OK")
}
let continuation = Response.continuationRequest(.responseText(.init(code: nil, text: self.ok!)))
let continuation = Response.continuationRequest(.responseText(.code(nil, text: self.ok!)))
// HACK: We shouldn't just emit those here, we should probably not be a B2MD anymore.
context.writeAndFlush(NIOAny(continuation), promise: nil)
}
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
import NIO
import NIOIMAPCore
extension NIOIMAP {
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
import NIO
import NIOIMAPCore
extension NIOIMAP {
+1 -3
View File
@@ -12,6 +12,4 @@
//
//===----------------------------------------------------------------------===//
public enum NIOIMAP {
}
@@ -1,149 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 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
//
//===----------------------------------------------------------------------===//
import NIO
internal struct SynchronizingLiteralParser {
private var offset = 0
private var synchronisingLiterals = 0
private var state = State.waitingForCompleteLine
private enum State: Equatable {
case waitingForCompleteLine
case waitingForLiteralBytes(Int)
}
private enum LineFragmentType {
case completeLine
case synchronisingLiteral(Int)
case nonSynchronisingLiteral(Int)
}
private static func reverseParseTrailingNewlines(_ buffer: inout ByteBuffer) throws {
switch (buffer.readableBytesView.reversed().dropFirst().first, buffer.readableBytesView.last) {
case (UInt8(ascii: "\r"), UInt8(ascii: "\n")):
buffer.moveWriterIndex(to: buffer.writerIndex - 2)
case (_, UInt8(ascii: "\n")):
buffer.moveWriterIndex(to: buffer.writerIndex - 1)
default:
throw ParserError()
}
}
private static func reverseParseIf(_ char: UInt8, _ buffer: inout ByteBuffer) throws -> Bool {
switch buffer.readableBytesView.last {
case .some(char):
buffer.moveWriterIndex(to: buffer.writerIndex - 1)
return true
case .some(_):
return false
case .none:
throw ParserError(hint: "whilst looking for \(char), found no bytes")
}
}
private static func reverseParseNumber(_ buffer: inout ByteBuffer) throws -> Int {
var current = 0
var magnitude = 1
while true {
switch buffer.readableBytesView.last {
case .some(let digit) where (UInt8(ascii: "0") ... UInt8(ascii: "9")).contains(digit):
current += (magnitude * Int(digit - UInt8(ascii: "0")))
magnitude *= 10
buffer.moveWriterIndex(to: buffer.writerIndex - 1)
case .some(_):
if magnitude == 1 {
throw ParserError()
} else {
return current
}
case .none:
throw ParserError()
}
}
}
private static func lineFragmentType(_ fragment: ByteBufferView) throws -> LineFragmentType {
var fragment = ByteBuffer(fragment)
assert(fragment.readableBytes > 0, "\(fragment)")
try reverseParseTrailingNewlines(&fragment)
guard fragment.readableBytes > 0 else {
return .completeLine // this is just an empty line
}
if try reverseParseIf(UInt8(ascii: "}"), &fragment) {
if try reverseParseIf(UInt8(ascii: "+"), &fragment) || reverseParseIf(UInt8(ascii: "-"), &fragment) {
let number = try reverseParseNumber(&fragment)
return .nonSynchronisingLiteral(number)
} else {
let number = try reverseParseNumber(&fragment)
return .synchronisingLiteral(number)
}
} else {
return .completeLine
}
}
internal struct FramingResult {
internal var maximumValidBytes: Int
internal var synchronizingLiteralCount: Int
}
internal mutating func parseContinuationsNecessary(_ buffer: ByteBuffer) throws -> FramingResult {
var lastOffset = self.offset
repeat {
switch self.state {
case .waitingForCompleteLine:
if let newlineIndex = buffer.readableBytesView[(buffer.readableBytesView.startIndex + self.offset)...].firstIndex(of: UInt8(ascii: "\n")) {
self.offset = newlineIndex - buffer.readableBytesView.startIndex + 1
switch try Self.lineFragmentType(buffer.readableBytesView[...newlineIndex]) {
case .synchronisingLiteral(let length):
self.synchronisingLiterals += 1
fallthrough
case .nonSynchronisingLiteral(let length):
if length > 0 {
self.state = .waitingForLiteralBytes(length)
} else {
assert(self.state == .waitingForCompleteLine)
}
case .completeLine:
() // nothing to do
}
}
case .waitingForLiteralBytes(let literalBytesLeft):
let remainingBytes = buffer.readableBytesView.endIndex - (buffer.readableBytesView.startIndex + self.offset)
if remainingBytes >= literalBytesLeft {
self.state = .waitingForCompleteLine
self.offset += literalBytesLeft
} else {
let newLiteralBytesLeft = literalBytesLeft - remainingBytes
assert(newLiteralBytesLeft > 0, "\(newLiteralBytesLeft)")
self.state = .waitingForLiteralBytes(newLiteralBytesLeft)
self.offset += remainingBytes
}
}
guard lastOffset < self.offset && self.offset < buffer.readableBytesView.endIndex else {
let synchronisingLiterals = self.synchronisingLiterals
self.synchronisingLiterals = 0
return FramingResult(maximumValidBytes: self.offset,
synchronizingLiteralCount: synchronisingLiterals)
}
lastOffset = self.offset
} while true
}
internal mutating func consumed(_ numberOfBytes: Int) {
precondition(self.offset >= numberOfBytes, "offset=\(self.offset), numberOfBytes consumed=\(numberOfBytes)")
self.offset -= numberOfBytes
}
}
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import NIO
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Body {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Date {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Date {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Date {
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import NIO
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import NIO
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// Mark: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Flag {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,8 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
import struct NIO.ByteBufferView
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Mailbox {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Mailbox {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Mailbox {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Mailbox.List {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Mailbox.List {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Mailbox.List {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Media {
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import NIO
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP.Media {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - NString
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import NIO
extension NIOIMAP.Partial {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
// MARK: - Encoding
extension ByteBuffer {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import NIO
import struct NIO.ByteBuffer
extension NIOIMAP {
Loaded 100 of 293 files, more files were not shown because too many files have changed in this diff. Show more