Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task Process(IConnection connection, SmtpCommand command)
        {
            if (connection.CurrentMessage != null)
            {
                await connection.WriteResponse(new SmtpResponse(
                                                   StandardSmtpResponseCode.BadSequenceOfCommands,
                                                   "You already told me who the message was from")).ConfigureAwait(false);

                return;
            }

            if (command.ArgumentsText.Length == 0)
            {
                await connection.WriteResponse(
                    new SmtpResponse(
                        StandardSmtpResponseCode.SyntaxErrorInCommandArguments,
                        "Must specify from address or <>")).ConfigureAwait(false);

                return;
            }

            ArgumentsParser argumentsParser = new ArgumentsParser(command.ArgumentsText);

            System.Collections.Generic.IReadOnlyCollection <string> arguments = argumentsParser.Arguments;

            string from = arguments.First();

            if (from.StartsWith("<", StringComparison.OrdinalIgnoreCase))
            {
                from = from.Remove(0, 1);
            }

            if (from.EndsWith(">", StringComparison.OrdinalIgnoreCase))
            {
                from = from.Remove(from.Length - 1, 1);
            }

            await connection.Server.Behaviour.OnMessageStart(connection, from).ConfigureAwait(false);

            await connection.NewMessage().ConfigureAwait(false);

            connection.CurrentMessage.ReceivedDate = this.currentDateTimeProvider.GetCurrentDateTime();
            connection.CurrentMessage.From         = from;

            try
            {
                await this.ParameterProcessorMap.Process(connection, arguments.Skip(1).ToArray(), true).ConfigureAwait(false);

                await connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "New message started")).ConfigureAwait(false);
            }
            catch
            {
                await connection.AbortMessage().ConfigureAwait(false);

                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task AddMessage()
        {
            IEditableSession session = this.GetSession();
            Mock <IMessage>  message = new Mock <IMessage>();

            session.AddMessage(message.Object);

            System.Collections.Generic.IReadOnlyCollection <IMessage> messages = await session.GetMessages();

            Assert.Single(messages);
            Assert.Same(message.Object, messages.First());
        }