mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
imap: resultify add_all_recipients_as_contacts()
This commit is contained in:
80
src/imap.rs
80
src/imap.rs
@@ -919,9 +919,9 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
self.prepare(context).await.context("could not connect")?;
|
self.prepare(context).await.context("could not connect")?;
|
||||||
|
|
||||||
add_all_recipients_as_contacts(context, self, Config::ConfiguredSentboxFolder).await;
|
add_all_recipients_as_contacts(context, self, Config::ConfiguredSentboxFolder).await?;
|
||||||
add_all_recipients_as_contacts(context, self, Config::ConfiguredMvboxFolder).await;
|
add_all_recipients_as_contacts(context, self, Config::ConfiguredMvboxFolder).await?;
|
||||||
add_all_recipients_as_contacts(context, self, Config::ConfiguredInboxFolder).await;
|
add_all_recipients_as_contacts(context, self, Config::ConfiguredInboxFolder).await?;
|
||||||
|
|
||||||
if context.get_config_bool(Config::FetchExistingMsgs).await? {
|
if context.get_config_bool(Config::FetchExistingMsgs).await? {
|
||||||
for config in &[
|
for config in &[
|
||||||
@@ -2334,49 +2334,47 @@ impl std::fmt::Display for UidRange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn add_all_recipients_as_contacts(context: &Context, imap: &mut Imap, folder: Config) {
|
|
||||||
let mailbox = if let Ok(Some(m)) = context.get_config(folder).await {
|
async fn add_all_recipients_as_contacts(
|
||||||
|
context: &Context,
|
||||||
|
imap: &mut Imap,
|
||||||
|
folder: Config,
|
||||||
|
) -> Result<()> {
|
||||||
|
let mailbox = if let Some(m) = context.get_config(folder).await? {
|
||||||
m
|
m
|
||||||
} else {
|
} else {
|
||||||
return;
|
return Ok(());
|
||||||
};
|
};
|
||||||
if let Err(e) = imap.select_with_uidvalidity(context, &mailbox).await {
|
imap.select_with_uidvalidity(context, &mailbox).await?;
|
||||||
// We are using Anyhow's .context() and to show the inner error, too, we need the {:#}:
|
let contacts = imap
|
||||||
warn!(context, "Could not select {}: {:#}", mailbox, e);
|
.get_all_recipients(context)
|
||||||
return;
|
.await
|
||||||
}
|
.context("could not get recipients")?;
|
||||||
match imap.get_all_recipients(context).await {
|
|
||||||
Ok(contacts) => {
|
|
||||||
let mut any_modified = false;
|
|
||||||
for contact in contacts {
|
|
||||||
let display_name_normalized = contact
|
|
||||||
.display_name
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| normalize_name(s))
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
match Contact::add_or_lookup(
|
let mut any_modified = false;
|
||||||
context,
|
for contact in contacts {
|
||||||
&display_name_normalized,
|
let display_name_normalized = contact
|
||||||
&contact.addr,
|
.display_name
|
||||||
Origin::OutgoingTo,
|
.as_ref()
|
||||||
)
|
.map(|s| normalize_name(s))
|
||||||
.await
|
.unwrap_or_default();
|
||||||
{
|
|
||||||
Ok((_, modified)) => {
|
let (_, modified) = Contact::add_or_lookup(
|
||||||
if modified != Modifier::None {
|
context,
|
||||||
any_modified = true;
|
&display_name_normalized,
|
||||||
}
|
&contact.addr,
|
||||||
}
|
Origin::OutgoingTo,
|
||||||
Err(e) => warn!(context, "Could not add recipient: {}", e),
|
)
|
||||||
}
|
.await
|
||||||
}
|
.context("could not add recipient")?;
|
||||||
if any_modified {
|
if modified != Modifier::None {
|
||||||
context.emit_event(EventType::ContactsChanged(None));
|
any_modified = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => warn!(context, "Could not add recipients: {}", e),
|
}
|
||||||
};
|
if any_modified {
|
||||||
|
context.emit_event(EventType::ContactsChanged(None));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user