Fixed queue migration, tenant quotas API and bumped dependencies

This commit is contained in:
mdecimus
2025-05-18 11:58:36 +02:00
parent 4e5c4554c7
commit c79367f790
11 changed files with 304 additions and 387 deletions

574
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -19,7 +19,7 @@ mail-auth = { version = "0.7" }
mail-send = { version = "0.5", default-features = false, features = ["cram-md5", "ring", "tls12"] }
smtp-proto = { version = "0.1", features = ["rkyv"] }
dns-update = { version = "0.1" }
calcard = { path = "/Users/me/code/calcard", features = ["rkyv"] }
calcard = { version = "0.1", features = ["rkyv"] }
ahash = { version = "0.8.2", features = ["serde"] }
parking_lot = "0.12.1"
regex = "1.7.0"

View File

@@ -7,7 +7,7 @@ edition = "2021"
trc = { path = "../trc" }
hashify = "0.2.6"
quick-xml = "0.37.2"
calcard = { path = "/Users/me/code/calcard", features = ["rkyv"] }
calcard = { version = "0.1", features = ["rkyv"] }
mail-parser = { version = "0.11", features = ["full_encoding", "rkyv"] }
hyper = "1.6.0"
rkyv = { version = "0.8.10", features = ["little_endian"] }
@@ -15,7 +15,7 @@ chrono = { version = "0.4.40", features = ["serde"], optional = true }
compact_str = "0.9.0"
[dev-dependencies]
calcard = { path = "/Users/me/code/calcard", features = ["serde", "rkyv"] }
calcard = { version = "0.1", features = ["serde", "rkyv"] }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.138"
chrono = { version = "0.4.40", features = ["serde"] }

View File

@@ -14,7 +14,7 @@ directory = { path = "../directory" }
http_proto = { path = "../http-proto" }
jmap_proto = { path = "../jmap-proto" }
trc = { path = "../trc" }
calcard = { path = "/Users/me/code/calcard", features = ["rkyv"] }
calcard = { version = "0.1", features = ["rkyv"] }
hashify = { version = "0.2" }
hyper = { version = "1.0.1", features = ["server", "http1", "http2"] }
percent-encoding = "2.3.1"

View File

@@ -2312,7 +2312,7 @@ impl ManageDirectory for Store {
quotas[0] = quota;
}
for quota in principal_quotas {
quotas[quota.typ as usize] = quota.quota;
quotas[(quota.typ as usize) + 1] = quota.quota;
}
result.set(PrincipalField::Quota, quotas);

View File

@@ -12,7 +12,7 @@ jmap_proto = { path = "../jmap-proto" }
trc = { path = "../trc" }
directory = { path = "../directory" }
dav-proto = { path = "../dav-proto" }
calcard = { path = "/Users/me/code/calcard", features = ["rkyv"] }
calcard = { version = "0.1", features = ["rkyv"] }
hashify = "0.2"
tokio = { version = "1.23", features = ["net", "macros"] }
rkyv = { version = "0.8.10", features = ["little_endian"] }

View File

