diff --git a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs index 0515aa496..8f89bfa33 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs @@ -141,18 +141,14 @@ public class EmailLogService(IRepository _emailLogRepository, } // 主题关键词筛选(如果IMAP服务器支持) - //if (!string.IsNullOrEmpty(query.ToRecipientName)) - //{ - // searchQuery = searchQuery.And(SearchQuery.HeaderContains("To", query.ToRecipientName)); - //} - if (!string.IsNullOrEmpty(query.ToRecipientName)) { - searchQuery = searchQuery.And(SearchQuery.SubjectContains(query.ToRecipientName)); - + searchQuery = searchQuery.And(SearchQuery.HeaderContains("To", query.ToRecipientName)); } - if (!string.IsNullOrEmpty(query.ToRecipientName)) + + + if (!string.IsNullOrEmpty(query.CcRecipientName)) { searchQuery = searchQuery.And(SearchQuery.HeaderContains("Cc", query.CcRecipientName)); } @@ -199,6 +195,8 @@ public class EmailLogService(IRepository _emailLogRepository, /// private EmailLogView ConvertToEmailLogView(UniqueId uid, MimeMessage message) { + string saveFolder = @"D:\MailAttachments"; + Directory.CreateDirectory(saveFolder); var emailView = new EmailLogView { UniqueId = uid.ToString(), @@ -208,6 +206,21 @@ public class EmailLogService(IRepository _emailLogRepository, Content = message.HtmlBody ?? string.Empty, }; + var toHeader = message.Headers[HeaderId.To]; // 原始头,未解码 + Console.WriteLine($"原始To头 = |{toHeader}|"); + + foreach (var att in message.Attachments) + { + // att 可能是 MimePart 或 MessagePart + if (att is MimePart part && !string.IsNullOrEmpty(part.FileName)) + { + var file = Path.Combine(saveFolder, part.FileName); + using (var stream = File.Create(file)) + part.Content.DecodeTo(stream); + Console.WriteLine($" 附件已保存:{file}"); + } + } + // 处理发件人信息 var fromMailbox = message.From.Mailboxes.FirstOrDefault(); if (fromMailbox != null)