Formatting Emails in 4D
This tutorial shows a quick and dirty way of formatting emails on screen in a similar fashion to email clients such as MS Outlook Express (when I say quick, I mean to say that it's pretty fast, and dirty, because the code is written to be fast compiled and not necessarily easy to follow). The idea is to take an email stored in a text field/variable or a BLOB field/variable, find all the hyperlinks and quoted text, then display a coloured version of the email in a 4D Write area, in a way so that the hyperlinks are activated when the user double-clicks them.
The sample code has been lifted from Mail4th Express, the vapourware email client written with 4D 6.5. Although Mail4th Express has never been finished, these routines seem to work fine. The main bottleneck with this code is in the formatting the 4D Write document. It doesn't seem to matter whether this is done on or off screen, it's still slow in comparison to the parsing code. Emails that are bigger than about 64K take too long to format in our opinion. There is a faster way of creating 4D Write documents, but we will release something separately for that. Typically, on a Powerbook G3 500, parsing a 32K 4D NUG digest email and formatting in the 4D Write area takes approximately 1 second.
The examples have been designed to work with 4D v6.5 and 4D Write v6.5, although they should work with v6, the 4D Write code would definitely need looking into to ensure compatibility with earlier versions. They've also been tested with 4D/4D Write 6.7.
Important: Forget about using this code in an interpreted database unless you're only viewing extremely small emails. The routine used for parsing and formatting emails has been optimised for compiled running and will be extremely unpleasant for your users if you run this in interpreted mode.
|