mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 07:09:40 +00:00
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
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using MimeKit;
|
|
|
|
namespace AIStudio.Tools.Mail;
|
|
|
|
/// <summary>
|
|
/// Reads how important the sender marked a mail.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Three headers say so, from three different eras, and mail programs send whichever they like,
|
|
/// often more than one. They are read in this order, and the first one with a value AI Studio
|
|
/// understands decides:
|
|
/// <list type="number">
|
|
/// <item>Importance (RFC 2156): low, normal or high. Outlook sends it.</item>
|
|
/// <item>X-Priority: a number from 1 (highest) to 5 (lowest), often followed by a word such as "1 (Highest)".</item>
|
|
/// <item>Priority (RFC 2156): non-urgent, normal or urgent.</item>
|
|
/// </list>
|
|
/// A header with a value nobody defined is skipped rather than read as normal, so that the next
|
|
/// header still gets its say.
|
|
/// </remarks>
|
|
public static class MailImportanceDetection
|
|
{
|
|
/// <summary>
|
|
/// Reads the importance from the header block of a mail.
|
|
/// </summary>
|
|
/// <param name="headers">The header block.</param>
|
|
/// <returns>The importance, NORMAL when no header says otherwise.</returns>
|
|
public static MailImportance Detect(HeaderList headers) =>
|
|
ReadImportance(headers[HeaderId.Importance]) ??
|
|
ReadXPriority(headers[HeaderId.XPriority]) ??
|
|
ReadPriority(headers[HeaderId.Priority]) ??
|
|
MailImportance.NORMAL;
|
|
|
|
private static MailImportance? ReadImportance(string? value) => value?.Trim().ToLowerInvariant() switch
|
|
{
|
|
"low" => MailImportance.LOW,
|
|
"normal" => MailImportance.NORMAL,
|
|
"high" => MailImportance.HIGH,
|
|
_ => null,
|
|
};
|
|
|
|
private static MailImportance? ReadXPriority(string? value)
|
|
{
|
|
// Only the leading digit counts, as in "2 (High)", and it has to stand alone:
|
|
var trimmed = value?.TrimStart();
|
|
if (string.IsNullOrEmpty(trimmed) || (trimmed.Length > 1 && char.IsDigit(trimmed[1])))
|
|
return null;
|
|
|
|
return trimmed[0] switch
|
|
{
|
|
'1' or '2' => MailImportance.HIGH,
|
|
'3' => MailImportance.NORMAL,
|
|
'4' or '5' => MailImportance.LOW,
|
|
_ => null,
|
|
};
|
|
}
|
|
|
|
private static MailImportance? ReadPriority(string? value) => value?.Trim().ToLowerInvariant() switch
|
|
{
|
|
"non-urgent" => MailImportance.LOW,
|
|
"normal" => MailImportance.NORMAL,
|
|
"urgent" => MailImportance.HIGH,
|
|
_ => null,
|
|
};
|
|
} |