1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum MailError {
4 Configuration,
6 Address,
8 Header,
10 Message,
12 Attachment,
14 Size,
16 Template,
18 Connection,
20 Authentication,
22 Tls,
24 Temporary,
26 Permanent,
28 Timeout,
30 CaptureFull,
32 CaptureStorage,
34 Queue,
36}
37impl MailError {
38 pub fn category(self) -> &'static str {
40 match self {
41 Self::Configuration => "configuration",
42 Self::Address => "address",
43 Self::Header => "header",
44 Self::Message => "message",
45 Self::Attachment => "attachment",
46 Self::Size => "size",
47 Self::Template => "template",
48 Self::Connection => "connection",
49 Self::Authentication => "authentication",
50 Self::Tls => "tls",
51 Self::Temporary => "temporary",
52 Self::Permanent => "permanent",
53 Self::Timeout => "timeout",
54 Self::CaptureFull => "capture_full",
55 Self::CaptureStorage => "capture_storage",
56 Self::Queue => "queue",
57 }
58 }
59 pub fn retryable(self) -> bool {
61 matches!(self, Self::Temporary | Self::Connection | Self::Timeout)
62 }
63}
64impl std::fmt::Display for MailError {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 write!(f, "Mail operation failed ({})", self.category())
67 }
68}
69impl std::error::Error for MailError {}
70impl From<askama::Error> for MailError {
71 fn from(_: askama::Error) -> Self {
72 Self::Template
73 }
74}
75impl From<MailError> for capy_core::AppError {
76 fn from(error: MailError) -> Self {
77 Self::Internal(error.into())
78 }
79}
80
81impl From<MailError> for capy_core::EventError {
82 fn from(error: MailError) -> Self {
83 Self::Failure(capy_core::AppError::from(error))
84 }
85}