Skip to content

Commit 9b94b1c

Browse files
committed
Fixed tokenization of atom tokens that start with +
Don't assume that if the first char of a token is a + that it's the only character in the atom string. Fixes issue #1914
1 parent 6d5bd5d commit 9b94b1c

File tree

7 files changed

+87
-83
lines changed

7 files changed

+87
-83
lines changed

MailKit/Net/Imap/ImapStream.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,6 @@ public ImapToken ReadToken (string specials, CancellationToken cancellationToken
836836
if (c == '\\')
837837
return ReadFlagToken (specials, cancellationToken);
838838

839-
if (c == '+') {
840-
inputIndex++;
841-
842-
return ImapToken.Plus;
843-
}
844-
845839
if (IsAtom (input[inputIndex], specials))
846840
return ReadAtomToken (specials, cancellationToken);
847841

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

891-
if (c == '+') {
892-
inputIndex++;
893-
894-
return ImapToken.Plus;
895-
}
896-
897885
if (IsAtom (input[inputIndex], specials))
898886
return await ReadAtomTokenAsync (specials, cancellationToken).ConfigureAwait (false);
899887

MailKit/Net/Imap/ImapToken.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public static ImapToken Create (ImapTokenType type, ByteArrayBuilder builder)
155155
}
156156
}
157157

158+
if (builder.Equals ("+", false))
159+
return Plus;
158160
if (builder.Equals ("OK", false))
159161
return Ok;
160162
if (builder.Equals ("FETCH", false))

UnitTests/Net/Imap/ImapClientTests.cs

Lines changed: 79 additions & 71 deletions
Large diffs are not rendered by default.

UnitTests/Net/Imap/Resources/gmail/list-all-no-status.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* LIST (\HasNoChildren \Subscribed) "/" "INBOX"
2+
* LIST (\HasNoChildren \Subscribed) "/" +Folder
23
* LIST (\HasChildren \NonExistent \Subscribed) "/" "[Gmail]"
34
* LIST (\HasNoChildren \Subscribed) "/" "[Gmail]/All Mail"
45
* LIST (\HasNoChildren \Subscribed) "/" "[Gmail]/Drafts"

UnitTests/Net/Imap/Resources/gmail/list-all.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
* LIST (\HasNoChildren \Subscribed) "/" "INBOX"
22
* STATUS "INBOX" (HIGHESTMODSEQ 41234 MESSAGES 60 RECENT 0 UIDNEXT 410 UIDVALIDITY 1 UNSEEN 0 SIZE 1024 MAILBOXID (d0f3b017-d3ec-40aa-9bb9-66c1aeccbb24))
3+
* LIST (\HasNoChildren \Subscribed) "/" +Folder
4+
* STATUS +Folder (HIGHESTMODSEQ 41234 MESSAGES 6 RECENT 0 UIDNEXT 7 UIDVALIDITY 1 UNSEEN 0 SIZE 1024 MAILBOXID (f001Ed6c-ebee-41a5-a65e-9498d3e0aec0))
35
* LIST (\HasChildren \NonExistent \Subscribed) "/" "[Gmail]"
46
* LIST (\HasNoChildren \Subscribed) "/" "[Gmail]/All Mail"
57
* STATUS "[Gmail]/All Mail" (HIGHESTMODSEQ 41234 MESSAGES 67 RECENT 0 UIDNEXT 1210 UIDVALIDITY 11 UNSEEN 3 SIZE 1024 MAILBOXID (f668b57d-9f42-453b-b315-a18cd3eb0f85))

UnitTests/Net/Imap/Resources/gmail/lsub-all.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* LSUB (\HasNoChildren) "/" "INBOX"
2+
* LSUB (\HasNoChildren) "/" +Folder
23
* LSUB (\HasChildren \NonExistent) "/" "[Gmail]"
34
* LSUB (\HasNoChildren) "/" "[Gmail]/All Mail"
45
* LSUB (\HasNoChildren) "/" "[Gmail]/Drafts"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* STATUS +Folder (HIGHESTMODSEQ 41234 MESSAGES 6 RECENT 0 UIDNEXT 7 UIDVALIDITY 1 UNSEEN 0 SIZE 1024 MAILBOXID (f001Ed6c-ebee-41a5-a65e-9498d3e0aec0))
2+
A######## OK Success

0 commit comments

Comments
 (0)