Function eml_codec::parse_message
source · pub fn parse_message(input: &[u8]) -> IResult<&[u8], Message<'_>>
Expand description
Parse a whole email including its (MIME) body
Returns the parsed content, but also the remaining bytes if the parser stopped before arriving to the end (for example due to a multipart delimiter).
§Arguments
input
- A buffer of bytes containing your full email
§Returns
rest
- The rest of the buffer, the part that is not parsed as the email ended before the end of the datamsg
- The parsed message
§Examples
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."#;
let (_, email) = eml_codec::parse_message(input).unwrap();
println!(
"{} raw message is:\n{}",
email.imf.from[0].to_string(),
String::from_utf8_lossy(email.child.as_text().unwrap().body),
);