~matthiasbeyer/imag

940ae85e63ae23166728460e9f48b8fcca777c3d — Matthias Beyer 9 months ago 4d0b274 imag-mail/scanner
Revert "Add helper function to create StoreId objects using the message id and the unique part of the filename"

This reverts commit cdc6e388748b1f88ea880ebc2ad44028050014af.
2 files changed, 10 insertions(+), 29 deletions(-)

M lib/domain/libimagmail/src/store.rs
M lib/domain/libimagmail/src/util.rs
M lib/domain/libimagmail/src/store.rs => lib/domain/libimagmail/src/store.rs +10 -8
@@ 41,6 41,7 @@ use crate::mid::MessageId;
use crate::mail::Mail;
use crate::mail::IsMail;
use crate::hasher::MailHasher;
use crate::util::get_message_id_for_mailfile;

pub trait MailStore<'a> {
    fn create_mail_from_path<P, CollName>(&'a self, p: P, collection_name: CollName, config: &Config)


@@ 70,8 71,9 @@ impl<'a> MailStore<'a> for Store {
        where P: AsRef<Path> + Debug,
              CollName: AsRef<str> + Debug
    {
        let mid       = crate::util::get_message_id_for_mailfile(p.as_ref())?;
        let new_sid   = crate::util::make_store_id_for_mailfile(p.as_ref(), &mid)?;
        let message_id = get_message_id_for_mailfile(p.as_ref())?;
        let new_sid    = crate::module_path::new_id(message_id.as_ref())?;

        let mut entry = self.create(new_sid)?;
        entry
            .as_ref_with_hasher_mut::<MailHasher>()


@@ 79,7 81,7 @@ impl<'a> MailStore<'a> for Store {

        let _ = entry
            .get_header_mut()
            .insert("mail.message-id", Value::String(mid.into()))?;
            .insert("mail.message-id", Value::String(message_id.into()))?;

        entry.set_isflag::<IsMail>()?;
        Ok(entry)


@@ 91,8 93,8 @@ impl<'a> MailStore<'a> for Store {
        -> Result<Option<FileLockEntry<'a>>>
        where P: AsRef<Path> + Debug
    {
        let mid     = crate::util::get_message_id_for_mailfile(p.as_ref())?;
        let new_sid = crate::util::make_store_id_for_mailfile(p.as_ref(), &mid)?;
        let message_id = get_message_id_for_mailfile(p.as_ref())?;
        let new_sid    = crate::module_path::new_id(message_id.as_ref())?;

        match self.get(new_sid)? {
            Some(mut entry) => {


@@ 106,7 108,7 @@ impl<'a> MailStore<'a> for Store {
                                           p.as_ref().display()))
                }

                let _ = entry.get_header_mut().insert("mail.message-id", Value::String(mid.into()))?;
                let _ = entry.get_header_mut().insert("mail.message-id", Value::String(message_id.into()))?;
                Ok(Some(entry))
            },
            None => Ok(None),


@@ 118,8 120,8 @@ impl<'a> MailStore<'a> for Store {
        where P: AsRef<Path> + Debug,
              CollName: AsRef<str> + Debug
    {
        let message_id = crate::util::get_message_id_for_mailfile(p.as_ref())?;
        let new_sid    = crate::util::make_store_id_for_mailfile(p.as_ref(), &message_id)?;
        let message_id = get_message_id_for_mailfile(&p)?;
        let new_sid    = crate::module_path::new_id(message_id.as_ref())?;

        trace!("Retrieving mail with Message-Id {}, StoreId: {}", message_id, new_sid);
        let mut entry  = self.retrieve(new_sid.clone())

M lib/domain/libimagmail/src/util.rs => lib/domain/libimagmail/src/util.rs +0 -21
@@ 25,8 25,6 @@ use failure::Error;
use failure::Fallible as Result;
use failure::ResultExt;

use libimagstore::storeid::StoreId;

use crate::mid::MessageId;

/// Get the message header at a specific key


@@ 71,25 69,6 @@ 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 make_store_id_for_mailfile<P>(p: P, message_id: &MessageId) -> Result<StoreId>
    where P: AsRef<Path>,
{
    use std::ffi::OsStr;

    let pathstr = p.as_ref()
        .file_name()
        .and_then(OsStr::to_str)
        .ok_or_else(|| format_err!("Non-UTF Path, cannot handle this: {}", p.as_ref().display()))?;

    let path_without_flags = pathstr.split(":").take(1).collect::<Vec<_>>();

    if path_without_flags.len() < 1 {
        return Err(format_err!("Failed to split path '{}' to remove flags", pathstr));
    }

    crate::module_path::new_id(format!("{}:{}", path_without_flags[0], message_id.as_ref()))
}

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)
}