private void ProcessResponse(string response) { if (!_greetSent) { return; } switch (CaptureData) { case 1: TransactionCommands.ProcessData(this, response); return; case 2: case 3: case 4: AuthenticationCommands.ProcessData(this, response.Trim()); return; } response = response.Trim(); string command; var data = string.Empty; if (response.Contains(":")) { command = response.Substring(0, response.IndexOf(":", StringComparison.Ordinal)).ToUpper().TrimEnd(); } else if (response.Contains(" ")) { command = response.Substring(0, response.IndexOf(" ", StringComparison.Ordinal)).ToUpper().TrimEnd(); } else { command = response.ToUpper(); } if (command.Length != response.Length) { data = response.Substring(command.Length).TrimStart(); } switch (command) { case "EHLO": Transaction = null; _protocolVersion = 2; WriteText($"250-{Server.Options.ServerName} at your service"); if (Server.AuthLogin != null) { WriteText("250-AUTH LOGIN PLAIN"); } if (!Secure && Server.Certificate != null) { WriteText("250-STARTTLS"); } WriteText("250 8BITMIME"); break; case "HELO": Transaction = null; _protocolVersion = 1; WriteText($"250 {Server.Options.ServerName} at your service"); break; case "STARTTLS": if (Secure) { WriteCode(503, "5.5.1"); return; } if (Server.Certificate == null) { WriteCode(502, "5.5.1"); return; } WriteCode(220, "2.0.0", "Ready for TLS"); _stream = new SslStream(_innerStream, false); Secure = true; Encryption = ConnectionEncryption.StartTls; ((SslStream)_stream).AuthenticateAsServer(Server.Certificate, false, Server.Options.Protocols, true); _reader = new StreamReader(_stream); break; case "HELP": WriteCode(214, "2.0.0"); break; case "AUTH": if (_protocolVersion == 0) { WriteCode(503, "5.5.1", "EHLO/HELO first."); return; } AuthenticationCommands.ProcessCommand(this, data); break; case "NOOP": WriteCode(250, "2.0.0"); break; case "QUIT": WriteCode(221, "2.0.0"); Dispose(); break; case "RSET": case "MAIL FROM": case "RCPT TO": case "DATA": if (_protocolVersion == 0) { WriteCode(503, "5.5.1", "EHLO/HELO first."); return; } TransactionCommands.ProcessCommand(this, command, data); break; case "VRFY": if (_protocolVersion == 0) { WriteCode(503, "5.5.1", "EHLO/HELO first."); return; } WriteCode(252, "5.5.1"); break; default: if (_protocolVersion == 0) { WriteCode(503, "5.5.1", "EHLO/HELO first."); return; } WriteCode(502, "5.5.1"); break; } }
public TransactionCommand(SQLiteConnection conn, TransactionCommands command) { this.conn = conn; this.cmd = command; }