mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 00:46:31 +03:00
fix: Prevent accidental wrong-password-notifications (#6122)
Over the past years, it happend two times that a user came to me worried about a false-positive "Cannot login as ***. Please check if the e-mail address and the password are correct." message. I'm not sure why this happened, but this PR makes the logic for showing this notification stricter: - Before: The notification is shown if connection fails two times in a row, and the second error contains the word "authentication". - Now: The notification is shown if the connection fails two times in a row, and _both_ error messages contain the word "authentication". The second commit just renames `login_failed_once` to `authentication_failed_once` in order to reflect this change.
This commit is contained in:
51
src/imap.rs
51
src/imap.rs
@@ -89,7 +89,7 @@ pub(crate) struct Imap {
|
|||||||
|
|
||||||
oauth2: bool,
|
oauth2: bool,
|
||||||
|
|
||||||
login_failed_once: bool,
|
authentication_failed_once: bool,
|
||||||
|
|
||||||
pub(crate) connectivity: ConnectivityStore,
|
pub(crate) connectivity: ConnectivityStore,
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ impl Imap {
|
|||||||
proxy_config,
|
proxy_config,
|
||||||
strict_tls,
|
strict_tls,
|
||||||
oauth2,
|
oauth2,
|
||||||
login_failed_once: false,
|
authentication_failed_once: false,
|
||||||
connectivity: Default::default(),
|
connectivity: Default::default(),
|
||||||
conn_last_try: UNIX_EPOCH,
|
conn_last_try: UNIX_EPOCH,
|
||||||
conn_backoff_ms: 0,
|
conn_backoff_ms: 0,
|
||||||
@@ -402,7 +402,7 @@ impl Imap {
|
|||||||
let mut lock = context.server_id.write().await;
|
let mut lock = context.server_id.write().await;
|
||||||
lock.clone_from(&session.capabilities.server_id);
|
lock.clone_from(&session.capabilities.server_id);
|
||||||
|
|
||||||
self.login_failed_once = false;
|
self.authentication_failed_once = false;
|
||||||
context.emit_event(EventType::ImapConnected(format!(
|
context.emit_event(EventType::ImapConnected(format!(
|
||||||
"IMAP-LOGIN as {}",
|
"IMAP-LOGIN as {}",
|
||||||
lp.user
|
lp.user
|
||||||
@@ -416,35 +416,38 @@ impl Imap {
|
|||||||
let imap_user = lp.user.to_owned();
|
let imap_user = lp.user.to_owned();
|
||||||
let message = stock_str::cannot_login(context, &imap_user).await;
|
let message = stock_str::cannot_login(context, &imap_user).await;
|
||||||
|
|
||||||
let err_str = err.to_string();
|
|
||||||
warn!(context, "IMAP failed to login: {err:#}.");
|
warn!(context, "IMAP failed to login: {err:#}.");
|
||||||
first_error.get_or_insert(format_err!("{message} ({err:#})"));
|
first_error.get_or_insert(format_err!("{message} ({err:#})"));
|
||||||
|
|
||||||
|
// If it looks like the password is wrong, send a notification:
|
||||||
let _lock = context.wrong_pw_warning_mutex.lock().await;
|
let _lock = context.wrong_pw_warning_mutex.lock().await;
|
||||||
if !configuring
|
if err.to_string().to_lowercase().contains("authentication") {
|
||||||
&& self.login_failed_once
|
if self.authentication_failed_once
|
||||||
&& err_str.to_lowercase().contains("authentication")
|
&& !configuring
|
||||||
&& context.get_config_bool(Config::NotifyAboutWrongPw).await?
|
&& context.get_config_bool(Config::NotifyAboutWrongPw).await?
|
||||||
{
|
|
||||||
let mut msg = Message::new_text(message);
|
|
||||||
if let Err(e) = chat::add_device_msg_with_importance(
|
|
||||||
context,
|
|
||||||
None,
|
|
||||||
Some(&mut msg),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
{
|
||||||
warn!(context, "Failed to add device message: {e:#}.");
|
let mut msg = Message::new_text(message);
|
||||||
|
if let Err(e) = chat::add_device_msg_with_importance(
|
||||||
|
context,
|
||||||
|
None,
|
||||||
|
Some(&mut msg),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
warn!(context, "Failed to add device message: {e:#}.");
|
||||||
|
} else {
|
||||||
|
context
|
||||||
|
.set_config_internal(Config::NotifyAboutWrongPw, None)
|
||||||
|
.await
|
||||||
|
.log_err(context)
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
context
|
self.authentication_failed_once = true;
|
||||||
.set_config_internal(Config::NotifyAboutWrongPw, None)
|
|
||||||
.await
|
|
||||||
.log_err(context)
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.login_failed_once = true;
|
self.authentication_failed_once = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user