Ejemplo n.º 1
0
        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"));
        }
Ejemplo n.º 2
0
      public void TestNestedOr()
      {
         Application application = SingletonProvider<TestSetup>.Instance.GetApp();


         Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

         // Send a message to this account.
         var smtpClientSimulator = new SmtpClientSimulator();
         smtpClientSimulator.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 OR OR OR OR OR OR SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 ALL");
         Assert.IsTrue(result.StartsWith("* SEARCH"), result);

         result =
            oSimulator.SendSingleCommand(
               "A4 SEARCH OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008 ALL");
         Assert.IsTrue(result.StartsWith("A4 NO"), result);
      }
Ejemplo n.º 3
0
      public void TestSearchOR()
      {


         SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

         // Send a message to this account.
         var smtpClientSimulator = new SmtpClientSimulator();
         smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");
         ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

         var oSimulator = new ImapClientSimulator();

         string sWelcomeMessage = oSimulator.Connect();
         oSimulator.Logon("*****@*****.**", "test");
         Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

         Assert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2001 ON 28-May-2001 ALL"));

         // Searching for mail sent a year from now or a specific date 2012 should not return any matches.
         var nextYear = DateTime.UtcNow.Year+1;
         Assert.IsNullOrEmpty(oSimulator.Search(string.Format("OR SINCE 28-May-{0} ON 28-May-2012 ALL", nextYear)));
         string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture).ToUpper();
         Assert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2017 ON " + formattedToday + " ALL"));

         string formatted2001 = new DateTime(2001, 01, 01).ToString("dd-MMM-yyyy").ToUpper();
         Assert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2008 ON " + formatted2001 + " ALL"));
      }
Ejemplo n.º 4
0
        public void TestDateSortOrder()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var simulator = new ImapClientSimulator();

            string sWelcomeMessage = simulator.Connect();

            simulator.LogonWithLiteral("*****@*****.**", "test");
            Assert.IsTrue(simulator.SelectFolder("Inbox"));

            string response =
                simulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 22:00:00 +0200\" {37}",
                                                       "Date: Wed, 15 Dec 2010 13:00:00 +0000");

            Assert.IsTrue(response.Contains("* 1 EXISTS"), response);

            response = simulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 21:00:00 +0200\" {37}",
                                                              "Date: Wed, 15 Dec 2010 14:00:00 +0000");
            Assert.IsTrue(response.Contains("* 2 EXISTS"), response);

            response = simulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 20:00:00 +0200\" {37}",
                                                              "Date: Wed, 15 Dec 2010 12:00:00 +0000");
            Assert.IsTrue(response.Contains("* 3 EXISTS"), response);

            response = simulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {37}",
                                                              "Date: Wed, 15 Dec 2010 11:00:00 +0000");
            Assert.IsTrue(response.Contains("* 4 EXISTS"), response);

            string sortDateResponse = simulator.SendSingleCommand("A10 SORT (DATE) US-ASCII ALL");

            Assert.IsTrue(sortDateResponse.Contains(" 4 3 1 2"));
            simulator.Disconnect();
        }
Ejemplo n.º 5
0
        public void TestSubjectSearchMultipleMatches()
        {
            Domain  domain  = _application.Domains[0];
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "TestA", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);
            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3);

            var simulator = new ImapClientSimulator();

            string sWelcomeMessage = simulator.Connect();

            simulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(simulator.SelectFolder("INBOX"));

            Assert.AreEqual("1 3", simulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\""));
            Assert.AreEqual("2", simulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"TestA\""));
            Assert.AreEqual("3 1", simulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\""));
            Assert.AreEqual("2", simulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"TestA\""));
            Assert.AreEqual("3 1", simulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT) \"Test1\""));
            Assert.AreEqual("2", simulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT) \"TestA\""));
        }
Ejemplo n.º 6
0
        public void TestTryCreateInvalidStructure()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var oSimulator = new ImapClientSimulator();

            oSimulator.Connect();
            oSimulator.LogonWithLiteral(oAccount.Address, "test");
            Assert.IsTrue(oSimulator.CreateFolder("1.2.3"));
            Assert.IsTrue(oSimulator.CreateFolder("1.2.3.4"));

            // Should fail because name taken.
            Assert.IsFalse(oSimulator.RenameFolder("1.2.3.4", "1.2.3"));
            Assert.IsFalse(oSimulator.RenameFolder("1.2.3.4", "1.2"));
            Assert.IsFalse(oSimulator.RenameFolder("1.2.3.4", "1"));

            // Should fail because invalid destination name.
            Assert.IsFalse(oSimulator.RenameFolder("1.2.3.4", ""));

            // Should fail because destination name taken.
            Assert.IsFalse(oSimulator.RenameFolder("1.2.3", "1.2.3.4"));
            Assert.IsFalse(oSimulator.RenameFolder("1.2", "1.2.3.4"));
            Assert.IsFalse(oSimulator.RenameFolder("1", "1.2.3.4"));

            Assert.IsFalse(oSimulator.RenameFolder("1.2.3", "1.2"));
            Assert.IsFalse(oSimulator.RenameFolder("1.2.3", "1"));

            Assert.IsTrue(oSimulator.RenameFolder("1.2.3", "A"));

            oSimulator.Disconnect();
        }
