mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 18:36:30 +03:00
Delete BCC-self messages after "delete_server_after" time
This commit is contained in:
@@ -1307,14 +1307,48 @@ fn precheck_imf(context: &Context, rfc724_mid: &str, server_folder: &str, server
|
||||
{
|
||||
if old_server_folder.is_empty() && old_server_uid == 0 {
|
||||
info!(context, "[move] detected bcc-self {}", rfc724_mid,);
|
||||
context.do_heuristics_moves(server_folder.as_ref(), msg_id);
|
||||
job_add(
|
||||
context,
|
||||
Action::MarkseenMsgOnImap,
|
||||
msg_id.to_u32() as i32,
|
||||
Params::new(),
|
||||
0,
|
||||
);
|
||||
|
||||
let delete_server_after = context.get_config_int(Config::DeleteServerAfter);
|
||||
|
||||
if delete_server_after != 0 {
|
||||
context.do_heuristics_moves(server_folder.as_ref(), msg_id);
|
||||
job_add(
|
||||
context,
|
||||
Action::MarkseenMsgOnImap,
|
||||
msg_id.to_u32() as i32,
|
||||
Params::new(),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
if delete_server_after >= 0 {
|
||||
info!(
|
||||
context,
|
||||
"Scheduling BCC-self deletion in {} seconds", delete_server_after
|
||||
);
|
||||
|
||||
let msg_ids = match message::get_all_by_rfc724_mid(context, &rfc724_mid) {
|
||||
Err(err) => {
|
||||
warn!(
|
||||
context,
|
||||
"Cannot get all database records for Message-ID {}: {}",
|
||||
&rfc724_mid,
|
||||
err
|
||||
);
|
||||
vec![msg_id] // Remove at least the MsgId we know about
|
||||
}
|
||||
Ok(msg_ids) => msg_ids,
|
||||
};
|
||||
for part_msg_id in msg_ids {
|
||||
job_add(
|
||||
context,
|
||||
Action::DeleteMsgOnImap,
|
||||
part_msg_id.to_u32() as i32,
|
||||
Params::new(),
|
||||
delete_server_after as i64,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if old_server_folder != server_folder {
|
||||
info!(context, "[move] detected moved message {}", rfc724_mid,);
|
||||
}
|
||||
|
||||
@@ -1411,6 +1411,28 @@ pub(crate) fn rfc724_mid_exists(
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Returns all MsgIds corresponding to Message-ID
|
||||
pub(crate) fn get_all_by_rfc724_mid(
|
||||
context: &Context,
|
||||
rfc724_mid: &str,
|
||||
) -> Result<Vec<MsgId>, Error> {
|
||||
ensure!(!rfc724_mid.is_empty(), "empty rfc724_mid");
|
||||
|
||||
let msg_ids = context.sql.query_map(
|
||||
"SELECT id FROM msgs WHERE rfc724_mid=?",
|
||||
params![rfc724_mid],
|
||||
|row| row.get::<_, MsgId>("id"),
|
||||
|ids| {
|
||||
let mut ret: Vec<MsgId> = Vec::new();
|
||||
for id in ids {
|
||||
ret.push(id?);
|
||||
}
|
||||
Ok(ret)
|
||||
},
|
||||
)?;
|
||||
Ok(msg_ids)
|
||||
}
|
||||
|
||||
pub fn update_server_uid(
|
||||
context: &Context,
|
||||
rfc724_mid: &str,
|
||||
|
||||
Reference in New Issue
Block a user