Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

Read the timestamp from the most recent Received header

See more Email Object Examples

Read the topmost Received field of a delivered message. Its timestamp follows the final semicolon. A draft can have no trace header, and some relays supply an unparseable timestamp.

Chilkat Objective-C Downloads

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

BOOL success = NO;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

CkoEmail *email = [[CkoEmail alloc] init];
success = [email LoadEml: @"received.eml"];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

CkoStringBuilder *trace = [[CkoStringBuilder alloc] init];
[trace Append: [email GetHeaderField: @"Received"]];
if ([trace Contains: @";" caseSensitive: YES] != YES) {
    NSLog(@"%@",@"No timestamp delimiter in the top Received field.");
    return;
}

NSString *stamp = [trace GetAfterFinal: @";" removeFlag: NO];
[trace SetString: stamp];
[trace Trim];
NSLog(@"%@%@",@"Relay timestamp: ",[trace GetAsString]);
CkoDateTime *when = [[CkoDateTime alloc] init];
success = [when SetFromRfc822: [trace GetAsString]];
if (success != YES) {
    NSLog(@"%@",@"Failed: when.SetFromRfc822.");
    return;
}

NSLog(@"%@%@",@"UTC: ",[when GetAsTimestamp: NO]);