public void TestNestedOrSearch() { Application application = SingletonProvider<TestSetup>.Instance.GetApp(); Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 1"), result); result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR SMALLER 1 LARGER 10000"); CustomAssert.IsTrue(result.StartsWith("* SEARCH\r\n"), result); result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SMALLER 1 LARGER 10000 SMALLER 10000"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 1\r\n"), result); }
public void TestDateSortOrder() { Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("Inbox")); string response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 22:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 13:00:00 +0000"); CustomAssert.IsTrue(response.Contains("* 1 EXISTS"), response); response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 21:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 14:00:00 +0000"); CustomAssert.IsTrue(response.Contains("* 2 EXISTS"), response); response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 20:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 12:00:00 +0000"); CustomAssert.IsTrue(response.Contains("* 3 EXISTS"), response); response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {37}", "Date: Wed, 15 Dec 2010 11:00:00 +0000"); CustomAssert.IsTrue(response.Contains("* 4 EXISTS"), response); string sortDateResponse = oSimulator.SendSingleCommand("A10 SORT (DATE) US-ASCII ALL"); CustomAssert.IsTrue(sortDateResponse.Contains(" 4 3 1 2")); oSimulator.Disconnect(); }
public void IfStlsRequiredLogonShouldSucceedIfStls() { var imapSimulator = new IMAPClientSimulator(false, 14303); imapSimulator.Connect(); imapSimulator.SendSingleCommand("A01 STARTTLS"); imapSimulator.Handshake(); // command is sent over TLS. imapSimulator.GetCapabilities(); CustomAssert.IsTrue(imapSimulator.Logon(_account.Address, "test")); }
public void TestSearchUID() { Application application = SingletonProvider<TestSetup>.Instance.GetApp(); Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); for (int i = 0; i < 3; i++) oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3); // There should be 3 UID's, 1,2,3 or similar. No skips in the middle fo them. var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.SendSingleCommand("* UID SEARCH UID 1:*"); // Potentially, the response is multiline. (UID RESPONSE and an OK line). We only want the first line... result = result.Substring(0, result.IndexOf("\r\n")); string[] tokens = Strings.Split(result, " ", -1, CompareMethod.Text); var uids = new List<int>(); foreach (string token in tokens) { int temp; if (Int32.TryParse(token, out temp)) { uids.Add(temp); } } CustomAssert.AreEqual(3, uids.Count, result); CustomAssert.AreEqual(1, uids[0]); CustomAssert.AreEqual(2, uids[1]); CustomAssert.AreEqual(3, uids[2]); }
public void TestSearchRange() { Application application = SingletonProvider<TestSetup>.Instance.GetApp(); Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); for (int i = 0; i < 5; i++) oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 5); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.SendSingleCommand("a01 search 2:4"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 2 3 4")); result = oSimulator.SendSingleCommand("a01 search 3,2"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 2 3")); result = oSimulator.SendSingleCommand("a01 search 3:*"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 3 4 5")); result = oSimulator.SendSingleCommand("a01 search 3,1,3"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 1 3")); result = oSimulator.SendSingleCommand("a01 search 1:*"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 1 2 3 4 5")); }
public void TestSearchInvalidCharset() { Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var oSimulator = new IMAPClientSimulator(); CustomAssert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.SendSingleCommand("A01 SEARCH CHARSET NONEXISTANT ALL SUBJECT MySubject"); CustomAssert.AreEqual("A01 NO [BADCHARSET]\r\n", result); }
public void StlsCommandShouldSwithToTls() { var imapSimulator = new IMAPClientSimulator(false, 14302); imapSimulator.Connect(); var data = imapSimulator.GetCapabilities(); imapSimulator.SendSingleCommand("A01 STARTTLS"); imapSimulator.Handshake(); // command is sent over TLS. imapSimulator.GetCapabilities(); imapSimulator.Logon(_account.Address, "test"); }
public void TestDateSortOrderNonexistantDate() { Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("Inbox")); string response = oSimulator.SendSingleCommandWithLiteral( "A04 APPEND INBOX \"22-Feb-2008 22:00:00 +0200\" {4}", "ABCD"); CustomAssert.IsTrue(response.Contains("* 1 EXISTS"), response); response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 21:00:00 +0200\" {4}", "ABCD"); CustomAssert.IsTrue(response.Contains("* 2 EXISTS"), response); response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 20:00:00 +0200\" {4}", "ABCD"); CustomAssert.IsTrue(response.Contains("* 3 EXISTS"), response); response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {4}", "ABCD"); CustomAssert.IsTrue(response.Contains("* 4 EXISTS"), response); /* * RFC 5256 "2.2. Sent Date" chapter. If the sent date cannot be determined (a Date: header is missing or cannot be parsed), * the INTERNALDATE for that message is used as the sent date. */ string sortDateResponse = oSimulator.SendSingleCommand("A10 SORT (DATE) US-ASCII ALL"); string sortArivalDateResponse = oSimulator.SendSingleCommand("A10 SORT (ARRIVAL) US-ASCII ALL"); CustomAssert.IsTrue(sortArivalDateResponse.Contains(" 3 2 1 4")); CustomAssert.AreEqual(sortDateResponse, sortArivalDateResponse); oSimulator.Disconnect(); }
public void TestSearchSpecficUID() { Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); for (int i = 0; i < 5; i++) oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 5); Messages messages = oAccount.IMAPFolders.get_ItemByName("Inbox").Messages; int second = messages[1].UID; int third = messages[2].UID; int fourth = messages[3].UID; var oSimulator = new IMAPClientSimulator(); oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.SendSingleCommand(string.Format("a01 SORT (REVERSE DATE) UTF-8 ALL UID {0},{1}", second, third)); AssertSortResultContains(result, 2, 3); result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0},{1}", third, second)); AssertSortResultContains(result, 2, 3); result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0}:{1}", second, fourth)); AssertSortResultContains(result, 2, 3, 4); result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0}:*", second)); AssertSortResultContains(result, 2, 3, 4, 5); }
public void TestAuthenticate() { Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); string result = oSimulator.SendSingleCommand("A01 AUTHENTICATE"); CustomAssert.IsTrue(result.Contains("NO Unsupported authentication mechanism.")); oSimulator.Disconnect(); }
public void TestUnseenResponseInSelect() { Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestMessage"); IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); var sim = new IMAPClientSimulator(); CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); CustomAssert.IsTrue(sim.SelectFolder("Inbox")); CustomAssert.IsTrue(sim.CreateFolder("Dummy")); CustomAssert.IsTrue(sim.Copy(1, "Dummy")); string result = sim.SendSingleCommand("a01 select Dummy"); CustomAssert.IsTrue(result.Contains("* 1 EXISTS\r\n* 1 RECENT"), result); string searchResponse = sim.SendSingleCommand("srch1 SEARCH ALL UNSEEN"); // We should have at least one message here. CustomAssert.IsTrue(searchResponse.Contains("* SEARCH 1\r\n"), searchResponse); // Now fetch the body. string bodyText = sim.Fetch("1 BODY[TEXT]"); // Now the message is no longer unseen. Confirm this. searchResponse = sim.SendSingleCommand("srch1 SEARCH ALL UNSEEN"); CustomAssert.IsTrue(searchResponse.Contains("* SEARCH\r\n"), searchResponse); // Close the messages to mark them as no longer recent. CustomAssert.IsTrue(sim.Close()); result = sim.SendSingleCommand("a01 select Dummy"); CustomAssert.IsTrue(result.Contains("* 1 EXISTS\r\n* 0 RECENT"), result); }
public void TestRecentRemovedOnMailboxClose() { Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestMessage"); IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); var sim = new IMAPClientSimulator(); CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); CustomAssert.IsTrue(sim.SelectFolder("Inbox")); CustomAssert.IsTrue(sim.CreateFolder("Dummy")); CustomAssert.IsTrue(sim.Copy(1, "Dummy")); string result = sim.SendSingleCommand("a01 select Dummy"); CustomAssert.IsTrue(result.Contains("* 1 EXISTS\r\n* 1 RECENT"), result); CustomAssert.IsTrue(sim.Logout()); sim = new IMAPClientSimulator(); CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); result = sim.SendSingleCommand("a01 select Dummy"); CustomAssert.IsFalse(result.Contains("* 1 EXISTS\r\n* 1 RECENT"), result); CustomAssert.IsTrue(sim.Logout()); }