From b2fd117b83130c6e7ba37ce0b778a8c3c3add028 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sat, 20 Dec 2025 11:42:59 -0500 Subject: [PATCH] feat: add email result and search filter models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add EmailResult class for holding email search results with subject, sender, date, body preview, attachments, and metadata. Add SearchFilters for encapsulating search criteria. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- EmailSearch/EmailResult.cs | 58 ++++++++++++++++++++++++++++++++++++ EmailSearch/SearchFilters.cs | 12 ++++++++ 2 files changed, 70 insertions(+) create mode 100644 EmailSearch/EmailResult.cs create mode 100644 EmailSearch/SearchFilters.cs diff --git a/EmailSearch/EmailResult.cs b/EmailSearch/EmailResult.cs new file mode 100644 index 0000000..a40dc88 --- /dev/null +++ b/EmailSearch/EmailResult.cs @@ -0,0 +1,58 @@ +using NetOffice.OutlookApi; + +public class EmailResult +{ + public string Subject { get; set; } = ""; + public string Sender { get; set; } = ""; + public string CC { get; set; } = ""; + public string BCC { get; set; } = ""; + public DateTime ReceivedDate { get; set; } + public string BodyPreview { get; set; } = ""; + public string Folder { get; set; } = ""; + public int AttachmentCount { get; set; } + public string AttachmentNames { get; set; } = ""; + public string Importance { get; set; } = ""; + public string Categories { get; set; } = ""; + public string FlagStatus { get; set; } = ""; + + public static EmailResult FromMailItem(MailItem mail, string folderName) + { + var bodyPreview = TruncatePreview(mail.Body ?? "", 300); + var attachmentNames = GetAttachmentNames(mail); + + return new EmailResult + { + Subject = mail.Subject ?? "(No Subject)", + Sender = $"{mail.SenderName} <{mail.SenderEmailAddress}>", + CC = mail.CC ?? "", + BCC = mail.BCC ?? "", + ReceivedDate = mail.ReceivedTime, + BodyPreview = bodyPreview, + Folder = folderName, + AttachmentCount = attachmentNames.Count, + AttachmentNames = string.Join(", ", attachmentNames), + Importance = mail.Importance.ToString().Replace("olImportance", ""), + Categories = mail.Categories ?? "", + FlagStatus = mail.FlagStatus.ToString().Replace("olFlag", "").Replace("olNo", "Not") + }; + } + + private static string TruncatePreview(string body, int maxLength) + { + var preview = body; + if (preview.Length > maxLength) + preview = preview.Substring(0, maxLength) + "..."; + return preview.Replace("\r\n", " ").Replace("\n", " ").Trim(); + } + + private static List GetAttachmentNames(MailItem mail) + { + var names = new List(); + foreach (var attachment in mail.Attachments) + { + if (attachment is Attachment att) + names.Add(att.FileName); + } + return names; + } +} diff --git a/EmailSearch/SearchFilters.cs b/EmailSearch/SearchFilters.cs new file mode 100644 index 0000000..624d576 --- /dev/null +++ b/EmailSearch/SearchFilters.cs @@ -0,0 +1,12 @@ +using NetOffice.OutlookApi.Enums; + +public class SearchFilters +{ + public string? Keywords { get; set; } + public string? Sender { get; set; } + public string? Subject { get; set; } + public string? HasAttachment { get; set; } + public OlImportance? Importance { get; set; } + public string? Category { get; set; } + public OlFlagStatus? FlagStatus { get; set; } +}