Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 public void WriteResponse(string data)
 {
     SmtpLog.Debug(data);
     _writer.WriteLine(data);
 }
Exemplo n.º 5
0
 public void Start()
 {
     Listener.Start();
     SmtpLog.Info(string.Format("Server started at {0}", new IPEndPoint(Address, Port)));
     ListenForClients();
 }