Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use common::config::smtp::report::AggregateFrequency;
|
||||
use mail_parser::DateTime;
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub mod analysis;
|
||||
pub mod dkim;
|
||||
pub mod dmarc;
|
||||
pub mod inbound;
|
||||
pub mod index;
|
||||
pub mod scheduler;
|
||||
pub mod send;
|
||||
pub mod spf;
|
||||
pub mod tls;
|
||||
|
||||
pub trait AggregateTimestamp {
|
||||
fn to_timestamp(&self) -> u64;
|
||||
fn to_timestamp_(&self, dt: DateTime) -> u64;
|
||||
fn as_secs(&self) -> u64;
|
||||
fn due(&self) -> u64;
|
||||
}
|
||||
|
||||
impl AggregateTimestamp for AggregateFrequency {
|
||||
fn to_timestamp(&self) -> u64 {
|
||||
self.to_timestamp_(DateTime::from_timestamp(
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.map_or(0, |d| d.as_secs()) as i64,
|
||||
))
|
||||
}
|
||||
|
||||
fn to_timestamp_(&self, mut dt: DateTime) -> u64 {
|
||||
(match self {
|
||||
AggregateFrequency::Hourly => {
|
||||
dt.minute = 0;
|
||||
dt.second = 0;
|
||||
dt.to_timestamp()
|
||||
}
|
||||
AggregateFrequency::Daily => {
|
||||
dt.hour = 0;
|
||||
dt.minute = 0;
|
||||
dt.second = 0;
|
||||
dt.to_timestamp()
|
||||
}
|
||||
AggregateFrequency::Weekly => {
|
||||
let dow = dt.day_of_week();
|
||||
dt.hour = 0;
|
||||
dt.minute = 0;
|
||||
dt.second = 0;
|
||||
dt.to_timestamp() - (86400 * dow as i64)
|
||||
}
|
||||
AggregateFrequency::Never => dt.to_timestamp(),
|
||||
}) as u64
|
||||
}
|
||||
|
||||
fn as_secs(&self) -> u64 {
|
||||
match self {
|
||||
AggregateFrequency::Hourly => 3600,
|
||||
AggregateFrequency::Daily => 86400,
|
||||
AggregateFrequency::Weekly => 7 * 86400,
|
||||
AggregateFrequency::Never => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn due(&self) -> u64 {
|
||||
self.to_timestamp() + self.as_secs()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user