From 6d40797a0755ada383261896605cab75ac2c3ecc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 28 Aug 2017 09:54:25 +0200 Subject: [PATCH] Fix libimagmail to use new libimagentryref interface --- lib/domain/libimagmail/src/iter.rs | 14 +++++++------- lib/domain/libimagmail/src/mail.rs | 16 +++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/domain/libimagmail/src/iter.rs b/lib/domain/libimagmail/src/iter.rs index fe1e72a4..6fee9e64 100644 --- a/lib/domain/libimagmail/src/iter.rs +++ b/lib/domain/libimagmail/src/iter.rs @@ -27,16 +27,17 @@ use mail::Mail; use result::Result; +use libimagstore::store::FileLockEntry; use libimagentryref::reference::Ref; use std::marker::PhantomData; -pub struct MailIter<'a, I: 'a + Iterator>> { - _marker: PhantomData<&'a I>, +pub struct MailIter<'a, I: Iterator>> { + _marker: PhantomData, i: I, } -impl<'a, I: Iterator>> MailIter<'a, I> { +impl<'a, I: Iterator>> MailIter<'a, I> { pub fn new(i: I) -> MailIter<'a, I> { MailIter { _marker: PhantomData, i: i } @@ -44,12 +45,11 @@ impl<'a, I: Iterator>> MailIter<'a, I> { } -impl<'a, I: Iterator>> Iterator for MailIter<'a, I> { - +impl<'a, I: Iterator>> Iterator for MailIter<'a, I> { type Item = Result>; - fn next(&mut self) -> Option>> { - self.i.next().map(Mail::from_ref) + fn next(&mut self) -> Option { + self.i.next().map(Mail::from_fle) } } diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs index 11b57398..d5f02cdf 100644 --- a/lib/domain/libimagmail/src/mail.rs +++ b/lib/domain/libimagmail/src/mail.rs @@ -23,8 +23,10 @@ use std::fs::File; use std::io::Read; use libimagstore::store::Store; +use libimagstore::store::FileLockEntry; use libimagentryref::reference::Ref; use libimagentryref::flags::RefFlags; +use libimagentryref::refstore::RefStore; use email::MimeMessage; use email::results::ParsingResult as EmailParsingResult; @@ -47,7 +49,7 @@ impl From for Buffer { } } -pub struct Mail<'a>(Ref<'a>, Buffer); +pub struct Mail<'a>(FileLockEntry<'a>, Buffer); impl<'a> Mail<'a> { @@ -57,7 +59,7 @@ impl<'a> Mail<'a> { let f = RefFlags::default().with_content_hashing(true).with_permission_tracking(false); let p = PathBuf::from(p.as_ref()); - Ref::create_with_hasher(store, p, f, h) + store.create_with_hasher(p, f, h) .map_err_into(MEK::RefCreationError) .and_then(|reference| { reference.fs_file() @@ -76,19 +78,19 @@ impl<'a> Mail<'a> { /// Opens a mail by the passed hash pub fn open>(store: &Store, hash: S) -> Result> { - Ref::get_by_hash(store, String::from(hash.as_ref())) + store.get_by_hash(String::from(hash.as_ref())) .map_err_into(MEK::FetchByHashError) .map_err_into(MEK::FetchError) .and_then(|o| match o { - Some(r) => Mail::from_ref(r).map(Some), + Some(r) => Mail::from_fle(r).map(Some), None => Ok(None), }) } /// Implement me as TryFrom as soon as it is stable - pub fn from_ref(r: Ref<'a>) -> Result { - r.fs_file() + pub fn from_fle(fle: FileLockEntry<'a>) -> Result> { + fle.fs_file() .map_err_into(MEK::RefHandlingError) .and_then(|path| File::open(path).map_err_into(MEK::IOError)) .and_then(|mut file| { @@ -98,7 +100,7 @@ impl<'a> Mail<'a> { .map_err_into(MEK::IOError) }) .map(Buffer::from) - .map(|buffer| Mail(r, buffer)) + .map(|buffer| Mail(fle, buffer)) } pub fn get_field(&self, field: &str) -> Result> {