diff --git a/melib/src/backends/mbox.rs b/melib/src/backends/mbox.rs index 77c7b45f..9815eff4 100644 --- a/melib/src/backends/mbox.rs +++ b/melib/src/backends/mbox.rs @@ -520,18 +520,46 @@ impl MailBackend for MboxType { /* Remove */ DebouncedEvent::NoticeRemove(pathbuf) | DebouncedEvent::Remove(pathbuf) => { - panic!(format!("mbox folder {} was removed.", pathbuf.display())) + if folders + .lock() + .unwrap() + .values() + .any(|f| &f.path == &pathbuf) + { + let folder_hash = get_path_hash!(&pathbuf); + sender.send(RefreshEvent { + hash: folder_hash, + kind: RefreshEventKind::Failure(MeliError::new(format!( + "mbox folder {} was removed.", + pathbuf.display() + ))), + }); + return; + } } - /* Envelope hasn't changed */ - DebouncedEvent::Rename(src, dest) => panic!(format!( - "mbox folder {} was renamed to {}.", - src.display(), - dest.display() - )), - /* Trigger rescan of folder */ + DebouncedEvent::Rename(src, dest) => { + if folders.lock().unwrap().values().any(|f| &f.path == &src) { + let folder_hash = get_path_hash!(&src); + sender.send(RefreshEvent { + hash: folder_hash, + kind: RefreshEventKind::Failure(MeliError::new(format!( + "mbox folder {} was renamed to {}.", + src.display(), + dest.display() + ))), + }); + return; + } + } + /* Trigger rescan of folders */ DebouncedEvent::Rescan => { - /* Actually should rescan all folders */ - unreachable!("Unimplemented: rescan of all folders in MboxType") + for h in folders.lock().unwrap().keys() { + sender.send(RefreshEvent { + hash: *h, + kind: RefreshEventKind::Rescan, + }); + } + return; } _ => {} }, diff --git a/melib/src/backends/notmuch.rs b/melib/src/backends/notmuch.rs index 52a59dab..9c59bf0a 100644 --- a/melib/src/backends/notmuch.rs +++ b/melib/src/backends/notmuch.rs @@ -216,13 +216,17 @@ impl MailBackend for NotmuchDb { let query: *mut notmuch_query_t = unsafe { notmuch_query_create(*database_lck, query_str.as_ptr()) }; if query.is_null() { - panic!("Out of memory."); + tx.send(AsyncStatus::Payload(Err(MeliError::new("Could not create query. Out of memory?")))).unwrap(); + tx.send(AsyncStatus::Finished).unwrap(); + return; } let mut messages: *mut notmuch_messages_t = std::ptr::null_mut(); let status = unsafe { notmuch_query_search_messages(query, &mut messages as *mut _) }; if status != 0 { - panic!(status); + tx.send(AsyncStatus::Payload(Err(MeliError::new("Search for {} returned {}", folder.query_str.as_str(), status)))).unwrap(); + tx.send(AsyncStatus::Finished).unwrap(); + return; } assert!(!messages.is_null()); let iter = MessageIterator { messages }; diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 67c7308f..7108d396 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -901,7 +901,7 @@ pub fn phrase(input: &[u8]) -> IResult<&[u8], Vec> { ); break; } - if ascii_s == ascii_e { + if ascii_s >= ascii_e { /* We have the start of an encoded word but not the end, so parse it as ascii */ ascii_e = input[ascii_s..] .find(b" ") diff --git a/melib/src/thread.rs b/melib/src/thread.rs index 7de5097e..a1f2445c 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -962,6 +962,9 @@ impl Threads { .get(envelopes_lck[&env_hash].message_id().raw()) .cloned() { + if self.thread_nodes[&id].message.is_some() { + return false; + } self.thread_nodes.entry(id).and_modify(|n| { n.message = Some(env_hash); n.date = envelopes_lck[&env_hash].date();