Commit Graph
219 Commits
Author SHA1 Message Date
David Evans 480785353a Add literal size limit (#671) 2022-01-26 12:07:49 +01:00
David Evans 4e7e11cb3a Use UnknownMessageIdentifier in MailboxData.Search. (#677) 2022-01-25 09:00:45 +01:00
David Evans 81718846da Implement a string parsing cache (#672)
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.
2022-01-10 14:52:33 +00:00
Daniel Eggert a0e9de1952 Allow single CR to be a newline (#670) 2022-01-03 10:35:56 +01:00
David Evans a6f3cd5924 Enable limiting the number of fetch attributes and body size (#665)
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.
2021-12-23 13:54:05 +00:00
David Evans 69f15a10ba Convert line length limit to 8192 (#666)
Resolves #663

Convert the default limits from 1000 to 8192 octets, as per RFC 7162.
2021-12-23 13:36:54 +00:00
David Evans c4d572029e Make grammar parser non-static (#661)
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.
2021-12-17 10:54:34 +00: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
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 433f08bdc2 Rename modificationSequence to modification (#649)
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).
2021-12-10 15:02:57 +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 2fcfcb5da5 Make parseSequenceSet generic on MessageIdentifier (#645) 2021-12-03 09:36:31 +00:00
David Evans ecb3902377 Implement generic parseMessageIdentifierRange (#644)
Lots of the same code dotted around, let's remove!

Parsing ranges of UID and SequenceNumber are the same, so let's only have one version.
2021-12-02 16:16:05 +00:00
David Evans ffa2910662 Implement generic parseMessageIdentifierFunction (#643)
Lots of the same code dotted around, let's remove!

Parsing UID and SequenceNumber are the same, so let's only have one version.
2021-12-02 08:46:35 +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
Daniel Eggert 8d6b2092b5 Update MessageID documentation. Hide implementation details. (#639)
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.
2021-11-29 18:02:52 +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
David Evans 4036cd48cd Define generic message identification protocol (#637)
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.
2021-11-23 11:44:05 +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
Daniel Eggert 00f8a5c862 Various cleanup of QResyncParameter. Fixes #615 (#625)
* Fix typos.
* Fix wrong types.
2021-10-12 14:58:19 +01:00
David Evans 88c224f737 Add ability to store gmail labels (#620) 2021-09-10 18:04:15 +01:00
Matt Diephouse 30d745813b VANISHED returns UIDs, not sequence numbers (#619)
* VANISHED returns UIDs, not sequence numbers
2021-09-08 19:02:24 +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 f07f6a7289 Fix up casing (#601) 2021-07-30 10:27:47 +01:00
David Evans 4b7ba41689 Change destinationUIDValidity type to UIDValidity (#590)
Resolves #584

Previously it was Int, but we have a dedicated type to represent this data, so we should use it.
2021-07-12 15:45:39 +01:00
David Evans e02089be0e Make case naming uniform between commands and responses (#589)
Noticed by Matt, we had, for example, Command.tagged, but Response.taggedResponse. In general I've removed the superfluous Response at the end of each case.
2021-07-12 15:45:21 +01:00
David Evans 274e42b2dc Minor fixes to the ResponseCodeAppend type (#585)
Resolves #583

Minor issues were flagged in the issue. The most significant is changing the struct from containing only one UID to containing a UIDSet. This is required to enable the MULTIAPPEND capability.
2021-07-05 10:43:44 +01:00
David Evans 4c4146003e Fix references (#574) 2021-06-08 17:36:32 +01:00
David Evans 8a1323ee6d Rename and change type of UIDValidity (#581) 2021-06-08 11:46:12 +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 86bc65187b Bump minimum version to Swift 5.4 (#568)
Bump minimum version to Swift 5.4
2021-06-02 19:21:23 +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 3719201015 New failable String.init for validating if bytes are valid UTF8 (#563)
We use String(buffer: ByteBuffer) quite a lot. This isn't ideal as it may crash if the bytes are not valid UTF-8. This PR addresses that problem by providing a failable initialiser on String that will handle invalid UTF8 bytes gracefully by returning nil.
2021-05-21 12:23:53 +01:00
David Evans 8e8410a486 Support strange TaggedResponse.State and UntaggedResponseStatus cases (#550)
Resolves #361

Sometimes for both tagged and untagged responses the server will send nothing except the code, or maybe an alert as well.

This isn't at all spec compliant, but unfortunately we need to support it.
2021-04-16 22:38:27 +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 e896aa2327 Convert parsing fetch attributes to use the lookup table parser (#549)
* Begin conversion

* Full conversion to lookup table

* Soundness

* Address PR comments
2021-04-13 16:39:46 +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 0c1420b0d3 Remove IPathQuery (#544) 2021-04-08 17:56:59 +01:00
David Evans 1ba38d4320 Remove IRelativePath (#543) 2021-04-08 17:01:54 +01:00
David Evans 6524b50b29 Rename IAuthenticatedURL to AuthenticatedURL (#542) 2021-04-08 16:59:15 +01:00
David Evans cf6d698c0c Rename AuthenticatedURL to NetworkMessagePath (#540)
* Rename AuthenticatedURL to NetworkMessagePath

* Address PR comments
2021-04-08 16:15:46 +01:00
David Evans 0b0b901888 Rename IRumpAuthenticatedURL to AuthenticatedURLRump (#541) 2021-04-08 16:06:24 +01:00
David Evans d2761fe21b Rename IAbsolutePath to AbsoluteMessagePath (#537) 2021-04-08 16:06:06 +01:00
David Evans 72f340f8e5 Rename IMessageOrPartial to URLFetchType (#538)
* Rename IMessageOrPartial to URLFetchType

* Rename fetch case
2021-04-08 16:01:54 +01:00
David Evans d146a3d363 Rename INetworkPath to NetworkPath (#539)
* Rename to NetworkPath

* Fix casing
2021-04-08 16:01:19 +01:00