summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-02 15:56:52 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-02 18:46:03 +0100
commitce12e29163e8f8d3c35010b124aafe5e45caad30 (patch)
treea7215ff47a50dc4f7c4afcca25646279948b2892
parentbfe69c17b3a6912f042449720ab3b1c0ef9a6231 (diff)
downloadimag-ce12e29163e8f8d3c35010b124aafe5e45caad30.zip
imag-ce12e29163e8f8d3c35010b124aafe5e45caad30.tar.gz
Use MessageId type where applicable
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/domain/imag-mail/src/lib.rs2
-rw-r--r--lib/domain/libimagmail/src/hasher.rs2
-rw-r--r--lib/domain/libimagmail/src/mail.rs16
-rw-r--r--lib/domain/libimagmail/src/store.rs12
-rw-r--r--lib/domain/libimagmail/src/util.rs6
5 files changed, 22 insertions, 16 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs
index d3cb8c4..0dd7f2b 100644
--- a/bin/domain/imag-mail/src/lib.rs
+++ b/bin/domain/imag-mail/src/lib.rs
@@ -165,7 +165,7 @@ fn list(rt: &Runtime) -> Result<()> {
print_content: bool) -> Result<()> {
let id = match m.get_message_id(&refconfig)? {
- Some(f) => f,
+ Some(f) => f.into(),
None => "<no id>".to_owned(),
};
diff --git a/lib/domain/libimagmail/src/hasher.rs b/lib/domain/libimagmail/src/hasher.rs
index 26a41d2..f686029 100644
--- a/lib/domain/libimagmail/src/hasher.rs
+++ b/lib/domain/libimagmail/src/hasher.rs
@@ -46,7 +46,7 @@ impl Hasher for MailHasher {
.map(String::from)
.ok_or_else(|| ErrorMsg::UTF8Error)?;
- let message_id = crate::util::get_message_id_for_mailfile(path)?;
+ let message_id : String = crate::util::get_message_id_for_mailfile(path)?.into();
path_str.push_str(&message_id);
diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs
index d48ce00..78d2e67 100644
--- a/lib/domain/libimagmail/src/mail.rs
+++ b/lib/domain/libimagmail/src/mail.rs
@@ -27,6 +27,8 @@ use libimagentryutil::isa::IsKindHeaderPathProvider;
use libimagentryref::reference::Config as RefConfig;
use libimagentryref::reference::{Ref, RefFassade};
+use crate::mid::MessageId;
+
provide_kindflag_path!(pub IsMail, "mail.is_mail");
pub trait Mail : RefFassade {
@@ -35,8 +37,8 @@ pub trait Mail : RefFassade {
fn get_from(&self, refconfig: &RefConfig) -> Result<Option<String>>;
fn get_to(&self, refconfig: &RefConfig) -> Result<Option<String>>;
fn get_subject(&self, refconfig: &RefConfig) -> Result<Option<String>>;
- fn get_message_id(&self, refconfig: &RefConfig) -> Result<Option<String>>;
- fn get_in_reply_to(&self, refconfig: &RefConfig) -> Result<Option<String>>;
+ fn get_message_id(&self, refconfig: &RefConfig) -> Result<Option<MessageId>>;
+ fn get_in_reply_to(&self, refconfig: &RefConfig) -> Result<Option<MessageId>>;
}
impl Mail for Entry {
@@ -110,9 +112,9 @@ impl Mail for Entry {
/// # Note
///
/// Use `Mail::mail_header()` if you need to read more than one field.
- fn get_message_id(&self, refconfig: &RefConfig) -> Result<Option<String>> {
+ fn get_message_id(&self, refconfig: &RefConfig) -> Result<Option<MessageId>> {
self.get_field(refconfig, "Message-ID")
- .map(|o| o.map(crate::util::strip_message_delimiters))
+ .map(|o| o.map(crate::util::strip_message_delimiters).map(MessageId::from))
}
/// Get a value of the `In-Reply-To` field of the mail file
@@ -120,8 +122,9 @@ impl Mail for Entry {
/// # Note
///
/// Use `Mail::mail_header()` if you need to read more than one field.
- fn get_in_reply_to(&self, refconfig: &RefConfig) -> Result<Option<String>> {
+ fn get_in_reply_to(&self, refconfig: &RefConfig) -> Result<Option<MessageId>> {
self.get_field(refconfig, "In-Reply-To")
+ .map(|o| o.map(crate::util::strip_message_delimiters).map(MessageId::from))
}
}
@@ -182,8 +185,9 @@ impl<'a> MailHeader<'a> {
}
/// Get a value of the `In-Reply-To` field of the mail file
- pub fn get_in_reply_to(&self) -> Result<Option<String>> {
+ pub fn get_in_reply_to(&self) -> Result<Option<MessageId>> {
self.get_field("In-Reply-To")
+ .map(|o| o.map(crate::util::strip_message_delimiters).map(MessageId::from))
}
// TODO: Offer functionality to load and parse mail _once_ from disk, and then use helper object
diff --git a/lib/domain/libimagmail/src/store.rs b/lib/domain/libimagmail/src/store.rs
index 1366356..637dac5 100644
--- a/lib/domain/libimagmail/src/store.rs
+++ b/lib/domain/libimagmail/src/store.rs
@@ -69,7 +69,7 @@ impl<'a> MailStore<'a> for Store {
CollName: AsRef<str> + Debug
{
let message_id = get_message_id_for_mailfile(p.as_ref())?;
- let new_sid = crate::module_path::new_id(message_id.clone())?;
+ let new_sid = crate::module_path::new_id(message_id.as_ref())?;
let mut entry = self.create(new_sid)?;
entry
@@ -78,7 +78,7 @@ impl<'a> MailStore<'a> for Store {
let _ = entry
.get_header_mut()
- .insert("mail.message-id", Value::String(message_id))?;
+ .insert("mail.message-id", Value::String(message_id.into()))?;
entry.set_isflag::<IsMail>()?;
Ok(entry)
@@ -91,7 +91,7 @@ impl<'a> MailStore<'a> for Store {
where P: AsRef<Path> + Debug
{
let message_id = get_message_id_for_mailfile(p.as_ref())?;
- let new_sid = crate::module_path::new_id(message_id.clone())?;
+ let new_sid = crate::module_path::new_id(message_id.as_ref())?;
match self.get(new_sid)? {
Some(mut entry) => {
@@ -105,7 +105,7 @@ impl<'a> MailStore<'a> for Store {
p.as_ref().display()))
}
- let _ = entry.get_header_mut().insert("mail.message-id", Value::String(message_id))?;
+ let _ = entry.get_header_mut().insert("mail.message-id", Value::String(message_id.into()))?;
Ok(Some(entry))
},
None => Ok(None),
@@ -118,12 +118,12 @@ impl<'a> MailStore<'a> for Store {
CollName: AsRef<str> + Debug
{
let message_id = get_message_id_for_mailfile(&p)?;
- let new_sid = crate::module_path::new_id(message_id.clone())?;
+ let new_sid = crate::module_path::new_id(message_id.as_ref())?;
let mut entry = self.retrieve(new_sid)?;
let _ = entry
.get_header_mut()
- .insert("mail.message-id", Value::String(message_id))?;
+ .insert("mail.message-id", Value::String(message_id.into()))?;
entry
.as_ref_with_hasher_mut::<DefaultHasher>()
diff --git a/lib/domain/libimagmail/src/util.rs b/lib/domain/libimagmail/src/util.rs
index 2c43dd6..853f462 100644
--- a/lib/domain/libimagmail/src/util.rs
+++ b/lib/domain/libimagmail/src/util.rs
@@ -25,6 +25,8 @@ use failure::Error;
use failure::Fallible as Result;
use failure::ResultExt;
+use crate::mid::MessageId;
+
/// Get the message header at a specific key
///
/// # WARNING
@@ -67,8 +69,8 @@ pub(crate) fn get_message_header_at_key<P: AsRef<Path>, K: AsRef<str>>(p: P, k:
.and_then(|hdr| hdr.get_value().context("Cannot get value from mail header").map_err(Error::from))
}
-pub(crate) fn get_message_id_for_mailfile<P: AsRef<Path>>(p: P) -> Result<String> {
- get_message_header_at_key(p, "message-id").map(strip_message_delimiters)
+pub(crate) fn get_message_id_for_mailfile<P: AsRef<Path>>(p: P) -> Result<MessageId> {
+ get_message_header_at_key(p, "message-id").map(strip_message_delimiters).map(MessageId::from)
}
/// Strips message delimiters ('<' and '>') from a Message-ID field.