Skip to content
Snippets Groups Projects
Commit 3f34dbcd authored by joalhelk's avatar joalhelk
Browse files

imap

parent 40e4f7aa
No related branches found
No related tags found
1 merge request!2imap
Showing
with 186 additions and 2 deletions
No preview for this file type
......@@ -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
}
}
{
"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
File added
File added
File added
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Joppe\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Joppe\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
ecfb1d2d9a35dd77852bf69575ecb4fc404b2ea7
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
No preview for this file type
File added
4f48870a7901b090f1a434130fea1c49378a219b
File added
File added
No preview for this file type
......@@ -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;
......
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment