Skip to content

Commit 2260156

Browse files
committed
feat: Don't fetch messages from unknown folders (#7190)
Actually this leads to fetching messages only from watched folders and Spam. Motivation: - At least Gmail has virtual folders which aren't correctly detected as such, e.g. "Sent". - At least Gmail has many virtual folders and scanning all of them takes significant time, 5-6 secs in median for me. This slows down receiving new messages and consumes battery. - Delta Chat shouldn't fetch messages from folders potentially created by other apps for their own purposes. NB: All compatible Delta Chat forks should use the "DeltaChat" folder as mvbox. - Fetching from folders that aren't watched, e.g. from "Sent", may lead to message ordering issues.
1 parent 129e970 commit 2260156

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

python/tests/test_1_online.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,12 +1755,12 @@ def test_group_quote(acfactory, lp):
17551755
"xyz",
17561756
False,
17571757
"xyz",
1758-
), # Test that emails are recognized in a random folder but not moved
1758+
), # Test that emails aren't found in a random folder
17591759
(
1760-
"xyz",
1760+
"Spam",
17611761
True,
17621762
"DeltaChat",
1763-
), # ...emails are found in a random folder and moved to DeltaChat
1763+
), # ...emails are moved from the spam folder to "DeltaChat"
17641764
(
17651765
"Spam",
17661766
False,
@@ -1785,7 +1785,7 @@ def test_scan_folders(acfactory, lp, folder, move, expected_destination):
17851785
ac1.stop_io()
17861786
assert folder in ac1.direct_imap.list_folders()
17871787

1788-
lp.sec("Send a message to from ac2 to ac1 and manually move it to the mvbox")
1788+
lp.sec("Send a message to from ac2 to ac1 and manually move it to `folder`")
17891789
ac1.direct_imap.select_config_folder("inbox")
17901790
with ac1.direct_imap.idle() as idle1:
17911791
acfactory.get_accepted_chat(ac2, ac1).send_text("hello")
@@ -1795,10 +1795,17 @@ def test_scan_folders(acfactory, lp, folder, move, expected_destination):
17951795
lp.sec("start_io() and see if DeltaChat finds the message (" + variant + ")")
17961796
ac1.set_config("scan_all_folders_debounce_secs", "0")
17971797
ac1.start_io()
1798-
msg = ac1._evtracker.wait_next_incoming_message()
1799-
assert msg.text == "hello"
1800-
1801-
# The message has been downloaded, which means it has reached its destination.
1798+
chat = ac1.create_chat(ac2)
1799+
n_msgs = 1 # "Messages are end-to-end encrypted."
1800+
if folder == "Spam":
1801+
msg = ac1._evtracker.wait_next_incoming_message()
1802+
assert msg.text == "hello"
1803+
n_msgs += 1
1804+
else:
1805+
ac1._evtracker.wait_idle_inbox_ready()
1806+
assert len(chat.get_messages()) == n_msgs
1807+
1808+
# The message has reached its destination.
18021809
ac1.direct_imap.select_folder(expected_destination)
18031810
assert len(ac1.direct_imap.get_all_messages()) == 1
18041811
if folder != expected_destination:

src/imap.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,10 @@ impl Session {
814814
.context("listing folders for resync")?;
815815
for folder in all_folders {
816816
let folder_meaning = get_folder_meaning(&folder);
817-
if folder_meaning != FolderMeaning::Virtual {
817+
if !matches!(
818+
folder_meaning,
819+
FolderMeaning::Virtual | FolderMeaning::Unknown | FolderMeaning::Drafts
820+
) {
818821
self.resync_folder_uids(context, folder.name(), folder_meaning)
819822
.await?;
820823
}

src/imap/scan_folders.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl Imap {
7575
if !watched_folders.contains(&folder.name().to_string())
7676
&& folder_meaning != FolderMeaning::Drafts
7777
&& folder_meaning != FolderMeaning::Trash
78+
&& folder_meaning != FolderMeaning::Unknown
7879
{
7980
self.fetch_move_delete(context, session, folder.name(), folder_meaning)
8081
.await

0 commit comments

Comments
 (0)