public static void RenderMultipartRelated(MultipartRelated related, WebBrowserEditabil pWebBrowser) { var root = related.Root; var multipart = root as Multipart; var text = root as TextPart; if (multipart != null) { for (int i = multipart.Count; i > 0; i--) { var body = multipart[i - 1] as TextPart; if (body == null) { continue; } if (body.ContentType.IsMimeType("text", "html")) { text = body; break; } if (text == null) { text = body; } } } if (text != null) { if (text.ContentType.IsMimeType("text", "html")) { var ctx = new MultipartRelatedImageContext(related); var converter = new HtmlToHtml() { HtmlTagCallback = ctx.HtmlTagCallback }; var html = converter.Convert(text.Text); pWebBrowser.DocumentText = html; } else { RenderText(text, pWebBrowser); } } else { return; } }
void RenderMultipartRelated(MultipartRelated related) { var root = related.Root; var multipart = root as Multipart; var text = root as TextPart; if (multipart != null) { // Note: the root document can sometimes be a multipart/alternative. // A multipart/alternative is just a collection of alternate views. // The last part is the format that most closely matches what the // user saw in his or her email client's WYSIWYG editor. for (int i = multipart.Count; i > 0; i--) { var body = multipart[i - 1] as TextPart; if (body == null) { continue; } // our preferred mime-type is text/html if (body.ContentType.IsMimeType("text", "html")) { text = body; break; } if (text == null) { text = body; } } } // check if we have a text/html document if (text != null) { if (text.ContentType.IsMimeType("text", "html")) { // replace image src urls that refer to related MIME parts with "data:" urls // Note: we could also save the related MIME part content to disk and use // file:// urls instead. var ctx = new MultipartRelatedImageContext(related); var converter = new HtmlToHtml() { HtmlTagCallback = ctx.HtmlTagCallback }; var html = converter.Convert(text.Text); webBrowser.DocumentText = html; } else { RenderText(text); } } else { // we don't know how to render this type of content return; } }
void RenderMultipartRelated (MultipartRelated related) { var root = related.Root; var multipart = root as Multipart; var text = root as TextPart; if (multipart != null) { // Note: the root document can sometimes be a multipart/alternative. // A multipart/alternative is just a collection of alternate views. // The last part is the format that most closely matches what the // user saw in his or her email client's WYSIWYG editor. for (int i = multipart.Count; i > 0; i--) { var body = multipart[i - 1] as TextPart; if (body == null) continue; // our preferred mime-type is text/html if (body.ContentType.Matches ("text", "html")) { text = body; break; } if (text == null) text = body; } } // check if we have a text/html document if (text != null) { if (text.ContentType.Matches ("text", "html")) { // replace image src urls that refer to related MIME parts with "data:" urls // Note: we could also save the related MIME part content to disk and use // file:// urls instead. var ctx = new MultipartRelatedImageContext (related); var converter = new HtmlToHtml () { HtmlTagCallback = ctx.HtmlTagCallback }; var html = converter.Convert (text.Text); webBrowser.DocumentText = html; } else { RenderText (text); } } else if (root != null) { // we don't know what we have, so render it as an entity Render (root); } }