From 56a501e6f005086e23b98e91aeff3ac4d9c09dcf Mon Sep 17 00:00:00 2001 From: Takashi Hashida Date: Mon, 20 May 2024 12:07:52 +0900 Subject: [PATCH] Add support to specify trusted addresses If a trusted domain entry contains "@", we regard it as address, not domain. --- Config/Config.cs | 9 +++++++-- Dialog/MainDialog.xaml.cs | 19 ++++++++++++++----- FlexConfirmMail.csproj | 35 +++++++++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Config/Config.cs b/Config/Config.cs index b6f6d5b..36210ce 100644 --- a/Config/Config.cs +++ b/Config/Config.cs @@ -19,7 +19,8 @@ public class Config public bool SafeNewDomainsEnabled = true; public HashSet Modified; - public string TrustedDomainsPattern = ""; + public string TrustedDomainsPattern = ""; + public string TrustedAddressesPattern = ""; public string UnsafeDomainsPattern = ""; public string UnsafeFilesPattern = ""; @@ -93,7 +94,11 @@ public void Merge(Config other) public void RebuildPatterns() { - TrustedDomainsPattern = $"^({string.Join("|", TrustedDomains.Select(ConvertWildCardToRegex))})$"; + var trustedAddressList = TrustedDomains.Where(_ => _.Contains("@")); + var trustedDomainList = TrustedDomains.Where(_ => !_.Contains("@")); + + TrustedDomainsPattern = $"^({string.Join("|", trustedDomainList.Select(ConvertWildCardToRegex))})$"; + TrustedAddressesPattern = $"^({string.Join("|", trustedAddressList.Select(ConvertWildCardToRegex))})$"; UnsafeDomainsPattern = $"^({string.Join("|", UnsafeDomains.Select(ConvertWildCardToRegex))})$"; UnsafeFilesPattern = $"({string.Join("|", UnsafeFiles.Select(ConvertWildCardToRegex))})"; } diff --git a/Dialog/MainDialog.xaml.cs b/Dialog/MainDialog.xaml.cs index b0d51b1..715d9a6 100644 --- a/Dialog/MainDialog.xaml.cs +++ b/Dialog/MainDialog.xaml.cs @@ -136,7 +136,7 @@ private List ToLower(List list) return ret; } - private bool IsTrustedDomain(string domain, HashSet trusted) + private bool IsTrustedDomain(string domain) { // Note: DOMAIN_EXCHANGE basically means "LegacyDN recipients whose // SMTP address we don't know". We assume they are internal users, @@ -152,17 +152,27 @@ private bool IsTrustedDomain(string domain, HashSet trusted) } catch (RegexMatchTimeoutException) { } + return false; + } + + private bool IsTrustedAddress(string address) + { + try + { + return Regex.IsMatch(address, _config.TrustedAddressesPattern, RegexOptions.IgnoreCase); + } + catch (RegexMatchTimeoutException) { } + return false; } private void RenderTrustedList(List recipients) { HashSet seen = new HashSet(); - HashSet trusted = GetHashSet(ToLower(_config.TrustedDomains)); foreach (RecipientInfo info in recipients) { - if (IsTrustedDomain(info.Domain, trusted)) + if (IsTrustedDomain(info.Domain) || IsTrustedAddress(info.Address)) { if (!seen.Contains(info.Domain)) { @@ -177,11 +187,10 @@ private void RenderTrustedList(List recipients) private void RenderExternalList(List list) { HashSet seen = new HashSet(); - HashSet trusted = GetHashSet(ToLower(_config.TrustedDomains)); foreach (RecipientInfo info in list) { - if (!IsTrustedDomain(info.Domain, trusted)) + if (!(IsTrustedDomain(info.Domain) || IsTrustedAddress(info.Address))) { if (!seen.Contains(info.Domain)) { diff --git a/FlexConfirmMail.csproj b/FlexConfirmMail.csproj index 4551510..8371488 100644 --- a/FlexConfirmMail.csproj +++ b/FlexConfirmMail.csproj @@ -26,16 +26,39 @@ false FlexConfirmMail FlexConfirmMail - 3 v4.7.2 VSTO40 true - HomeSite + 公開\ + + ja + 1.0.0.0 + true + true + 7 + days + False + FlexConfirmMail + + + FlexConfirmMail + + 3 + + False + Microsoft .NET Framework 4.7.2 %28x86 および x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + False - Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29 + Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 および x64%29 true @@ -202,6 +225,7 @@ True + SettingsSingleFileGenerator Settings.Designer.cs @@ -256,11 +280,10 @@ true - - + FlexConfirmMail_TemporaryKey.pfx - 73E7B9D1F72EDA033E7A9D6B17BC37A96CE8513A + 64B05F83B44EB4280B93BFCE98903E9770346EA4 false