mirror of
https://github.com/chatmail/core.git
synced 2026-05-13 03:46:32 +03:00
Mark message for deletion right after receiving it
This commit is contained in:
@@ -623,19 +623,6 @@ impl Context {
|
|||||||
self.get_config_bool(Config::MdnsEnabled).await
|
self.get_config_bool(Config::MdnsEnabled).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets configured "delete_server_after"
|
|
||||||
///
|
|
||||||
/// `None` means never delete the message, `Some(0)` means delete
|
|
||||||
/// at once, `Some(x)` is never returned
|
|
||||||
// TODO rename and refactor
|
|
||||||
pub async fn get_config_delete_server_after(&self) -> Result<Option<i64>> {
|
|
||||||
let val = match !self.get_config_bool(Config::BccSelf).await? && self.is_chatmail().await? {
|
|
||||||
true => Some(0),
|
|
||||||
false => None,
|
|
||||||
};
|
|
||||||
Ok(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the configured provider.
|
/// Gets the configured provider.
|
||||||
///
|
///
|
||||||
/// The provider is determined by the current primary transport.
|
/// The provider is determined by the current primary transport.
|
||||||
|
|||||||
@@ -61,7 +61,6 @@
|
|||||||
//! the database entries which are expired either according to their
|
//! the database entries which are expired either according to their
|
||||||
//! ephemeral message timers.
|
//! ephemeral message timers.
|
||||||
|
|
||||||
use std::cmp::max;
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
@@ -652,22 +651,6 @@ pub(crate) async fn ephemeral_loop(context: &Context, interrupt_receiver: Receiv
|
|||||||
#[expect(clippy::arithmetic_side_effects)]
|
#[expect(clippy::arithmetic_side_effects)]
|
||||||
pub(crate) async fn delete_expired_imap_messages(context: &Context) -> Result<()> {
|
pub(crate) async fn delete_expired_imap_messages(context: &Context) -> Result<()> {
|
||||||
let now = time();
|
let now = time();
|
||||||
// TODO if is_chatmail, but not bcc_self, then delete after downloading
|
|
||||||
// apart from this, we may be able to remove the delete_server_after part
|
|
||||||
|
|
||||||
let (threshold_timestamp, threshold_timestamp_extended) =
|
|
||||||
match context.get_config_delete_server_after().await? {
|
|
||||||
None => (0, 0),
|
|
||||||
Some(delete_server_after) => (
|
|
||||||
match delete_server_after {
|
|
||||||
// Guarantee immediate deletion.
|
|
||||||
0 => i64::MAX,
|
|
||||||
_ => now - delete_server_after,
|
|
||||||
},
|
|
||||||
now - max(delete_server_after, 48 * 60 * 60),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
@@ -675,11 +658,9 @@ pub(crate) async fn delete_expired_imap_messages(context: &Context) -> Result<()
|
|||||||
SET target=''
|
SET target=''
|
||||||
WHERE rfc724_mid IN (
|
WHERE rfc724_mid IN (
|
||||||
SELECT rfc724_mid FROM msgs
|
SELECT rfc724_mid FROM msgs
|
||||||
WHERE ((download_state = 0 AND timestamp < ?) OR
|
WHERE ephemeral_timestamp != 0 AND ephemeral_timestamp <= ?
|
||||||
(download_state != 0 AND timestamp < ?) OR
|
|
||||||
(ephemeral_timestamp != 0 AND ephemeral_timestamp <= ?))
|
|
||||||
)",
|
)",
|
||||||
(threshold_timestamp, threshold_timestamp_extended, now),
|
(now,),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
24
src/imap.rs
24
src/imap.rs
@@ -1284,6 +1284,7 @@ impl Session {
|
|||||||
if request_uids.is_empty() {
|
if request_uids.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
let is_chatmail = self.is_chatmail();
|
||||||
|
|
||||||
for (request_uids, set) in build_sequence_sets(&request_uids)? {
|
for (request_uids, set) in build_sequence_sets(&request_uids)? {
|
||||||
info!(context, "Starting UID FETCH of message set \"{}\".", set);
|
info!(context, "Starting UID FETCH of message set \"{}\".", set);
|
||||||
@@ -1381,6 +1382,29 @@ impl Session {
|
|||||||
"Passing message UID {} to receive_imf().", request_uid
|
"Passing message UID {} to receive_imf().", request_uid
|
||||||
);
|
);
|
||||||
let res = receive_imf_inner(context, rfc724_mid, body, is_seen).await;
|
let res = receive_imf_inner(context, rfc724_mid, body, is_seen).await;
|
||||||
|
|
||||||
|
// If the message is not needed anymore on the server, mark it for deletion:
|
||||||
|
info!(
|
||||||
|
context,
|
||||||
|
"dbg Marking for deletion?: bcc_self={}, is_chatmail={}",
|
||||||
|
context.get_config_bool(Config::BccSelf).await?,
|
||||||
|
is_chatmail
|
||||||
|
);
|
||||||
|
if !context.get_config_bool(Config::BccSelf).await? && is_chatmail {
|
||||||
|
info!(context, "dbg Marking {rfc724_mid} for deletion");
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.execute(
|
||||||
|
&format!("UPDATE imap SET target='' WHERE rfc724_mid=?"),
|
||||||
|
(rfc724_mid,),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
context.scheduler.interrupt_inbox().await;
|
||||||
|
} else {
|
||||||
|
info!(context, "dbg NOT marking {rfc724_mid} for deletion");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there was an error receiving the message, show a device message:
|
||||||
let received_msg = match res {
|
let received_msg = match res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(context, "receive_imf error: {err:#}.");
|
warn!(context, "receive_imf error: {err:#}.");
|
||||||
|
|||||||
@@ -904,10 +904,12 @@ UPDATE config SET value=? WHERE keyname='configured_addr' AND value!=?1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get user-configured server deletion
|
// Get user-configured server deletion
|
||||||
let delete_server_after = context.get_config_delete_server_after().await?;
|
|
||||||
|
|
||||||
if !received_msg.msg_ids.is_empty() {
|
if !received_msg.msg_ids.is_empty() {
|
||||||
let target = if received_msg.needs_delete_job || delete_server_after == Some(0) {
|
info!(
|
||||||
|
context,
|
||||||
|
"dbg Would mark for deletion previously: rfc724_mid={rfc724_mid}, rfc724_mid_orig={rfc724_mid_orig}"
|
||||||
|
);
|
||||||
|
let target = if received_msg.needs_delete_job {
|
||||||
Some("".to_string())
|
Some("".to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user