eml-codec/examples/simple.rs

28 lines
899 B
Rust
Raw Normal View History

2023-07-24 09:17:47 +00:00
pub fn main() {
let input = br#"Date: 7 Mar 2023 08:00:00 +0200
From: deuxfleurs@example.com
To: someone_else@example.com
Subject: An RFC 822 formatted message
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
This is the plain text body of the message. Note the blank line
between the header information and the body of the message."#;
2023-07-24 12:05:47 +00:00
// if you are only interested in email metadata/headers
2023-07-24 16:10:44 +00:00
let (_, header) = eml_codec::imf(input).unwrap();
2023-07-24 09:17:47 +00:00
println!(
2023-07-24 10:37:30 +00:00
"{} just sent you an email with subject \"{}\"",
2023-07-24 12:05:47 +00:00
header.from[0].to_string(),
header.subject.unwrap().to_string(),
);
// if you like to also parse the body/content
2023-07-24 16:10:44 +00:00
let (_, email) = eml_codec::email(input).unwrap();
2023-07-24 12:05:47 +00:00
println!(
"{} raw message is:\n{}",
2023-07-24 10:26:53 +00:00
email.imf.from[0].to_string(),
2023-07-24 12:05:47 +00:00
String::from_utf8_lossy(email.child.as_text().unwrap().body),
2023-07-24 09:17:47 +00:00
);
}