Objective-C Requires Chilkat v11.0.0+
Objective-C
Preserve the original email and save a modified copy
See more Email Object Examples
Use with-attachments.eml as a stand-in for bytes from an IMAP fetch or a message queue. Preserve those bytes first. Parse them into an Email object, add a local processing header, and serialize the result into a separate buffer. The archived input remains suitable for later byte-level inspection.
Chilkat Objective-C Downloads
#import <CkoBinData.h>
#import <CkoEmail.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoBinData *mimeBytes = [[CkoBinData alloc] init];
success = [mimeBytes LoadFile: @"with-attachments.eml"];
if (success != YES) {
NSLog(@"%@",@"Failed: mimeBytes.LoadFile.");
return;
}
success = [mimeBytes WriteFile: @"received-original.eml"];
if (success != YES) {
NSLog(@"%@",@"Failed: mimeBytes.WriteFile.");
return;
}
CkoEmail *email = [[CkoEmail alloc] init];
success = [email SetFromMimeBd: mimeBytes];
if (success != YES) {
NSLog(@"%@",email.LastErrorText);
return;
}
[email AddHeaderField: @"X-Workflow-State" fieldValue: @"reviewed"];
// GetMimeBd appends to its destination. Use a fresh buffer for this message.
CkoBinData *rendered = [[CkoBinData alloc] init];
success = [email GetMimeBd: rendered];
if (success != YES) {
NSLog(@"%@",email.LastErrorText);
return;
}
success = [rendered WriteFile: @"reviewed.eml"];
if (success != YES) {
NSLog(@"%@",@"Failed: rendered.WriteFile.");
return;
}
NSLog(@"%@",@"Archived received-original.eml and saved reviewed.eml.");