From f7161dc39b82bb46b68ced2902bfd242b6791990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Tue, 18 Jun 2024 02:22:55 +0200 Subject: [PATCH] Pre-post authentication ID extension for IMAP. Some servers require it pre-auth looks like. --- Wino.Core/Integration/ImapClientPool.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Wino.Core/Integration/ImapClientPool.cs b/Wino.Core/Integration/ImapClientPool.cs index c272d8df..b34b5be5 100644 --- a/Wino.Core/Integration/ImapClientPool.cs +++ b/Wino.Core/Integration/ImapClientPool.cs @@ -58,6 +58,8 @@ namespace Wino.Core.Integration { await EnsureConnectedAsync(client); + bool mustDoPostAuthIdentification = false; + if (isCreatedNew && client.IsConnected) { // Activate supported pre-auth capabilities. @@ -65,14 +67,32 @@ namespace Wino.Core.Integration await client.CompressAsync(); // 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)) - 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); if (isCreatedNew && client.IsAuthenticated) { + if (mustDoPostAuthIdentification) await client.IdentifyAsync(_implementation); + // Activate post-auth capabilities. if (client.Capabilities.HasFlag(ImapCapabilities.QuickResync)) await client.EnableQuickResyncAsync();