From 0122e59bb073a4bee0e74f6d1e09c32e077dc249 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 12 Dec 2019 22:45:37 +0100 Subject: 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 --- lib/domain/libimagmail/src/hasher.rs | 20 ++++---------------- 1 file 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>(path: P) -> Result { - 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) } } -- cgit v1.2.3