Sample code for 30+ languages & platforms
Unicode C

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmailW email;
    int n;
    int i;
    const wchar_t *name;
    const wchar_t *value;

    success = FALSE;

    email = CkEmailW_Create();

    // First, load an email from a file. 
    // Note: an email object may be loaded from a file, or
    // downloaded directly from a POP3 or IMAP server...

    success = CkEmailW_LoadEml(email,L"testReceivedHdrs.eml");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return;
    }

    // How many header fields?

    n = CkEmailW_getNumHeaderFields(email);
    if (n > 0) {

        // Display the name and value of each header:

        for (i = 0; i <= n - 1; i++) {
            name = CkEmailW_getHeaderFieldName(email,i);
            value = CkEmailW_getHeaderFieldValue(email,i);
            wprintf(L"%d\n",i);
            wprintf(L"%s\n",name);
            wprintf(L"%s\n",value);

        }

    }



    CkEmailW_Dispose(email);

    }