Fix libimagmail to use new libimagentryref interface

This commit is contained in:
Matthias Beyer 2017-08-28 09:54:25 +02:00
parent d58b97fdf1
commit 6d40797a07
2 changed files with 16 additions and 14 deletions

View file

@ -27,16 +27,17 @@
use mail::Mail; use mail::Mail;
use result::Result; use result::Result;
use libimagstore::store::FileLockEntry;
use libimagentryref::reference::Ref; use libimagentryref::reference::Ref;
use std::marker::PhantomData; use std::marker::PhantomData;
pub struct MailIter<'a, I: 'a + Iterator<Item = Ref<'a>>> { pub struct MailIter<'a, I: Iterator<Item = FileLockEntry<'a>>> {
_marker: PhantomData<&'a I>, _marker: PhantomData<I>,
i: I, i: I,
} }
impl<'a, I: Iterator<Item = Ref<'a>>> MailIter<'a, I> { impl<'a, I: Iterator<Item = FileLockEntry<'a>>> MailIter<'a, I> {
pub fn new(i: I) -> MailIter<'a, I> { pub fn new(i: I) -> MailIter<'a, I> {
MailIter { _marker: PhantomData, i: i } MailIter { _marker: PhantomData, i: i }
@ -44,12 +45,11 @@ impl<'a, I: Iterator<Item = Ref<'a>>> MailIter<'a, I> {
} }
impl<'a, I: Iterator<Item = Ref<'a>>> Iterator for MailIter<'a, I> { impl<'a, I: Iterator<Item = FileLockEntry<'a>>> Iterator for MailIter<'a, I> {
type Item = Result<Mail<'a>>; type Item = Result<Mail<'a>>;
fn next(&mut self) -> Option<Result<Mail<'a>>> { fn next(&mut self) -> Option<Self::Item> {
self.i.next().map(Mail::from_ref) self.i.next().map(Mail::from_fle)
} }
} }

View file

@ -23,8 +23,10 @@ use std::fs::File;
use std::io::Read; use std::io::Read;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::store::FileLockEntry;
use libimagentryref::reference::Ref; use libimagentryref::reference::Ref;
use libimagentryref::flags::RefFlags; use libimagentryref::flags::RefFlags;
use libimagentryref::refstore::RefStore;
use email::MimeMessage; use email::MimeMessage;
use email::results::ParsingResult as EmailParsingResult; use email::results::ParsingResult as EmailParsingResult;
@ -47,7 +49,7 @@ impl From<String> for Buffer {
} }
} }
pub struct Mail<'a>(Ref<'a>, Buffer); pub struct Mail<'a>(FileLockEntry<'a>, Buffer);
impl<'a> Mail<'a> { 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 f = RefFlags::default().with_content_hashing(true).with_permission_tracking(false);
let p = PathBuf::from(p.as_ref()); 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) .map_err_into(MEK::RefCreationError)
.and_then(|reference| { .and_then(|reference| {
reference.fs_file() reference.fs_file()
@ -76,19 +78,19 @@ impl<'a> Mail<'a> {
/// Opens a mail by the passed hash /// Opens a mail by the passed hash
pub fn open<S: AsRef<str>>(store: &Store, hash: S) -> Result<Option<Mail>> { pub fn open<S: AsRef<str>>(store: &Store, hash: S) -> Result<Option<Mail>> {
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::FetchByHashError)
.map_err_into(MEK::FetchError) .map_err_into(MEK::FetchError)
.and_then(|o| match o { .and_then(|o| match o {
Some(r) => Mail::from_ref(r).map(Some), Some(r) => Mail::from_fle(r).map(Some),
None => Ok(None), None => Ok(None),
}) })
} }
/// Implement me as TryFrom as soon as it is stable /// Implement me as TryFrom as soon as it is stable
pub fn from_ref(r: Ref<'a>) -> Result<Mail> { pub fn from_fle(fle: FileLockEntry<'a>) -> Result<Mail<'a>> {
r.fs_file() fle.fs_file()
.map_err_into(MEK::RefHandlingError) .map_err_into(MEK::RefHandlingError)
.and_then(|path| File::open(path).map_err_into(MEK::IOError)) .and_then(|path| File::open(path).map_err_into(MEK::IOError))
.and_then(|mut file| { .and_then(|mut file| {
@ -98,7 +100,7 @@ impl<'a> Mail<'a> {
.map_err_into(MEK::IOError) .map_err_into(MEK::IOError)
}) })
.map(Buffer::from) .map(Buffer::from)
.map(|buffer| Mail(r, buffer)) .map(|buffer| Mail(fle, buffer))
} }
pub fn get_field(&self, field: &str) -> Result<Option<String>> { pub fn get_field(&self, field: &str) -> Result<Option<String>> {