Пример #1
0
        /// <summary>
        /// Connect the client to the server.
        /// </summary>
        /// <param name="sender">The current server to client connection channel.</param>
        /// <param name="data">The data from the client.</param>
        /// <param name="command">The command sent.</param>
        private void Connect(Pop3SslProxyConnection sender, string data, string command)
        {
            try
            {
                // Add custom validation here.
                // Get the current data.
                string dataArray = data.Trim();

                // Is the command user.
                if (command.Equals("USER"))
                {
                    sender.ConnectionName = dataArray;
                }

                // Is the command pass then connected
                if (command.Equals("PASS"))
                {
                    sender.Connected = true;
                }

                // Send the command to the pop3 server.
                sender.SendSocketCommand(command + " " + dataArray);
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }

                base.Write("Pop3SslProxyServer", "Connect", e.Message,
                           382, WriteTo.EventLog, LogType.Error);

                // Reply to client internal server error command.
                ReplyToSender(sender, "500 Error");
            }
        }
Пример #2
0
        /// <summary>
        /// Processes all in-comming client command requests.
        /// </summary>
        /// <param name="sender">The current server to client connection channel.</param>
        /// <param name="dataReceived">The data received from the client.</param>
        private void client_OnDataReceived(Pop3SslProxyConnection sender, string dataReceived)
        {
            try
            {
                // Decrypt the data recived from the client.
                string receivedData = dataReceived.Trim();
                string command      = string.Empty;
                string data         = string.Empty;

                // Get the command from the client and
                // any data the client has sent.
                if (receivedData.Length < 4)
                {
                    command = receivedData.Substring(0, 3).Trim();
                }
                else if (receivedData.Length < 5)
                {
                    command = receivedData.Substring(0, 4).Trim();
                }
                else
                {
                    command = receivedData.Substring(0, 4).Trim();
                    data    = receivedData.Substring(4).Trim();
                }

                // Delay.
                System.Threading.Thread.Sleep(10);

                // Process the command.
                switch (command.ToUpper())
                {
                case "QUIT":
                    // Close the client connection.
                    Disconnect(sender);
                    break;

                case "USER":
                    // User name.
                    Connect(sender, data, command);
                    break;

                case "PASS":
                    // User password.
                    Connect(sender, data, command);
                    break;

                case "ENDC":
                    // End the client connection.
                    EndConnection(sender);
                    break;

                default:
                    // An unknown command sent.
                    //Unknown(sender);
                    sender.SendSocketCommand(receivedData);
                    break;
                }
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }

                base.Write("Pop3SslProxyServer", "OnDataReceived", e.Message,
                           292, WriteTo.EventLog, LogType.Error);

                // Reply to client internal server error command.
                ReplyToSender(sender, "500 Error");
            }
        }