public static int dele_command(handleClient hc, string[] param) { messageManager.load(); var lst = messageManager.list(); int i = 1; if (param.Length != 2) { hc.Write("-ERR Invalid command.\r\n"); return(0); } var no = int.Parse(param[1]); if (!hc.auth.auth()) { hc.Write("-ERR Authentification required.\r\n"); return(0); } foreach (Message m in lst) { if (m.to == hc.auth.login || m.to == (hc.auth.login + Settings.atdomain)) { if (i == no) { messageManager.list().Remove(m); //messageManager.save(); hc.Write("+Ok message " + no + " deleted\r\n"); return(0); } i++; } } hc.Write("-ERR Message not found\r\n"); return(0); }
public static int capa_command(handleClient hc, string[] param) { var tosend = "+Ok\nUIDL\nLOGIN PLAIN\nUSER\n.\r\n"; hc.Write(tosend); return(0); }
public static int apop_command(handleClient hc, string[] param) { if (param.Length != 3) { hc.Write("-ERR Missing parameter.\r\n"); return(0); } var idx = Array.IndexOf(Settings.users, param[1] + Settings.atdomain); var idx2 = Array.IndexOf(Settings.users, param[1]); if (idx < 0 && idx2 < 0) { hc.Write("-ERR Unknow user.\r\n"); return(0); } if (idx >= 0) { idx2 = idx; } else { idx = idx2; } var full_secret = hc.secret + Settings.passwords[idx]; if (param[2] == Protocol.CalculateMD5Hash(full_secret)) { hc.Write("+Ok\r\n"); hc.auth.login = param[1]; hc.auth.password = Settings.passwords[idx]; } return(0); }
public void run() { while (true) { var client = this._masterSocket.AcceptTcpClient(); handleClient handle = new handleClient(client); if (handle.init()) { handle.start(); } } }
public static int user_command(handleClient hc, string[] param) { if (param.Length > 1) { hc.auth.login = param[1]; hc.Write("+Ok User accepted\r\n"); } else { hc.Write("-ERR Need USER\r\n"); } return(0); }
public static void execute(handleClient hc, string command) { char[] splitTab = new char[2]; splitTab[0] = ' '; splitTab[1] = ' '; var commandTab = command.Split(splitTab); if (Protocol.commands.Contains(commandTab[0].ToUpper())) { var index = Array.IndexOf(Protocol.commands, commandTab[0].ToUpper()); funcPtr[index](hc, commandTab); } else { hc.Write("-ERR Unknow command.\r\n"); // hc.Write("+Ok\r\n"); } }
public static int pass_command(handleClient hc, string[] param) { if (param.Length > 1) { hc.auth.password = param[1]; if (hc.auth.auth()) { hc.Write("+Ok Pass accepted\r\n"); } else { hc.Write("-ERR Authentification failed.\r\n"); } } else { hc.Write("-ERR Need USER\r\n"); } return(0); }
public static int retr_command(handleClient hc, string[] param) { messageManager.load(); var lst = messageManager.list(); int count = 0; int tosend = int.Parse(param[1]); int size = 0; if (!hc.auth.auth()) { hc.Write("-ERR Authentification required.\r\n"); return(0); } foreach (Message m in lst) { if (m.to == hc.auth.login || m.to == (hc.auth.login + Settings.atdomain)) { count++; size += m.getSize(); if (count == tosend) { hc.Write("+Ok " + m.getSize() + " octets\r\n"); int max_len = 1048576; int send_data_cnt = 0; while ((m.body.Length - max_len * send_data_cnt) >= max_len) { hc.Write(m.body.Substring(max_len * send_data_cnt, max_len)); send_data_cnt++; } if ((m.body.Length - max_len * send_data_cnt) > 0) { hc.Write(m.body.Substring(max_len * send_data_cnt, m.body.Length - max_len * send_data_cnt)); } hc.Write(".\r\n"); } } } return(0); }
public static int uidl_command(handleClient hc, string[] param) { //messageManager.save(); messageManager.load(); var lst = messageManager.list(); int i = 1; if (!hc.auth.auth()) { hc.Write("-ERR Authentification required.\r\n"); return(0); } hc.Write("+Ok Mailbox contents follows\r\n"); foreach (Message m in lst) { if (m.to == hc.auth.login || m.to == (hc.auth.login + Settings.atdomain)) { hc.Write(i++ + " " + Protocol.CalculateMD5Hash(m.body) + "\r\n"); } } hc.Write(".\r\n"); return(0); }
public static int stat_command(handleClient hc, string[] param) { messageManager.load(); var lst = messageManager.list(); int count = 0; int size = 0; if (!hc.auth.auth()) { hc.Write("-ERR Authentification required.\r\n"); return(0); } foreach (Message m in lst) { if (m.to == hc.auth.login || m.to == (hc.auth.login + Settings.atdomain)) { count++; size += m.getSize(); } } hc.Write("+Ok " + count + " " + size + "\r\n"); return(0); }
public static int quit_command(handleClient hc, string[] param) { hc.exit(); return(0); }
public static int top_command(handleClient hc, string[] param) { return(0); }