postfix_log_parser/events/
smtp.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub enum SmtpEvent {
10 Sent {
12 queue_id: String,
13 to: String,
14 relay_hostname: String,
15 relay_ip: Option<String>,
16 relay_port: Option<u16>,
17 delay: f64,
18 delay_before_queue: Option<f64>,
19 delay_in_queue: Option<f64>,
20 delay_connection: Option<f64>,
21 delay_transmission: Option<f64>,
22 dsn: Option<String>,
23 status: String,
24 message_size: Option<u64>,
25 },
26 Deferred {
28 queue_id: String,
29 to: Option<String>,
30 relay_hostname: Option<String>,
31 relay_ip: Option<String>,
32 relay_port: Option<u16>,
33 delay: Option<f64>,
34 delay_before_queue: Option<f64>,
35 delay_in_queue: Option<f64>,
36 delay_connection: Option<f64>,
37 delay_transmission: Option<f64>,
38 dsn: Option<String>,
39 status: String,
40 defer_reason: String,
41 },
42 Bounced {
44 queue_id: String,
45 to: String,
46 relay_hostname: Option<String>,
47 relay_ip: Option<String>,
48 relay_port: Option<u16>,
49 delay: Option<f64>,
50 delay_before_queue: Option<f64>,
51 delay_in_queue: Option<f64>,
52 delay_connection: Option<f64>,
53 delay_transmission: Option<f64>,
54 dsn: Option<String>,
55 status: String,
56 bounce_reason: String,
57 },
58 ConnectionTimeout {
60 queue_id: String,
61 target_hostname: String,
62 target_ip: String,
63 target_port: u16,
64 timeout_duration: Option<u32>,
65 },
66 ConnectionRefused {
68 queue_id: String,
69 target_hostname: String,
70 target_ip: String,
71 target_port: u16,
72 },
73 ConnectionLost {
75 queue_id: String,
76 target_hostname: String,
77 target_ip: String,
78 lost_stage: String,
79 },
80 ProtocolInteraction {
82 queue_id: String,
83 interaction_type: String,
84 details: String,
85 },
86 Other {
88 queue_id: Option<String>,
89 event_type: String,
90 message: String,
91 },
92}
93
94impl SmtpEvent {
95 pub fn event_type(&self) -> &'static str {
96 match self {
97 SmtpEvent::Sent { .. } => "sent",
98 SmtpEvent::Deferred { .. } => "deferred",
99 SmtpEvent::Bounced { .. } => "bounced",
100 SmtpEvent::ConnectionTimeout { .. } => "connection_timeout",
101 SmtpEvent::ConnectionRefused { .. } => "connection_refused",
102 SmtpEvent::ConnectionLost { .. } => "connection_lost",
103 SmtpEvent::ProtocolInteraction { .. } => "protocol_interaction",
104 SmtpEvent::Other { .. } => "other",
105 }
106 }
107
108 pub fn queue_id(&self) -> Option<&str> {
109 match self {
110 SmtpEvent::Sent { queue_id, .. } => Some(queue_id),
111 SmtpEvent::Deferred { queue_id, .. } => Some(queue_id),
112 SmtpEvent::Bounced { queue_id, .. } => Some(queue_id),
113 SmtpEvent::ConnectionTimeout { queue_id, .. } => Some(queue_id),
114 SmtpEvent::ConnectionRefused { queue_id, .. } => Some(queue_id),
115 SmtpEvent::ConnectionLost { queue_id, .. } => Some(queue_id),
116 SmtpEvent::ProtocolInteraction { queue_id, .. } => Some(queue_id),
117 SmtpEvent::Other { queue_id, .. } => queue_id.as_deref(),
118 }
119 }
120}