neo_email/errors.rs
1use std::fmt;
2
3use super::command::Commands;
4
5/// # SMTP Error
6///
7/// This enum represents the possible errors that can occur in the SMTP server.
8#[derive(Debug)]
9pub enum SMTPError {
10 /// # IO Error
11 ///
12 /// This error occurs when there is an IO error.
13 IoError(std::io::Error),
14 /// # Parse Error
15 ///
16 /// This error occurs when there is a parsing error.
17 ParseError(String),
18 /// # DKIM Error
19 ///
20 /// This error occurs when there is a DKIM error.
21 DKIMError(String),
22 /// # SPF Error
23 ///
24 /// This error occurs when there is a SPF error.
25 SPFError(String),
26 /// # DNS Error
27 ///
28 /// This error occurs when there is a DNS error.
29 DNSError(String),
30 /// # Unknown Command
31 ///
32 /// This error occurs when there is an unknown command.
33 UnknownCommand(Commands),
34 /// # Custom Error
35 ///
36 /// This error occurs when there is a custom error.
37 CustomError(String),
38}
39
40/// # Display implementation for SMTPError
41impl fmt::Display for SMTPError {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match self {
44 SMTPError::IoError(err) => write!(f, "IO Error: {}", err),
45 SMTPError::ParseError(err) => write!(f, "Parse Error: {}", err),
46 SMTPError::DKIMError(err) => write!(f, "DKIM Error: {}", err),
47 SMTPError::SPFError(err) => write!(f, "SPF Error: {}", err),
48 SMTPError::DNSError(err) => write!(f, "DNS Error: {}", err),
49 SMTPError::UnknownCommand(cmd) => write!(f, "Unknown Command: {:?}", cmd),
50 SMTPError::CustomError(msg) => write!(f, "Custom Error: {}", msg),
51 }
52 }
53}
54
55/// # Standard Error implementation for SMTPError
56impl std::error::Error for SMTPError {}