Skip to content

Commit

Permalink
Restructured ParseFolderList/Async to improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Dec 31, 2023
1 parent 46df9e8 commit 6ad1c01
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions MailKit/Net/Imap/ImapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public static void ParseFolderList (ImapEngine engine, List<ImapFolder> list, bo
if (token.Type == ImapTokenType.CloseParen)
break;

// a LIST extension
// A LIST extension (rfc5258).

ImapEngine.AssertToken (token, ImapTokenType.Atom, ImapTokenType.QString, format, token);

Expand All @@ -691,8 +691,10 @@ public static void ParseFolderList (ImapEngine engine, List<ImapFolder> list, bo

engine.Stream.UngetToken (token);

var value = ReadNStringToken (engine, format, false, cancellationToken);

if (!renamed && atom.Equals ("OLDNAME", StringComparison.OrdinalIgnoreCase)) {
var oldEncodedName = ReadFolderName (engine, delim, format, cancellationToken);
var oldEncodedName = value.TrimEnd (delim);

if (engine.FolderCache.TryGetValue (oldEncodedName, out ImapFolder oldFolder)) {
var args = new ImapFolderConstructorArgs (engine, encodedName, attrs, delim);
Expand All @@ -704,8 +706,6 @@ public static void ParseFolderList (ImapEngine engine, List<ImapFolder> list, bo
}

renamed = true;
} else {
ReadNStringToken (engine, format, false, cancellationToken);
}
} while (true);
} while (true);
Expand Down Expand Up @@ -782,7 +782,7 @@ public static async Task ParseFolderListAsync (ImapEngine engine, List<ImapFolde
if (token.Type == ImapTokenType.CloseParen)
break;

// a LIST extension
// A LIST extension (rfc5258).

ImapEngine.AssertToken (token, ImapTokenType.Atom, ImapTokenType.QString, format, token);

Expand All @@ -800,10 +800,12 @@ public static async Task ParseFolderListAsync (ImapEngine engine, List<ImapFolde

engine.Stream.UngetToken (token);

if (!renamed && atom.Equals ("OLDNAME", StringComparison.OrdinalIgnoreCase)) {
var oldEncodedName = await ReadFolderNameAsync (engine, delim, format, cancellationToken).ConfigureAwait (false);
var value = await ReadNStringTokenAsync (engine, format, false, cancellationToken).ConfigureAwait (false);

if (engine.FolderCache.TryGetValue (oldEncodedName, out ImapFolder oldFolder)) {
if (atom.Equals ("OLDNAME", StringComparison.OrdinalIgnoreCase)) {
var oldEncodedName = value.TrimEnd (delim);

if (!renamed && engine.FolderCache.TryGetValue (oldEncodedName, out ImapFolder oldFolder)) {
var args = new ImapFolderConstructorArgs (engine, encodedName, attrs, delim);

engine.FolderCache.Remove (oldEncodedName);
Expand All @@ -813,8 +815,6 @@ public static async Task ParseFolderListAsync (ImapEngine engine, List<ImapFolde
}

renamed = true;
} else {
await ReadNStringTokenAsync (engine, format, false, cancellationToken).ConfigureAwait (false);
}
} while (true);
} while (true);
Expand Down

0 comments on commit 6ad1c01

Please sign in to comment.