fix(account): prevent IMAP password from being overwritten when editing account #7

This commit is contained in:
rustmailer
2025-11-24 19:11:52 +08:00
parent b97f2666a0
commit 5ebc7394d0
3 changed files with 12 additions and 9 deletions
-1
View File
@@ -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<String>,
}
+10 -6
View File
@@ -16,7 +16,6 @@
// 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 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 {
+2 -2
View File
@@ -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