Solved

Code needed to deal with MIME enriched text format

Posted on 2002-03-24
7
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

623 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