Files
Wino-Mail/Wino.Core.UWP/Services/ThumbnailService.cs

65 lines
1.8 KiB
C#
Raw Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.Linq;
using System.Net.Mail;
namespace Wino.Core.UWP.Services
2024-04-18 01:44:37 +02:00
{
public static class ThumbnailService
2024-04-18 01:44:37 +02:00
{
private static string[] knownCompanies = new string[]
{
"microsoft.com", "apple.com", "google.com", "steampowered.com", "airbnb.com", "youtube.com", "uber.com"
};
2024-04-18 01:44:37 +02:00
public static bool IsKnown(string mailHost) => !string.IsNullOrEmpty(mailHost) && knownCompanies.Contains(mailHost);
2024-04-18 01:44:37 +02:00
public static string GetHost(string address)
2024-04-18 01:44:37 +02:00
{
if (string.IsNullOrEmpty(address))
return string.Empty;
2024-04-18 01:44:37 +02:00
if (address.Contains('@'))
2024-04-18 01:44:37 +02:00
{
var splitted = address.Split('@');
if (splitted.Length >= 2 && !string.IsNullOrEmpty(splitted[1]))
2025-02-16 11:35:43 +01:00
{
try
{
return new MailAddress(address).Host;
}
catch (Exception)
{
// TODO: Exceptions are ignored for now.
}
2024-04-18 01:44:37 +02:00
}
}
return string.Empty;
2024-04-18 01:44:37 +02:00
}
public static Tuple<bool, string> CheckIsKnown(string host)
{
// Check known hosts.
// Apply company logo if available.
2024-04-18 01:44:37 +02:00
try
{
var last = host.Split('.');
2024-04-18 01:44:37 +02:00
if (last.Length > 2)
host = $"{last[last.Length - 2]}.{last[last.Length - 1]}";
}
catch (Exception)
{
return new Tuple<bool, string>(false, host);
}
2024-04-18 01:44:37 +02:00
return new Tuple<bool, string>(IsKnown(host), host);
2024-04-18 01:44:37 +02:00
}
public static string GetKnownHostImage(string host)
=> $"ms-appx:///Assets/Thumbnails/{host}.png";
2024-04-18 01:44:37 +02:00
}
}