diff options
| author | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2022-07-13 23:27:54 +0300 |
|---|---|---|
| committer | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2022-07-13 23:27:54 +0300 |
| commit | ed93ff49687362512270a47e8c05ad37b4a225f1 (patch) | |
| tree | d25e59e5ab2a3b3ea6f5e920754e1ec4167b8ea4 | |
| parent | 39d7096bba656cc64ec3ca8cc21ea3e6de9c2056 (diff) | |
message: sanitize maildir
Remove trailing '/' in maildirs, since people have that (like "/foo/"),
and earlier version didn't complain about that.
Fixes #2298
| -rw-r--r-- | lib/message/mu-message.cc | 14 | ||||
| -rw-r--r-- | lib/message/mu-message.hh | 10 | ||||
| -rw-r--r-- | lib/message/test-mu-message.cc | 10 |
3 files changed, 31 insertions, 3 deletions
diff --git a/lib/message/mu-message.cc b/lib/message/mu-message.cc index ea3507c..4c5fc4d 100644 --- a/lib/message/mu-message.cc +++ b/lib/message/mu-message.cc @@ -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(); diff --git a/lib/message/mu-message.hh b/lib/message/mu-message.hh index 2e30222..043ef42 100644 --- a/lib/message/mu-message.hh +++ b/lib/message/mu-message.hh @@ -209,6 +209,16 @@ public: 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 * * @return the subject of this Message diff --git a/lib/message/test-mu-message.cc b/lib/message/test-mu-message.cc index 3363088..5311e86 100644 --- a/lib/message/test-mu-message.cc +++ b/lib/message/test-mu-message.cc @@ -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 main(int argc, char* argv[]) { @@ -844,6 +852,8 @@ main(int argc, char* argv[]) test_message_calendar); g_test_add_func("/message/message/fail", test_message_fail); + g_test_add_func("/message/message/sanitize-maildir", + test_message_sanitize_maildir); return g_test_run(); } |
