mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 14:26:30 +03:00
feat: add device message for imported contacts after configuration
Add a short info message about how many contacts were added during configuration.
This commit is contained in:
23
src/imap.rs
23
src/imap.rs
@@ -768,14 +768,16 @@ impl Imap {
|
|||||||
&mut self,
|
&mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
session: &mut Session,
|
session: &mut Session,
|
||||||
) -> Result<()> {
|
) -> Result<i32> {
|
||||||
|
let mut created = 0;
|
||||||
|
created +=
|
||||||
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder)
|
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder)
|
||||||
.await
|
.await
|
||||||
.context("failed to get recipients from the sentbox")?;
|
.context("failed to get recipients from the sentbox")?;
|
||||||
add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder)
|
created += add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder)
|
||||||
.await
|
.await
|
||||||
.context("failed to get recipients from the movebox")?;
|
.context("failed to get recipients from the movebox")?;
|
||||||
add_all_recipients_as_contacts(context, session, Config::ConfiguredInboxFolder)
|
created += add_all_recipients_as_contacts(context, session, Config::ConfiguredInboxFolder)
|
||||||
.await
|
.await
|
||||||
.context("failed to get recipients from the inbox")?;
|
.context("failed to get recipients from the inbox")?;
|
||||||
|
|
||||||
@@ -802,7 +804,7 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!(context, "Done fetching existing messages.");
|
info!(context, "Done fetching existing messages.");
|
||||||
Ok(())
|
Ok(created)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2479,11 +2481,14 @@ impl std::fmt::Display for UidRange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add all recipients as contacts.
|
||||||
|
/// Returns how many contacts were created.
|
||||||
async fn add_all_recipients_as_contacts(
|
async fn add_all_recipients_as_contacts(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
session: &mut Session,
|
session: &mut Session,
|
||||||
folder: Config,
|
folder: Config,
|
||||||
) -> Result<()> {
|
) -> Result<i32> {
|
||||||
let mailbox = if let Some(m) = context.get_config(folder).await? {
|
let mailbox = if let Some(m) = context.get_config(folder).await? {
|
||||||
m
|
m
|
||||||
} else {
|
} else {
|
||||||
@@ -2491,7 +2496,7 @@ async fn add_all_recipients_as_contacts(
|
|||||||
context,
|
context,
|
||||||
"Folder {} is not configured, skipping fetching contacts from it.", folder
|
"Folder {} is not configured, skipping fetching contacts from it.", folder
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(0);
|
||||||
};
|
};
|
||||||
session
|
session
|
||||||
.select_with_uidvalidity(context, &mailbox)
|
.select_with_uidvalidity(context, &mailbox)
|
||||||
@@ -2504,6 +2509,7 @@ async fn add_all_recipients_as_contacts(
|
|||||||
.context("could not get recipients")?;
|
.context("could not get recipients")?;
|
||||||
|
|
||||||
let mut any_modified = false;
|
let mut any_modified = false;
|
||||||
|
let mut created = 0;
|
||||||
for recipient in recipients {
|
for recipient in recipients {
|
||||||
let recipient_addr = match ContactAddress::new(&recipient.addr) {
|
let recipient_addr = match ContactAddress::new(&recipient.addr) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -2528,12 +2534,15 @@ async fn add_all_recipients_as_contacts(
|
|||||||
if modified != Modifier::None {
|
if modified != Modifier::None {
|
||||||
any_modified = true;
|
any_modified = true;
|
||||||
}
|
}
|
||||||
|
if modified == Modifier::Created {
|
||||||
|
created += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if any_modified {
|
if any_modified {
|
||||||
context.emit_event(EventType::ContactsChanged(None));
|
context.emit_event(EventType::ContactsChanged(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(created)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ use crate::download::{download_msg, DownloadState};
|
|||||||
use crate::ephemeral::{self, delete_expired_imap_messages};
|
use crate::ephemeral::{self, delete_expired_imap_messages};
|
||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
use crate::imap::{session::Session, FolderMeaning, Imap};
|
use crate::imap::{session::Session, FolderMeaning, Imap};
|
||||||
use crate::location;
|
|
||||||
use crate::log::LogExt;
|
use crate::log::LogExt;
|
||||||
use crate::message::MsgId;
|
use crate::message::{Message, MsgId};
|
||||||
use crate::smtp::{send_smtp_messages, Smtp};
|
use crate::smtp::{send_smtp_messages, Smtp};
|
||||||
use crate::sql;
|
use crate::sql;
|
||||||
use crate::tools::{self, duration_to_str, maybe_add_time_based_warnings, time, time_elapsed};
|
use crate::tools::{self, duration_to_str, maybe_add_time_based_warnings, time, time_elapsed};
|
||||||
|
use crate::{chat, location};
|
||||||
|
|
||||||
pub(crate) mod connectivity;
|
pub(crate) mod connectivity;
|
||||||
|
|
||||||
@@ -514,9 +514,19 @@ async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session)
|
|||||||
warn!(ctx, "Can't set Config::FetchedExistingMsgs: {:#}", err);
|
warn!(ctx, "Can't set Config::FetchedExistingMsgs: {:#}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = imap.fetch_existing_msgs(ctx, &mut session).await {
|
match imap.fetch_existing_msgs(ctx, &mut session).await {
|
||||||
|
Err(err) => {
|
||||||
warn!(ctx, "Failed to fetch existing messages: {:#}", err);
|
warn!(ctx, "Failed to fetch existing messages: {:#}", err);
|
||||||
}
|
}
|
||||||
|
Ok(count) => {
|
||||||
|
let mut msg = Message::new_text(format!(
|
||||||
|
"Added {} contacts from outgoing chats",
|
||||||
|
count
|
||||||
|
));
|
||||||
|
|
||||||
|
chat::add_device_msg(ctx, None, Some(&mut msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user