예제 #1
0
        public static void ChangeUrlProxyLinks(this MailDraftData draft, ILog log = null)
        {
            if (log == null)
            {
                log = new NullLog();
            }

            try
            {
                draft.HtmlBody = HtmlSanitizer.RemoveProxyHttpUrls(draft.HtmlBody);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("ChangeUrlProxyLinks(): Exception: {0}", ex.ToString());
            }
        }
        public static void ChangeUrlProxyLinks(this MailDraft draft, ILogger log = null)
        {
            if (log == null)
            {
                log = new NullLogger();
            }

            try
            {
                var htmlSanitizer = new HtmlSanitizer();
                draft.HtmlBody = htmlSanitizer.RemoveProxyHttpUrls(draft.HtmlBody);
            }
            catch (Exception ex)
            {
                log.Error("ChangeUrlProxyLinks(): Exception: {0}", ex.ToString());
            }
        }
        public void TestReplaceProxyUrlsBackToUrls()
        {
            const string html = "<html>" +
                                "<head></head>" +
                                "<body>" +
                                "<div>" +
                                "<a style=\"text-decoration:none;height:95px;width:630px;margin:0;padding:35px 0 0 50px;display:block;background-image:url(/httphandlers/urlProxy.ashx?url=aHR0cDovL2Nkbi50ZWFtbGFiLmNvbS9tZWRpYS9uZXdzbGV0dGVycy9pbWFnZXMvaGVhZGVyXzA3LmpwZw==);\" href=\"http://www.onlyoffice.com/\">" +
                                "<img style=\"border: 0; margin: 0; padding: 0; color: #fff; font-size: 26px; font-weight: 700; display: block;\" alt=\"ONLYOFFICE™\" src=\"/httphandlers/urlProxy.ashx?url=aHR0cDovL2Nkbi50ZWFtbGFiLmNvbS9tZWRpYS9uZXdzbGV0dGVycy9pbWFnZXMvaGVhZGVyXzA4LnBuZw==\">" +
                                "</a>" +
                                "</div>" +
                                "<table width=\"600\">" +
                                "<tr>" +
                                "<td background=\"/httphandlers/urlProxy.ashx?url=aHR0cDovL2Nkbi50ZWFtbGFiLmNvbS9tZWRpYS9uZXdzbGV0dGVycy9pbWFnZXMvaGVhZGVyXzA3LmpwZw==\">Ячейка с фоновым рисунком</td>" +
                                "</tr>" +
                                "</table>" +
                                "</body>" +
                                "</html>";

            var htmlSanitizer = new HtmlSanitizer();

            var res = htmlSanitizer.RemoveProxyHttpUrls(html);

            Assert.AreEqual("<html><head></head><body><div><a style=\"text-decoration:none;height:95px;width:630px;margin:0;padding:35px 0 0 50px;display:block;background-image:url(http://cdn.teamlab.com/media/newsletters/images/header_07.jpg);\" href=\"http://www.onlyoffice.com/\"><img style=\"border: 0; margin: 0; padding: 0; color: #fff; font-size: 26px; font-weight: 700; display: block;\" alt=\"ONLYOFFICE™\" src=\"http://cdn.teamlab.com/media/newsletters/images/header_08.png\"></a></div><table width=\"600\"><tr><td background=\"http://cdn.teamlab.com/media/newsletters/images/header_07.jpg\">Ячейка с фоновым рисунком</td></tr></table></body></html>", res);
        }