feat: add email result and search filter models
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 <noreply@anthropic.com>
This commit is contained in:
58
EmailSearch/EmailResult.cs
Normal file
58
EmailSearch/EmailResult.cs
Normal file
@@ -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<string> GetAttachmentNames(MailItem mail)
|
||||||
|
{
|
||||||
|
var names = new List<string>();
|
||||||
|
foreach (var attachment in mail.Attachments)
|
||||||
|
{
|
||||||
|
if (attachment is Attachment att)
|
||||||
|
names.Add(att.FileName);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
EmailSearch/SearchFilters.cs
Normal file
12
EmailSearch/SearchFilters.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user