Example #1
0
        public void TestCopyMessage()
        {
            hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp();

            hMailServer.Utilities utilities = app.Utilities;

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

            // Create a new folder.
            hMailServer.IMAPFolder folder = account.IMAPFolders.get_ItemByName("INBOX");
            folder.Save();

            hMailServer.IMAPFolder someOtherFolder = account.IMAPFolders.Add("SomeOtherFolder");

            for (int i = 0; i < 3; i++)
            {
                hMailServer.Message message = folder.Messages.Add();
                message.set_Flag(hMailServer.eMessageFlag.eMFSeen, true);
                message.Save();

                message.Copy(someOtherFolder.ID);
            }

            SMTPClientSimulator.StaticSend("*****@*****.**", account.Address, "Test", "Test");

            // Copy back to inbox.
            for (int i = 0; i < 3; i++)
            {
                hMailServer.Message message = someOtherFolder.Messages[i];
                message.Copy(folder.ID);
            }

            POP3Simulator.AssertMessageCount(account.Address, "test", 7);

            IMAPSimulator sim = new IMAPSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            sim.SelectFolder("Inbox");
            string response = sim.Fetch("1:7 UID");

            string[] lines = Microsoft.VisualBasic.Strings.Split(response, Environment.NewLine, -1, Microsoft.VisualBasic.CompareMethod.Text);

            List <string> uids = new List <string>();

            foreach (string line in lines)
            {
                int paraPos    = line.IndexOf("(");
                int paraEndPos = line.IndexOf(")");

                if (paraPos < 0 || paraEndPos < 0)
                {
                    continue;
                }

                string paraContent = line.Substring(paraPos + 1, paraEndPos - paraPos - 1);

                if (!uids.Contains(paraContent))
                {
                    uids.Add(paraContent);
                }
            }

            Assert.AreEqual(7, uids.Count);

            // Make sure the UIDS are sorted properly by creating a copy, sort the copy
            // and then compare to original.
            List <string> copy = new List <string>();

            copy.InsertRange(0, uids);
            copy.Sort();

            Assert.AreEqual(copy, uids);
        }