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 <CkEmailW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkEmailW email;

    // 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 = email.LoadEml(L"testReceivedHdrs.eml");
    if (success != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

    // How many header fields?
    int n;
    n = email.get_NumHeaderFields();
    if (n > 0) {

        // Display the name and value of each header:
        int i;
        const wchar_t *name = 0;
        const wchar_t *value = 0;
        for (i = 0; i <= n - 1; i++) {
            name = email.getHeaderFieldName(i);
            value = email.getHeaderFieldValue(i);
            wprintf(L"%d\n",i);
            wprintf(L"%s\n",name);
            wprintf(L"%s\n",value);

        }

    }
    }