mirror of https://github.com/djcb/mu.git
message: sanitize maildir
Remove trailing '/' in maildirs, since people have that (like "/foo/"), and earlier version didn't complain about that. Fixes #2298
This commit is contained in:
parent
39d7096bba
commit
ed93ff4968
|
@ -800,14 +800,22 @@ Message::cache_path(Option<size_t> index) const
|
||||||
return Ok(std::string{priv_->cache_path});
|
return Ok(std::string{priv_->cache_path});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for now this only remove stray '/' at the end
|
||||||
|
std::string
|
||||||
|
Message::sanitize_maildir(const std::string& mdir)
|
||||||
|
{
|
||||||
|
if (mdir.size() > 1 && mdir.at(mdir.length()-1) == '/')
|
||||||
|
return mdir.substr(0, mdir.length() - 1);
|
||||||
|
else
|
||||||
|
return mdir;
|
||||||
|
}
|
||||||
|
|
||||||
Result<void>
|
Result<void>
|
||||||
Message::update_after_move(const std::string& new_path,
|
Message::update_after_move(const std::string& new_path,
|
||||||
const std::string& new_maildir,
|
const std::string& new_maildir,
|
||||||
Flags new_flags)
|
Flags new_flags)
|
||||||
{
|
{
|
||||||
const auto statbuf{get_statbuf(new_path)};
|
if (auto statbuf{get_statbuf(new_path)}; !statbuf)
|
||||||
if (!statbuf)
|
|
||||||
return Err(statbuf.error());
|
return Err(statbuf.error());
|
||||||
else
|
else
|
||||||
priv_->ctime = statbuf->st_ctime;
|
priv_->ctime = statbuf->st_ctime;
|
||||||
|
@ -820,7 +828,7 @@ Message::update_after_move(const std::string& new_path,
|
||||||
|
|
||||||
set_flags(new_flags);
|
set_flags(new_flags);
|
||||||
|
|
||||||
if (const auto res = set_maildir(new_maildir); !res)
|
if (const auto res = set_maildir(sanitize_maildir(new_maildir)); !res)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|
|
@ -208,6 +208,16 @@ public:
|
||||||
*/
|
*/
|
||||||
Result<void> set_maildir(const std::string& maildir);
|
Result<void> set_maildir(const std::string& maildir);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up the maildir. This is for internal use, but exposed for testing.
|
||||||
|
* For now cleaned-up means "stray trailing / removed".
|
||||||
|
*
|
||||||
|
* @param maildir some maildir
|
||||||
|
*
|
||||||
|
* @return a cleaned-up version
|
||||||
|
*/
|
||||||
|
static std::string sanitize_maildir(const std::string& maildir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the subject of this message
|
* Get the subject of this message
|
||||||
*
|
*
|
||||||
|
|
|
@ -823,6 +823,14 @@ test_message_fail ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_message_sanitize_maildir()
|
||||||
|
{
|
||||||
|
assert_equal(Message::sanitize_maildir("/"), "/");
|
||||||
|
assert_equal(Message::sanitize_maildir("/foo/bar"), "/foo/bar");
|
||||||
|
assert_equal(Message::sanitize_maildir("/foo/bar/cuux/"), "/foo/bar/cuux");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char* argv[])
|
main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -844,6 +852,8 @@ main(int argc, char* argv[])
|
||||||
test_message_calendar);
|
test_message_calendar);
|
||||||
g_test_add_func("/message/message/fail",
|
g_test_add_func("/message/message/fail",
|
||||||
test_message_fail);
|
test_message_fail);
|
||||||
|
g_test_add_func("/message/message/sanitize-maildir",
|
||||||
|
test_message_sanitize_maildir);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue