#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum Subject {
#[default]
Clean,
Keep,
KeepNonPatch,
}
#[derive(Clone, Copy, Debug, Default)]
#[non_exhaustive]
pub struct Options {
pub subject: Subject,
pub scissors: bool,
pub message_id: bool,
}
impl Options {
#[must_use]
pub fn with_subject(mut self, value: Subject) -> Self {
self.subject = value;
self
}
#[must_use]
pub fn with_scissors(mut self, value: bool) -> Self {
self.scissors = value;
self
}
#[must_use]
pub fn with_message_id(mut self, value: bool) -> Self {
self.message_id = value;
self
}
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct Limits {
pub max_input_bytes: usize,
pub max_header_bytes: usize,
pub max_headers: usize,
pub max_decoded_bytes: usize,
pub max_mime_parts: usize,
pub max_mime_depth: usize,
pub max_message_bytes: usize,
pub max_patch_bytes: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
max_input_bytes: 64 << 20,
max_header_bytes: 1 << 20,
max_headers: 1000,
max_decoded_bytes: 64 << 20,
max_mime_parts: 1000,
max_mime_depth: 8,
max_message_bytes: 16 << 20,
max_patch_bytes: 64 << 20,
}
}
}
impl Limits {
#[must_use]
pub fn with_max_input_bytes(mut self, value: usize) -> Self {
self.max_input_bytes = value;
self
}
#[must_use]
pub fn with_max_header_bytes(mut self, value: usize) -> Self {
self.max_header_bytes = value;
self
}
#[must_use]
pub fn with_max_headers(mut self, value: usize) -> Self {
self.max_headers = value;
self
}
#[must_use]
pub fn with_max_decoded_bytes(mut self, value: usize) -> Self {
self.max_decoded_bytes = value;
self
}
#[must_use]
pub fn with_max_mime_parts(mut self, value: usize) -> Self {
self.max_mime_parts = value;
self
}
#[must_use]
pub fn with_max_mime_depth(mut self, value: usize) -> Self {
self.max_mime_depth = value;
self
}
#[must_use]
pub fn with_max_message_bytes(mut self, value: usize) -> Self {
self.max_message_bytes = value;
self
}
#[must_use]
pub fn with_max_patch_bytes(mut self, value: usize) -> Self {
self.max_patch_bytes = value;
self
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Message {
pub author: Option<String>,
pub email: Option<String>,
pub subject: Option<String>,
pub date: Option<String>,
pub message_id: Option<String>,
pub message: Vec<u8>,
pub patch: Vec<u8>,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("patch mail exceeds {0} limit")]
Limit(&'static str),
#[error("unsupported patch mail {0}")]
Unsupported(&'static str),
#[error("invalid patch mail {0}")]
Malformed(&'static str),
#[error("patch mail extraction cancelled")]
Cancelled,
}