public async Task Unsecured_Certificate_ExtendedHelloResponds()
        {
            var channel = new MockSmtpChannel();
            var conn    = new MockConnectionSecurity();

            conn.Certificate = TestHelpers.GetSelfSigned();

            var command = new ExtendedHelloCommand(
                TestHelpers.GetAuths(),
                conn,
                channel,
                TestHelpers.MakeSettings("test.vaettir.net"),
                new MockLogger());

            command.Initialize("Sender.net");

            await command.ExecuteAsync(CancellationToken.None);

            Assert.True(channel.Entries.All(c => c.Code == SmtpReplyCode.Okay));
            Assert.True(channel.Entries.Take(channel.Entries.Count - 1).All(e => e.More));
            Assert.False(channel.Entries.Last().More);

            Assert.Contains(channel.Entries, e => e.Message == "STARTTLS");
            List <MockSmtpChannel.Entry> authReplies = channel.Entries.Where(e => e.Message.StartsWith("AUTH")).ToList();

            Assert.Single(authReplies);
            List <string> authParts = authReplies[0].Message.Split(' ').Skip(1).ToList();

            SequenceAssert.SameSet(new[] { "PLN" }, authParts);

            MockSmtpChannel.Entry signoff = channel.Entries.First();
            Assert.Contains("test.vaettir.net", signoff.Message);
            Assert.Contains("Sender.net", signoff.Message);
        }
        public async Task AuthenticatedLargeMessageAccepted()
        {
            var expectedBody = "From:[email protected]\r\n\r\nFirst Line\r\nSecond Line\r\n";

            (MockMailQueue queue, MockMailBuilder builder, MockSmtpChannel channel, DataCommand command) = Prepare(
                expectedBody + ".\r\n",
                TestHelpers.MakeSettings(unauthenticatedMessageSizeLimit: 1));

            channel.AuthenticatedUser = new UserData("*****@*****.**");

            builder.PendingMail = new SmtpMailMessage(new SmtpPath("*****@*****.**"))
            {
                Recipents = { "*****@*****.**" }
            };
            await command.ExecuteAsync(CancellationToken.None);

            Assert.Equal(2, channel.Entries.Count);
            SmtpTestHelper.AssertResponse(channel.Entries[0], SmtpReplyCode.StartMail);
            SmtpTestHelper.AssertResponse(channel.Entries[1], SmtpReplyCode.Okay);
            Assert.Equal(1, queue.References.Count);
            MockMailReference mailReference = queue.References[0];

            Assert.True(mailReference.IsSaved);
            Assert.Equal("*****@*****.**", mailReference.Sender);
            SequenceAssert.SameSet(new[] { "*****@*****.**" }, mailReference.Recipients);
            Assert.Throws <ObjectDisposedException>(() => mailReference.BodyStream.WriteByte(1));
            string mailBody = Encoding.UTF8.GetString(mailReference.BackupBodyStream.ToArray());

            Assert.EndsWith(expectedBody, mailBody);
            Assert.StartsWith("Received:", mailBody);
            Assert.Null(builder.PendingMail);
        }
Exemple #3
0
 public void ParseMailboxListHeader_MultiSingleQuoted()
 {
     SequenceAssert.SameSet(
         new[] { "*****@*****.**", "*****@*****.**" },
         _dispatcher.ParseMailboxListHeader(
             "\"Box, The\" <*****@*****.**>, \"Guy, Other\" <*****@*****.**>".ToEnumerable()));
 }
Exemple #4
0
        public async Task InternalSenderCanSendAnywhere()
        {
            var body = "My body\nNext Line";

            _queue.References.Add(
                new MockMailReference(
                    "ext-mail",
                    "*****@*****.**",
                    new[] { "*****@*****.**" }.ToImmutableList(),
                    true,
                    body,
                    _queue));

            await _dispatcher.ProcessAllMailReferencesAsync(CancellationToken.None);

            Assert.Empty(_queue.References);
            Assert.Equal(1, _queue.DeletedReferences.Count);
            Assert.Equal(1, _transfer.References.Count(r => r.IsSaved));
            string newBody;

            using (MockMailReference reference = _transfer.References.FirstOrDefault(r => r.IsSaved))
            {
                Assert.NotNull(reference);
                Assert.Equal("*****@*****.**", reference.Sender);
                SequenceAssert.SameSet(new[] { "*****@*****.**" }, reference.Recipients);
                newBody = await StreamUtility.ReadAllFromStreamAsync(reference.BackupBodyStream);
            }

            Assert.Equal(body, newBody);
            Assert.Empty(_mailbox.References);
        }
Exemple #5
0
 public void ResolveDomains_ExpandsKeepsOthers()
 {
     SequenceAssert.SameSet(
         new[] { "*****@*****.**", "*****@*****.**", "*****@*****.**" },
         _dispatcher.ExpandDistributionLists(
             "*****@*****.**",
             new[] { "*****@*****.**", "*****@*****.**" },
             new HashSet <string>()));
 }
Exemple #6
0
 public void ResolveDomains_RespectExclusion()
 {
     SequenceAssert.SameSet(
         new[] { "*****@*****.**" },
         _dispatcher.ExpandDistributionLists(
             "*****@*****.**",
             new[] { "*****@*****.**" },
             new HashSet <string> {
         "*****@*****.**"
     }));
 }
Exemple #7
0
 public void ParseMailboxListHeader_MultiMulti()
 {
     SequenceAssert.SameSet(
         new[] { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" },
         _dispatcher.ParseMailboxListHeader(
             new[]
     {
         "\"Box, The\" <*****@*****.**>, \"Guy, Other\" <*****@*****.**>",
         "[email protected], [email protected]"
     }));
 }
Exemple #8
0
        public async Task AcceptMultiple()
        {
            var channel = new MockSmtpChannel();
            var mail    = new SmtpMailMessage(new SmtpPath("*****@*****.**"));

            mail.Recipents.Add("*****@*****.**");
            var builder = new MockMailBuilder {
                PendingMail = mail
            };
            var command = new RecipientCommand(
                builder,
                channel,
                TestHelpers.MakeSettings(
                    "test.vaettir.net",
                    new[] { new SmtpAcceptDomain("test.vaettir.net") })
                );

            command.Initialize("TO:<*****@*****.**>");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.Okay);
            Assert.Same(mail, builder.PendingMail);
            SequenceAssert.SameSet(new[] { "*****@*****.**", "*****@*****.**" }, mail.Recipents);
        }
Exemple #9
0
 public void ResolveDomains_NoResolve()
 {
     SequenceAssert.SameSet(
         new[] { "*****@*****.**" },
         _dispatcher.ExpandDistributionLists("*****@*****.**", new[] { "*****@*****.**" }, new HashSet <string>()));
 }
Exemple #10
0
 public void ParseMailboxListHeader_HeaderParsing_Single()
 {
     SequenceAssert.SameSet(
         new[] { "*****@*****.**" },
         _dispatcher.ParseMailboxListHeader("*****@*****.**".ToEnumerable()));
 }