Skip to content

Commit

Permalink
Refactored some of ImapUtils to split sync/async
Browse files Browse the repository at this point in the history
Part of an ongoing effort to fix issue #1335
  • Loading branch information
jstedfast committed Dec 27, 2023
1 parent 7df2cfe commit c2b4695
Show file tree
Hide file tree
Showing 4 changed files with 983 additions and 223 deletions.
4 changes: 2 additions & 2 deletions MailKit/Net/Imap/ImapEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ internal void ProcessUntaggedResponse (CancellationToken cancellationToken)
} while (true);
} else if (atom.Equals ("FLAGS", StringComparison.OrdinalIgnoreCase)) {
var keywords = new HashSet<string> (StringComparer.Ordinal);
var flags = ImapUtils.ParseFlagsListAsync (this, atom, keywords, doAsync: false, cancellationToken).GetAwaiter ().GetResult ();
var flags = ImapUtils.ParseFlagsList (this, atom, keywords, cancellationToken);
folder.UpdateAcceptedFlags (flags, keywords);
token = ReadToken (cancellationToken);

Expand Down Expand Up @@ -2491,7 +2491,7 @@ internal async Task ProcessUntaggedResponseAsync (CancellationToken cancellation
} while (true);
} else if (atom.Equals ("FLAGS", StringComparison.OrdinalIgnoreCase)) {
var keywords = new HashSet<string> (StringComparer.Ordinal);
var flags = await ImapUtils.ParseFlagsListAsync (this, atom, keywords, doAsync: true, cancellationToken).ConfigureAwait (false);
var flags = await ImapUtils.ParseFlagsListAsync (this, atom, keywords, cancellationToken).ConfigureAwait (false);
folder.UpdateAcceptedFlags (flags, keywords);
token = await ReadTokenAsync (cancellationToken).ConfigureAwait (false);

Expand Down
16 changes: 8 additions & 8 deletions MailKit/Net/Imap/ImapFolderFetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void ParseSummaryItems (ImapEngine engine, MessageSummary message, FetchSummaryI
message.Fields |= MessageSummaryItems.Size;
} else if (atom.Equals ("BODYSTRUCTURE", StringComparison.OrdinalIgnoreCase)) {
format = string.Format (ImapEngine.GenericItemSyntaxErrorFormat, "BODYSTRUCTURE", "{0}");
message.Body = ImapUtils.ParseBodyAsync (engine, format, string.Empty, false, cancellationToken).GetAwaiter ().GetResult ();
message.Body = ImapUtils.ParseBody (engine, format, string.Empty, cancellationToken);
message.Fields |= MessageSummaryItems.BodyStructure;
} else if (atom.Equals ("BODY", StringComparison.OrdinalIgnoreCase)) {
token = engine.PeekToken (cancellationToken);
Expand Down Expand Up @@ -366,14 +366,14 @@ void ParseSummaryItems (ImapEngine engine, MessageSummary message, FetchSummaryI
if (referencesField)
message.Fields |= MessageSummaryItems.References;
} else {
message.Body = ImapUtils.ParseBodyAsync (engine, format, string.Empty, false, cancellationToken).GetAwaiter ().GetResult ();
message.Body = ImapUtils.ParseBody (engine, format, string.Empty, cancellationToken);
message.Fields |= MessageSummaryItems.Body;
}
} else if (atom.Equals ("ENVELOPE", StringComparison.OrdinalIgnoreCase)) {
message.Envelope = ImapUtils.ParseEnvelopeAsync (engine, false, cancellationToken).GetAwaiter ().GetResult ();
message.Envelope = ImapUtils.ParseEnvelope (engine, cancellationToken);
message.Fields |= MessageSummaryItems.Envelope;
} else if (atom.Equals ("FLAGS", StringComparison.OrdinalIgnoreCase)) {
message.Flags = ImapUtils.ParseFlagsListAsync (engine, atom, (HashSet<string>) message.Keywords, false, cancellationToken).GetAwaiter ().GetResult ();
message.Flags = ImapUtils.ParseFlagsList (engine, atom, (HashSet<string>) message.Keywords, cancellationToken);
message.Fields |= MessageSummaryItems.Flags;
} else if (atom.Equals ("MODSEQ", StringComparison.OrdinalIgnoreCase)) {
token = engine.ReadToken (cancellationToken);
Expand Down Expand Up @@ -520,7 +520,7 @@ async Task ParseSummaryItemsAsync (ImapEngine engine, MessageSummary message, Fe
message.Fields |= MessageSummaryItems.Size;
} else if (atom.Equals ("BODYSTRUCTURE", StringComparison.OrdinalIgnoreCase)) {
format = string.Format (ImapEngine.GenericItemSyntaxErrorFormat, "BODYSTRUCTURE", "{0}");
message.Body = await ImapUtils.ParseBodyAsync (engine, format, string.Empty, true, cancellationToken).ConfigureAwait (false);
message.Body = await ImapUtils.ParseBodyAsync (engine, format, string.Empty, cancellationToken).ConfigureAwait (false);
message.Fields |= MessageSummaryItems.BodyStructure;
} else if (atom.Equals ("BODY", StringComparison.OrdinalIgnoreCase)) {
token = await engine.PeekTokenAsync (cancellationToken).ConfigureAwait (false);
Expand Down Expand Up @@ -602,14 +602,14 @@ async Task ParseSummaryItemsAsync (ImapEngine engine, MessageSummary message, Fe
if (referencesField)
message.Fields |= MessageSummaryItems.References;
} else {
message.Body = await ImapUtils.ParseBodyAsync (engine, format, string.Empty, true, cancellationToken).ConfigureAwait (false);
message.Body = await ImapUtils.ParseBodyAsync (engine, format, string.Empty, cancellationToken).ConfigureAwait (false);
message.Fields |= MessageSummaryItems.Body;
}
} else if (atom.Equals ("ENVELOPE", StringComparison.OrdinalIgnoreCase)) {
message.Envelope = await ImapUtils.ParseEnvelopeAsync (engine, true, cancellationToken).ConfigureAwait (false);
message.Envelope = await ImapUtils.ParseEnvelopeAsync (engine, cancellationToken).ConfigureAwait (false);
message.Fields |= MessageSummaryItems.Envelope;
} else if (atom.Equals ("FLAGS", StringComparison.OrdinalIgnoreCase)) {
message.Flags = await ImapUtils.ParseFlagsListAsync (engine, atom, (HashSet<string>) message.Keywords, true, cancellationToken).ConfigureAwait (false);
message.Flags = await ImapUtils.ParseFlagsListAsync (engine, atom, (HashSet<string>) message.Keywords, cancellationToken).ConfigureAwait (false);
message.Fields |= MessageSummaryItems.Flags;
} else if (atom.Equals ("MODSEQ", StringComparison.OrdinalIgnoreCase)) {
token = await engine.ReadTokenAsync (cancellationToken).ConfigureAwait (false);
Expand Down
Loading

0 comments on commit c2b4695

Please sign in to comment.