Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for confirming unsafe addresses #26

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class Config

public string TrustedDomainsPattern = "";
public string TrustedAddressesPattern = "";
public string UnsafeDomainsPattern = "";
public string UnsafeDomainsPattern = "";
public string UnsafeAddressesPattern = "";
public string UnsafeFilesPattern = "";

public Config()
Expand Down Expand Up @@ -96,10 +97,13 @@ public void RebuildPatterns()
{
var trustedAddressList = TrustedDomains.Where(_ => _.Contains("@"));
var trustedDomainList = TrustedDomains.Where(_ => !_.Contains("@"));
var unsafeAddressList = UnsafeDomains.Where(_ => _.Contains("@"));
var unsafeDomainList = UnsafeDomains.Where(_ => !_.Contains("@"));

TrustedDomainsPattern = $"^({string.Join("|", trustedDomainList.Select(ConvertWildCardToRegex))})$";
TrustedAddressesPattern = $"^({string.Join("|", trustedAddressList.Select(ConvertWildCardToRegex))})$";
UnsafeDomainsPattern = $"^({string.Join("|", UnsafeDomains.Select(ConvertWildCardToRegex))})$";
UnsafeDomainsPattern = $"^({string.Join("|", unsafeDomainList.Select(ConvertWildCardToRegex))})$";
UnsafeAddressesPattern = $"^({string.Join("|", unsafeAddressList.Select(ConvertWildCardToRegex))})$";
UnsafeFilesPattern = $"({string.Join("|", UnsafeFiles.Select(ConvertWildCardToRegex))})";
}

Expand Down
27 changes: 26 additions & 1 deletion Dialog/MainDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void RenderMain()
// Attachments/Alerts
CheckSafeBcc(_recipients);
CheckUnsafeDomains(_recipients);
CheckUnsafeAddresses(_recipients);
CheckUnsafeFiles();

foreach (Outlook.Attachment item in _mail.Attachments)
Expand Down Expand Up @@ -224,7 +225,31 @@ private void CheckUnsafeDomains(List<RecipientInfo> recipients)
seen.Add(info.Domain);
}
}
}
}

private void CheckUnsafeAddresses(List<RecipientInfo> recipients)
{
HashSet<string> seen = new HashSet<string>();

foreach (RecipientInfo info in recipients)
{
if (!seen.Contains(info.Address))
{
try
{
if (Regex.IsMatch(info.Address, _config.UnsafeAddressesPattern, RegexOptions.IgnoreCase))
{
spFile.Children.Add(GetWarnCheckBox(
string.Format(Properties.Resources.MainUnsafeAddressesWarning, info.Address),
Properties.Resources.MainUnsafeAddressesWarningHint
));
}
}
catch (RegexMatchTimeoutException) { }
seen.Add(info.Address);
}
}
}

