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.
RFC 7888, section 5 says:
> Note that the form of the non-synchronizing literal does not change: it still uses the "+" in the literal itself, even if the applicable extension is LITERAL-.
Resolves#669
Maintaining many versions of the same string can be expensive for strings over a given size (10 bytes), where they become heap-allocated. For example, in IMAP there may be many thousands of messages with the same flags (e.g. deleted, seen, replied).
Here we introduce a user-controllable cache that allows the user to provide a single instances of some strings if they require. Whenever we parse an atom (i.e. a string), that string is passed to the cache (which defaults to just returning the string), which may then return a cached version.
Resolves#402
To prevent a massive amount of fetch attributes from being sent maliciously, the parser now supports a configurable limit on how many fetch attributes are allowed. If this limit is exceeded then an error is thrown.
Added some tests to show that this works for both "simple" attributes, and ones that involve streaming.
Support appending a `UnsafeRawBufferPointer`. This is useful when the input is `Data` or `DispatchData`.
Add `inputBufferByteCount: Int` property -- which is useful for logging and tests.
Add `testTwoCommandsAcrossMultipleBuffers()` test case.
The static grammar parser has served us well and has been very easy to use. Sadly, however, the time for static to die has arrived, as we now need the parser to be configurable with certain limits (e.g. maximum supported message body size).
This is kind of simple, just remove static from everywhere, and then use instances of the parser instead of calling the static methods.
It is massive though, sorry.
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.
With the recent changes to message identifier set it’s no longer possible to access the range count, but we’d only ever need that to calculate isContiguous. Moving this into NIOIMAPCore seems like the better approach.
Resolves#604
Rename modificationSequence to just modified as it might not contain SequenceNumbers. Also change the associated type from SequenceSet (aka MessageIdentifierSet<SequenceNumber>) to UnknownIdentifier, which can then be treated as either UIDs or SequenceNumbers depending on what the user is expecting.
(Note this is required as it is impossible to distinguish between SequenceNumbers and UIDs when parsing).
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.
This introduces FramingResult, which signals either a "complete" frame, "incomplete", or "invalid".
If a frame is incomplete then the minimum number of required bytes to make a complete frame are sent.
if a frame is invalid or complete then you are provided with the bytes in that frame.
Invalid frames are forwarded onto the user via user events.
It doesn't have many bells and whistles yet, but it handles a lot of use cases we'll see in the wild, and you'll probably still find it useful
Given the command A1 LOG it will delivered .incompleteFrame(2) to signal that this frame is incomplete, and that we need at least 2 more bytes (in this case the CR and LF) to complete the frame (this is because it doesn't have the ability to understand the login command fully as it's only used to build frames).
Given the command A1 LOGIN {3}\r\na it will deliver 2 frames:
.complete("A1 LOGIN {3}\r\n
.complete("a") this is a "complete" frame because we're streaming a literal, so need to forward all bytes as soon as possible
Finally a case of invalid, A1 LOGIN {a will deliver 1 frame containing the data, including the byte where we detected the issue: .invalid("A1 LOGIN {a")
Resolves#605
SearchReturnData may contain either a UIDSet or SequenceNumber. The two have different meanings, however because they appear identical it is not possible to distinguish while parsing. To get around this we now have a MessageIdentificationNumber type from which either UIDs or SequenceNumbers can be extracted.
Due to all the changes to create generic types a lot of the types specified in various bits of documentation were actually wrong. They've been fixed.
Also delete a redundant duplicate function writeUID
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.
Message-IDs look like <B27397-0100000@cac.washington.edu> — and there’s often confusion about if the < + > are included in its representation. Thus, calling out that they are included helps. 😄
Also: hide the rawValue implementation details to align with the project code style.
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.
A "message identifier" can be a UID, a SequenceNumber, or an unknown instance of the two (because they look the same it's impossible to distinguish when parsing).
Originally we had the 3 types duplicated 3 times, however this PR brings us closer to have one implementation. While code duplication isn't usually "that bad", in this case it can be an issue as :
The code is complicated
There's a lot of it
This PR works to address a few things, using the UID type as a proof-of-concept:
Make UID conform to a protocol MessageIdentifier
Create a new MessageIdentifierRange type that will eventually replace the UIDRange and SequenceNumberRange types.
Remove UIDShiftWrapper and SequenceNumberWrapper as they did the same thing for UIDs and SequenceNumbers respectively.
Motivation:
The code was identical, just with different names.
Modifications:
Remove UIDShiftWrapper and SequenceNumberWrapper and replace with a new MessageIdentificationNumber type.
Result:
Less code, more code reuse, more happiness.
Resolves#612
The IMAP RFC dictates that casing for constants shouldn't matter, however there was a bug in the constants we were using that made this sometimes untrue, as we used an internal init to provide a fast path for known attributes. This fast path assumed that the constants were already lowercased, however a couple weren't.
The bug has been fixed by removing the fast path. As a nicety towards mail we also now preserve the case, however manually make equality comparisons non-case-sensitive.
* 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
* Boilerplate
* Add extremely simple tests cases
* Basic literal support
* Add literal+, literal-, and binary support
* Fix backtracking
* Start some integration tests
* A few type renames
* Make the framer throwing
* Soundness
* Address some of Cory's comments
* More graceful handling or CRs and LFs
* Apple Cory suggestions part 2
* Swallow LF
* Make it all work
* Refactor
* Define LineFeedStrategy enum
* Refactor integer parsing and add frame status
* Digit constants
* Refactor adjusting frame length
* Defend against infinite size
* Fix literal bugs
* Soundness
* Add some docs
* Update Sources/NIOIMAP/Client/FramingParser.swift
Co-authored-by: Cory Benfield <lukasa@apple.com>
* Prefer () over break
* Use UInt64 where appropriate
* Implement a stepback function
* Fix FrameSatus typo
* Don't allocate 2 buffers
* Rename LiteralSubstate to LiteralHeaderState
* Use Float64
* Remove frame debugging function
* Fix empty frame logic
* Discard empty bytes
* Fix handing optional LF in a literal
* Soundness
* Remove random Darwin import
* Cory nits
* Discard when we've read over half the buffer
* Read at least 1KB before cleaning
* Soundness
* Fix precondition
Co-authored-by: Cory Benfield <lukasa@apple.com>