mda

Struct Email

Source
pub struct Email { /* private fields */ }
Expand description

A representation of an email.

Implementations§

Source§

impl Email

Source

pub fn filter(&self, cmd: &[&str]) -> Result<Email>

Filters the contents of the email using an external command, returning a new email with the filtered contents.

The command is expected to be provided as a &str array, with the first element being the command name and the remaining elements the command arguments.

§Example
use mda::Email;
let email = Email::from_stdin()?;
let email = email.filter(&["bogofilter", "-ep"])?;
Source

pub fn process(&self, cmd: &[&str]) -> Result<Output>

Process the contents of the email using an external command, returning a std::process::Output for the executed command.

The command is expected to be provided as a &str array, with the first element being the command name and the remaining elements the command arguments.

§Example
use mda::Email;
let email = Email::from_stdin()?;
let output = email.process(&["bogofilter"])?;
if let Some(0) = output.status.code() {
    email.deliver_to_maildir("/my/spam/path")?;
}
Source

pub fn from_stdin_filtered(cmd: &[&str]) -> Result<Self>

Creates an Email by filtering the contents from stdin.

This can be more efficient than creating an Email from stdin and filtering separately, since it can avoid an extra data copy.

The command is expected to be provided as a &str array, with the first element being the command name and the remaining elements the command arguments.

§Example
use mda::Email;
let email = Email::from_stdin_filtered(&["bogofilter", "-ep"])?;
Source§

impl Email

Source

pub fn from_stdin() -> Result<Self>

Creates an Email by reading data from stdin.

§Example
let email = Email::from_stdin()?;
Source

pub fn from_vec(data: Vec<u8>) -> Result<Self>

Creates an Email by using data passed in a Vec<u8>.

§Example
let email = Email::from_vec(vec![1, 2, 3])?;
Source

pub fn set_delivery_durability( &mut self, delivery_durability: DeliveryDurability, )

Sets the durability method for delivery of this email.

§Example
let mut email = Email::from_stdin()?;
email.set_delivery_durability(DeliveryDurability::FileSyncOnly);
Source

pub fn header_field(&self, name: &str) -> Option<&str>

Returns the value of a header field, if present. If a field occurs multiple times, the value of the first occurrence is returned.

§Example
let email = Email::from_stdin()?;
let to = email.header_field("To").unwrap_or("");
Source

pub fn header_field_all_occurrences(&self, name: &str) -> Option<&Vec<String>>

Returns the values from all occurrences of a header field, if present.

§Example
let email = Email::from_stdin()?;
if let Some(all_received) = email.header_field_all_occurrences("Received") {
    // process all_received
}
Source

pub fn deliver_to_maildir(&self, path: impl AsRef<Path>) -> Result<PathBuf>

Delivers the email to the specified maildir. If the maildir isn’t present it is created.

The first delivery of an email involves writing the email data to the target file, whereas subsequent deliveries try to use a hard link to the first delivery, falling back to a normal write if needed.

The email is delivered durably by syncing both the file and the associated directories (DeliveryDurability::FileAndDirSync), unless a different durability method is specified with set_delivery_durability.

§Example
let email = Email::from_stdin()?;
email.deliver_to_maildir("/path/to/maildir/")?;
Source

pub fn has_been_delivered(&self) -> bool

Returns whether the email has been delivered to at least one maildir.

§Example
let email = Email::from_stdin()?;
if !email.has_been_delivered() {
    email.deliver_to_maildir("/fallback/maildir/")?;
}
Source

pub fn data(&self) -> &[u8]

Provides access to the normalized email byte data.

Source

pub fn header(&self) -> &[u8]

Provides access to the normalized email header byte data.

Source

pub fn body(&self) -> &[u8]

Provides access to the normalized email body byte data.

Source

pub fn raw_data(&self) -> &[u8]

Provides access to the raw (non-normalized) email byte data.

Auto Trait Implementations§

§

impl !Freeze for Email

§

impl RefUnwindSafe for Email

§

impl Send for Email

§

impl Sync for Email

§

impl Unpin for Email

§

impl UnwindSafe for Email

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> 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.