Пример #1
0
        private MailMessage ReceiveMessage()
        {
            var message            = new MailMessage();
            var processingFinished = false;

            SendServerReady();

            while (!processingFinished)
            {
                string nextLine;

                try
                {
                    nextLine = _clientController.Read();
                }
                catch (Exception e)
                {
                    Logger.LogWarning("Stream was closed before QUIT command from server:\n" + e.Message);
                    break;
                }

                if (nextLine.Length > 0)
                {
                    var messageCode = RequestCommandsConverter.ToRequestCommandCode(nextLine);
                    switch (messageCode)
                    {
                    case RequestCommands.Hello:
                        processingFinished = HandleHello(message, nextLine);
                        break;

                    case RequestCommands.MailFrom:
                        processingFinished = HandleMailFrom(message, nextLine);
                        break;

                    case RequestCommands.RcptTo:
                        processingFinished = HandleMailTo(message, nextLine);
                        break;

                    case RequestCommands.Data:
                        processingFinished = HandleDataSection(message, nextLine);
                        break;

                    case RequestCommands.Quit:
                        processingFinished = HandleQuit(message, nextLine);
                        break;

                    case RequestCommands.StartTls:
                        processingFinished = SwitchToTls(message, nextLine);
                        break;

                    case RequestCommands.ParseError:
                        processingFinished = true;
                        break;
                    }
                }
            }

            return(message);
        }
Пример #2
0
 public SmtpServerClientProcessor(ITcpClientController clientController, ILogger logger)
 {
     _clientController          = clientController;
     EmailParser                = new EmailParser();
     RequestCommandsConverter   = new RequestCommandsConverter();
     ServerStatusCodesConverter = new ServerStatusCodesConverter();
     Logger = logger;
 }