Ejemplo n.º 7
0
        public void TestSortReverseArrival()
        {
            Domain  domain  = _application.Domains[0];
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

            // The two messages needs to be sent a second apart, so we actually need to pause a bit here.

            Thread.Sleep(1000);
            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            var simulator = new ImapClientSimulator();

            string sWelcomeMessage = simulator.Connect();

            simulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(simulator.SelectFolder("INBOX"));

            Assert.AreEqual("1 2", simulator.Sort("(ARRIVAL) UTF-8 ALL"));
            Assert.AreEqual("2 1", simulator.Sort("(REVERSE ARRIVAL) UTF-8 ALL"));
        }
Ejemplo n.º 8
0
        public void TestDistributionListPointingAtItself()
        {
            // Add distribution list
            var recipients = new List <string>();

            recipients.Add("*****@*****.**");
            recipients.Add("*****@*****.**");
            recipients.Add("*****@*****.**");
            recipients.Add("*****@*****.**");

            SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients);

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1");

            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
        }
Ejemplo n.º 9
0
        private static ImapClientSimulator ConnectAndLogon()
        {
            ImapClientSimulator sim = new ImapClientSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            return(sim);
        }
Ejemplo n.º 10
0
        public void TestDistributionListAnnouncementFromDomainAlias()
        {
            var smtpClientSimulator = new SmtpClientSimulator();

            //
            // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES
            //


            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var recipients = new List <string>();

            recipients.Add("*****@*****.**");

            DistributionList list3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**",
                                                                                                 recipients);

            list3.Mode = eDistributionListMode.eLMAnnouncement;
            list3.RequireSenderAddress = "*****@*****.**";
            list3.Save();

            // THIS MESSAGE SHOULD FAIL
            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"));

            DomainAlias domainAlias = _domain.DomainAliases.Add();

            domainAlias.AliasName = "dummy-example.com";
            domainAlias.Save();

            // THIS MESSAGE SHOULD SUCCEED
            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
        }
Ejemplo n.º 11
0
        public void TestDistributionListModeMembers()
        {
            var recipients = new List <string>();

            recipients.Add("*****@*****.**");
            recipients.Add("*****@*****.**");
            recipients.Add("*****@*****.**");

            var list = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients);

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var announcer = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Switch list mode so that only a single announcer can send to list.
            list.Mode = eDistributionListMode.eLMMembership;
            list.RequireSenderAddress = announcer.Address;
            list.RequireSMTPAuth      = false;
            list.Save();

            var smtpClient = new SmtpClientSimulator();

            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClient.Send("*****@*****.**", list.Address, "Mail 1", "Mail 1"));
            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1"));
            smtpClient.Send(recipients[0], list.Address, "Mail 1", "Mail 1");

            foreach (var recipientAddress in recipients)
            {
                ImapClientSimulator.AssertMessageCount(recipientAddress, "test", "Inbox", 1);
            }
        }
Ejemplo n.º 12
0
        public void TestFetchBody()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string attachmentName = "本本本.zip";

            string filename = Path.Combine(Path.GetTempPath(), attachmentName);

            File.WriteAllText(filename, "tjena moss");

            var message = new Message();

            message.Charset = "utf-8";
            message.AddRecipient("test", account.Address);
            message.From        = "Test";
            message.FromAddress = account.Address;
            message.Body        = "hejsan";
            message.Attachments.Add(filename);
            message.Save();

            CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1);

            var oSimulator = new ImapClientSimulator();

            oSimulator.ConnectAndLogon(account.Address, "test");
            oSimulator.SelectFolder("INBOX");
            string bodyStructureResponse = oSimulator.Fetch("1 BODYSTRUCTURE");
            string bodyResponse          = oSimulator.Fetch("1 BODY");

            oSimulator.Disconnect();

            Assert.IsTrue(bodyStructureResponse.Contains("BOUNDARY"));
            Assert.IsFalse(bodyResponse.Contains("BOUNDARY"));
        }
