Files
AI-Studio/app/MindWork AI Studio/Tools/Mail/MailTextSource.cs
T
Thorsten Sommer c4400c0ff6
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Added mailboxes as local data sources (#1022)
2026-10-04 12:26:26 +02:00

35 lines
1.9 KiB
C#

using MimeKit;
namespace AIStudio.Tools.Mail;
/// <summary>
/// What MailTextBuilder reads one mail from.
/// </summary>
/// <remarks>
/// Not a whole mail on purpose: the sync fetches the header block and the structure first, and
/// the text parts only of a mail which turns out readable. The attachments themselves are never
/// part of this, only their names.
/// </remarks>
/// <param name="Headers">The complete header block of the mail.</param>
/// <param name="HtmlBody">The HTML part a reader sees, decoded from its transfer encoding and charset, or null when there is none.</param>
/// <param name="TextBody">The plain text part, decoded likewise, or null when there is none.</param>
/// <param name="AttachmentNames">The file names of the attachments, in their order, without the signature of a signed mail.</param>
/// <param name="StructureEncryption">How the structure of the mail says its content is encrypted, see MailEncryptionDetection.</param>
public sealed record MailTextSource(HeaderList Headers, string? HtmlBody, string? TextBody, IReadOnlyList<string> AttachmentNames, MailEncryptionKind StructureEncryption)
{
/// <summary>
/// Takes everything from a mail which was fetched or loaded as a whole.
/// </summary>
/// <param name="message">The parsed mail.</param>
/// <returns>The source for MailTextBuilder.</returns>
public static MailTextSource FromMessage(MimeMessage message)
{
var attachmentNames = message.Attachments
.Where(attachment => !MailAttachmentRules.IsSignature(attachment.ContentType))
.Select(attachment => attachment.ContentDisposition?.FileName ?? attachment.ContentType.Name ?? string.Empty)
.Where(name => !string.IsNullOrWhiteSpace(name))
.ToList();
return new(message.Headers, message.HtmlBody, message.TextBody, attachmentNames, MailEncryptionDetection.Detect(message.Body));
}
}