Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ impl Context {
convert_folder_meaning(self, folder_meaning).await?
{
connection
.fetch_move_delete(self, &mut session, true, &watch_folder, folder_meaning)
.fetch_move_delete(self, &mut session, &watch_folder, folder_meaning)
.await?;
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ pub(crate) const MIN_DELETE_SERVER_AFTER: i64 = 48 * 60 * 60;
// current value is a bit less than the minimum auto download setting from the UIs (which is 160 KiB)
pub(crate) const PRE_MSG_ATTACHMENT_SIZE_THRESHOLD: u64 = 140_000;

/// Max message size to be fetched in the background.
/// This limit defines what messages are fully fetched in the background.
/// This is for all messages that don't have the Post-Message header.
pub(crate) const MAX_FETCH_MSG_SIZE: u32 = 1_000_000;

/// Max size for pre messages. A warning is emitted when this is exceeded.
/// Should be well below `MAX_FETCH_MSG_SIZE`
pub(crate) const PRE_MSG_SIZE_WARNING_THRESHOLD: usize = 150_000;

/// Download state of the message.
Expand Down
54 changes: 6 additions & 48 deletions src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use num_traits::FromPrimitive;
use ratelimit::Ratelimit;
use url::Url;

use crate::calls::{create_fallback_ice_servers, create_ice_servers_from_metadata};
use crate::chat::{self, ChatId, ChatIdBlocked, add_device_msg};
use crate::chatlist_events;
use crate::config::Config;
Expand All @@ -47,10 +48,6 @@ use crate::tools::{self, create_id, duration_to_str, time};
use crate::transport::{
ConfiguredLoginParam, ConfiguredServerLoginParam, prioritize_server_login_params,
};
use crate::{
calls::{create_fallback_ice_servers, create_ice_servers_from_metadata},
download::MAX_FETCH_MSG_SIZE,
};

pub(crate) mod capabilities;
mod client;
Expand Down Expand Up @@ -523,7 +520,6 @@ impl Imap {
&mut self,
context: &Context,
session: &mut Session,
is_background_fetch: bool,
watch_folder: &str,
folder_meaning: FolderMeaning,
) -> Result<()> {
Expand All @@ -533,13 +529,7 @@ impl Imap {
}

let msgs_fetched = self
.fetch_new_messages(
context,
session,
is_background_fetch,
watch_folder,
folder_meaning,
)
.fetch_new_messages(context, session, watch_folder, folder_meaning)
.await
.context("fetch_new_messages")?;
if msgs_fetched && context.get_config_delete_device_after().await?.is_some() {
Expand All @@ -565,7 +555,6 @@ impl Imap {
&mut self,
context: &Context,
session: &mut Session,
is_background_fetch: bool,
folder: &str,
folder_meaning: FolderMeaning,
) -> Result<bool> {
Expand Down Expand Up @@ -593,13 +582,7 @@ impl Imap {
let mut read_cnt = 0;
loop {
let (n, fetch_more) = self
.fetch_new_msg_batch(
context,
session,
is_background_fetch,
folder,
folder_meaning,
)
.fetch_new_msg_batch(context, session, folder, folder_meaning)
.await?;
read_cnt += n;
if !fetch_more {
Expand All @@ -613,7 +596,6 @@ impl Imap {
&mut self,
context: &Context,
session: &mut Session,
is_background_fetch: bool,
folder: &str,
folder_meaning: FolderMeaning,
) -> Result<(usize, bool)> {
Expand Down Expand Up @@ -737,47 +719,23 @@ impl Imap {
)
.await.context("prefetch_should_download")?
{
let fetch_now: bool = if headers
if headers
.get_header_value(HeaderDef::ChatIsPostMessage)
.is_some()
{
info!(context, "{} is a post message", message_id.clone());
// This is a Post-Message
available_post_msgs.push(message_id.clone());

// whether it fits download size limit
if download_limit.is_none_or(|download_limit| size < download_limit) {
if is_background_fetch {
download_when_normal_starts.push(message_id.clone());
false
} else {
true
}
} else {
false
download_when_normal_starts.push(message_id.clone());
}
} else {
info!(context, "{} is not a post message", message_id.clone());
// This is not a Post-Message
if is_background_fetch {
if size < MAX_FETCH_MSG_SIZE {
// may be a Pre-Message or a small normal message, fetch now
true
} else {
// This is e.g. a classical email or large webxdc status update
// Queue for full download, in order to prevent missing messages
download_when_normal_starts.push(message_id.clone());
false
}
} else {
true
}
};

if fetch_now {
uids_fetch.push(uid);
uid_message_ids.insert(uid, message_id);
}
};
} else {
largest_uid_skipped = Some(uid);
}
Expand Down
2 changes: 1 addition & 1 deletion src/imap/scan_folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Imap {
&& folder_meaning != FolderMeaning::Trash
&& folder_meaning != FolderMeaning::Unknown
{
self.fetch_move_delete(context, session, false, folder.name(), folder_meaning)
self.fetch_move_delete(context, session, folder.name(), folder_meaning)
.await
.context("Can't fetch new msgs in scanned folder")
.log_err(context)
Expand Down
4 changes: 2 additions & 2 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ async fn fetch_idle(
{
// Fetch the watched folder.
connection
.fetch_move_delete(ctx, &mut session, true, &watch_folder, folder_meaning)
.fetch_move_delete(ctx, &mut session, &watch_folder, folder_meaning)
.await
.context("fetch_move_delete")?;

Expand Down Expand Up @@ -617,7 +617,7 @@ async fn fetch_idle(
// no new messages. We want to select the watched folder anyway before going IDLE
// there, so this does not take additional protocol round-trip.
connection
.fetch_move_delete(ctx, &mut session, true, &watch_folder, folder_meaning)
.fetch_move_delete(ctx, &mut session, &watch_folder, folder_meaning)
.await
.context("fetch_move_delete after scan_folders")?;
}
Expand Down
Loading