邮件修改
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
70e4829f32
commit
7f1621915f
|
|
@ -141,18 +141,14 @@ public class EmailLogService(IRepository<EmailLog> _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<EmailLog> _emailLogRepository,
|
|||
/// <returns></returns>
|
||||
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<EmailLog> _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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue