// // Copyright (c) 2025 rustmailer.com (https://rustmailer.com) // // This file is part of the Bichon Email Archiving Project // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . use std::sync::LazyLock; use crate::modules::{account::state::AccountRunningState, database::ModelsAdapter}; use ahash::{AHashMap, AHashSet}; use mailbox::MailBox; use native_db::Models; pub mod mailbox; pub mod sync; pub mod task; pub static MAILBOX_MODELS: LazyLock = LazyLock::new(|| { let mut adapter = ModelsAdapter::new(); adapter.register_model::(); adapter.register_model::(); adapter.models }); pub fn find_missing_mailboxes( local_mailboxes: &[MailBox], server_mailboxes: &[MailBox], ) -> Vec { let local_names: AHashSet<_> = local_mailboxes.iter().map(|m| &m.name).collect(); server_mailboxes .iter() .filter(|m| !local_names.contains(&m.name)) .cloned() .collect() } pub fn find_intersecting_mailboxes( local_mailboxes: &[MailBox], remote_mailboxes: &[MailBox], ) -> Vec<(MailBox, MailBox)> { let local_map: AHashMap<_, _> = local_mailboxes .iter() .map(|m| (m.name.clone(), m.clone())) .collect(); remote_mailboxes .iter() .filter_map(|m| { local_map .get(&m.name) .map(|local_mailbox| (local_mailbox.clone(), m.clone())) }) .collect() }