Skip to content

Commit f9e3795

Browse files
authored
Merge pull request #39 from FlexConfirmMail/unify-line-break-to-LF
Unify line break to LF
2 parents 74e01c6 + a2ccc2d commit f9e3795

9 files changed

+228
-228
lines changed

Config/Config.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class Config
1919
public bool SafeNewDomainsEnabled = true;
2020
public HashSet<ConfigOption> Modified;
2121

22-
public string TrustedDomainsPattern = "";
22+
public string TrustedDomainsPattern = "";
2323
public string TrustedAddressesPattern = "";
24-
public string UnsafeDomainsPattern = "";
24+
public string UnsafeDomainsPattern = "";
2525
public string UnsafeAddressesPattern = "";
2626
public string UnsafeFilesPattern = "";
2727

@@ -83,8 +83,8 @@ public void Merge(Config other)
8383
if (other.Modified.Contains(ConfigOption.UnsafeFiles))
8484
{
8585
UnsafeFiles.AddRange(other.UnsafeFiles);
86-
}
87-
86+
}
87+
8888
if (other.Modified.Contains(ConfigOption.SafeNewDomainsEnabled))
8989
{
9090
SafeNewDomainsEnabled = other.SafeNewDomainsEnabled;
@@ -95,9 +95,9 @@ public void Merge(Config other)
9595

9696
public void RebuildPatterns()
9797
{
98-
var trustedAddressList = TrustedDomains.Where(_ => _.Contains("@"));
99-
var trustedDomainList = TrustedDomains.Where(_ => !_.Contains("@"));
100-
var unsafeAddressList = UnsafeDomains.Where(_ => _.Contains("@"));
98+
var trustedAddressList = TrustedDomains.Where(_ => _.Contains("@"));
99+
var trustedDomainList = TrustedDomains.Where(_ => !_.Contains("@"));
100+
var unsafeAddressList = UnsafeDomains.Where(_ => _.Contains("@"));
101101
var unsafeDomainList = UnsafeDomains.Where(_ => !_.Contains("@"));
102102

103103
TrustedDomainsPattern = $"^({string.Join("|", trustedDomainList.Select(ConvertWildCardToRegex))})$";

Config/Const.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public class RegistryPath
88
public static readonly string Policy = @"SOFTWARE\Policies\FlexConfirmMail";
99
}
1010

11-
public class ConfigPath
12-
{
13-
public static readonly string DefaultConfigDirName = @"DefaultConfig";
11+
public class ConfigPath
12+
{
13+
public static readonly string DefaultConfigDirName = @"DefaultConfig";
1414
}
1515

1616
public enum ConfigOption
@@ -23,7 +23,7 @@ public enum ConfigOption
2323
MainSkipIfNoExt,
2424
TrustedDomains,
2525
UnsafeDomains,
26-
UnsafeFiles,
26+
UnsafeFiles,
2727
SafeNewDomainsEnabled,
2828
}
2929
}

Config/Loader.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ private static bool Assign(Config config, string key, string val)
173173
config.Modified.Add(ConfigOption.UnsafeFiles);
174174
return true;
175175
}
176-
}
177-
176+
}
177+
178178
if (key == "SafeNewDomainsEnabled")
179179
{
180180
if (ParseBool(val, out b))

Config/StandardPath.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public static string GetUserDir()
99
{
1010
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
1111
return Path.Combine(appData, Global.AppName);
12-
}
13-
12+
}
13+
1414
public static string GetDefaultConfigDir()
15-
{
16-
string dllDirectory = AppDomain.CurrentDomain.BaseDirectory;
15+
{
16+
string dllDirectory = AppDomain.CurrentDomain.BaseDirectory;
1717
return Path.Combine(dllDirectory, ConfigPath.DefaultConfigDirName);
1818
}
1919
}

Dialog/ConfigDialog.xaml.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace FlexConfirmMail.Dialog
1111
public partial class ConfigDialog : Window
1212
{
1313
Config _config = new Config();
14-
Config _default = new Config();
14+
Config _default = new Config();
1515
Config _local = new Config();
1616

1717
public ConfigDialog()
@@ -24,9 +24,9 @@ public ConfigDialog()
2424
{
2525
_default = Loader.LoadFromReg(RegistryPath.DefaultPolicy);
2626
_config.Merge(_default);
27-
}
28-
Config defaultWithFile = Loader.LoadFromDir(StandardPath.GetDefaultConfigDir());
29-
_default.Merge(defaultWithFile);
27+
}
28+
Config defaultWithFile = Loader.LoadFromDir(StandardPath.GetDefaultConfigDir());
29+
_default.Merge(defaultWithFile);
3030
_config.Merge(defaultWithFile);
3131

3232
_local = Loader.LoadFromDir(StandardPath.GetUserDir());

Dialog/MainDialog.xaml.cs

