// // 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 . use std::collections::{BTreeSet, HashMap}; use poem_openapi::Object; use serde::{Deserialize, Serialize}; use crate::modules::{ account::{ entity::ImapConfig, migration::{AccountModel, AccountType, QuotaWindow}, since::{DateSince, RelativeDate}, }, users::UserModel, }; #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize, Object)] pub struct AccountResp { pub id: u64, pub imap: Option, pub enabled: bool, pub email: String, pub account_name: Option, pub login_name: Option, pub capabilities: Option>, pub date_since: Option, pub date_before: Option, pub folder_limit: Option, pub download_folders: Option>, pub account_type: AccountType, pub download_interval_min: Option, pub download_batch_size: Option, pub known_folders: Option>, pub created_at: i64, pub updated_at: i64, pub created_by: u64, //user id pub created_user_name: String, pub created_user_email: String, pub use_proxy: Option, pub use_dangerous: bool, pub pgp_key: Option, pub imap_quota_bytes: Option, pub imap_quota_window: Option, pub auto_download_new_mailboxes: Option, } impl AccountResp { pub fn from_model(account: AccountModel, user_map: &HashMap) -> AccountResp { let user = user_map.get(&account.created_by); AccountResp { id: account.id, imap: account.imap, enabled: account.enabled, email: account.email, account_name: account.account_name, login_name: account.login_name, capabilities: account.capabilities, date_since: account.date_since, date_before: account.date_before, folder_limit: account.folder_limit, download_folders: account.download_folders, account_type: account.account_type, download_interval_min: account.download_interval_min, download_batch_size: account.download_batch_size, known_folders: account.known_folders, created_at: account.created_at, updated_at: account.updated_at, created_by: account.created_by, created_user_name: user .map(|u| u.username.clone()) .unwrap_or_else(|| "Unknown".to_string()), created_user_email: user .map(|u| u.email.clone()) .unwrap_or_else(|| "N/A".to_string()), use_proxy: account.use_proxy, use_dangerous: account.use_dangerous, pgp_key: account.pgp_key, imap_quota_bytes: account.imap_quota_bytes, imap_quota_window: account.imap_quota_window, auto_download_new_mailboxes: account.auto_download_new_mailboxes, } } }