Commit Graph
87 Commits
Author SHA1 Message Date
Daniel Eggert e8bb770d00 Only include CHARSET in search when there’s text (#723) 2022-12-09 15:28:23 +01:00
Daniel Eggert ad85d4a0cc Cleanup CustomDebugStringConvertible conformance (#713)
With this PR the implementation of `CustomDebugStringConvertible` generally uses new `makeDescription` convenience methods on the three encode buffers, e.g.:
```swift
extension ResponseEncodeBuffer {
    static func makeDescription(_ closure: (inout ResponseEncodeBuffer) -> Void) -> String
}
```
such that conformance can be implemented as e.g.
```swift
extension Command: CustomDebugStringConvertible {
    public var debugDescription: String {
        CommandEncodeBuffer.makeDescription {
            $0.writeCommand(self)
        }
    }
}
```

This also adds `CustomDebugStringConvertible` to `MessageAttribute` and `StreamingKind`.
2022-09-10 12:35:32 +02:00
Daniel Eggert 6c256a6baf Add support for encoding custom commands (#693)
This _only_ handles _encoding_ of custom commands.

This simply adds a
```swift
case custom(name: String, payloads: [CustomCommandPayload])
```
such that clients of this library do their own encoding of such commands.

This is related to the discussion in #92
2022-02-20 23:04:36 -08:00
Daniel Eggert 3726eb0fa5 Fix RFC 4731 vs. RFC 3501 style search commands (#688)
The existing code was not able to differentiate between

A1 SEARCH ANSWERED
A1 SEARCH RETURN () ANSWERED
commands. The former is an RFC 3501 style search, the latter an RFC 4731 style search.

RFC 3501 does not allow for any RETURN options.

With this PR, those get mapped to

public enum Command: Hashable {
    ...
    case search(key: SearchKey, charset: String? = nil, returnOptions: [SearchReturnOption] = [])
such that returnOptions are empty for RFC 3501 style searches, wheras RFC 4731 style searches will always contain at least one element.

Note that RETURN () is a shorthand for RETURN (ALL), and as such gets mapped to [.all].

This is called out in the comments for Command.search.

Also

The SearchCorrelator’s tag is now a String to align with TaggedCommand’s tag.

SearchReturnData now uses UnknownMessageIdentifier instead of Int for min and max.
2022-02-18 21:14:22 -08:00
Daniel Eggert 879c1bff09 Fix Log Redaction of PII (#683) 2022-02-07 17:35:50 +01:00
David Evans 8ac6696b3c Implement encoding logging mode for redaction (#678)
Resolves #662

Command/Response Encoder can be configured using loggingMode. If turned on then user-sensitive strings won't be encoding, but any metadata will.

For example, 1 LOGIN username password becomes 1 LOGIN "" "", thereby hiding the user's information.
2022-01-26 15:50:12 -08:00
David Evans 4411870711 Use proper store modifiers (#660)
Resolves #656

The UID STORE command takes an OrderedDictionary argument for the modifiers. This is both inconvenient and technically incorrect as it doesn't store the right kind of data.
2021-12-15 15:41:42 +00:00
Daniel Eggert 76a25fa7ff Don’t output empty fetch modifiers. Fixes #658 (#659) 2021-12-14 16:11:33 +01:00
David Evans 6382eba97e Actually use fetch modifiers (#654)
Resolves #603

We previously defined FetchModifier, but forgot to use them in the fetch command.

Now they're actually used.
2021-12-13 17:30:51 +00:00
David Evans fe03b16eb1 Fix Hashable implementations across all types (#648)
Resolves #634

The majority of types that were Equatable are now Hashable.

Anywhere that we had a custom == and the type was also Hashable we also now have custom hash functions.
2021-12-10 13:58:41 +00:00
David Evans 11469f3d9b Conform CommandStreamPart, TaggedCommand, and Command to CustomDebugStringConvertible (#647) 2021-12-09 16:45:17 +00:00
David Evans d8a2deb0e3 Use typealiases (#642)
UIDRange == MessageIdentifierRange<UID>
UIDSet == MessageIdentifierSet<UID>
UIDSetNonEmpty == MessageIdentifierSetNonEmpty<UID>

SequenceRange == MessageIdentifierRange<SequenceNumber>
SequenceSet == MessageIdentifierSet<SequenceNumber>
2021-11-30 20:34:07 +00:00
David Evans 0490280833 Remove SequenceRange and SequenceRangeSet (#640)
Note - I'll update documentation in a follow-up PR

Remove SequenceRange and SequenceRangeSet and replace with new MessageIdentifier* types.

Motivation:

There was lots of very complicated duplicate code, and there was about to be more if we didn't make the new MessageIdentifier types.

Modifications:

Replace basically every occurrence of SequenceRange with MessageIdentifierRange<SequenceNumber> and SequenceRangeSet with MessageIdentifierSet<SequenceRangeNumber>.
Result:

Lots of lines deleted.
2021-11-30 10:52:46 +00:00
David Evans d936fce407 Replace UIDSet* with generic MessageIdentificationSet (#638)
In a previous PR we made UID conform to a new protocol MessageIdentifier. This PR continues the trend of removing concrete types and replacing them with generic types.

In this case we have UIDSet and UIDSetNonEmpty. These are identical to SequenceNumberSet and SequenceNumberSetNonEmpty. To allow us to remove the duplicate code a new generic type MessageIdentifierSet has been defined that takes a generic parameter T: MessageIdentifier. Both UID and SequenceNumber conform to MessageIdentifier.

In the next PR I will remove the code for SequenceNumberSet* and replace with MessageIdentifierSet. This PR only addresses the UIDSet* types.

Note: I will update all documentation in another (probably the last) PR.
2021-11-24 09:53:56 +00:00
Daniel Eggert 2eec7bd240 Rename “rename” argument “params” → “parameters” (#627) 2021-10-13 12:26:13 +01:00
Daniel Eggert 8ef2b091ee Change Command.examine to use SelectParameter (#626)
* Change Command.examine to use SelectParameter. Fixes #600

`SELECT` and `EXAMINE` are really two variants of the same command — they should take the same parameters.

* soundness

* Fixes

* Fixes
2021-10-13 12:01:35 +01:00
David Evans 88c224f737 Add ability to store gmail labels (#620) 2021-09-10 18:04:15 +01:00
David Evans 708944174f Implement compress extension (RFC 4978) (#593)
Resolves #554

COMPRESS is quite a small extension. It adds a new capability and a command, so there's not much to see. Parsing and encoding is fully implemented and tested using the existing testing framework.
2021-07-30 17:32:43 +01:00
David Evans 79657fd985 Track command tags and restrict potential concurrent commands. (#596)
In most cases in IMAP it's possible to allow multiple commands to run concurrently. However, in some cases this would lead to undefined behaviour.

In particular, when appending, append is the only command that can be sent/active, as for authenticating, and obviously IDLE.

This PR implements that by tracking the outgoing tags, and the incoming tagged responses.
2021-07-30 11:04:15 +01:00
David Evans d696611e6c Fix references (#591) 2021-07-13 09:00:57 +01:00
Daniel Eggert 9987d80be1 Add support for expressing Pipelining Behavior (#569)
Add support for expressing Pipelining Behavior

Motivation:

IMAP supports command pipelining. But there are restrictions as to what commands can be run at the same time.

This is described in RFC 3501 section 5.5. “Multiple Commands in Progress”.

With this change, it’s possible to know if a specific command can be run while a given set of commands is running.
2021-06-11 16:06:58 +01:00
David Evans db0f559b05 Rename to startTLS (#580) 2021-06-08 11:34:26 +01:00
David Evans 794c94e56a Fix typo in extendedsearch (#576)
Resolves #571

Command.extendedsearch -> Command.extendedSearch
2021-06-04 12:29:35 +01:00
David Evans 67f1d23383 Add MetadataEntryName type (#575)
* Add MetadataEntryName type

* Soundness
2021-06-04 12:26:05 +01:00
David Evans a66eeb228b Use SPI to remove underscored members (#567)
Resolves #556

We've talked quite a bit offline, and decided that for now @_spi is the way to go, as it avoids build system issues. The goal is to remove the number of underscored public types and fields.
2021-06-02 19:21:47 +01:00
David Evans 8565ac900e Rename Command types to better represent what they are (#557)
Resolves #522

Some command names were misleading, they should be better now. Also removed a redundant initialiser.

PartialCommandStream -> SynchronizedCommand

CommandStream -> CommandStreamPart
2021-05-21 16:39:22 +01:00
David Evans 10bdc22671 Replace KeyValues with OrderedDictionary from swift-collections (#546)
* Add swift-collections

* Delete KeyValues

* Soundness

* Fix comment
2021-04-14 10:05:06 +01:00
David Evans ff1b31f5f3 Remove superfluous underscores. (#548)
Way too many things were underscored that really didn't need to be.
2021-04-13 10:48:34 +01:00
David Evans 51f3058447 Rename authentication method and InitialClientResponse (#545)
* Rename method to mechanism

* Rename InitialClientResponse to ClientResponse

* Rename AuthKind to AuthMechanism
2021-04-12 15:22:10 +01:00
David Evans 0654d550e5 Fix continuation request state tracking to disambiguate idle and authentication (#526)
* Fix state tracking

* Soundness

* Fix tests

* Fix auth encoding

* Make state private

* Add reentrancy test

* Add asserts

* Better error types

* Soundness

* Use "real" example base64

* Soundness

* PR review

* Soundness

* Fix rebase
2021-04-07 13:41:52 +01:00
David Evans 919d6d0be4 Use KeyValues<String, String?> for ID data (#521) 2021-04-06 12:55:49 +01:00
David Evans a719f935b6 Use AuthenticationKind in Command.authenticate (#491)
* Make authentication kind it's own thing

* Make auth kind var non-public

* Fix compile

* Rebase
2021-03-18 11:45:35 +00:00
David Evans 81c8e9158d Underscore EncodeBuffer (#479)
* Underscore

* Underscore everything

* Add soundness self insert
2021-03-18 11:25:05 +00:00
David Evans 3bdebc12bd Address API review comments part 1 (#474)
* Rename Date to IMAPDate

* Rename all esearch types to extended search

* Rename Address to EmailAddress

* Rename genUrlAuth

* Rename Auth to Authorization

* Rename IServer

* Rename IUserInfo

* Soundness
2021-03-11 11:31:52 +00:00
David Evans 1e0f89fd11 Non empty UID set (#448)
* Convert UIDSet to LastCommandSet

* Soundness

* Define UIDSetNonEmpty

* Use UIDSetNonEmpty

* Soundness

* Fix tests

* Soundness

* Convenience funcs

* Soundness

* Fix compile

* Use parseOneOf

* Soundness
2021-03-05 17:48:42 +00:00
David Evans 6191061fb4 Create generic type to wrap a set or IMAP "last result" (#463)
* Define last command set type

* Replace SequenceSet

* Docs

* Soundness

* Update dates

* Rename last command set

* Cleanup

* Update docs
2021-03-04 14:45:12 +00:00
David Evans 33d6060046 Final key value refactor (#432)
* Remove a load of parameter types

* Remove NameSpaceResponseExtension

* Remove SearchModificationSequenceExtension

* Remove SearchReturnDataExtension

* Remove SearchReturnOptionExtension

* Soundness
2021-02-05 12:09:00 +00:00
David Evans df5074856c Remove all minor Key/Value types (#430)
* Define basic KeyValue type

* Remove TaggedExtension

* Replace Parameter

* Remove ParameterPair

* Remove EntryValue

* Remove OptionExtension

* Soudness

* Docs

* Inline

* Soundness

* PR comments
2021-02-04 11:03:41 +00:00
David Evans f056b14fa6 Refactor out ID parameter and replace with new KeyValues type (#424)
* Add conveniences

* Make iteratable

* Add ID example

* Add docs

* Converting backing to KeyValue struct

* Fix soundness
2021-02-01 18:12:12 +00:00
David Evans 8ad4a69522 Fix encode (#411) 2021-01-21 15:26:36 +00:00
David Evans 0b29dcb192 Encode missing space in CREATE command (#410)
* Encode missing space

* Fix sanity
2021-01-21 15:01:25 +00:00
David EvansandDaniel Eggert 7d6997edcf Enable custom continuation handling (#372)
* Client handler outputs responseorcontinuations

* Finish implementation

* Remove BB array from authenticate

* Fix sanity

* Refactor

* Fix sanity

* Apply suggestions from code review

Co-authored-by: Daniel Eggert <daniel.eggert@hoerbuch.dk>

* Rename to continuation response

* Fix compile

* Fix tests

* Fix sanity

* PR comments

* Fix sanity

Co-authored-by: Daniel Eggert <daniel.eggert@hoerbuch.dk>
2021-01-05 17:21:38 +00:00
David Evans c418cdcd2a Rename URL Rump mechanism (#395) 2021-01-05 16:06:41 +00:00
David Evans 135f473bf6 Documentation PR part 5 (#383)
* 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

* PR review

* Fix sanity

* Document FullDate
2020-12-10 12:37:05 +00:00
David EvansandGeorge Barnett 475c53f168 Documentation PR part 1 (#373)
* Document AppendData

* Document AppendMessage

* Document AppendOptions

* Document BodyStructure.Disposition

* Document BodyStructure.DispositionAndLanguage

* Document BodyStructure.Encoding

* Document BodyStructure helper typoes/conformances

* Document BodyStructure.Singlepart

* Document BodyStructure.Singlepart.Kind

* Document BodyStructure.Singlepart.Message

* Document BodyStructure.Singlepart.Text

* Document BodyStructure.Singlepart.Extension

* Document Command

* Document TaggedCommand

* Make base64 non-public

* Fix sanity

* Remove doc tracking

* Apply suggestions from code review

Co-authored-by: George Barnett <gbarnett@apple.com>

Co-authored-by: George Barnett <gbarnett@apple.com>
2020-12-03 14:02:22 +00:00
David EvansandCory Benfield 0b4bc1a702 Documentation (part 1 of many) (#368)
* Update Access docs

* Update AppendCommand docs

* Update CatenateData docs

* BodyExtension docs

* Main BodyStructure docs

* Disposition docs

* Add disposition docs

* Encoding docs

* Fields docs

* Document language location

* Document and refine LocationExtensions API

* Document ParameterPair

* Document multipart

* Document multipart extension

* Apply suggestions from code review

Co-authored-by: Cory Benfield <lukasa@apple.com>

* Fix sanity

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-11-18 18:41:09 +00:00
David EvansandGeorge Barnett 78b55555bf Add some documentation (#341)
* Fix documentation

* Remove link to NIO http 2

* Document TooDeep error

* Remove ParsingError

* Make GrammarParser non-public

* Better UTF7 errors

* Document Access

* Document CommandStream types

* Partially document `Command`

* Document date

* Document Access

* Update Sources/NIOIMAPCore/Grammar/Date/Date.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Update Sources/NIOIMAPCore/Grammar/Access.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Update Sources/NIOIMAPCore/Grammar/Command/CommandStream.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Fix typo

Co-authored-by: George Barnett <gbarnett@apple.com>
2020-10-26 09:54:46 +00:00
David EvansandGeorge Barnett 9642c5a063 Document the various core writing functions. (#333)
* Simplify array has minimum size

* Document the writing functions

* Fix sanity

* Many documentation comments

* Update Sources/NIOIMAPCore/ByteBuffer+WriteLiteral.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Address PR comments

* PR comments

Co-authored-by: George Barnett <gbarnett@apple.com>
2020-10-13 11:39:45 +01:00
David EvansandGeorge Barnett 4c72d6c9bb Implement RFC 4467 URL Auth (#329)
* Define URL Auth types with tests

* Finish

* Fix sanity

* Add todo

* Fix sanity

* Move writing spaces out

* Fix sanity

* George PR comments

* Fix sanity

* Move prefix to start of array

* Update Sources/NIOIMAPCore/Grammar/Command/Command.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

Co-authored-by: George Barnett <gbarnett@apple.com>
2020-10-09 13:11:38 +01:00
Matt Diephouse 8cab632576 Don't add an empty parameter list to SELECT (#331) 2020-10-08 23:39:44 +01:00