mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
Compare commits
3 Commits
link2xt/pr
...
hoc/stats-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0dd4edd4e6 | ||
|
|
0df7cc2612 | ||
|
|
24876f92aa |
@@ -473,7 +473,6 @@ mod tests {
|
||||
add_contact_to_chat, create_broadcast, create_group, get_chat_contacts,
|
||||
remove_contact_from_chat, send_text_msg, set_chat_name,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::receive_imf::receive_imf;
|
||||
use crate::securejoin::get_securejoin_qr;
|
||||
use crate::stock_str::StockMessage;
|
||||
@@ -666,7 +665,6 @@ mod tests {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_search_single_chat() -> anyhow::Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
t.set_config(Config::ProcessUnencrypted, Some("1")).await?;
|
||||
|
||||
// receive a one-to-one-message
|
||||
receive_imf(
|
||||
@@ -727,7 +725,6 @@ mod tests {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_search_single_chat_without_authname() -> anyhow::Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
t.set_config(Config::ProcessUnencrypted, Some("1")).await?;
|
||||
|
||||
// receive a one-to-one-message without authname set
|
||||
receive_imf(
|
||||
|
||||
@@ -486,11 +486,6 @@ pub enum Config {
|
||||
/// Experimental option denoting that the current profile is shared between multiple team members.
|
||||
/// For now, the only effect of this option is that seen flags are not synchronized.
|
||||
TeamProfile,
|
||||
|
||||
/// Process unencrypted messages.
|
||||
///
|
||||
/// Unencrypted messages are fetched and processed only if this setting is explicitly enabled.
|
||||
ProcessUnencrypted,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
||||
@@ -1056,12 +1056,6 @@ impl Context {
|
||||
"team_profile",
|
||||
self.get_config_bool(Config::TeamProfile).await?.to_string(),
|
||||
);
|
||||
res.insert(
|
||||
"process_unencrypted",
|
||||
self.get_config_bool(Config::ProcessUnencrypted)
|
||||
.await?
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let elapsed = time_elapsed(&self.creation_time);
|
||||
res.insert("uptime", duration_to_str(elapsed));
|
||||
|
||||
11
src/imap.rs
11
src/imap.rs
@@ -1996,21 +1996,12 @@ pub(crate) async fn prefetch_should_download(
|
||||
// prevent_rename=true as this might be a mailing list message and in this case it would be bad if we rename the contact.
|
||||
// (prevent_rename is the last argument of from_field_to_contact_id())
|
||||
|
||||
let is_encrypted = if let Some(content_type) = headers.get_header_value(HeaderDef::ContentType)
|
||||
{
|
||||
mailparse::parse_content_type(&content_type).mimetype == "multipart/encrypted"
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if flags.any(|f| f == Flag::Draft) {
|
||||
info!(context, "Ignoring draft message");
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let should_download = maybe_ndn
|
||||
|| (!blocked_contact
|
||||
&& (is_encrypted || context.get_config_bool(Config::ProcessUnencrypted).await?));
|
||||
let should_download = !blocked_contact || maybe_ndn;
|
||||
Ok(should_download)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ const PREFETCH_FLAGS: &str = "(UID RFC822.SIZE BODY.PEEK[HEADER.FIELDS (\
|
||||
DATE \
|
||||
X-MICROSOFT-ORIGINAL-MESSAGE-ID \
|
||||
FROM \
|
||||
CONTENT-TYPE \
|
||||
CHAT-VERSION \
|
||||
CHAT-IS-POST-MESSAGE \
|
||||
AUTOCRYPT-SETUP-MESSAGE\
|
||||
|
||||
@@ -505,11 +505,6 @@ pub(crate) async fn receive_imf_inner(
|
||||
Ok(mime_parser) => mime_parser,
|
||||
};
|
||||
|
||||
if !mime_parser.was_encrypted() && !context.get_config_bool(Config::ProcessUnencrypted).await? {
|
||||
warn!(context, "Fetched unencrypted message, ignoring");
|
||||
return trash().await;
|
||||
}
|
||||
|
||||
let rfc724_mid_orig = &mime_parser
|
||||
.get_rfc724_mid()
|
||||
.unwrap_or(rfc724_mid.to_string());
|
||||
|
||||
@@ -29,6 +29,7 @@ const STATISTICS_BOT_VCARD: &str = include_str!("../assets/statistics-bot.vcf");
|
||||
const SENDING_INTERVAL_SECONDS: i64 = 3600 * 24 * 7; // 1 week
|
||||
// const SENDING_INTERVAL_SECONDS: i64 = 60; // 1 minute (for testing)
|
||||
const MESSAGE_STATS_UPDATE_INTERVAL_SECONDS: i64 = 4 * 60; // 4 minutes (less than the lowest ephemeral messages timeout)
|
||||
const KEY_CREATE_TIMESTAMP_RESOLUTION: u32 = 3600 * 24 * 7 * 4; // 4 weeks
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Statistics {
|
||||
@@ -348,7 +349,13 @@ async fn get_stats(context: &Context) -> Result<String> {
|
||||
let key_create_timestamps: Vec<u32> = load_self_public_keyring(context)
|
||||
.await?
|
||||
.iter()
|
||||
.map(|k| k.created_at().as_secs())
|
||||
.map(|k| {
|
||||
k.created_at()
|
||||
.as_secs()
|
||||
.div_ceil(KEY_CREATE_TIMESTAMP_RESOLUTION)
|
||||
.checked_mul(KEY_CREATE_TIMESTAMP_RESOLUTION)
|
||||
.unwrap_or(0)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let sending_enabled_timestamps =
|
||||
|
||||
@@ -486,6 +486,17 @@ async fn test_stats_key_creation_timestamp() -> Result<()> {
|
||||
// Alice uses a pregenerated key. It was created at this timestamp:
|
||||
const ALICE_KEY_CREATION_TIME: u128 = 1582855645;
|
||||
|
||||
// The key creation time's resolution is reduced in order to prevent deanonymization:
|
||||
const CENSORED_KEY_CREATION_TIME: u128 = 1584576000;
|
||||
assert!(CENSORED_KEY_CREATION_TIME.is_multiple_of(u128::from(KEY_CREATE_TIMESTAMP_RESOLUTION)));
|
||||
const {
|
||||
assert!(CENSORED_KEY_CREATION_TIME > ALICE_KEY_CREATION_TIME);
|
||||
}
|
||||
assert!(
|
||||
CENSORED_KEY_CREATION_TIME - ALICE_KEY_CREATION_TIME
|
||||
< u128::from(KEY_CREATE_TIMESTAMP_RESOLUTION)
|
||||
);
|
||||
|
||||
let alice = &TestContext::new_alice().await;
|
||||
alice.set_config_bool(Config::StatsSending, true).await?;
|
||||
|
||||
@@ -495,7 +506,7 @@ async fn test_stats_key_creation_timestamp() -> Result<()> {
|
||||
assert_eq!(
|
||||
key_create_timestamps,
|
||||
&vec![Value::Number(
|
||||
Number::from_u128(ALICE_KEY_CREATION_TIME).unwrap()
|
||||
Number::from_u128(CENSORED_KEY_CREATION_TIME).unwrap()
|
||||
)]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user