public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            var body = report.GetEmailMessage().Body;
            document.LoadHtml(body);

            // Get all image tags in there
            var imageTags = document.DocumentNode.Find(HtmlElementType.Img);

            var valid = true;

            // For each image tag
            foreach(var imageTag in imageTags)
            {
                var widthAttr = imageTag.Attributes["width"];
                if (widthAttr == null || string.IsNullOrEmpty(widthAttr.Value))
                    continue;

                float width;
                if(float.TryParse(widthAttr.Value, out width) && width > 610) {
                    valid = false;
                }
            }

            return new EmailValidationResult
                       {
                           Valid = valid,
                           ReportRule = rule
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var maxWordCount = 200;
            var maxCharCount = 1000;
            var paragraphRegex = new Regex("<p.*>.*</p>");
            var blockRegex = new Regex("<table.*id=.*BLOCK.*>.*</table>");
            var htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);
            var body = report.GetEmailMessage().Body;
            var paragraphMatches = paragraphRegex.Matches(body);
            var blockMatches = blockRegex.Matches(body);

            var validate = new Func<Match, bool>(match =>
                {
                    var value = match.Value.StripHtml();
                    var words = value.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);
                    return words.Length < maxWordCount && value.Length < maxCharCount;
                });

            var valid = paragraphMatches.Cast<Match>().All(validate) &&
                        blockMatches.Cast<Match>().All(validate);

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = valid
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var htmlDocument = new HtmlDocument();
            htmlDocument.LoadHtml(report.GetEmailMessage().Body);

            var body = htmlDocument.DocumentNode.Find(HtmlElementType.Body).FirstOrDefault();
            var blocks = htmlDocument.DocumentNode.Find("#block");
            var tables = htmlDocument.DocumentNode.Find(HtmlElementType.Table);
            var styleRegex = new Regex(@"background[\s]*:.*(!#fff|!#ffffff|white|transparent)");
            var isVisibleColor = new Func<string, bool>(x =>
                                                            {
                                                                var value = x.ToLower();
                                                                var hiddenValues = new string[] { "#fff", "#ffffff", "white", "transparent" };
                                                                return !string.IsNullOrEmpty(value) && !hiddenValues.Any(y => value.Contains(y));
                                                            });

            var valid = body == null ||
                        (body.Attributes.Any(x => x.Name.ToLower() == "bgcolor" && isVisibleColor(x.Value)) ||
                        body.Attributes.Any(x => x.Name.ToLower() == "style" && styleRegex.IsMatch(x.Value.ToLower())) ||
                        blocks.Any(block => block.Attributes.Any(x => x.Name.ToLower() == "style" && styleRegex.IsMatch(x.Value.ToLower()))) ||
                        blocks.Any(block => block.Attributes.Any(x => x.Name.ToLower() == "bgcolor" && isVisibleColor(x.Value))) ||
                        tables.Any(table => table.Attributes.Any(x => x.Name.ToLower() == "style" && styleRegex.IsMatch(x.Value.ToLower()))) ||
                        tables.Any(table => table.Attributes.Any(x => x.Name.ToLower() == "bgcolor" && isVisibleColor(x.Value))));

            return new EmailValidationResult
                       {
                           Valid = valid,
                           ReportRule = rule
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage();
            var strongRegex = new Regex("<strong>", RegexOptions.IgnoreCase);
            var inlineBoldRegex = new Regex("<b>", RegexOptions.IgnoreCase);
            var cssBoldRegex = new Regex("font-weight:bold;", RegexOptions.IgnoreCase);

            var inlineItalicsRegex = new Regex("<i>.*</i>", RegexOptions.IgnoreCase);
            var cssItalicsRegex = new Regex("font-style:.italic;", RegexOptions.IgnoreCase);

            var inlineUnderlineRegex = new Regex("<u>.</u>", RegexOptions.IgnoreCase);
            var underlineRegex = new Regex("text-decoration:.underline;", RegexOptions.IgnoreCase);

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = strongRegex.Match(emailMessage.Body).Success ||
                                   inlineBoldRegex.Match(emailMessage.Body).Success ||
                                   cssItalicsRegex.Match(emailMessage.Body).Success ||
                                   inlineItalicsRegex.Match(emailMessage.Body).Success ||
                                   cssBoldRegex.Match(emailMessage.Body).Success ||
                                   inlineUnderlineRegex.Match(emailMessage.Body).Success ||
                                   underlineRegex.Match(emailMessage.Body).Success
                       };
        }
 public EmailValidationResult Validate(EmailReport report, ReportRule rule)
 {
     var emailMessage = report.GetEmailMessage();
     return new EmailValidationResult
                {
                    ReportRule = rule,
                    Valid = emailMessage.Subject.Count() < 50
                };
 }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            document.LoadHtml(report.GetEmailMessage().Body);

            var anchorTags = document.DocumentNode.Find(HtmlElementType.A);
            var valid = anchorTags.Any(tag => rule.Dictionary.Any(entry => tag.Attributes.Any(a => a.Name.ToLower() == "href" && a.Value.ToLower().Contains(entry.Value.ToLower()))));
            var first = anchorTags.FirstOrDefault(tag => rule.Dictionary.Any(entry => tag.Attributes.Any(a => a.Name.ToLower() == "href" && a.Value.ToLower().Contains(entry.Value.ToLower()))));
            return new EmailValidationResult {ReportRule = rule, Valid = valid};
        }
