public void TestForRemovingHtml()
        {
            const string html = "<html></html>";
            var          res  = _htmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual(String.Empty, res);
        }
        public void TestForScriptTagRemove()
        {
            const string html = "<html><head></head><body>ter\"><script>alert(document.cookie);</script> <scr<script>ipt>alert();</scr<script>ipt></body></html>";
            var          res  = HtmlSanitizer.SanitizeHtmlForEditor(HtmlSanitizer.Sanitize(html, false));

            Assert.AreEqual("<div>ter\"> </div>", res);
        }
Beispiel #3
0
        public MailMessageItem GetMessage(int id, bool?unblocked, bool?is_need_to_sanitize_html, bool?mark_read)
        {
            if (id <= 0)
            {
                throw new ArgumentException(@"Invalid message id", "id");
            }

            var unblockedFlag    = unblocked.GetValueOrDefault(false);
            var needSanitizeHtml = is_need_to_sanitize_html.GetValueOrDefault(false);

            var item = MailBoxManager.GetMailInfo(TenantId, Username, id, unblockedFlag, true);

            if (item == null)
            {
                throw new ItemNotFoundException(String.Format("Message with {0} wasn't founded.", id));
            }

            if (item.WasNew && mark_read.HasValue && mark_read.Value)
            {
                MailBoxManager.SetMessagesReadFlags(TenantId, Username, new List <int> {
                    (int)item.Id
                }, true);
            }

            if (needSanitizeHtml)
            {
                item.HtmlBody = HtmlSanitizer.SanitizeHtmlForEditor(item.HtmlBody);
            }

            return(item);
        }
        public void TestForWrongBodyReplacements()
        {
            const string html = "<html><head></head><body>I used tag <body></body> thats problem.</body></html>";
            var          res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual("<div>I used tag <body></body> thats problem.</div>", res);
        }
        public void TestForComplexBodyReplace()
        {
            const string html = "<html><head></head><body></body></html>";
            var          res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual("<div></div>", res);
        }
        public void TestForRemovingHead3()
        {
            const string html = "<html>\r\n<head> \r\n<style> \r\n some \r\n content \r\n inside \r\n styles \r\n </style> \r\n </head> \r\n</html>";
            var          res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual(String.Empty, res);
        }
        public void TestForRemovingHead2()
        {
            const string html = "<html><head><style>some content inside styles</style></head></html>";
            var          res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual(String.Empty, res);
        }
        public void TestForAttributeInBodySaving()
        {
            const string html = "<body class='test'></body>";
            var          res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual("<div class='test'></div>", res);
        }
Beispiel #9
0
        public void TestForSimpleBodyReplace()
        {
            var html = "<body></body>";
            var res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual("<div></div>", res);
        }
Beispiel #10
0
        public void TestForRemovingHead1()
        {
            var html = "<html><head></head></html>";
            var res  = HtmlSanitizer.SanitizeHtmlForEditor(html);

            Assert.AreEqual(String.Empty, res);
        }
        public MailMessage GetMessage(int id, bool?loadImages, bool?needSanitize, bool?markRead)
        {
            if (id <= 0)
            {
                throw new ArgumentException(@"Invalid message id", "id");
            }

            var needSanitizeHtml = needSanitize.GetValueOrDefault(false);

#if DEBUG
            var watch = new Stopwatch();
            watch.Start();
#endif
            var item = MailBoxManager.GetMailInfo(TenantId, Username, id, new MailMessage.Options
            {
                LoadImages    = loadImages.GetValueOrDefault(false),
                LoadBody      = true,
                NeedProxyHttp = NeedProxyHttp,
                NeedSanitizer = needSanitizeHtml
            });

            if (item == null)
            {
#if DEBUG
                watch.Stop();
                Logger.Debug("Mail->GetMessage(id={0})->Elapsed {1}ms [NotFound] (NeedProxyHttp={2}, NeedSanitizer={3})", id, watch.Elapsed.TotalMilliseconds, NeedProxyHttp, needSanitizeHtml);
#endif
                throw new ItemNotFoundException(string.Format("Message with {0} wasn't founded.", id));
            }

            if (item.WasNew && markRead.HasValue && markRead.Value)
            {
                MailBoxManager.SetMessagesReadFlags(TenantId, Username, new List <int> {
                    (int)item.Id
                }, true);
            }

            if (needSanitizeHtml)
            {
                var htmlSanitizer = new HtmlSanitizer();
                item.HtmlBody = htmlSanitizer.SanitizeHtmlForEditor(item.HtmlBody);
            }
#if DEBUG
            watch.Stop();
            Logger.Debug("Mail->GetMessage(id={0})->Elapsed {1}ms (NeedProxyHttp={2}, NeedSanitizer={3})", id, watch.Elapsed.TotalMilliseconds, NeedProxyHttp, needSanitizeHtml);
#endif
            return(item);
        }
