Sample code for 30+ languages & platforms
Unicode C

Set a MIME Body from Transfer-Encoded Text

See more MIME Examples

Demonstrates the Chilkat Mime.SetBodyFromEncoded method, which sets the body from already transfer-encoded text. The first argument is the encoding (base64 or quoted-printable) and the second is the encoded text.

Background: Sometimes you already hold content in its encoded form — a Base64 string from a database or another API — and re-decoding just to have Chilkat re-encode it is wasteful. This method stores the encoded text as-is and records the matching transfer encoding, so the body is correct without a needless round trip. Only the standard reversible encodings, Base64 and quoted-printable, are accepted.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMimeW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMimeW mime;
    const wchar_t *base64Body;
    const wchar_t *decoded;

    success = FALSE;

    //  Demonstrates the Mime.SetBodyFromEncoded method, which sets the body from already transfer-
    //  encoded text.  The 1st argument is the encoding ("base64" or "quoted-printable") and the 2nd is
    //  the encoded text.

    mime = CkMimeW_Create();

    CkMimeW_putContentType(mime,L"text/plain");

    //  The body is provided already Base64-encoded; Chilkat stores it without re-encoding.
    base64Body = L"SGVsbG8sIHRoaXMgaXMgdGhlIGJvZHku";
    success = CkMimeW_SetBodyFromEncoded(mime,L"base64",base64Body);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        return;
    }

    //  The decoded body is the original text.
    decoded = CkMimeW_getBodyDecoded(mime);
    if (CkMimeW_getLastMethodSuccess(mime) == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        return;
    }

    wprintf(L"%s\n",decoded);


    CkMimeW_Dispose(mime);

    }