use std::ffi::CString;
use std::path::PathBuf;
use supercow::{Supercow};
use error::{Error, Result};
use ffi;
use utils::{ToStr, ScopedPhantomcow, ScopedSupercow};
use Filenames;
use FilenamesOwner;
use Messages;
use Tags;
use TagsOwner;
use Query;
pub trait MessageOwner: Send + Sync {}
#[derive(Debug)]
pub(crate) struct MessagePtr {
pub ptr: *mut ffi::notmuch_message_t,
}
#[derive(Debug)]
pub struct Message<'d, 'q>
where
'd: 'q,
{
pub(crate) handle: MessagePtr,
marker: ScopedPhantomcow<'q, Query<'d>>,
}
impl<'d, 'q> MessageOwner for Message<'d, 'q> where 'd: 'q {}
impl<'d, 'q> FilenamesOwner for Message<'d, 'q> where 'd: 'q {}
impl<'d, 'q> TagsOwner for Message<'d, 'q> where 'd: 'q {}
impl<'d, 'q> Message<'d, 'q>
where
'd: 'q,
{
pub fn from_ptr
(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'d, 'q>
where
P: Into>>,
{
Message {
handle: MessagePtr { ptr },
marker: owner.into(),
}
}
pub fn id(self: &Self) -> String {
let mid = unsafe { ffi::notmuch_message_get_message_id(self.handle.ptr) };
mid.to_str().unwrap().to_string()
}
pub fn thread_id(self: &Self) -> String {
let tid = unsafe { ffi::notmuch_message_get_thread_id(self.handle.ptr) };
tid.to_str().unwrap().to_string()
}
pub fn replies(self: &mut Self) -> Messages<'d, 'q>
{
Messages::from_ptr(
unsafe { ffi::notmuch_message_get_replies(self.handle.ptr) },
ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker),
)
}
#[cfg(feature = "v0_26")]
pub fn count_files(self: &Self) -> i32 {
unsafe { ffi::notmuch_message_count_files(self.handle.ptr) }
}
pub fn filenames(self: &Self) -> Filenames {
>::filenames(self)
}
pub fn filename(self: &Self) -> PathBuf {
PathBuf::from(
unsafe { ffi::notmuch_message_get_filename(self.handle.ptr) }
.to_str()
.unwrap(),
)
}
pub fn date(&self) -> i64 {
unsafe { ffi::notmuch_message_get_date(self.handle.ptr) as i64 }
}
pub fn header(&self, name: &str) -> Result