Skip to content

Commit de65eec

Browse files
committed
meli/accounts: add mailbox_by_path() tests
Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 18e9d5c commit de65eec

File tree

3 files changed

+480
-15
lines changed

3 files changed

+480
-15
lines changed

meli/src/accounts.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,16 +1337,23 @@ impl Account {
13371337
.list_mailboxes()
13381338
.into_iter()
13391339
.map(|n| (n.hash, n.depth))
1340-
.collect::<BTreeMap<MailboxHash, usize>>();
1340+
.collect::<IndexMap<MailboxHash, usize>>();
13411341
let mut entries = self
13421342
.mailbox_entries
13431343
.iter()
1344-
.map(|(h, f)| (h, f.ref_mailbox.path()))
1344+
.map(|(h, f)| (h, f.ref_mailbox.name(), f.ref_mailbox.path()))
13451345
.collect::<Vec<_>>();
1346-
entries.sort_by_cached_key(|(h, _)| nodes.get(h).cloned().unwrap_or(usize::MAX));
1346+
entries.sort_by_cached_key(|(h, n, p)| {
1347+
(
1348+
n.len(),
1349+
nodes.get(*h).cloned().unwrap_or(usize::MAX),
1350+
*p,
1351+
*n,
1352+
)
1353+
});
13471354
let patterns = &[path.trim_matches('/')];
13481355
let mut potential_matches = IndexSet::new();
1349-
for (_, haystack) in entries {
1356+
for (_, _, haystack) in &entries {
13501357
let ac = AhoCorasick::builder()
13511358
.ascii_case_insensitive(true)
13521359
.build(patterns)

meli/src/accounts/mailbox_ops.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::*;
2626
use crate::command::actions::MailboxOperation;
2727

2828
impl Account {
29-
pub fn mailbox_operation(&mut self, op: MailboxOperation) -> Result<()> {
29+
pub fn mailbox_operation(&mut self, op: MailboxOperation) -> Result<JobId> {
3030
if self.settings.account.read_only {
3131
return Err(Error::new("Account is read-only."));
3232
}
@@ -42,11 +42,12 @@ impl Account {
4242
job,
4343
self.is_async(),
4444
);
45+
let job_id = handle.job_id;
4546
self.insert_job(
4647
handle.job_id,
4748
JobRequest::Mailbox(MailboxJobRequest::CreateMailbox { path, handle }),
4849
);
49-
Ok(())
50+
Ok(job_id)
5051
}
5152
MailboxOperation::Delete(path) => {
5253
if self.mailbox_entries.len() == 1 {
@@ -60,14 +61,15 @@ impl Account {
6061
job,
6162
self.is_async(),
6263
);
64+
let job_id = handle.job_id;
6365
self.insert_job(
6466
handle.job_id,
6567
JobRequest::Mailbox(MailboxJobRequest::DeleteMailbox {
6668
mailbox_hash,
6769
handle,
6870
}),
6971
);
70-
Ok(())
72+
Ok(job_id)
7173
}
7274
MailboxOperation::Subscribe(path) => {
7375
let mailbox_hash = self.mailbox_by_path(&path)?;
@@ -81,6 +83,7 @@ impl Account {
8183
job,
8284
self.is_async(),
8385
);
86+
let job_id = handle.job_id;
8487
self.insert_job(
8588
handle.job_id,
8689
JobRequest::Mailbox(MailboxJobRequest::SetMailboxSubscription {
@@ -89,7 +92,7 @@ impl Account {
8992
handle,
9093
}),
9194
);
92-
Ok(())
95+
Ok(job_id)
9396
}
9497
MailboxOperation::Unsubscribe(path) => {
9598
let mailbox_hash = self.mailbox_by_path(&path)?;
@@ -103,15 +106,16 @@ impl Account {
103106
job,
104107
self.is_async(),
105108
);
109+
let job_id = handle.job_id;
106110
self.insert_job(
107-
handle.job_id,
111+
job_id,
108112
JobRequest::Mailbox(MailboxJobRequest::SetMailboxSubscription {
109113
mailbox_hash,
110114
new_value: false,
111115
handle,
112116
}),
113117
);
114-
Ok(())
118+
Ok(job_id)
115119
}
116120
MailboxOperation::Rename(path, new_path) => {
117121
let mailbox_hash = self.mailbox_by_path(&path)?;
@@ -125,15 +129,16 @@ impl Account {
125129
job,
126130
self.is_async(),
127131
);
132+
let job_id = handle.job_id;
128133
self.insert_job(
129-
handle.job_id,
134+
job_id,
130135
JobRequest::Mailbox(MailboxJobRequest::RenameMailbox {
131136
handle,
132137
mailbox_hash,
133138
new_path,
134139
}),
135140
);
136-
Ok(())
141+
Ok(job_id)
137142
}
138143
MailboxOperation::SetPermissions(_) => Err(Error::new("Not implemented.")),
139144
}

0 commit comments

Comments
 (0)