summaryrefslogtreecommitdiffstats
path: root/libimagmail
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-09-21 18:14:20 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-10-12 19:17:40 +0200
commit5b8239e45e01fc8917d7f058434d49a33f92cb5e (patch)
tree6b8c6d3ca1900e2617d533769d435563d34e146f /libimagmail
parent03ae71497046f915125806ce4fb9dd687c3836ac (diff)
Impl Mail::import_from_path()
Diffstat (limited to 'libimagmail')
-rw-r--r--libimagmail/src/mail.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/libimagmail/src/mail.rs b/libimagmail/src/mail.rs
index 897fc37e..cae45db1 100644
--- a/libimagmail/src/mail.rs
+++ b/libimagmail/src/mail.rs
@@ -1,11 +1,16 @@
use std::result::Result as RResult;
use std::path::Path;
+use std::path::PathBuf;
use libimagstore::store::{FileLockEntry, Store};
+use libimagref::reference::Ref;
+use libimagref::flags::RefFlags;
use mailparse::{MailParseError, ParsedMail, parse_mail};
+use hasher::MailHasher;
use result::Result;
+use error::{MapErrInto, MailErrorKind as MEK};
struct Buffer(String);
@@ -21,16 +26,19 @@ impl From<String> for Buffer {
}
}
-pub struct Mail<'a> {
- fle: FileLockEntry<'a>,
- buffer: Buffer,
-}
+pub struct Mail<'a>(Ref<'a>);
impl<'a> Mail<'a> {
/// Imports a mail from the Path passed
pub fn import_from_path<P: AsRef<Path>>(store: &Store, p: P) -> Result<Mail> {
- unimplemented!()
+ let h = MailHasher::new();
+ 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)
+ .map_err_into(MEK::RefCreationError)
+ .map(|r| Mail(r))
}
/// Imports a mail from the String passed