Beispiel #1
0
        public void TestSearchOR()
        {
            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("*****@*****.**", "test", "INBOX", 1);

            var oSimulator = new IMAPClientSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));

            CustomAssert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2001 ON 28-May-2001 ALL"));
            CustomAssert.IsNullOrEmpty(oSimulator.Search("OR SINCE 28-May-2020 ON 28-May-2012 ALL"));

            string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture).ToUpper();

            CustomAssert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2017 ON " + formattedToday + " ALL"));

            string formatted2001 = new DateTime(2001, 01, 01).ToString("dd-MMM-yyyy").ToUpper();

            CustomAssert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2008 ON " + formatted2001 + " ALL"));
        }
Beispiel #2
0
        public void TestPOP3TransactionSafety()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"));
            POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

            var sim = new POP3ClientSimulator();

            sim.ConnectAndLogon(account.Address, "test");

            // Now delete the message using an IMAP client.
            var imapSimulator = new IMAPClientSimulator();

            CustomAssert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test"));
            CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
            CustomAssert.IsTrue(imapSimulator.SetDeletedFlag(1));
            CustomAssert.IsTrue(imapSimulator.Expunge());
            CustomAssert.AreEqual(0, imapSimulator.GetMessageCount("Inbox"));

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"));
            IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

            // This deletion should not have any effect, since the POP3 connection is referencing an old message.
            sim.DELE(1);
            sim.QUIT();

            CustomAssert.AreEqual(1, imapSimulator.GetMessageCount("Inbox"));
        }
Beispiel #3
0
        public void TestMetaDataSortCC()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

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

            // disable...
            SendMessage("Test C", "Body", "", "ÄÄÄ");
            IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

            SendMessage("Test B", "Body", "", "ÖÖÖ");
            IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2);

            SendMessage("Test A", "Body", "", "ÅÅÅ");
            IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3);

            AssertAllMessagesIndexed();

            var sim = new IMAPClientSimulator(account.Address, "test", "Inbox");

            string result = sim.Sort("(CC) UTF-8 ALL");

            CustomAssert.AreEqual("3 1 2", result);

            // Disable the indexing functionality
            _indexing.Enabled = false;
            _indexing.Clear();

            // Make sure the sort order is the same.
            string resultAfter = sim.Sort("(CC) UTF-8 ALL");

            CustomAssert.AreEqual(result, resultAfter);
        }
Beispiel #4
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();

            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);
        }
Beispiel #5
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();

            TestSetup.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();

            CustomAssert.IsTrue(bodyStructureResponse.Contains("BOUNDARY"));
            CustomAssert.IsFalse(bodyResponse.Contains("BOUNDARY"));
        }
Beispiel #6
0
        public void TestTryCreateInvalidStructure()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var oSimulator = new IMAPClientSimulator();

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

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

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

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

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

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

            oSimulator.Disconnect();
        }
Beispiel #7
0
        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"));
        }
Beispiel #8
0
        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"));
        }
Beispiel #9
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();

            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"));
        }
Beispiel #10
0
        public void TestSearchWithLiterals()
        {
            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("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.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");

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

            string result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test1");

            CustomAssert.IsTrue(result.StartsWith("* SEARCH 1\r\n"));

            result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test2");
            CustomAssert.IsTrue(result.StartsWith("* SEARCH 2\r\n"));
        }
Beispiel #11
0
        public void TestIMAPServerNormal()
        {
            var sim = new IMAPClientSimulator();

            sim.ConnectAndLogon(GetUsername(), GetPassword());
            EnsureNoPassword();
        }
Beispiel #12
0
        public void TestSearchUTF8TEXT()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string body = TestSetup.GetResource("Messages.MessageContainingGreekSubject.txt");

            SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body);

            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.Search("CHARSET UTF-8 ALL TEXT GRΣΣK");

            CustomAssert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT 標準語");
            CustomAssert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK標準語");
            CustomAssert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣKWHAT標準語");
            CustomAssert.AreEqual("", result);
        }
Beispiel #13
0
        public void TestSearchORWithParenthesisSubjectNested()
        {
            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("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.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");
            CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));

            if (oSimulator.Search("ALL (OR (HEADER SUBJECT \"Test1\") (HEADER SUBJECT \"Test2\"))") != "1 2")
            {
                throw new Exception("ERROR - Search or flag failed");
            }
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        public void TestChangeSeenFlag()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CustomAssert.IsTrue(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();

            CustomAssert.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();

            CustomAssert.AreNotEqual(secondFlags, secondFlagsAfter);
        }
        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");
            CustomAssert.IsTrue(oSimulator.CreateFolder(folderName));
            CustomAssert.IsTrue(oSimulator.Subscribe("Test"));
            CustomAssert.IsTrue(oSimulator.Subscribe("Test/Test"));
            string lsubResponse = oSimulator.LSUB();

            CustomAssert.IsTrue(lsubResponse.Contains("\"Test/Test\""));
            CustomAssert.IsTrue(lsubResponse.Contains("\"Test\""));
            oSimulator.Disconnect();
        }
