Ejemplo n.º 1
0
        public IEnumerable <EmailReport> List()
        {
            List <EmailReport> _return = new List <EmailReport>();

            using (SqlConnection Con = new SqlConnection(_connStr.Value.SqlServer))
            {
                using (SqlCommand Cmd = new SqlCommand())
                {
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Connection  = Con;
                    Cmd.CommandText = "[sp_EMAILS_MI4D_LIST]";

                    Con.Open();

                    using (SqlDataReader MyDR = Cmd.ExecuteReader())
                    {
                        while (MyDR.Read())
                        {
                            EmailReport er = new EmailReport(
                                MyDR.GetInt32(0),
                                MyDR.GetString(1),
                                MyDR.GetInt32(2),
                                MyDR.GetString(3),
                                MyDR.GetDateTime(4)
                                );

                            _return.Add(er);
                        }
                    }
                }
            }

            return(_return);
        }
        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
                       };
        }
Ejemplo n.º 3
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 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 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
                       };
        }
Ejemplo n.º 5
0
        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 void TestEmptyWithSubject()
        {
            var emailRpt = new EmailReport(_config)
            {
                Subject = "Empty Test email with subject"
            };

            emailRpt.Send(false);
        }
 public EmailValidationResult Validate(EmailReport report, ReportRule rule)
 {
     var emailMessage = report.GetEmailMessage();
     return new EmailValidationResult
                {
                    ReportRule = rule,
                    Valid = emailMessage.Subject.Count() < 50
                };
 }
        public void TestEmptyWithSubjectCC()
        {
            var emailRpt = new EmailReport(_config)
            {
                Subject = "Empty Test email with subject",
                CC      = "*****@*****.**"
            };

            emailRpt.Send(false);
        }
        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};
        }
Ejemplo n.º 10
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 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"))
                       };
        }
Ejemplo n.º 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
                       };
        }
Ejemplo n.º 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().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};
        }
        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 void TestPoleCountEmail()
        {
            var tempPath = Path.GetTempPath();
            var xmlPath  = Path.Combine(tempPath, @"poles.xml");

            File.WriteAllText(xmlPath, GetPoleCountXmlString());

            var emailRpt = new EmailReport(_config)
            {
                Subject = "Test Pole Down Report email"
            };

            emailRpt.SendAsAttachment(xmlPath, false);
        }
        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};
        }
Ejemplo n.º 21
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
                       };
        }
        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)
                       };
        }
Ejemplo n.º 23
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
                       };
        }
Ejemplo n.º 24
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
                       };
        }
        public void TestHtmlReport()
        {
            var rpt  = getXmlString();
            var xsl  = getXslString();
            var html = TransformReport(rpt, xsl);

            var tempPath = Path.GetTempPath();
            var htmlPath = Path.Combine(tempPath, @"temp.html");

            File.WriteAllText(htmlPath, html);

            var emailRpt = new EmailReport(_config)
            {
                Subject = "Test Report email",
                Report  = htmlPath,
                CC      = @"*****@*****.**"
            };

            emailRpt.Send(true);
        }
Ejemplo n.º 26
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
                       };
        }
        static void EmailReport()
        {
            try
            {
                // Step 00:  Setup Data
                EmailReport data = new EmailReport();
                data.ReportName = "Some Report";
                data.Version    = 2;
                data.Problems.Add("wibble thing needs fixing");
                data.Problems.Add("thingy-ma-bop needs straightening");
                data.Problems.Add("doobery needs inverting");

                // Step 01: Load HTML Template From embedded resource
                var htmlTemplate = EmbeddedResourceUtils.GetAppResource("EmailReport.cshtml");

                // Step 02: Generate HTML Contents
                var htmlReport = new RazorGenerator(htmlTemplate, data).Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} - {MethodBase.GetCurrentMethod().Name}");
            }
        }
 public EmailValidationResult Validate(EmailReport report, ReportRule rule)
 {
     return DictionaryValidator.ValidateRegion(report, rule, 0, 1.0);
 }
Ejemplo n.º 29
0
 public ActionResult Register(RegisterModel model)
 {
     try
     {
         var emailReport = new EmailReport
                    {
                        ReportId = GetReportId(),
                        CreationApplication = model.CreationApplication,
                        Industry = model.Industry,
                        UserEmailAddress = model.EmailAddress,
                        Status = EmailStatus.Waiting
                    };
         emailReport = _emailReportService.SaveEmailReport(emailReport);
         var uniqueId = emailReport.ReportId;
         var emailAddress = string.Format("{0}@{1}", uniqueId, ECO.Configuration.Configuration.DomainName);
         return View("SendUsYourEmail", new SendUsYourEmailModel { EmailAddres = emailAddress });
     }
     catch (Exception ex)
     {
         return View("SendUsYourEmail", new SendUsYourEmailModel
                                            {
                                                EmailAddres = GetFullErrorMessagE(ex)
                                            });
     }
 }
Ejemplo n.º 30
0
 public EmailValidationResult ValidateRule(EmailReport report, ReportRule rule)
 {
     var validator = GetReportRuleValidator(rule.Name);
     return validator == null
                ? new EmailValidationResult {ReportRule = rule, Valid = false}
                : validator.Validate(report, rule);
 }
Ejemplo n.º 31
0
 public EmailReport SaveEmailReport(EmailReport newEmailReport)
 {
     return _baseRepository.SaveOrUpdate(newEmailReport);
 }
 public EmailValidationResult Validate(EmailReport report, ReportRule rule)
 {
     return new EmailValidationResult {ReportRule = rule, Valid = true};
 }
        public void TestEmptyEmailSend()
        {
            var emailRpt = new EmailReport(_config);

            emailRpt.Send(false);
        }