Solved

Code needed to deal with MIME enriched text format

Posted on 2002-03-24
7
166 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 142
creating threads in delphi 1 157
update joined tables 2 62
How to Get Images From Server to Client using App Tethering 1 39
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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