From a8c1016f3773174d891bbddd45731eec86f51cd2 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 12 Mar 2020 09:47:39 +0200 Subject: [PATCH] Add various logic checks --- melib/src/backends/imap.rs | 1 + melib/src/collection.rs | 8 +++++++- melib/src/thread.rs | 7 +++++++ src/bin.rs | 10 +++++++--- src/components/mail/view/thread.rs | 2 ++ src/conf/accounts.rs | 10 ++++++---- src/terminal/cells.rs | 3 +-- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 2be7a4e2..ef6465ea 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -827,6 +827,7 @@ impl ImapType { debug!("parse error for {:?}", l); } } + mailboxes.retain(|_, v| v.hash != 0); conn.send_command(b"LSUB \"\" \"*\"")?; conn.read_response(&mut res)?; debug!("out: {}", &res); diff --git a/melib/src/collection.rs b/melib/src/collection.rs index 700034ab..ccb2c0ca 100644 --- a/melib/src/collection.rs +++ b/melib/src/collection.rs @@ -350,8 +350,13 @@ impl Collection { } } - pub fn insert(&mut self, envelope: Envelope, mailbox_hash: MailboxHash) { + pub fn insert(&mut self, envelope: Envelope, mailbox_hash: MailboxHash) -> bool { let hash = envelope.hash(); + if self.message_ids.contains_key(envelope.message_id().raw()) { + /* Duplicate. For example could be same message sent to two mailing lists and we get + * it twice */ + return true; + }; self.mailboxes.entry(mailbox_hash).and_modify(|m| { m.insert(hash); }); @@ -369,6 +374,7 @@ impl Collection { { self.insert_reply(hash); } + false } pub fn insert_reply(&mut self, env_hash: EnvelopeHash) { diff --git a/melib/src/thread.rs b/melib/src/thread.rs index 859239e7..63fdd4e7 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -679,6 +679,13 @@ impl Threads { .message_ids .get(message_id) .cloned() + .or( + if envelopes_lck[&env_hash].thread() != ThreadNodeHash::null() { + Some(envelopes_lck[&env_hash].thread()) + } else { + None + }, + ) .unwrap_or_else(|| ThreadNodeHash::new()); { let mut node = self.thread_nodes.entry(new_id).or_default(); diff --git a/src/bin.rs b/src/bin.rs index 6ecdafe0..312569c4 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -97,11 +97,15 @@ fn notify( signals: &[c_int], sender: crossbeam::channel::Sender, ) -> std::result::Result, std::io::Error> { + use std::time::Duration; let alarm_sender = sender.clone(); let alarm_handler = move |info: &nix::libc::siginfo_t| { let value = unsafe { info.si_value().sival_ptr as u8 }; alarm_sender - .send(ThreadEvent::UIEvent(UIEvent::Timer(value))) + .send_timeout( + ThreadEvent::UIEvent(UIEvent::Timer(value)), + Duration::from_millis(500), + ) .unwrap(); }; unsafe { @@ -114,11 +118,11 @@ fn notify( loop { ctr %= 3; if ctr == 0 { - sender.send(ThreadEvent::Pulse).unwrap(); + sender.send_timeout(ThreadEvent::Pulse, Duration::from_millis(500)); } for signal in signals.pending() { - s.send(signal).unwrap(); + s.send_timeout(signal, Duration::from_millis(500)).unwrap(); } std::thread::sleep(std::time::Duration::from_millis(100)); diff --git a/src/components/mail/view/thread.rs b/src/components/mail/view/thread.rs index 3aed8c61..19483426 100644 --- a/src/components/mail/view/thread.rs +++ b/src/components/mail/view/thread.rs @@ -647,6 +647,7 @@ impl ThreadView { /* First draw the thread subject on the first row */ let y = if self.dirty { + clear_area(grid, area, crate::conf::value(context, "theme_default")); let account = &context.accounts[self.coordinates.0]; let threads = &account.collection.threads[&self.coordinates.1]; let thread_root = threads @@ -749,6 +750,7 @@ impl ThreadView { /* First draw the thread subject on the first row */ let y = { + clear_area(grid, area, crate::conf::value(context, "theme_default")); let account = &context.accounts[self.coordinates.0]; let threads = &account.collection.threads[&self.coordinates.1]; let thread_root = threads diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index 13da3714..d9e9595b 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -327,7 +327,6 @@ impl Account { } let mut tree: Vec = Vec::new(); - let mut collection: Collection = Collection::new(Default::default()); for (h, f) in ref_mailboxes.iter() { if !f.is_subscribed() { /* Skip unsubscribed mailbox */ @@ -344,7 +343,7 @@ impl Account { ); } }); - collection.new_mailbox(*h); + self.collection.new_mailbox(*h); } build_mailboxes_order(&mut tree, &mailbox_entries, &mut mailboxes_order); @@ -352,7 +351,6 @@ impl Account { self.mailbox_entries = mailbox_entries; self.tree = tree; self.sent_mailbox = sent_mailbox; - self.collection = collection; } fn new_worker( @@ -536,7 +534,11 @@ impl Account { ); } } - self.collection.insert(*envelope, mailbox_hash); + + if self.collection.insert(*envelope, mailbox_hash) { + /* is a duplicate */ + return None; + } if self.mailbox_entries[&mailbox_hash] .conf diff --git a/src/terminal/cells.rs b/src/terminal/cells.rs index 1affb8c9..2e72a3bc 100644 --- a/src/terminal/cells.rs +++ b/src/terminal/cells.rs @@ -1707,6 +1707,7 @@ pub fn write_string_to_grid( } } for c in s.chars() { + inspect_bounds!(grid, area, x, y, line_break); if c == '\r' { continue; } @@ -1753,8 +1754,6 @@ pub fn write_string_to_grid( _ => {} } x += 1; - - inspect_bounds!(grid, area, x, y, line_break); } (x, y) }