Add Mailuser type; Use Mailuser instead of String and Host in Request to represent the sender;
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use {
|
|
crate::prelude::{ParseHostError, ParseMailboxError},
|
|
std::fmt,
|
|
};
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
/// Errors which can occur when parsing a request
|
|
pub enum Error {
|
|
MissingSeparator,
|
|
EmptyUser,
|
|
EmptyHost,
|
|
EmptyMessage,
|
|
Malformed,
|
|
ParseHostError(ParseHostError),
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::ParseHostError(e) => write!(f, "{e}"),
|
|
_ => write!(f, "{self:?}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for Error {
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
match self {
|
|
Self::ParseHostError(e) => Some(e),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<ParseMailboxError> for Error {
|
|
fn from(value: ParseMailboxError) -> Self {
|
|
match value {
|
|
ParseMailboxError::ParseHostError(e) => Self::ParseHostError(e),
|
|
ParseMailboxError::EmptyUser => Self::EmptyUser,
|
|
ParseMailboxError::EmptyHost => Self::EmptyHost,
|
|
ParseMailboxError::IllegalWhitespace => Self::Malformed,
|
|
ParseMailboxError::MissingSeparator => Self::MissingSeparator,
|
|
}
|
|
}
|
|
}
|