Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET POP3

 AfterLogic Forum : MailBee.NET POP3
Subject Topic: Rep[lyto In HTML message Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Terryc
Newbie
Newbie
Avatar

Joined: 10 November 2008
Location: United States
Online Status: Offline
Posts: 2
Posted: 10 November 2008 at 2:36pm | IP Logged Quote Terryc

How can the contentEditable attribute, with a div tag, be added to the HTML message stream so an HTML message can be edited for a reply in a winform using the webcontrol object?

Back to Top View Terryc's Profile Search for other posts by Terryc
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 11 November 2008 at 6:03am | IP Logged Quote Andrew

The complexity is that HTML messages may contain full HTML document with <!DOCTYPE>, <HTML>, <HEAD>, etc. Placing such HTML into a <DIV> would not allow you to display the document correctly.

There are two possible ways:

- remove everything except contents of <BODY></BODY> tag and place it inside a <DIV></DIV>;
- place <DIV></DIV> inside <BODY></BODY>.

In both the cases, MailBee.Html namespace would be useful to you. The following sample implements the second approach:

Code:
using MailBee;
using MailBee.Mime;
using MailBee.Html;

MailMessage msg = new MailMessage();

msg.LoadMessage(@"D:\test.eml");

Processor htmlProcessor = new MailBee.Html.Processor();

// Assign HTML body from the message to HtmlProcessor
htmlProcessor.Dom.OuterHtml = msg.GetHtmlAndSaveRelatedFiles();

if (htmlProcessor.Dom.GetInnerElementsByName("BODY").Count > 0)
{
    // Get reference to <BODY></BODY> element
    Element bodyElement = htmlProcessor.Dom.GetInnerElementsByName("BODY")[0];
    // Create new <DIV> element
    Element divElement = new Element("<div contentEditable=\"true\"></div>");

    // Copy all contents of <BODY> to the <DIV>
    foreach (Element elem in bodyElement.InnerElements)
    {
        divElement.InnerElements.Add(elem);
    }

    // Remove all <BODY> subelements
    bodyElement.InnerElements.RemoveAll( );
    // Add <DIV> to <BODY>
    bodyElement.InnerElements.Add(divEle ment);

    // Get the resulting HTML
    string str = htmlProcessor.Dom.OuterHtml;
    webBrowser1.DocumentText = str;
}
else
{
    MessageBox.Show("Message doesn't contain BODY tag");
}



Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide