2016-08-09 13:38:35 +00:00
|
|
|
use std::result::Result as RResult;
|
|
|
|
use std::path::Path;
|
2016-09-21 16:14:20 +00:00
|
|
|
use std::path::PathBuf;
|
2016-08-09 13:38:35 +00:00
|
|
|
|
|
|
|
use libimagstore::store::{FileLockEntry, Store};
|
2016-09-21 16:14:20 +00:00
|
|
|
use libimagref::reference::Ref;
|
|
|
|
use libimagref::flags::RefFlags;
|
2016-08-09 13:38:35 +00:00
|
|
|
|
2016-09-21 15:43:27 +00:00
|
|
|
use mailparse::{MailParseError, ParsedMail, parse_mail};
|
|
|
|
|
2016-09-21 16:14:20 +00:00
|
|
|
use hasher::MailHasher;
|
2016-09-21 15:43:27 +00:00
|
|
|
use result::Result;
|
2016-09-21 16:14:20 +00:00
|
|
|
use error::{MapErrInto, MailErrorKind as MEK};
|
2016-09-21 15:43:27 +00:00
|
|
|
|
|
|
|
struct Buffer(String);
|
|
|
|
|
|
|
|
impl Buffer {
|
|
|
|
pub fn parsed<'a>(&'a self) -> RResult<ParsedMail<'a>, MailParseError> {
|
|
|
|
parse_mail(self.0.as_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for Buffer {
|
|
|
|
fn from(data: String) -> Buffer {
|
|
|
|
Buffer(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-21 16:14:20 +00:00
|
|
|
pub struct Mail<'a>(Ref<'a>);
|
2016-08-09 13:38:35 +00:00
|
|
|
|
|
|
|
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> {
|
2016-09-21 16:14:20 +00:00
|
|
|
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))
|
2016-08-09 13:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Opens a mail by the passed hash
|
|
|
|
pub fn open<S: AsRef<str>>(store: &Store, hash: S) -> Result<Option<Mail>> {
|
2016-09-21 17:11:31 +00:00
|
|
|
Ref::get_by_hash(store, String::from(hash.as_ref()))
|
|
|
|
.map(|opt| opt.map(|r| Mail(r)))
|
|
|
|
.map_err_into(MEK::FetchByHashError)
|
|
|
|
.map_err_into(MEK::FetchError)
|
2016-08-09 13:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_field<S: AsRef<str>>(&self, field: S) -> Result<Option<&str>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_from(&self) -> Result<Option<&str>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_to(&self) -> Result<Option<&str>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_subject(&self) -> Result<Option<&str>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_message_id(&self) -> Result<Option<&str>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_in_reply_to(&self) -> Result<Option<&str>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|