use crate::events::cleanup::CleanupEvent;
use serde_json::{json, Value};
pub fn format_cleanup_event(event: &CleanupEvent) -> Value {
match event {
CleanupEvent::MessageId {
queue_id,
message_id,
} => {
json!({
"event_type": "message_id",
"queue_id": queue_id,
"message_id": message_id,
"description": "邮件Message-ID处理"
})
}
CleanupEvent::QueueFileWarning {
operation,
file_path,
error_reason,
} => {
json!({
"event_type": "queue_file_warning",
"operation": operation,
"file_path": file_path,
"error_reason": error_reason,
"severity": "warning",
"description": "队列文件操作警告"
})
}
CleanupEvent::MessageSize { queue_id, size } => {
json!({
"event_type": "message_size",
"queue_id": queue_id,
"size": size,
"size_mb": *size as f64 / 1024.0 / 1024.0,
"description": "邮件大小信息"
})
}
CleanupEvent::HeaderProcessing {
queue_id,
header_name,
header_value,
action,
} => {
json!({
"event_type": "header_processing",
"queue_id": queue_id,
"header_name": header_name,
"header_value": header_value,
"action": action,
"description": "邮件头处理"
})
}
CleanupEvent::FilterAction {
queue_id,
filter_name,
action,
details,
} => {
json!({
"event_type": "filter_action",
"queue_id": queue_id,
"filter_name": filter_name,
"action": action,
"details": details,
"description": "邮件过滤器处理"
})
}
CleanupEvent::AddressRewrite {
queue_id,
address_type,
original_address,
rewritten_address,
} => {
json!({
"event_type": "address_rewrite",
"queue_id": queue_id,
"address_type": address_type,
"original_address": original_address,
"rewritten_address": rewritten_address,
"description": "地址重写"
})
}
CleanupEvent::MessageRewrite {
queue_id,
rewrite_type,
original,
rewritten,
} => {
json!({
"event_type": "message_rewrite",
"queue_id": queue_id,
"rewrite_type": rewrite_type,
"original": original,
"rewritten": rewritten,
"description": "邮件内容重写"
})
}
CleanupEvent::MessageReject {
queue_id,
reason,
action,
} => {
json!({
"event_type": "message_reject",
"queue_id": queue_id,
"reason": reason,
"action": action,
"severity": "error",
"description": "邮件拒绝"
})
}
CleanupEvent::ResourceLimit {
resource_type,
limit_details,
current_value,
limit_value,
} => {
json!({
"event_type": "resource_limit",
"resource_type": resource_type,
"limit_details": limit_details,
"current_value": current_value,
"limit_value": limit_value,
"severity": "warning",
"description": "资源限制警告"
})
}
CleanupEvent::MilterInteraction {
queue_id,
milter_name,
command,
response,
} => {
json!({
"event_type": "milter_interaction",
"queue_id": queue_id,
"milter_name": milter_name,
"command": command,
"response": response,
"description": "Milter交互"
})
}
CleanupEvent::ConfigurationWarning {
warning_type,
message,
} => {
json!({
"event_type": "configuration_warning",
"warning_type": warning_type,
"message": message,
"severity": "warning",
"description": "配置警告"
})
}
CleanupEvent::Statistics {
processed,
rejected,
errors,
} => {
json!({
"event_type": "statistics",
"processed": processed,
"rejected": rejected,
"errors": errors,
"description": "Cleanup处理统计"
})
}
CleanupEvent::SnowflakeInit {
node_id,
node_bits,
seq_bits,
} => {
json!({
"event_type": "snowflake_init",
"node_id": node_id,
"node_bits": node_bits,
"seq_bits": seq_bits,
"description": "Snowflake ID生成器初始化"
})
}
CleanupEvent::MessageHold {
queue_id,
hold_reason,
sender,
recipient,
client_ip,
client_hostname,
client_port,
protocol,
helo,
description,
} => {
json!({
"event_type": "message_hold",
"queue_id": queue_id,
"hold_reason": hold_reason,
"sender": sender,
"recipient": recipient,
"client_ip": client_ip,
"client_hostname": client_hostname,
"client_port": client_port,
"protocol": protocol,
"helo": helo,
"description": description,
"severity": "warning"
})
}
CleanupEvent::MessageDiscard {
queue_id,
discard_reason,
sender,
recipient,
client_ip,
client_hostname,
client_port,
protocol,
helo,
description,
} => {
json!({
"event_type": "discarded",
"queue_id": queue_id,
"discard_reason": discard_reason,
"sender": sender,
"recipient": recipient,
"client_ip": client_ip,
"client_hostname": client_hostname,
"client_port": client_port,
"protocol": protocol,
"helo": helo,
"description": description,
"severity": "info"
})
}
CleanupEvent::MessageRemoved {
queue_id,
removal_reason,
details,
} => {
json!({
"event_type": "message_removed",
"queue_id": queue_id,
"removal_reason": removal_reason,
"details": details,
"description": "邮件从队列中移除"
})
}
CleanupEvent::Other {
event_type,
message,
queue_id,
} => {
json!({
"event_type": "other",
"sub_type": event_type,
"message": message,
"queue_id": queue_id,
"description": "其他Cleanup事件"
})
}
}
}