public void TestSetAndGetProperty(bool permanent) { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); const int value1 = 5; const string value2 = "foo"; const bool value3 = false; var value4 = new object(); transaction.SetProperty("foo", value1, permanent); var actualValue1 = transaction.GetProperty <int>("foo"); Assert.Equal(value1, actualValue1); transaction.SetProperty("foo", value2, permanent); var actualValue2 = transaction.GetProperty <string>("foo"); Assert.Equal(value2, actualValue2); transaction.SetProperty("foo", value3, permanent); var actualValue3 = transaction.GetProperty <bool>("foo"); Assert.Equal(value3, actualValue3); transaction.SetProperty("foo", value4, permanent); var actualValue4 = transaction.GetProperty <object>("foo"); Assert.Equal(value4, actualValue4); } }
public void TestGetNonExistantProperty() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.Equal(default(int), transaction.GetProperty <int>("nonExistant")); Assert.Equal(default(bool), transaction.GetProperty <bool>("nonExistant")); Assert.Equal(default(string), transaction.GetProperty <string>("nonExistant")); } }
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)); }
public void TestResetProperties() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); transaction.SetProperty("foo", "bar", false); transaction.SetProperty("foo2", "baz", true); Assert.True(transaction.HasProperty("foo")); Assert.Equal("bar", transaction.GetProperty <string>("foo")); Assert.True(transaction.HasProperty("foo2")); Assert.Equal("baz", transaction.GetProperty <string>("foo2")); transaction.Reset(); Assert.False(transaction.HasProperty("foo")); Assert.Equal(default(string), transaction.GetProperty <string>("foo")); Assert.True(transaction.HasProperty("foo2")); Assert.Equal("baz", transaction.GetProperty <string>("foo2")); } }
public override SMTPResponse DoExecute(SMTPTransaction transaction, string parameters) { if (string.IsNullOrEmpty(parameters)) { return(new SMTPResponse(SMTPStatusCode.SyntaxError)); } var parts = parameters.Split(' '); if (parts.Length > 2) { return(new SMTPResponse(SMTPStatusCode.SyntaxError)); } if (transaction.GetProperty <bool>("Authenticated")) { return(new SMTPResponse(SMTPStatusCode.BadSequence)); } IAuthMethod method; if (!_authMethods.TryGetValue(parts[0].ToUpperInvariant(), out method)) { return(new SMTPResponse(SMTPStatusCode.ParamNotImplemented)); } string initialResponse = null; if (parts.Length > 1) { if (parts[1].Equals("=")) { initialResponse = string.Empty; } else { try { initialResponse = Base64Decode(parts[1]); } catch (FormatException) { return(new SMTPResponse(SMTPStatusCode.SyntaxError)); } } } return(HandleResponse(transaction, initialResponse, method)); }
public void TestOvershadowingProperties() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); const string value1 = "bar"; const string value2 = "baz"; transaction.SetProperty("foo", value1, true); Assert.Equal(value1, transaction.GetProperty <string>("foo")); transaction.SetProperty("foo", value2, false); Assert.Equal(value2, transaction.GetProperty <string>("foo")); transaction.SetProperty("foo", null, false); Assert.Equal(value1, transaction.GetProperty <string>("foo")); transaction.SetProperty("foo", null, true); Assert.Equal(default(string), transaction.GetProperty <string>("foo")); } }
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)); }
public override SMTPResponse DoExecute(SMTPTransaction transaction, string parameters) { if (transaction.GetProperty <bool>("MailInProgress")) { return(new SMTPResponse(SMTPStatusCode.BadSequence)); } var match = FromRegex.Match(parameters); if (!match.Success) { return(new SMTPResponse(SMTPStatusCode.SyntaxError)); } var path = match.Groups[1].Value.Equals("<>") ? MailPath.Empty : MailPath.FromMatch(match); transaction.SetProperty("ReversePath", path); transaction.SetProperty("MailInProgress", true); return(new SMTPResponse(SMTPStatusCode.Okay)); }
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)); }