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:
2026-09-18 10:21:56 -07:00
commit 7dae9b29fd
1650 changed files with 485521 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::{
Server,
auth::AccountCache,
storage::{ObjectQuota, TenantQuota},
};
use registry::{
schema::enums::{StorageQuota, TenantStorageQuota},
types::EnumImpl,
};
use store::{ValueKey, write::ValueClass};
use trc::AddContext;
impl Server {
pub async fn get_used_quota_account(&self, account_id: u32) -> trc::Result<i64> {
self.core
.storage
.data
.get_counter(ValueKey {
account_id,
collection: 0,
document_id: 0,
class: ValueClass::Quota,
})
.await
.add_context(|err| err.caused_by(trc::location!()).account_id(account_id))
}
#[cfg(not(feature = "enterprise"))]
pub async fn get_used_quota_tenant(&self, _tenant_id: u32) -> trc::Result<i64> {
Ok(0)
}
pub async fn has_available_quota(
&self,
account: &AccountCache,
item_size: u64,
) -> trc::Result<()> {
if account.quota_disk != 0 {
let used_quota = self.get_used_quota_account(account.id).await?.max(0) as u64;
if used_quota + item_size > account.quota_disk {
return Err(trc::LimitEvent::Quota
.into_err()
.ctx(trc::Key::Limit, account.quota_disk)
.ctx(trc::Key::Size, used_quota));
}
}
Ok(())
}
#[inline(always)]
pub fn object_quota(&self, user_quotas: Option<&ObjectQuota>, object: StorageQuota) -> u32 {
user_quotas.unwrap_or(&self.core.email.max_objects).0[object as usize]
}
}
impl ObjectQuota {
#[inline(always)]
pub fn set(&mut self, item: StorageQuota, max: u32) {
self.0[item as usize] = max;
}
#[inline(always)]
pub fn get(&self, item: StorageQuota) -> u32 {
self.0[item as usize]
}
}
impl TenantQuota {
#[inline(always)]
pub fn set(&mut self, item: TenantStorageQuota, max: u32) {
self.0[item as usize] = max;
}
#[inline(always)]
pub fn get(&self, item: TenantStorageQuota) -> u32 {
self.0[item as usize]
}
}
impl Default for ObjectQuota {
fn default() -> Self {
Self([u32::MAX; StorageQuota::COUNT - 1])
}
}
impl Default for TenantQuota {
fn default() -> Self {
Self([u32::MAX; TenantStorageQuota::COUNT - 1])
}
}