Sample code for 30+ languages & platforms
C

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat C Downloads

C
#include <C_CkEmail.h>

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

    success = FALSE;

    email = CkEmail_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 = CkEmail_LoadEml(email,"testReceivedHdrs.eml");
    if (success != TRUE) {
        printf("%s\n",CkEmail_lastErrorText(email));
        CkEmail_Dispose(email);
        return;
    }

    // How many header fields?

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

        // Display the name and value of each header:

        for (i = 0; i <= n - 1; i++) {
            name = CkEmail_getHeaderFieldName(email,i);
            value = CkEmail_getHeaderFieldValue(email,i);
            printf("%d\n",i);
            printf("%s\n",name);
            printf("%s\n",value);

        }

    }



    CkEmail_Dispose(email);

    }