Sample code for 30+ languages & platforms
Unicode C

Get Contents of a T-Mobile Text Message (as Email)

See more Email Object Examples

How to get the contents of an email that originated as a T-Mobile SMS text.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMimeW.h>
#include <C_CkEmailW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMimeW mime;
    HCkEmailW email;
    int i;
    int numRelatedItems;
    HCkStringBuilderW sbContentType;

    success = FALSE;

    // First, for the purpose of understanding the structure of the MIME,
    // let's load the MIME into a Chilkat MIME object and examine the MIME structure.
    mime = CkMimeW_Create();

    success = CkMimeW_LoadMimeFile(mime,L"qa_data/eml/TMobileTextMsg.eml");
    // Show the MIME structure in text format (as opposed to XML format).
    wprintf(L"%s\n",CkMimeW_getStructure(mime,L"text"));

    // The MIME structure for our test email looks like this:
    // multipart/related
    //     text/html
    //     text/plain
    //     image/gif
    //     image/gif
    //     image/gif

    // The HTML part is not considered a "related item" because the related items
    // are defined as being related to the HTML part.  Therefore, we should always
    // expect to find a text/html part under a multipart/related.  The HTML parts
    // is simply the HTML body, and the other parts are the related items.
    // If the text/plain part was to be considered as an alternative body,
    // then a properly structured email would include a multipart/alternative structure.

    email = CkEmailW_Create();

    success = CkEmailW_LoadEml(email,L"qa_data/eml/TMobileTextMsg.eml");

    // We should see 4 related items.
    wprintf(L"Num Related Items = %d\n",CkEmailW_getNumRelatedItems(email));
    // There should be 0 attachments.  
    wprintf(L"Num Attachments = %d\n",CkEmailW_getNumAttachments(email));

    // Find the indices of the text/plain related part, and the text/html related part
    i = 0;
    numRelatedItems = CkEmailW_getNumRelatedItems(email);
    sbContentType = CkStringBuilderW_Create();
    while (i < numRelatedItems) {
        CkStringBuilderW_Append(sbContentType,CkEmailW_getRelatedContentType(email,i));
        wprintf(L"%d: %s\n",i,CkStringBuilderW_getAsString(sbContentType));
        if (CkStringBuilderW_ContentsEqual(sbContentType,L"text/plain",FALSE)) {
            wprintf(L"---- text/plain part:\n");
            wprintf(L"%s\n",CkEmailW_getRelatedString(email,i,L"utf-8"));
        }

        CkStringBuilderW_Clear(sbContentType);
        i = i + 1;
    }



    CkMimeW_Dispose(mime);
    CkEmailW_Dispose(email);
    CkStringBuilderW_Dispose(sbContentType);

    }