summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-12 22:45:37 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-02 23:22:12 +0100
commit0122e59bb073a4bee0e74f6d1e09c32e077dc249 (patch)
tree0b39a6d12ba2f59afe3e21c34dcbf2d633ac074f
parent759d57e79738f62d83ff852d7390279096688437 (diff)
Rewrite Hasher::hash() for MailHasher
Because message ids should be unique, we consider this to be safe. This should seems to be the best practice. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/hasher.rs20
1 files changed, 4 insertions, 16 deletions
diff --git a/lib/domain/libimagmail/src/hasher.rs b/lib/domain/libimagmail/src/hasher.rs
index da7170b7..2ecbc7b1 100644
--- a/lib/domain/libimagmail/src/hasher.rs
+++ b/lib/domain/libimagmail/src/hasher.rs
@@ -22,34 +22,22 @@ use std::path::Path;
use failure::Fallible as Result;
use libimagentryref::hasher::Hasher;
-use libimagerror::errors::ErrorMsg;
-use libimagentryref::hasher::sha1::Sha1Hasher;
pub struct MailHasher;
impl Hasher for MailHasher {
const NAME: &'static str = "MailHasher";
- /// hash the file at path `path`
+ /// Hash the Messgae-ID
///
- /// We create a sha1 over the path of the file (which is NOT safe, because mails can move) and
- /// the Message-ID of the mail itself.
+ /// We create a sha1 over the Message-ID of the mail itself. As a Message-ID should be unique,
+ /// this can be considered save.
///
/// # TODO: Fix
///
/// The file name is not constant with mail files, because flags are encoded in the filename.
/// The path is not constant with mail files, because they can be moved between boxes.
fn hash<P: AsRef<Path>>(path: P) -> Result<String> {
- let mut path_str = path
- .as_ref()
- .to_str()
- .map(String::from)
- .ok_or_else(|| ErrorMsg::UTF8Error)?;
-
- let message_id : String = crate::util::get_message_id_for_mailfile(path)?.into();
-
- path_str.push_str(&message_id);
-
- Ok(Sha1Hasher::sha1_hash(path_str.as_bytes()))
+ crate::util::get_message_id_for_mailfile(path).map(Into::into)
}
}