From a5d7fc96a618ebbb6030e5935c2c72fbc2255b5a Mon Sep 17 00:00:00 2001 From: Andrea Corti Date: Thu, 28 Apr 2022 16:43:25 +0200 Subject: [PATCH 1/4] Updated to FX 4.6 - Performance Improvements Update all projects to FX 4.6 Removed the parsing of all folders on login Corrected two exceptions on parsing Added parameters to avoid SubFolders on GetMessage --- ActiveUp.Net.sln | 40 +++++- .../ActiveUp.Net.Common.csproj | 9 +- Class Library/ActiveUp.Net.Common/Parser.cs | 9 +- .../ActiveUp.Net.Common/SslHandShake.cs | 2 +- .../ActiveUp.Net.Dns/ActiveUp.Net.Dns.csproj | 9 +- .../ActiveUp.Net.Groupware.csproj | 9 +- .../ActiveUp.Net.Imap4.csproj | 9 +- .../ActiveUp.Net.Imap4/Imap4Client.cs | 12 +- .../ActiveUp.Net.Mail.csproj | 14 +- .../ActiveUp.Net.Nntp.csproj | 9 +- .../ActiveUp.Net.OpenPGP.csproj | 9 +- .../ActiveUp.Net.Pop3.csproj | 9 +- .../ActiveUp.Net.Smtp.csproj | 9 +- .../ActiveUp.Net.Tests.csproj | 6 +- .../ActiveUp.Net.WhoIs.csproj | 9 +- .../ActiveUp.Net/ActiveUp.Net.csproj | 6 +- .../ActiveQConfiguration.csproj | 12 +- .../ActiveQConfiguration/app.config | 3 + .../ActiveQInstallCreateDefaultConfig.csproj | 12 +- .../app.config | 3 + .../ActiveQInstallDescription.csproj | 12 +- .../ActiveQInstallDescription/app.config | 3 + .../ActiveQInstallInteractDesktop.csproj | 12 +- .../ActiveQInstallInteractDesktop/app.config | 3 + .../ActiveQInstallLaunchService.csproj | 12 +- .../ActiveQInstallLaunchService/app.config | 3 + .../ActiveQLibrary/ActiveQLibrary.csproj | 9 +- .../ActiveQManager/ActiveQManager.csproj | 12 +- .../Properties/Resources.Designer.cs | 4 +- Queuing System/ActiveQManager/app.config | 3 + .../ActiveQTestConsole.csproj | 12 +- Queuing System/ActiveQTestConsole/app.config | 3 + .../ActiveQWindowsService.csproj | 12 +- .../ActiveQWindowsService/app.config | 3 + WindowsFormsApp1/App.config | 6 + WindowsFormsApp1/Class1.cs | 70 +++++++++ WindowsFormsApp1/Form1.Designer.cs | 48 +++++++ WindowsFormsApp1/Form1.cs | 27 ++++ WindowsFormsApp1/Form1.resx | 120 ++++++++++++++++ WindowsFormsApp1/Program.cs | 22 +++ WindowsFormsApp1/Properties/AssemblyInfo.cs | 36 +++++ .../Properties/Resources.Designer.cs | 71 ++++++++++ WindowsFormsApp1/Properties/Resources.resx | 117 +++++++++++++++ .../Properties/Settings.Designer.cs | 30 ++++ WindowsFormsApp1/Properties/Settings.settings | 7 + WindowsFormsApp1/WindowsFormsApp1.csproj | 134 ++++++++++++++++++ 46 files changed, 941 insertions(+), 50 deletions(-) create mode 100644 Queuing System/ActiveQConfiguration/app.config create mode 100644 Queuing System/ActiveQInstallCreateDefaultConfig/app.config create mode 100644 Queuing System/ActiveQInstallDescription/app.config create mode 100644 Queuing System/ActiveQInstallInteractDesktop/app.config create mode 100644 Queuing System/ActiveQInstallLaunchService/app.config create mode 100644 Queuing System/ActiveQManager/app.config create mode 100644 Queuing System/ActiveQTestConsole/app.config create mode 100644 Queuing System/ActiveQWindowsService/app.config create mode 100644 WindowsFormsApp1/App.config create mode 100644 WindowsFormsApp1/Class1.cs create mode 100644 WindowsFormsApp1/Form1.Designer.cs create mode 100644 WindowsFormsApp1/Form1.cs create mode 100644 WindowsFormsApp1/Form1.resx create mode 100644 WindowsFormsApp1/Program.cs create mode 100644 WindowsFormsApp1/Properties/AssemblyInfo.cs create mode 100644 WindowsFormsApp1/Properties/Resources.Designer.cs create mode 100644 WindowsFormsApp1/Properties/Resources.resx create mode 100644 WindowsFormsApp1/Properties/Settings.Designer.cs create mode 100644 WindowsFormsApp1/Properties/Settings.settings create mode 100644 WindowsFormsApp1/WindowsFormsApp1.csproj diff --git a/ActiveUp.Net.sln b/ActiveUp.Net.sln index 533b108..618bb64 100644 --- a/ActiveUp.Net.sln +++ b/ActiveUp.Net.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32319.34 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Class Library", "Class Library", "{629D406B-F46A-4A9D-A31F-C5956E0AB157}" EndProject @@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActiveUp.Net.Tests", "Class EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActiveUp.Net", "Class Library\ActiveUp.Net\ActiveUp.Net.csproj", "{25DA9502-B959-4E81-9368-471AE231BCC0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsFormsApp1", "WindowsFormsApp1\WindowsFormsApp1.csproj", "{B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|.NET = Debug|.NET @@ -606,6 +608,36 @@ Global {25DA9502-B959-4E81-9368-471AE231BCC0}.Trial|Any CPU.Build.0 = Trial|Any CPU {25DA9502-B959-4E81-9368-471AE231BCC0}.Trial|Mixed Platforms.ActiveCfg = Trial|Any CPU {25DA9502-B959-4E81-9368-471AE231BCC0}.Trial|Mixed Platforms.Build.0 = Trial|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Debug|.NET.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Debug|.NET.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.MailSystem Dev|.NET.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.MailSystem Dev|.NET.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.MailSystem Dev|Any CPU.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.MailSystem Dev|Any CPU.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.MailSystem Dev|Mixed Platforms.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.MailSystem Dev|Mixed Platforms.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Release|.NET.ActiveCfg = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Release|.NET.Build.0 = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Release|Any CPU.Build.0 = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Retail|.NET.ActiveCfg = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Retail|.NET.Build.0 = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Retail|Any CPU.ActiveCfg = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Retail|Any CPU.Build.0 = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Retail|Mixed Platforms.ActiveCfg = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Retail|Mixed Platforms.Build.0 = Release|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Trial|.NET.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Trial|.NET.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Trial|Any CPU.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Trial|Any CPU.Build.0 = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Trial|Mixed Platforms.ActiveCfg = Debug|Any CPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F}.Trial|Mixed Platforms.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -632,5 +664,9 @@ Global {D9BCD15E-A438-4554-89D3-1CF122167FDD} = {629D406B-F46A-4A9D-A31F-C5956E0AB157} {5AD3438E-9024-4908-BA15-92726159C4FB} = {33BAFFED-FB5D-48EF-85D9-CDE2EB2CFA64} {25DA9502-B959-4E81-9368-471AE231BCC0} = {629D406B-F46A-4A9D-A31F-C5956E0AB157} + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F} = {33BAFFED-FB5D-48EF-85D9-CDE2EB2CFA64} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CFB097AB-7158-4A40-90C3-C54C646BF177} EndGlobalSection EndGlobal diff --git a/Class Library/ActiveUp.Net.Common/ActiveUp.Net.Common.csproj b/Class Library/ActiveUp.Net.Common/ActiveUp.Net.Common.csproj index 3646690..9e19ed0 100644 --- a/Class Library/ActiveUp.Net.Common/ActiveUp.Net.Common.csproj +++ b/Class Library/ActiveUp.Net.Common/ActiveUp.Net.Common.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.Common.XML AllRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Common.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ prompt ../Obfuscation/Trial/ActiveUp.Net.Common.xml AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ prompt ..\Bin\Retail\ActiveUp.Net.Common.xml AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Common/Parser.cs b/Class Library/ActiveUp.Net.Common/Parser.cs index 4d8b006..01bfb3d 100644 --- a/Class Library/ActiveUp.Net.Common/Parser.cs +++ b/Class Library/ActiveUp.Net.Common/Parser.cs @@ -1118,9 +1118,16 @@ public static DateTime ParseAsUniversalDateTime(string input) string[] dateParts = parts[3].Split(':'); int hour = Convert.ToInt32(dateParts[0]); int minute = Convert.ToInt32(dateParts[1]); + int second = 0; if (dateParts.Length > 2) - second = Convert.ToInt32(dateParts[2]); + { + if(dateParts[2].Contains(".")) + second = Convert.ToInt32(dateParts[2].Substring(0, dateParts[2].IndexOf("."))); + else + second = Convert.ToInt32(dateParts[2]); + } + int offset_hours = Convert.ToInt32(parts[4].Substring(0, 3)); int offset_minutes = Convert.ToInt32(parts[4].Substring(3, 2)); DateTime date = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc); diff --git a/Class Library/ActiveUp.Net.Common/SslHandShake.cs b/Class Library/ActiveUp.Net.Common/SslHandShake.cs index ef96dcf..16a04a2 100644 --- a/Class Library/ActiveUp.Net.Common/SslHandShake.cs +++ b/Class Library/ActiveUp.Net.Common/SslHandShake.cs @@ -48,7 +48,7 @@ public SslHandShake(string hostName, System.Security.Authentication.SslProtocols { } - public SslHandShake(string hostName) : this(hostName, System.Security.Authentication.SslProtocols.None, null, null, null, false) + public SslHandShake(string hostName) : this(hostName, System.Security.Authentication.SslProtocols.Default, null, null, null, false) { } diff --git a/Class Library/ActiveUp.Net.Dns/ActiveUp.Net.Dns.csproj b/Class Library/ActiveUp.Net.Dns/ActiveUp.Net.Dns.csproj index 9580108..0f20efa 100644 --- a/Class Library/ActiveUp.Net.Dns/ActiveUp.Net.Dns.csproj +++ b/Class Library/ActiveUp.Net.Dns/ActiveUp.Net.Dns.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.Dns.XML AllRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Dns.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ prompt ../Obfuscation/Trial/ActiveUp.Net.Dns.xml AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ prompt ..\Bin\Retail\ActiveUp.Net.Dns.xml AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Groupware/ActiveUp.Net.Groupware.csproj b/Class Library/ActiveUp.Net.Groupware/ActiveUp.Net.Groupware.csproj index 1f37afc..68ad561 100644 --- a/Class Library/ActiveUp.Net.Groupware/ActiveUp.Net.Groupware.csproj +++ b/Class Library/ActiveUp.Net.Groupware/ActiveUp.Net.Groupware.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.PDI.XML MinimumRecommendedRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.PDI.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ AnyCPU prompt AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj b/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj index 8098c0c..511d6d3 100644 --- a/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj +++ b/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -21,7 +21,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -49,6 +49,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.Imap4.XML AllRules.ruleset + false pdbonly @@ -59,6 +60,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Imap4.XML AllRules.ruleset + false bin\Trial\ @@ -69,6 +71,7 @@ prompt ../Obfuscation/Trial/ActiveUp.Net.Imap4.xml AllRules.ruleset + false ..\Bin\Retail\ @@ -79,6 +82,7 @@ prompt ..\Bin\Retail\ActiveUp.Net.Imap4.xml AllRules.ruleset + false bin\MailSystem Dev\ @@ -89,6 +93,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs b/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs index 407f536..fe02d9a 100644 --- a/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs +++ b/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs @@ -899,7 +899,7 @@ public string Login(string username, string password) OnAuthenticating(new AuthenticatingEventArgs(username, password, host)); string response = Command("login " + username + " " + password); OnAuthenticated(new AuthenticatedEventArgs(username, password, host, response)); - LoadMailboxes(); + //LoadMailboxes(); return response; } public IAsyncResult BeginLogin(string username, string password, AsyncCallback callback) @@ -1042,6 +1042,7 @@ public byte[] CommandBinary(string command, CommandOptions options = null) public byte[] CommandBinary(string command, string stamp, CommandOptions options = null) { + System.Diagnostics.Debug.WriteLine(command); if (options == null) options = new CommandOptions(); @@ -1872,7 +1873,7 @@ public void EndUnsubscribeMailbox(IAsyncResult result) { _delegateMailboxOperationReturnsString.EndInvoke(result); } - + public bool SubFolders = true; /// /// Selects a mailbox on the server. /// @@ -1919,7 +1920,10 @@ public Mailbox SelectMailbox(string mailboxName) mailboxName = renderSafeParam(mailboxName); Mailbox mailbox = new Mailbox(); + + if(SubFolders) mailbox.SubMailboxes = GetMailboxes(mailboxName, "*"); + string response = Command("select \"" + mailboxName + "\""); string[] lines = System.Text.RegularExpressions.Regex.Split(response, "\r\n"); @@ -1945,7 +1949,9 @@ public Mailbox SelectMailbox(string mailboxName) int unseen = 0; try { - unseen = Convert.ToInt32(FindLine(lines, "[UNSEEN ").Split(' ')[3].TrimEnd(']')); + string line = FindLine(lines, "[UNSEEN "); + if(!String.IsNullOrEmpty(line)) + unseen = Convert.ToInt32(line.Split(' ')[3].TrimEnd(']')); } catch (Exception) { } mailbox.FirstUnseen = (response.ToLower().IndexOf("[unseen") != -1) ? unseen : 0; diff --git a/Class Library/ActiveUp.Net.Mail/ActiveUp.Net.Mail.csproj b/Class Library/ActiveUp.Net.Mail/ActiveUp.Net.Mail.csproj index 6c7d8dd..77958e6 100644 --- a/Class Library/ActiveUp.Net.Mail/ActiveUp.Net.Mail.csproj +++ b/Class Library/ActiveUp.Net.Mail/ActiveUp.Net.Mail.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -21,7 +21,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -50,6 +50,7 @@ ..\Bin\Debug\ActiveUp.Net.Mail.XML true AllRules.ruleset + false pdbonly @@ -60,6 +61,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Mail.XML AllRules.ruleset + false bin\Trial\ @@ -70,6 +72,7 @@ AnyCPU prompt AllRules.ruleset + false ..\Bin\Retail\ @@ -81,6 +84,7 @@ prompt true AllRules.ruleset + false bin\MailSystem Dev\ @@ -91,6 +95,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Retail\ @@ -103,22 +108,27 @@ On ../Obfuscation/Retail/ActiveUp.Net.Mail.xml AllRules.ruleset + false TRIAL bin\Trial\ bin\Trial\ActiveUp.Net.Mail.XML AllRules.ruleset + false AllRules.ruleset + false AllRules.ruleset bin\Release\ + false AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Nntp/ActiveUp.Net.Nntp.csproj b/Class Library/ActiveUp.Net.Nntp/ActiveUp.Net.Nntp.csproj index d747c72..f846d1c 100644 --- a/Class Library/ActiveUp.Net.Nntp/ActiveUp.Net.Nntp.csproj +++ b/Class Library/ActiveUp.Net.Nntp/ActiveUp.Net.Nntp.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.Nntp.XML AllRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Nntp.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ prompt ../Obfuscation/Trial/ActiveUp.Net.Nntp.xml AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ prompt ..\Bin\Retail\ActiveUp.Net.Nntp.xml AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.OpenPGP/ActiveUp.Net.OpenPGP.csproj b/Class Library/ActiveUp.Net.OpenPGP/ActiveUp.Net.OpenPGP.csproj index e63a70a..ce5bae3 100644 --- a/Class Library/ActiveUp.Net.OpenPGP/ActiveUp.Net.OpenPGP.csproj +++ b/Class Library/ActiveUp.Net.OpenPGP/ActiveUp.Net.OpenPGP.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.OpenPGP.XML MinimumRecommendedRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.OpenPGP.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ AnyCPU prompt AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Pop3/ActiveUp.Net.Pop3.csproj b/Class Library/ActiveUp.Net.Pop3/ActiveUp.Net.Pop3.csproj index 1bdac66..5f9a958 100644 --- a/Class Library/ActiveUp.Net.Pop3/ActiveUp.Net.Pop3.csproj +++ b/Class Library/ActiveUp.Net.Pop3/ActiveUp.Net.Pop3.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.Pop3.XML AllRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Pop3.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ prompt ../Obfuscation/Trial/ActiveUp.Net.Pop3.xml AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ prompt ..\Bin\Retail\ActiveUp.Net.Pop3.xml AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Smtp/ActiveUp.Net.Smtp.csproj b/Class Library/ActiveUp.Net.Smtp/ActiveUp.Net.Smtp.csproj index 18107df..0bf767d 100644 --- a/Class Library/ActiveUp.Net.Smtp/ActiveUp.Net.Smtp.csproj +++ b/Class Library/ActiveUp.Net.Smtp/ActiveUp.Net.Smtp.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.Smtp.XML AllRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.Smtp.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ prompt ../Obfuscation/Trial/ActiveUp.Net.Smtp.xml AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ prompt ..\Bin\Retail\ActiveUp.Net.Smtp.xml AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net.Tests/ActiveUp.Net.Tests.csproj b/Class Library/ActiveUp.Net.Tests/ActiveUp.Net.Tests.csproj index 44a5b97..3e72a19 100644 --- a/Class Library/ActiveUp.Net.Tests/ActiveUp.Net.Tests.csproj +++ b/Class Library/ActiveUp.Net.Tests/ActiveUp.Net.Tests.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties ActiveUp.Net.Tests ActiveUp.Net.Tests - v4.0 + v4.6 512 @@ -42,6 +42,7 @@ prompt 4 AllRules.ruleset + false pdbonly @@ -51,6 +52,7 @@ prompt 4 AllRules.ruleset + false true diff --git a/Class Library/ActiveUp.Net.WhoIs/ActiveUp.Net.WhoIs.csproj b/Class Library/ActiveUp.Net.WhoIs/ActiveUp.Net.WhoIs.csproj index 3628a3e..e7d4296 100644 --- a/Class Library/ActiveUp.Net.WhoIs/ActiveUp.Net.WhoIs.csproj +++ b/Class Library/ActiveUp.Net.WhoIs/ActiveUp.Net.WhoIs.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -25,7 +25,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -53,6 +53,7 @@ 4 ..\Bin\Debug\ActiveUp.Net.WhoIs.XML AllRules.ruleset + false pdbonly @@ -63,6 +64,7 @@ 4 ..\Bin\Release\ActiveUp.Net.WhoIs.XML AllRules.ruleset + false bin\Trial\ @@ -73,6 +75,7 @@ AnyCPU prompt AllRules.ruleset + false ..\Bin\Retail\ @@ -83,6 +86,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -93,6 +97,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Class Library/ActiveUp.Net/ActiveUp.Net.csproj b/Class Library/ActiveUp.Net/ActiveUp.Net.csproj index 3eb9ea8..f20746f 100644 --- a/Class Library/ActiveUp.Net/ActiveUp.Net.csproj +++ b/Class Library/ActiveUp.Net/ActiveUp.Net.csproj @@ -16,7 +16,7 @@ SAK true ActiveUp.Net.snk - v4.0 + v4.6 @@ -48,6 +48,7 @@ prompt 4 bin\Debug\ActiveUp.Net.XML + false pdbonly @@ -57,6 +58,7 @@ prompt 4 bin\Release\ActiveUp.Net.XML + false bin\Retail\ @@ -66,6 +68,7 @@ pdbonly AnyCPU prompt + false bin\Trial\ @@ -75,6 +78,7 @@ pdbonly AnyCPU prompt + false diff --git a/Queuing System/ActiveQConfiguration/ActiveQConfiguration.csproj b/Queuing System/ActiveQConfiguration/ActiveQConfiguration.csproj index 1533e8f..ac33390 100644 --- a/Queuing System/ActiveQConfiguration/ActiveQConfiguration.csproj +++ b/Queuing System/ActiveQConfiguration/ActiveQConfiguration.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -36,7 +36,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -77,6 +77,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -101,6 +102,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -112,6 +114,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -123,6 +126,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -134,6 +138,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -233,6 +238,9 @@ true + + + diff --git a/Queuing System/ActiveQConfiguration/app.config b/Queuing System/ActiveQConfiguration/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQConfiguration/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQInstallCreateDefaultConfig/ActiveQInstallCreateDefaultConfig.csproj b/Queuing System/ActiveQInstallCreateDefaultConfig/ActiveQInstallCreateDefaultConfig.csproj index 07f7dfe..2537b11 100644 --- a/Queuing System/ActiveQInstallCreateDefaultConfig/ActiveQInstallCreateDefaultConfig.csproj +++ b/Queuing System/ActiveQInstallCreateDefaultConfig/ActiveQInstallCreateDefaultConfig.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -35,7 +35,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -76,6 +76,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -100,6 +101,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -111,6 +113,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -122,6 +125,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -133,6 +137,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -186,6 +191,9 @@ true + + + diff --git a/Queuing System/ActiveQInstallCreateDefaultConfig/app.config b/Queuing System/ActiveQInstallCreateDefaultConfig/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQInstallCreateDefaultConfig/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQInstallDescription/ActiveQInstallDescription.csproj b/Queuing System/ActiveQInstallDescription/ActiveQInstallDescription.csproj index 02cc584..e2efc84 100644 --- a/Queuing System/ActiveQInstallDescription/ActiveQInstallDescription.csproj +++ b/Queuing System/ActiveQInstallDescription/ActiveQInstallDescription.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -35,7 +35,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -76,6 +76,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -100,6 +101,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -111,6 +113,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -122,6 +125,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -133,6 +137,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -176,6 +181,9 @@ true + + + diff --git a/Queuing System/ActiveQInstallDescription/app.config b/Queuing System/ActiveQInstallDescription/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQInstallDescription/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQInstallInteractDesktop/ActiveQInstallInteractDesktop.csproj b/Queuing System/ActiveQInstallInteractDesktop/ActiveQInstallInteractDesktop.csproj index fced1d3..76eb3c9 100644 --- a/Queuing System/ActiveQInstallInteractDesktop/ActiveQInstallInteractDesktop.csproj +++ b/Queuing System/ActiveQInstallInteractDesktop/ActiveQInstallInteractDesktop.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -35,7 +35,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -76,6 +76,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -100,6 +101,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -111,6 +113,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -122,6 +125,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -133,6 +137,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -181,6 +186,9 @@ true + + + diff --git a/Queuing System/ActiveQInstallInteractDesktop/app.config b/Queuing System/ActiveQInstallInteractDesktop/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQInstallInteractDesktop/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQInstallLaunchService/ActiveQInstallLaunchService.csproj b/Queuing System/ActiveQInstallLaunchService/ActiveQInstallLaunchService.csproj index 2437611..e24155f 100644 --- a/Queuing System/ActiveQInstallLaunchService/ActiveQInstallLaunchService.csproj +++ b/Queuing System/ActiveQInstallLaunchService/ActiveQInstallLaunchService.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -35,7 +35,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -76,6 +76,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -100,6 +101,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -111,6 +113,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -122,6 +125,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -133,6 +137,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -181,6 +186,9 @@ true + + + diff --git a/Queuing System/ActiveQInstallLaunchService/app.config b/Queuing System/ActiveQInstallLaunchService/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQInstallLaunchService/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQLibrary/ActiveQLibrary.csproj b/Queuing System/ActiveQLibrary/ActiveQLibrary.csproj index f2b3d38..ff03ba8 100644 --- a/Queuing System/ActiveQLibrary/ActiveQLibrary.csproj +++ b/Queuing System/ActiveQLibrary/ActiveQLibrary.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -36,7 +36,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -77,6 +77,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -101,6 +102,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -113,6 +115,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -125,6 +128,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -137,6 +141,7 @@ AnyCPU prompt AllRules.ruleset + false diff --git a/Queuing System/ActiveQManager/ActiveQManager.csproj b/Queuing System/ActiveQManager/ActiveQManager.csproj index 04b7124..577a6e6 100644 --- a/Queuing System/ActiveQManager/ActiveQManager.csproj +++ b/Queuing System/ActiveQManager/ActiveQManager.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -36,7 +36,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -77,6 +77,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -101,6 +102,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -112,6 +114,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -123,6 +126,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -134,6 +138,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -210,6 +215,9 @@ true + + + diff --git a/Queuing System/ActiveQManager/Properties/Resources.Designer.cs b/Queuing System/ActiveQManager/Properties/Resources.Designer.cs index 3b741a5..54bc29e 100644 --- a/Queuing System/ActiveQManager/Properties/Resources.Designer.cs +++ b/Queuing System/ActiveQManager/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18010 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,7 +19,7 @@ namespace ActiveQManager.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/Queuing System/ActiveQManager/app.config b/Queuing System/ActiveQManager/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQManager/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQTestConsole/ActiveQTestConsole.csproj b/Queuing System/ActiveQTestConsole/ActiveQTestConsole.csproj index 590053c..aa45efb 100644 --- a/Queuing System/ActiveQTestConsole/ActiveQTestConsole.csproj +++ b/Queuing System/ActiveQTestConsole/ActiveQTestConsole.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -35,7 +35,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -76,6 +76,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -100,6 +101,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -111,6 +113,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -122,6 +125,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -133,6 +137,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -179,6 +184,9 @@ true + + + diff --git a/Queuing System/ActiveQTestConsole/app.config b/Queuing System/ActiveQTestConsole/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQTestConsole/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Queuing System/ActiveQWindowsService/ActiveQWindowsService.csproj b/Queuing System/ActiveQWindowsService/ActiveQWindowsService.csproj index 4047f61..4d37db7 100644 --- a/Queuing System/ActiveQWindowsService/ActiveQWindowsService.csproj +++ b/Queuing System/ActiveQWindowsService/ActiveQWindowsService.csproj @@ -1,5 +1,5 @@  - + Local 8.0.50727 @@ -36,7 +36,7 @@ 3.5 - v4.0 + v4.6 publish\ true Disk @@ -77,6 +77,7 @@ full prompt AllRules.ruleset + false bin\Release\ @@ -101,6 +102,7 @@ none prompt AllRules.ruleset + false bin\Retail\ @@ -112,6 +114,7 @@ AnyCPU prompt AllRules.ruleset + false bin\Trial\ @@ -123,6 +126,7 @@ AnyCPU prompt AllRules.ruleset + false bin\MailSystem Dev\ @@ -134,6 +138,7 @@ AnyCPU prompt AllRules.ruleset + false @@ -202,6 +207,9 @@ true + + + diff --git a/Queuing System/ActiveQWindowsService/app.config b/Queuing System/ActiveQWindowsService/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Queuing System/ActiveQWindowsService/app.config @@ -0,0 +1,3 @@ + + + diff --git a/WindowsFormsApp1/App.config b/WindowsFormsApp1/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/WindowsFormsApp1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/WindowsFormsApp1/Class1.cs b/WindowsFormsApp1/Class1.cs new file mode 100644 index 0000000..e3e7edf --- /dev/null +++ b/WindowsFormsApp1/Class1.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using ActiveUp.Net.Mail; + +namespace WindowsFormsApp1 +{ + public class MailRepository + { + private Imap4Client _client = null; + + public MailRepository(string mailServer, int port, bool ssl, string login, string password) + { + if (ssl) + Client.ConnectSsl(mailServer, port); + else + Client.Connect(mailServer, port); + Client.Login(login, password); + } + + public IEnumerable GetAllMails(string mailBox) + { + return GetMails(mailBox, "ALL").Cast(); + } + + public IEnumerable GetUnreadMails(string mailBox) + { + return GetMails(mailBox, "UNSEEN").Cast(); + } + + protected Imap4Client Client + { + get + { + if (_client == null) + _client = new Imap4Client(); + return _client; + } + } + + private MessageCollection GetMails(string mailBox, string searchPhrase) + { + Mailbox mails = Client.SelectMailbox(mailBox); + MessageCollection messages = mails.SearchParse(searchPhrase); + return messages; + } + + Mailbox _mb; + public void ActivateMailBox(string mailBox) + { //var test = Client.Mailboxes; + //foreach (Mailbox folder in Client.Mailboxes) + //{ + // //Console.WriteLine("[folder] {0}", folder.); + //} + Client.SubFolders = false; + _mb = Client.SelectMailbox(mailBox); + + for (int x = _mb.MessageCount; x > 0; x--) + { + Message email = GetMessage(x); + System.Diagnostics.Debug.WriteLine(email.Subject); + } + } + internal Message GetMessage(int index) + { + return _mb.Fetch.MessageObject(index); + } + } +} \ No newline at end of file diff --git a/WindowsFormsApp1/Form1.Designer.cs b/WindowsFormsApp1/Form1.Designer.cs new file mode 100644 index 0000000..ec7d1ed --- /dev/null +++ b/WindowsFormsApp1/Form1.Designer.cs @@ -0,0 +1,48 @@ +namespace WindowsFormsApp1 +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + + } + + #endregion + } +} + diff --git a/WindowsFormsApp1/Form1.cs b/WindowsFormsApp1/Form1.cs new file mode 100644 index 0000000..fa682e3 --- /dev/null +++ b/WindowsFormsApp1/Form1.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApp1 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + //MailRepository temp = new MailRepository("outlook.office365.com", 993, true, "****@****.it", "****"); + MailRepository temp = new MailRepository("outlook.office365.com", 993, true, "*****@*****.it", "*********"); + temp.ActivateMailBox("INBOX"); + } + } +} diff --git a/WindowsFormsApp1/Form1.resx b/WindowsFormsApp1/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WindowsFormsApp1/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsApp1/Program.cs b/WindowsFormsApp1/Program.cs new file mode 100644 index 0000000..63442a0 --- /dev/null +++ b/WindowsFormsApp1/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApp1 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/WindowsFormsApp1/Properties/AssemblyInfo.cs b/WindowsFormsApp1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7d7bcb4 --- /dev/null +++ b/WindowsFormsApp1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WindowsFormsApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsApp1")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b1aca405-9ef9-4d7f-8cea-44ad36d35a2f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WindowsFormsApp1/Properties/Resources.Designer.cs b/WindowsFormsApp1/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b21d543 --- /dev/null +++ b/WindowsFormsApp1/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApp1.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/WindowsFormsApp1/Properties/Resources.resx b/WindowsFormsApp1/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/WindowsFormsApp1/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsApp1/Properties/Settings.Designer.cs b/WindowsFormsApp1/Properties/Settings.Designer.cs new file mode 100644 index 0000000..438df21 --- /dev/null +++ b/WindowsFormsApp1/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/WindowsFormsApp1/Properties/Settings.settings b/WindowsFormsApp1/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/WindowsFormsApp1/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/WindowsFormsApp1/WindowsFormsApp1.csproj b/WindowsFormsApp1/WindowsFormsApp1.csproj new file mode 100644 index 0000000..3e7be1b --- /dev/null +++ b/WindowsFormsApp1/WindowsFormsApp1.csproj @@ -0,0 +1,134 @@ + + + + + Debug + AnyCPU + {B1ACA405-9EF9-4D7F-8CEA-44AD36D35A2F} + WinExe + WindowsFormsApp1 + WindowsFormsApp1 + v4.6 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {3a83ae95-c23f-48b4-9f1a-ad4b32c37b93} + ActiveUp.Net.Common + + + {a82ce4dd-9b08-439c-bc28-cb7b2bffa85c} + ActiveUp.Net.Dns + + + {c646ed2b-50b7-4178-befa-657f1259251f} + ActiveUp.Net.Groupware + + + {6bee77df-2dd2-41c3-ba16-60e20b1eddcc} + ActiveUp.Net.Imap4 + + + {2bd4c73e-c8db-420e-9505-96d3f3bca7b6} + ActiveUp.Net.Mail + + + {ff4b354a-213b-415a-b8f7-582baafabc8c} + ActiveUp.Net.Nntp + + + {00cb8737-ba35-4775-afa4-b8cd446ab83f} + ActiveUp.Net.OpenPGP + + + {3f01cf20-c49d-44a9-aa57-68f04915fe97} + ActiveUp.Net.Pop3 + + + {d9bcd15e-a438-4554-89d3-1cf122167fdd} + ActiveUp.Net.Smtp + + + {5ad3438e-9024-4908-ba15-92726159c4fb} + ActiveUp.Net.Tests + + + {1e4d8e5b-d422-47dc-9cf3-b8e88a4472af} + ActiveUp.Net.WhoIs + + + {25da9502-b959-4e81-9368-471ae231bcc0} + ActiveUp.Net + + + + \ No newline at end of file From 25849047c4a6fdcb130462f710038923b9093388 Mon Sep 17 00:00:00 2001 From: "dtentori@softeam.it" Date: Fri, 25 Nov 2022 12:05:39 +0100 Subject: [PATCH 2/4] added OAuth2 authentication (Imap4Client.LoginOAuth2) --- .gitignore | 1 + Class Library/ActiveUp.Net.Common/Events.cs | 159 +++++++++++++----- .../ActiveUp.Net.Imap4.csproj | 19 +++ .../ExceptionsExtensions.cs | 26 +++ .../ActiveUp.Net.Imap4/Imap4Client.cs | 127 ++++++++++++-- .../ActiveUp.Net.Imap4/Imap4Exception.cs | 3 +- .../ActiveUp.Net.Imap4/OAuth2Token.cs | 24 +++ .../ActiveUp.Net.Imap4/packages.config | 6 + WindowsFormsApp1/Class1.cs | 9 +- WindowsFormsApp1/Form1.Designer.cs | 18 +- WindowsFormsApp1/Form1.cs | 16 +- WindowsFormsApp1/WindowsFormsApp1.csproj | 9 + 12 files changed, 351 insertions(+), 66 deletions(-) create mode 100644 Class Library/ActiveUp.Net.Imap4/ExceptionsExtensions.cs create mode 100644 Class Library/ActiveUp.Net.Imap4/OAuth2Token.cs create mode 100644 Class Library/ActiveUp.Net.Imap4/packages.config diff --git a/.gitignore b/.gitignore index fa97a93..f64b456 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML *.pubxml +/.cr/personal/Navigation/Code Places.xml diff --git a/Class Library/ActiveUp.Net.Common/Events.cs b/Class Library/ActiveUp.Net.Common/Events.cs index d030ea9..d373e56 100644 --- a/Class Library/ActiveUp.Net.Common/Events.cs +++ b/Class Library/ActiveUp.Net.Common/Events.cs @@ -24,11 +24,11 @@ namespace ActiveUp.Net.Mail /// /// EventHandler to be used with the Authenticating event. /// - public delegate void AuthenticatingEventHandler(object sender, AuthenticatingEventArgs e); + public delegate void AuthenticatingEventHandler(object sender, AuthenticatingEventArgsBase e); /// /// EventHandler to be used with the Authenticated event. /// - public delegate void AuthenticatedEventHandler(object sender, AuthenticatedEventArgs e); + public delegate void AuthenticatedEventHandler(object sender, AuthenticatedEventArgsBase e); /// /// EventHandler to be used with the Nooping event. /// @@ -559,10 +559,49 @@ public string Response #if !PocketPC [System.Serializable] #endif - public class AuthenticatedEventArgs : System.EventArgs + + + public class AuthenticatedEventArgsBase : System.EventArgs { - string _username,_password,_host,_serverResponse; + protected string _username, _password, _host, _serverResponse; + /// + /// The username used to authenticate the user. + /// + public string Username + { + get + { + return _username; + } + } + + /// + /// The address of the remote server. + /// + public string Host + { + get + { + return _host; + } + } + + /// + /// The server's response + /// + public string ServerResponse + { + get + { + return _serverResponse; + } + } + } + + public class AuthenticatedEventArgs : AuthenticatedEventArgsBase + { + /// /// Constructor. /// @@ -591,56 +630,84 @@ public AuthenticatedEventArgs(string username, string password, string serverRes _serverResponse = serverResponse; } /// - /// The username used to authenticate the user. + /// The password used to authenticate the user. /// - public string Username + public string Password { get { - return _username; + return _password; } } + + } + + public class AuthenticatedOAuth2EventArgs : AuthenticatedEventArgsBase + { /// - /// The password used to authenticate the user. + /// Constructor. /// - public string Password + /// Username used to authenticate the user. + /// Address of the remote server. + /// The server response to the PASS command. + public AuthenticatedOAuth2EventArgs(string username, string host, string serverResponse) { - get - { - return _password; - } + _username = username; + _host = host; + _serverResponse = serverResponse; } /// - /// The address of the remote server. + /// Constructor. /// - public string Host + /// Username used to authenticate the user. + /// The server response to the PASS command. + public AuthenticatedOAuth2EventArgs(string username, string serverResponse) + { + _username = username; + _host = "unknown"; + _serverResponse = serverResponse; + } + + } + /// + /// Represents a future authentication process. + /// +#if !PocketPC + [System.Serializable] +#endif + + + public class AuthenticatingEventArgsBase : System.EventArgs + { + protected string _username, _host; + + /// + /// The username used to authenticate the user. + /// + public string Username { get { - return _host; + return _username; } } + /// - /// The server's response + /// The address of the remote server. /// - public string ServerResponse + public string Host { get { - return _serverResponse; + return _host; } } + } - /// - /// Represents a future authentication process. - /// -#if !PocketPC - [System.Serializable] -#endif - public class AuthenticatingEventArgs : System.EventArgs + public class AuthenticatingEventArgs : AuthenticatingEventArgsBase { - string _username,_password,_host; + string _password; /// /// Constructor. @@ -665,37 +732,45 @@ public AuthenticatingEventArgs(string username, string password) _password = password; _host = "unkwown"; } + /// - /// The username used to authenticate the user. + /// The password used to authenticate the user. /// - public string Username + public string Password { get { - return _username; + return _password; } } + } + + public class AuthenticatingOAuth2EventArgs : AuthenticatingEventArgsBase + { /// - /// The password used to authenticate the user. + /// Constructor. /// - public string Password + /// Username used to authenticate the user. + /// Password used to authenticate the user. + /// Address of the remote server. + public AuthenticatingOAuth2EventArgs(string username, string host) { - get - { - return _password; - } + _username = username; + _host = host; } + /// - /// The address of the remote server. + /// Constructor. /// - public string Host + /// Username used to authenticate the user. + /// Password used to authenticate the user. + public AuthenticatingOAuth2EventArgs(string username) { - get - { - return _host; - } + _username = username; + _host = "unkwown"; } } + /*/// /// EventArgs used by the ArticleRetrieved event. /// diff --git a/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj b/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj index 511d6d3..f93802d 100644 --- a/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj +++ b/Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj @@ -96,12 +96,29 @@ false + + + ..\..\packages\Microsoft.Identity.Client.4.48.1\lib\net45\Microsoft.Identity.Client.dll + + + ..\..\packages\Microsoft.IdentityModel.Abstractions.6.22.0\lib\net45\Microsoft.IdentityModel.Abstractions.dll + + + ..\..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + @@ -111,10 +128,12 @@ + + diff --git a/Class Library/ActiveUp.Net.Imap4/ExceptionsExtensions.cs b/Class Library/ActiveUp.Net.Imap4/ExceptionsExtensions.cs new file mode 100644 index 0000000..123d8b1 --- /dev/null +++ b/Class Library/ActiveUp.Net.Imap4/ExceptionsExtensions.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ActiveUp.Net.Imap4 +{ + public static class ExceptionsExtensions + { + + public static string HideSensitiveData(this string message) + { + if (!string.IsNullOrEmpty(message)) + { + var loginToken = "login"; + var idx = message.IndexOf(loginToken, StringComparison.InvariantCultureIgnoreCase); + if (idx > 0) + { + message = message.Substring(0, idx + loginToken.Length); + message += " *** SENSITIVE DATA *** "; + } + } + return message; + } + } +} diff --git a/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs b/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs index fe02d9a..0335c23 100644 --- a/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs +++ b/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs @@ -21,6 +21,14 @@ using ActiveUp.Net.Security; using System.Net.Sockets; using System.Net.Security; +using System.Net.Http; +using Newtonsoft.Json; +using System.Net; +using System.Threading.Tasks; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using ActiveUp.Net.Imap4; +using Microsoft.Identity.Client; namespace ActiveUp.Net.Mail { @@ -261,13 +269,13 @@ static Imap4Client() #region Event triggers and logging - internal void OnAuthenticating(AuthenticatingEventArgs e) + internal void OnAuthenticating(AuthenticatingEventArgsBase e) { if (Authenticating != null) Authenticating(this, e); Logger.AddEntry(GetType(), "Authenticating as <" + e.Username + "> on <" + e.Host + ">...", 2); } - internal void OnAuthenticated(AuthenticatedEventArgs e) + internal void OnAuthenticated(AuthenticatedEventArgsBase e) { if (Authenticated != null) Authenticated(this, e); @@ -396,7 +404,7 @@ private string _CramMd5(string username, string password) } private string _Login(string username, string password) - { + { OnAuthenticating(new AuthenticatingEventArgs(username, password)); string stamp = DateTime.Now.ToString("yyMMddhhmmss" + DateTime.Now.Millisecond.ToString()); Command("authenticate login"); @@ -420,7 +428,7 @@ private string _Plain(string username, string password) } private static string FindLine(string[] input, string pattern) - { + { foreach (string str in input) if (str.IndexOf(pattern) != -1) return str; @@ -902,13 +910,93 @@ public string Login(string username, string password) //LoadMailboxes(); return response; } + + internal async Task GetOAuth2Token(string tenantId, string clientId, string clientSecret) + { + //https://stackoverflow.com/questions/38494279/how-do-i-get-an-oauth-2-0-authentication-token-in-c-sharp + + string baseAddress = $"https://login.microsoftonline.com/{tenantId}/oauth2/token"; + string grant_type = "client_credentials"; + + bool useMSAL = true; + + if (useMSAL) + { + var app = ConfidentialClientApplicationBuilder + .Create(clientId) + .WithTenantId(tenantId) + .WithClientSecret(clientSecret) + .Build(); + + string[] scopes = new string[] { + "https://outlook.office365.com/.default", + }; + + var result = await app.AcquireTokenForClient(scopes).ExecuteAsync(); + string accessToken = result.AccessToken; + return accessToken; + } + else + { + //[dt] token generation is OK but AUTH fails, further investigations needed + var client = new HttpClient(); + + List scopes = new List + { + "https://outlook.office365.com/.default", + }; + + var form = new Dictionary + { + {"grant_type", grant_type}, + {"client_id", clientId}, + {"client_secret", clientSecret}, + {"scope", string.Join(" ",scopes) } + }; + + HttpResponseMessage tokenResponse = await client.PostAsync(baseAddress, new FormUrlEncodedContent(form)); + var jsonContent = await tokenResponse.Content.ReadAsStringAsync(); + OAuth2Token token = JsonConvert.DeserializeObject(jsonContent); + return token.AccessToken; + } + } + + public async Task LoginOAuth2(string userName, string tenantId, string clientId, string clientSecret) + { + var token = await GetOAuth2Token(tenantId, clientId, clientSecret); + + OnAuthenticating(new AuthenticatingOAuth2EventArgs(userName, host)); + + //https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth + string response = ""; + string xOauth2; + using (var ms = new MemoryStream(token.Length + 200)) + { + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Encoding.ASCII.GetBytes("user=")); + bw.Write(Encoding.ASCII.GetBytes(userName)); + bw.Write((byte)1); + bw.Write(Encoding.ASCII.GetBytes("auth=Bearer ")); + bw.Write(Encoding.ASCII.GetBytes(token)); + bw.Write((byte)1); + bw.Write((byte)1); + } + xOauth2 = Convert.ToBase64String(ms.ToArray()); + } + var cmd = $"AUTHENTICATE XOAUTH2 {xOauth2}"; + response = Command(cmd); + OnAuthenticated(new AuthenticatedOAuth2EventArgs(userName, host, response)); + return response; + } + + public IAsyncResult BeginLogin(string username, string password, AsyncCallback callback) { _delegateLogin = Login; return _delegateLogin.BeginInvoke(username, password, callback, _delegateLogin); } - /// /// Same as Login but doesn't load the AllMailboxes and Mailboxes properties of the Imap4Client object, ensuring faster operation. /// @@ -1100,7 +1188,8 @@ public byte[] CommandBinary(string command, string stamp, CommandOptions options { Logger.AddEntry(GetType(), "part response is null"); partResponse = ""; - } else + } + else Logger.AddEntry(GetType(), "part response: " + partResponse); buffer.Append(partResponse); @@ -1167,7 +1256,7 @@ public byte[] CommandBinary(string command, string stamp, CommandOptions options sr.BaseStream.Read(bufferBytes, 0, bufferBytes.Length); if (!sr.CurrentEncoding.Equals(Encoding.UTF8)) - { + { var utf8Bytes = Encoding.Convert(sr.CurrentEncoding, Encoding.UTF8, sr.CurrentEncoding.GetBytes(bufferString)); bufferString = Encoding.UTF8.GetString(utf8Bytes); } @@ -1364,8 +1453,10 @@ public string EndCommand(IAsyncResult result) /// Gets the communication stream of this object. /// /// A Stream object, either of type NetworkStream or SslStream if the channel is secured. - public Stream Stream { - get { + public Stream Stream + { + get + { #if !PocketPC if (_sslStream != null) return _sslStream; @@ -1920,10 +2011,10 @@ public Mailbox SelectMailbox(string mailboxName) mailboxName = renderSafeParam(mailboxName); Mailbox mailbox = new Mailbox(); - - if(SubFolders) - mailbox.SubMailboxes = GetMailboxes(mailboxName, "*"); - + + if (SubFolders) + mailbox.SubMailboxes = GetMailboxes(mailboxName, "*"); + string response = Command("select \"" + mailboxName + "\""); string[] lines = System.Text.RegularExpressions.Regex.Split(response, "\r\n"); @@ -1950,8 +2041,8 @@ public Mailbox SelectMailbox(string mailboxName) try { string line = FindLine(lines, "[UNSEEN "); - if(!String.IsNullOrEmpty(line)) - unseen = Convert.ToInt32(line.Split(' ')[3].TrimEnd(']')); + if (!String.IsNullOrEmpty(line)) + unseen = Convert.ToInt32(line.Split(' ')[3].TrimEnd(']')); } catch (Exception) { } mailbox.FirstUnseen = (response.ToLower().IndexOf("[unseen") != -1) ? unseen : 0; @@ -1966,8 +2057,10 @@ public Mailbox SelectMailbox(string mailboxName) mailbox.UidValidity = uidValidity; // flags. - foreach (string str in FindLine(lines, " FLAGS").Split(' ')) { - if (str.StartsWith("(\\") || str.StartsWith("\\")) { + foreach (string str in FindLine(lines, " FLAGS").Split(' ')) + { + if (str.StartsWith("(\\") || str.StartsWith("\\")) + { mailbox.ApplicableFlags.Add(str.Trim(new char[] { ' ', '\\', ')', '(' })); } } diff --git a/Class Library/ActiveUp.Net.Imap4/Imap4Exception.cs b/Class Library/ActiveUp.Net.Imap4/Imap4Exception.cs index 612738d..dd17ec3 100644 --- a/Class Library/ActiveUp.Net.Imap4/Imap4Exception.cs +++ b/Class Library/ActiveUp.Net.Imap4/Imap4Exception.cs @@ -15,6 +15,7 @@ // along with SharpMap; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +using ActiveUp.Net.Imap4; using System; namespace ActiveUp.Net.Mail @@ -42,7 +43,7 @@ public Imap4Exception(byte[] response) : this("An unspecified IMAP error occurre /// Constructor, sets message to the specified value. /// /// - public Imap4Exception(string message) : base(message) { } + public Imap4Exception(string message) : base(message.HideSensitiveData()) { } /// /// Constructor, sets message to the specified value diff --git a/Class Library/ActiveUp.Net.Imap4/OAuth2Token.cs b/Class Library/ActiveUp.Net.Imap4/OAuth2Token.cs new file mode 100644 index 0000000..c077e3e --- /dev/null +++ b/Class Library/ActiveUp.Net.Imap4/OAuth2Token.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ActiveUp.Net.Imap4 +{ + public class OAuth2Token + { + [JsonProperty("access_token")] + public string AccessToken { get; set; } + + [JsonProperty("token_type")] + public string TokenType { get; set; } + + [JsonProperty("expires_in")] + public int ExpiresIn { get; set; } + + [JsonProperty("refresh_token")] + public string RefreshToken { get; set; } + } +} diff --git a/Class Library/ActiveUp.Net.Imap4/packages.config b/Class Library/ActiveUp.Net.Imap4/packages.config new file mode 100644 index 0000000..d4e77e2 --- /dev/null +++ b/Class Library/ActiveUp.Net.Imap4/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/WindowsFormsApp1/Class1.cs b/WindowsFormsApp1/Class1.cs index e3e7edf..60e6438 100644 --- a/WindowsFormsApp1/Class1.cs +++ b/WindowsFormsApp1/Class1.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using System.Web; using ActiveUp.Net.Mail; @@ -10,13 +11,17 @@ public class MailRepository { private Imap4Client _client = null; - public MailRepository(string mailServer, int port, bool ssl, string login, string password) + public MailRepository(string mailServer, int port, bool ssl) { if (ssl) Client.ConnectSsl(mailServer, port); else Client.Connect(mailServer, port); - Client.Login(login, password); + } + + public async Task LoginOAuth2(string user, string tenantId, string clientId, string clientSecret) + { + return await Client.LoginOAuth2(user, tenantId, clientId, clientSecret); } public IEnumerable GetAllMails(string mailBox) diff --git a/WindowsFormsApp1/Form1.Designer.cs b/WindowsFormsApp1/Form1.Designer.cs index ec7d1ed..c1729ba 100644 --- a/WindowsFormsApp1/Form1.Designer.cs +++ b/WindowsFormsApp1/Form1.Designer.cs @@ -28,13 +28,25 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton(); this.SuspendLayout(); // + // simpleButton1 + // + this.simpleButton1.Location = new System.Drawing.Point(195, 298); + this.simpleButton1.Name = "simpleButton1"; + this.simpleButton1.Size = new System.Drawing.Size(110, 36); + this.simpleButton1.TabIndex = 0; + this.simpleButton1.Text = "simpleButton1"; + this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click); + // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(1067, 554); + this.Controls.Add(this.simpleButton1); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); @@ -43,6 +55,8 @@ private void InitializeComponent() } #endregion + + private DevExpress.XtraEditors.SimpleButton simpleButton1; } } diff --git a/WindowsFormsApp1/Form1.cs b/WindowsFormsApp1/Form1.cs index fa682e3..dfe0779 100644 --- a/WindowsFormsApp1/Form1.cs +++ b/WindowsFormsApp1/Form1.cs @@ -20,8 +20,20 @@ public Form1() private void Form1_Load(object sender, EventArgs e) { //MailRepository temp = new MailRepository("outlook.office365.com", 993, true, "****@****.it", "****"); - MailRepository temp = new MailRepository("outlook.office365.com", 993, true, "*****@*****.it", "*********"); - temp.ActivateMailBox("INBOX"); + //MailRepository temp = new MailRepository("outlook.office365.com", 993, true, "*****@*****.it", "*********"); + } + + private async void simpleButton1_Click(object sender, EventArgs e) + { + MailRepository mailRep = new MailRepository("outlook.office365.com", 993, true); + + string tenantId = "APP TENANTID"; + string client_id = "APP CLIENTID"; + string client_secret = "APP SECRET"; + + await mailRep.LoginOAuth2("lyrahelpcc@softeam.it", tenantId, client_id, client_secret); + mailRep.ActivateMailBox("INBOX"); + } } } diff --git a/WindowsFormsApp1/WindowsFormsApp1.csproj b/WindowsFormsApp1/WindowsFormsApp1.csproj index 3e7be1b..5b05011 100644 --- a/WindowsFormsApp1/WindowsFormsApp1.csproj +++ b/WindowsFormsApp1/WindowsFormsApp1.csproj @@ -33,8 +33,17 @@ 4 + + + + + + + + + From b10941e1da3f607eb5d3f4b189daf98f9af074a0 Mon Sep 17 00:00:00 2001 From: "dtentori@softeam.it" Date: Fri, 25 Nov 2022 18:11:34 +0100 Subject: [PATCH 3/4] logging improvements --- Class Library/ActiveUp.Net.Common/Events.cs | 26 ++-- Class Library/ActiveUp.Net.Common/Logger.cs | 2 +- .../ActiveUp.Net.Imap4/Imap4Client.cs | 128 ++++++++++-------- WindowsFormsApp1/Class1.cs | 25 +++- WindowsFormsApp1/Form1.Designer.cs | 24 +++- WindowsFormsApp1/Form1.cs | 31 ++++- 6 files changed, 157 insertions(+), 79 deletions(-) diff --git a/Class Library/ActiveUp.Net.Common/Events.cs b/Class Library/ActiveUp.Net.Common/Events.cs index d373e56..e216e9a 100644 --- a/Class Library/ActiveUp.Net.Common/Events.cs +++ b/Class Library/ActiveUp.Net.Common/Events.cs @@ -559,15 +559,15 @@ public string Response #if !PocketPC [System.Serializable] #endif + public class AuthEventArgsBase : System.EventArgs + { + public string Message { get; set; } + } - - public class AuthenticatedEventArgsBase : System.EventArgs + public class AuthenticatedEventArgsBase : AuthEventArgsBase { + protected string _username, _password, _host, _serverResponse; - /// - /// The username used to authenticate the user. - /// - public string Username { get @@ -601,7 +601,7 @@ public string ServerResponse public class AuthenticatedEventArgs : AuthenticatedEventArgsBase { - + /// /// Constructor. /// @@ -655,6 +655,8 @@ public AuthenticatedOAuth2EventArgs(string username, string host, string server _username = username; _host = host; _serverResponse = serverResponse; + + Message = $"AUTHENTICATED: username = {_username}; host = {_host}; serverResponse = {_serverResponse}"; } /// /// Constructor. @@ -666,6 +668,7 @@ public AuthenticatedOAuth2EventArgs(string username, string serverResponse) _username = username; _host = "unknown"; _serverResponse = serverResponse; + Message = $"AUTHENTICATED: username = {_username}; serverResponse = {_serverResponse}"; } } @@ -677,8 +680,10 @@ public AuthenticatedOAuth2EventArgs(string username, string serverResponse) #endif - public class AuthenticatingEventArgsBase : System.EventArgs + + public class AuthenticatingEventArgsBase : AuthEventArgsBase { + protected string _username, _host; /// @@ -702,8 +707,7 @@ public string Host return _host; } } - - } + } public class AuthenticatingEventArgs : AuthenticatingEventArgsBase { @@ -757,6 +761,7 @@ public AuthenticatingOAuth2EventArgs(string username, string host) { _username = username; _host = host; + Message = $"AUTHENTICATING: username = {username}; host = {_host}"; } /// @@ -768,6 +773,7 @@ public AuthenticatingOAuth2EventArgs(string username) { _username = username; _host = "unkwown"; + Message = $"AUTHENTICATING: username = {username}"; } } diff --git a/Class Library/ActiveUp.Net.Common/Logger.cs b/Class Library/ActiveUp.Net.Common/Logger.cs index 8d90397..b793475 100644 --- a/Class Library/ActiveUp.Net.Common/Logger.cs +++ b/Class Library/ActiveUp.Net.Common/Logger.cs @@ -58,7 +58,7 @@ public static class Logger /// /// Specify whether if the logger needs to append the Trace Console. /// - public static bool UseTraceConsole { get; set; } = false; + public static bool UseTraceConsole { get; set; } = true; /// /// Specify whether if the logging functions are disabled. diff --git a/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs b/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs index 0335c23..11726de 100644 --- a/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs +++ b/Class Library/ActiveUp.Net.Imap4/Imap4Client.cs @@ -918,76 +918,92 @@ internal async Task GetOAuth2Token(string tenantId, string clientId, str string baseAddress = $"https://login.microsoftonline.com/{tenantId}/oauth2/token"; string grant_type = "client_credentials"; - bool useMSAL = true; - - if (useMSAL) - { - var app = ConfidentialClientApplicationBuilder - .Create(clientId) - .WithTenantId(tenantId) - .WithClientSecret(clientSecret) - .Build(); - - string[] scopes = new string[] { - "https://outlook.office365.com/.default", - }; - - var result = await app.AcquireTokenForClient(scopes).ExecuteAsync(); - string accessToken = result.AccessToken; - return accessToken; - } - else + try { - //[dt] token generation is OK but AUTH fails, further investigations needed - var client = new HttpClient(); + bool useMSAL = true; - List scopes = new List + if (useMSAL) { - "https://outlook.office365.com/.default", - }; - - var form = new Dictionary + var app = ConfidentialClientApplicationBuilder + .Create(clientId) + .WithTenantId(tenantId) + .WithClientSecret(clientSecret) + .Build(); + + string[] scopes = new string[] { + "https://outlook.office365.com/.default", + }; + + var result = await app.AcquireTokenForClient(scopes).ExecuteAsync(); + string accessToken = result.AccessToken; + return accessToken; + } + else { - {"grant_type", grant_type}, - {"client_id", clientId}, - {"client_secret", clientSecret}, - {"scope", string.Join(" ",scopes) } - }; - - HttpResponseMessage tokenResponse = await client.PostAsync(baseAddress, new FormUrlEncodedContent(form)); - var jsonContent = await tokenResponse.Content.ReadAsStringAsync(); - OAuth2Token token = JsonConvert.DeserializeObject(jsonContent); - return token.AccessToken; + //[dt] token generation is OK but AUTH fails, further investigations needed + var client = new HttpClient(); + + List scopes = new List + { + "https://outlook.office365.com/.default", + }; + + var form = new Dictionary + { + {"grant_type", grant_type}, + {"client_id", clientId}, + {"client_secret", clientSecret}, + {"scope", string.Join(" ",scopes) } + }; + + HttpResponseMessage tokenResponse = await client.PostAsync(baseAddress, new FormUrlEncodedContent(form)); + var jsonContent = await tokenResponse.Content.ReadAsStringAsync(); + OAuth2Token token = JsonConvert.DeserializeObject(jsonContent); + return token.AccessToken; + } + } + catch (Exception ex) + { + OnAuthenticating(new AuthenticatingEventArgsBase { Message = $"error during token generation: {ex.Message}\n{ex.StackTrace}" }); + throw ex; } } - public async Task LoginOAuth2(string userName, string tenantId, string clientId, string clientSecret) + public async Task LoginOAuth2(string userName, string tenantId, string clientId, string clientSecret) { - var token = await GetOAuth2Token(tenantId, clientId, clientSecret); - - OnAuthenticating(new AuthenticatingOAuth2EventArgs(userName, host)); - - //https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth string response = ""; - string xOauth2; - using (var ms = new MemoryStream(token.Length + 200)) + try { - using (var bw = new BinaryWriter(ms)) + var token = await GetOAuth2Token(tenantId, clientId, clientSecret); + + OnAuthenticating(new AuthenticatingOAuth2EventArgs(userName, host)); + //https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth + string xOauth2; + using (var ms = new MemoryStream(token.Length + 200)) { - bw.Write(Encoding.ASCII.GetBytes("user=")); - bw.Write(Encoding.ASCII.GetBytes(userName)); - bw.Write((byte)1); - bw.Write(Encoding.ASCII.GetBytes("auth=Bearer ")); - bw.Write(Encoding.ASCII.GetBytes(token)); - bw.Write((byte)1); - bw.Write((byte)1); + using (var bw = new BinaryWriter(ms)) + { + bw.Write(Encoding.ASCII.GetBytes("user=")); + bw.Write(Encoding.ASCII.GetBytes(userName)); + bw.Write((byte)1); + bw.Write(Encoding.ASCII.GetBytes("auth=Bearer ")); + bw.Write(Encoding.ASCII.GetBytes(token)); + bw.Write((byte)1); + bw.Write((byte)1); + } + xOauth2 = Convert.ToBase64String(ms.ToArray()); } - xOauth2 = Convert.ToBase64String(ms.ToArray()); + var cmd = $"AUTHENTICATE XOAUTH2 {xOauth2}"; + + response = Command(cmd); + } + catch (Exception ex) + { + OnAuthenticating(new AuthenticatingEventArgsBase { Message = $"error during token login: {ex.Message}\n{ex.StackTrace}" }); + return false; } - var cmd = $"AUTHENTICATE XOAUTH2 {xOauth2}"; - response = Command(cmd); OnAuthenticated(new AuthenticatedOAuth2EventArgs(userName, host, response)); - return response; + return true; } diff --git a/WindowsFormsApp1/Class1.cs b/WindowsFormsApp1/Class1.cs index 60e6438..e49bc53 100644 --- a/WindowsFormsApp1/Class1.cs +++ b/WindowsFormsApp1/Class1.cs @@ -7,8 +7,17 @@ namespace WindowsFormsApp1 { + + public delegate void AuthenticatingEventHandler(object sender, AuthenticatingEventArgsBase e); + public delegate void AuthenticatedEventHandler(object sender, AuthenticatedEventArgsBase e); + + public class MailRepository { + + public event AuthenticatingEventHandler Authenticating; + public event AuthenticatedEventHandler Authenticated; + private Imap4Client _client = null; public MailRepository(string mailServer, int port, bool ssl) @@ -19,7 +28,7 @@ public MailRepository(string mailServer, int port, bool ssl) Client.Connect(mailServer, port); } - public async Task LoginOAuth2(string user, string tenantId, string clientId, string clientSecret) + public async Task LoginOAuth2(string user, string tenantId, string clientId, string clientSecret) { return await Client.LoginOAuth2(user, tenantId, clientId, clientSecret); } @@ -39,11 +48,25 @@ protected Imap4Client Client get { if (_client == null) + { _client = new Imap4Client(); + _client.Authenticating += _client_Authenticating; + _client.Authenticated += _client_Authenticated; + } return _client; } } + private void _client_Authenticated(object sender, AuthenticatedEventArgsBase e) + { + Authenticated?.Invoke(sender, e); + } + + private void _client_Authenticating(object sender, AuthenticatingEventArgsBase e) + { + Authenticating?.Invoke(sender, e); + } + private MessageCollection GetMails(string mailBox, string searchPhrase) { Mailbox mails = Client.SelectMailbox(mailBox); diff --git a/WindowsFormsApp1/Form1.Designer.cs b/WindowsFormsApp1/Form1.Designer.cs index c1729ba..dccf252 100644 --- a/WindowsFormsApp1/Form1.Designer.cs +++ b/WindowsFormsApp1/Form1.Designer.cs @@ -29,27 +29,38 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton(); + this.memoEdit1 = new DevExpress.XtraEditors.MemoEdit(); + ((System.ComponentModel.ISupportInitialize)(this.memoEdit1.Properties)).BeginInit(); this.SuspendLayout(); // // simpleButton1 // - this.simpleButton1.Location = new System.Drawing.Point(195, 298); + this.simpleButton1.Location = new System.Drawing.Point(22, 30); + this.simpleButton1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.simpleButton1.Name = "simpleButton1"; - this.simpleButton1.Size = new System.Drawing.Size(110, 36); + this.simpleButton1.Size = new System.Drawing.Size(122, 29); this.simpleButton1.TabIndex = 0; - this.simpleButton1.Text = "simpleButton1"; + this.simpleButton1.Text = "Connect to IMAP"; this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click); // + // memoEdit1 + // + this.memoEdit1.Location = new System.Drawing.Point(22, 98); + this.memoEdit1.Name = "memoEdit1"; + this.memoEdit1.Size = new System.Drawing.Size(753, 306); + this.memoEdit1.TabIndex = 1; + // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1067, 554); + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.memoEdit1); this.Controls.Add(this.simpleButton1); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); + ((System.ComponentModel.ISupportInitialize)(this.memoEdit1.Properties)).EndInit(); this.ResumeLayout(false); } @@ -57,6 +68,7 @@ private void InitializeComponent() #endregion private DevExpress.XtraEditors.SimpleButton simpleButton1; + private DevExpress.XtraEditors.MemoEdit memoEdit1; } } diff --git a/WindowsFormsApp1/Form1.cs b/WindowsFormsApp1/Form1.cs index dfe0779..ce5fde8 100644 --- a/WindowsFormsApp1/Form1.cs +++ b/WindowsFormsApp1/Form1.cs @@ -27,13 +27,34 @@ private async void simpleButton1_Click(object sender, EventArgs e) { MailRepository mailRep = new MailRepository("outlook.office365.com", 993, true); - string tenantId = "APP TENANTID"; - string client_id = "APP CLIENTID"; - string client_secret = "APP SECRET"; + string tenantId = "**********************"; + string client_id = "**********************"; + string client_secret = "**********************"; - await mailRep.LoginOAuth2("lyrahelpcc@softeam.it", tenantId, client_id, client_secret); - mailRep.ActivateMailBox("INBOX"); + mailRep.Authenticated += MailRep_Authenticated; + mailRep.Authenticating += MailRep_Authenticating; + bool res = await mailRep.LoginOAuth2("lyrahelpcc@softeam.it", tenantId, client_id, client_secret); + if (res) + { + mailRep.ActivateMailBox("INBOX"); + } + } + + private void MailRep_Authenticating(object sender, ActiveUp.Net.Mail.AuthenticatingEventArgsBase e) + { + this.Invoke(new Action(() => + { + memoEdit1.Text += e.Message + Environment.NewLine; + })); + } + + private void MailRep_Authenticated(object sender, ActiveUp.Net.Mail.AuthenticatedEventArgsBase e) + { + this.Invoke(new Action(() => + { + memoEdit1.Text += e.Message + Environment.NewLine; ; + })); } } } From c26e7a29f48f7f0bfd852777ac607958ea5976e1 Mon Sep 17 00:00:00 2001 From: "dtentori@softeam.it" Date: Mon, 28 Nov 2022 11:52:28 +0100 Subject: [PATCH 4/4] removed console tracing --- Class Library/ActiveUp.Net.Common/Logger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Class Library/ActiveUp.Net.Common/Logger.cs b/Class Library/ActiveUp.Net.Common/Logger.cs index b793475..8d90397 100644 --- a/Class Library/ActiveUp.Net.Common/Logger.cs +++ b/Class Library/ActiveUp.Net.Common/Logger.cs @@ -58,7 +58,7 @@ public static class Logger /// /// Specify whether if the logger needs to append the Trace Console. /// - public static bool UseTraceConsole { get; set; } = true; + public static bool UseTraceConsole { get; set; } = false; /// /// Specify whether if the logging functions are disabled.