public void TestSPFViaIncomingRelay() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 5; string message = @"Received: from openspf.org ([76.79.20.184]) by Someone ; Mon, 29 Dec 2008 13:42:55 +0100\r\n" + "Message-ID: <5F90152F-DAC5-43CF-B553-FCF9302F6E0C@WORK>\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "\r\n" + "This is a test message.\r\n"; // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); // Add a forwarding relay pointing at localhost, so that the message will appear to be // properly forwarded. hMailServer.IncomingRelays incomingRelays = _settings.IncomingRelays; Assert.AreEqual(0, incomingRelays.Count); hMailServer.IncomingRelay incomingRelay = incomingRelays.Add(); incomingRelay.Name = "Localhost"; incomingRelay.LowerIP = "127.0.0.1"; incomingRelay.UpperIP = "127.0.0.1"; incomingRelay.Save(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); // change so that the forwarding relay no longer covers the IP. incomingRelay.LowerIP = "1.1.1.1"; incomingRelay.UpperIP = "1.1.1.1"; incomingRelay.Save(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); }
public void TestFetchHeaderFieldsNot() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string message = "From: Someone <*****@*****.**>" + Environment.NewLine + "To: Someoen <*****@*****.**>" + Environment.NewLine + "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine + "Subject: Something" + Environment.NewLine + Environment.NewLine + "Hello" + Environment.NewLine; var smtpSimulator = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message)); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 BODY.PEEK[HEADER.FIELDS.NOT (Subject From)]"); oSimulator.Disconnect(); CustomAssert.IsTrue(result.Contains("Received:"), result); CustomAssert.IsFalse(result.Contains("Subject:"), result); CustomAssert.IsFalse(result.Contains("From:"), result); // The feedback should end with an empty header line. CustomAssert.IsTrue(result.Contains("\r\n\r\n)"), result); }
public void RequestingSameHeaderFieldMultipleTimesShouldReturnItOnce() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string message = "From: Someone <*****@*****.**>" + Environment.NewLine + "To: Someoen <*****@*****.**>" + Environment.NewLine + "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine + "Subject: SubjectText" + Environment.NewLine + Environment.NewLine + "Hello" + Environment.NewLine; var smtpSimulator = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message)); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 BODY.PEEK[HEADER.FIELDS (Subject Subject)]"); oSimulator.Disconnect(); CustomAssert.AreEqual(1, StringExtensions.Occurences(result, "SubjectText")); }
public void TestFetchEnvelopeWithDateContainingQuote() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string message = "From: Someone <*****@*****.**>" + Environment.NewLine + "To: Someoen <*****@*****.**>" + Environment.NewLine + "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine + "Subject: Something" + Environment.NewLine + Environment.NewLine + "Hello" + Environment.NewLine; var smtpSimulator = new SMTPClientSimulator(); smtpSimulator.SendRaw(account.Address, account.Address, message); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 ENVELOPE"); oSimulator.Disconnect(); CustomAssert.IsTrue(result.Contains("Wed, 22 Apr 2009 11:05:09 GMT")); }
public void IfInReplyToFieldContainsQuoteThenFetchHeadersShouldEncodeIt() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string message = "From: Someone <*****@*****.**>" + Environment.NewLine + "To: Someoen <*****@*****.**>" + Environment.NewLine + "In-Reply-To: ShouldBeEncodedDueToQuote\"" + Environment.NewLine + "Subject: Something" + Environment.NewLine + Environment.NewLine + "Hello" + Environment.NewLine; var smtpSimulator = new SMTPClientSimulator(); smtpSimulator.SendRaw(account.Address, account.Address, message); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 ENVELOPE"); oSimulator.Disconnect(); CustomAssert.IsFalse(result.Contains("ShouldBeEncodedDueToQuote")); }
public void TestLongLineInData() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 11000; i++) { sb.Append("1234567890"); } SMTPClientSimulator sim = new SMTPClientSimulator(); Assert.IsFalse(sim.SendRaw("*****@*****.**", "*****@*****.**", sb.ToString())); }
public void TestLongLineInData() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 11000; i++) { sb.Append("1234567890"); } SMTPClientSimulator sim = new SMTPClientSimulator(); Assert.IsFalse(sim.SendRaw("*****@*****.**", "*****@*****.**", sb.ToString())); }
public void TestLongLineInData() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var sb = new StringBuilder(); for (int i = 0; i < 11000; i++) { sb.Append("1234567890"); } var sim = new SMTPClientSimulator(); CustomAssert.IsFalse(sim.SendRaw("*****@*****.**", "*****@*****.**", sb.ToString())); }
public void TestOverlappingBoundaryNames() { string content = "Return-Path: <*****@*****.**>\r\n" + "From: \"test\" <*****@*****.**>\r\n" + "To: \"Test\" <*****@*****.**>\r\n" + "Subject: rtest\r\n" + "Date: Thu, 22 Jan 2009 13:20:32 +0100\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670\"\r\n" + "\r\n" + "This is a multi-part message in MIME format.\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" + "Content-Type: multipart/alternative;\r\n" + " boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670.ALT\"\r\n" + "\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" + "Content-Type: text/plain;\r\n" + " charset=\"iso-8859-1\"\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + "test\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" + "Content-Type: text/html;\r\n" + " charset=\"iso-8859-1\"\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + "<a>test</a>\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670.ALT--\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" + "Content-Type: application/octet-stream;\r\n" + " name=\"test.vbs\"\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "Content-Disposition: attachment;\r\n" + " filename=\"test.vbs\"\r\n" + "\r\n" + "s = \"abc\"\r\n" + "\r\n" + "msgbox mid(s,1,100000)\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670--\r\n" + "\r\n" + ""; // Add an account hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Rule oRule = oAccount.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "Subject"; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "rtest"; oRuleCriteria.Save(); // Add action hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRASetHeaderValue; oRuleAction.HeaderName = "SomeHeader"; oRuleAction.Value = "SomeValue"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Spam folder oSMTP.SendRaw("*****@*****.**", "*****@*****.**", content); string sContents = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0); Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0); }
public void TestOverlappingBoundaryNames() { string content = "Return-Path: <*****@*****.**>\r\n" + "From: \"test\" <*****@*****.**>\r\n" + "To: \"Test\" <*****@*****.**>\r\n" + "Subject: rtest\r\n" + "Date: Thu, 22 Jan 2009 13:20:32 +0100\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670\"\r\n" + "\r\n" + "This is a multi-part message in MIME format.\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" + "Content-Type: multipart/alternative;\r\n" + " boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670.ALT\"\r\n" + "\r\n"+ "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" + "Content-Type: text/plain;\r\n" + " charset=\"iso-8859-1\"\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + "test\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" + "Content-Type: text/html;\r\n" + " charset=\"iso-8859-1\"\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + "<a>test</a>\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670.ALT--\r\n" + "\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" + "Content-Type: application/octet-stream;\r\n" + " name=\"test.vbs\"\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "Content-Disposition: attachment;\r\n" + " filename=\"test.vbs\"\r\n" + "\r\n" + "s = \"abc\"\r\n" + "\r\n" + "msgbox mid(s,1,100000)\r\n" + "------=_NextPart_000_000D_01C97C94.33D5E670--\r\n" + "\r\n" + ""; // Add an account hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Rule oRule = oAccount.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "Subject"; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "rtest"; oRuleCriteria.Save(); // Add action hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRASetHeaderValue; oRuleAction.HeaderName = "SomeHeader"; oRuleAction.Value = "SomeValue"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Spam folder oSMTP.SendRaw("*****@*****.**", "*****@*****.**", content); string sContents = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0); Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0); }
public void CriteriaContainsHTMLBody() { // Add an account hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Rule oRule = account.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = true; oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTBody; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "MyHTMLBody"; oRuleCriteria.Save(); // Add action hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder; oRuleAction.IMAPFolder = "INBOX.Wildcard"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string message = "From: Someone <*****@*****.**>" + Environment.NewLine + "Content-Type: text/html; charset=\"Windows-1251\"" + Environment.NewLine + "Content-Transfer-Encoding: quoted-printable" + Environment.NewLine + Environment.NewLine + "<HTML><Center>MyHTMLBody</Center></HTML>" + Environment.NewLine; oSMTP.SendRaw("*****@*****.**", account.Address, message); // The message should be placed in the Wildcard folder, since the HTML body of the message contains MyHTMLBody. IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox.Wildcard", 1); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 0); }