Browse Source

Replace some panics with errors

tags/alpha-0.4.1
Manos Pitsidianakis 2 months ago
parent
commit
58209d6f6b
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
4 changed files with 48 additions and 13 deletions
  1. +38
    -10
      melib/src/backends/mbox.rs
  2. +6
    -2
      melib/src/backends/notmuch.rs
  3. +1
    -1
      melib/src/email/parser.rs
  4. +3
    -0
      melib/src/thread.rs

+ 38
- 10
melib/src/backends/mbox.rs View File

@@ -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;
}
}
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;
}
}
/* Envelope hasn't changed */
DebouncedEvent::Rename(src, dest) => panic!(format!(
"mbox folder {} was renamed to {}.",
src.display(),
dest.display()
)),
/* Trigger rescan of folder */
/* 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;
}
_ => {}
},


+ 6
- 2
melib/src/backends/notmuch.rs View File

@@ -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 };


+ 1
- 1
melib/src/email/parser.rs View File

@@ -901,7 +901,7 @@ pub fn phrase(input: &[u8]) -> IResult<&[u8], Vec<u8>> {
);
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" ")


+ 3
- 0
melib/src/thread.rs View File

@@ -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();


Loading…
Cancel
Save