Rust
Rust
Get Contents of a T-Mobile Text Message (as Email)
See more Email Object Examples
How to get the contents of an email that originated as a T-Mobile SMS text.
Chilkat Rust Downloads
// First, for the purpose of understanding the structure of the MIME,
// let's load the MIME into a Chilkat MIME object and examine the MIME structure.
let mime = chilkat::Mime::new();
let _ = mime.load_mime_file("qa_data/eml/TMobileTextMsg.eml").is_ok();
// Show the MIME structure in text format (as opposed to XML format).
println!("{}", mime.get_structure("text").unwrap_or_default());
// The MIME structure for our test email looks like this:
// multipart/related
// text/html
// text/plain
// image/gif
// image/gif
// image/gif
// The HTML part is not considered a "related item" because the related items
// are defined as being related to the HTML part. Therefore, we should always
// expect to find a text/html part under a multipart/related. The HTML parts
// is simply the HTML body, and the other parts are the related items.
// If the text/plain part was to be considered as an alternative body,
// then a properly structured email would include a multipart/alternative structure.
let email = chilkat::Email::new();
let _ = email.load_eml("qa_data/eml/TMobileTextMsg.eml").is_ok();
// We should see 4 related items.
println!("Num Related Items = {}", email.num_related_items());
// There should be 0 attachments.
println!("Num Attachments = {}", email.num_attachments());
// Find the indices of the text/plain related part, and the text/html related part
let mut i = 0;
let num_related_items = email.num_related_items();
let sb_content_type = chilkat::StringBuilder::new();
while i < num_related_items {
let _ = sb_content_type.append(&email.get_related_content_type(i).unwrap_or_default());
println!("{}: {}", i, sb_content_type.get_as_string().unwrap_or_default());
if sb_content_type.contents_equal("text/plain", false) {
println!("---- text/plain part:");
println!("{}", email.get_related_string(i, "utf-8").unwrap_or_default());
}
sb_content_type.clear();
i = i + 1;
}