diff --git a/lib/message/mu-message.cc b/lib/message/mu-message.cc index 2d1d333e..facfc726 100644 --- a/lib/message/mu-message.cc +++ b/lib/message/mu-message.cc @@ -36,6 +36,7 @@ #include #include +#include #include #include "gmime/gmime-message.h" @@ -231,6 +232,7 @@ Message::load_mime_message(bool reload) const return false; } else { priv_->mime_msg = std::move(mime_msg.value()); + fill_document(*priv_); return true; } } @@ -784,20 +786,29 @@ Message::parts() const } Result -Message::cache_path() const +Message::cache_path(Option index) const { /* create tmpdir for this message, if needed */ if (priv_->cache_path.empty()) { GError *err{}; - auto tpath{to_string_opt_gchar( - g_dir_make_tmp("mu-message-part-XXXXXX", &err))}; + auto tpath{to_string_opt_gchar(g_dir_make_tmp("mu-cache-XXXXXX", &err))}; if (!tpath) - return Err(Error::Code::File, &err, - "failed to create temp dir"); + return Err(Error::Code::File, &err, "failed to create temp dir"); + priv_->cache_path = std::move(tpath.value()); } - return Ok(std::string{priv_->cache_path}); + if (index) { + GError *err{}; + auto tpath = format("%s/%zu", priv_->cache_path.c_str(), *index); + if (g_mkdir(tpath.c_str(), 0700) != 0) + return Err(Error::Code::File, &err, + "failed to create cache dir '%s'; err=%d", + tpath.c_str(), errno); + return Ok(std::move(tpath)); + } else + + return Ok(std::string{priv_->cache_path}); } diff --git a/lib/message/mu-message.hh b/lib/message/mu-message.hh index 9b60c61c..650a53e1 100644 --- a/lib/message/mu-message.hh +++ b/lib/message/mu-message.hh @@ -399,9 +399,12 @@ public: * Get the path to a cche directory for this message, which * is useful for temporarily saving attachments * + * @param index optionally, create / instead; + * this is useful for having part-specific subdirectories. + * * @return path to a (created) cache directory, or an error. */ - Result cache_path() const; + Result cache_path(Option index={}) const; /**