예제 #7
0
        public static EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage();
            var valid = rule.Dictionary.Any(dictionary => emailMessage.Body.ToLower().Contains(dictionary.Value.ToLower()));

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = valid
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var bottomRegion = report.GetEmailMessage().Body.GetRegion(0.8, 1.0);
            var zipCodeRegex = new Regex(@"[\d]{5}|[\d]{5}\-[\d]{4}");

            bottomRegion = StripHtml(bottomRegion);

            return new EmailValidationResult
            {
                ReportRule = rule,
                Valid = zipCodeRegex.Match(bottomRegion).Success
            };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage();
            var htmlDocument = new HtmlDocument();
            htmlDocument.Load(new StringReader(emailMessage.Body));

            var images = htmlDocument.DocumentNode.SelectNodes("//img");
            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = !images.Any(x => !x.XPath.Contains("href"))
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage().Body.Replace('\n',' ');

            // Matches any dictionary entry text plus a link including the text 'click' somewhere further on (Having trouble viewing? <a href='blah'>Click here</a>)
            var valid = rule.Dictionary.Any(x => new Regex(x.Value.ToLower() + ".*<a.*click.*").Match(emailMessage.ToLower()).Success);

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = valid
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            document.LoadHtml(report.GetEmailMessage().Body);

            var isUrl = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);

            var anchorTags = document.DocumentNode.Find(HtmlElementType.A);

            var valid = !anchorTags.Any(x => (!rule.Dictionary.Any(dict => x.InnerText == dict.Value))
                                            && (isUrl.Match(x.InnerText).Success));
            return new EmailValidationResult {ReportRule = rule, Valid = valid};
        }
예제 #12
0
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage();
            var emailBody = emailMessage.Body;
            var topBody = emailBody.Substring(0, (int) Math.Ceiling(emailBody.Length*.1));
            var imageRegex = new Regex("<img .*>");

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = imageRegex.Match(topBody).Success
                       };
        }
