librelist archives

« back to archive

example of HTML renderer

example of HTML renderer

Hoà V. Dinh
2013-02-03 @ 06:47
Here's how the HTML renderer will work.

1. For local messages:

    mailcore::Data * data = Data::dataWithContentsOfFile(MCSTR("message.eml"));
    mailcore::MessageParser * parser = 
    MCLog("%s", MCUTF8(parser->htmlRendering()));

2. For IMAP messages:

Once you fetched an IMAP message:
    mailcore::IMAPMessage * msg;
    mailcore::String * result = msg->htmlRendering("INBOX", imapCallback);

imapCallback is an instance of HTMLRendererIMAPCallback.

    class HTMLRendererIMAPCallback {
        virtual Data * dataForIMAPPart(String * folder, IMAPPart * part) {
return NULL; }
        virtual void prefetchAttachmentIMAPPart(String * folder, IMAPPart 
* part) {}
        virtual void prefetchImageIMAPPart(String * folder, IMAPPart * part) {}

dataForIMAPPart() should return the data of the given part from a cache.
It can return NULL is data is not in cache. The callback class can use 
this opportunity to fetch the data from the network if needed and try to 
call htmlRendering() again later when data is available.
If there's some missing data (when one of the dataForIMAPPart() call 
returns NULL), result of htmlRendering() will be NULL.

If you need more customisation for the HTML rendering, you can have a look
at HTMLRendererTemplateCallback definition.
Let me know if you think something is missing.

ctemplate has been added as a dependency.

My next steps

I also worked on a Cocoa view to show a message though it's blocked by the
Objective-C API.
I'm working on the implementation of String::cleanedHTMLString(), which 
will use libtidy to provide a valid HTML.
Providing a valid HTML should help users do some processing on the HTML 
before rendering without having to care about whether the HTML is valid.

Hoà V. Dinh