namespace AIStudio.Tools.Databases.IndexStore; /// /// A sign-in the server of a mailbox refused. /// /// When the server refused the sign-in. /// What the server answered, empty when it gave no reason. public sealed record MailboxAuthFailure(DateTimeOffset FailedAtUtc, string FailureMessage) { /// /// How much of the answer of the server is kept. The reason is in the first sentence, if at all. /// public const int MAX_FAILURE_MESSAGE_LENGTH = 500; /// /// Records a sign-in the server refused just now, together with what it answered. /// /// /// The answer often says why, e.g., that the provider requires an app password. It may name /// the user as well, which is why it is kept for the settings of the mailbox and never logged. /// /// What the server answered. /// The refused sign-in. public static MailboxAuthFailure FromServerAnswer(string serverAnswer) { var trimmedAnswer = serverAnswer.Trim(); return new(DateTimeOffset.UtcNow, trimmedAnswer.Length > MAX_FAILURE_MESSAGE_LENGTH ? trimmedAnswer[..MAX_FAILURE_MESSAGE_LENGTH] : trimmedAnswer); } }