Function eml_codec::parse_imf

source ·
pub fn parse_imf(input: &[u8]) -> IResult<&[u8], Imf<'_>>
Expand description

Only extract the headers of the email that are part of the Internet Message Format spec

Emails headers contain MIME and IMF (Internet Message Format) headers. Sometimes you only need to know the recipient or the sender of an email, and are not interested in its content. In this case, you only need to parse the IMF fields and can ignore the MIME headers + the body. This is what this function does.

§Arguments

  • input - A buffer of bytes containing either only the headers of your email or your full email (in both cases, the body will be ignored)

§Returns

  • rest - The rest of the buffer, ie. the body of your email as raw bytes
  • imf - The parsed IMF headers of your email

§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 (_, imf) = eml_codec::parse_imf(input).unwrap();
println!(
    "{} just sent you an email with subject \"{}\"",
    imf.from[0].to_string(),
    imf.subject.unwrap().to_string(),
);