Ejemplo n.º 1
0
        public SmtpSession CreateSession(ISmtpResponderFactory responderFactory)
        {
            var session = new SmtpSession(this, responderFactory);
            session.OnSessionDisconnected +=
                (sender, args) => ClientDisconnected(this, new SmtpConnectionEventArgs(this));
            Session = session;

            SessionCreated(this, new SmtpSessionEventArgs(Session));
            return session;
        }
        public SmtpSession CreateSession(ISmtpResponderFactory responderFactory)
        {
            var session = new SmtpSession(this, responderFactory);

            session.OnSessionDisconnected +=
                (sender, args) => ClientDisconnected(this, new SmtpConnectionEventArgs(this));
            Session = session;

            SessionCreated(this, new SmtpSessionEventArgs(Session));
            return(session);
        }
 public SmtpSessionEventArgs(SmtpSession session)
 {
     Session = session;
 }
Ejemplo n.º 4
0
        private async Task SetupSessionThenProcessCommands(SmtpConnection connection, SmtpSession session)
        {
            await SendGreetingAsync(connection, Greeting ?? Configuration.DefaultGreeting);

            var sessionInfoParseResponder = new SmtpSessionInfoResponder(session.ResponderFactory, session.SessionInfo);

            var rawLineDecoder = new RawLineDecoder(connection);
            rawLineDecoder.RequestDisconnection += (s, e) =>
            {
                if (!e.DisconnectionExpected)
                {
                    MailServerLogger.Instance.Warn(String.Format("Connection unexpectedly lost {0}", connection.RemoteEndPoint));
                }

                rawLineDecoder.Cancel();
                session.Disconnect();
            };
            rawLineDecoder.DetectedActivity += (s, e) => session.UpdateActivity();
            rawLineDecoder.ProcessLineCommand += async (s, e) =>
            {
                // ReSharper disable PossibleUnintendedReferenceComparison
                var response = sessionInfoParseResponder.ProcessLineCommand(e.Buffer);
                if (response == SmtpResponse.None) return;

                if (response == SmtpResponse.Disconnect)
                {
                    await SendResponseAsync(connection, response);

                    MailServerLogger.Instance.Debug(String.Format("Remote connection disconnected {0}", connection.RemoteEndPoint));
                    rawLineDecoder.Cancel();
                    session.Disconnect();
                    return;
                }
                // ReSharper restore PossibleUnintendedReferenceComparison

                await SendResponseAsync(connection, response);
            };

#pragma warning disable 4014
            rawLineDecoder.ProcessCommandsAsync();
#pragma warning restore 4014
        }
Ejemplo n.º 5
0
        private async Task SetupSessionThenProcessCommands(SmtpConnection connection, SmtpSession session)
        {
            await SendGreetingAsync(connection, Greeting ?? Configuration.DefaultGreeting);

            var sessionInfoParseResponder = new SmtpSessionInfoResponder(session.ResponderFactory, session.SessionInfo);

            var rawLineDecoder = new RawLineDecoder(connection);

            rawLineDecoder.RequestDisconnection += (s, e) =>
            {
                if (!e.DisconnectionExpected)
                {
                    MailServerLogger.Instance.Warn(String.Format("Connection unexpectedly lost {0}", connection.RemoteEndPoint));
                }

                rawLineDecoder.Cancel();
                session.Disconnect();
            };
            rawLineDecoder.DetectedActivity   += (s, e) => session.UpdateActivity();
            rawLineDecoder.ProcessLineCommand += async(s, e) =>
            {
                // ReSharper disable PossibleUnintendedReferenceComparison
                var response = sessionInfoParseResponder.ProcessLineCommand(e.Buffer);
                if (response == SmtpResponse.None)
                {
                    return;
                }

                if (response == SmtpResponse.Disconnect)
                {
                    await SendResponseAsync(connection, response);

                    MailServerLogger.Instance.Debug(String.Format("Remote connection disconnected {0}", connection.RemoteEndPoint));
                    rawLineDecoder.Cancel();
                    session.Disconnect();
                    return;
                }
                // ReSharper restore PossibleUnintendedReferenceComparison

                await SendResponseAsync(connection, response);
            };

#pragma warning disable 4014
            rawLineDecoder.ProcessCommandsAsync();
#pragma warning restore 4014
        }
Ejemplo n.º 6
0
        private async Task SetupSessionThenProcessCommands(SmtpConnection connection, SmtpSession session)
        {
            await SendGreetingAsync(connection, Greeting ?? Configuration.DefaultGreeting);

            var sessionInfoParseResponder = new SmtpSessionInfoResponder(session.ResponderFactory, session.SessionInfo);

            var rawLineDecoder = new RawLineDecoder(connection);

            rawLineDecoder.RequestDisconnection += (s, e) =>
            {
                if (!e.DisconnectionExpected)
                {
                    MailServerLogger.Instance.Warn(String.Format("Connection unexpectedly lost {0}", connection.RemoteEndPoint));
                }

                rawLineDecoder.Cancel();
                session.Disconnect();
            };
            rawLineDecoder.DetectedActivity   += (s, e) => session.UpdateActivity();
            rawLineDecoder.ProcessLineCommand += async(s, e) =>
            {
                var response = sessionInfoParseResponder.ProcessLineCommand(e.Buffer);
                if (response == null || !response.HasValue)
                {
                    return;
                }

                if (response.ResponseCode == SmtpResponses.DisconnectResponseCode)
                {
                    await SendResponseAsync(connection, response);

                    MailServerLogger.Instance.Debug(String.Format("Remote connection disconnected {0}", connection.RemoteEndPoint));
                    rawLineDecoder.Cancel();
                    await Task.Delay(100).ContinueWith(t => session.Disconnect());

                    return;
                }

                await SendResponseAsync(connection, response);
            };

#pragma warning disable 4014
            rawLineDecoder.ProcessCommandsAsync();
#pragma warning restore 4014
        }
Ejemplo n.º 7
0
        private async Task SetupSessionThenProcessCommands(SmtpConnection connection, SmtpSession session)
        {
            await SendGreetingAsync(connection, Greeting ?? Configuration.DefaultGreeting);

            var sessionInfoParseResponder = new SmtpSessionInfoResponder(session.ResponderFactory, session.SessionInfo);

            var rawLineDecoder = new RawLineDecoder(connection);
            rawLineDecoder.RequestDisconnection += (s, e) =>
            {
                if (!e.DisconnectionExpected)
                {
                    MailServerLogger.Instance.Warn($"Connection unexpectedly lost {connection.RemoteEndPoint}");
                }

                rawLineDecoder.Cancel();
                session.Disconnect();
            };
            rawLineDecoder.DetectedActivity += (s, e) => session.UpdateActivity();
            rawLineDecoder.ProcessLineCommand += async (s, e) =>
            {
                var response = sessionInfoParseResponder.ProcessLineCommand(e.Buffer);
                if (response == null || !response.HasValue) return;

                if (response.ResponseCode == SmtpResponses.DisconnectResponseCode)
                {
                    await SendResponseAsync(connection, response);

                    MailServerLogger.Instance.Debug($"Remote connection disconnected {connection.RemoteEndPoint}");
                    rawLineDecoder.Cancel();
                    await Task.Delay(100).ContinueWith(t => session.Disconnect());
                    return;
                }

                await SendResponseAsync(connection, response);
            };

#pragma warning disable 4014
            rawLineDecoder.ProcessCommandsAsync();
#pragma warning restore 4014
        }
Ejemplo n.º 8
0
 public SmtpSessionEventArgs(SmtpSession session)
 {
     Session = session;
 }