Solved

Code needed to deal with MIME enriched text format

Posted on 2002-03-24
7
161 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

20 Experts available now in Live!

Get 1:1 Help Now