Example #1
0
        private static void CheckHtml(MimeEntity entity)
        {
            if (entity.DataText.Trim().Length == 0)
            {
                entity.WrapDataText("<html>", "</html>");
            }
            else
            {
                var ipos = 0;
                var c    = entity.DataText[ipos];
                while (ipos < entity.DataText.Length - 1 && (c == ' ' || c == '\t' || c == '\r' || c == '\n'))
                {
                    c = entity.DataText[++ipos];
                }
                var dtstr = entity.DataText.Substring(0, "<!DOCTYPE".Length);
                if (dtstr.ToUpper() == "<!DOCTYPE")
                {
                    ipos = entity.DataText.IndexOf('>', ipos + "<!DOCTYPE".Length);
                    while (ipos < entity.DataText.Length - 1 && (c == ' ' || c == '\t' || c == '\r' || c == '\n'))
                    {
                        c = entity.DataText[++ipos];
                    }
                }

                if (ipos > 4 && ipos < entity.DataText.Length - 5)
                {
                    var hdr = entity.DataText.Substring(ipos, 4);
                    if (hdr.ToLower() == "<div")
                    {
                        entity.WrapDataText("<html>", "</html>");
                    }
                }
                else
                {
                    entity.WrapDataText("<html>", "</html>");
                }
            }
        }