Files
bichon/src/modules/cache/imap/mod.rs
T

70 lines
2.1 KiB
Rust
Raw Normal View History

2025-11-19 02:14:37 +08:00
//
// Copyright (c) 2025-2026 rustmailer.com (https://rustmailer.com)
2025-11-19 02:14:37 +08:00
//
// 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 <http://www.gnu.org/licenses/>.
use std::sync::LazyLock;
use crate::modules::{
account::{state::DownloadState, old_state::AccountRunningState},
database::ModelsAdapter,
};
2025-11-19 02:14:37 +08:00
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<Models> = LazyLock::new(|| {
let mut adapter = ModelsAdapter::new();
adapter.register_model::<MailBox>();
adapter.register_model::<AccountRunningState>();
adapter.register_model::<DownloadState>();
2025-11-19 02:14:37 +08:00
adapter.models
});
pub fn find_missing_mailboxes(
local_mailboxes: &[MailBox],
server_mailboxes: &[MailBox],
) -> Vec<MailBox> {
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()
}