Scheduled reports: Download, a report for a period as a ZIP
inbuxa:ReportExport/set creates {reportId, from?, to?}: the report built
for that period (its last full one by default, at most 90 days back, as
far as metrics are kept) as a ZIP of summary.txt and the section CSVs,
stored as an upload, mailing nobody. Reading needs sysScheduledReportGet,
as seeing the report does; a tenant administrator downloads only their
own; every download is in the audit log. A download doesn't move the
deliverability baseline the next mail compares with.
This commit is contained in:
1 parent
ff5480cb55
commit
09ccad4b4b
16 files changed
+494
-3
No files matched your search
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
//! `inbuxa:ReportExport/set` under `urn:inbuxa:jmap`: a scheduled report
|
||||
//! for a period as a ZIP of a summary and CSVs, without mailing anyone
|
||||
//! (scheduled-reports spec, RP-19). Exports aren't kept; `/get` finds none.
|
||||
|
||||
use crate::object::{AnyId, JmapObject, JmapObjectId};
|
||||
use jmap_tools::{Element, Key, Property};
|
||||
use std::{borrow::Cow, str::FromStr};
|
||||
use types::id::Id;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ReportExport;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum ReportExportProperty {
|
||||
Id,
|
||||
ReportId,
|
||||
From,
|
||||
To,
|
||||
BlobId,
|
||||
Size,
|
||||
Sha256,
|
||||
Files,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum ReportExportValue {
|
||||
Id(Id),
|
||||
}
|
||||
|
||||
impl Property for ReportExportProperty {
|
||||
fn try_parse(parent: Option<&Key<'_, Self>>, value: &str) -> Option<Self> {
|
||||
// Keys inside the lists stay plain keys
|
||||
match parent {
|
||||
None => ReportExportProperty::parse(value),
|
||||
Some(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_cow(&self) -> Cow<'static, str> {
|
||||
match self {
|
||||
ReportExportProperty::Id => "id",
|
||||
ReportExportProperty::ReportId => "reportId",
|
||||
ReportExportProperty::From => "from",
|
||||
ReportExportProperty::To => "to",
|
||||
ReportExportProperty::BlobId => "blobId",
|
||||
ReportExportProperty::Size => "size",
|
||||
ReportExportProperty::Sha256 => "sha256",
|
||||
ReportExportProperty::Files => "files",
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ReportExportProperty {
|
||||
fn parse(value: &str) -> Option<Self> {
|
||||
hashify::tiny_map!(value.as_bytes(),
|
||||
b"id" => ReportExportProperty::Id,
|
||||
b"reportId" => ReportExportProperty::ReportId,
|
||||
b"from" => ReportExportProperty::From,
|
||||
b"to" => ReportExportProperty::To,
|
||||
b"blobId" => ReportExportProperty::BlobId,
|
||||
b"size" => ReportExportProperty::Size,
|
||||
b"sha256" => ReportExportProperty::Sha256,
|
||||
b"files" => ReportExportProperty::Files,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for ReportExportProperty {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
ReportExportProperty::parse(s).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for ReportExportValue {
|
||||
type Property = ReportExportProperty;
|
||||
|
||||
fn try_parse<P>(key: &Key<'_, Self::Property>, value: &str) -> Option<Self> {
|
||||
match key {
|
||||
Key::Property(ReportExportProperty::Id) => {
|
||||
Id::from_str(value).ok().map(ReportExportValue::Id)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_cow(&self) -> Cow<'static, str> {
|
||||
match self {
|
||||
ReportExportValue::Id(id) => id.to_string().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl JmapObject for ReportExport {
|
||||
type Property = ReportExportProperty;
|
||||
|
||||
type Element = ReportExportValue;
|
||||
|
||||
type Id = Id;
|
||||
|
||||
type Filter = ();
|
||||
|
||||
type Comparator = ();
|
||||
|
||||
type GetArguments = ();
|
||||
|
||||
type SetArguments<'de> = ();
|
||||
|
||||
type QueryArguments = ();
|
||||
|
||||
type CopyArguments = ();
|
||||
|
||||
type ParseArguments = ();
|
||||
|
||||
const ID_PROPERTY: Self::Property = ReportExportProperty::Id;
|
||||
}
|
||||
|
||||
impl From<Id> for ReportExportValue {
|
||||
fn from(id: Id) -> Self {
|
||||
ReportExportValue::Id(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl JmapObjectId for ReportExportValue {
|
||||
fn as_id(&self) -> Option<Id> {
|
||||
match self {
|
||||
ReportExportValue::Id(id) => Some(*id),
|
||||
}
|
||||
}
|
||||
|
||||
fn as_any_id(&self) -> Option<AnyId> {
|
||||
match self {
|
||||
ReportExportValue::Id(id) => Some(AnyId::Id(*id)),
|
||||
}
|
||||
}
|
||||
|
||||
fn as_id_ref(&self) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn try_set_id(&mut self, new_id: AnyId) -> bool {
|
||||
if let AnyId::Id(id) = new_id {
|
||||
*self = ReportExportValue::Id(id);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl JmapObjectId for ReportExportProperty {
|
||||
fn as_id(&self) -> Option<Id> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_any_id(&self) -> Option<AnyId> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_id_ref(&self) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn try_set_id(&mut self, _: AnyId) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ pub mod inbuxa_mail_rule; // inbuxa: DLP and mail flow rules
|
||||
pub mod inbuxa_security_acceptance; // inbuxa: accepted security to-do items
|
||||
pub mod inbuxa_deliverability_report; // inbuxa: the deliverability check
|
||||
pub mod inbuxa_deliverability_settings; // inbuxa: the deliverability check
|
||||
pub mod inbuxa_report_export; // inbuxa: scheduled reports, RP-19
|
||||
pub mod inbuxa_scheduled_report; // inbuxa: scheduled reports
|
||||
pub mod inbuxa_scheduled_report_settings; // inbuxa: scheduled reports
|
||||
pub mod inbuxa_journal; // inbuxa: journaling
|
||||
|
||||
@@ -97,6 +97,9 @@ impl Response<'_> {
|
||||
GetResponseMethod::DeliverabilitySettings(response) => {
|
||||
response.eval_jptr(path, &mut results)
|
||||
}
|
||||
GetResponseMethod::ReportExport(response) => {
|
||||
response.eval_jptr(path, &mut results)
|
||||
}
|
||||
GetResponseMethod::ScheduledReport(response) => {
|
||||
response.eval_jptr(path, &mut results)
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ impl Response<'_> {
|
||||
GetRequestMethod::SecurityAcceptance(request) => request.resolve_references(self)?,
|
||||
GetRequestMethod::DeliverabilityReport(request) => request.resolve_references(self)?,
|
||||
GetRequestMethod::DeliverabilitySettings(request) => request.resolve_references(self)?,
|
||||
GetRequestMethod::ReportExport(request) => request.resolve_references(self)?,
|
||||
GetRequestMethod::ScheduledReport(request) => request.resolve_references(self)?,
|
||||
GetRequestMethod::ScheduledReportSettings(request) => request.resolve_references(self)?,
|
||||
GetRequestMethod::Journal(request) => request.resolve_references(self)?,
|
||||
@@ -150,6 +151,9 @@ impl Response<'_> {
|
||||
SetRequestMethod::DeliverabilitySettings(request) => {
|
||||
request.resolve_references(self, 1, false)?
|
||||
}
|
||||
SetRequestMethod::ReportExport(request) => {
|
||||
request.resolve_references(self, 1, false)?
|
||||
}
|
||||
SetRequestMethod::ScheduledReport(request) => {
|
||||
request.resolve_references(self, 1, false)?
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ pub enum MethodObject {
|
||||
// inbuxa: the deliverability check
|
||||
DeliverabilityReport,
|
||||
DeliverabilitySettings,
|
||||
ReportExport,
|
||||
ScheduledReport,
|
||||
ScheduledReportSettings,
|
||||
HeldMessage,
|
||||
@@ -126,6 +127,7 @@ impl MethodObject {
|
||||
| MethodObject::HeldMessage
|
||||
| MethodObject::DeliverabilityReport
|
||||
| MethodObject::DeliverabilitySettings
|
||||
| MethodObject::ReportExport
|
||||
| MethodObject::ScheduledReport
|
||||
| MethodObject::ScheduledReportSettings
|
||||
| MethodObject::Journal
|
||||
@@ -336,6 +338,8 @@ impl MethodName {
|
||||
(MethodFunction::Set, MethodObject::DeliverabilityReport) => "inbuxa:DeliverabilityReport/set",
|
||||
(MethodFunction::Get, MethodObject::DeliverabilitySettings) => "inbuxa:DeliverabilitySettings/get",
|
||||
(MethodFunction::Set, MethodObject::DeliverabilitySettings) => "inbuxa:DeliverabilitySettings/set",
|
||||
(MethodFunction::Get, MethodObject::ReportExport) => "inbuxa:ReportExport/get",
|
||||
(MethodFunction::Set, MethodObject::ReportExport) => "inbuxa:ReportExport/set",
|
||||
(MethodFunction::Get, MethodObject::ScheduledReport) => "inbuxa:ScheduledReport/get",
|
||||
(MethodFunction::Set, MethodObject::ScheduledReport) => "inbuxa:ScheduledReport/set",
|
||||
(MethodFunction::Get, MethodObject::ScheduledReportSettings) => "inbuxa:ScheduledReportSettings/get",
|
||||
@@ -518,6 +522,8 @@ impl MethodName {
|
||||
"inbuxa:DeliverabilityReport/set" => (MethodObject::DeliverabilityReport, MethodFunction::Set),
|
||||
"inbuxa:DeliverabilitySettings/get" => (MethodObject::DeliverabilitySettings, MethodFunction::Get),
|
||||
"inbuxa:DeliverabilitySettings/set" => (MethodObject::DeliverabilitySettings, MethodFunction::Set),
|
||||
"inbuxa:ReportExport/get" => (MethodObject::ReportExport, MethodFunction::Get),
|
||||
"inbuxa:ReportExport/set" => (MethodObject::ReportExport, MethodFunction::Set),
|
||||
"inbuxa:ScheduledReport/get" => (MethodObject::ScheduledReport, MethodFunction::Get),
|
||||
"inbuxa:ScheduledReport/set" => (MethodObject::ScheduledReport, MethodFunction::Set),
|
||||
"inbuxa:ScheduledReportSettings/get" => (MethodObject::ScheduledReportSettings, MethodFunction::Get),
|
||||
@@ -607,6 +613,7 @@ impl Display for MethodObject {
|
||||
MethodObject::SecurityAcceptance => "inbuxa:SecurityAcceptance",
|
||||
MethodObject::DeliverabilityReport => "inbuxa:DeliverabilityReport",
|
||||
MethodObject::DeliverabilitySettings => "inbuxa:DeliverabilitySettings",
|
||||
MethodObject::ReportExport => "inbuxa:ReportExport",
|
||||
MethodObject::ScheduledReport => "inbuxa:ScheduledReport",
|
||||
MethodObject::ScheduledReportSettings => "inbuxa:ScheduledReportSettings",
|
||||
MethodObject::Journal => "inbuxa:Journal",
|
||||
|
||||
@@ -128,6 +128,7 @@ pub enum GetRequestMethod {
|
||||
SecurityAcceptance(Box<GetRequest<crate::object::inbuxa_security_acceptance::SecurityAcceptance>>),
|
||||
DeliverabilityReport(Box<GetRequest<crate::object::inbuxa_deliverability_report::DeliverabilityReport>>),
|
||||
DeliverabilitySettings(Box<GetRequest<crate::object::inbuxa_deliverability_settings::DeliverabilitySettings>>),
|
||||
ReportExport(Box<GetRequest<crate::object::inbuxa_report_export::ReportExport>>),
|
||||
ScheduledReport(Box<GetRequest<crate::object::inbuxa_scheduled_report::ScheduledReport>>),
|
||||
ScheduledReportSettings(Box<GetRequest<crate::object::inbuxa_scheduled_report_settings::ScheduledReportSettings>>),
|
||||
Journal(Box<GetRequest<crate::object::inbuxa_journal::Journal>>),
|
||||
@@ -178,6 +179,7 @@ pub enum SetRequestMethod<'x> {
|
||||
),
|
||||
DeliverabilityReport(Box<SetRequest<'x, crate::object::inbuxa_deliverability_report::DeliverabilityReport>>),
|
||||
DeliverabilitySettings(Box<SetRequest<'x, crate::object::inbuxa_deliverability_settings::DeliverabilitySettings>>),
|
||||
ReportExport(Box<SetRequest<'x, crate::object::inbuxa_report_export::ReportExport>>),
|
||||
ScheduledReport(Box<SetRequest<'x, crate::object::inbuxa_scheduled_report::ScheduledReport>>),
|
||||
ScheduledReportSettings(Box<SetRequest<'x, crate::object::inbuxa_scheduled_report_settings::ScheduledReportSettings>>),
|
||||
Journal(Box<SetRequest<'x, crate::object::inbuxa_journal::Journal>>),
|
||||
|
||||
@@ -743,6 +743,20 @@ impl<'de> Visitor<'de> for CallVisitor {
|
||||
return Err(de::Error::invalid_length(1, &self));
|
||||
}
|
||||
},
|
||||
(MethodFunction::Get, MethodObject::ReportExport) => match seq.next_element() {
|
||||
Ok(Some(value)) => RequestMethod::Get(GetRequestMethod::ReportExport(value)),
|
||||
Err(err) => RequestMethod::invalid(err),
|
||||
Ok(None) => {
|
||||
return Err(de::Error::invalid_length(1, &self));
|
||||
}
|
||||
},
|
||||
(MethodFunction::Set, MethodObject::ReportExport) => match seq.next_element() {
|
||||
Ok(Some(value)) => RequestMethod::Set(SetRequestMethod::ReportExport(value)),
|
||||
Err(err) => RequestMethod::invalid(err),
|
||||
Ok(None) => {
|
||||
return Err(de::Error::invalid_length(1, &self));
|
||||
}
|
||||
},
|
||||
// inbuxa: journaling
|
||||
(MethodFunction::Get, MethodObject::JournalEntry) => match seq.next_element() {
|
||||
Ok(Some(value)) => RequestMethod::Get(GetRequestMethod::JournalEntry(value)),
|
||||
|
||||
@@ -115,6 +115,7 @@ pub enum GetResponseMethod {
|
||||
SecurityAcceptance(GetResponse<crate::object::inbuxa_security_acceptance::SecurityAcceptance>),
|
||||
DeliverabilityReport(GetResponse<crate::object::inbuxa_deliverability_report::DeliverabilityReport>),
|
||||
DeliverabilitySettings(GetResponse<crate::object::inbuxa_deliverability_settings::DeliverabilitySettings>),
|
||||
ReportExport(GetResponse<crate::object::inbuxa_report_export::ReportExport>),
|
||||
ScheduledReport(GetResponse<crate::object::inbuxa_scheduled_report::ScheduledReport>),
|
||||
ScheduledReportSettings(GetResponse<crate::object::inbuxa_scheduled_report_settings::ScheduledReportSettings>),
|
||||
Journal(GetResponse<crate::object::inbuxa_journal::Journal>),
|
||||
@@ -165,6 +166,7 @@ pub enum SetResponseMethod {
|
||||
),
|
||||
DeliverabilityReport(Box<SetResponse<crate::object::inbuxa_deliverability_report::DeliverabilityReport>>),
|
||||
DeliverabilitySettings(Box<SetResponse<crate::object::inbuxa_deliverability_settings::DeliverabilitySettings>>),
|
||||
ReportExport(Box<SetResponse<crate::object::inbuxa_report_export::ReportExport>>),
|
||||
ScheduledReport(Box<SetResponse<crate::object::inbuxa_scheduled_report::ScheduledReport>>),
|
||||
ScheduledReportSettings(Box<SetResponse<crate::object::inbuxa_scheduled_report_settings::ScheduledReportSettings>>),
|
||||
Journal(Box<SetResponse<crate::object::inbuxa_journal::Journal>>),
|
||||
@@ -896,6 +898,17 @@ impl<'x> From<SetResponse<crate::object::inbuxa_deliverability_settings::Deliver
|
||||
ResponseMethod::Set(SetResponseMethod::DeliverabilitySettings(Box::new(value)))
|
||||
}
|
||||
}
|
||||
impl<'x> From<GetResponse<crate::object::inbuxa_report_export::ReportExport>> for ResponseMethod<'x> {
|
||||
fn from(value: GetResponse<crate::object::inbuxa_report_export::ReportExport>) -> Self {
|
||||
ResponseMethod::Get(GetResponseMethod::ReportExport(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'x> From<SetResponse<crate::object::inbuxa_report_export::ReportExport>> for ResponseMethod<'x> {
|
||||
fn from(value: SetResponse<crate::object::inbuxa_report_export::ReportExport>) -> Self {
|
||||
ResponseMethod::Set(SetResponseMethod::ReportExport(Box::new(value)))
|
||||
}
|
||||
}
|
||||
impl<'x> From<GetResponse<crate::object::inbuxa_scheduled_report::ScheduledReport>> for ResponseMethod<'x> {
|
||||
fn from(value: GetResponse<crate::object::inbuxa_scheduled_report::ScheduledReport>) -> Self {
|
||||
ResponseMethod::Get(GetResponseMethod::ScheduledReport(value))
|
||||
|
||||
Reference in new issue
Block a user