mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-27 05:04:23 +00:00
* Document UseAttribute * Document URLRumpMechanism * Document URLFetchData * Document UAuthMechanism * Document StoreModifier * Document SortData * Document SequenceMatchData * Document QResyncParameter * Document SelectParameter * Document SectionSpecifier * Document SectionSpecifier.Part * Document SectionSpecifier.Kind * Document ResponseEncodingOptions * Document ResponseEncodeBuffer * Document EncodeBuffer * Document EncodeBuffer.Chunk * Document EncodeBuffer more. * Document CommandEncodeBuffer * Document ParserError * Document ResponseParser * Document CommandParser * Document SynchronisingLiteralParser * Remove public where it isn't needed * Document write CommandStream * Document write TaggedCommand * Remove public from write functions * Document FetchAttribute * Document top-level Capability * Documents Capability subtypes * Document FullDateTime * Document FullDate * Document FullTime * Document ContinuationRequest * Document ListSelectOptions * Document ResponseOrContinuationRequest * Document Response * Document FetchResponse * Document StreamingKind * Document ResponseText * Document ResponseTextCode * Document TaggedResponse * Document TaggedResponseState * Remove docs * Document UntaggedStatus * Document ScopeOption * Document ReturnOption * Document IServer * Document InitialClientResponse * Document AttributeFlag * Document UIDValidity * Document UIDSet * Document UID * Document EncodedAuthenticationType * Document EncodedMailbox * Document EncodedSearch * Document EncodedSection * Document EncodedURLAuth * Document EncodedUser * Document ResponseCodeAppend * Document ResponsePayload * Document SequenceNumber * Document OptionValueComp * Document QuotaLimit * Document QuotaResource * Document OptionVendorTag * Document IPartial and remove IPartialOnly * Document QuotaRoot * Document ESearchResponse * Document SearchCorrelator * Document Address * Document UIDRange * Document IUID * Document SearchModificationSequence * Document SearchModificationSequenceExtension * Document SearchReturnData * Document SearchReturnDataExtension * Document SearchReturnOption * Document SearchReturnOptionExtension * Document SequenceRange * Document SequenceRangeSet * Fix compile * Document SequenceSet * Document ParameterValue * Define TaggedExtension * Document AuthIMAPURL * Document AuthIMAPURLFull * Document AuthIMAPURLRump * Document ChangedSinceModifier * Document UnchangedSinceModifier * Document CreateParameter * Document EntryValue * Document Expire * Document FetchModifier * Document FetchModificationResponse * Document IAbsolutePath * Document IAuth * Document ICommand * Document IMailboxReference * Document MetadataValue * Document IMAPURL * Document MetadataOption * Document MetadataResponse * Document RelativeIMAPURL * Document INetworkPath * Document MechanismBase64 * Document IMessageList * Document IMessageOrPartial * Document IMessagePart * Document IPathQuery * Document ISection * Document IRelativePath * Document IUAVerifier * Document IURLAuthRump * Document IURLAuthRump * Document IUserInfo * Fix missing documentation * Document CommandEncoder * Fix sanity * Update CommandDecoder.swift * PR reviews
47 lines
1.5 KiB
Swift
47 lines
1.5 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
import NIOIMAPCore
|
|
|
|
/// Thrown if an error occurs when decoding IMAP data.
|
|
public struct IMAPDecoderError: Error {
|
|
/// The error that was thrown by the IMAP parser.
|
|
public var parserError: Error
|
|
|
|
/// The buffer that was provided to the parser.
|
|
public var buffer: ByteBuffer
|
|
}
|
|
|
|
struct CommandDecoder: NIOSingleStepByteToMessageDecoder {
|
|
typealias InboundOut = PartialCommandStream
|
|
|
|
private var ok: ByteBuffer?
|
|
private var parser = CommandParser()
|
|
private var synchronisingLiteralParser = SynchronizingLiteralParser()
|
|
|
|
mutating func decode(buffer: inout ByteBuffer) throws -> PartialCommandStream? {
|
|
let save = buffer
|
|
do {
|
|
return try self.parser.parseCommandStream(buffer: &buffer)
|
|
} catch {
|
|
throw IMAPDecoderError(parserError: error, buffer: save)
|
|
}
|
|
}
|
|
|
|
mutating func decodeLast(buffer: inout ByteBuffer, seenEOF: Bool) throws -> PartialCommandStream? {
|
|
try self.decode(buffer: &buffer)
|
|
}
|
|
}
|