@@ -200,13 +200,15 @@ impl FromLegacy for Principal {
let mut principal_quotas = Vec::new();
for (idx, quota) in quotas.into_iter().take(Type::MAX_ID + 2).enumerate() {
if idx != 0 {
principal_quotas.push(PrincipalQuota {
quota,
typ: Type::from_u8((idx - 1) as u8),
});
} else if quota != 0 {
principal.quota = Some(quota);
if quota != 0 {
if idx != 0 {
principal_quotas.push(PrincipalQuota {
quota,
typ: Type::from_u8((idx - 1) as u8),
});
} else {
principal.quota = Some(quota);
}
}
}

View File

@@ -6,7 +6,9 @@
use crate::LegacyBincode;
use common::Server;
use smtp::queue::Message;
use smtp::queue::{
Domain, ErrorDetails, HostResponse, Message, QueueId, QuotaKey, Recipient, Status,
};
use store::{
IterateParams, Serialize, U64_LEN, ValueKey,
ahash::AHashSet,
@@ -16,6 +18,7 @@ use store::{
},
};
use trc::AddContext;
use utils::BlobHash;
pub(crate) async fn migrate_queue(server: &Server) -> trc::Result<()> {
let from_key = ValueKey::from(ValueClass::Queue(QueueClass::MessageEvent(
@@ -51,16 +54,45 @@ pub(crate) async fn migrate_queue(server: &Server) -> trc::Result<()> {
for queue_id in queue_ids {
match server
.store()
.get_value::<LegacyBincode<Message>>(ValueKey::from(ValueClass::Queue(
.get_value::<LegacyBincode<LegacyMessage>>(ValueKey::from(ValueClass::Queue(
QueueClass::Message(queue_id),
)))
.await
{
Ok(Some(bincoded)) => {
let message = bincoded.inner;
let message = Message {
queue_id: message.queue_id,
created: message.created,
blob_hash: message.blob_hash,
return_path: message.return_path,
return_path_lcase: message.return_path_lcase,
return_path_domain: message.return_path_domain,
recipients: message
.recipients
.into_iter()
.map(|r| Recipient {
domain_idx: r.domain_idx as u32,
address: r.address,
address_lcase: r.address_lcase,
status: r.status,
flags: r.flags,
orcpt: r.orcpt,
})
.collect(),
domains: message.domains,
flags: message.flags,
env_id: message.env_id,
priority: message.priority,
size: message.size as u64,
quota_keys: message.quota_keys,
span_id: message.span_id,
};
let mut batch = BatchBuilder::new();
batch.set(
ValueClass::Queue(QueueClass::Message(queue_id)),
Archiver::new(bincoded.inner)
Archiver::new(message)
.serialize()
.caused_by(trc::location!())?,
);
@@ -98,3 +130,36 @@ pub(crate) async fn migrate_queue(server: &Server) -> trc::Result<()> {
Ok(())
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
pub struct LegacyMessage {
pub queue_id: QueueId,
pub created: u64,
pub blob_hash: BlobHash,
pub return_path: String,
pub return_path_lcase: String,
pub return_path_domain: String,
pub recipients: Vec<LegacyRecipient>,
pub domains: Vec<Domain>,
pub flags: u64,
pub env_id: Option<String>,
pub priority: i16,
pub size: usize,
pub quota_keys: Vec<QuotaKey>,
#[serde(skip)]
pub span_id: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
pub struct LegacyRecipient {
pub domain_idx: usize,
pub address: String,
pub address_lcase: String,
pub status: Status<HostResponse<String>, HostResponse<ErrorDetails>>,
pub flags: u64,
pub orcpt: Option<String>,
}

View File

@@ -46,16 +46,7 @@ pub enum MessageSource {
Autogenerated,
}
#[derive(
rkyv::Serialize,
rkyv::Deserialize,
rkyv::Archive,
Debug,
Clone,
PartialEq,
Eq,
serde::Deserialize,
)]
#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, Debug, Clone, PartialEq, Eq)]
pub struct Message {
pub queue_id: QueueId,
pub created: u64,
@@ -75,7 +66,6 @@ pub struct Message {
pub quota_keys: Vec<QuotaKey>,
#[rkyv(with = rkyv::with::Skip)]
#[serde(skip)]
pub span_id: u64,
}

View File

@@ -18,13 +18,13 @@ mail-send = { version = "0.5", default-features = false, features = ["cram-md5",
ahash = { version = "0.8", features = ["serde"] }
chrono = "0.4"
rand = "0.9.0"
webpki-roots = { version = "0.26"}
webpki-roots = { version = "1.0"}
ring = { version = "0.17" }
base64 = "0.22"
serde_json = "1.0"
rcgen = "0.13"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-webpki-roots", "http2", "stream"]}
x509-parser = "0.16.0"
x509-parser = "0.17.0"
pem = "3.0"
parking_lot = "0.12"
futures = "0.3"

View File

@@ -29,7 +29,7 @@ imap = { path = "../crates/imap", features = ["test_mode"] }
imap_proto = { path = "../crates/imap-proto" }
dav = { path = "../crates/dav", features = ["test_mode"] }
dav-proto = { path = "../crates/dav-proto", features = ["test_mode"] }
calcard = { path = "/Users/me/code/calcard", features = ["rkyv"] }
calcard = { version = "0.1", features = ["rkyv"] }
groupware = { path = "../crates/groupware", features = ["test_mode"] }
http = { path = "../crates/http", features = ["test_mode", "enterprise"] }
http_proto = { path = "../crates/http-proto" }