postfix_log_parser/events/
smtpd.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub enum SmtpdEvent {
10 Connect {
12 client_ip: String,
13 client_hostname: String,
14 port: Option<u16>,
15 },
16 Disconnect {
18 client_ip: String,
19 client_hostname: String,
20 port: Option<u16>,
21 command_stats: Option<CommandStats>,
23 },
24 LostConnection {
26 client_ip: String,
27 client_hostname: String,
28 last_command: Option<String>,
30 },
31 Timeout {
33 client_ip: String,
34 client_hostname: String,
35 last_command: Option<String>,
37 },
38 ClientAssignment {
40 queue_id: String,
41 client_ip: String,
42 client_hostname: String,
43 port: Option<u16>,
44 },
45 Auth {
47 method: String,
48 username: String,
49 success: bool,
51 failure_reason: Option<String>,
53 },
54 Reject {
56 reason: String,
57 code: Option<u16>,
58 reject_type: RejectType,
60 from: Option<String>,
62 to: Option<String>,
64 client_ip: Option<String>,
66 client_hostname: Option<String>,
67 },
68 NoQueueFilter {
70 client_ip: String,
71 client_hostname: String,
72 filter_info: String,
73 filter_target: String,
75 },
76 Helo {
78 hostname: String,
79 client_ip: Option<String>,
80 client_hostname: Option<String>,
81 },
82 Accept {
84 from: Option<String>,
85 to: Vec<String>,
86 size: Option<u64>,
87 queue_id: Option<String>,
88 },
89 ProtocolViolation {
91 client_ip: String,
92 client_hostname: String,
93 violation_type: String,
94 details: String,
95 },
96 SystemWarning {
98 warning_type: String,
99 message: String,
100 client_info: Option<ClientInfo>,
101 },
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct CommandStats {
109 pub ehlo: Option<u32>,
111
112 pub helo: Option<u32>,
114
115 pub mail: Option<u32>,
117
118 pub rcpt: Option<u32>,
120
121 pub data: Option<u32>,
123
124 pub bdat: Option<u32>,
126
127 pub quit: Option<u32>,
129
130 pub commands: Option<u32>,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
136pub enum RejectType {
137 NoQueue,
139 Queued,
141 Unknown,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
149pub struct ClientInfo {
150 pub ip: String,
152
153 pub hostname: String,
156
157 pub port: Option<u16>,
160}
161
162impl SmtpdEvent {
163 pub fn event_type(&self) -> &'static str {
164 match self {
165 SmtpdEvent::Connect { .. } => "connect",
166 SmtpdEvent::Disconnect { .. } => "disconnect",
167 SmtpdEvent::LostConnection { .. } => "lost_connection",
168 SmtpdEvent::Timeout { .. } => "timeout",
169 SmtpdEvent::ClientAssignment { .. } => "client_assignment",
170 SmtpdEvent::Auth { .. } => "auth",
171 SmtpdEvent::Reject { .. } => "reject",
172 SmtpdEvent::NoQueueFilter { .. } => "noqueue_filter",
173 SmtpdEvent::Helo { .. } => "helo",
174 SmtpdEvent::Accept { .. } => "accept",
175 SmtpdEvent::ProtocolViolation { .. } => "protocol_violation",
176 SmtpdEvent::SystemWarning { .. } => "system_warning",
177 }
178 }
179
180 pub fn queue_id(&self) -> Option<&str> {
182 match self {
183 SmtpdEvent::ClientAssignment { queue_id, .. } => Some(queue_id),
184 SmtpdEvent::Accept { queue_id, .. } => queue_id.as_deref(),
185 _ => None,
186 }
187 }
188}