How to handle different Content-Type's

Giganews Newsgroups
Subject: How to handle different Content-Type's
Posted by:  Etienne van Tonder (e…@infoware.com.au)
Date: Mon, 19 Jul 2004

I'm having some problems trying to determine how best to handle the
different content types. Is there a standard way of handling the different
types and if so is anyone willing to share some code to show me how to do
it. Currently I am using the following code but it assumes that if the
content-type does not include multipart it's either text or html. This is
not the case as I've discovered as the Content-Type can contain many types
including "video/x-ms-wmv" for example.

        if (indEMailRecv->ContentType.Trim().LowerCase().Pos("multipart/"))
        {
            LogEntry(fpLog, "GetBody: multipart message\
");
            // should have a MIME-coded body
            htmlbody = GetMimeBody("text/html");
            if (htmlbody.IsEmpty())
                // maybe xml?
                htmlbody = GetMimeBody("text/xml");
            html = (!htmlbody.IsEmpty());
            // Get normal text/plain body
            textbody = GetMimeBody("text/plain");
            if (textbody.IsEmpty())
                textbody = msg->Body->Text;
            if (htmlbody.IsEmpty())
                htmlbody = textbody;
        }
        else
        {
            LogEntry(fpLog, "GetBody: not a multipart message\
");
            // Get normal text/plain body
            textbody = msg->Body->Text;
            htmlbody = textbody;
            // Determine body type
            if
(indEMailRecv->ContentType.Trim().LowerCase().Pos("text/plain"))
                html = false;
            else
                html = true;
        }

Thanks,

Etienne.

Replies