pub struct Email { /* private fields */ }
Expand description
A representation of an email.
Implementations§
Source§impl Email
impl Email
Sourcepub fn filter(&self, cmd: &[&str]) -> Result<Email>
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"])?;
Sourcepub fn process(&self, cmd: &[&str]) -> Result<Output>
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")?;
}
Sourcepub fn from_stdin_filtered(cmd: &[&str]) -> Result<Self>
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
impl Email
Sourcepub fn from_stdin() -> Result<Self>
pub fn from_stdin() -> Result<Self>
Sourcepub fn from_vec(data: Vec<u8>) -> Result<Self>
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])?;
Sourcepub fn set_delivery_durability(
&mut self,
delivery_durability: DeliveryDurability,
)
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);
Sourcepub fn header_field(&self, name: &str) -> Option<&str>
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("");
Sourcepub fn header_field_all_occurrences(&self, name: &str) -> Option<&Vec<String>>
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
}
Sourcepub fn deliver_to_maildir(&self, path: impl AsRef<Path>) -> Result<PathBuf>
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/")?;
Sourcepub fn has_been_delivered(&self) -> bool
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/")?;
}