Beispiel #1
0
        public void TestGetListProperty(bool permanent)
        {
            using (ShimsContext.Create())
            {
                var server      = new ShimSMTPServer();
                var settings    = new StubIReceiveSettings();
                var transaction = new SMTPTransaction(server, settings);

                var list = transaction.GetListProperty <string>("foo", permanent);

                Assert.NotNull(list);
                Assert.Empty(list);

                list.Add("fubar");

                list = transaction.GetListProperty <string>("foo", permanent);

                Assert.NotNull(list);
                Assert.Contains("fubar", list);

                transaction.SetProperty("foo", null, permanent);

                list = transaction.GetListProperty <string>("foo", permanent);

                Assert.NotNull(list);
                Assert.Empty(list);
            }
        }
Beispiel #2
0
        public static SMTPResponse DataHandler(SMTPTransaction transaction, string data)
        {
            transaction.Server.TriggerNewMessage(transaction, transaction.GetProperty <MailPath>("ReversePath"),
                                                 transaction.GetListProperty <MailPath>("ForwardPath").ToArray(), data);

            transaction.Reset();

            return(new SMTPResponse(SMTPStatusCode.Okay));
        }
Beispiel #3
0
        public override SMTPResponse DoExecute(SMTPTransaction transaction, string parameters)
        {
            if (!string.IsNullOrEmpty(parameters))
            {
                return(new SMTPResponse(SMTPStatusCode.SyntaxError));
            }

            var forwardPath = transaction.GetListProperty <MailPath>("ForwardPath");

            if (!transaction.GetProperty <bool>("MailInProgress") || forwardPath == null || !forwardPath.Any())
            {
                return(new SMTPResponse(SMTPStatusCode.BadSequence));
            }

            transaction.StartDataMode(DataLineHandler, data => DataHandler(transaction, data));

            return(new SMTPResponse(SMTPStatusCode.StartMailInput));
        }
Beispiel #4
0
        public override SMTPResponse DoExecute(SMTPTransaction transaction, string parameters)
        {
            if (!transaction.GetProperty <bool>("MailInProgress"))
            {
                return(new SMTPResponse(SMTPStatusCode.BadSequence));
            }

            var match = ToRegex.Match(parameters);

            if (!match.Success)
            {
                return(new SMTPResponse(SMTPStatusCode.SyntaxError));
            }

            var path = match.Groups[1].Value.Equals("<postmaster>", StringComparison.InvariantCultureIgnoreCase)
                ? MailPath.Postmaster
                : MailPath.FromMatch(match);

            transaction.GetListProperty <MailPath>("ForwardPath").Add(path);

            return(new SMTPResponse(SMTPStatusCode.Okay));
        }