postfix_log_parser/events/
local.rs1use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub enum LocalEvent {
12 ConfigurationWarning(ConfigurationWarning),
13 LocalDelivery(LocalDelivery),
14 ExternalDelivery(ExternalDelivery),
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct ConfigurationWarning {
22 pub timestamp: DateTime<Utc>,
24
25 pub warning_type: WarningType,
28
29 pub message: String,
32
33 pub details: HashMap<String, String>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
39pub enum WarningType {
40 NisDomainNotSet,
41 RequiredAliasNotFound,
42 FilePermission,
43 Configuration,
44 Other,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct LocalDelivery {
52 pub timestamp: DateTime<Utc>,
54
55 pub queue_id: String,
57
58 pub recipient: String,
61
62 pub original_recipient: Option<String>,
65
66 pub relay: String,
69
70 pub delay: f64,
73
74 pub delays: Vec<f64>,
77
78 pub dsn: String,
81
82 pub status: DeliveryStatus,
84
85 pub delivery_method: DeliveryMethod,
87
88 pub size: Option<u64>,
90
91 pub nrcpt: Option<u32>,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
96pub enum DeliveryStatus {
97 Sent,
98 Bounced,
99 Deferred,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
103pub enum DeliveryMethod {
104 Mailbox,
105 Discarded,
106 Forwarded,
107 Piped,
108 File,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct ExternalDelivery {
116 pub timestamp: DateTime<Utc>,
118
119 pub queue_id: String,
121
122 pub recipient: String,
124
125 pub original_recipient: Option<String>,
128
129 pub command: Option<String>,
132
133 pub file_path: Option<String>,
136
137 pub status: DeliveryStatus,
139
140 pub delay: f64,
143
144 pub details: HashMap<String, String>,
147}
148
149impl LocalEvent {
150 pub fn timestamp(&self) -> DateTime<Utc> {
151 match self {
152 LocalEvent::ConfigurationWarning(event) => event.timestamp,
153 LocalEvent::LocalDelivery(event) => event.timestamp,
154 LocalEvent::ExternalDelivery(event) => event.timestamp,
155 }
156 }
157
158 pub fn event_type(&self) -> &'static str {
159 match self {
160 LocalEvent::ConfigurationWarning(_) => "configuration_warning",
161 LocalEvent::LocalDelivery(_) => "local_delivery",
162 LocalEvent::ExternalDelivery(_) => "external_delivery",
163 }
164 }
165}
166
167impl WarningType {
168 pub fn as_str(&self) -> &'static str {
169 match self {
170 WarningType::NisDomainNotSet => "nis_domain_not_set",
171 WarningType::RequiredAliasNotFound => "required_alias_not_found",
172 WarningType::FilePermission => "file_permission",
173 WarningType::Configuration => "configuration",
174 WarningType::Other => "other",
175 }
176 }
177}
178
179impl DeliveryStatus {
180 pub fn as_str(&self) -> &'static str {
181 match self {
182 DeliveryStatus::Sent => "sent",
183 DeliveryStatus::Bounced => "bounced",
184 DeliveryStatus::Deferred => "deferred",
185 }
186 }
187}
188
189impl DeliveryMethod {
190 pub fn as_str(&self) -> &'static str {
191 match self {
192 DeliveryMethod::Mailbox => "mailbox",
193 DeliveryMethod::Discarded => "discarded",
194 DeliveryMethod::Forwarded => "forwarded",
195 DeliveryMethod::Piped => "piped",
196 DeliveryMethod::File => "file",
197 }
198 }
199}