diff --git a/src/core/DigitalData.MessagingService.Abstraction/EmailAccountDto.cs b/src/core/DigitalData.MessagingService.Abstraction/EmailAccountDto.cs index de47b68..5563413 100644 --- a/src/core/DigitalData.MessagingService.Abstraction/EmailAccountDto.cs +++ b/src/core/DigitalData.MessagingService.Abstraction/EmailAccountDto.cs @@ -22,8 +22,6 @@ public class EmailAccountDto public string Password { get; set; } = null!; #endif - public bool PasswordEncrypted { get; set; } = false; - #if NET public required string SmtpServer { get; set; } #else diff --git a/src/core/DigitalData.MessagingService.Domain/DigitalData.MessagingService.Domain.csproj b/src/core/DigitalData.MessagingService.Domain/DigitalData.MessagingService.Domain.csproj index 23957d0..ff515ef 100644 --- a/src/core/DigitalData.MessagingService.Domain/DigitalData.MessagingService.Domain.csproj +++ b/src/core/DigitalData.MessagingService.Domain/DigitalData.MessagingService.Domain.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsEmailService.cs b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsEmailService.cs index 6f865ee..c015a19 100644 --- a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsEmailService.cs +++ b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsEmailService.cs @@ -16,8 +16,7 @@ namespace DigitalData.MessagingService.Infrastructure.Services; /// Uses the first account in the list whose equals "default", /// or falls back to the first account if none is named "default". /// -public class LimilabsEmailService( - IEncryptionService encryptionService) : IEmailService +public class LimilabsEmailService() : IEmailService { // Register encoding provider for Limilabs (requires windows-1252 and other code pages) static LimilabsEmailService() @@ -71,7 +70,7 @@ public class LimilabsEmailService( } } - private async Task ConnectAndAuthenticateSmtpAsync(Smtp smtp, EmailAccountDto smtpAccount) + private static async Task ConnectAndAuthenticateSmtpAsync(Smtp smtp, EmailAccountDto smtpAccount) { if (smtpAccount.SmtpUseSsl) { @@ -88,9 +87,7 @@ public class LimilabsEmailService( } else { - var password = smtpAccount.PasswordEncrypted ? encryptionService.Decrypt(smtpAccount.Password) : smtpAccount.Password; - - await smtp.LoginAsync(smtpAccount.Username, password); + await smtp.LoginAsync(smtpAccount.Username, smtpAccount.Password); } } diff --git a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs index 69b6b2e..90f2499 100644 --- a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs +++ b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs @@ -31,9 +31,9 @@ public class LimilabsImapEmailService( public async Task> FetchEmailsAsync( EmailAccountDto account, MailSearchFilter filter, - CancellationToken cancellationToken = default) + CancellationToken cancel = default) { - using var imap = await OpenAsync(account, filter.Folder); + using var imap = await OpenAsync(account, filter.Folder, cancel); try { #region Find UIDs @@ -51,7 +51,7 @@ public class LimilabsImapEmailService( } var searchExpression = criterions.Count > 0 ? Expression.And([.. criterions]) : Expression.All(); - List uids = [.. await imap.SearchAsync(searchExpression, cancellationToken)]; + List uids = [.. await imap.SearchAsync(searchExpression, cancel)]; if (filter.SortOrder == MailSortOrder.NewestFirst) uids.Reverse(); @@ -64,7 +64,7 @@ public class LimilabsImapEmailService( foreach (var uid in uids) { - cancellationToken.ThrowIfCancellationRequested(); + cancel.ThrowIfCancellationRequested(); try { @@ -73,9 +73,9 @@ public class LimilabsImapEmailService( CacheKeyPrefix + uid, async entry => { - var eml = await imap.GetMessageByUIDAsync(uid, cancellationToken); + var eml = await imap.GetMessageByUIDAsync(uid, cancel); var mail = new MailBuilder().CreateFromEml(eml); - var flags = await imap.GetFlagsByUIDAsync(uid, cancellationToken); + var flags = await imap.GetFlagsByUIDAsync(uid, cancel); var attachments = new List(); @@ -169,7 +169,7 @@ public class LimilabsImapEmailService( } } - await imap.CloseAsync(cancellationToken); + await imap.CloseAsync(cancel); if (filter.MaxCount is int maxCount && maxCount > 0 && results.Count > maxCount) return results.Take(maxCount); @@ -194,13 +194,13 @@ public class LimilabsImapEmailService( EmailAccountDto account, long uid, string folder = "INBOX", - CancellationToken cancellationToken = default) + CancellationToken cancel = default) { - using var imap = await OpenAsync(account, folder); + using var imap = await OpenAsync(account, folder, cancel); try { - await imap.MarkMessageSeenByUIDAsync(uid, cancellationToken); - await imap.CloseAsync(cancellationToken); + await imap.MarkMessageSeenByUIDAsync(uid, cancel); + await imap.CloseAsync(cancel); } catch (Limilabs.Client.ServerException ex) { @@ -216,25 +216,21 @@ public class LimilabsImapEmailService( } } - private async Task OpenAsync(EmailAccountDto account, string folder) + private static async Task OpenAsync(EmailAccountDto account, string folder, CancellationToken cancel) { var imap = new Imap(); if (account.ImapUseSsl) - await imap.ConnectSSLAsync(account.ImapServer!, account.ImapPort); + await imap.ConnectSSLAsync(account.ImapServer!, account.ImapPort, cancel: cancel); else - await imap.ConnectAsync(account.ImapServer!, account.ImapPort); + await imap.ConnectAsync(account.ImapServer!, account.ImapPort, cancel: cancel); - var password = account.PasswordEncrypted - ? EncryptionService.Decrypt(account.Password) - : account.Password; - - await imap.LoginAsync(account.Username, password); + await imap.LoginAsync(account.Username, account.Password, cancel); if (string.Equals(folder, "INBOX", StringComparison.OrdinalIgnoreCase)) - await imap.SelectInboxAsync(); + await imap.SelectInboxAsync(cancel); else - await imap.SelectAsync(folder); + await imap.SelectAsync(folder, cancel); return imap; }