From 6abe0e18f6fab9133201af0510df44c7de6c92dd Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 13 Aug 2026 16:48:22 +0200 Subject: [PATCH] feat(application): add EmailSyncResult DTO, Folder/AccountId to ReceivedEmailDto, rename CreateRangeAsync in IRepository, update IImapEmailService signature, add AutoMapper profiles for ReceivedEmail and EmailAttachment --- .../Common/Dto/EmailSyncResult.cs | 5 +++++ .../Common/Dto/ReceivedEmailDto.cs | 15 +++++++++++++ .../Common/Interfaces/IImapEmailService.cs | 22 ++++++++----------- .../Interfaces/Repositories/IRepository.cs | 2 +- .../Common/Mappings/EmailMappingProfile.cs | 13 +++++++++++ 5 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 src/core/DigitalData.MessagingService.Application/Common/Dto/EmailSyncResult.cs diff --git a/src/core/DigitalData.MessagingService.Application/Common/Dto/EmailSyncResult.cs b/src/core/DigitalData.MessagingService.Application/Common/Dto/EmailSyncResult.cs new file mode 100644 index 0000000..bd7144b --- /dev/null +++ b/src/core/DigitalData.MessagingService.Application/Common/Dto/EmailSyncResult.cs @@ -0,0 +1,5 @@ +#if NET +namespace DigitalData.MessagingService.Application.Common.Dto; + +public record EmailSyncResult(int ProcessedCount = 0, int FailedCount = 0); +#endif \ No newline at end of file diff --git a/src/core/DigitalData.MessagingService.Application/Common/Dto/ReceivedEmailDto.cs b/src/core/DigitalData.MessagingService.Application/Common/Dto/ReceivedEmailDto.cs index 4fe877e..8be26c7 100644 --- a/src/core/DigitalData.MessagingService.Application/Common/Dto/ReceivedEmailDto.cs +++ b/src/core/DigitalData.MessagingService.Application/Common/Dto/ReceivedEmailDto.cs @@ -14,6 +14,15 @@ public sealed record ReceivedEmailDto public long Uid { get; set; } #endif + /// + /// ID of the email account this message belongs to. + /// +#if NET + public int AccountId { get; init; } +#else + public int AccountId { get; set; } +#endif + /// /// Sender address (From header). /// @@ -94,4 +103,10 @@ public sealed record ReceivedEmailDto #else public bool IsSeen { get; set; } #endif + +#if NET + public required string Folder { get; init; } +#else + public string Folder { get; set; } = null!; +#endif } diff --git a/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IImapEmailService.cs b/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IImapEmailService.cs index fdf7cc8..834cc8f 100644 --- a/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IImapEmailService.cs +++ b/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IImapEmailService.cs @@ -1,6 +1,5 @@ #if NET using DigitalData.MessagingService.Application.Common.Dto; -using DigitalData.MessagingService.Application.Common.Dto.MailSearch; using DigitalData.MessagingService.Domain.Entities; namespace DigitalData.MessagingService.Application.Common.Interfaces; @@ -11,19 +10,16 @@ namespace DigitalData.MessagingService.Application.Common.Interfaces; public interface IImapEmailService { /// - /// Fetches emails from the specified mailbox folder. + /// /// - /// Account whose IMAP settings will be used. - /// - /// When (default), fetched messages are marked as \Seen on the server. - /// Set to for a non-destructive read (uses BODY.PEEK internally). - /// - /// Cancellation token. - public Task SyncEmailsAsync( - EmailAccount account, - DateFilter date, - string folder = "INBOX", - CancellationToken cancel = default); + /// + /// + /// + /// + Task SyncEmailsAsync( + EmailAccount account, + string folder = "INBOX", + CancellationToken cancel = default); /// /// Marks a message as seen (read) on the server. diff --git a/src/core/DigitalData.MessagingService.Application/Common/Interfaces/Repositories/IRepository.cs b/src/core/DigitalData.MessagingService.Application/Common/Interfaces/Repositories/IRepository.cs index ea85f14..7a04480 100644 --- a/src/core/DigitalData.MessagingService.Application/Common/Interfaces/Repositories/IRepository.cs +++ b/src/core/DigitalData.MessagingService.Application/Common/Interfaces/Repositories/IRepository.cs @@ -11,7 +11,7 @@ public interface IRepository where TEntity : class // CREATE Task CreateAsync(TDto dto, CancellationToken cancellationToken = default); - Task> CreateAsync(IEnumerable dtos, CancellationToken cancellationToken = default); + Task> CreateRangeAsync(IEnumerable dtos, CancellationToken cancellationToken = default); // READ Task GetByIdAsync(int id, CancellationToken cancellationToken = default); diff --git a/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs b/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs index c778f7c..1c79029 100644 --- a/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs +++ b/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs @@ -23,6 +23,19 @@ public class EmailMappingProfile : Profile // EmailAccountDto -> EmailAccount CreateMap(); CreateMap(); + + // ReceivedEmailDto <-> ReceivedEmail + CreateMap() + .ForMember(dest => dest.Id, opt => opt.Ignore()) + .ForMember(dest => dest.Account, opt => opt.Ignore()); + CreateMap(); + + // EmailAttachmentDto <-> EmailAttachment + CreateMap() + .ForMember(dest => dest.Id, opt => opt.Ignore()) + .ForMember(dest => dest.EmailId, opt => opt.Ignore()) + .ForMember(dest => dest.Email, opt => opt.Ignore()); + CreateMap(); } } #endif \ No newline at end of file