Skip to content

Commit

Permalink
Need to lock the NilTokens List since multiple threads may be trying …
Browse files Browse the repository at this point in the history
…to add to it
  • Loading branch information
jstedfast committed Aug 20, 2023
1 parent 6ed1bef commit 50b06a7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions MailKit/Net/Imap/ImapToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,21 @@ public static ImapToken Create (ImapTokenType type, ByteArrayBuilder builder)
}
} else if (type == ImapTokenType.Atom) {
if (builder.Equals ("NIL", true)) {
foreach (var token in NilTokens) {
value = (string) token.Value;
// Look for the cached NIL token that matches this capitalization.
lock (NilTokens) {
foreach (var token in NilTokens) {
value = (string) token.Value;

if (builder.Equals (value))
return token;
}
if (builder.Equals (value))
return token;
}

var nil = new ImapToken (ImapTokenType.Nil, builder.ToString ());
NilTokens.Add (nil);
// Add this new variation to our NIL token cache.
var nil = new ImapToken (ImapTokenType.Nil, builder.ToString ());
NilTokens.Add (nil);

return nil;
return nil;
}
}

if (builder.Equals ("FETCH", false))
Expand Down

0 comments on commit 50b06a7

Please sign in to comment.