Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add device message for imported contacts after configuration #6195

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,16 @@ impl Imap {
&mut self,
context: &Context,
session: &mut Session,
) -> Result<()> {
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder)
.await
.context("failed to get recipients from the sentbox")?;
add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder)
) -> Result<i32> {
let mut created = 0;
created +=
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder)
.await
.context("failed to get recipients from the sentbox")?;
created += add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder)
.await
.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
.context("failed to get recipients from the inbox")?;

Expand All @@ -802,7 +804,7 @@ impl Imap {
}

info!(context, "Done fetching existing messages.");
Ok(())
Ok(created)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the device message right from this function? Otherwise it's strange that the function returns smth very particular, it's about messages, but returns the number of contacts

}
}

Expand Down Expand Up @@ -2479,19 +2481,22 @@ impl std::fmt::Display for UidRange {
}
}
}

/// Add all recipients as contacts.
/// Returns how many contacts were created.
async fn add_all_recipients_as_contacts(
context: &Context,
session: &mut Session,
folder: Config,
) -> Result<()> {
) -> Result<i32> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather say it should be usize, but at least unsigned.

let mailbox = if let Some(m) = context.get_config(folder).await? {
m
} else {
info!(
context,
"Folder {} is not configured, skipping fetching contacts from it.", folder
);
return Ok(());
return Ok(0);
};
session
.select_with_uidvalidity(context, &mailbox)
Expand All @@ -2504,6 +2509,7 @@ async fn add_all_recipients_as_contacts(
.context("could not get recipients")?;

let mut any_modified = false;
let mut created = 0;
for recipient in recipients {
let recipient_addr = match ContactAddress::new(&recipient.addr) {
Err(err) => {
Expand All @@ -2528,12 +2534,15 @@ async fn add_all_recipients_as_contacts(
if modified != Modifier::None {
any_modified = true;
}
if modified == Modifier::Created {
created += 1;
}
}
if any_modified {
context.emit_event(EventType::ContactsChanged(None));
}

Ok(())
Ok(created)
}

#[cfg(test)]
Expand Down
18 changes: 14 additions & 4 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use crate::download::{download_msg, DownloadState};
use crate::ephemeral::{self, delete_expired_imap_messages};
use crate::events::EventType;
use crate::imap::{session::Session, FolderMeaning, Imap};
use crate::location;
use crate::log::LogExt;
use crate::message::MsgId;
use crate::message::{Message, MsgId};
use crate::smtp::{send_smtp_messages, Smtp};
use crate::sql;
use crate::tools::{self, duration_to_str, maybe_add_time_based_warnings, time, time_elapsed};
use crate::{chat, location};

pub(crate) mod connectivity;

Expand Down Expand Up @@ -514,8 +514,18 @@ async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session)
warn!(ctx, "Can't set Config::FetchedExistingMsgs: {:#}", err);
}

if let Err(err) = imap.fetch_existing_msgs(ctx, &mut session).await {
warn!(ctx, "Failed to fetch existing messages: {:#}", err);
match imap.fetch_existing_msgs(ctx, &mut session).await {
Err(err) => {
warn!(ctx, "Failed to fetch existing messages: {:#}", err);
}
Ok(count) => {
let mut msg = Message::new_text(format!(
"Added {} contacts from outgoing chats",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Added {} contacts from outgoing chats",
"Added {} contacts from outgoing messages.",

It seems we don't have the term "outgoing chat", at least i don't see it in the core code / Delta Chat FAQ.

count
));
Comment on lines +522 to +525
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a translated message


chat::add_device_msg(ctx, None, Some(&mut msg)).await?;
}
}
}
}
Expand Down
Loading