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:
Dirk-Jan C. Binnema
2022-07-13 23:27:54 +03:00
parent 39d7096bba
commit ed93ff4968
3 changed files with 31 additions and 3 deletions

View File

@ -800,14 +800,22 @@ Message::cache_path(Option<size_t> index) const
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>
Message::update_after_move(const std::string& new_path,
const std::string& new_maildir,
Flags new_flags)
{
const auto statbuf{get_statbuf(new_path)};
if (!statbuf)
if (auto statbuf{get_statbuf(new_path)}; !statbuf)
return Err(statbuf.error());
else
priv_->ctime = statbuf->st_ctime;
@ -820,7 +828,7 @@ Message::update_after_move(const std::string& new_path,
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 Ok();