diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-05-26 02:34:03 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:50 +0300 |
commit | 42654410e3229797abcc3a4ddd7330e756eb7567 (patch) | |
tree | c2febf1c5c34a6a0a4fabab60c592a1eca77602d /ui/src | |
parent | eff1c1641cbfd7d672d12bdfe7dde020c5cb267c (diff) |
ui: move Collection to Account
Each account had one mailbox per folder, which had one associated
collection. Now each Account has one Collection for all folders and each
Mailbox object holds only the hashes of each message.
Collection also gets Threads for each folder in order to mix messages
(ie from/to Sent folder).
Insert Sent emails in chronological order
if inserted unsorted, mails a, b with a happened-before b, might never
get added.
Fix multiple insertions in ThreadTree upon insert_reply
insert_reply was creating multiple copies in threading
Diffstat (limited to 'ui/src')
-rw-r--r-- | ui/src/components/mail/accounts.rs | 11 | ||||
-rw-r--r-- | ui/src/components/mail/compose.rs | 34 | ||||
-rw-r--r-- | ui/src/components/mail/listing.rs | 8 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 53 | ||||
-rw-r--r-- | ui/src/components/mail/listing/plain.rs | 38 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 40 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 71 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 50 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 15 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 139 | ||||
-rw-r--r-- | ui/src/execute/actions.rs | 3 |
11 files changed, 251 insertions, 211 deletions
diff --git a/ui/src/components/mail/accounts.rs b/ui/src/components/mail/accounts.rs index 8c7a24d6..034e7f0f 100644 --- a/ui/src/components/mail/accounts.rs +++ b/ui/src/components/mail/accounts.rs @@ -163,12 +163,11 @@ impl AccountsPanel { write_string_to_grid( &format!( "total {}", - a.iter_mailboxes().fold(0, |mut acc, m| { - acc += m - .map(|m| m.collection.values().filter(|e| !e.is_seen()).count()) - .unwrap_or(0); - acc - }) + a.collection + .envelopes + .values() + .filter(|e| !e.is_seen()) + .count() ), &mut self.content, Color::Default, diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 554fc896..de73c790 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -127,21 +127,14 @@ impl Composer { * msg: index of message we reply to in thread_nodes * context: current context */ - pub fn edit(coordinates: (usize, usize, usize), msg: ThreadHash, context: &Context) -> Self { - let mailbox = &context.accounts[coordinates.0][coordinates.1] - .as_ref() - .unwrap(); - let threads = &mailbox.collection.threads; - let thread_nodes = &threads.thread_nodes(); + pub fn edit(account_pos: usize, h: EnvelopeHash, context: &Context) -> Self { let mut ret = Composer::default(); - let message = &mailbox.collection[&thread_nodes[&msg].message().unwrap()]; - let op = context.accounts[coordinates.0] - .backend - .operation(message.hash(), mailbox.folder.hash()); + let op = context.accounts[account_pos].operation(&h); + let envelope: &Envelope = context.accounts[account_pos].get_env(&h); - ret.draft = Draft::edit(message, op); + ret.draft = Draft::edit(envelope, op); - ret.account_cursor = coordinates.0; + ret.account_cursor = account_pos; ret } pub fn with_context( @@ -149,17 +142,14 @@ impl Composer { msg: ThreadHash, context: &Context, ) -> Self { - let mailbox = &context.accounts[coordinates.0][coordinates.1] - .as_ref() - .unwrap(); - let threads = &mailbox.collection.threads; + let account = &context.accounts[coordinates.0]; + let mailbox = &account[coordinates.1].as_ref().unwrap(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; let thread_nodes = &threads.thread_nodes(); let mut ret = Composer::default(); let p = &thread_nodes[&msg]; - let parent_message = &mailbox.collection[&p.message().unwrap()]; - let mut op = context.accounts[coordinates.0] - .backend - .operation(parent_message.hash(), mailbox.folder.hash()); + let parent_message = &account.collection[&p.message().unwrap()]; + let mut op = account.operation(&parent_message.hash()); let parent_bytes = op.as_bytes(); ret.draft = Draft::new_reply(parent_message, parent_bytes.unwrap()); @@ -168,10 +158,10 @@ impl Composer { if p.show_subject() { format!( "Re: {}", - mailbox.collection[&p.message().unwrap()].subject().clone() + account.get_env(&p.message().unwrap()).subject().clone() ) } else { - mailbox.collection[&p.message().unwrap()].subject().into() + account.get_env(&p.message().unwrap()).subject().into() }, ); diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 3522f275..8c16ac82 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -500,11 +500,13 @@ impl Listing { ) { match context.accounts[index].status(entries[&folder_idx].hash()) { Ok(_) => { - let count = context.accounts[index][entries[&folder_idx].hash()] + let account = &context.accounts[index]; + let count = account[entries[&folder_idx].hash()] .as_ref() .unwrap() - .collection - .values() + .envelopes + .iter() + .map(|h| &account.collection[&h]) .filter(|e| !e.is_seen()) .count(); let len = s.len(); diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 923c43b9..3839deb4 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -189,15 +189,15 @@ impl MailboxView { } if old_cursor_pos == self.new_cursor_pos { self.view.update(context); - } else { + } else if self.unfocused { self.view = ThreadView::new(self.new_cursor_pos, None, context); } - let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_ref() - .unwrap(); + let account = &context.accounts[self.cursor_pos.0]; + let mailbox = account[self.cursor_pos.1].as_ref().unwrap(); - self.length = mailbox.collection.threads.root_len(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; + self.length = threads.root_len(); self.content = CellBuffer::new(MAX_COLS, self.length + 1, Cell::with_char(' ')); self.order.clear(); if self.length == 0 { @@ -211,11 +211,10 @@ impl MailboxView { ); return; } - let threads = &mailbox.collection.threads; let mut rows = Vec::with_capacity(1024); let mut min_width = (0, 0, 0); - threads.sort_by(self.sort, self.subsort, &mailbox.collection); + threads.sort_by(self.sort, self.subsort, &account.collection); for (idx, root_idx) in threads.root_iter().enumerate() { let thread_node = &threads.thread_nodes()[&root_idx]; let i = if let Some(i) = thread_node.message() { @@ -227,7 +226,7 @@ impl MailboxView { } threads.thread_nodes()[&iter_ptr].message().unwrap() }; - if !mailbox.collection.contains_key(&i) { + if !context.accounts[self.cursor_pos.0].contains_key(&i) { debug!("key = {}", i); debug!( "name = {} {}", @@ -238,7 +237,7 @@ impl MailboxView { panic!(); } - let root_envelope: &Envelope = &mailbox.collection[&i]; + let root_envelope: &Envelope = &context.accounts[self.cursor_pos.0].get_env(&i); let strings = MailboxView::make_entry_string( root_envelope, @@ -277,14 +276,14 @@ impl MailboxView { } threads.thread_nodes()[&iter_ptr].message().unwrap() }; - if !mailbox.collection.contains_key(&i) { - debug!("key = {}", i); - debug!( - "name = {} {}", - mailbox.name(), - context.accounts[self.cursor_pos.0].name() - ); - debug!("{:#?}", context.accounts); + if !context.accounts[self.cursor_pos.0].contains_key(&i) { + //debug!("key = {}", i); + //debug!( + // "name = {} {}", + // mailbox.name(), + // context.accounts[self.cursor_pos.0].name() + //); + //debug!("{:#?}", context.accounts); panic!(); } @@ -365,13 +364,12 @@ impl MailboxView { context: &Context, ) { if idx == self.cursor_pos.2 || grid.is_none() { - let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_ref() - .unwrap(); - if mailbox.is_empty() { + if self.length == 0 { return; } - let threads = &mailbox.collection.threads; + let account = &context.accounts[self.cursor_pos.0]; + let mailbox = account[self.cursor_pos.1].as_ref().unwrap(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; let thread_node = threads.root_set(idx); let thread_node = &threads.thread_nodes()[&thread_node]; let i = if let Some(i) = thread_node.message() { @@ -384,7 +382,7 @@ impl MailboxView { threads.thread_nodes()[&iter_ptr].message().unwrap() }; - let root_envelope: &Envelope = &mailbox.collection[&i]; + let root_envelope: &Envelope = &account.get_env(&i); let fg_color = if !root_envelope.is_seen() { Color::Byte(0) } else { @@ -671,11 +669,12 @@ impl Component for MailboxView { Action::ToggleThreadSnooze => { { //FIXME NLL - - let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_mut() + let account = &mut context.accounts[self.cursor_pos.0]; + let folder_hash = account[self.cursor_pos.1] + .as_ref() + .map(|m| m.folder.hash()) .unwrap(); - let threads = &mut mailbox.collection.threads; + let threads = account.collection.threads.entry(folder_hash).or_default(); let thread_group = threads.thread_nodes() [&threads.root_set(self.cursor_pos.2)] .thread_group(); diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index b1245594..83c9eeaf 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -131,9 +131,8 @@ impl PlainListing { return; } } - let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_ref() - .unwrap(); + let account = &context.accounts[self.cursor_pos.0]; + let mailbox = &account[self.cursor_pos.1].as_ref().unwrap(); self.length = mailbox.len(); self.content = CellBuffer::new(MAX_COLS, self.length + 1, Cell::with_char(' ')); @@ -158,31 +157,31 @@ impl PlainListing { break; } /* Write an entire line for each envelope entry. */ - self.local_collection = mailbox.collection.keys().cloned().collect(); + self.local_collection = account.collection.keys().cloned().collect(); let sort = self.sort; self.local_collection.sort_by(|a, b| match sort { (SortField::Date, SortOrder::Desc) => { - let ma = &mailbox.collection[a]; - let mb = &mailbox.collection[b]; + let ma = &account.get_env(a); + let mb = &account.get_env(b); mb.date().cmp(&ma.date()) } (SortField::Date, SortOrder::Asc) => { - let ma = &mailbox.collection[a]; - let mb = &mailbox.collection[b]; + let ma = &account.get_env(a); + let mb = &account.get_env(b); ma.date().cmp(&mb.date()) } (SortField::Subject, SortOrder::Desc) => { - let ma = &mailbox.collection[a]; - let mb = &mailbox.collection[b]; + let ma = &account.get_env(a); + let mb = &account.get_env(b); ma.subject().cmp(&mb.subject()) } (SortField::Subject, SortOrder::Asc) => { - let ma = &mailbox.collection[a]; - let mb = &mailbox.collection[b]; + let ma = &account.get_env(a); + let mb = &account.get_env(b); mb.subject().cmp(&ma.subject()) } }); - let envelope: &Envelope = &mailbox.collection[&self.local_collection[idx]]; + let envelope: &Envelope = &account.get_env(&self.local_collection[idx]); let fg_color = if !envelope.is_seen() { Color::Byte(0) @@ -230,10 +229,8 @@ impl PlainListing { } fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) { - let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_ref() - .unwrap(); - let envelope: &Envelope = &mailbox.collection[&self.local_collection[idx]]; + let account = &context.accounts[self.cursor_pos.0]; + let envelope: &Envelope = &account.get_env(&self.local_collection[idx]); let fg_color = if !envelope.is_seen() { Color::Byte(0) @@ -367,11 +364,8 @@ impl Component for PlainListing { false } else { let account = &mut context.accounts[self.cursor_pos.0]; - let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap(); - let envelope: &mut Envelope = &mut mailbox - .collection - .entry(self.local_collection[idx]) - .or_default(); + let envelope: &mut Envelope = + &mut account.get_env_mut(&self.local_collection[idx]); !envelope.is_seen() } }; diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index 26848010..dd33040b 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -20,7 +20,6 @@ */ use super::*; -use std::dbg; const MAX_COLS: usize = 500; @@ -129,11 +128,10 @@ impl ThreadListing { return; } } - let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_ref() - .unwrap(); + let account = &context.accounts[self.cursor_pos.0]; + let mailbox = account[self.cursor_pos.1].as_ref().unwrap(); - self.length = mailbox.collection.threads.len(); + self.length = account.collection.threads.len(); self.content = CellBuffer::new(MAX_COLS, self.length + 1, Cell::with_char(' ')); self.locations.clear(); if self.length == 0 { @@ -151,8 +149,8 @@ impl ThreadListing { let mut indentations: Vec<bool> = Vec::with_capacity(6); let mut thread_idx = 0; // needed for alternate thread colors /* Draw threaded view. */ - let threads = &mailbox.collection.threads; - threads.sort_by(self.sort, self.subsort, &mailbox.collection); + let threads = &account.collection.threads[&mailbox.folder.hash()]; + threads.sort_by(self.sort, self.subsort, &account.collection); let thread_nodes: &FnvHashMap<ThreadHash, ThreadNode> = &threads.thread_nodes(); let mut iter = threads.threads_iter().peekable(); /* This is just a desugared for loop so that we can use .peek() */ @@ -164,7 +162,7 @@ impl ThreadListing { thread_idx += 1; } if thread_node.has_message() { - let envelope: &Envelope = &mailbox.collection[&thread_node.message().unwrap()]; + let envelope: &Envelope = &account.get_env(&thread_node.message().unwrap()); self.locations.push(envelope.hash()); let fg_color = if !envelope.is_seen() { Color::Byte(0) @@ -230,7 +228,8 @@ impl ThreadListing { return; } if self.locations[idx] != 0 { - let envelope: &Envelope = &mailbox.collection[&self.locations[idx]]; + let envelope: &Envelope = + &context.accounts[self.cursor_pos.0].get_env(&self.locations[idx]); let fg_color = if !envelope.is_seen() { Color::Byte(0) @@ -262,7 +261,8 @@ impl ThreadListing { } if self.locations[idx] != 0 { - let envelope: &Envelope = &mailbox.collection[&self.locations[idx]]; + let envelope: &Envelope = + &context.accounts[self.cursor_pos.0].get_env(&self.locations[idx]); let fg_color = if !envelope.is_seen() { Color::Byte(0) @@ -469,26 +469,14 @@ impl Component for ThreadListing { } else { let account = &mut context.accounts[self.cursor_pos.0]; let (hash, is_seen) = { - let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap(); - debug!("key is {}", self.locations[dbg!(self.cursor_pos).2]); let envelope: &Envelope = - &mailbox.collection[&self.locations[self.cursor_pos.2]]; + &account.get_env(&self.locations[self.cursor_pos.2]); (envelope.hash(), envelope.is_seen()) }; if !is_seen { - let folder_hash = { - let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap(); - mailbox.folder.hash() - }; - let op = { - let backend = &account.backend; - backend.operation(hash, folder_hash) - }; - let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap(); - let envelope: &mut Envelope = mailbox - .collection - .get_mut(&self.locations[self.cursor_pos.2]) - .unwrap(); + let op = account.operation(&hash); + let envelope: &mut Envelope = + account.get_env_mut(&self.locations[self.cursor_pos.2]); envelope.set_seen(op).unwrap(); true } else { diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 1ac321ae..ba8083dc 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -89,8 +89,7 @@ impl MailView { ) -> Self { let account = &mut context.accounts[coordinates.0]; let (hash, is_seen) = { - let mailbox = &mut account[coordinates.1].as_mut().unwrap(); - let envelope: &mut Envelope = &mut mailbox.collection.entry(coordinates.2).or_default(); + let envelope: &Envelope = &account.get_env(&coordinates.2); (envelope.hash(), envelope.is_seen()) }; if !is_seen { @@ -102,8 +101,7 @@ impl MailView { let backend = &account.backend; backend.operation(hash, folder_hash) }; - let mailbox = &mut account[coordinates.1].as_mut().unwrap(); - let envelope: &mut Envelope = &mut mailbox.collection.entry(coordinates.2).or_default(); + let envelope: &mut Envelope = &mut account.get_env_mut(&coordinates.2); envelope.set_seen(op).unwrap(); } MailView { @@ -292,16 +290,13 @@ impl Component for MailView { let bottom_right = bottom_right!(area); let y: usize = { - let accounts = &mut context.accounts; - let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - if !mailbox.collection.contains_key(&self.coordinates.2) { + let account = &mut context.accounts[self.coordinates.0]; + if !account.contains_key(&self.coordinates.2) { /* The envelope has been renamed or removed, so wait for the appropriate event to * arrive */ return; } - let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); if self.mode == ViewMode::Raw { clear_area(grid, area); @@ -383,14 +378,9 @@ impl Component for MailView { if self.dirty { let body = { - let mailbox_idx = self.coordinates; // coordinates are mailbox idxs - let mailbox = &context.accounts[mailbox_idx.0][mailbox_idx.1] - .as_ref() - .unwrap(); - let envelope: &Envelope = &mailbox.collection[&mailbox_idx.2]; - let op = context.accounts[mailbox_idx.0] - .backend - .operation(envelope.hash(), mailbox.folder.hash()); + let account = &mut context.accounts[self.coordinates.0]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); + let op = account.operation(&envelope.hash()); envelope.body(op) }; match self.mode { @@ -413,14 +403,9 @@ impl Component for MailView { ViewMode::Subview | ViewMode::ContactSelector(_) => {} ViewMode::Raw => { let text = { - let mailbox_idx = self.coordinates; // coordinates are mailbox idxs - let mailbox = &context.accounts[mailbox_idx.0][mailbox_idx.1] - .as_ref() - .unwrap(); - let envelope: &Envelope = &mailbox.collection[&mailbox_idx.2]; - let mut op = context.accounts[mailbox_idx.0] - .backend - .operation(envelope.hash(), mailbox.folder.hash()); + let account = &mut context.accounts[self.coordinates.0]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); + let mut op = account.operation(&envelope.hash()); op.as_bytes() .map(|v| String::from_utf8_lossy(v).into_owned()) .unwrap_or_else(|e| e.to_string()) @@ -507,8 +492,7 @@ impl Component for MailView { let account = &mut context.accounts[self.coordinates.0]; let mut results = Vec::new(); { - let mailbox = &account[self.coordinates.1].as_ref().unwrap(); - let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); for c in s.collect() { let c = usize::from_ne_bytes({ [c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]] @@ -536,11 +520,8 @@ impl Component for MailView { } return true; } - let accounts = &context.accounts; - let mailbox = &accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; + let account = &mut context.accounts[self.coordinates.0]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); let mut entries = Vec::new(); for (idx, env) in envelope @@ -594,15 +575,9 @@ impl Component for MailView { .push_back(UIEvent::StatusEvent(StatusEvent::BufClear)); { - let accounts = &context.accounts; - let mailbox = &accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - - let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; - let op = context.accounts[self.coordinates.0] - .backend - .operation(envelope.hash(), mailbox.folder.hash()); + let account = &mut context.accounts[self.coordinates.0]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); + let op = account.operation(&envelope.hash()); if let Some(u) = envelope.body(op).attachments().get(lidx) { match u.content_type() { ContentType::MessageRfc822 => { @@ -690,16 +665,10 @@ impl Component for MailView { .replies .push_back(UIEvent::StatusEvent(StatusEvent::BufClear)); let url = { - let accounts = &context.accounts; - let mailbox = &accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - - let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; + let account = &mut context.accounts[self.coordinates.0]; + let envelope: &Envelope = &account.get_env(&self.coordinates.2); let finder = LinkFinder::new(); - let op = context.accounts[self.coordinates.0] - .backend - .operation(envelope.hash(), mailbox.folder.hash()); + let op = account.operation(&envelope.hash()); let mut t = envelope.body(op).text().to_string(); let links: Vec<Link> = finder.links(&t).collect(); if let Some(u) = links.get(lidx) { diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index bac5c8e4..ee3531e7 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -146,16 +146,15 @@ impl ThreadView { } fn initiate(&mut self, expanded_hash: Option<ThreadHash>, context: &Context) { /* stack to push thread messages in order in order to pop and print them later */ - let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - let threads = &mailbox.collection.threads; + let account = &context.accounts[self.coordinates.0]; + let mailbox = &account[self.coordinates.1].as_ref().unwrap(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; let thread_iter = threads.thread_iter(self.coordinates.2); self.entries.clear(); for (line, (ind, thread_hash)) in thread_iter.enumerate() { let entry = if let Some(msg_hash) = threads.thread_nodes()[&thread_hash].message() { - let seen: bool = mailbox.collection[&msg_hash].is_seen(); + let seen: bool = account.get_env(&msg_hash).is_seen(); self.make_entry((ind, thread_hash, line), msg_hash, seen) } else { continue; @@ -180,7 +179,7 @@ impl ThreadView { let mut highlight_reply_subjects: Vec<Option<usize>> = Vec::with_capacity(self.entries.len()); for e in &mut self.entries { - let envelope: &Envelope = &mailbox.collection[&e.msg_hash]; + let envelope: &Envelope = &context.accounts[self.coordinates.0].get_env(&e.msg_hash); let thread_node = &threads.thread_nodes()[&e.index.1]; let string = if thread_node.show_subject() { let subject = envelope.subject(); @@ -533,10 +532,9 @@ impl ThreadView { /* First draw the thread subject on the first row */ let y = if self.dirty { - let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - let threads = &mailbox.collection.threads; + let account = &context.accounts[self.coordinates.0]; + let mailbox = &account[self.coordinates.1].as_ref().unwrap(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)]; let i = if let Some(i) = thread_node.message() { i @@ -545,7 +543,7 @@ impl ThreadView { .message() .unwrap() }; - let envelope: &Envelope = &mailbox.collection[&i]; + let envelope: &Envelope = account.get_env(&i); let (x, y) = write_string_to_grid( &envelope.subject(), @@ -613,10 +611,9 @@ impl ThreadView { /* First draw the thread subject on the first row */ let y = { - let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - let threads = &mailbox.collection.threads; + let account = &context.accounts[self.coordinates.0]; + let mailbox = &account[self.coordinates.1].as_ref().unwrap(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)]; let i = if let Some(i) = thread_node.message() { i @@ -627,7 +624,7 @@ impl ThreadView { } threads.thread_nodes()[&iter_ptr].message().unwrap() }; - let envelope: &Envelope = &mailbox.collection[&i]; + let envelope: &Envelope = account.get_env(&i); let (x, y) = write_string_to_grid( &envelope.subject(), @@ -833,10 +830,9 @@ impl Component for ThreadView { } UIEvent::Input(Key::Char('e')) => { { - let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1] - .as_ref() - .unwrap(); - let threads = &mailbox.collection.threads; + let account = &context.accounts[self.coordinates.0]; + let mailbox = &account[self.coordinates.1].as_ref().unwrap(); + let threads = &account.collection.threads[&mailbox.folder.hash()]; let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)]; let i = if let Some(i) = thread_node.message() { @@ -846,20 +842,18 @@ impl Component for ThreadView { .message() .unwrap() }; - let envelope: &Envelope = &mailbox.collection[&i]; - let op = context.accounts[self.coordinates.0] - .backend - .operation(envelope.hash(), mailbox.folder.hash()); + let envelope: &Envelope = &account.get_env(&i); + let op = account.operation(&envelope.hash()); debug!( "sending action edit for {}, {}", envelope.message_id(), op.description() ); + context.replies.push_back(UIEvent::Action(Tab(Edit( + self.coordinates.0, + envelope.hash(), + )))); } - context.replies.push_back(UIEvent::Action(Tab(Edit( - self.coordinates, - self.entries[self.expanded_pos].index.1, - )))); return true; } UIEvent::Input(Key::Up) => { diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 32691015..7ea825af 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -868,13 +868,18 @@ impl Component for StatusBar { return false; } } - let m = &context.accounts[*idx_a][*idx_f].as_ref().unwrap(); + let account = &context.accounts[*idx_a]; + let m = &account[*idx_f].as_ref().unwrap(); self.status = format!( "{} | Mailbox: {}, Messages: {}, New: {}", self.mode, m.folder.name(), - m.collection.len(), - m.collection.values().filter(|e| !e.is_seen()).count() + m.envelopes.len(), + m.envelopes + .iter() + .map(|h| &account.collection[&h]) + .filter(|e| !e.is_seen()) + .count() ); self.dirty = true; } @@ -1254,8 +1259,8 @@ impl Component for Tabbed { self.children[self.cursor_pos].set_dirty(); return true; } - UIEvent::Action(Tab(Edit(coordinates, msg))) => { - self.add_component(Box::new(Composer::edit(coordinates, msg, context))); + UIEvent::Action(Tab(Edit(account_pos, msg))) => { + self.add_component(Box::new(Composer::edit(account_pos, msg, context))); self.cursor_pos = self.children.len() - 1; self.children[self.cursor_pos].set_dirty(); return true; diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 02e4e258..7c78d9cc 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -31,9 +31,11 @@ use melib::async_workers::{Async, AsyncBuilder, AsyncStatus}; use melib::backends::FolderHash; use melib::error::Result; use melib::mailbox::backends::{ |