Fix imag-mail for new error interface

This commit is contained in:
Matthias Beyer 2018-02-12 21:15:01 +01:00
parent ee23f432de
commit 8128d3ade9

View file

@ -25,7 +25,7 @@ extern crate libimagmail;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagutil; extern crate libimagutil;
use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit}; use libimagerror::trace::{MapErrTrace, trace_error};
use libimagmail::mail::Mail; use libimagmail::mail::Mail;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
@ -67,19 +67,7 @@ fn list(rt: &Runtime) {
use libimagmail::error::MailErrorKind as MEK; use libimagmail::error::MailErrorKind as MEK;
use libimagmail::error::ResultExt; use libimagmail::error::ResultExt;
let store = rt.store(); // TODO: Implement lister type in libimagmail for this
let iter = match store.retrieve_for_module("ref") {
Ok(iter) => iter.filter_map(|id| {
match store.get(id).chain_err(|| MEK::RefHandlingError).map_err_trace() {
Ok(Some(fle)) => Mail::from_fle(fle).map_err_trace().ok(),
Ok(None) => None,
Err(e) => trace_error_exit(&e, 1),
}
}),
Err(e) => trace_error_exit(&e, 1),
};
fn list_mail(m: Mail) { fn list_mail(m: Mail) {
let id = match m.get_message_id() { let id = match m.get_message_id() {
Ok(Some(f)) => f, Ok(Some(f)) => f,
@ -125,10 +113,18 @@ fn list(rt: &Runtime) {
); );
} }
// TODO: Implement lister type in libimagmail for this let _ = rt.store()
for mail in iter { .retrieve_for_module("ref")
list_mail(mail) .map_err_trace_exit_unwrap(1)
} .filter_map(|id| {
rt.store()
.get(id)
.chain_err(|| MEK::RefHandlingError)
.map_err_trace_exit_unwrap(1)
.map(|fle| Mail::from_fle(fle).map_err_trace().ok())
})
.filter_map(|e| e)
.for_each(list_mail);
} }
fn mail_store(rt: &Runtime) { fn mail_store(rt: &Runtime) {