+51-51
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace FlexConfirmMail.Dialog
99
{
1010
public partial class MainDialog : Window
1111
{
12-
private Outlook.MailItem _mail;
13-
private List<RecipientInfo> _recipients;
12+
private Outlook.MailItem _mail;
13+
private List<RecipientInfo> _recipients;
1414
private List<RecipientInfo> _originalRecipients;
1515
private Config _config;
1616

@@ -29,9 +29,9 @@ internal MainDialog(Config config, Outlook.MailItem mail, List<RecipientInfo> or
2929
QueueLogger.Log("===== Open MainDialog() =====");
3030

3131
// Show the subject string in title bar
32-
Title = $"{mail.Subject} - {Global.AppName} v{Global.Version} {Global.Edition}";
33-
34-
// Set recipient info
32+
Title = $"{mail.Subject} - {Global.AppName} v{Global.Version} {Global.Edition}";
33+
34+
// Set recipient info
3535
List<RecipientInfo> recipients = new List<RecipientInfo>();
3636

3737
foreach (Outlook.Recipient recp in _mail.Recipients)
@@ -80,23 +80,23 @@ private void RenderMain()
8080
}
8181
}
8282

83-
private bool CheckNewDomains()
84-
{
85-
if (_originalRecipients == null)
86-
{
87-
return true;
88-
}
89-
var originalDomains = _originalRecipients.Select(_ => _.Domain).ToHashSet();
90-
var newDomainAddresses = _recipients
91-
.Where(_ => !originalDomains.Contains(_.Domain))
92-
.Select(_ => _.Address)
93-
.ToHashSet();
94-
if (newDomainAddresses.Count == 0)
95-
{
96-
return true;
97-
}
98-
var newDomainDialog = new NewDomainDialog(newDomainAddresses);
99-
return newDomainDialog.ShowDialog() ?? false;
83+
private bool CheckNewDomains()
84+
{
85+
if (_originalRecipients == null)
86+
{
87+
return true;
88+
}
89+
var originalDomains = _originalRecipients.Select(_ => _.Domain).ToHashSet();
90+
var newDomainAddresses = _recipients
91+
.Where(_ => !originalDomains.Contains(_.Domain))
92+
.Select(_ => _.Address)
93+
.ToHashSet();
94+
if (newDomainAddresses.Count == 0)
95+
{
96+
return true;
97+
}
98+
var newDomainDialog = new NewDomainDialog(newDomainAddresses);
99+
return newDomainDialog.ShowDialog() ?? false;
100100
}
101101

102102
private bool IsEmbeddedImage(Outlook.Attachment item)
@@ -147,18 +147,18 @@ private bool IsTrustedDomain(string domain)
147147
return true;
148148
}
149149

150-
try
150+
try
151151
{
152152
return Regex.IsMatch(domain, _config.TrustedDomainsPattern, RegexOptions.IgnoreCase);
153153
}
154154
catch (RegexMatchTimeoutException) { }
155155

156156
return false;
157-
}
158-
157+
}
158+
159159
private bool IsTrustedAddress(string address)
160160
{
161-
try
161+
try
162162
{
163163
return Regex.IsMatch(address, _config.TrustedAddressesPattern, RegexOptions.IgnoreCase);
164164
}
@@ -211,7 +211,7 @@ private void CheckUnsafeDomains(List<RecipientInfo> recipients)
211211
{
212212
if (!seen.Contains(info.Domain))
213213
{
214-
try
214+
try
215215
{
216216
if (Regex.IsMatch(info.Domain, _config.UnsafeDomainsPattern, RegexOptions.IgnoreCase))
217217
{
@@ -225,8 +225,8 @@ private void CheckUnsafeDomains(List<RecipientInfo> recipients)
225225
seen.Add(info.Domain);
226226
}
227227
}
228-
}
229-
228+
}
229+
230230
private void CheckUnsafeAddresses(List<RecipientInfo> recipients)
231231
{
232232
HashSet<string> seen = new HashSet<string>();
@@ -235,7 +235,7 @@ private void CheckUnsafeAddresses(List<RecipientInfo> recipients)
235235
{
236236
if (!seen.Contains(info.Address))
237237
{
238-
try
238+
try
239239
{
240240
if (Regex.IsMatch(info.Address, _config.UnsafeAddressesPattern, RegexOptions.IgnoreCase))
241241
{
@@ -249,28 +249,28 @@ private void CheckUnsafeAddresses(List<RecipientInfo> recipients)
249249
seen.Add(info.Address);
250250
}
251251
}
252-
}
252+
}
253253

254254
private void CheckUnsafeFiles()
255255
{
256256
HashSet<string> notsafe = GetHashSet(_config.UnsafeFiles);
257257

258258
foreach (Outlook.Attachment item in _mail.Attachments)
259-
{
259+
{
260260
HashSet<string> seen = new HashSet<string>();
261-
try
261+
try
262262
{
263263
foreach (Match match in Regex.Matches(item.FileName, _config.UnsafeFilesPattern, RegexOptions.IgnoreCase))
264-
{
265-
string lowerValue = match.Value.ToLower();
266-
if (seen.Contains(lowerValue))
267-
{
268-
continue;
269-
}
264+
{
265+
string lowerValue = match.Value.ToLower();
266+
if (seen.Contains(lowerValue))
267+
{
268+
continue;
269+
}
270270
spFile.Children.Add(GetWarnCheckBox(
271271
string.Format(Properties.Resources.MainUnsafeFilesWarning, match.Value),
272272
Properties.Resources.MainUnsafeFilesWarningHint
273-
));
273+
));
274274
seen.Add(lowerValue);
275275
}
276276
}
@@ -384,17 +384,17 @@ private void CheckBox_Click(object sender, RoutedEventArgs e)
384384
}
385385

386386
private void ButtonOK_Click(object sender, RoutedEventArgs e)
387-
{
388-
QueueLogger.Log("* Send button clicked.");
389-
if (_config.SafeNewDomainsEnabled)
390-
{
391-
QueueLogger.Log("* Check new domains");
392-
if (!CheckNewDomains())
393-
{
394-
return;
395-
}
396-
}
397-
387+
{
388+
QueueLogger.Log("* Send button clicked.");
389+
if (_config.SafeNewDomainsEnabled)
390+
{
391+
QueueLogger.Log("* Check new domains");
392+
if (!CheckNewDomains())
393+
{
394+
return;
395+
}
396+
}
397+
398398
QueueLogger.Log("* closing...");
399399
DialogResult = true;
400400
}

Dialog/NewDomainDialog.xaml.cs

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Globalization;
4-
using System.Windows;
5-
using System.Windows.Documents;
6-
using System.Windows.Threading;
7-
8-
namespace FlexConfirmMail.Dialog
9-
{
10-
public partial class NewDomainDialog : Window
11-
{
12-
public NewDomainDialog()
13-
{
14-
QueueLogger.Log($"===== Open {nameof(NewDomainDialog)} =====");
15-
InitializeComponent();
16-
}
17-
18-
public NewDomainDialog(HashSet<string> addresses) : this()
19-
{
20-
CultureInfo.CurrentCulture = new CultureInfo("en-US", false);
21-
22-
if (addresses.Count > 2)
23-
{
24-
double margin = 10;
25-
this.Height += (addresses.Count - 2) * (textBlockBody.FontSize + margin);
26-
}
27-
textBlockBody.Inlines.Add(Properties.Resources.ConfirmNewDomainsBody1);
28-
textBlockBody.Inlines.Add("\n\n");
29-
textBlockBody.Inlines.Add(new Run()
30-
{
31-
Text = string.Join("\n", addresses),
32-
FontWeight = FontWeights.Bold
33-
});
34-
textBlockBody.Inlines.Add("\n\n");
35-
textBlockBody.Inlines.Add(Properties.Resources.ConfirmNewDomainsBody2);
36-
}
37-
38-
private void buttonSend_Click(object sender, RoutedEventArgs e)
39-
{
40-
QueueLogger.Log($"* Send button clicked. closing...");
41-
DialogResult = true;
42-
}
43-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Windows;
5+
using System.Windows.Documents;
6+
using System.Windows.Threading;
7+
8+
namespace FlexConfirmMail.Dialog
9+
{
10+
public partial class NewDomainDialog : Window
11+
{
12+
public NewDomainDialog()
13+
{
14+
QueueLogger.Log($"===== Open {nameof(NewDomainDialog)} =====");
15+
InitializeComponent();
16+
}
17+
18+
public NewDomainDialog(HashSet<string> addresses) : this()
19+
{
20+
CultureInfo.CurrentCulture = new CultureInfo("en-US", false);
21+
22+
if (addresses.Count > 2)
23+
{
24+
double margin = 10;
25+
this.Height += (addresses.Count - 2) * (textBlockBody.FontSize + margin);
26+
}
27+
textBlockBody.Inlines.Add(Properties.Resources.ConfirmNewDomainsBody1);
28+
textBlockBody.Inlines.Add("\n\n");
29+
textBlockBody.Inlines.Add(new Run()
30+
{
31+
Text = string.Join("\n", addresses),
32+
FontWeight = FontWeights.Bold
33+
});
34+
textBlockBody.Inlines.Add("\n\n");
35+
textBlockBody.Inlines.Add(Properties.Resources.ConfirmNewDomainsBody2);
36+
}
37+
38+
private void buttonSend_Click(object sender, RoutedEventArgs e)
39+
{
40+
QueueLogger.Log($"* Send button clicked. closing...");
41+
DialogResult = true;
42+
}
43+
}
4444
}

FlexConfirmMail.iss

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ Source: "bin\Release\es\FlexConfirmMail.resources.dll"; DestDir: "{app}\es"; Fla
4646
Source: "bin\Release\Microsoft.Office.Tools.Common.v4.0.Utilities.dll"; DestDir: "{app}"; Flags: ignoreversion
4747
Source: "bin\Release\Microsoft.Office.Tools.Outlook.v4.0.Utilities.dll"; DestDir: "{app}"; Flags: ignoreversion
4848
Source: "Resources\fcm.ico"; DestDir: "{app}"; Flags: ignoreversion
49-
Source: "{src}\DefaultConfig\*.txt"; DestDir: "{app}\DefaultConfig"; Flags:external skipifsourcedoesntexist
49+
Source: "{src}\DefaultConfig\*.txt"; DestDir: "{app}\DefaultConfig"; Flags:external skipifsourcedoesntexist

0 commit comments

Comments
 (0)