Struct EmlParser

Source
pub struct EmlParser { /* private fields */ }

Implementations§

Source§

impl EmlParser

Source

pub fn from_file(filename: impl AsRef<Path>) -> Result<Self, EmlError>

Read an .eml file from disk, parsing its contents. Note that the current implementation loads the entire file to memory since std::fs::File doesn’t provide an iterator over char that could give a Peekable.

Examples found in repository?
examples/parse.rs (line 5)
4fn main() -> Result<(), EmlError> {
5    let mut eml = EmlParser::from_file("test_emails/0.eml")?;
6    if let Ok(parsed) = eml.parse() {
7        println!("{:?}", parsed.to);
8    } else {
9        println!("Failed to parse");
10    }
11    println!();
12
13    let mut eml = EmlParser::from_file("test_emails/1.eml")?;
14    if let Ok(parsed) = eml.parse() {
15        println!("{:?}", parsed.to);
16    } else {
17        println!("Failed to parse");
18    }
19
20    Ok(())
21}
Source

pub fn from_string(content: String) -> Self

Source

pub fn ignore_body(self) -> Self

Source

pub fn with_body(self) -> Self

Source

pub fn with_body_preview(self, bytes: usize) -> Self

Source

pub fn parse(&mut self) -> Result<Eml, EmlError>

Examples found in repository?
examples/parse.rs (line 6)
4fn main() -> Result<(), EmlError> {
5    let mut eml = EmlParser::from_file("test_emails/0.eml")?;
6    if let Ok(parsed) = eml.parse() {
7        println!("{:?}", parsed.to);
8    } else {
9        println!("Failed to parse");
10    }
11    println!();
12
13    let mut eml = EmlParser::from_file("test_emails/1.eml")?;
14    if let Ok(parsed) = eml.parse() {
15        println!("{:?}", parsed.to);
16    } else {
17        println!("Failed to parse");
18    }
19
20    Ok(())
21}

Trait Implementations§

Source§

impl Debug for EmlParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.