Skip to content

Commit

Permalink
Add an ImapTokenType.Plus enum value to simplify things a tad
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Aug 20, 2023
1 parent 7e801ec commit 8915ab5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions MailKit/Net/Imap/ImapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,7 @@ public bool Step ()
token = Engine.ReadToken (CancellationToken);
}

// FIXME: can we have a '+' token instead of using an Atom?
if (token.Type == ImapTokenType.Atom && token.Value.ToString () == "+") {
if (token.Type == ImapTokenType.Plus) {
// we've gotten a continuation response from the server
var text = Engine.ReadLine (CancellationToken).Trim ();

Expand Down Expand Up @@ -1045,8 +1044,7 @@ public async Task<bool> StepAsync ()
token = await Engine.ReadTokenAsync (CancellationToken).ConfigureAwait (false);
}

// FIXME: can we have a '+' token instead of using an Atom?
if (token.Type == ImapTokenType.Atom && token.Value.ToString () == "+") {
if (token.Type == ImapTokenType.Plus) {
// we've gotten a continuation response from the server
var text = (await Engine.ReadLineAsync (CancellationToken).ConfigureAwait (false)).Trim ();

Expand Down
12 changes: 12 additions & 0 deletions MailKit/Net/Imap/ImapStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,12 @@ public ImapToken ReadToken (string specials, CancellationToken cancellationToken
if (c == '\\')
return ReadFlagToken (specials, cancellationToken);

if (c == '+') {
inputIndex++;

return ImapToken.Plus;
}

if (IsAtom (input[inputIndex], specials))
return ReadAtomToken (specials, cancellationToken);

Expand Down Expand Up @@ -882,6 +888,12 @@ public async ValueTask<ImapToken> ReadTokenAsync (string specials, CancellationT
if (c == '\\')
return await ReadFlagTokenAsync (specials, cancellationToken).ConfigureAwait (false);

if (c == '+') {
inputIndex++;

return ImapToken.Plus;
}

if (IsAtom (input[inputIndex], specials))
return await ReadAtomTokenAsync (specials, cancellationToken).ConfigureAwait (false);

Expand Down
3 changes: 3 additions & 0 deletions MailKit/Net/Imap/ImapToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ enum ImapTokenType {
Asterisk = (int) '*',
OpenBracket = (int) '[',
CloseBracket = (int) ']',
Plus = (int) '+',
}

class ImapToken
{
public static readonly ImapToken Plus = new ImapToken (ImapTokenType.Plus, '+');
public static readonly ImapToken Asterisk = new ImapToken (ImapTokenType.Asterisk, '*');
public static readonly ImapToken OpenParen = new ImapToken (ImapTokenType.OpenParen, '(');
public static readonly ImapToken CloseParen = new ImapToken (ImapTokenType.CloseParen, ')');
Expand Down Expand Up @@ -105,6 +107,7 @@ class ImapToken
public static ImapToken Create (ImapTokenType type, char c)
{
switch (type) {
case ImapTokenType.Plus: return Plus;
case ImapTokenType.Asterisk: return Asterisk;
case ImapTokenType.OpenParen: return OpenParen;
case ImapTokenType.CloseParen: return CloseParen;
Expand Down

0 comments on commit 8915ab5

Please sign in to comment.