Exemplo n.º 1
0
        private void ImapClient_FetchMessageParts_Test(int size, string mailMessage, MailMessage message, int mimePartCount)
        {
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.SELE, GetSelectInboxResponse());
            dict.Add(TcpCommand.FETC, GetMailMessage(size, mailMessage));

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.FetchMessageParts(9370);

                Assert.NotNull(result);
                Assert.Equal(mimePartCount, result.ToArray().Length);
            }
        }
Exemplo n.º 2
0
        private void ImapClient_FetchMailFromHeader_Returns_Null_If_Error_Occurs_Test()
        {
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.SELE, GetSelectInboxResponse());
            dict.Add(TcpCommand.FETC, null);

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.FetchMailFromHeader(1050);

                Assert.Null(result);
            }
        }
Exemplo n.º 3
0
        private void ImapClient_FetchMail_Test(int size, string mailMessage, MailMessage message, int mimePartCount)
        {
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.SELE, GetSelectInboxResponse());
            dict.Add(TcpCommand.FETC, GetMailMessage(size, mailMessage));

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.FetchMail(9370);

                Assert.Equal(message.Headers, result.Headers);
                Assert.Equal(message.Subject, result.Subject);
                Assert.Equal(message.From, result.From);
                Assert.Equal(message.To, result.To);
            }
        }
Exemplo n.º 4
0
        private void ImapClient_GetMessageFlags_Test(string input, MailFlag flag, int totalIndexCount, int[] indexes, string expected)
        {
            IEnumerable<int> outMailboxes = null;
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.SELE, GetSelectInboxResponse());
            dict.Add(TcpCommand.FETC, input);

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.GetAllMessagesFlag(flag, out outMailboxes);

                Assert.Equal(expected, result);
                Assert.Equal(totalIndexCount, outMailboxes.Count());
                Assert.True(CompareMailIndexes(indexes, outMailboxes));
            }
        }
Exemplo n.º 5
0
        private void ImapClient_FetchMailFromHeader_Test(int size, string messageHeader, MailMessage message)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine("* 9370 FETCH (BODY[HEADER] {" + size.ToString() + "}");
            builder.Append(messageHeader);
            builder.AppendLine("");
            builder.AppendLine(" FLAGS (\\Seen))");
            builder.AppendLine("$ OK FETCH completed.");

            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.SELE, GetSelectInboxResponse());
            dict.Add(TcpCommand.FETC, builder.ToString());

            using(var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.FetchMailFromHeader(9370);

                Assert.Equal(message.Headers, result.Headers);
                Assert.Equal(message.Subject, result.Subject);
                Assert.Equal(message.From, result.From);
                Assert.Equal(message.To, result.To);
            }
        }
Exemplo n.º 6
0
        private void ImapClient_FetchMailboxes_Test(string input, int totalMailboxes, Mailbox[] array, string expected)
        {
            IEnumerable<Mailbox> outMailboxes = null;
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.LIST, input);
            dict.Add(TcpCommand.CLOS, "$ OK CLOSE completed.\r\n");
            dict.Add(TcpCommand.LOGT, "* BYE Microsoft Exchange Server 2016 IMAP4 server signing off.\r\n");

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.FetchMailboxes(out outMailboxes);
                ((IDisposable)client).Dispose();

                outMailboxes.ToList().Sort();

                Assert.Equal(expected, result);
                Assert.Equal(totalMailboxes, outMailboxes.Count());
                Assert.True(CompareMailboxes(array, outMailboxes));
            }
        }
Exemplo n.º 7
0
        private void ImapClient_DeleteMail_Test(string input, string expected)
        {
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.SELE, GetSelectInboxResponse());
            dict.Add(TcpCommand.DELE, input);

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.DeleteMail(1050);

                Assert.Equal(expected, result);
            }
        }
Exemplo n.º 8
0
        private void ImapClient_GetTotalMail_Test(string input, int totalMail, string expected)
        {
            int actMail = -1;
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.STAT, input);
            dict.Add(TcpCommand.CLOS, "\r\n");
            dict.Add(TcpCommand.LOGT, "* BYE Microsoft Exchange Server 2016 IMAP4 server signing off.\r\n");

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.GetTotalMail(out actMail);
                ((IDisposable)client).Dispose();

                Assert.Equal(expected, result);
                Assert.Equal(totalMail, actMail);
            }
        }
Exemplo n.º 9
0
        private void ImapClient_LogOut_Test()
        {
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.LOGT, "* BYE Microsoft Exchange Server 2016 IMAP4 server signing off.\r\n");
            dict.Add(TcpCommand.CLOS, null);

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.LogOut();

                Assert.True(string.IsNullOrEmpty(result));
            }
        }
Exemplo n.º 10
0
        private void ImapClient_Authentication_Test(string input, string expected)
        {
            var dict = new Dictionary<TcpCommand, string>();

            dict.Add(TcpCommand.LOGN, input);

            using (var stream = new ImapStream(dict))
            {
                var client = GetMailClient(stream);
                var result = client.LogIn(string.Empty, string.Empty);

                Assert.Equal(expected, result);
            }
        }