Ejemplo n.º 13
0
        public void TestFetch()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1");
            ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2");
            ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2);

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3");
            ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3);


            var sim = new ImapClientSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            sim.SelectFolder("INBOX");
            string result = sim.Fetch("1 BODY[1]");

            Assert.IsTrue(result.Contains("SampleBody1"), result);
            result = sim.Fetch("2 BODY[1]");
            Assert.IsTrue(result.Contains("SampleBody2"), result);
            result = sim.Fetch("3 BODY[1]");
            Assert.IsTrue(result.Contains("SampleBody3"), result);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        public void TestMediumVolume()
        {
            // Fetch default domain
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var smtpClientSimulator = new SmtpClientSimulator();


            var oThreads = new ArrayList();

            for (int i = 0; i < 5; i++)
            {
                var oThread = new Thread(Send50Messages);
                oThreads.Add(oThread);
                oThread.Start();
            }

            // Join the threads
            for (int i = 0; i < 5; i++)
            {
                var oThread = (Thread)oThreads[i];
                oThread.Join();
            }

            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 250);
        }
Ejemplo n.º 16
0
        public void TestExpunge()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test");
            Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.SelectFolder("Inbox");
            Assert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted"));

            var secondSimulator = new ImapClientSimulator();

            secondSimulator.ConnectAndLogon(oAccount.Address, "test");
            string result = secondSimulator.ExamineFolder("INBOX");

            Assert.IsTrue(result.Contains("1 EXISTS"), result);
            Assert.IsFalse(secondSimulator.Expunge());

            simulator.SelectFolder("INBOX");
            Assert.IsTrue(simulator.Expunge());

            simulator.Close();
            secondSimulator.Close();
        }
Ejemplo n.º 17
0
        public void TestListSpecial()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var    oSimulator      = new ImapClientSimulator();
            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(oAccount.Address, "test");
            string response = oSimulator.List("");

            Assert.IsTrue(response.StartsWith("* LIST (\\Noselect) \".\" \"\""));
            oSimulator.Disconnect();

            _settings.IMAPHierarchyDelimiter = "/";

            oSimulator      = new ImapClientSimulator();
            sWelcomeMessage = oSimulator.Connect();
            oSimulator.Logon(oAccount.Address, "test");
            response = oSimulator.List("");
            Assert.IsTrue(response.StartsWith("* LIST (\\Noselect) \"/\" \"\""));
            oSimulator.Disconnect();

            _settings.IMAPHierarchyDelimiter = "\\";

            oSimulator      = new ImapClientSimulator();
            sWelcomeMessage = oSimulator.Connect();
            oSimulator.Logon(oAccount.Address, "test");
            response = oSimulator.List("", false);
            string expectedResponse = "* LIST (\\Noselect) \"\\\\\" \"\"";

            Assert.IsTrue(response.StartsWith(expectedResponse));
            oSimulator.Disconnect();
        }
