Pre-post authentication ID extension for IMAP. Some servers require it pre-auth looks like.

This commit is contained in:
Burak Kaan Köse
2024-06-18 02:22:55 +02:00
parent d8ea41e4dd
commit f7161dc39b

View File

@@ -58,6 +58,8 @@ namespace Wino.Core.Integration
{ {
await EnsureConnectedAsync(client); await EnsureConnectedAsync(client);
bool mustDoPostAuthIdentification = false;
if (isCreatedNew && client.IsConnected) if (isCreatedNew && client.IsConnected)
{ {
// Activate supported pre-auth capabilities. // Activate supported pre-auth capabilities.
@@ -65,14 +67,32 @@ namespace Wino.Core.Integration
await client.CompressAsync(); await client.CompressAsync();
// Identify if the server supports ID extension. // Identify if the server supports ID extension.
// Some servers require it pre-authentication, some post-authentication.
// We'll observe the response here and do it after authentication if needed.
if (client.Capabilities.HasFlag(ImapCapabilities.Id)) if (client.Capabilities.HasFlag(ImapCapabilities.Id))
await client.IdentifyAsync(_implementation); {
try
{
await client.IdentifyAsync(_implementation);
}
catch (ImapCommandException commandException) when (commandException.Response == ImapCommandResponse.No)
{
mustDoPostAuthIdentification = true;
}
catch (Exception)
{
throw;
}
}
} }
await EnsureAuthenticatedAsync(client); await EnsureAuthenticatedAsync(client);
if (isCreatedNew && client.IsAuthenticated) if (isCreatedNew && client.IsAuthenticated)
{ {
if (mustDoPostAuthIdentification) await client.IdentifyAsync(_implementation);
// Activate post-auth capabilities. // Activate post-auth capabilities.
if (client.Capabilities.HasFlag(ImapCapabilities.QuickResync)) if (client.Capabilities.HasFlag(ImapCapabilities.QuickResync))
await client.EnableQuickResyncAsync(); await client.EnableQuickResyncAsync();