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(); 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(); Assert.AreEqual(1, StringExtensions.Occurences(result, "SubjectText")); }
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(); Assert.IsFalse(result.Contains("ShouldBeEncodedDueToQuote")); }
public static void StaticSendRaw(string sFrom, string recipient, string sBody) { var oSimulator = new SmtpClientSimulator(); oSimulator.SendRaw(sFrom, recipient, sBody); }
public static void StaticSendRaw(string sFrom, string recipient, string sBody) { var oSimulator = new SmtpClientSimulator(); oSimulator.SendRaw(sFrom, recipient, sBody); }
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(); 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(); Assert.IsTrue(result.Contains("Received:"), result); Assert.IsFalse(result.Contains("Subject:"), result); Assert.IsFalse(result.Contains("From:"), result); // The feedback should end with an empty header line. Assert.IsTrue(result.Contains("\r\n\r\n)"), result); }
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(); Assert.IsTrue(result.Contains("Wed, 22 Apr 2009 11:05:09 GMT")); }
public static void StaticSendRaw(string sFrom, string list, string sBody) { var simulator = new SmtpClientSimulator(); simulator.SendRaw(sFrom, list, sBody); }
public void CriteriaContainsHTMLBody() { // Add an account Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); Rule oRule = account.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = true; oRuleCriteria.PredefinedField = eRulePredefinedField.eFTBody; oRuleCriteria.MatchType = eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "MyHTMLBody"; oRuleCriteria.Save(); // Add action RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = eRuleActionType.eRAMoveToImapFolder; oRuleAction.IMAPFolder = "INBOX.Wildcard"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); var smtpClientSimulator = 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; smtpClientSimulator.SendRaw("*****@*****.**", account.Address, message); // The message should be placed in the Wildcard folder, since the HTML body of the message contains MyHTMLBody. ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox.Wildcard", 1); ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 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 Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); Rule oRule = oAccount.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "Subject"; oRuleCriteria.MatchType = eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "rtest"; oRuleCriteria.Save(); // Add action RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = eRuleActionType.eRASetHeaderValue; oRuleAction.HeaderName = "SomeHeader"; oRuleAction.Value = "SomeValue"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder smtpClientSimulator.SendRaw("*****@*****.**", "*****@*****.**", content); string sContents = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0); Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0); }
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(); CustomAsserts.Throws<DeliveryFailedException>(() => sim.SendRaw("*****@*****.**", "*****@*****.**", sb.ToString())); }