Ejemplo n.º 18
0
        public void TestChangeRecentFlag()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test");
            Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            string result = simulator.ExamineFolder("Inbox");

            Assert.IsTrue(result.Contains("* 1 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();

            simulator = new ImapClientSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            Assert.IsTrue(simulator.SelectFolder("Inbox", out result));
            Assert.IsTrue(result.Contains("* 1 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();

            simulator = new ImapClientSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            result = simulator.ExamineFolder("Inbox");
            Assert.IsTrue(result.Contains("* 0 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();
        }
Ejemplo n.º 19
0
        public void TestCreateLongFolder()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var oSimulator = new ImapClientSimulator();

            oSimulator.Connect();
            oSimulator.LogonWithLiteral(oAccount.Address, "test");

            string folderName = "";

            for (int i = 0; i < 255; i++)
            {
                folderName = folderName + "A";
            }

            string result = oSimulator.Send("A01 CREATE " + folderName);

            Assert.IsTrue(result.Contains("A01 OK"));
            Assert.IsTrue(oSimulator.SelectFolder(folderName));

            folderName = "";
            for (int i = 0; i < 256; i++)
            {
                folderName = folderName + "A";
            }

            result = oSimulator.Send("A01 CREATE " + folderName);
            Assert.IsTrue(result.Contains("A01 NO"));
            Assert.IsFalse(oSimulator.SelectFolder(folderName));

            oSimulator.Disconnect();
        }
Ejemplo n.º 20
0
        public void TestChangeSeenFlag()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test");
            Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.ExamineFolder("Inbox");
            string flags      = simulator.GetFlags(1);
            string body       = simulator.Fetch("1 RFC822");
            string flagsAfter = simulator.GetFlags(1);

            simulator.Close();
            simulator.Disconnect();

            Assert.AreEqual(flags, flagsAfter);

            var secondSimulator = new ImapClientSimulator();

            secondSimulator.ConnectAndLogon(oAccount.Address, "test");
            secondSimulator.SelectFolder("Inbox");
            string secondFlags      = secondSimulator.GetFlags(1);
            string secondBody       = secondSimulator.Fetch("1 RFC822");
            string secondFlagsAfter = secondSimulator.GetFlags(1);

            secondSimulator.Close();
            secondSimulator.Disconnect();

            Assert.AreNotEqual(secondFlags, secondFlagsAfter);
        }
Ejemplo n.º 21
0
        public void TestSortReverseSize()
        {
            Domain  domain  = _application.Domains[0];
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var longBodyString = new StringBuilder();

            longBodyString.Append('A', 10000);

            // Send a message to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test1", longBodyString.ToString());
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test2", "Test body");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            var simulator = new ImapClientSimulator();

            string sWelcomeMessage = simulator.Connect();

            simulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(simulator.SelectFolder("INBOX"));

            Assert.AreEqual("2 1", simulator.Sort("(SIZE) UTF-8 ALL"));
            Assert.AreEqual("1 2", simulator.Sort("(REVERSE SIZE) UTF-8 ALL"));
        }
Ejemplo n.º 22
0
        public void TestFolderDeletion()
        {
            // Create a test account
            // Fetch the default domain
            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPFolder folder = account1.IMAPFolders.Add("TestFolder1");

            folder.Save();

            var simulator1 = new ImapClientSimulator();

            simulator1.ConnectAndLogon(account1.Address, "test");
            string result = simulator1.List();

            Assert.IsTrue(result.Contains(folder.Name));
            simulator1.Disconnect();

            // Delete the folder and confirm it's no longer listed.
            folder.Delete();

            simulator1.ConnectAndLogon(account1.Address, "test");
            result = simulator1.List();
            Assert.IsFalse(result.Contains(folder.Name));
            simulator1.Disconnect();
        }
Ejemplo n.º 23
0
        public void TestSortSubjectSearch()
        {
            Domain  domain  = _application.Domains[0];
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "aa", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "bb", "This is a test of IMAP Search");
            ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            var    simulator       = new ImapClientSimulator();
            string sWelcomeMessage = simulator.Connect();

            simulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(simulator.SelectFolder("INBOX"));

            Assert.AreEqual("1 2", simulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT bb"));
            Assert.AreEqual("1 2",
                            simulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT bb)"));
            Assert.AreEqual("1 2",
                            simulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT bb)"));

            Assert.AreEqual("1", simulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT cc"));
            Assert.AreEqual("1",
                            simulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT cc)"));
            Assert.AreEqual("1", simulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT cc)"));

            Assert.AreEqual("2", simulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT bb HEADER SUBJECT cc"));
            Assert.AreEqual("2",
                            simulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT bb) (HEADER SUBJECT cc)"));
            Assert.AreEqual("2", simulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT bb HEADER SUBJECT cc)"));
        }
Ejemplo n.º 24
0
        public void TestHierarchyDelimiterLsubResponse()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            Settings settings = _settings;

            settings.IMAPHierarchyDelimiter = "/";

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string folderName = "Test/Test";

            var    oSimulator      = new ImapClientSimulator();
            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(account.Address, "test");
            Assert.IsTrue(oSimulator.CreateFolder(folderName));
            Assert.IsTrue(oSimulator.Subscribe("Test"));
            Assert.IsTrue(oSimulator.Subscribe("Test/Test"));
            string lsubResponse = oSimulator.LSUB();

            Assert.IsTrue(lsubResponse.Contains("\"Test/Test\""));
            Assert.IsTrue(lsubResponse.Contains("\"Test\""));
            oSimulator.Disconnect();
        }
Ejemplo n.º 25
0
        public void ConfirmFileAddedToCorrectAccountFolder()
        {
            TestSetup testSetup = SingletonProvider <TestSetup> .Instance;
            Account   account   = testSetup.AddAccount(_domain, "*****@*****.**", "test");
            var       simulator = new ImapClientSimulator();

            // Confirm that the public folder is empty before we start our test.
            string publicDir = GetPublicDirectory();

            CustomAsserts.AssertFilesInDirectory(publicDir, 0);

            // Add a message to the inbox.
            simulator.Connect();
            simulator.LogonWithLiteral("*****@*****.**", "test");
            simulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {4}", "ABCD");

            // Confirm it exists in the IMAP folder.
            Assert.AreEqual(1, simulator.GetMessageCount("INBOX"));
            simulator.Disconnect();

            // The public directory should still be empty - the message was added to the user account.
            CustomAsserts.AssertFilesInDirectory(publicDir, 0);

            // There should be a single file in the users directory.
            CustomAsserts.AssertFilesInUserDirectory(account, 1);
        }
Ejemplo n.º 26
0
        public void ChangingFlagShouldAffectAllConnections()
        {
            var account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Test");

            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

            var sim1 = new ImapClientSimulator();

            Assert.IsTrue(sim1.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(sim1.SelectFolder("Inbox"));

            var sim2 = new ImapClientSimulator();

            Assert.IsTrue(sim2.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(sim2.SelectFolder("Inbox"));

            sim1.SetFlagOnMessage(1, true, "\\Deleted");

            var flags1 = sim1.GetFlags(1);
            var flags2 = sim2.GetFlags(1);

            Assert.IsTrue(flags2.Contains(@"* 1 FETCH (FLAGS (\Deleted))"), flags2);
            Assert.IsTrue(flags2.Contains(@"* 1 FETCH (FLAGS (\Deleted) UID 1)"), flags2);
        }
Ejemplo n.º 27
0
      public void TestSearchON()
      {
         Application application = SingletonProvider<TestSetup>.Instance.GetApp();


         Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

         // Send a message to this account.
         var smtpClientSimulator = new SmtpClientSimulator();
         smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");
         ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

         var oSimulator = new ImapClientSimulator();

         string sWelcomeMessage = oSimulator.Connect();
         oSimulator.Logon("*****@*****.**", "test");
         Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

         string formattedTomorrow =
            (DateTime.Now + new TimeSpan(1, 0, 0, 0)).ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture).ToUpper();
         string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture).ToUpper();

         if (oSimulator.Search("ON " + formattedTomorrow) != "")
         {
            throw new Exception("ERROR - Search or flag failed");
         }

         if (oSimulator.Search("ON " + formattedToday) != "1")
         {
            throw new Exception("ERROR - Search or flag failed");
         }
      }
Ejemplo n.º 28
0
        public void TestImportOfMessageIntoOtherFolder()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "Test\r\n";

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            account.IMAPFolders.Add("Woho");

            string domainPath  = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com");
            string accountPath = Path.Combine(domainPath, "test");

            Directory.CreateDirectory(accountPath);
            string fileName = Path.Combine(accountPath, "something.eml");

            File.WriteAllText(fileName, messageText);

            Assert.IsTrue(_application.Utilities.ImportMessageFromFileToIMAPFolder(fileName, account.ID, "Woho"));

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 0);
            var sim = new ImapClientSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            Assert.AreEqual(1, sim.GetMessageCount("Woho"));
            sim.Disconnect();
        }
Ejemplo n.º 29
0
      public void TestSearchORWithLiterals()
      {
         Application application = SingletonProvider<TestSetup>.Instance.GetApp();


         Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

         // Send a message to this account.
         var smtpClientSimulator = new SmtpClientSimulator();
         smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
         ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
         smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
         ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

         var oSimulator = new ImapClientSimulator();

         string sWelcomeMessage = oSimulator.Connect();
         oSimulator.Logon("*****@*****.**", "test");

         Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

         string result = oSimulator.Send("A01 SEARCH ALL OR (HEADER SUBJECT {5}");
         result = oSimulator.Send("Test1) (HEADER SUBJECT {5}");
         result = oSimulator.Send("Test2)");
         Assert.IsTrue(result.StartsWith("* SEARCH 1 2"));
      }
Ejemplo n.º 30
0
        public void TestBodyStructureWithNonLatinCharacter()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string attachmentName = "本本本.zip";

            string filename = Path.Combine(Path.GetTempPath(), attachmentName);

            File.WriteAllText(filename, "tjena moss");

            var message = new Message();

            message.Charset = "utf-8";
            message.AddRecipient("test", account.Address);
            message.From        = "Test";
            message.FromAddress = account.Address;
            message.Body        = "hejsan";
            message.Attachments.Add(filename);
            message.Save();

            CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1);

            var oSimulator = new ImapClientSimulator();

            oSimulator.ConnectAndLogon(account.Address, "test");
            oSimulator.SelectFolder("INBOX");
            string result = oSimulator.Fetch("1 BODYSTRUCTURE");

            oSimulator.Disconnect();

            // utf-8 representation of 本本本.zip:
            Assert.IsTrue(result.Contains("=?utf-8?B?5pys5pys5pys?=.zip"));
        }