Clippy fixes
This commit is contained in:
17
crates/email/src/cache/email.rs
vendored
17
crates/email/src/cache/email.rs
vendored
@@ -33,18 +33,17 @@ pub(crate) async fn update_email_cache(
|
||||
};
|
||||
|
||||
for (document_id, is_update) in changed_ids {
|
||||
if *is_update {
|
||||
if let Some(archive) = server
|
||||
if *is_update
|
||||
&& let Some(archive) = server
|
||||
.get_archive(account_id, Collection::Email, *document_id)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
insert_item(
|
||||
&mut new_cache,
|
||||
*document_id,
|
||||
archive.to_unarchived::<MessageData>()?,
|
||||
);
|
||||
}
|
||||
{
|
||||
insert_item(
|
||||
&mut new_cache,
|
||||
*document_id,
|
||||
archive.to_unarchived::<MessageData>()?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
crates/email/src/cache/mailbox.rs
vendored
17
crates/email/src/cache/mailbox.rs
vendored
@@ -28,18 +28,17 @@ pub(crate) async fn update_mailbox_cache(
|
||||
};
|
||||
|
||||
for (document_id, is_update) in changed_ids {
|
||||
if *is_update {
|
||||
if let Some(archive) = server
|
||||
if *is_update
|
||||
&& let Some(archive) = server
|
||||
.get_archive(account_id, Collection::Mailbox, *document_id)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
insert_item(
|
||||
&mut new_cache,
|
||||
*document_id,
|
||||
archive.unarchive::<Mailbox>()?,
|
||||
);
|
||||
}
|
||||
{
|
||||
insert_item(
|
||||
&mut new_cache,
|
||||
*document_id,
|
||||
archive.unarchive::<Mailbox>()?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,23 +136,23 @@ impl EmailDeletion for Server {
|
||||
}
|
||||
|
||||
// Auto-expunge deleted and junk messages
|
||||
if let Some(hold_period) = self.core.jmap.mail_autoexpunge_after {
|
||||
if let Err(err) = self.emails_auto_expunge(account_id, hold_period).await {
|
||||
trc::error!(
|
||||
err.details("Failed to auto-expunge e-mail messages.")
|
||||
.account_id(account_id)
|
||||
);
|
||||
}
|
||||
if let Some(hold_period) = self.core.jmap.mail_autoexpunge_after
|
||||
&& let Err(err) = self.emails_auto_expunge(account_id, hold_period).await
|
||||
{
|
||||
trc::error!(
|
||||
err.details("Failed to auto-expunge e-mail messages.")
|
||||
.account_id(account_id)
|
||||
);
|
||||
}
|
||||
|
||||
// Auto-expunge iMIP messages
|
||||
if let Some(hold_period) = self.core.groupware.itip_inbox_auto_expunge {
|
||||
if let Err(err) = self.itip_auto_expunge(account_id, hold_period).await {
|
||||
trc::error!(
|
||||
err.details("Failed to auto-expunge iTIP messages.")
|
||||
.account_id(account_id)
|
||||
);
|
||||
}
|
||||
if let Some(hold_period) = self.core.groupware.itip_inbox_auto_expunge
|
||||
&& let Err(err) = self.itip_auto_expunge(account_id, hold_period).await
|
||||
{
|
||||
trc::error!(
|
||||
err.details("Failed to auto-expunge iTIP messages.")
|
||||
.account_id(account_id)
|
||||
);
|
||||
}
|
||||
|
||||
// Purge tombstoned messages
|
||||
@@ -164,13 +164,13 @@ impl EmailDeletion for Server {
|
||||
}
|
||||
|
||||
// Purge changelogs
|
||||
if let Some(history) = self.core.jmap.changes_max_history {
|
||||
if let Err(err) = self.delete_changes(account_id, history).await {
|
||||
trc::error!(
|
||||
err.details("Failed to purge changes.")
|
||||
.account_id(account_id)
|
||||
);
|
||||
}
|
||||
if let Some(history) = self.core.jmap.changes_max_history
|
||||
&& let Err(err) = self.delete_changes(account_id, history).await
|
||||
{
|
||||
trc::error!(
|
||||
err.details("Failed to purge changes.")
|
||||
.account_id(account_id)
|
||||
);
|
||||
}
|
||||
|
||||
// Delete lock
|
||||
|
||||
@@ -205,38 +205,36 @@ impl EmailIngest for Server {
|
||||
}
|
||||
|
||||
// If the message is classified as spam, check whether the sender address is present in the user's address book
|
||||
if is_spam && self.core.spam.card_is_ham {
|
||||
if let Some(sender) = message
|
||||
if is_spam
|
||||
&& self.core.spam.card_is_ham
|
||||
&& let Some(sender) = message
|
||||
.from()
|
||||
.and_then(|s| s.first())
|
||||
.and_then(|s| s.address())
|
||||
.and_then(sanitize_email)
|
||||
&& sender != deliver_to
|
||||
&& is_sender_authenticated
|
||||
&& !self
|
||||
.store()
|
||||
.filter(
|
||||
account_id,
|
||||
Collection::ContactCard,
|
||||
vec![Filter::eq(IDX_EMAIL, sender.into_bytes())],
|
||||
)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
.results
|
||||
.is_empty()
|
||||
{
|
||||
is_spam = false;
|
||||
if self
|
||||
.core
|
||||
.spam
|
||||
.bayes
|
||||
.as_ref()
|
||||
.is_some_and(|config| config.auto_learn_card_is_ham)
|
||||
{
|
||||
if sender != deliver_to
|
||||
&& is_sender_authenticated
|
||||
&& !self
|
||||
.store()
|
||||
.filter(
|
||||
account_id,
|
||||
Collection::ContactCard,
|
||||
vec![Filter::eq(IDX_EMAIL, sender.into_bytes())],
|
||||
)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
.results
|
||||
.is_empty()
|
||||
{
|
||||
is_spam = false;
|
||||
if self
|
||||
.core
|
||||
.spam
|
||||
.bayes
|
||||
.as_ref()
|
||||
.is_some_and(|config| config.auto_learn_card_is_ham)
|
||||
{
|
||||
train_spam = Some(false);
|
||||
}
|
||||
}
|
||||
train_spam = Some(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,75 +313,72 @@ impl EmailIngest for Server {
|
||||
.subtype()
|
||||
.is_some_and(|st| st.eq_ignore_ascii_case("calendar"))
|
||||
&& ct.has_attribute("method")
|
||||
}) {
|
||||
if let Some(itip_message) = part.text_contents() {
|
||||
if itip_message.len()
|
||||
< self.core.groupware.itip_inbound_max_ical_size
|
||||
{
|
||||
if let Some(sender) = sender.get_or_insert_with(|| {
|
||||
message
|
||||
.from()
|
||||
.and_then(|s| s.first())
|
||||
.and_then(|s| s.address())
|
||||
.and_then(sanitize_email)
|
||||
}) {
|
||||
match self
|
||||
.itip_ingest(
|
||||
params.access_token,
|
||||
&resource_token,
|
||||
sender,
|
||||
itip_message,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(message) => {
|
||||
if let Some(message) = message {
|
||||
itip_messages.push(message);
|
||||
}
|
||||
trc::event!(
|
||||
Calendar(
|
||||
trc::CalendarEvent::ItipMessageReceived
|
||||
),
|
||||
SpanId = params.session_id,
|
||||
From = sender.to_string(),
|
||||
AccountId = account_id,
|
||||
);
|
||||
}) && let Some(itip_message) = part.text_contents()
|
||||
{
|
||||
if itip_message.len() < self.core.groupware.itip_inbound_max_ical_size {
|
||||
if let Some(sender) = sender.get_or_insert_with(|| {
|
||||
message
|
||||
.from()
|
||||
.and_then(|s| s.first())
|
||||
.and_then(|s| s.address())
|
||||
.and_then(sanitize_email)
|
||||
}) {
|
||||
match self
|
||||
.itip_ingest(
|
||||
params.access_token,
|
||||
&resource_token,
|
||||
sender,
|
||||
itip_message,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(message) => {
|
||||
if let Some(message) = message {
|
||||
itip_messages.push(message);
|
||||
}
|
||||
Err(ItipIngestError::Message(itip_error)) => {
|
||||
match itip_error {
|
||||
ItipError::NothingToSend
|
||||
| ItipError::OtherSchedulingAgent => (),
|
||||
err => {
|
||||
trc::event!(
|
||||
Calendar(trc::CalendarEvent::ItipMessageError),
|
||||
SpanId = params.session_id,
|
||||
From = sender.to_string(),
|
||||
AccountId = account_id,
|
||||
Details = err.to_string(),
|
||||
)
|
||||
}
|
||||
trc::event!(
|
||||
Calendar(trc::CalendarEvent::ItipMessageReceived),
|
||||
SpanId = params.session_id,
|
||||
From = sender.to_string(),
|
||||
AccountId = account_id,
|
||||
);
|
||||
}
|
||||
Err(ItipIngestError::Message(itip_error)) => {
|
||||
match itip_error {
|
||||
ItipError::NothingToSend
|
||||
| ItipError::OtherSchedulingAgent => (),
|
||||
err => {
|
||||
trc::event!(
|
||||
Calendar(
|
||||
trc::CalendarEvent::ItipMessageError
|
||||
),
|
||||
SpanId = params.session_id,
|
||||
From = sender.to_string(),
|
||||
AccountId = account_id,
|
||||
Details = err.to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
Err(ItipIngestError::Internal(err)) => {
|
||||
trc::error!(err.caused_by(trc::location!()));
|
||||
}
|
||||
}
|
||||
Err(ItipIngestError::Internal(err)) => {
|
||||
trc::error!(err.caused_by(trc::location!()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trc::event!(
|
||||
Calendar(trc::CalendarEvent::ItipMessageError),
|
||||
SpanId = params.session_id,
|
||||
From = message
|
||||
.from()
|
||||
.and_then(|a| a.first())
|
||||
.and_then(|a| a.address())
|
||||
.map(|a| a.to_string()),
|
||||
AccountId = account_id,
|
||||
Details = "iMIP message too large",
|
||||
Limit = self.core.groupware.itip_inbound_max_ical_size,
|
||||
Size = itip_message.len(),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
trc::event!(
|
||||
Calendar(trc::CalendarEvent::ItipMessageError),
|
||||
SpanId = params.session_id,
|
||||
From = message
|
||||
.from()
|
||||
.and_then(|a| a.first())
|
||||
.and_then(|a| a.address())
|
||||
.map(|a| a.to_string()),
|
||||
AccountId = account_id,
|
||||
Details = "iMIP message too large",
|
||||
Limit = self.core.groupware.itip_inbound_max_ical_size,
|
||||
Size = itip_message.len(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,12 +510,12 @@ impl EmailIngest for Server {
|
||||
part.offset_end += offset_start as u32;
|
||||
part.offset_header += offset_start as u32;
|
||||
|
||||
if let PartType::Message(sub_message) = &mut part.body {
|
||||
if sub_message.root_part().offset_header != 0 {
|
||||
sub_message.raw_message = raw_message.as_ref().into();
|
||||
part_iter_stack.push(part_iter);
|
||||
part_iter = sub_message.parts.iter_mut();
|
||||
}
|
||||
if let PartType::Message(sub_message) = &mut part.body
|
||||
&& sub_message.root_part().offset_header != 0
|
||||
{
|
||||
sub_message.raw_message = raw_message.as_ref().into();
|
||||
part_iter_stack.push(part_iter);
|
||||
part_iter = sub_message.parts.iter_mut();
|
||||
}
|
||||
} else if let Some(iter) = part_iter_stack.pop() {
|
||||
part_iter = iter;
|
||||
@@ -544,56 +539,56 @@ impl EmailIngest for Server {
|
||||
IngestSource::Smtp { .. } => self.core.jmap.encrypt,
|
||||
IngestSource::Restore => false,
|
||||
};
|
||||
if do_encrypt && !message.is_encrypted() {
|
||||
if let Some(encrypt_params_) = self
|
||||
if do_encrypt
|
||||
&& !message.is_encrypted()
|
||||
&& let Some(encrypt_params_) = self
|
||||
.get_archive_by_property(account_id, Collection::Principal, 0, Property::Parameters)
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
let encrypt_params = encrypt_params_
|
||||
.unarchive::<EncryptionParams>()
|
||||
.caused_by(trc::location!())?;
|
||||
match message.encrypt(encrypt_params).await {
|
||||
Ok(new_raw_message) => {
|
||||
raw_message = Cow::from(new_raw_message);
|
||||
raw_message_len = raw_message.len() as u64;
|
||||
message = MessageParser::default()
|
||||
.parse(raw_message.as_ref())
|
||||
.ok_or_else(|| {
|
||||
trc::EventType::MessageIngest(trc::MessageIngestEvent::Error)
|
||||
.ctx(trc::Key::Code, 550)
|
||||
.ctx(
|
||||
trc::Key::Reason,
|
||||
"Failed to parse encrypted e-mail message.",
|
||||
)
|
||||
})?;
|
||||
{
|
||||
let encrypt_params = encrypt_params_
|
||||
.unarchive::<EncryptionParams>()
|
||||
.caused_by(trc::location!())?;
|
||||
match message.encrypt(encrypt_params).await {
|
||||
Ok(new_raw_message) => {
|
||||
raw_message = Cow::from(new_raw_message);
|
||||
raw_message_len = raw_message.len() as u64;
|
||||
message = MessageParser::default()
|
||||
.parse(raw_message.as_ref())
|
||||
.ok_or_else(|| {
|
||||
trc::EventType::MessageIngest(trc::MessageIngestEvent::Error)
|
||||
.ctx(trc::Key::Code, 550)
|
||||
.ctx(
|
||||
trc::Key::Reason,
|
||||
"Failed to parse encrypted e-mail message.",
|
||||
)
|
||||
})?;
|
||||
|
||||
// Remove contents from parsed message
|
||||
for part in &mut message.parts {
|
||||
match &mut part.body {
|
||||
PartType::Text(txt) | PartType::Html(txt) => {
|
||||
*txt = Cow::from("");
|
||||
}
|
||||
PartType::Binary(bin) | PartType::InlineBinary(bin) => {
|
||||
*bin = Cow::from(&[][..]);
|
||||
}
|
||||
PartType::Message(_) => {
|
||||
part.body = PartType::Binary(Cow::from(&[][..]));
|
||||
}
|
||||
PartType::Multipart(_) => (),
|
||||
// Remove contents from parsed message
|
||||
for part in &mut message.parts {
|
||||
match &mut part.body {
|
||||
PartType::Text(txt) | PartType::Html(txt) => {
|
||||
*txt = Cow::from("");
|
||||
}
|
||||
PartType::Binary(bin) | PartType::InlineBinary(bin) => {
|
||||
*bin = Cow::from(&[][..]);
|
||||
}
|
||||
PartType::Message(_) => {
|
||||
part.body = PartType::Binary(Cow::from(&[][..]));
|
||||
}
|
||||
PartType::Multipart(_) => (),
|
||||
}
|
||||
}
|
||||
Err(EncryptMessageError::Error(err)) => {
|
||||
trc::bail!(
|
||||
trc::StoreEvent::CryptoError
|
||||
.into_err()
|
||||
.caused_by(trc::location!())
|
||||
.reason(err)
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Err(EncryptMessageError::Error(err)) => {
|
||||
trc::bail!(
|
||||
trc::StoreEvent::CryptoError
|
||||
.into_err()
|
||||
.caused_by(trc::location!())
|
||||
.reason(err)
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,26 +78,25 @@ impl SieveScriptActivate for Server {
|
||||
}
|
||||
|
||||
// Activate script
|
||||
if let Some(document_id) = activate_id {
|
||||
if let Some(sieve_) = self
|
||||
if let Some(document_id) = activate_id
|
||||
&& let Some(sieve_) = self
|
||||
.get_archive(account_id, Collection::SieveScript, document_id)
|
||||
.await?
|
||||
{
|
||||
let sieve = sieve_
|
||||
.to_unarchived::<SieveScript>()
|
||||
.caused_by(trc::location!())?;
|
||||
let mut new_sieve = sieve.deserialize().caused_by(trc::location!())?;
|
||||
new_sieve.is_active = true;
|
||||
batch
|
||||
.update_document(document_id)
|
||||
.custom(
|
||||
ObjectIndexBuilder::new()
|
||||
.with_changes(new_sieve)
|
||||
.with_current(sieve),
|
||||
)
|
||||
.caused_by(trc::location!())?;
|
||||
changed_ids.push((document_id, true));
|
||||
}
|
||||
{
|
||||
let sieve = sieve_
|
||||
.to_unarchived::<SieveScript>()
|
||||
.caused_by(trc::location!())?;
|
||||
let mut new_sieve = sieve.deserialize().caused_by(trc::location!())?;
|
||||
new_sieve.is_active = true;
|
||||
batch
|
||||
.update_document(document_id)
|
||||
.custom(
|
||||
ObjectIndexBuilder::new()
|
||||
.with_changes(new_sieve)
|
||||
.with_current(sieve),
|
||||
)
|
||||
.caused_by(trc::location!())?;
|
||||
changed_ids.push((document_id, true));
|
||||
}
|
||||
|
||||
// Write changes
|
||||
|
||||
@@ -186,10 +186,10 @@ impl SieveScriptIngest for Server {
|
||||
TRASH_ID
|
||||
} else {
|
||||
let mut mailbox_id = u32::MAX;
|
||||
if let Ok(role) = SpecialUse::parse_value(&role) {
|
||||
if let Some(m) = cache.mailbox_by_role(&role) {
|
||||
mailbox_id = m.document_id;
|
||||
}
|
||||
if let Ok(role) = SpecialUse::parse_value(&role)
|
||||
&& let Some(m) = cache.mailbox_by_role(&role)
|
||||
{
|
||||
mailbox_id = m.document_id;
|
||||
}
|
||||
|
||||
mailbox_id
|
||||
@@ -317,17 +317,17 @@ impl SieveScriptIngest for Server {
|
||||
}
|
||||
|
||||
// Find mailbox by role
|
||||
if let Some(special_use) = special_use {
|
||||
if target_id == u32::MAX {
|
||||
if special_use.eq_ignore_ascii_case("inbox") {
|
||||
target_id = INBOX_ID;
|
||||
} else if special_use.eq_ignore_ascii_case("trash") {
|
||||
target_id = TRASH_ID;
|
||||
} else if let Ok(role) = SpecialUse::parse_value(&special_use) {
|
||||
if let Some(item) = cache.mailbox_by_role(&role) {
|
||||
target_id = item.document_id;
|
||||
}
|
||||
}
|
||||
if let Some(special_use) = special_use
|
||||
&& target_id == u32::MAX
|
||||
{
|
||||
if special_use.eq_ignore_ascii_case("inbox") {
|
||||
target_id = INBOX_ID;
|
||||
} else if special_use.eq_ignore_ascii_case("trash") {
|
||||
target_id = TRASH_ID;
|
||||
} else if let Ok(role) = SpecialUse::parse_value(&special_use)
|
||||
&& let Some(item) = cache.mailbox_by_role(&role)
|
||||
{
|
||||
target_id = item.document_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user