1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/// Safe error categories. Raw SMTP responses/credentials/content are never retained.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MailError {
/// Invalid or unsafe configuration.
Configuration,
/// Invalid mailbox syntax.
Address,
/// Invalid header or control characters.
Header,
/// Invalid message structure.
Message,
/// Invalid attachment metadata or size.
Attachment,
/// Message exceeds configured bounds.
Size,
/// Template rendering failed.
Template,
/// Connection or protocol failure, conservatively retryable.
Connection,
/// Authentication rejected; operator action required.
Authentication,
/// TLS negotiation or certificate validation failed.
Tls,
/// SMTP temporary failure.
Temporary,
/// SMTP permanent failure.
Permanent,
/// Total send deadline expired; delivery may already have happened.
Timeout,
/// Test capture reached its explicit limit.
CaptureFull,
/// Private development inbox I/O, permissions or serialization failed.
CaptureStorage,
/// Queue persistence failed; commit status can be ambiguous.
Queue,
}
impl MailError {
/// Stable category for safe observability.
pub fn category(self) -> &'static str {
match self {
Self::Configuration => "configuration",
Self::Address => "address",
Self::Header => "header",
Self::Message => "message",
Self::Attachment => "attachment",
Self::Size => "size",
Self::Template => "template",
Self::Connection => "connection",
Self::Authentication => "authentication",
Self::Tls => "tls",
Self::Temporary => "temporary",
Self::Permanent => "permanent",
Self::Timeout => "timeout",
Self::CaptureFull => "capture_full",
Self::CaptureStorage => "capture_storage",
Self::Queue => "queue",
}
}
/// Only temporary/connection/deadline errors are automatically retryable by Jobs.
pub fn retryable(self) -> bool {
matches!(self, Self::Temporary | Self::Connection | Self::Timeout)
}
}
impl std::fmt::Display for MailError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Mail operation failed ({})", self.category())
}
}
impl std::error::Error for MailError {}
impl From<askama::Error> for MailError {
fn from(_: askama::Error) -> Self {
Self::Template
}
}
impl From<MailError> for capy_core::AppError {
fn from(error: MailError) -> Self {
Self::Internal(error.into())
}
}
impl From<MailError> for capy_core::EventError {
fn from(error: MailError) -> Self {
Self::Failure(capy_core::AppError::from(error))
}
}