From 7f1621915f206783d85358607e06764beb2d6534 Mon Sep 17 00:00:00 2001 From: he <109787524@qq.com> Date: Wed, 29 Oct 2025 10:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/EmailLogService.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) 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)