use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CleanupEvent {
MessageId {
queue_id: String,
message_id: String,
},
QueueFileWarning {
operation: String, file_path: String, error_reason: String, },
MessageRewrite {
queue_id: String,
rewrite_type: String, original: String, rewritten: String, },
MessageSize {
queue_id: String,
size: u64, },
HeaderProcessing {
queue_id: String,
header_name: String, header_value: String, action: String, },
FilterAction {
queue_id: String,
filter_name: String, action: String, details: Option<String>, },
AddressRewrite {
queue_id: String,
address_type: String, original_address: String,
rewritten_address: String,
},
MessageReject {
queue_id: String,
reason: String, action: String, },
ResourceLimit {
resource_type: String, limit_details: String, current_value: Option<u64>,
limit_value: Option<u64>,
},
MilterInteraction {
queue_id: String,
milter_name: String, command: String, response: Option<String>, },
ConfigurationWarning {
warning_type: String, message: String, },
Statistics {
processed: Option<u32>, rejected: Option<u32>, errors: Option<u32>, },
SnowflakeInit {
node_id: u32, node_bits: u32, seq_bits: u32, },
MessageHold {
queue_id: String,
hold_reason: String, sender: Option<String>, recipient: Option<String>, client_ip: Option<String>, client_hostname: Option<String>, client_port: Option<u16>, protocol: Option<String>, helo: Option<String>, description: String, },
MessageDiscard {
queue_id: String,
discard_reason: String, sender: Option<String>, recipient: Option<String>, client_ip: Option<String>, client_hostname: Option<String>, client_port: Option<u16>, protocol: Option<String>, helo: Option<String>, description: String, },
MessageRemoved {
queue_id: String,
removal_reason: String, details: Option<String>, },
Other {
event_type: String,
message: String,
queue_id: Option<String>,
},
}
impl CleanupEvent {
pub fn event_type(&self) -> &'static str {
match self {
CleanupEvent::MessageId { .. } => "message_id",
CleanupEvent::QueueFileWarning { .. } => "queue_file_warning",
CleanupEvent::MessageRewrite { .. } => "message_rewrite",
CleanupEvent::MessageSize { .. } => "message_size",
CleanupEvent::HeaderProcessing { .. } => "header_processing",
CleanupEvent::FilterAction { .. } => "filter_action",
CleanupEvent::AddressRewrite { .. } => "address_rewrite",
CleanupEvent::MessageReject { .. } => "message_reject",
CleanupEvent::ResourceLimit { .. } => "resource_limit",
CleanupEvent::MilterInteraction { .. } => "milter_interaction",
CleanupEvent::ConfigurationWarning { .. } => "configuration_warning",
CleanupEvent::Statistics { .. } => "statistics",
CleanupEvent::SnowflakeInit { .. } => "snowflake_init",
CleanupEvent::MessageHold { .. } => "message_hold",
CleanupEvent::MessageDiscard { .. } => "message_discard",
CleanupEvent::MessageRemoved { .. } => "message_removed",
CleanupEvent::Other { .. } => "other",
}
}
pub fn queue_id(&self) -> Option<&str> {
match self {
CleanupEvent::MessageId { queue_id, .. } => Some(queue_id),
CleanupEvent::MessageRewrite { queue_id, .. } => Some(queue_id),
CleanupEvent::MessageSize { queue_id, .. } => Some(queue_id),
CleanupEvent::HeaderProcessing { queue_id, .. } => Some(queue_id),
CleanupEvent::FilterAction { queue_id, .. } => Some(queue_id),
CleanupEvent::AddressRewrite { queue_id, .. } => Some(queue_id),
CleanupEvent::MessageReject { queue_id, .. } => Some(queue_id),
CleanupEvent::MilterInteraction { queue_id, .. } => Some(queue_id),
CleanupEvent::MessageHold { queue_id, .. } => Some(queue_id),
CleanupEvent::MessageDiscard { queue_id, .. } => Some(queue_id),
CleanupEvent::MessageRemoved { queue_id, .. } => Some(queue_id),
CleanupEvent::Other { queue_id, .. } => queue_id.as_deref(),
_ => None,
}
}
pub fn is_error_event(&self) -> bool {
matches!(
self,
CleanupEvent::QueueFileWarning { .. }
| CleanupEvent::MessageReject { .. }
| CleanupEvent::ResourceLimit { .. }
)
}
pub fn is_warning_event(&self) -> bool {
matches!(
self,
CleanupEvent::QueueFileWarning { .. }
| CleanupEvent::ConfigurationWarning { .. }
| CleanupEvent::ResourceLimit { .. }
)
}
pub fn is_normal_event(&self) -> bool {
matches!(
self,
CleanupEvent::MessageId { .. }
| CleanupEvent::MessageSize { .. }
| CleanupEvent::HeaderProcessing { .. }
| CleanupEvent::FilterAction { .. }
| CleanupEvent::MessageDiscard { .. }
| CleanupEvent::MessageRemoved { .. }
| CleanupEvent::SnowflakeInit { .. }
)
}
}