예제 #13
0
        public static EmailValidationResult ValidateRegion(EmailReport report, ReportRule rule, double start, double end)
        {
            var emailMessage = report.GetEmailMessage();
            var emailBody = emailMessage.Body;
            var region = emailBody.GetRegion(start, end);
            var valid = rule.Dictionary.Any(dictionary => region.ToLower().Contains(dictionary.Value.ToLower()));

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = valid
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage();
            var htmlDocument = new HtmlDocument();
            htmlDocument.Load(new StringReader(emailMessage.Body));
            var bodyWords = htmlDocument.DocumentNode.InnerText.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = bodyWords.Length < 500
                           //Valid = bodyWords.Length < 200
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var htmlDocument = new HtmlDocument();
            htmlDocument.LoadHtml(report.GetEmailMessage().Body);

            var body = htmlDocument.DocumentNode.Find(HtmlElementType.Body).FirstOrDefault();

            var valid = body == null || !body.Attributes.Any(x => x.Name.ToLower() == "background");

            return new EmailValidationResult
                       {
                           Valid = valid,
                           ReportRule = rule
                       };
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            document.LoadHtml(report.GetEmailMessage().Body);

            var isUrl = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);

            var anchorTags = document.DocumentNode.Find(HtmlElementType.A);
            var valid = anchorTags.Any(x =>
            {
                var href = x.Attributes["href"];
                return href != null && isUrl.Match(href.Value).Success;
            });

            return new EmailValidationResult {ReportRule = rule, Valid = valid};
        }
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            var body = report.GetEmailMessage().Body;
            // Get the HTML of the first half of the body text
            document.LoadHtml(body.Substring(0, body.Length / 2));

            // Get all image tags in there
            var imageTags = document.DocumentNode.Find(HtmlElementType.Img);

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           // If there are any image tags, return true
                           Valid = (imageTags.Count > 0?true:false)
                       };
        }
예제 #18
0
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var emailMessage = report.GetEmailMessage();
            var inlineFontsRegex = new Regex("<font.>.</font>", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
            var cssFontsRegex = new Regex("font-family:.", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);

            var inlineFonts = inlineFontsRegex.Match(emailMessage.Body);
            var cssFonts = cssFontsRegex.Match(emailMessage.Body);

            var totalUniqueFontCount = inlineFonts.Captures.Count + cssFonts.Captures.Count;

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = totalUniqueFontCount < 3
                       };
        }
예제 #19
0
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            var body = report.GetEmailMessage().Body;
            // Get the HTML of the first half of the body text
            document.LoadHtml(body.Substring(0, body.Length / 2));

            // Get all image tags in there
            var imageTags = document.DocumentNode.Find(HtmlElementType.Img);

            var valid = imageTags.Any(x => HtmlDocumentExtensions.Parent(x, HtmlElementType.A) != null);

            return new EmailValidationResult
                       {
                           Valid = valid,
                           ReportRule = rule
                       };
        }
예제 #20
0
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            var body = report.GetEmailMessage().Body;
            // Get the HTML of the first half of the body text
            document.LoadHtml(body.Substring(0, body.Length / 2));

            // Get all image tags in there
            var imageTags = document.DocumentNode.Find(HtmlElementType.Img);

            var valid = !imageTags.Any(x => (!rule.Dictionary.Any(dict => x.Attributes["src"].Value != dict.Value))
                                            && (x.Attributes.Any(y => y.Name == "alt" && string.IsNullOrEmpty(y.Value))
                                            || !x.Attributes.Any(y => y.Name == "alt")));

            return new EmailValidationResult
                       {
                           ReportRule = rule,
                           Valid = valid
                       };
        }
예제 #21
0
        public EmailValidationResult Validate(EmailReport report, ReportRule rule)
        {
            var document = new HtmlDocument();
            var body = report.GetEmailMessage().Body;

            document.LoadHtml(body);

            // Get all image tags in there
            var imageTags = document.DocumentNode.Find(HtmlElementType.Img);

            var valid = true;
            // For each image tag
            foreach(var imageTag in imageTags)
            {
                var src = imageTag.Attributes["src"];
                if (src == null || string.IsNullOrEmpty(src.Value))
                    continue;

                // If supported by the webserver, get the content length.
                // This way we don't have to download the image!
                try
                {
                    var href = new Uri(src.Value);
                    System.Net.WebRequest req = System.Net.HttpWebRequest.Create(href);
                    req.Method = "HEAD";
                    System.Net.WebResponse resp = req.GetResponse();
                    int ContentLength;
                    if (int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength))
                    {
                        if (ContentLength > 256000) valid = false;
                    }
                }
                catch (Exception) { }
            }

            return new EmailValidationResult
                       {
                           Valid = valid,
                           ReportRule = rule
                       };
        }