Rust Requires Chilkat v11.0.0+
Rust
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 Rust Downloads
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let mime_bytes = chilkat::BinData::new();
if mime_bytes.load_file("with-attachments.eml").is_err() {
println!("Failed: mimeBytes.LoadFile.");
return;
}
if mime_bytes.write_file("received-original.eml").is_err() {
println!("Failed: mimeBytes.WriteFile.");
return;
}
let email = chilkat::Email::new();
if email.set_from_mime_bd(&mime_bytes).is_err() {
println!("{}", email.last_error_text());
return;
}
email.add_header_field("X-Workflow-State", "reviewed");
// GetMimeBd appends to its destination. Use a fresh buffer for this message.
let rendered = chilkat::BinData::new();
if email.get_mime_bd(&rendered).is_err() {
println!("{}", email.last_error_text());
return;
}
if rendered.write_file("reviewed.eml").is_err() {
println!("Failed: rendered.WriteFile.");
return;
}
println!("Archived received-original.eml and saved reviewed.eml.");