Skip to content

Commit c0b2f58

Browse files
committed
feat: Remove Config::ConfiguredSentboxFolder and everything related
It's used in `fetch_existing_msgs()`, but we can remove it and tell users that they need to move/copy messages from Sentbox to Inbox so that Delta Chat adds all contacts from them. This way users will be also informed that Delta Chat needs users to CC/BCC/To themselves to see messages sent from other MUAs.
1 parent 4cf89fd commit c0b2f58

File tree

7 files changed

+30
-115
lines changed

7 files changed

+30
-115
lines changed

python/tests/test_1_online.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_enable_mvbox_move(acfactory, lp):
269269
assert ac2._evtracker.wait_next_incoming_message().text == "message1"
270270

271271

272-
def test_mvbox_thread_and_sentbox(acfactory, lp):
272+
def test_mvbox_thread_and_trash(acfactory, lp):
273273
lp.sec("ac1: start with mvbox thread")
274274
ac1 = acfactory.new_online_configuring_account(mvbox_move=True)
275275

@@ -279,8 +279,8 @@ def test_mvbox_thread_and_sentbox(acfactory, lp):
279279
lp.sec("ac2 and ac1: waiting for configuration")
280280
acfactory.bring_accounts_online()
281281

282-
lp.sec("ac1: create sentbox")
283-
ac1.direct_imap.create_folder("Sent")
282+
lp.sec("ac1: create trash")
283+
ac1.direct_imap.create_folder("Trash")
284284
ac1.set_config("scan_all_folders_debounce_secs", "0")
285285
ac1.stop_io()
286286
ac1.start_io()
@@ -290,7 +290,7 @@ def test_mvbox_thread_and_sentbox(acfactory, lp):
290290
assert ac2._evtracker.wait_next_incoming_message().text == "message1"
291291

292292
assert ac1.get_config("configured_mvbox_folder") == "DeltaChat"
293-
while ac1.get_config("configured_sentbox_folder") != "Sent":
293+
while ac1.get_config("configured_trash_folder") != "Trash":
294294
ac1._evtracker.get_matching("DC_EVENT_CONNECTIVITY_CHANGED")
295295

296296

@@ -834,9 +834,9 @@ def test_no_draft_if_cant_send(acfactory):
834834

835835
def test_dont_show_emails(acfactory, lp):
836836
"""Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them.
837-
So: If it's outgoing AND there is no Received header AND it's not in the sentbox, then ignore the email.
837+
So: If it's outgoing AND there is no Received header, then ignore the email.
838838
839-
If the draft email is sent out later (i.e. moved to "Sent"), it must be shown.
839+
If the draft email is sent out and received later (i.e. it's in "Inbox"), it must be shown.
840840
841841
Also, test that unknown emails in the Spam folder are not shown."""
842842
ac1 = acfactory.new_online_configuring_account()
@@ -845,7 +845,6 @@ def test_dont_show_emails(acfactory, lp):
845845

846846
acfactory.wait_configured(ac1)
847847
ac1.direct_imap.create_folder("Drafts")
848-
ac1.direct_imap.create_folder("Sent")
849848
ac1.direct_imap.create_folder("Spam")
850849
ac1.direct_imap.create_folder("Junk")
851850

