From cc76f4bee0ed612ae186138185dea42e14d830df Mon Sep 17 00:00:00 2001 From: Daniel Eggert Date: Sun, 25 Oct 2026 12:27:06 +0100 Subject: [PATCH] Make writeIfExists / write(if:) free functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As EncodeBuffer methods, `self.write(if:) { self.write… }` borrows the buffer while the closure mutates it, forcing a copy and a CoW on the first write inside the closure. Hand edit: Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift, which defines the free functions. Call sites converted with: git ls-files -z 'Sources/*.swift' 'Tests/*.swift' | xargs -0 perl -pi -e \ 's/\b(?:self\.buffer|self|buffer)\.(writeIfExists\(|write\(if:)/$1/g' --- .../NIOIMAPCore/ByteBuffer+WriteLiteral.swift | 80 ++++++++++--------- .../Grammar/Append/AppendOptions.swift | 4 +- .../Grammar/AuthenticatedURLRump.swift | 2 +- .../Grammar/Body/Field/LanguageLocation.swift | 2 +- .../Body/Field/LocationAndExtensions.swift | 2 +- .../NIOIMAPCore/Grammar/Body/Multipart.swift | 4 +- .../NIOIMAPCore/Grammar/Body/Singlepart.swift | 2 +- .../Grammar/ByteRange/ByteRange.swift | 2 +- .../NIOIMAPCore/Grammar/Command/Command.swift | 30 +++---- .../Grammar/Command/CommandStreamPart.swift | 4 +- .../ESearch/ExtendedSearchOptions.swift | 6 +- .../ESearch/ExtendedSearchSourceOptions.swift | 2 +- .../Grammar/EncodedSearchQuery.swift | 2 +- .../NIOIMAPCore/Grammar/FetchAttribute.swift | 6 +- .../NIOIMAPCore/Grammar/FullDateTime.swift | 2 +- Sources/NIOIMAPCore/Grammar/IMAPServer.swift | 4 +- Sources/NIOIMAPCore/Grammar/IMAPURL.swift | 2 +- .../Grammar/List/ListReturnOps.swift | 2 +- .../Grammar/List/ListSelectOption.swift | 2 +- .../Grammar/Mailbox/MailboxData.swift | 4 +- .../Grammar/Mailbox/MailboxInfo.swift | 4 +- .../Grammar/MailboxUIDValidity.swift | 2 +- .../NIOIMAPCore/Grammar/MechanismBase64.swift | 2 +- .../Grammar/Message/MessageAttributes.swift | 6 +- Sources/NIOIMAPCore/Grammar/MessagePath.swift | 4 +- .../Response/ExtendedSearchResponse.swift | 6 +- .../Grammar/Response/ResponseText.swift | 2 +- .../Grammar/Response/ResponseTextCode.swift | 4 +- .../Grammar/Response/UIDBatchesResponse.swift | 2 +- .../Grammar/Search/SearchCorrelator.swift | 4 +- .../Grammar/Search/SearchKey.swift | 2 +- .../Grammar/Search/SearchReturnOption.swift | 2 +- .../Search/SearchReturnOptionExtension.swift | 2 +- Sources/NIOIMAPCore/Grammar/SectionSpec.swift | 4 +- .../NIOIMAPCore/Grammar/SelectParameter.swift | 6 +- .../Grammar/Sequence/SequenceRange.swift | 2 +- .../Grammar/Tagged/TaggedExtension.swift | 2 +- .../Grammar/Tagged/TaggedExtensiontComp.swift | 2 +- .../Grammar/UID/MessageIdentifierRange.swift | 2 +- Sources/NIOIMAPCore/Grammar/URLCommand.swift | 2 +- Sources/NIOIMAPCore/Grammar/UserInfo.swift | 4 +- .../NIOIMAPCore/ResponseEncodeBuffer.swift | 2 +- 42 files changed, 119 insertions(+), 113 deletions(-) diff --git a/Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift b/Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift index 3f586243..7f724676 100644 --- a/Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift +++ b/Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift @@ -197,24 +197,24 @@ extension EncodeBuffer { // TODO: This should probably check // collection.count != 0 // such that an empty collection gets encoded as "()". - self.write(if: collection.count > 0) { + write(if: collection.count > 0) { self.writeString(prefix) } - + self.write(if: parenthesis) { () -> Int in + + write(if: parenthesis) { () -> Int in self.writeString("(") } + 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 + + write(if: i < collection.count - 1) { () -> Int in self.writeString(separator) } } - + self.write(if: parenthesis) { () -> Int in + + write(if: parenthesis) { () -> Int in self.writeString(")") } - + self.write(if: collection.count > 0) { + + write(if: collection.count > 0) { self.writeString(suffix) } } @@ -239,52 +239,58 @@ extension EncodeBuffer { // TODO: This should probably check // collection.count != 0 // such that an empty collection gets encoded as "()". - self.write(if: values.count > 0) { + write(if: values.count > 0) { self.writeString(prefix) } - + self.write(if: parenthesis) { () -> Int in + + write(if: parenthesis) { () -> Int in self.writeString("(") } + 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 + + write(if: i < values.count - 1) { () -> Int in self.writeString(separator) } } - + self.write(if: parenthesis) { () -> Int in + + write(if: parenthesis) { () -> Int in self.writeString(")") } - + self.write(if: values.count > 0) { + + write(if: values.count > 0) { self.writeString(suffix) } } - - /// Writes to self using a closure if the given `value` is non-`nil`. This allows for chaining together writes - /// when attempting to perform composite writes and return the total number of bytes written. - /// - parameters: - /// - value: The optional field to evaluate. - /// - writer: The closure to invoke if `value` is non-`nil`. If `value` exists then it is passed as - /// the only argument to this closure. - /// - returns: The number of bytes written. - @discardableResult func writeIfExists(_ value: T?, _ writer: (inout T) -> Int) -> Int { - guard var value = value else { - return 0 - } - return writer(&value) - } - - /// Writes to self using a closure if a condition is met. This allows for chaining together writes - /// when attempting to perform composite writes and return the total number of bytes written. - /// - parameters: - /// - condition: The condition to evaluate, if `true` then `writer` will be invoked. - /// - writer: The closure to invoke if `condition` is met. - /// - returns: The number of bytes written. - @discardableResult func write(if condition: Bool, _ writer: () -> Int) -> Int { - guard condition else { - return 0 - } - return writer() - } +} + +// MARK: - Conditional writes + +// Free functions, not `EncodeBuffer` methods: a method call `self.write(if: …) { self.write… }` +// borrows `self` while the closure mutates it, so the compiler copies the buffer and the first write +// inside the closure pays for copy-on-write. + +/// Writes using a closure if the given `value` is non-`nil`. This allows for chaining together writes +/// when attempting to perform composite writes and return the total number of bytes written. +/// - parameters: +/// - value: The optional field to evaluate. +/// - writer: The closure to invoke if `value` is non-`nil`. If `value` exists then it is passed as +/// the only argument to this closure. +/// - returns: The number of bytes written. +@discardableResult func writeIfExists(_ value: T?, _ writer: (inout T) -> Int) -> Int { + guard var value = value else { + return 0 + } + return writer(&value) +} + +/// Writes using a closure if a condition is met. This allows for chaining together writes +/// when attempting to perform composite writes and return the total number of bytes written. +/// - parameters: +/// - condition: The condition to evaluate, if `true` then `writer` will be invoked. +/// - writer: The closure to invoke if `condition` is met. +/// - returns: The number of bytes written. +@discardableResult func write(if condition: Bool, _ writer: () -> Int) -> Int { + guard condition else { + return 0 + } + return writer() } diff --git a/Sources/NIOIMAPCore/Grammar/Append/AppendOptions.swift b/Sources/NIOIMAPCore/Grammar/Append/AppendOptions.swift index 0b146da6..7af88f01 100644 --- a/Sources/NIOIMAPCore/Grammar/Append/AppendOptions.swift +++ b/Sources/NIOIMAPCore/Grammar/Append/AppendOptions.swift @@ -89,10 +89,10 @@ public struct AppendOptions: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeAppendOptions(_ options: AppendOptions) -> Int { - self.write(if: options.flagList.count >= 1) { + write(if: options.flagList.count >= 1) { self.writeSpace() + self.writeFlags(options.flagList) } - + self.writeIfExists(options.internalDate) { (internalDate) -> Int in + + writeIfExists(options.internalDate) { (internalDate) -> Int in self.writeSpace() + self.writeInternalDate(internalDate) } + self.writeOrderedDictionary(options.extensions, prefix: " ", parenthesis: false) { (ext, self) -> Int in diff --git a/Sources/NIOIMAPCore/Grammar/AuthenticatedURLRump.swift b/Sources/NIOIMAPCore/Grammar/AuthenticatedURLRump.swift index 5cf363a9..4d66dc9d 100644 --- a/Sources/NIOIMAPCore/Grammar/AuthenticatedURLRump.swift +++ b/Sources/NIOIMAPCore/Grammar/AuthenticatedURLRump.swift @@ -94,7 +94,7 @@ public struct AuthenticatedURLRump: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeAuthenticatedURLRump(_ data: AuthenticatedURLRump) -> Int { - self.writeIfExists(data.expire) { expire in + writeIfExists(data.expire) { expire in self.writeExpire(expire) } + self.writeString(";URLAUTH=") + self.writeAccess(data.access) } diff --git a/Sources/NIOIMAPCore/Grammar/Body/Field/LanguageLocation.swift b/Sources/NIOIMAPCore/Grammar/Body/Field/LanguageLocation.swift index 2d2f06bb..c5ade8bd 100644 --- a/Sources/NIOIMAPCore/Grammar/Body/Field/LanguageLocation.swift +++ b/Sources/NIOIMAPCore/Grammar/Body/Field/LanguageLocation.swift @@ -64,7 +64,7 @@ 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 + + writeIfExists(langLoc.location) { (location) -> Int in self.writeBodyLocationAndExtensions(location) } } diff --git a/Sources/NIOIMAPCore/Grammar/Body/Field/LocationAndExtensions.swift b/Sources/NIOIMAPCore/Grammar/Body/Field/LocationAndExtensions.swift index 499bcc18..7bca9b9f 100644 --- a/Sources/NIOIMAPCore/Grammar/Body/Field/LocationAndExtensions.swift +++ b/Sources/NIOIMAPCore/Grammar/Body/Field/LocationAndExtensions.swift @@ -69,7 +69,7 @@ extension EncodeBuffer { _ locationExtension: BodyStructure.LocationAndExtensions ) -> Int { self.writeSpace() + self.writeNString(locationExtension.location) - + self.write(if: !locationExtension.extensions.isEmpty) { + + write(if: !locationExtension.extensions.isEmpty) { self.writeSpace() + self.writeBodyExtensions(locationExtension.extensions) } } diff --git a/Sources/NIOIMAPCore/Grammar/Body/Multipart.swift b/Sources/NIOIMAPCore/Grammar/Body/Multipart.swift index f77cee35..37df3e31 100644 --- a/Sources/NIOIMAPCore/Grammar/Body/Multipart.swift +++ b/Sources/NIOIMAPCore/Grammar/Body/Multipart.swift @@ -103,14 +103,14 @@ extension EncodeBuffer { 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 + + 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 + + writeIfExists(ext.dispositionAndLanguage) { (dspLanguage) -> Int in self.writeBodyDispositionAndLanguage(dspLanguage) } } diff --git a/Sources/NIOIMAPCore/Grammar/Body/Singlepart.swift b/Sources/NIOIMAPCore/Grammar/Body/Singlepart.swift index 960cdea6..f36d05e0 100644 --- a/Sources/NIOIMAPCore/Grammar/Body/Singlepart.swift +++ b/Sources/NIOIMAPCore/Grammar/Body/Singlepart.swift @@ -208,7 +208,7 @@ extension EncodeBuffer { @discardableResult mutating func writeBodyExtensionSinglePart(_ ext: BodyStructure.Singlepart.Extension) -> Int { self.writeNString(ext.digest) - + self.writeIfExists(ext.dispositionAndLanguage) { (dsp) -> Int in + + writeIfExists(ext.dispositionAndLanguage) { (dsp) -> Int in self.writeBodyDispositionAndLanguage(dsp) } } diff --git a/Sources/NIOIMAPCore/Grammar/ByteRange/ByteRange.swift b/Sources/NIOIMAPCore/Grammar/ByteRange/ByteRange.swift index 675da4f4..0e1848cb 100644 --- a/Sources/NIOIMAPCore/Grammar/ByteRange/ByteRange.swift +++ b/Sources/NIOIMAPCore/Grammar/ByteRange/ByteRange.swift @@ -50,7 +50,7 @@ extension EncodeBuffer { @discardableResult mutating func writeByteRange(_ data: ByteRange) -> Int { self.writeString("\(data.offset)") - + self.writeIfExists(data.length) { length in + + writeIfExists(data.length) { length in self.writeString(".\(length)") } } diff --git a/Sources/NIOIMAPCore/Grammar/Command/Command.swift b/Sources/NIOIMAPCore/Grammar/Command/Command.swift index 39938990..7eff7996 100644 --- a/Sources/NIOIMAPCore/Grammar/Command/Command.swift +++ b/Sources/NIOIMAPCore/Grammar/Command/Command.swift @@ -797,7 +797,7 @@ extension CommandEncodeBuffer { entries: [MetadataEntryName] ) -> Int { self.buffer.writeString("GETMETADATA") - + self.buffer.write(if: options.count >= 1) { + + write(if: options.count >= 1) { buffer.writeSpace() + buffer.writeMetadataOptions(options) } + self.buffer.writeSpace() + self.buffer.writeMailbox(mailbox) + self.buffer.writeSpace() + self.buffer.writeEntries(entries) @@ -825,7 +825,7 @@ 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) { + + write(if: parameters.count > 0) { self.buffer.writeSpace() + self.buffer.writeArray(parameters, separator: "", parenthesis: true) { (param, buffer) -> Int in buffer.writeCreateParameter(param) @@ -849,11 +849,11 @@ extension CommandEncodeBuffer { returnOptions: [ReturnOption] ) -> Int { self.buffer.writeString("LIST") - + self.buffer.writeIfExists(selectOptions) { (options) -> Int in + + 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) { + + write(if: returnOptions.count >= 1) { self.buffer.writeSpace() + self.buffer.writeListReturnOptions(returnOptions) } } @@ -865,14 +865,14 @@ extension CommandEncodeBuffer { returnOptions: [ReturnOption] ) -> Int { self.buffer.writeString("LIST") - + self.buffer.write(if: selectOptions.count >= 1) { + + write(if: selectOptions.count >= 1) { self.buffer.writeSpace() + 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) { + + write(if: returnOptions.count >= 1) { self.buffer.writeSpace() + self.buffer.writeListReturnOptions(returnOptions) } } @@ -889,7 +889,7 @@ extension CommandEncodeBuffer { ) -> Int { self.buffer.writeString("RENAME ") + self.buffer.writeMailbox(from) + self.buffer.writeSpace() + self.buffer.writeMailbox(to) - + self.buffer.writeIfExists(parameters) { (params) -> Int in + + writeIfExists(parameters) { (params) -> Int in self.buffer.writeParameters(params) } } @@ -918,7 +918,7 @@ extension CommandEncodeBuffer { private mutating func writeCommandKind_uidBatches(batchSize: Int, batchRange: ClosedRange?) -> Int { self.buffer.writeString("UIDBATCHES \(batchSize)") - + self.buffer.writeIfExists(batchRange) { + + writeIfExists(batchRange) { let range = UnknownMessageIdentifier(exactly: $0.lowerBound)!...UnknownMessageIdentifier( exactly: $0.upperBound @@ -942,7 +942,7 @@ extension CommandEncodeBuffer { initialResponse: InitialResponse? ) -> Int { self.buffer.writeString("AUTHENTICATE ") + self.buffer.writeAuthenticationMechanism(mechanism) - + self.buffer.writeIfExists(initialResponse) { resp in + + writeIfExists(initialResponse) { resp in var c = self.buffer.writeSpace() if self.buffer.loggingMode { c += self.buffer.writeString("∅") @@ -1031,7 +1031,7 @@ extension CommandEncodeBuffer { data: StoreData ) -> Int { self.buffer.writeString("STORE ") + self.buffer.writeLastCommandSet(set) - + self.buffer.write(if: modifiers.count >= 1) { + + write(if: modifiers.count >= 1) { self.buffer.writeSpace() + self.buffer.writeArray(modifiers) { (element, buffer) -> Int in buffer.writeStoreModifier(element) @@ -1045,7 +1045,7 @@ extension CommandEncodeBuffer { data: StoreData ) -> Int { self.buffer.writeString("UID STORE ") + self.buffer.writeLastCommandSet(set) - + self.buffer.write(if: modifiers.count >= 1) { + + write(if: modifiers.count >= 1) { self.buffer.writeStoreModifiers(modifiers) } + self.buffer.writeSpace() + self.buffer.writeStoreData(data) } @@ -1056,11 +1056,11 @@ extension CommandEncodeBuffer { returnOptions: [SearchReturnOption] = [] ) -> Int { self.buffer.writeString("SEARCH") - + self.buffer.writeIfExists(returnOptions) { (options) -> Int in + + writeIfExists(returnOptions) { (options) -> Int in self.buffer.writeSearchReturnOptions(options) } + self.buffer.writeSpace() - + self.buffer.write(if: key.usesString && options.useSearchCharset) { - self.buffer.writeIfExists(charset) { (charset) -> Int in + + write(if: key.usesString && options.useSearchCharset) { + writeIfExists(charset) { (charset) -> Int in self.buffer.writeString("CHARSET ") + self.buffer.writeCharacterSetName(charset) + self.buffer.writeSpace() } @@ -1083,7 +1083,7 @@ extension CommandEncodeBuffer { returnOptions: [SearchReturnOption] = [] ) -> Int { self.buffer.writeString("SORT") - + self.buffer.writeIfExists(returnOptions) { (options) -> Int in + + writeIfExists(returnOptions) { (options) -> Int in self.buffer.writeSearchReturnOptions(options) } + self.buffer.writeSpace() + self.buffer.writeSortCriteria(criteria) diff --git a/Sources/NIOIMAPCore/Grammar/Command/CommandStreamPart.swift b/Sources/NIOIMAPCore/Grammar/Command/CommandStreamPart.swift index 615667c6..28e391a5 100644 --- a/Sources/NIOIMAPCore/Grammar/Command/CommandStreamPart.swift +++ b/Sources/NIOIMAPCore/Grammar/Command/CommandStreamPart.swift @@ -343,11 +343,11 @@ extension CommandEncodeBuffer { self.encodedAtLeastOneCatenateElement = true } - return self.buffer.write(if: self.encodedAtLeastOneCatenateElement) { self.buffer.writeSpace() } + return 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() } + write(if: self.encodedAtLeastOneCatenateElement) { self.buffer.writeSpace() } + self.buffer.writeString("TEXT ") if self.options.useNonSynchronizingLiteralPlus { diff --git a/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchOptions.swift b/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchOptions.swift index 065df485..5200751b 100644 --- a/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchOptions.swift +++ b/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchOptions.swift @@ -93,13 +93,13 @@ public struct ExtendedSearchOptions: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeExtendedSearchOptions(_ options: ExtendedSearchOptions) -> Int { - self.writeIfExists(options.sourceOptions) { (options) -> Int in + writeIfExists(options.sourceOptions) { (options) -> Int in self.writeSpace() + self.writeExtendedSearchSourceOptions(options) } - + self.writeIfExists(options.returnOptions) { (options) -> Int in + + writeIfExists(options.returnOptions) { (options) -> Int in self.writeSearchReturnOptions(options) } + self.writeSpace() - + self.writeIfExists(options.charset) { (charset) -> Int in + + writeIfExists(options.charset) { (charset) -> Int in self.writeString("CHARSET ") + self.writeCharacterSetName(charset) + self.writeSpace() } + self.writeSearchKey(options.key) } diff --git a/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchSourceOptions.swift b/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchSourceOptions.swift index 4a1e1e51..20649c99 100644 --- a/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchSourceOptions.swift +++ b/Sources/NIOIMAPCore/Grammar/ESearch/ExtendedSearchSourceOptions.swift @@ -78,7 +78,7 @@ extension EncodeBuffer { + self.writeArray(options.sourceMailbox, parenthesis: false) { (filter, buffer) -> Int in buffer.writeMailboxFilter(filter) } - + self.writeIfExists(options.scopeOptions) { scopeOptions in + + writeIfExists(options.scopeOptions) { scopeOptions in self.writeString(" (") + self.writeExtendedSearchScopeOptions(scopeOptions) + self.writeString(")") } + self.writeString(")") } diff --git a/Sources/NIOIMAPCore/Grammar/EncodedSearchQuery.swift b/Sources/NIOIMAPCore/Grammar/EncodedSearchQuery.swift index d1cbba7c..35030b26 100644 --- a/Sources/NIOIMAPCore/Grammar/EncodedSearchQuery.swift +++ b/Sources/NIOIMAPCore/Grammar/EncodedSearchQuery.swift @@ -39,7 +39,7 @@ public struct EncodedSearchQuery: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeEncodedSearchQuery(_ ref: EncodedSearchQuery) -> Int { self.writeEncodedMailboxUIDValidity(ref.mailboxUIDValidity) - + self.writeIfExists(ref.encodedSearch) { search in + + writeIfExists(ref.encodedSearch) { search in self.writeString("?") + self.writeEncodedSearch(search) } } diff --git a/Sources/NIOIMAPCore/Grammar/FetchAttribute.swift b/Sources/NIOIMAPCore/Grammar/FetchAttribute.swift index a40c7cbe..c66fe096 100644 --- a/Sources/NIOIMAPCore/Grammar/FetchAttribute.swift +++ b/Sources/NIOIMAPCore/Grammar/FetchAttribute.swift @@ -392,7 +392,7 @@ extension EncodeBuffer { partial: ClosedRange? ) -> Int { self.writeString(peek ? "BODY.PEEK" : "BODY") + self.writeSection(section) - + self.writeIfExists(partial) { (partial) -> Int in + + writeIfExists(partial) { (partial) -> Int in self.writeByteRange(partial) } } @@ -407,10 +407,10 @@ extension EncodeBuffer { partial: ClosedRange? ) -> Int { self.writeString("BINARY") - + self.write(if: peek) { + + write(if: peek) { self.writeString(".PEEK") } + self.writeSectionBinary(section) - + self.writeIfExists(partial) { (partial) -> Int in + + writeIfExists(partial) { (partial) -> Int in self.writeByteRange(partial) } } diff --git a/Sources/NIOIMAPCore/Grammar/FullDateTime.swift b/Sources/NIOIMAPCore/Grammar/FullDateTime.swift index 97a4829c..f3d62bd0 100644 --- a/Sources/NIOIMAPCore/Grammar/FullDateTime.swift +++ b/Sources/NIOIMAPCore/Grammar/FullDateTime.swift @@ -247,7 +247,7 @@ extension EncodeBuffer { 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 + + writeIfExists(data.fraction) { fraction in self.writeString(".\(fraction.stringValue)") } + self.writeTimeOffset(data.offset) } diff --git a/Sources/NIOIMAPCore/Grammar/IMAPServer.swift b/Sources/NIOIMAPCore/Grammar/IMAPServer.swift index a19b462e..c5b064bb 100644 --- a/Sources/NIOIMAPCore/Grammar/IMAPServer.swift +++ b/Sources/NIOIMAPCore/Grammar/IMAPServer.swift @@ -276,10 +276,10 @@ extension IMAPServer.Host: ExpressibleByStringLiteral { extension EncodeBuffer { @discardableResult mutating func writeIMAPServer(_ server: IMAPServer) -> Int { - self.writeIfExists(server.userAuthenticationMechanism) { authMechanism in + writeIfExists(server.userAuthenticationMechanism) { authMechanism in self.writeUserAuthenticationMechanism(authMechanism) + self.writeString("@") } + self.writeString(server.host.stringValue) - + self.writeIfExists(server.port) { port in + + writeIfExists(server.port) { port in self.writeString(":\(port)") } } diff --git a/Sources/NIOIMAPCore/Grammar/IMAPURL.swift b/Sources/NIOIMAPCore/Grammar/IMAPURL.swift index c03ba772..cd6afdb9 100644 --- a/Sources/NIOIMAPCore/Grammar/IMAPURL.swift +++ b/Sources/NIOIMAPCore/Grammar/IMAPURL.swift @@ -88,7 +88,7 @@ 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 + + writeIfExists(url.command) { command in self.writeURLCommand(command) } } diff --git a/Sources/NIOIMAPCore/Grammar/List/ListReturnOps.swift b/Sources/NIOIMAPCore/Grammar/List/ListReturnOps.swift index c953f12d..7ba3d170 100644 --- a/Sources/NIOIMAPCore/Grammar/List/ListReturnOps.swift +++ b/Sources/NIOIMAPCore/Grammar/List/ListReturnOps.swift @@ -19,7 +19,7 @@ import struct NIO.ByteBuffer extension EncodeBuffer { @discardableResult mutating func writeListReturnOptions(_ options: [ReturnOption]) -> Int { self.writeString("RETURN ") + self.writeString("(") - + self.write(if: options.count >= 1) { + + write(if: options.count >= 1) { self.writeArray(options, parenthesis: false) { (option, self) in self.writeReturnOption(option) } diff --git a/Sources/NIOIMAPCore/Grammar/List/ListSelectOption.swift b/Sources/NIOIMAPCore/Grammar/List/ListSelectOption.swift index 6a58c36e..a8a44158 100644 --- a/Sources/NIOIMAPCore/Grammar/List/ListSelectOption.swift +++ b/Sources/NIOIMAPCore/Grammar/List/ListSelectOption.swift @@ -125,7 +125,7 @@ extension EncodeBuffer { @discardableResult mutating func writeListSelectOptions(_ options: ListSelectOptions?) -> Int { self.writeString("(") - + self.writeIfExists(options) { (optionsData) -> Int in + + 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) diff --git a/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxData.swift b/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxData.swift index 1ceb537b..0c1e9531 100644 --- a/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxData.swift +++ b/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxData.swift @@ -218,7 +218,7 @@ extension EncodeBuffer { + self.writeArray(list, prefix: " ", separator: " ", parenthesis: false) { (id, buffer) -> Int in buffer.writeMessageIdentifier(id) } - + self.writeIfExists(modificationSequence) { value -> Int in + + writeIfExists(modificationSequence) { value -> Int in self.writeString(" (MODSEQ ") + self.writeModificationSequenceValue(value) + self.writeString(")") } } @@ -231,7 +231,7 @@ extension EncodeBuffer { + self.writeArray(list, prefix: " ", separator: " ", parenthesis: false) { (id, buffer) -> Int in buffer.writeMessageIdentifier(id) } - + self.writeIfExists(modificationSequence) { value -> Int in + + writeIfExists(modificationSequence) { value -> Int in self.writeString(" (MODSEQ ") + self.writeModificationSequenceValue(value) + self.writeString(")") } } diff --git a/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxInfo.swift b/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxInfo.swift index abbdf213..875c0eef 100644 --- a/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxInfo.swift +++ b/Sources/NIOIMAPCore/Grammar/Mailbox/MailboxInfo.swift @@ -294,11 +294,11 @@ extension EncodeBuffer { @discardableResult mutating func writeMailboxInfo(_ list: MailboxInfo) -> Int { self.writeString("(") - + self.writeIfExists(list.attributes) { (flags) -> Int in + + writeIfExists(list.attributes) { (flags) -> Int in self.writeMailboxListFlags(flags) } + self.writeString(") ") + self.writeMailboxPathSeparator(list.path.pathSeparator) + self.writeSpace() + self.writeMailbox(list.path.name) - + self.write(if: list.objectID != nil || !list.extensions.isEmpty) { + + write(if: list.objectID != nil || !list.extensions.isEmpty) { self.writeSpace() + self.writeMailboxListExtended(objectID: list.objectID, extensions: list.extensions) } } diff --git a/Sources/NIOIMAPCore/Grammar/MailboxUIDValidity.swift b/Sources/NIOIMAPCore/Grammar/MailboxUIDValidity.swift index af0cd529..7dff5eaf 100644 --- a/Sources/NIOIMAPCore/Grammar/MailboxUIDValidity.swift +++ b/Sources/NIOIMAPCore/Grammar/MailboxUIDValidity.swift @@ -76,7 +76,7 @@ public struct MailboxUIDValidity: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeEncodedMailboxUIDValidity(_ ref: MailboxUIDValidity) -> Int { self.writeEncodedMailbox(ref.encodedMailbox) - + self.writeIfExists(ref.uidValidity) { value in + + writeIfExists(ref.uidValidity) { value in self.writeString(";UIDVALIDITY=") + self.writeUIDValidity(value) } } diff --git a/Sources/NIOIMAPCore/Grammar/MechanismBase64.swift b/Sources/NIOIMAPCore/Grammar/MechanismBase64.swift index baec2edf..2f8c0fe6 100644 --- a/Sources/NIOIMAPCore/Grammar/MechanismBase64.swift +++ b/Sources/NIOIMAPCore/Grammar/MechanismBase64.swift @@ -41,7 +41,7 @@ public struct MechanismBase64: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeMechanismBase64(_ data: MechanismBase64) -> Int { self.writeURLAuthenticationMechanism(data.mechanism) - + self.writeIfExists(data.base64) { base64 in + + writeIfExists(data.base64) { base64 in // mechanism-base64 = mechanism ["=" base64]; the parser decodes, so encode here. self.writeString("=") + self.writeBufferAsBase64(base64) } diff --git a/Sources/NIOIMAPCore/Grammar/Message/MessageAttributes.swift b/Sources/NIOIMAPCore/Grammar/Message/MessageAttributes.swift index 4efe9e88..9d2d9ef4 100644 --- a/Sources/NIOIMAPCore/Grammar/Message/MessageAttributes.swift +++ b/Sources/NIOIMAPCore/Grammar/Message/MessageAttributes.swift @@ -346,7 +346,7 @@ extension EncodeBuffer { hasExtensionData: Bool ) -> Int { self.writeString("BODY") - + self.write(if: hasExtensionData) { () -> Int in + + write(if: hasExtensionData) { () -> Int in self.writeString("STRUCTURE") } + self.writeSpace() + self.writeBody(body) } @@ -357,14 +357,14 @@ extension EncodeBuffer { string: ByteBuffer? ) -> Int { self.writeString("BODY") + self.writeSection(section) - + self.writeIfExists(number) { (number) -> Int in + + writeIfExists(number) { (number) -> Int in self.writeString("<\(number)>") } + 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 + + writeIfExists(number) { (number) -> Int in self.writeString("<\(number)>") } + self.writeString(" {\(size)}\r\n") } diff --git a/Sources/NIOIMAPCore/Grammar/MessagePath.swift b/Sources/NIOIMAPCore/Grammar/MessagePath.swift index 364e7d1c..387393c4 100644 --- a/Sources/NIOIMAPCore/Grammar/MessagePath.swift +++ b/Sources/NIOIMAPCore/Grammar/MessagePath.swift @@ -109,10 +109,10 @@ 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 + + writeIfExists(data.section) { section in self.writeURLMessageSection(section) } - + self.writeIfExists(data.range) { partial in + + writeIfExists(data.range) { partial in self.writeMessagePathByteRange(partial) } } diff --git a/Sources/NIOIMAPCore/Grammar/Response/ExtendedSearchResponse.swift b/Sources/NIOIMAPCore/Grammar/Response/ExtendedSearchResponse.swift index bdc80a3f..2aa4ef1d 100644 --- a/Sources/NIOIMAPCore/Grammar/Response/ExtendedSearchResponse.swift +++ b/Sources/NIOIMAPCore/Grammar/Response/ExtendedSearchResponse.swift @@ -241,13 +241,13 @@ extension ExtendedSearchResponse { extension EncodeBuffer { @discardableResult mutating func writeExtendedSearchResponse(_ response: ExtendedSearchResponse) -> Int { self.writeString("ESEARCH") - + self.writeIfExists(response.correlator) { (correlator) -> Int in + + writeIfExists(response.correlator) { (correlator) -> Int in self.writeSearchCorrelator(correlator) } - + self.write(if: response.kind == .uid) { + + write(if: response.kind == .uid) { self.writeString(" UID") } - + self.write(if: response.returnData.count > 0) { + + write(if: response.returnData.count > 0) { self.writeSpace() } + self.writeArray(response.returnData, parenthesis: false) { (data, self) in diff --git a/Sources/NIOIMAPCore/Grammar/Response/ResponseText.swift b/Sources/NIOIMAPCore/Grammar/Response/ResponseText.swift index acb72511..330f1b37 100644 --- a/Sources/NIOIMAPCore/Grammar/Response/ResponseText.swift +++ b/Sources/NIOIMAPCore/Grammar/Response/ResponseText.swift @@ -70,7 +70,7 @@ public struct ResponseText: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeResponseText(_ text: ResponseText) -> Int { - self.writeIfExists(text.code) { (code) -> Int in + writeIfExists(text.code) { (code) -> Int in self.writeString("[") + self.writeResponseTextCode(code) + self.writeString("] ") } diff --git a/Sources/NIOIMAPCore/Grammar/Response/ResponseTextCode.swift b/Sources/NIOIMAPCore/Grammar/Response/ResponseTextCode.swift index d5e54a0a..a0d0d696 100644 --- a/Sources/NIOIMAPCore/Grammar/Response/ResponseTextCode.swift +++ b/Sources/NIOIMAPCore/Grammar/Response/ResponseTextCode.swift @@ -592,7 +592,7 @@ extension EncodeBuffer { private mutating func writeResponseTextCode_badCharsets(_ charsets: [CharacterSetName]) -> Int { self.writeString("BADCHARSET") - + self.write(if: charsets.count >= 1) { + + write(if: charsets.count >= 1) { self.writeSpace() + self.writeArray(charsets) { (charset, self) in self.writeCharacterSetName(charset) @@ -602,7 +602,7 @@ extension EncodeBuffer { private mutating func writeResponseTextCode_other(atom: String, string: String?) -> Int { self.writeString(atom) - + self.writeIfExists(string) { (string) -> Int in + + writeIfExists(string) { (string) -> Int in self.writeString(" \(string)") } } diff --git a/Sources/NIOIMAPCore/Grammar/Response/UIDBatchesResponse.swift b/Sources/NIOIMAPCore/Grammar/Response/UIDBatchesResponse.swift index 0a3204da..bbf81cb4 100644 --- a/Sources/NIOIMAPCore/Grammar/Response/UIDBatchesResponse.swift +++ b/Sources/NIOIMAPCore/Grammar/Response/UIDBatchesResponse.swift @@ -75,7 +75,7 @@ extension EncodeBuffer { @discardableResult mutating func writeUIDBatchesResponse(_ response: UIDBatchesResponse) -> Int { self.writeString(#"UIDBATCHES"#) + self.writeSearchCorrelator(response.correlator) - + self.write(if: !response.batches.isEmpty) { + + write(if: !response.batches.isEmpty) { self.writeString(" ") + self.writeArray(response.batches, separator: ",", parenthesis: false) { range, buffer -> Int in buffer.writeMessageIdentifierRange(range, descending: true) diff --git a/Sources/NIOIMAPCore/Grammar/Search/SearchCorrelator.swift b/Sources/NIOIMAPCore/Grammar/Search/SearchCorrelator.swift index 48636d0a..cff18a0d 100644 --- a/Sources/NIOIMAPCore/Grammar/Search/SearchCorrelator.swift +++ b/Sources/NIOIMAPCore/Grammar/Search/SearchCorrelator.swift @@ -78,10 +78,10 @@ extension EncodeBuffer { @discardableResult mutating func writeSearchCorrelator(_ correlator: SearchCorrelator) -> Int { // search-correlator = SP "(" "TAG" SP tag-string ")", tag-string = string self.writeString(" (TAG ") + self.writeIMAPString(correlator.tag) - + self.writeIfExists(correlator.mailbox) { mailbox in + + writeIfExists(correlator.mailbox) { mailbox in self.writeString(" MAILBOX ") + self.writeMailbox(mailbox) } - + self.writeIfExists(correlator.uidValidity) { uidValidity in + + writeIfExists(correlator.uidValidity) { uidValidity in self.writeString(" UIDVALIDITY ") + self.writeUIDValidity(uidValidity) } + self.writeString(")") } diff --git a/Sources/NIOIMAPCore/Grammar/Search/SearchKey.swift b/Sources/NIOIMAPCore/Grammar/Search/SearchKey.swift index 3ebacceb..9d3c4391 100644 --- a/Sources/NIOIMAPCore/Grammar/Search/SearchKey.swift +++ b/Sources/NIOIMAPCore/Grammar/Search/SearchKey.swift @@ -640,7 +640,7 @@ extension EncodeBuffer { let (i, key) = row return size + self.writeSearchKey(key, encloseInParenthesisIfNeeded: true) - + self.write(if: i < keys.count - 1) { () -> Int in + + write(if: i < keys.count - 1) { () -> Int in self.writeString(" ") } } diff --git a/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOption.swift b/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOption.swift index 66fc4ac7..9e1c398a 100644 --- a/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOption.swift +++ b/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOption.swift @@ -125,7 +125,7 @@ extension EncodeBuffer { // servers will fail to parse this correctly. return self.writeString(" RETURN (") - + self.writeIfExists(options) { (options) -> Int in + + writeIfExists(options) { (options) -> Int in self.writeArray(options, parenthesis: false) { (option, self) in self.writeSearchReturnOption(option) } diff --git a/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOptionExtension.swift b/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOptionExtension.swift index 8bb424ff..3a6c192f 100644 --- a/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOptionExtension.swift +++ b/Sources/NIOIMAPCore/Grammar/Search/SearchReturnOptionExtension.swift @@ -21,7 +21,7 @@ extension EncodeBuffer { _ option: KeyValue, ParameterValue?> ) -> Int { self.writeExtensionKey(option.key) - + self.writeIfExists(option.value) { (params) -> Int in + + writeIfExists(option.value) { (params) -> Int in self.writeSpace() + self.writeParameterValue(params) } } diff --git a/Sources/NIOIMAPCore/Grammar/SectionSpec.swift b/Sources/NIOIMAPCore/Grammar/SectionSpec.swift index 84eb531e..b5ae9190 100644 --- a/Sources/NIOIMAPCore/Grammar/SectionSpec.swift +++ b/Sources/NIOIMAPCore/Grammar/SectionSpec.swift @@ -354,7 +354,7 @@ extension EncodeBuffer { @discardableResult mutating func writeSection(_ section: SectionSpecifier?) -> Int { self.writeString("[") - + self.writeIfExists(section) { (spec) -> Int in + + writeIfExists(section) { (spec) -> Int in self.writeSectionSpecifier(spec) } + self.writeString("]") } @@ -365,7 +365,7 @@ extension EncodeBuffer { } return self.writeSectionPart(spec.part) - + self.writeIfExists(spec.kind) { (kind) -> Int in + + writeIfExists(spec.kind) { (kind) -> Int in self.writeSectionKind(kind, dot: spec.part.array.count > 0 && spec.kind != .complete) } } diff --git a/Sources/NIOIMAPCore/Grammar/SelectParameter.swift b/Sources/NIOIMAPCore/Grammar/SelectParameter.swift index e5cc8630..8b3ecf2f 100644 --- a/Sources/NIOIMAPCore/Grammar/SelectParameter.swift +++ b/Sources/NIOIMAPCore/Grammar/SelectParameter.swift @@ -180,7 +180,7 @@ extension EncodeBuffer { return self.writeString("CONDSTORE") case .objectID(let compound): return self.writeString("OBJECTID") - + self.writeIfExists(compound) { (compound) -> Int in + + writeIfExists(compound) { (compound) -> Int in self.writeSpace() + self.writeCompoundObjectID(compound) } } @@ -189,10 +189,10 @@ extension EncodeBuffer { @discardableResult mutating func writeQResyncParameter(param: QResyncParameter) -> Int { self.writeString("QRESYNC (\(param.uidValidity.rawValue) ") + self.writeModificationSequenceValue(param.modificationSequenceValue) - + self.writeIfExists(param.knownUIDs) { (set) -> Int in + + writeIfExists(param.knownUIDs) { (set) -> Int in self.writeSpace() + self.writeUIDSet(set) } - + self.writeIfExists(param.sequenceMatchData) { (data) -> Int in + + writeIfExists(param.sequenceMatchData) { (data) -> Int in self.writeSpace() + self.writeSequenceMatchData(data) } + self.writeString(")") } diff --git a/Sources/NIOIMAPCore/Grammar/Sequence/SequenceRange.swift b/Sources/NIOIMAPCore/Grammar/Sequence/SequenceRange.swift index 1f752c8e..579f3055 100644 --- a/Sources/NIOIMAPCore/Grammar/Sequence/SequenceRange.swift +++ b/Sources/NIOIMAPCore/Grammar/Sequence/SequenceRange.swift @@ -19,7 +19,7 @@ import struct NIO.ByteBuffer extension EncodeBuffer { @discardableResult mutating func writeSequenceRange(_ range: SequenceRange) -> Int { self.writeSequenceNumberOrWildcard(range.range.lowerBound) - + self.write(if: range.range.lowerBound < range.range.upperBound) { + + write(if: range.range.lowerBound < range.range.upperBound) { self.writeString(":") + self.writeSequenceNumberOrWildcard(range.range.upperBound) } } diff --git a/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtension.swift b/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtension.swift index 1072deff..e22ff400 100644 --- a/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtension.swift +++ b/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtension.swift @@ -42,7 +42,7 @@ extension EncodeBuffer { _ param: KeyValue, ParameterValue?> ) -> Int { self.writeExtensionKey(param.key) - + self.writeIfExists(param.value) { (value) -> Int in + + writeIfExists(param.value) { (value) -> Int in self.writeSpace() + self.writeParameterValue(value) } } diff --git a/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtensiontComp.swift b/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtensiontComp.swift index 80675b46..b25cfc7c 100644 --- a/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtensiontComp.swift +++ b/Sources/NIOIMAPCore/Grammar/Tagged/TaggedExtensiontComp.swift @@ -18,7 +18,7 @@ import struct NIO.ByteBuffer extension EncodeBuffer { @discardableResult mutating func writeTaggedExtensionComp(_ comp: [String]) -> Int { - self.write(if: comp.count >= 1) { + write(if: comp.count >= 1) { self.writeArray(comp) { (string, self) in self.writeIMAPString(string) } diff --git a/Sources/NIOIMAPCore/Grammar/UID/MessageIdentifierRange.swift b/Sources/NIOIMAPCore/Grammar/UID/MessageIdentifierRange.swift index 3ec341d1..1fe99bf7 100644 --- a/Sources/NIOIMAPCore/Grammar/UID/MessageIdentifierRange.swift +++ b/Sources/NIOIMAPCore/Grammar/UID/MessageIdentifierRange.swift @@ -208,7 +208,7 @@ extension EncodeBuffer { let a = descending ? range.range.upperBound : range.range.lowerBound let b = descending ? range.range.lowerBound : range.range.upperBound return self.writeMessageIdentifier(a) - + self.write(if: range.range.lowerBound < range.range.upperBound) { + + write(if: range.range.lowerBound < range.range.upperBound) { self.writeString(":") + self.writeMessageIdentifier(b) } } diff --git a/Sources/NIOIMAPCore/Grammar/URLCommand.swift b/Sources/NIOIMAPCore/Grammar/URLCommand.swift index 4375de62..b9451cb5 100644 --- a/Sources/NIOIMAPCore/Grammar/URLCommand.swift +++ b/Sources/NIOIMAPCore/Grammar/URLCommand.swift @@ -84,7 +84,7 @@ extension EncodeBuffer { return self.writeEncodedSearchQuery(list) case .fetch(path: let path, authenticatedURL: let authenticatedURL): return self.writeMessagePath(path) - + self.writeIfExists(authenticatedURL) { authenticatedURL in + + writeIfExists(authenticatedURL) { authenticatedURL in self.writeIAuthenticatedURL(authenticatedURL) } } diff --git a/Sources/NIOIMAPCore/Grammar/UserInfo.swift b/Sources/NIOIMAPCore/Grammar/UserInfo.swift index c8c8e4f8..9d38fe36 100644 --- a/Sources/NIOIMAPCore/Grammar/UserInfo.swift +++ b/Sources/NIOIMAPCore/Grammar/UserInfo.swift @@ -82,10 +82,10 @@ public struct UserAuthenticationMechanism: Hashable, Sendable { extension EncodeBuffer { @discardableResult mutating func writeUserAuthenticationMechanism(_ data: UserAuthenticationMechanism) -> Int { - self.writeIfExists(data.encodedUser) { user in + writeIfExists(data.encodedUser) { user in self.writeEncodedUser(user) } - + self.writeIfExists(data.authenticationMechanism) { iAuth in + + writeIfExists(data.authenticationMechanism) { iAuth in self.writeIMAPURLAuthenticationMechanism(iAuth) } } diff --git a/Sources/NIOIMAPCore/ResponseEncodeBuffer.swift b/Sources/NIOIMAPCore/ResponseEncodeBuffer.swift index c4a36260..17c3eef1 100644 --- a/Sources/NIOIMAPCore/ResponseEncodeBuffer.swift +++ b/Sources/NIOIMAPCore/ResponseEncodeBuffer.swift @@ -195,7 +195,7 @@ extension EncodeBuffer { return self.writeString("BINARY") case .body(let section, let offset): return self.writeString("BODY") + self.writeSection(section) - + self.writeIfExists(offset) { offset in + + writeIfExists(offset) { offset in self.writeString("<\(offset)>") } case .rfc822: