mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Merge pull request #1613 from deltachat/warn-wrong-pw
Show a better toast and a notification when the password is wrong (because it was changed on the server)
This commit is contained in:
16
src/chat.rs
16
src/chat.rs
@@ -2669,10 +2669,12 @@ pub(crate) async fn get_chat_id_by_grpid(
|
|||||||
/// Adds a message to device chat.
|
/// Adds a message to device chat.
|
||||||
///
|
///
|
||||||
/// Optional `label` can be provided to ensure that message is added only once.
|
/// Optional `label` can be provided to ensure that message is added only once.
|
||||||
pub async fn add_device_msg(
|
/// If `important` is true, a notification will be sent.
|
||||||
|
pub async fn add_device_msg_with_importance(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
label: Option<&str>,
|
label: Option<&str>,
|
||||||
msg: Option<&mut Message>,
|
msg: Option<&mut Message>,
|
||||||
|
important: bool,
|
||||||
) -> Result<MsgId, Error> {
|
) -> Result<MsgId, Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
label.is_some() || msg.is_some(),
|
label.is_some() || msg.is_some(),
|
||||||
@@ -2732,12 +2734,24 @@ pub async fn add_device_msg(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !msg_id.is_unset() {
|
if !msg_id.is_unset() {
|
||||||
|
if important {
|
||||||
context.emit_event(Event::IncomingMsg { chat_id, msg_id });
|
context.emit_event(Event::IncomingMsg { chat_id, msg_id });
|
||||||
|
} else {
|
||||||
|
context.emit_event(Event::MsgsChanged { chat_id, msg_id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn add_device_msg(
|
||||||
|
context: &Context,
|
||||||
|
label: Option<&str>,
|
||||||
|
msg: Option<&mut Message>,
|
||||||
|
) -> Result<MsgId, Error> {
|
||||||
|
add_device_msg_with_importance(context, label, msg, false).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn was_device_msg_ever_added(context: &Context, label: &str) -> Result<bool, Error> {
|
pub async fn was_device_msg_ever_added(context: &Context, label: &str) -> Result<bool, Error> {
|
||||||
ensure!(!label.is_empty(), "empty label");
|
ensure!(!label.is_empty(), "empty label");
|
||||||
if let Ok(()) = context
|
if let Ok(()) = context
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ pub enum Config {
|
|||||||
|
|
||||||
#[strum(serialize = "sys.config_keys")]
|
#[strum(serialize = "sys.config_keys")]
|
||||||
SysConfigKeys,
|
SysConfigKeys,
|
||||||
|
|
||||||
|
#[strum(props(default = "0"))]
|
||||||
|
/// Whether we send a warning if the password is wrong (set to false when we send a warning
|
||||||
|
/// because we do not want to send a second warning)
|
||||||
|
NotifyAboutWrongPw,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ impl Context {
|
|||||||
|
|
||||||
let mut param = LoginParam::from_database(self, "").await;
|
let mut param = LoginParam::from_database(self, "").await;
|
||||||
let success = configure(self, &mut param).await;
|
let success = configure(self, &mut param).await;
|
||||||
|
self.set_config(Config::NotifyAboutWrongPw, None).await?;
|
||||||
|
|
||||||
if let Some(provider) = provider::get_provider_info(¶m.addr) {
|
if let Some(provider) = provider::get_provider_info(¶m.addr) {
|
||||||
if let Some(config_defaults) = &provider.config_defaults {
|
if let Some(config_defaults) = &provider.config_defaults {
|
||||||
@@ -100,11 +101,12 @@ impl Context {
|
|||||||
|
|
||||||
match success {
|
match success {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
self.set_config(Config::NotifyAboutWrongPw, Some("1"))
|
||||||
|
.await?;
|
||||||
progress!(self, 1000);
|
progress!(self, 1000);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(self, "Configure Failed: {}", err);
|
|
||||||
progress!(self, 0);
|
progress!(self, 0);
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
@@ -457,7 +459,10 @@ async fn try_imap_connections(
|
|||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
return Ok(()); // we directly return here if it was autoconfig or the connection succeeded
|
return Ok(());
|
||||||
|
}
|
||||||
|
if was_autoconfig {
|
||||||
|
bail!("autoconfig did not succeed");
|
||||||
}
|
}
|
||||||
|
|
||||||
progress!(context, 670);
|
progress!(context, 670);
|
||||||
@@ -491,7 +496,7 @@ async fn try_imap_connection(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if was_autoconfig {
|
if was_autoconfig {
|
||||||
return Ok(());
|
bail!("autoconfig did not succeed");
|
||||||
}
|
}
|
||||||
|
|
||||||
progress!(context, 650 + variation * 30);
|
progress!(context, 650 + variation * 30);
|
||||||
@@ -551,7 +556,7 @@ async fn try_smtp_connections(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if was_autoconfig {
|
if was_autoconfig {
|
||||||
return Ok(());
|
bail!("No SMTP connection");
|
||||||
}
|
}
|
||||||
progress!(context, 850);
|
progress!(context, 850);
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ pub struct InnerContext {
|
|||||||
pub(crate) generating_key_mutex: Mutex<()>,
|
pub(crate) generating_key_mutex: Mutex<()>,
|
||||||
/// Mutex to enforce only a single running oauth2 is running.
|
/// Mutex to enforce only a single running oauth2 is running.
|
||||||
pub(crate) oauth2_mutex: Mutex<()>,
|
pub(crate) oauth2_mutex: Mutex<()>,
|
||||||
|
/// Mutex to prevent a race condition when a "your pw is wrong" warning is sent, resulting in multiple messeges being sent.
|
||||||
|
pub(crate) wrong_pw_warning_mutex: Mutex<()>,
|
||||||
pub(crate) translated_stockstrings: RwLock<HashMap<usize, String>>,
|
pub(crate) translated_stockstrings: RwLock<HashMap<usize, String>>,
|
||||||
pub(crate) events: Events,
|
pub(crate) events: Events,
|
||||||
|
|
||||||
@@ -120,6 +122,7 @@ impl Context {
|
|||||||
last_smeared_timestamp: RwLock::new(0),
|
last_smeared_timestamp: RwLock::new(0),
|
||||||
generating_key_mutex: Mutex::new(()),
|
generating_key_mutex: Mutex::new(()),
|
||||||
oauth2_mutex: Mutex::new(()),
|
oauth2_mutex: Mutex::new(()),
|
||||||
|
wrong_pw_warning_mutex: Mutex::new(()),
|
||||||
translated_stockstrings: RwLock::new(HashMap::new()),
|
translated_stockstrings: RwLock::new(HashMap::new()),
|
||||||
events: Events::default(),
|
events: Events::default(),
|
||||||
scheduler: RwLock::new(Scheduler::Stopped),
|
scheduler: RwLock::new(Scheduler::Stopped),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ use crate::mimeparser;
|
|||||||
use crate::oauth2::dc_get_oauth2_access_token;
|
use crate::oauth2::dc_get_oauth2_access_token;
|
||||||
use crate::param::Params;
|
use crate::param::Params;
|
||||||
use crate::provider::get_provider_info;
|
use crate::provider::get_provider_info;
|
||||||
use crate::{scheduler::InterruptInfo, stock::StockMessage};
|
use crate::{chat, scheduler::InterruptInfo, stock::StockMessage};
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod idle;
|
mod idle;
|
||||||
@@ -36,6 +36,7 @@ pub mod select_folder;
|
|||||||
mod session;
|
mod session;
|
||||||
|
|
||||||
use client::Client;
|
use client::Client;
|
||||||
|
use message::Message;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -116,6 +117,7 @@ pub struct Imap {
|
|||||||
connected: bool,
|
connected: bool,
|
||||||
interrupt: Option<stop_token::StopSource>,
|
interrupt: Option<stop_token::StopSource>,
|
||||||
should_reconnect: bool,
|
should_reconnect: bool,
|
||||||
|
login_failed_once: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -189,6 +191,7 @@ impl Imap {
|
|||||||
connected: Default::default(),
|
connected: Default::default(),
|
||||||
interrupt: Default::default(),
|
interrupt: Default::default(),
|
||||||
should_reconnect: Default::default(),
|
should_reconnect: Default::default(),
|
||||||
|
login_failed_once: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,18 +296,40 @@ impl Imap {
|
|||||||
// needs to be set here to ensure it is set on reconnects.
|
// needs to be set here to ensure it is set on reconnects.
|
||||||
self.connected = true;
|
self.connected = true;
|
||||||
self.session = Some(session);
|
self.session = Some(session);
|
||||||
|
self.login_failed_once = false;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
Err((err, _)) => {
|
Err((err, _)) => {
|
||||||
let imap_user = self.config.imap_user.to_owned();
|
let imap_user = self.config.imap_user.to_owned();
|
||||||
let message = context
|
let message = context
|
||||||
.stock_string_repl_str(StockMessage::CannotLogin, &imap_user)
|
.stock_string_repl_str(StockMessage::CannotLogin, &imap_user)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
emit_event!(
|
warn!(context, "{} ({})", message, err);
|
||||||
context,
|
emit_event!(context, Event::ErrorNetwork(message.clone()));
|
||||||
Event::ErrorNetwork(format!("{} ({})", message, err))
|
|
||||||
);
|
let lock = context.wrong_pw_warning_mutex.lock().await;
|
||||||
|
if self.login_failed_once
|
||||||
|
&& context.get_config_bool(Config::NotifyAboutWrongPw).await
|
||||||
|
{
|
||||||
|
if let Err(e) = context.set_config(Config::NotifyAboutWrongPw, None).await {
|
||||||
|
warn!(context, "{}", e);
|
||||||
|
}
|
||||||
|
drop(lock);
|
||||||
|
|
||||||
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
|
msg.text = Some(message);
|
||||||
|
if let Err(e) =
|
||||||
|
chat::add_device_msg_with_importance(context, None, Some(&mut msg), true)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
warn!(context, "{}", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.login_failed_once = true;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger_reconnect();
|
self.trigger_reconnect();
|
||||||
Err(Error::LoginFailed(format!("cannot login as {}", imap_user)))
|
Err(Error::LoginFailed(format!("cannot login as {}", imap_user)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ impl Smtp {
|
|||||||
.stock_string_repl_str2(
|
.stock_string_repl_str2(
|
||||||
StockMessage::ServerResponse,
|
StockMessage::ServerResponse,
|
||||||
format!("SMTP {}:{}", domain, port),
|
format!("SMTP {}:{}", domain, port),
|
||||||
format!("{}, ({:?})", err.to_string(), err),
|
err.to_string(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,9 @@ pub enum StockMessage {
|
|||||||
))]
|
))]
|
||||||
AcSetupMsgBody = 43,
|
AcSetupMsgBody = 43,
|
||||||
|
|
||||||
#[strum(props(fallback = "Cannot login as %1$s."))]
|
#[strum(props(
|
||||||
|
fallback = "Cannot login as \"%1$s\". Please check if the email address and the password are correct."
|
||||||
|
))]
|
||||||
CannotLogin = 60,
|
CannotLogin = 60,
|
||||||
|
|
||||||
#[strum(props(fallback = "Could not connect to %1$s: %2$s"))]
|
#[strum(props(fallback = "Could not connect to %1$s: %2$s"))]
|
||||||
|
|||||||
Reference in New Issue
Block a user