diff --git a/IMAPClient/.vs/IMAPClient/v16/.suo b/IMAPClient/.vs/IMAPClient/v16/.suo index 7db2c9a155dab4b89b6bab8a8f2e7c7f8dad541c..567d97fbcb1293cadb6e463f8b43f4b4d45217e2 100644 Binary files a/IMAPClient/.vs/IMAPClient/v16/.suo and b/IMAPClient/.vs/IMAPClient/v16/.suo differ diff --git a/IMAPClient/IMAPClient/Client.cs b/IMAPClient/IMAPClient/Client.cs index a9247f1e03bc22b77cd7ba7312eb20016661a82a..ee2852a5966fcae9e8cbccf17309cc6effdb6847 100644 --- a/IMAPClient/IMAPClient/Client.cs +++ b/IMAPClient/IMAPClient/Client.cs @@ -25,6 +25,69 @@ namespace IMAPClient StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); + Boolean keskustelu = true; + String viesti = ""; + ImapState tila = ImapState.Unaunthenticated; + int counter = 1; + string user = "mrc"; + string pass = "secret"; + + while (keskustelu) + { + viesti = sr.ReadLine(); + Console.WriteLine(viesti); + String[] status = viesti.Split(' '); + string vastaus = ""; + + switch(tila) + { + case ImapState.Unaunthenticated: + if(status[0] == "OK") + { + vastaus = "a" + counter.ToString("000") + " "; + vastaus += "login "; + vastaus += user + " " + pass; + sw.WriteLine(vastaus); + counter++; + tila = ImapState.Authenticated; + } + break; + case ImapState.Authenticated: + if(status[1] == "OK") + { + vastaus = "a" + counter.ToString("000") + " "; + vastaus += "list INBOX/\\ \"\""; + sw.WriteLine(vastaus); + counter++; + tila = ImapState.Logout; + } + break; + case ImapState.Logout: + vastaus = "a" + counter.ToString("000") + " "; + vastaus += "logout"; + sw.WriteLine(vastaus); + keskustelu = false; + break; + default: + break; + } + + sw.Flush(); + } + Console.ReadKey(); + + sw.Close(); + sr.Close(); + ns.Close(); + socket.Close(); } } + + enum ImapState : UInt16 + { + Unaunthenticated, + Authenticated, + Selected, + Logout + } } diff --git a/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.deps.json b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.deps.json new file mode 100644 index 0000000000000000000000000000000000000000..8b9f8e5f23aeedab46522fdd7907cab8544e6a57 --- /dev/null +++ b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v3.1", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v3.1": { + "IMAPClient/1.0.0": { + "runtime": { + "IMAPClient.dll": {} + } + } + } + }, + "libraries": { + "IMAPClient/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.dll b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.dll new file mode 100644 index 0000000000000000000000000000000000000000..48d2a9dec8444c897c95eb6e3c88df78358d76b0 Binary files /dev/null and b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.dll differ diff --git a/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.exe b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.exe new file mode 100644 index 0000000000000000000000000000000000000000..8127ce3866e0b85376a9ca8772cb4bdeef17572b Binary files /dev/null and b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.exe differ diff --git a/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.pdb b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.pdb new file mode 100644 index 0000000000000000000000000000000000000000..42b0c9128834c1b1c34f11c895c8bbd8e25b7fea Binary files /dev/null and b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.pdb differ diff --git a/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.runtimeconfig.dev.json b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.runtimeconfig.dev.json new file mode 100644 index 0000000000000000000000000000000000000000..9c9aff74d0f5c5b745a7d98df0d03319b4b012c4 --- /dev/null +++ b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.runtimeconfig.dev.json @@ -0,0 +1,8 @@ +{ + "runtimeOptions": { + "additionalProbingPaths": [ + "C:\\Users\\Joppe\\.dotnet\\store\\|arch|\\|tfm|", + "C:\\Users\\Joppe\\.nuget\\packages" + ] + } +} \ No newline at end of file diff --git a/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.runtimeconfig.json b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.runtimeconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..bc456d7868bb54ec1809da30e339cd43f0a8a09c --- /dev/null +++ b/IMAPClient/IMAPClient/bin/Debug/netcoreapp3.1/IMAPClient.runtimeconfig.json @@ -0,0 +1,9 @@ +{ + "runtimeOptions": { + "tfm": "netcoreapp3.1", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "3.1.0" + } + } +} \ No newline at end of file diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csproj.CoreCompileInputs.cache b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000000000000000000000000000000000000..62f865bf5372447305f96f129296618d3d93c498 --- /dev/null +++ b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +ecfb1d2d9a35dd77852bf69575ecb4fc404b2ea7 diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csproj.FileListAbsolute.txt b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csproj.FileListAbsolute.txt new file mode 100644 index 0000000000000000000000000000000000000000..08b953114c8b79ff00fe2454bcb2efe43d326240 --- /dev/null +++ b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csproj.FileListAbsolute.txt @@ -0,0 +1,13 @@ +E:\Kurssit\ties323\IMAPClient\IMAPClient\bin\Debug\netcoreapp3.1\IMAPClient.exe +E:\Kurssit\ties323\IMAPClient\IMAPClient\bin\Debug\netcoreapp3.1\IMAPClient.deps.json +E:\Kurssit\ties323\IMAPClient\IMAPClient\bin\Debug\netcoreapp3.1\IMAPClient.runtimeconfig.json +E:\Kurssit\ties323\IMAPClient\IMAPClient\bin\Debug\netcoreapp3.1\IMAPClient.runtimeconfig.dev.json +E:\Kurssit\ties323\IMAPClient\IMAPClient\bin\Debug\netcoreapp3.1\IMAPClient.dll +E:\Kurssit\ties323\IMAPClient\IMAPClient\bin\Debug\netcoreapp3.1\IMAPClient.pdb +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.csprojAssemblyReference.cache +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.AssemblyInfoInputs.cache +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.AssemblyInfo.cs +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.csproj.CoreCompileInputs.cache +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.dll +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.pdb +E:\Kurssit\ties323\IMAPClient\IMAPClient\obj\Debug\netcoreapp3.1\IMAPClient.genruntimeconfig.cache diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csprojAssemblyReference.cache b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csprojAssemblyReference.cache index 74fe67b1ca671095970d4a7fbcae2417231e8f41..a0fbfd12797557adefa2aaaacd9d5126dec64303 100644 Binary files a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csprojAssemblyReference.cache and b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.csprojAssemblyReference.cache differ diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.dll b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.dll new file mode 100644 index 0000000000000000000000000000000000000000..48d2a9dec8444c897c95eb6e3c88df78358d76b0 Binary files /dev/null and b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.dll differ diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.genruntimeconfig.cache b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.genruntimeconfig.cache new file mode 100644 index 0000000000000000000000000000000000000000..cfd54d3633fd9fc9d1dd576e393da6cf460bc519 --- /dev/null +++ b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.genruntimeconfig.cache @@ -0,0 +1 @@ +4f48870a7901b090f1a434130fea1c49378a219b diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.pdb b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.pdb new file mode 100644 index 0000000000000000000000000000000000000000..42b0c9128834c1b1c34f11c895c8bbd8e25b7fea Binary files /dev/null and b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/IMAPClient.pdb differ diff --git a/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/apphost.exe b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/apphost.exe new file mode 100644 index 0000000000000000000000000000000000000000..8127ce3866e0b85376a9ca8772cb4bdeef17572b Binary files /dev/null and b/IMAPClient/IMAPClient/obj/Debug/netcoreapp3.1/apphost.exe differ diff --git a/SMTPServer/.vs/SMTPServer/v16/.suo b/SMTPServer/.vs/SMTPServer/v16/.suo index 125393bfb92589c12e8609eaa7e586a5d24cfd38..900385410ffe1fbacf25502dcc64cb13d040c492 100644 Binary files a/SMTPServer/.vs/SMTPServer/v16/.suo and b/SMTPServer/.vs/SMTPServer/v16/.suo differ diff --git a/SMTPServer/STMPServer/Server.cs b/SMTPServer/STMPServer/Server.cs index e2b93790207e9e2ed9e1df58b609742a7d4c2698..0145802f2ff6c4a8c2c92473722f2e73ae8011b3 100644 --- a/SMTPServer/STMPServer/Server.cs +++ b/SMTPServer/STMPServer/Server.cs @@ -117,10 +117,17 @@ namespace SMTPServer } } + enum ImapState : UInt16 + { + Unaunthenticated, + Authenticated, + Selected, + Logout + } + public static void threadListenImap(object obj) { Socket scon = obj as Socket; - byte[] data = new byte[2048]; IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint Remote = (EndPoint)(sender); @@ -132,13 +139,72 @@ namespace SMTPServer string ip = ((IPEndPoint)(newSocket.RemoteEndPoint)).Address.ToString(); string asiakas_port = ((IPEndPoint)(newSocket.RemoteEndPoint)).Port.ToString(); - Console.WriteLine("Uusi asiakas: {0} portista: {1}", ip, asiakas_port); + Console.WriteLine("Uusi IMAP asiakas: {0} portista: {1}", ip, asiakas_port); + + ImapState state = ImapState.Unaunthenticated; + VastaaAsiakas("OK IMAP4rev1 Service Ready", newSocket); + bool keskustelu = true; + int counter = 1; + string asiakas_vastaus = ""; + string vastaus = ""; + + while(keskustelu) + { + byte[] buffer = new byte[2048]; + newSocket.Receive(buffer); + asiakas_vastaus = TrimVastaus(Encoding.UTF8.GetString(buffer), newSocket); + switch(asiakas_vastaus.Split(' ')[1]) + { + case "login": + bool valid = CheckImapLogin(asiakas_vastaus); + if (valid) + { + vastaus = "a" + counter.ToString("000"); + vastaus += " OK LOGIN completed"; + VastaaAsiakas(vastaus, newSocket); + counter++; + } + break; + // List is missing logic from different char combinations etc... + case "list": + HandleImapList(asiakas_vastaus, newSocket); + vastaus = "a" + counter.ToString("000"); + VastaaAsiakas(vastaus + " OK LIST completed", newSocket); + break; + case "logout": + vastaus = "BYE IMAP4rev1 server terminating connection"; + VastaaAsiakas(vastaus, newSocket); + vastaus = "a" + counter.ToString("000"); + keskustelu = false; + vastaus += " OK LOGOUT completed"; + VastaaAsiakas(vastaus, newSocket); + break; + } + + } } catch (SocketException) { } } + private static void HandleImapList(string str, Socket socket) + { + List<string> mail = Mailbox.getMail(); + string targetBox = str.Split(' ')[2]; + for (int i = 0; i < mail.Count; i++) + { + string vastaus = "* LIST (here more info on box) \"/\" " + targetBox + "/Sent"; + VastaaAsiakas(vastaus, socket); + } + } + + private static bool CheckImapLogin(string str) + { + string[] arr = str.Split(' '); + return arr[2] == "mrc" && arr[3] == "secret"; + } + public static void threadListenSmtp(object obj) { Socket scon = obj as Socket; diff --git a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.dll b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.dll index 3831285af342cc2001e52a23b31f7d3150b3b3e1..a6f5de56c8e94d2cd91a837d5d9bd1b40f75c9ef 100644 Binary files a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.dll and b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.dll differ diff --git a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.pdb b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.pdb index e7de267a0c30d9dc142262dfdb614983cb4c3c90..ef7de9497ec1e5797fb30c73599d5f693e308463 100644 Binary files a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.pdb and b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/SMTPServer.pdb differ diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.csprojAssemblyReference.cache b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.csprojAssemblyReference.cache index e66dd0bcf87a391bcf0e5def59dea2668c769a8b..75c16613d637ba1aee3feac158410536d13849e8 100644 Binary files a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.csprojAssemblyReference.cache and b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.csprojAssemblyReference.cache differ diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.dll b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.dll index 3831285af342cc2001e52a23b31f7d3150b3b3e1..a6f5de56c8e94d2cd91a837d5d9bd1b40f75c9ef 100644 Binary files a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.dll and b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.dll differ diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.pdb b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.pdb index e7de267a0c30d9dc142262dfdb614983cb4c3c90..ef7de9497ec1e5797fb30c73599d5f693e308463 100644 Binary files a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.pdb and b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/SMTPServer.pdb differ