Rust
Rust
Remove a Single Attached Message from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.
Background: Attached messages (forwarded emails carried as
message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.Chilkat Rust Downloads
// Demonstrates the RemoveAttachedMessage method, which removes the Nth message/rfc822
// sub-part (attached email) of the email. The index is zero-based.
// Build an inner email and attach it to an outer email.
let inner_email = chilkat::Email::new();
inner_email.set_subject("Embedded message");
inner_email.set_from("alice@example.com");
let email = chilkat::Email::new();
email.set_subject("Has an attached message");
if email.attach_email(&inner_email).is_err() {
println!("{}", email.last_error_text());
return;
}
println!("NumAttachedMessages before = {}", email.num_attached_messages());
// Remove the first attached message (index 0).
email.remove_attached_message(0);
println!("NumAttachedMessages after = {}", email.num_attached_messages());