Beispiel #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("");

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

            _settings.IMAPHierarchyDelimiter = "/";

            oSimulator      = new IMAPClientSimulator();
            sWelcomeMessage = oSimulator.Connect();
            oSimulator.Logon(oAccount.Address, "test");
            response = oSimulator.List("");
            CustomAssert.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) \"\\\\\" \"\"";

            CustomAssert.IsTrue(response.StartsWith(expectedResponse));
            oSimulator.Disconnect();
        }
Beispiel #18
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();

            CustomAssert.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();
            CustomAssert.IsFalse(result.Contains(folder.Name));
            simulator1.Disconnect();
        }
Beispiel #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);

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

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

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

            oSimulator.Disconnect();
        }
Beispiel #20
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();

            CustomAssert.IsFalse(smtpClient.Send("*****@*****.**", list.Address, "Mail 1", "Mail 1"));
            CustomAssert.IsFalse(smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1"));
            CustomAssert.IsTrue(smtpClient.Send(recipients[0], list.Address, "Mail 1", "Mail 1"));

            foreach (var recipient in recipients)
            {
                IMAPClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1);
            }
        }
Beispiel #21
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();

            TestSetup.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:
            CustomAssert.IsTrue(result.Contains("=?utf-8?B?5pys5pys5pys?=.zip"));
        }
Beispiel #22
0
        public void ConfirmFileAddedToCorrectAccountFolder()
        {
            TestSetup testSetup  = SingletonProvider <TestSetup> .Instance;
            Account   oAccount   = testSetup.AddAccount(_domain, "*****@*****.**", "test");
            var       oSimulator = new IMAPClientSimulator();

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

            testSetup.AssertFilesInDirectory(publicDir, 0);

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

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

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

            // There should be a single file in the users directory.
            testSetup.AssertFilesInUserDirectory(oAccount, 1);
        }
Beispiel #23
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]");

            CustomAssert.IsTrue(result.Contains("SampleBody1"), result);
            result = sim.Fetch("2 BODY[1]");
            CustomAssert.IsTrue(result.Contains("SampleBody2"), result);
            result = sim.Fetch("3 BODY[1]");
            CustomAssert.IsTrue(result.Contains("SampleBody3"), result);
        }
Beispiel #24
0
        public void TestIMAPServer()
        {
            TestSetup.DeleteCurrentDefaultLog();

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

            for (int i = 0; i < 30; i++)
            {
                try
                {
                    var imapSim = new IMAPClientSimulator(true, 14301);
                    imapSim.ConnectAndLogon(account.Address, "test");
                    CustomAssert.IsTrue(imapSim.SelectFolder("Inbox"), "SelectInbox");
                    imapSim.CreateFolder("Test");
                    CustomAssert.IsTrue(imapSim.SelectFolder("Test"), "SelectTest");
                    CustomAssert.IsTrue(imapSim.Logout(), "Logout");

                    imapSim.Disconnect();
                    break;
                }
                catch (Exception)
                {
                    if (i == 29)
                    {
                        throw;
                    }
                }
            }
        }
Beispiel #25
0
        public void TestRetrievalOfMessageInDeletedFolderUsingIMAP()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text;

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

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody");

            IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");


            TestSetup.AssertFolderMessageCount(inbox, 1);

            Message message = inbox.Messages[0];

            var           dir    = new DirectoryInfo(Path.GetFullPath(message.Filename));
            DirectoryInfo parent = dir.Parent.Parent.Parent;

            parent.Delete(true);

            var sim = new IMAPClientSimulator();

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

            CustomAssert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));
            TestSetup.AssertReportedError("Message retrieval failed because message file");
        }
Beispiel #26
0
        public void TestExpunge()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new IMAPClientSimulator();

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

            var secondSimulator = new IMAPClientSimulator();

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

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

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

            simulator.Close();
            secondSimulator.Close();
        }
Beispiel #27
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);

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

            POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 0);
            var sim = new IMAPClientSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            CustomAssert.AreEqual(1, sim.GetMessageCount("Woho"));
            sim.Disconnect();
        }
Beispiel #28
0
        public void TestChangeRecentFlag()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CustomAssert.IsTrue(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");

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

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

            simulator = new IMAPClientSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            result = simulator.ExamineFolder("Inbox");
            CustomAssert.IsTrue(result.Contains("* 0 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();
        }
        public void TestDistributionListPointingAtItself()
        {
            // Add distribution list
            var oRecipients = new List <string>();

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

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

            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");

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"));

            IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
            IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
            IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
        }
Beispiel #30
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 oSMTP = new SMTPClientSimulator();

            oSMTP.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");
            CustomAssert.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");
            }
        }