From 5ebc7394d0af988b6d854608522aca52d4dc7d9e Mon Sep 17 00:00:00 2001 From: rustmailer Date: Mon, 24 Nov 2025 19:11:52 +0800 Subject: [PATCH] fix(account): prevent IMAP password from being overwritten when editing account #7 --- src/modules/account/entity.rs | 1 - src/modules/account/migration.rs | 16 ++++++++++------ src/modules/rest/mod.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/modules/account/entity.rs b/src/modules/account/entity.rs index 4081112..dc0e5c1 100644 --- a/src/modules/account/entity.rs +++ b/src/modules/account/entity.rs @@ -70,7 +70,6 @@ pub struct AuthConfig { /// /// Users should provide a plaintext password (1 to 256 characters). /// The server will encrypt the password using AES-256-GCM and securely store it. - /// The plaintext password is never stored, so users must remember it for authentication. #[oai(validator(max_length = 256, min_length = 1))] pub password: Option, } diff --git a/src/modules/account/migration.rs b/src/modules/account/migration.rs index 30db562..c2eb0a2 100644 --- a/src/modules/account/migration.rs +++ b/src/modules/account/migration.rs @@ -16,7 +16,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - use native_db::*; use native_model::{native_model, Model}; @@ -323,12 +322,17 @@ impl AccountV1 { if matches!(old.account_type, AccountType::IMAP) { if let Some(imap) = &request.imap { - let mut new_imap = imap.clone(); - if let Some(password) = &new_imap.auth.password { - let encrypted_password = encrypt!(password)?; - new_imap.auth.password = Some(encrypted_password); + if let Some(current_imap) = &mut new.imap { + current_imap.host = imap.host.clone(); + current_imap.port = imap.port.clone(); + current_imap.encryption = imap.encryption.clone(); + current_imap.auth.auth_type = imap.auth.auth_type.clone(); + if let Some(password) = &imap.auth.password { + let encrypted_password = encrypt!(password)?; + current_imap.auth.password = Some(encrypted_password); + } + current_imap.use_proxy = imap.use_proxy; } - new.imap = Some(new_imap); } if let Some(folder_names) = request.sync_folders { diff --git a/src/modules/rest/mod.rs b/src/modules/rest/mod.rs index 48d9468..51f1f33 100644 --- a/src/modules/rest/mod.rs +++ b/src/modules/rest/mod.rs @@ -122,7 +122,7 @@ pub async fn start_http_server() -> BichonResult<()> { .with(CatchPanic::new()); let server = Server::new(listener) - .name("RustMailer API Service") + .name("Bichon Service") .idle_timeout(Duration::from_secs(60)) .run_with_graceful_shutdown( route.catch_all_error(error_handler), @@ -130,7 +130,7 @@ pub async fn start_http_server() -> BichonResult<()> { Some(Duration::from_secs(5)), ); println!( - "RustMailer API Service is now running on port {}.", + "Bichon Service is now running on port {}.", SETTINGS.bichon_http_port ); server