Exemplo n.º 1
0
        public void TestParseDovcotEnvelopeWithGroupAddresses()
        {
            const string text = "(\"Mon, 13 Jul 2015 21:15:32 -0400\" \"Test message\" ((\"Example From\" NIL \"from\" \"example.com\")) ((\"Example Sender\" NIL \"sender\" \"example.com\")) ((\"Example Reply-To\" NIL \"reply-to\" \"example.com\")) ((NIL NIL \"boys\" NIL)(NIL NIL \"aaron\" \"MISSING_DOMAIN\")(NIL NIL \"jeff\" \"MISSING_DOMAIN\")(NIL NIL \"zach\" \"MISSING_DOMAIN\")(NIL NIL NIL NIL)(NIL NIL \"girls\" NIL)(NIL NIL \"alice\" \"MISSING_DOMAIN\")(NIL NIL \"hailey\" \"MISSING_DOMAIN\")(NIL NIL \"jenny\" \"MISSING_DOMAIN\")(NIL NIL NIL NIL)) NIL NIL NIL \"<*****@*****.**>\")";

            using (var memory = new MemoryStream(Encoding.ASCII.GetBytes(text), false)) {
                using (var tokenizer = new ImapStream(memory, null, new NullProtocolLogger())) {
                    using (var engine = new ImapEngine(null)) {
                        Envelope envelope;

                        engine.SetStream(tokenizer);

                        try {
                            envelope = ImapUtils.ParseEnvelopeAsync(engine, false, CancellationToken.None).GetAwaiter().GetResult();
                        } catch (Exception ex) {
                            Assert.Fail("Parsing ENVELOPE failed: {0}", ex);
                            return;
                        }

                        Assert.AreEqual("\"Example Sender\" <*****@*****.**>", envelope.Sender.ToString());
                        Assert.AreEqual("\"Example From\" <*****@*****.**>", envelope.From.ToString());
                        Assert.AreEqual("\"Example Reply-To\" <*****@*****.**>", envelope.ReplyTo.ToString());
                        Assert.AreEqual("boys: aaron, jeff, zach;, girls: alice, hailey, jenny;", envelope.To.ToString());
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestParseExampleEnvelopeRfc3501()
        {
            const string text = "(\"Wed, 17 Jul 1996 02:23:25 -0700 (PDT)\" \"IMAP4rev1 WG mtg summary and minutes\" ((\"Terry Gray\" NIL \"gray\" \"cac.washington.edu\")) ((\"Terry Gray\" NIL \"gray\" \"cac.washington.edu\")) ((\"Terry Gray\" NIL \"gray\" \"cac.washington.edu\")) ((NIL NIL \"imap\" \"cac.washington.edu\")) ((NIL NIL \"minutes\" \"CNRI.Reston.VA.US\") (\"John Klensin\" NIL \"KLENSIN\" \"MIT.EDU\")) NIL NIL \"<*****@*****.**>\")\r\n";

            using (var memory = new MemoryStream(Encoding.ASCII.GetBytes(text), false)) {
                using (var tokenizer = new ImapStream(memory, null, new NullProtocolLogger())) {
                    using (var engine = new ImapEngine(null)) {
                        Envelope envelope;

                        engine.SetStream(tokenizer);

                        try {
                            envelope = ImapUtils.ParseEnvelopeAsync(engine, false, CancellationToken.None).GetAwaiter().GetResult();
                        } catch (Exception ex) {
                            Assert.Fail("Parsing ENVELOPE failed: {0}", ex);
                            return;
                        }

                        var token = engine.ReadToken(CancellationToken.None);
                        Assert.AreEqual(ImapTokenType.Eoln, token.Type, "Expected new-line, but got: {0}", token);

                        Assert.IsTrue(envelope.Date.HasValue, "Parsed ENVELOPE date is null.");
                        Assert.AreEqual("Wed, 17 Jul 1996 02:23:25 -0700", DateUtils.FormatDate(envelope.Date.Value), "Date does not match.");
                        Assert.AreEqual("IMAP4rev1 WG mtg summary and minutes", envelope.Subject, "Subject does not match.");

                        Assert.AreEqual(1, envelope.From.Count, "From counts do not match.");
                        Assert.AreEqual("\"Terry Gray\" <*****@*****.**>", envelope.From.ToString(), "From does not match.");

                        Assert.AreEqual(1, envelope.Sender.Count, "Sender counts do not match.");
                        Assert.AreEqual("\"Terry Gray\" <*****@*****.**>", envelope.Sender.ToString(), "Sender does not match.");

                        Assert.AreEqual(1, envelope.ReplyTo.Count, "Reply-To counts do not match.");
                        Assert.AreEqual("\"Terry Gray\" <*****@*****.**>", envelope.ReplyTo.ToString(), "Reply-To does not match.");

                        Assert.AreEqual(1, envelope.To.Count, "To counts do not match.");
                        Assert.AreEqual("*****@*****.**", envelope.To.ToString(), "To does not match.");

                        Assert.AreEqual(2, envelope.Cc.Count, "Cc counts do not match.");
                        Assert.AreEqual("[email protected], \"John Klensin\" <*****@*****.**>", envelope.Cc.ToString(), "Cc does not match.");

                        Assert.AreEqual(0, envelope.Bcc.Count, "Bcc counts do not match.");

                        Assert.IsNull(envelope.InReplyTo, "In-Reply-To is not null.");

                        Assert.AreEqual("*****@*****.**", envelope.MessageId, "Message-Id does not match.");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void TestParseMalformedMailboxAddressInEnvelope()
        {
            const string text = "(\"Mon, 10 Apr 2017 06:04:00 -0700\" \"Session 2: Building the meditation habit\" ((\"Headspace\" NIL \"members\" \"headspace.com\")) ((NIL NIL \"<members=headspace.com\" \"members.headspace.com>\")) ((\"Headspace\" NIL \"members\" \"headspace.com\")) ((NIL NIL \"user\" \"gmail.com\")) NIL NIL NIL \"<*****@*****.**>\")";

            using (var memory = new MemoryStream(Encoding.ASCII.GetBytes(text), false)) {
                using (var tokenizer = new ImapStream(memory, null, new NullProtocolLogger())) {
                    using (var engine = new ImapEngine(null)) {
                        Envelope envelope;

                        engine.SetStream(tokenizer);

                        try {
                            envelope = ImapUtils.ParseEnvelopeAsync(engine, false, CancellationToken.None).GetAwaiter().GetResult();
                        } catch (Exception ex) {
                            Assert.Fail("Parsing ENVELOPE failed: {0}", ex);
                            return;
                        }

                        Assert.IsTrue(envelope.Date.HasValue, "Parsed ENVELOPE date is null.");
                        Assert.AreEqual("Mon, 10 Apr 2017 06:04:00 -0700", DateUtils.FormatDate(envelope.Date.Value), "Date does not match.");
                        Assert.AreEqual("Session 2: Building the meditation habit", envelope.Subject, "Subject does not match.");

                        Assert.AreEqual(1, envelope.From.Count, "From counts do not match.");
                        Assert.AreEqual("\"Headspace\" <*****@*****.**>", envelope.From.ToString(), "From does not match.");

                        Assert.AreEqual(1, envelope.Sender.Count, "Sender counts do not match.");
                        Assert.AreEqual("[email protected]", envelope.Sender.ToString(), "Sender does not match.");

                        Assert.AreEqual(1, envelope.ReplyTo.Count, "Reply-To counts do not match.");
                        Assert.AreEqual("\"Headspace\" <*****@*****.**>", envelope.ReplyTo.ToString(), "Reply-To does not match.");

                        Assert.AreEqual(1, envelope.To.Count, "To counts do not match.");
                        Assert.AreEqual("*****@*****.**", envelope.To.ToString(), "To does not match.");

                        Assert.AreEqual(0, envelope.Cc.Count, "Cc counts do not match.");
                        Assert.AreEqual(0, envelope.Bcc.Count, "Bcc counts do not match.");

                        Assert.IsNull(envelope.InReplyTo, "In-Reply-To is not null.");

                        Assert.AreEqual("*****@*****.**", envelope.MessageId, "Message-Id does not match.");
                    }
                }
            }
        }