Solved

Code needed to deal with MIME enriched text format

Posted on 2002-03-24
7
158 Views
Last Modified: 2010-04-05
I am writing a Delphi email client and I want to deal with email messages where the content-type is text/enriched.

Text/enriched is a MIME standard relying on tags for formatting where the tags are like <bigger> </bigger>. They are not HTML tags.

Can someone please let me know where to find Delphi code to either convert from enriched text to HTML or to plain text without the enriched tags.

With thanks - Dan
0
Comment
Question by:seabear
  • 4
  • 3
7 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 200 total points
ID: 6893484
The format is defined in the following RFC:
http://www.faqs.org/rfcs/rfc1896.html
0
 

Author Comment

by:seabear
ID: 6895237
Hi AvonWyss,
   Thanks for the URl, this gives C code for the conversion, does anyone know of Delphi code to do the same job (convert enriched text to html)

regards - Dan
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6895269
I don't have any Delphi code at hand for this, but I believe that it should not be too hard (just a little time-consuming) to write this code.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 14

Expert Comment

by:AvonWyss
ID: 6895271
I don't have any Delphi code at hand for this, but I believe that it should not be too hard (just a little time-consuming) to write this code.
0
 

Author Comment

by:seabear
ID: 6909253
AvonWyss is right, the Delphi code is not that hard, even took less time than I thought, I have just been putting the job off. Here is the code I have written and am now using to convert enriched text to HTML - Dan

function enrichedToHTML(erText : string) : string;
var
    i, j, maxLen : integer;
    ch, etag, htag, htmText : string;
begin
    maxLen := length(erText);
    i := 1;
    while i <= maxLen - 1 do
    begin
        ch := erText[i];
        if ch = #13 then  //new line
        begin
            htmText := htmText + '<br>';
            inc(i,2); //assume next char is #10
        end
        else if ch <> '<' then     //ordinary character
        begin
            htmText := htmText + ch;
            inc(i);
        end
        else
        begin
            j := i + 1;
            while (erText[j] <> '>') and (j < maxLen) do inc(j);
            hTag := '';
            eTag := copy(erText, i + 1, j - i - 1);

            if lowercase(etag) = 'bold' then
            begin
                htag := '<b>';
            end
            else if lowercase(etag) = '/bold' then
            begin
                htag := '</b>';
            end

            else if lowercase(etag) = 'italic' then
            begin
                htag := '<i>';
            end
            else if lowercase(etag) = '/italic' then
            begin
                htag := '</i>';
            end

            else if lowercase(etag) = 'center' then
            begin
                htag := '<i>';
            end
            else if lowercase(etag) = '/center' then
            begin
                htag := '</i>';
            end


            else if lowercase(etag) = 'color' then
            //assume an enriched tag like this
            //<color><param>FF00,0000,0000</param>
            //note RGB colors are in 4 digit hex, Windows uses 2 didgit hex 0-255
            //so I will truncate to this
            begin
                htag := '<font color="#'
                 + copy(erText,i + 15,2)
                 + copy(erText,i + 20,2)
                 + copy(erText,i + 25,2) + '">';
                 j := i + 35; //to end of </param>
            end
            else if lowercase(etag) = '/color' then
            begin
                htag := '</font>';
            end

            else if lowercase(etag) = 'bigger' then
            //may have <bigger> or <bigger><bigger> or <bigger><bigger><bigger>
            begin
                if lowercase(copy(erText,i+9,16)) = '<bigger><bigger>' then
                begin
                    htag := '<font size="+4">';
                    j := i + 23;
                end
                else if lowercase(copy(erText,i+9,8)) = '<bigger>' then
                begin
                    htag := '<font size="+3">';
                    j := i + 15;
                end
                else
                begin
                    htag := '<font size="+2">';
                    j := i + 7;
                end;
            end
            else if lowercase(etag) = 'smaller' then
            begin
                htag := '</font>';
            //may have <smaller> or <smaller><smaller>
            //or <smaller><smaller><smaller>
                if lowercase(copy(erText,i+9,16)) = '<smaller><smaller>' then
                begin
                    j := i + 26;
                end
                else if lowercase(copy(erText,i+9,8)) = '<bigger>' then
                begin
                    j := i + 17;
                end
                else
                begin
                    j := i + 8;
                end;
            end

            ;
            htmText := htmText + htag;
            i := j + 1;

        end;
    end;
    result := htmText;
end;
0
 

Author Comment

by:seabear
ID: 6909257
Hi AvonWyss,
     Thanks for pointing me in the right direction - Dan
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6909384
Glad to help! Also, thank you (in the name of the community) for posting your code, so that it will appear in the PAQ if someone wants to see the solution.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now