Ejemplo n.º 1
0
        public void SanitizeHtmlWithPrefixShouldWork()
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            var content = File.ReadAllText("Data/outlook-html-email.txt").Replace("Relay for ", "RE: Relay for ");

            sanitizer.TrySanitizeHtml(ref content, new SubjectModel
            {
                Prefix      = "RE: ",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeTrue();
        }
Ejemplo n.º 2
0
        public void SanitizeHtmlShouldFailIfNotMatched()
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            var content = File.ReadAllText("Data/outlook-html-email.txt").Replace("*****@*****.**", "*****@*****.**");

            sanitizer.TrySanitizeHtml(ref content, new SubjectModel
            {
                Prefix      = "RE: ",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeFalse();
            content.Should().Contain("*****@*****.**", "because no replacement occured");
        }
Ejemplo n.º 3
0
        public void SanitizeHtmlShouldWorkWithSubjectPrefix()
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            // when first responding to email the new subject will have "RE: .."
            // while the old subject(copied into the body) doesn't have it -> should parse just fine
            var content = File.ReadAllText("Data/outlook-html-email.txt");

            sanitizer.TrySanitizeHtml(ref content, new SubjectModel
            {
                Prefix      = "RE: ",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeTrue();
        }
Ejemplo n.º 4
0
        public void SanitizeHtmlShouldWork(bool escapeNewlines)
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            var content = File.ReadAllText("Data/outlook-html-email.txt");

            if (escapeNewlines)
            {
                // sendgrid escapes newlines so both should work
                content = content.Replace("\r\n", "\\r\\n");
            }
            sanitizer.TrySanitizeHtml(ref content, new SubjectModel
            {
                Prefix      = "",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeTrue();
        }
Ejemplo n.º 5
0
        public void SanitizePlainTextShouldWork()
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            var content = @"This is my response

___________________________________________
From: [email protected] <*****@*****.**>
Sent: Tuesday, September 3, 2019 11:19:42 PM
To: [email protected] <*****@*****.**>
Subject: RE: Relay for [email protected]: Test
 
This is the original message from someone";

            sanitizer.TrySanitizePlainText(ref content, new SubjectModel
            {
                Prefix      = "RE: ",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeTrue();
        }
Ejemplo n.º 6
0
        public void SanitizePlainTextShouldFailIfNotMatched()
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            var content = @"This is my response

___________________________________________
From: [email protected] <*****@*****.**>
expects all 4 in order, by adding some random stuff inbetween it should fail to match
Sent: Tuesday, September 3, 2019 11:19:42 PM
To: [email protected] <*****@*****.**>
Subject: RE: Relay for [email protected]: Test
 
This is the original message from someone";

            sanitizer.TrySanitizePlainText(ref content, new SubjectModel
            {
                Prefix      = "RE: ",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeFalse();
        }
Ejemplo n.º 7
0
        public void SanitizeInitialMailShouldWorkWithoutReplacement()
        {
            var parser    = new SubjectParser();
            var sanitizer = new OutlookWebSanitizer(parser);

            var content = "Hello";

            sanitizer.TrySanitizeHtml(ref content, new SubjectModel
            {
                Prefix      = "",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeTrue();
            content.Should().Be("Hello");

            sanitizer.TrySanitizePlainText(ref content, new SubjectModel
            {
                Prefix      = "",
                RelayTarget = "*****@*****.**",
                Subject     = "Test"
            }, "*****@*****.**", "*****@*****.**").Should().BeTrue();
            content.Should().Be("Hello");
        }