Files
bichon/src/modules/mailbox/delete.rs
T

50 lines
1.7 KiB
Rust
Raw Normal View History

2026-04-05 16:06:07 +08:00
//
// Copyright (c) 2025-2026 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 <http://www.gnu.org/licenses/>.
2026-01-05 18:27:40 +08:00
use crate::modules::{
2026-04-19 01:01:46 +08:00
cache::imap::mailbox::MailBox, error::BichonResult, store::tantivy::envelope::ENVELOPE_MANAGER,
2026-01-05 18:27:40 +08:00
};
pub async fn delete_mailbox_impl(account_id: u64, mailbox_id: u64) -> BichonResult<()> {
2026-04-05 16:06:07 +08:00
let mailbox = MailBox::async_get(mailbox_id).await?;
2026-01-05 18:27:40 +08:00
let name = mailbox.name;
let delimiter = mailbox.delimiter.unwrap_or("/".to_owned());
let all_mailboxes = MailBox::list_all(account_id).await?;
let prefix = format!("{}{}", name, delimiter);
let ids_to_delete: Vec<u64> = all_mailboxes
.into_iter()
.filter(|m| m.id == mailbox_id || m.name.starts_with(&prefix))
.map(|m| m.id)
.collect();
if ids_to_delete.is_empty() {
return Ok(());
}
for id in &ids_to_delete {
MailBox::delete(*id).await?;
}
2026-04-19 01:01:46 +08:00
ENVELOPE_MANAGER
2026-01-05 18:27:40 +08:00
.delete_mailbox_envelopes(account_id, ids_to_delete.clone())
.await?;
Ok(())
}