Beispiel #12
0
        public MailMessageItem GetMessage(int id, bool?unblocked, bool?is_need_to_sanitize_html)
        {
            if (id <= 0)
            {
                throw new ArgumentException("Invalid message id", "id");
            }

            var unblocked_flag             = unblocked.GetValueOrDefault(false);
            var is_need_to_sanitize_html_f = is_need_to_sanitize_html.GetValueOrDefault(false);

            var item = mailBoxManager.GetMailInfo(TenantId, Username, id, unblocked_flag, true);

            if (item == null)
            {
                throw new ItemNotFoundException(String.Format("Message with {0} wasn't founded.", id));
            }

            if (is_need_to_sanitize_html_f)
            {
                item.HtmlBody = HtmlSanitizer.SanitizeHtmlForEditor(item.HtmlBody);
            }

            return(item);
        }
        public MailMessage GetMessage(int id, bool?loadImages, bool?needSanitize, bool?markRead)
        {
            if (id <= 0)
            {
                throw new ArgumentException(@"Invalid message id", "id");
            }

            var needSanitizeHtml = needSanitize.GetValueOrDefault(false);

#if DEBUG
            var watch = new Stopwatch();
            watch.Start();
#endif
            var item = MailEngineFactory.MessageEngine.GetMessage(id, new MailMessage.Options
            {
                LoadImages    = loadImages.GetValueOrDefault(false),
                LoadBody      = true,
                NeedProxyHttp = Defines.NeedProxyHttp,
                NeedSanitizer = needSanitizeHtml
            });

            if (item == null)
            {
#if DEBUG
                watch.Stop();
                Logger.DebugFormat(
                    "Mail->GetMessage(id={0})->Elapsed {1}ms [NotFound] (NeedProxyHttp={2}, NeedSanitizer={3})", id,
                    watch.Elapsed.TotalMilliseconds, Defines.NeedProxyHttp, needSanitizeHtml);
#endif
                throw new ItemNotFoundException(string.Format("Message with {0} wasn't found.", id));
            }

            if (item.WasNew && markRead.HasValue && markRead.Value)
            {
                MailEngineFactory.MessageEngine.SetUnread(new List <int> {
                    item.Id
                }, false);
                item.IsNew = false;
            }

            if (needSanitizeHtml)
            {
                item.HtmlBody = HtmlSanitizer.SanitizeHtmlForEditor(item.HtmlBody);
            }
#if DEBUG
            watch.Stop();
            Logger.DebugFormat("Mail->GetMessage(id={0})->Elapsed {1}ms (NeedProxyHttp={2}, NeedSanitizer={3})", id,
                               watch.Elapsed.TotalMilliseconds, Defines.NeedProxyHttp, needSanitizeHtml);
#endif
            if (item.Folder != FolderType.UserFolder)
            {
                return(item);
            }

            var userFoler = GetUserFolderByMailId((uint)item.Id);

            if (userFoler != null)
            {
                item.UserFolderId = userFoler.Id;
            }

            return(item);
        }