mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-27 05:04:23 +00:00
Remove initial response (#283)
This commit is contained in:
1 parent
495d5f8c4b
commit
794f81bb66
5 files changed
+8
-70
No files matched your search
@@ -28,7 +28,7 @@ public enum Command: Equatable {
|
||||
case status(MailboxName, [MailboxAttribute])
|
||||
case subscribe(MailboxName)
|
||||
case unsubscribe(MailboxName)
|
||||
case authenticate(method: String, InitialResponse?, [ByteBuffer])
|
||||
case authenticate(method: String, [ByteBuffer])
|
||||
case login(username: String, password: String)
|
||||
case starttls
|
||||
case check
|
||||
@@ -85,8 +85,8 @@ extension EncodeBuffer {
|
||||
return self.writeCommandKind_subscribe(mailbox: mailbox)
|
||||
case .unsubscribe(let mailbox):
|
||||
return self.writeCommandKind_unsubscribe(mailbox: mailbox)
|
||||
case .authenticate(let method, let initial, let data):
|
||||
return self.writeCommandKind_authenticate(method: method, initial: initial, data: data)
|
||||
case .authenticate(let method, let data):
|
||||
return self.writeCommandKind_authenticate(method: method, data: data)
|
||||
case .login(let userid, let password):
|
||||
return self.writeCommandKind_login(userID: userid, password: password)
|
||||
case .starttls:
|
||||
@@ -230,12 +230,8 @@ extension EncodeBuffer {
|
||||
self.writeMailbox(mailbox)
|
||||
}
|
||||
|
||||
private mutating func writeCommandKind_authenticate(method: String, initial: InitialResponse?, data: [ByteBuffer]) -> Int {
|
||||
private mutating func writeCommandKind_authenticate(method: String, data: [ByteBuffer]) -> Int {
|
||||
self.writeString("AUTHENTICATE \(method)") +
|
||||
self.writeIfExists(initial) { (initial) -> Int in
|
||||
self.writeSpace() +
|
||||
self.writeInitialResponse(initial)
|
||||
} +
|
||||
self.writeArray(data, separator: "", parenthesis: false) { (base64, self) -> Int in
|
||||
var base64 = base64
|
||||
return self.writeString("\r\n") + self.writeBuffer(&base64)
|
||||
|
||||
@@ -1,34 +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 struct NIO.ByteBuffer
|
||||
|
||||
/// IMAPv4 `initial-response`
|
||||
public enum InitialResponse: Equatable {
|
||||
case equals
|
||||
case base64(ByteBuffer)
|
||||
}
|
||||
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeInitialResponse(_ response: InitialResponse) -> Int {
|
||||
switch response {
|
||||
case .equals:
|
||||
return self.writeString("=")
|
||||
case .base64(let base64):
|
||||
return self.writeBase64(base64)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,23 +126,18 @@ extension GrammarParser {
|
||||
}
|
||||
}
|
||||
|
||||
// authenticate = "AUTHENTICATE" SP auth-type [SP initial-resp] *(CRLF base64)
|
||||
// authenticate = "AUTHENTICATE" SP auth-type *(CRLF base64)
|
||||
static func parseAuthenticate(buffer: inout ByteBuffer, tracker: StackTracker) throws -> Command {
|
||||
try ParserLibrary.parseComposite(buffer: &buffer, tracker: tracker) { buffer, tracker -> Command in
|
||||
try ParserLibrary.parseFixedString("AUTHENTICATE ", buffer: &buffer, tracker: tracker)
|
||||
let authMethod = try self.parseAtom(buffer: &buffer, tracker: tracker)
|
||||
|
||||
let initial = try ParserLibrary.parseOptional(buffer: &buffer, tracker: tracker) { (buffer, tracker) -> InitialResponse in
|
||||
try ParserLibrary.parseSpace(buffer: &buffer, tracker: tracker)
|
||||
return try self.parseInitialResp(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
|
||||
// NOTE: Spec is super unclear, so we're ignoring the possibility of multiple base 64 chunks right now
|
||||
// let data = try ParserLibrary.parseOptional(buffer: &buffer, tracker: tracker) { (buffer, tracker) -> [ByteBuffer] in
|
||||
// try ParserLibrary.parseFixedString("\r\n", buffer: &buffer, tracker: tracker)
|
||||
// return [try self.parseBase64(buffer: &buffer, tracker: tracker)]
|
||||
// } ?? []
|
||||
return .authenticate(method: authMethod, initial, [])
|
||||
return .authenticate(method: authMethod, [])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1401,23 +1396,6 @@ extension GrammarParser {
|
||||
try ParserLibrary.parseNewline(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
|
||||
// initial-resp = (base64 / "=")
|
||||
static func parseInitialResp(buffer: inout ByteBuffer, tracker: StackTracker) throws -> InitialResponse {
|
||||
func parseInitialResp_equals(buffer: inout ByteBuffer, tracker: StackTracker) throws -> InitialResponse {
|
||||
try ParserLibrary.parseFixedString("=", buffer: &buffer, tracker: tracker)
|
||||
return .equals
|
||||
}
|
||||
|
||||
func parseInitialResp_base64(buffer: inout ByteBuffer, tracker: StackTracker) throws -> InitialResponse {
|
||||
.base64(try self.parseBase64(buffer: &buffer, tracker: tracker))
|
||||
}
|
||||
|
||||
return try ParserLibrary.parseOneOf([
|
||||
parseInitialResp_equals,
|
||||
parseInitialResp_base64,
|
||||
], buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
|
||||
// list = "LIST" [SP list-select-opts] SP mailbox SP mbox-or-pat [SP list-return-opts]
|
||||
static func parseList(buffer: inout ByteBuffer, tracker: StackTracker) throws -> Command {
|
||||
try ParserLibrary.parseComposite(buffer: &buffer, tracker: tracker) { (buffer, tracker) in
|
||||
|
||||
@@ -816,11 +816,10 @@ extension ParserUnitTests {
|
||||
func testParseCommandNonAuth_valid_authenticate() {
|
||||
TestUtilities.withBuffer("AUTHENTICATE some", terminator: "\r\n") { (buffer) in
|
||||
let result = try GrammarParser.parseCommandNonauth(buffer: &buffer, tracker: .testTracker)
|
||||
guard case .authenticate(let type, let initial, let dataArray) = result else {
|
||||
guard case .authenticate(let type, let dataArray) = result else {
|
||||
XCTFail("Case mixup \(result)")
|
||||
return
|
||||
}
|
||||
XCTAssertNil(initial)
|
||||
XCTAssertEqual(type, "some")
|
||||
|
||||
XCTAssertEqual(dataArray, [])
|
||||
|
||||
@@ -33,8 +33,7 @@ final class RoundtripTests: XCTestCase {
|
||||
|
||||
(.login(username: "user", password: "password"), #line),
|
||||
|
||||
(.authenticate(method: "some", nil, []), #line),
|
||||
(.authenticate(method: "some", .equals, []), #line),
|
||||
(.authenticate(method: "some", []), #line),
|
||||
|
||||
(.create(.inbox, []), #line),
|
||||
(.create(MailboxName("mailbox"), []), #line),
|
||||
|
||||
Reference in new issue
Block a user