Skip to content

Commit 6ad3f80

Browse files
committed
Mark message for deletion right after receiving it
1 parent 0b4d8f5 commit 6ad3f80

4 files changed

Lines changed: 31 additions & 37 deletions

File tree

src/config.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -623,19 +623,6 @@ impl Context {
623623
self.get_config_bool(Config::MdnsEnabled).await
624624
}
625625

626-
/// Gets configured "delete_server_after"
627-
///
628-
/// `None` means never delete the message, `Some(0)` means delete
629-
/// at once, `Some(x)` is never returned
630-
// TODO rename and refactor
631-
pub async fn get_config_delete_server_after(&self) -> Result<Option<i64>> {
632-
let val = match !self.get_config_bool(Config::BccSelf).await? && self.is_chatmail().await? {
633-
true => Some(0),
634-
false => None,
635-
};
636-
Ok(val)
637-
}
638-
639626
/// Gets the configured provider.
640627
///
641628
/// The provider is determined by the current primary transport.

src/ephemeral.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
//! the database entries which are expired either according to their
6262
//! ephemeral message timers.
6363
64-
use std::cmp::max;
6564
use std::collections::BTreeSet;
6665
use std::fmt;
6766
use std::num::ParseIntError;
@@ -652,34 +651,16 @@ pub(crate) async fn ephemeral_loop(context: &Context, interrupt_receiver: Receiv
652651
#[expect(clippy::arithmetic_side_effects)]
653652
pub(crate) async fn delete_expired_imap_messages(context: &Context) -> Result<()> {
654653
let now = time();
655-
// TODO if is_chatmail, but not bcc_self, then delete after downloading
656-
// apart from this, we may be able to remove the delete_server_after part
657-
658-
let (threshold_timestamp, threshold_timestamp_extended) =
659-
match context.get_config_delete_server_after().await? {
660-
None => (0, 0),
661-
Some(delete_server_after) => (
662-
match delete_server_after {
663-
// Guarantee immediate deletion.
664-
0 => i64::MAX,
665-
_ => now - delete_server_after,
666-
},
667-
now - max(delete_server_after, 48 * 60 * 60),
668-
),
669-
};
670-
671654
context
672655
.sql
673656
.execute(
674657
"UPDATE imap
675658
SET target=''
676659
WHERE rfc724_mid IN (
677660
SELECT rfc724_mid FROM msgs
678-
WHERE ((download_state = 0 AND timestamp < ?) OR
679-
(download_state != 0 AND timestamp < ?) OR
680-
(ephemeral_timestamp != 0 AND ephemeral_timestamp <= ?))
661+
WHERE ephemeral_timestamp != 0 AND ephemeral_timestamp <= ?
681662
)",
682-
(threshold_timestamp, threshold_timestamp_extended, now),
663+
(now,),
683664
)
684665
.await?;
685666

src/imap.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ impl Session {
12841284
if request_uids.is_empty() {
12851285
return Ok(());
12861286
}
1287+
let is_chatmail = self.is_chatmail();
12871288

12881289
for (request_uids, set) in build_sequence_sets(&request_uids)? {
12891290
info!(context, "Starting UID FETCH of message set \"{}\".", set);
@@ -1381,6 +1382,29 @@ impl Session {
13811382
"Passing message UID {} to receive_imf().", request_uid
13821383
);
13831384
let res = receive_imf_inner(context, rfc724_mid, body, is_seen).await;
1385+
1386+
// If the message is not needed anymore on the server, mark it for deletion:
1387+
info!(
1388+
context,
1389+
"dbg Marking for deletion?: bcc_self={}, is_chatmail={}",
1390+
context.get_config_bool(Config::BccSelf).await?,
1391+
is_chatmail
1392+
);
1393+
if !context.get_config_bool(Config::BccSelf).await? && is_chatmail {
1394+
info!(context, "dbg Marking {rfc724_mid} for deletion");
1395+
context
1396+
.sql
1397+
.execute(
1398+
&format!("UPDATE imap SET target='' WHERE rfc724_mid=?"),
1399+
(rfc724_mid,),
1400+
)
1401+
.await?;
1402+
context.scheduler.interrupt_inbox().await;
1403+
} else {
1404+
info!(context, "dbg NOT marking {rfc724_mid} for deletion");
1405+
}
1406+
1407+
// If there was an error receiving the message, show a device message:
13841408
let received_msg = match res {
13851409
Err(err) => {
13861410
warn!(context, "receive_imf error: {err:#}.");

src/receive_imf.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,12 @@ UPDATE config SET value=? WHERE keyname='configured_addr' AND value!=?1
904904
}
905905

906906
// Get user-configured server deletion
907-
let delete_server_after = context.get_config_delete_server_after().await?;
908-
909907
if !received_msg.msg_ids.is_empty() {
910-
let target = if received_msg.needs_delete_job || delete_server_after == Some(0) {
908+
info!(
909+
context,
910+
"dbg Would mark for deletion previously: rfc724_mid={rfc724_mid}, rfc724_mid_orig={rfc724_mid_orig}"
911+
);
912+
let target = if received_msg.needs_delete_job {
911913
Some("".to_string())
912914
} else {
913915
None

0 commit comments

Comments
 (0)