@@ -861,21 +860,7 @@ def test_dont_show_emails(acfactory, lp):
861860
Message-ID: <[email protected]>
862861
Content-Type: text/plain; charset=utf-8
863862
864-
message in Drafts that is moved to Sent later
865-
""".format(
866-
ac1.get_config("configured_addr"),
867-
),
868-
)
869-
ac1.direct_imap.append(
870-
"Sent",
871-
"""
872-
From: ac1 <{}>
873-
Subject: subj
874-
875-
Message-ID: <[email protected]>
876-
Content-Type: text/plain; charset=utf-8
877-
878-
message in Sent
863+
message in Drafts received later
879864
""".format(
880865
ac1.get_config("configured_addr"),
881866
),
@@ -955,31 +940,30 @@ def test_dont_show_emails(acfactory, lp):
955940
lp.sec("All prepared, now let DC find the message")
956941
ac1.start_io()
957942

958-
msg = ac1._evtracker.wait_next_messages_changed()
959-
960943
# Wait until each folder was scanned, this is necessary for this test to test what it should test:
961944
ac1._evtracker.wait_idle_inbox_ready()
962945

963-
assert msg.text == "subj – message in Sent"
946+
fresh_msgs = list(ac1.get_fresh_messages())
947+
msg = fresh_msgs[0]
964948
chat_msgs = msg.chat.get_messages()
965-
assert len(chat_msgs) == 2
949+
assert len(chat_msgs) == 1
966950
assert any(msg.text == "subj – Actually interesting message in Spam" for msg in chat_msgs)
967951

968952
assert not any("unknown.address" in c.get_name() for c in ac1.get_chats())
969953
ac1.direct_imap.select_folder("Spam")
970954
assert ac1.direct_imap.get_uid_by_message_id("[email protected]")
971955

972956
ac1.stop_io()
973-
lp.sec("'Send out' the draft, i.e. move it to the Sent folder, and wait for DC to display it this time")
957+
lp.sec("'Send out' the draft by moving it to Inbox, and wait for DC to display it this time")
974958
ac1.direct_imap.select_folder("Drafts")
975959
uid = ac1.direct_imap.get_uid_by_message_id("[email protected]")
976-
ac1.direct_imap.conn.move(uid, "Sent")
960+
ac1.direct_imap.conn.move(uid, "Inbox")
977961

978962
ac1.start_io()
979963
msg2 = ac1._evtracker.wait_next_messages_changed()
980964

981-
assert msg2.text == "subj – message in Drafts that is moved to Sent later"
982-
assert len(msg.chat.get_messages()) == 3
965+
assert msg2.text == "subj – message in Drafts received later"
966+
assert len(msg.chat.get_messages()) == 2
983967

984968

985969
def test_bot(acfactory, lp):

src/config.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ pub enum Config {
281281
/// Configured folder for chat messages.
282282
ConfiguredMvboxFolder,
283283

284-
/// Configured "Sent" folder.
285-
ConfiguredSentboxFolder,
286-
287284
/// Configured "Trash" folder.
288285
ConfiguredTrashFolder,
289286

src/context.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,6 @@ impl Context {
861861
.get_config(Config::ConfiguredInboxFolder)
862862
.await?
863863
.unwrap_or_else(|| "<unset>".to_string());
864-
let configured_sentbox_folder = self
865-
.get_config(Config::ConfiguredSentboxFolder)
866-
.await?
867-
.unwrap_or_else(|| "<unset>".to_string());
868864
let configured_mvbox_folder = self
869865
.get_config(Config::ConfiguredMvboxFolder)
870866
.await?
@@ -960,7 +956,6 @@ impl Context {
960956
folders_configured.to_string(),
961957
);
962958
res.insert("configured_inbox_folder", configured_inbox_folder);
963-
res.insert("configured_sentbox_folder", configured_sentbox_folder);
964959
res.insert("configured_mvbox_folder", configured_mvbox_folder);
965960
res.insert("configured_trash_folder", configured_trash_folder);
966961
res.insert("mdns_enabled", mdns_enabled.to_string());

src/imap.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ pub enum FolderMeaning {
144144
Spam,
145145
Inbox,
146146
Mvbox,
147-
Sent,
148147
Trash,
149148
Drafts,
150149

@@ -164,7 +163,6 @@ impl FolderMeaning {
164163
FolderMeaning::Spam => None,
165164
FolderMeaning::Inbox => Some(Config::ConfiguredInboxFolder),
166165
FolderMeaning::Mvbox => Some(Config::ConfiguredMvboxFolder),
167-
FolderMeaning::Sent => Some(Config::ConfiguredSentboxFolder),
168166
FolderMeaning::Trash => Some(Config::ConfiguredTrashFolder),
169167
FolderMeaning::Drafts => None,
170168
FolderMeaning::Virtual => None,
@@ -790,9 +788,6 @@ impl Imap {
790788
context: &Context,
791789
session: &mut Session,
792790
) -> Result<()> {
793-
add_all_recipients_as_contacts(context, session, Config::ConfiguredSentboxFolder)
794-
.await
795-
.context("failed to get recipients from the sentbox")?;
796791
add_all_recipients_as_contacts(context, session, Config::ConfiguredMvboxFolder)
797792
.await
798793
.context("failed to get recipients from the movebox")?;
@@ -1980,7 +1975,7 @@ async fn spam_target_folder_cfg(
19801975
}
19811976
}
19821977

1983-
/// Returns `ConfiguredInboxFolder`, `ConfiguredMvboxFolder` or `ConfiguredSentboxFolder` if
1978+
/// Returns `ConfiguredInboxFolder` or `ConfiguredMvboxFolder` if
19841979
/// the message needs to be moved from `folder`. Otherwise returns `None`.
19851980
pub async fn target_folder_cfg(
19861981
context: &Context,
@@ -2067,38 +2062,6 @@ async fn needs_move_to_mvbox(
20672062
// but sth. different in others - a hard job.
20682063
fn get_folder_meaning_by_name(folder_name: &str) -> FolderMeaning {
20692064
// source: <https://stackoverflow.com/questions/2185391/localized-gmail-imap-folders>
2070-
const SENT_NAMES: &[&str] = &[
2071-
"sent",
2072-
"sentmail",
2073-
"sent objects",
2074-
"gesendet",
2075-
"Sent Mail",
2076-
"Sendte e-mails",
2077-
"Enviados",
2078-
"Messages envoyés",
2079-
"Messages envoyes",
2080-
"Posta inviata",
2081-
"Verzonden berichten",
2082-
"Wyslane",
2083-
"E-mails enviados",
2084-
"Correio enviado",
2085-
"Enviada",
2086-
"Enviado",
2087-
"Gönderildi",
2088-
"Inviati",
2089-
"Odeslaná pošta",
2090-
"Sendt",
2091-
"Skickat",
2092-
"Verzonden",
2093-
"Wysłane",
2094-
"Éléments envoyés",
2095-
"Απεσταλμένα",
2096-
"Отправленные",
2097-
"寄件備份",
2098-
"已发送邮件",
2099-
"送信済み",
2100-
"보낸편지함",
2101-
];
21022065
const SPAM_NAMES: &[&str] = &[
21032066
"spam",
21042067
"junk",
@@ -2163,9 +2126,7 @@ fn get_folder_meaning_by_name(folder_name: &str) -> FolderMeaning {
21632126
];
21642127
let lower = folder_name.to_lowercase();
21652128

2166-
if SENT_NAMES.iter().any(|s| s.to_lowercase() == lower) {
2167-
FolderMeaning::Sent
2168-
} else if SPAM_NAMES.iter().any(|s| s.to_lowercase() == lower) {
2129+
if SPAM_NAMES.iter().any(|s| s.to_lowercase() == lower) {
21692130
FolderMeaning::Spam
21702131
} else if DRAFT_NAMES.iter().any(|s| s.to_lowercase() == lower) {
21712132
FolderMeaning::Drafts
@@ -2180,7 +2141,6 @@ fn get_folder_meaning_by_attrs(folder_attrs: &[NameAttribute]) -> FolderMeaning
21802141
for attr in folder_attrs {
21812142
match attr {
21822143
NameAttribute::Trash => return FolderMeaning::Trash,
2183-
NameAttribute::Sent => return FolderMeaning::Sent,
21842144
NameAttribute::Junk => return FolderMeaning::Spam,
21852145
NameAttribute::Drafts => return FolderMeaning::Drafts,
21862146
NameAttribute::All | NameAttribute::Flagged => return FolderMeaning::Virtual,

src/imap/imap_tests.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@ use crate::test_utils::TestContext;
33

44
#[test]
55
fn test_get_folder_meaning_by_name() {
6-
assert_eq!(get_folder_meaning_by_name("Gesendet"), FolderMeaning::Sent);
7-
assert_eq!(get_folder_meaning_by_name("GESENDET"), FolderMeaning::Sent);
8-
assert_eq!(get_folder_meaning_by_name("gesendet"), FolderMeaning::Sent);
9-
assert_eq!(
10-
get_folder_meaning_by_name("Messages envoyés"),
11-
FolderMeaning::Sent
12-
);
13-
assert_eq!(
14-
get_folder_meaning_by_name("mEsSaGes envoyÉs"),
15-
FolderMeaning::Sent
16-
);
176
assert_eq!(get_folder_meaning_by_name("xxx"), FolderMeaning::Unknown);
187
assert_eq!(get_folder_meaning_by_name("SPAM"), FolderMeaning::Spam);
198
assert_eq!(get_folder_meaning_by_name("Trash"), FolderMeaning::Trash);
@@ -119,9 +108,6 @@ async fn check_target_folder_combination(
119108
t.ctx
120109
.set_config(Config::ConfiguredMvboxFolder, Some("DeltaChat"))
121110
.await?;
122-
t.ctx
123-
.set_config(Config::ConfiguredSentboxFolder, Some("Sent"))
124-
.await?;
125111
t.ctx
126112
.set_config(Config::MvboxMove, Some(if mvbox_move { "1" } else { "0" }))
127113
.await?;

src/imap/scan_folders.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,15 @@ impl Imap {
8484
}
8585
}
8686

87-
// Set configs for necessary folders. Or reset if the folder was deleted.
88-
for conf in [
89-
Config::ConfiguredSentboxFolder,
90-
Config::ConfiguredTrashFolder,
91-
] {
92-
let val = folder_configs.get(&conf).map(|s| s.as_str());
93-
let interrupt = conf == Config::ConfiguredTrashFolder
94-
&& val.is_some()
95-
&& context.get_config(conf).await?.is_none();
96-
context.set_config_internal(conf, val).await?;
97-
if interrupt {
98-
// `Imap::fetch_move_delete()` is possible now for other folders (NB: we are in the
99-
// Inbox loop).
100-
context.scheduler.interrupt_oboxes().await;
101-
}
87+
// Set config for the Trash folder. Or reset if the folder was deleted.
88+
let conf = Config::ConfiguredTrashFolder;
89+
let val = folder_configs.get(&conf).map(|s| s.as_str());
90+
let interrupt = val.is_some() && context.get_config(conf).await?.is_none();
91+
context.set_config_internal(conf, val).await?;
92+
if interrupt {
93+
// `Imap::fetch_move_delete()`, particularly message deletion, is possible now for other
94+
// folders (NB: we are in the Inbox loop).
95+
context.scheduler.interrupt_oboxes().await;
10296
}
10397

10498
info!(context, "Found folders: {folder_names:?}.");

src/sql/migrations.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,18 @@ UPDATE chats SET protected=1, type=120 WHERE type=130;"#,
401401
.await?;
402402
}
403403
if dbversion < 73 {
404-
use Config::*;
405404
sql.execute(
406405
r#"
407406
CREATE TABLE imap_sync (folder TEXT PRIMARY KEY, uidvalidity INTEGER DEFAULT 0, uid_next INTEGER DEFAULT 0);"#,
408407
()
409408
)
410409
.await?;
411-
for c in &[
412-
ConfiguredInboxFolder,
413-
ConfiguredSentboxFolder,
414-
ConfiguredMvboxFolder,
410+
for c in [
411+
"configured_inbox_folder",
412+
"configured_sentbox_folder",
413+
"configured_mvbox_folder",
415414
] {
416-
if let Some(folder) = context.get_config(*c).await? {
415+
if let Some(folder) = context.sql.get_raw_config(c).await? {
417416
let (uid_validity, last_seen_uid) =
418417
imap::get_config_last_seen_uid(context, &folder).await?;
419418
if last_seen_uid > 0 {

0 commit comments

Comments
 (0)