예제 #1
0
        public void Start()
        {
            if (!_socket.Connected)
            {
                return;
            }

            _reader = new StreamReader(_socket.Stream);
            _writer = new StreamWriter(_socket.Stream)
            {
                AutoFlush = true
            };

            _writer.WriteLine("220 localhost Server Ready");
            var isMessageBody = false;

            while (_socket.Connected)
            {
                var token = SmtpToken.FromLine(_reader.ReadLine(), isMessageBody);

                SmtpLog.Debug(token.Data);

                var handler = ProtocolHandlers.HandlerFor(token);
                if (handler.Handle(token, this) == ContinueProcessing.Stop)
                {
                    break;
                }

                isMessageBody = token.IsData && token.IsMessageBody;
            }
        }
예제 #2
0
        private void handleException(Exception exc)
        {
            if (exc is AggregateException)
            {
                var inner = exc.InnerException;
                if (inner != null)
                {
                    handleException(exc);
                }
                return;
            }

            if (exc is ObjectDisposedException)
            {
                return;
            }

            SmtpLog.Error("Listener socket is closed", exc);
        }
예제 #3
0
        public void OnClientConnect(ISocket clientSocket)
        {
            if (_closed)
            {
                return;
            }

            SmtpLog.Info("Client connected");
            ListenForClients();

            var session = new SmtpSession(clientSocket)
            {
                OnMessage = (msg) => _messages.Add(msg)
            };

            session.Start();

            _sessions.Add(session);
        }
예제 #4
0
 public void WriteResponse(string data)
 {
     SmtpLog.Debug(data);
     _writer.WriteLine(data);
 }
예제 #5
0
 public void Start()
 {
     Listener.Start();
     SmtpLog.Info(string.Format("Server started at {0}", new IPEndPoint(Address, Port)));
     ListenForClients();
 }