Fixed signing in to mailboxes with characters beyond ASCII in the username or password (#1224)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Peer HogeterpandThorsten Sommer authored and GitHub committed 2026-11-24 15:53:19 +01:00
1 parent f6a4348820
commit c72a1948b3
27 files changed
+1052 -30

No files matched your search

@@ -39,6 +39,7 @@ public sealed class MailboxProviderConfigurationTests
["Port"] = "1143",
["UsernameHint"] = "\"Your account as DOMAIN\\\\username\"",
["HelpUrl"] = "\"https://intranet.example.org/mail/imap\"",
["PasswordEncoding"] = "\" Windows-1254 \"",
});
Assert.That(provider, Is.Not.Null);
@@ -52,6 +53,7 @@ public sealed class MailboxProviderConfigurationTests
Assert.That(provider.Port, Is.EqualTo(1143));
Assert.That(provider.UsernameHint, Is.EqualTo(@"Your account as DOMAIN\username"));
Assert.That(provider.HelpUrl, Is.EqualTo("https://intranet.example.org/mail/imap"));
Assert.That(provider.PasswordEncoding?.Name, Is.EqualTo("windows-1254"));
}
}
@@ -68,6 +70,7 @@ public sealed class MailboxProviderConfigurationTests
Assert.That(withStartTls?.Port, Is.EqualTo(143));
Assert.That(withoutEncryption?.UsernameHint, Is.Empty);
Assert.That(withoutEncryption?.HelpUrl, Is.Empty);
Assert.That(withoutEncryption?.PasswordEncoding, Is.Null, "Without a word from the organization, the mailbox keeps the encoding it has.");
}
}
@@ -94,6 +97,12 @@ public sealed class MailboxProviderConfigurationTests
[TestCase("Port", "65536")]
[TestCase("HelpUrl", "\"ftp://intranet.example.org/mail\"")]
[TestCase("HelpUrl", "\"/mail/imap\"")]
[TestCase("PasswordEncoding", "\"UNKNOWN\"")]
[TestCase("PasswordEncoding", "\"\"")]
[TestCase("PasswordEncoding", "\"utf-16\"")]
[TestCase("PasswordEncoding", "\"IBM037\"")]
[TestCase("PasswordEncoding", "\"utf-8, windows-1252\"")]
[TestCase("PasswordEncoding", "true")]
public async Task AnEntryWithAnInvalidFieldIsLeftOut(string field, string? value)
{
var provider = await ReadAsync(new Dictionary<string, string?> { [field] = value });
@@ -3,6 +3,7 @@ using System.Text.Json;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
using AIStudio.Tools.Mail;
using Microsoft.Extensions.Logging.Abstractions;
@@ -40,6 +41,7 @@ public sealed class MailboxSettingsTests
Port = 143,
TransportSecurity = MailboxTransportSecurity.STARTTLS,
AuthMethod = MailboxAuthMethod.PASSWORD,
PasswordEncoding = MailboxPasswordEncoding.FromName("windows-1252"),
Username = "someone@example.org",
RootFolder = "INBOX/Projects",
IncludeSentAndDrafts = false,
@@ -137,6 +139,45 @@ public sealed class MailboxSettingsTests
Assert.That(mailbox.IncludeSentAndDrafts, Is.True);
}
[Test]
public void AMailboxStoredBeforeThePasswordEncodingSignsInWithUtf8()
{
// UTF-8 is what every sign-in used until then:
var mailbox = JsonSerializer.Deserialize<DataSourceMailbox>("""{"RootFolder": "INBOX"}""", SettingsManager.JSON_OPTIONS);
Assert.That(mailbox.PasswordEncoding, Is.EqualTo(MailboxPasswordEncoding.DEFAULT));
}
[Test]
public void AnEncodingThisVersionDoesNotKnowIsKeptButSignsInNowhere()
{
// The name stays, so that it is stored as it was; ImapMailboxConnectorTests checks that nothing is sent:
var mailbox = JsonSerializer.Deserialize<DataSourceMailbox>("""{"PasswordEncoding": "x-encoding-of-the-future"}""", SettingsManager.JSON_OPTIONS);
using (Assert.EnterMultipleScope())
{
Assert.That(mailbox.PasswordEncoding.Name, Is.EqualTo("x-encoding-of-the-future"));
Assert.That(mailbox.PasswordEncoding.IsKnown, Is.False);
Assert.That(JsonSerializer.Serialize(mailbox, SettingsManager.JSON_OPTIONS), Does.Contain("\"PasswordEncoding\": \"x-encoding-of-the-future\""));
}
}
[Test]
public void AnEncodingWhichIsNoNameSignsInNowhereButKeepsTheOtherSettings()
{
var mailbox = JsonSerializer.Deserialize<DataSourceMailbox>("""{"PasswordEncoding": {"CodePage": 1252}, "RootFolder": "INBOX"}""", SettingsManager.JSON_OPTIONS);
using (Assert.EnterMultipleScope())
{
Assert.That(mailbox.PasswordEncoding.IsKnown, Is.False);
Assert.That(mailbox.RootFolder, Is.EqualTo("INBOX"));
}
}
[Test]
public void AKnownEncodingIsStoredByTheNameDotNetGivesIt()
{
var mailbox = JsonSerializer.Deserialize<DataSourceMailbox>("""{"PasswordEncoding": " Windows-1254 "}""", SettingsManager.JSON_OPTIONS);
Assert.That(JsonSerializer.Serialize(mailbox, SettingsManager.JSON_OPTIONS), Does.Contain("\"PasswordEncoding\": \"windows-1254\""));
}
[Test]
public void ValuesThisVersionCannotReadFallBackToTheSafeSide()
{