Commit Graph
340 Commits
Author SHA1 Message Date
Daniel Eggert 879c1bff09 Fix Log Redaction of PII (#683) 2022-02-07 17:35:50 +01:00
Daniel Eggert bb0e803d99 UID convenience (#682) 2022-02-04 15:21:13 +01:00
Daniel Eggert 4954dc6bef Make UnknownMessageIdentifier conversion public (#680)
Need to be able to access these.
2022-02-01 10:27:42 +00: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 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
Daniel Eggert 6d7fc4cf25 Always encode non-synchronizing literal with + (#676)
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-.
2022-01-24 19:30:38 +01:00
Daniel Eggert 2caea0cf64 Make MessageIdentifierSet.RangeView conform to RandomAccessCollection (#673) 2022-01-18 16:52:28 +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
Daniel Eggert 76a25fa7ff Don’t output empty fetch modifiers. Fixes #658 (#659) 2021-12-14 16:11:33 +01:00
Daniel Eggert c2628c0721 Fix ResponseTextCode.modified convenience init (#657)
Was generating an empty set instead of converting the UID set.
2021-12-14 11:39:16 +00:00
Daniel Eggert 11bff712e2 Make ResponseTextCode indirect (#655)
Without indirect codegen would create very inefficient code that could exhaust the stack.
2021-12-14 10:22:47 +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 d487e39d8a Add conversions from UnknownMessageIdentifier wrappers to UID/SequenceNumber types (#653)
Resolves #652

MessageIdentifierSet<UnknownMessageIdentifier> <-> MessageIdentifierSet<UID>
MessageIdentifierSet<UnknownMessageIdentifier> <-> MessageIdentifierSet<SequenceNumber>
MessageIdentifierRange<UnknownMessageIdentifier> <-> MessageIdentifierRange<UID>
MessageIdentifierRange<UnknownMessageIdentifier> <-> MessageIdentifierRange<SequenceNumber>
2021-12-13 15:56:40 +00:00
Daniel Eggert 2b3149e4a7 Disallow directo conversion between SequenceNumber and UID (#651)
With this, you’d have to explicitly go through UnknownMessageIdentifier.
2021-12-13 10:33:48 +00:00
Daniel Eggert 17b0f8e467 Add isContiguous to MessageIdentifierSet (#650)
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.
2021-12-13 10:33:35 +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 11469f3d9b Conform CommandStreamPart, TaggedCommand, and Command to CustomDebugStringConvertible (#647) 2021-12-09 16:45:17 +00:00
David Evans aa1ea1b7b3 Implement MessageIdentificationNumber for SearchReturnData (#635)
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.
2021-12-06 17:47:34 +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 1639174b33 Update all docs to correctly represent types (#641)
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
2021-12-01 14:02:38 +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
David Evans c750d94d6f Refactor shift wrapper to remove duplicate types (#636)
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.
2021-11-16 13:39:25 +00:00
David Evans 6dc74a37f0 Make Mailbox/Use Attribute casing match the spec (#633)
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.
2021-11-03 13:14:06 +00:00
Daniel Eggert 9796dc79cc Add init?(exactly:) to ModificationSequenceValue (#631) 2021-10-28 10:40:42 +01:00
Daniel Eggert 9d0071fea5 Make FetchAttribute conform to CustomDebugStringConvertible (#630) 2021-10-27 10:08:10 +01:00
Daniel Eggert 2eec7bd240 Rename “rename” argument “params” → “parameters” (#627) 2021-10-13 12:26:13 +01:00
Daniel Eggert 329fd7d952 Make ResponseTextCode conform to CustomDebugStringConvertible (#628) 2021-10-13 12:25:53 +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
Daniel Eggert 87ef2cce69 Don’t upper case in MailboxName.debugDescription. Fixes #594 (#624) 2021-10-07 12:21:52 +01:00
Daniel Eggert 661688f008 Fix Gmail capability. (#623) 2021-09-27 16:27:39 +01:00
David Evans 46a6e2b8ec Extend Gmail label support for label creation and extracting string value (#621)
* Add gmail to string support

* Soundness
2021-09-17 11:39:59 +01:00
David Evans 88c224f737 Add ability to store gmail labels (#620) 2021-09-10 18:04:15 +01:00
David Evans 59a57ee70b New client state machine (#610)
The client state machine has now been fully rewritten, and encapsulates the miniature state machines implemented in previous PRs.

I've extracted the state machine from IMAPClientHandler and moved it into ClientStateMachine, hence all the code deletion.

The state machine receives a command, response, or continuation request from the IMAPClientHandler and returns an array of Chunk/EventLoopPromise pairs that the client handler should then write to the network.

Also we didn't previously queue Append commands like we did for others, however it's now become apparent that all commands types should be queued, so we do that now.

A lot of tests have been added to make sure everything works.

Note that a lot of sendCommand tests have been deleted as we now precondition on user errors instead of throwing.
2021-09-10 13:45:11 +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
Matt Diephouse 085566c41e Make ModificationSequenceValue Strideable (#618)
* Make ModificationSequenceValue strideable
2021-09-08 17:05:31 +01:00
Daniel Eggert a3a75838f8 Allow converting MailboxInfo.Attribute → UseAttribute (#613)
Special Use can be returned as part of the `LIST` response. They’ll then be wrapped in `MailboxInfo.Attribute`.

See RFC 6154 section 5.1 — https://datatracker.ietf.org/doc/html/rfc6154#section-5.1

```
C: t1 LIST "" "%"
S: * LIST (\Marked \HasNoChildren) "/" Inbox
S: * LIST (\HasNoChildren) "/" ToDo
S: * LIST (\HasChildren) "/" Projects
S: * LIST (\Sent \HasNoChildren) "/" SentMail
S: * LIST (\Marked \Drafts \HasNoChildren) "/" MyDrafts
S: * LIST (\Trash \HasNoChildren) "/" Trash
S: t1 OK done
```
2021-08-19 12:44:17 +01:00