private void CheckUnsafeFiles()
{
Expand Down
30 changes: 27 additions & 3 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Properties/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
# To add more domains, input entries (one per line) below.
# You can also exclude domains by adding "-" at the beginning.
# And wildcards (* and ?) are also available.
# You can specify not only domains but also addresses.
# * When an entry contains @, the entry is regarded as address.
# * When an entry does not contains @, the entry is regarded as domain.
##################################

{1}</value>
Expand Down Expand Up @@ -255,6 +258,9 @@ example.org</value>
# (2) Enter one entry per line as follows.
# (3) Lines starting with # are ignored.
# (4) Wildcards (* and ?) are available.
# (5) You can specify not only domains but also addresses.
# * When an entry contains @, the entry is regarded as address.
# * when an entry does not contains @, the entry is regarded as domain.
#
##################################

Expand Down Expand Up @@ -357,4 +363,10 @@ so please use Bcc when sending an message to unrelated parties.</value>
<data name="Warrning" xml:space="preserve">
<value>Warning!</value>
</data>
<data name="MainUnsafeAddressesWarning" xml:space="preserve">
<value>[Warn] An unsafe address "{0}" found in the recipient list</value>
</data>
<data name="MainUnsafeAddressesWarningHint" xml:space="preserve">
<value>This address is registered as unsafe. Please recheck and confirm.</value>
</data>
</root>
14 changes: 13 additions & 1 deletion Properties/Resources.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
# Para agregar más dominios, ingrese las entradas (una por línea) a continuación.
# También puedes excluir dominios agregando "-" al principio
# Y también están disponibles los comodines (* y ?).
# You can specify not only domains but also addresses.
# * When an entry contains @, the entry is regarded as address.
# * When an entry does not contains @, the entry is regarded as domain.
##################################

{1}</value>
Expand Down Expand Up @@ -255,6 +258,9 @@ ejemplo.org</value>
# (2) Introduzca una entrada por línea de la siguiente manera.
# (3) Las líneas que comienzan con # se ignoran.
# (4) Los comodines (* y ?) estan disponibles.
# (5) You can specify not only domains but also addresses.
# * When an entry contains @, the entry is regarded as address.
# * when an entry does not contains @, the entry is regarded as domain.
#
##################################

Expand Down Expand Up @@ -357,4 +363,10 @@ asi que por favor utilice Bcc cuando envie mensajes a destinatarios no relaciona
<data name="Warrning" xml:space="preserve">
<value>Advertencia!</value>
</data>
</root>
<data name="MainUnsafeAddressesWarning" xml:space="preserve">
<value>[Advertencia] El correo inseguro "{0}" fue encontradro en la lista de destinatarios</value>
</data>
<data name="MainUnsafeAddressesWarningHint" xml:space="preserve">
<value>Este correo esta registrado como inseguro. Por favor revise y confirme.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
# さらにドメインを追加する場合は、以下に1行ずつ入力してください。
# また、先頭に「-」をつけると、ドメインを除外することができます。
# 指定にはワイルドカード(*および?)も使用可能です。
# また、ドメインだけでなくアドレスを指定することもできます。
# * @を含む場合はアドレスが指定されたとみなします
# * @を含まない場合はドメインが指定されたとみなします
##################################

{1}</value>
Expand Down Expand Up @@ -267,6 +270,9 @@ example.org</value>
# (1) 添付ファイルに含まれる場合に警告する注意ワードを指定します。
# (2) 以下の例のように一行に一件ずつ記載します。
# (3) 冒頭が「#」から始まる行は無視されます。
# (4) ドメインだけでなくアドレス全体を指定することもできます。
# * @を含む場合はアドレスが指定されたとみなします。
# * @を含まない場合はドメインが指定されたとみなします。
#
##################################

Expand Down Expand Up @@ -357,4 +363,10 @@ ToおよびCcに含まれるメールアドレスはすべての受取人が確
<data name="Warning" xml:space="preserve">
<value>⨉ 警告!</value>
</data>
<data name="MainUnsafeAddressesWarning" xml:space="preserve">
<value>[警告] 注意が必要なアドレス({0})が宛先に含まれています。</value>
</data>
<data name="MainUnsafeAddressesWarningHint" xml:space="preserve">
<value>このアドレスは誤送信の可能性が高いため、再確認を促す警告を出してします。</value>
</data>
</root>
12 changes: 12 additions & 0 deletions Properties/Resources.zh.resx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
# 要添加更多的域,请在下面输入条目(每行一个)。
# 你也可以通过在开头添加"-"来排除域名。
# And wildcards (* and ?) are also available.
# You can specify not only domains but also addresses.
# * When an entry contains @, the entry is regarded as address.
# * When an entry does not contains @, the entry is regarded as domain.
##################################

{1}</value>
Expand Down Expand Up @@ -255,6 +258,9 @@ example.org</value>
# (2) 每行写一个条目,如下所示
# (3) 以 "#" 开头的行被忽略
# (4) Wildcards (* and ?) are available.
# (5) You can specify not only domains but also addresses.
# * When an entry contains @, the entry is regarded as address.
# * when an entry does not contains @, the entry is regarded as domain.
#
##################################

Expand Down Expand Up @@ -354,4 +360,10 @@ example.org</value>
<data name="Warning" xml:space="preserve">
<value>⨉ 警告!</value>
</data>
<data name="MainUnsafeAddressesWarning" xml:space="preserve">
<value>[警告] 包含不安全地址 ({0})</value>
</data>
<data name="MainUnsafeAddressesWarningHint" xml:space="preserve">
<value>该地址被列入不安全地址列表中</value>
</data>
</root>
Loading