Sample code for 30+ languages & platforms
Objective-C

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat Objective-C Downloads

Objective-C
#import <CkoEmail.h>
#import <NSString.h>

BOOL success = NO;

CkoEmail *email = [[CkoEmail alloc] init];

// 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: @"testReceivedHdrs.eml"];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

// How many header fields?
int n;
n = [email.NumHeaderFields intValue];
if (n > 0) {

    // Display the name and value of each header:
    int i;
    NSString *name = 0;
    NSString *value = 0;
    for (i = 0; i <= n - 1; i++) {
        name = [email GetHeaderFieldName: [NSNumber numberWithInt: i]];
        value = [email GetHeaderFieldValue: [NSNumber numberWithInt: i]];
        NSLog(@"%d",i);
        NSLog(@"%@",name);
        NSLog(@"%@",value);

    }

}