public void SetUp()
        {
            theSession = MockRepository.GenerateStub<ISmtpSession>();
            theHandler = new HeloHandler();
            theToken = new SmtpToken();

            theSession.Stub(x => x.RemoteAddress).Return("1234");
        }
        public void SetUp()
        {
            theSession = MockRepository.GenerateStub <ISmtpSession>();
            theHandler = new HeloHandler();
            theToken   = new SmtpToken();

            theSession.Stub(x => x.RemoteAddress).Return("1234");
        }
        public void matches_when_is_message_body()
        {
            var token = new SmtpToken {
                IsMessageBody = true
            };

            theHandler.Matches(token).ShouldBeTrue();
        }
        public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
        {
            if(token.Command == Recipient)
            {
                var rawAddress = token.Data.ValueFromAttributeSyntax(); // <*****@*****.**>
                session.AddRecipient(rawAddress.Replace("<", "").Replace(">", ""));
            }

            session.WriteResponse("250 Ok");
            return ContinueProcessing.Continue;
        }
 public bool Matches(SmtpToken token)
 {
     if(!token.IsMessageBody)
     {
         // Not the cleanest way to do this but this little guy maintains some state between commands so we clear it out here
         _messageGatherer.Length = 0;
         return false;
     }
     
     return true;
 }
Exemple #6
0
        public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
        {
            if (token.Command == Recipient)
            {
                var rawAddress = token.Data.ValueFromAttributeSyntax(); // <*****@*****.**>
                session.AddRecipient(rawAddress.Replace("<", "").Replace(">", ""));
            }

            session.WriteResponse("250 Ok");
            return(ContinueProcessing.Continue);
        }
Exemple #7
0
        public bool Matches(SmtpToken token)
        {
            if (!token.IsMessageBody)
            {
                // Not the cleanest way to do this but this little guy maintains some state between commands so we clear it out here
                _messageGatherer.Length = 0;
                return(false);
            }

            return(true);
        }
Exemple #8
0
        public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
        {
            _messageGatherer.AppendLine(token.Data);

            if (token.Data != null && token.Data.Trim() == ".")
            {
                session.WriteResponse(string.Format("250 Ok: queued as {0}", Guid.NewGuid()));
                session.SaveMessage(CreateMessage(_messageGatherer, session));
                token.IsMessageBody = false;
            }

            return(ContinueProcessing.Continue);
        }
        public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
        {
            _messageGatherer.AppendLine(token.Data);

            if(token.Data != null && token.Data.Trim() == ".")
            {
                session.WriteResponse(string.Format("250 Ok: queued as {0}", Guid.NewGuid()));
                session.SaveMessage(CreateMessage(_messageGatherer, session));
                token.IsMessageBody = false;
            }

            return ContinueProcessing.Continue;
        }
        public void maintains_message_state()
        {
            theMessageBody
            .ToString()
            .Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
            .Each(line =>
            {
                if (line.Trim() == ".")
                {
                    return;
                }

                var token = SmtpToken.FromLine(line);
                theHandler.Handle(token, theSession);
            });

            theHandler.CurrentMessage.ShouldNotBeEmpty();

            theHandler.Matches(new SmtpToken {
                IsMessageBody = false
            });
            theHandler.CurrentMessage.ShouldBeEmpty();
        }
Exemple #11
0
 public bool Matches(SmtpToken token)
 {
     return((new[] { "MAIL FROM", Recipient }).Contains(token.Command));
 }
        public void does_not_match_when_is_not_message_body()
        {
            var token = new SmtpToken();

            theHandler.Matches(token).ShouldBeFalse();
        }
 public bool Matches(SmtpToken token)
 {
     return token.IsData && !token.IsMessageBody;
 }
 public void SetUp()
 {
     theSession = MockRepository.GenerateStub<ISmtpSession>();
     theHandler = new QuitHandler();
     theToken = new SmtpToken();
 }
Exemple #15
0
 public bool Matches(SmtpToken token)
 {
     return(token.Command == "QUIT");
 }
 public bool Matches(SmtpToken token)
 {
     return((new[] { "HELO", "EHLO" }).Contains(token.Command));
 }
 public bool Matches(SmtpToken token)
 {
     return token.Command == "QUIT";
 }
Exemple #18
0
 private void verifyToken(string input, Action <SmtpToken> action)
 {
     action(SmtpToken.FromLine(input));
 }
 public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
 {
     session.WriteResponse(string.Format("250 Hello {0}, I am glad to meet you", session.RemoteAddress));
     return(ContinueProcessing.Continue);
 }
 public void SetUp()
 {
     theSession = MockRepository.GenerateStub<ISmtpSession>();
     theHandler = new RegisterAddressesHandler();
     theToken = new SmtpToken();
 }
 public bool Matches(SmtpToken token)
 {
     return (new[] {"HELO", "EHLO"}).Contains(token.Command);
 }
 public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
 {
     session.WriteResponse(string.Format("250 Hello {0}, I am glad to meet you", session.RemoteAddress));
     return ContinueProcessing.Continue;
 }
Exemple #23
0
 public void SetUp()
 {
     theSession = MockRepository.GenerateStub <ISmtpSession>();
     theHandler = new RegisterAddressesHandler();
     theToken   = new SmtpToken();
 }
Exemple #24
0
 public void SetUp()
 {
     theSession = MockRepository.GenerateStub <ISmtpSession>();
     theHandler = new DataHandler();
     theToken   = new SmtpToken();
 }
 public static ISmtpProtocolHandler HandlerFor(SmtpToken token)
 {
     return Handlers.LastOrDefault(h => h.Matches(token));
 }
Exemple #26
0
 public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
 {
     session.WriteResponse("354 End data with .");
     token.IsMessageBody = true;
     return(ContinueProcessing.Continue);
 }
 public static ISmtpProtocolHandler HandlerFor(SmtpToken token)
 {
     return(Handlers.LastOrDefault(h => h.Matches(token)));
 }
 public void does_not_match_when_is_not_message_body()
 {
     var token = new SmtpToken();
     theHandler.Matches(token).ShouldBeFalse();
 }
Exemple #29
0
 public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
 {
     session.WriteResponse("221 Bye");
     return(ContinueProcessing.Stop);
 }
 public void matches_when_is_message_body()
 {
     var token = new SmtpToken { IsMessageBody = true};
     theHandler.Matches(token).ShouldBeTrue();
 }
 public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
 {
     session.WriteResponse("354 End data with .");
     token.IsMessageBody = true;
     return ContinueProcessing.Continue;
 }
 public ContinueProcessing Handle(SmtpToken token, ISmtpSession session)
 {
     session.WriteResponse("221 Bye");
     return ContinueProcessing.Stop;
 }
 public bool Matches(SmtpToken token)
 {
     return (new[] { "MAIL FROM", Recipient }).Contains(token.Command);
 }
Exemple #34
0
 public bool Matches(SmtpToken token)
 {
     return(token.IsData && !token.IsMessageBody);
 }