// // 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::collections::{BTreeSet, HashMap}; use poem_openapi::Object; use serde::{Deserialize, Serialize}; use crate::modules::{ account::{ entity::ImapConfig, migration::{AccountModel, AccountType}, since::DateSince, }, users::BichonUser, }; #[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 name: Option, pub capabilities: Option>, pub date_since: Option, pub folder_limit: Option, pub sync_folders: Option>, pub account_type: AccountType, pub sync_interval_min: 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, } 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, name: account.name, capabilities: account.capabilities, date_since: account.date_since, folder_limit: account.folder_limit, sync_folders: account.sync_folders, account_type: account.account_type, sync_interval_min: account.sync_interval_min, 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, } } }