diff --git a/lib/mu-store.cc b/lib/mu-store.cc index e8bafb93..c1afbfd2 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -548,7 +548,7 @@ Store::move_message(Store::Id id, if (none_of(opts & Store::MoveOptions::DupFlags) || message_id.empty() || !new_flags) return Ok(std::move(id_paths)); - /* handle the dupflags case; i.e. apply (a subset of) the flags to + /* handle the dup-flags case; i.e. apply (a subset of) the flags to * all messages with the same message-id as well */ auto dups{priv_->find_duplicates_unlocked(*this, message_id)}; for (auto&& dupid: dups) { @@ -562,17 +562,20 @@ Store::move_message(Store::Id id, /* For now, don't change Draft/Flagged/Trashed */ const auto dup_flags{filter_dup_flags(dup_msg->flags(), *new_flags)}; - /* use the updated new_flags and default MoveOptions (so we don't recurse, nor do we - * change the base-name of moved messages) */ + /* use the updated new_flags and MoveOptions without DupFlags (so we don't + * recurse) */ + opts = opts & ~MoveOptions::DupFlags; if (auto dup_res = priv_->move_message_unlocked( - std::move(*dup_msg), Nothing, - dup_flags, - Store::MoveOptions::None); !dup_res) + std::move(*dup_msg), Nothing, dup_flags, opts); !dup_res) mu_warning("failed to move dup: {}", dup_res.error().what()); else id_paths.emplace_back(dupid, dup_res->first); } + // sort the dup paths by name; + std::sort(id_paths.begin() + 1, id_paths.end(), + [](const auto& idp1, const auto& idp2) { return idp1.second < idp2.second; }); + return Ok(std::move(id_paths)); } diff --git a/lib/mu-store.hh b/lib/mu-store.hh index a1521891..a699a0ec 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -309,6 +309,9 @@ public: * @return Result, either an IdPathVec with ids and paths for the moved message(s) or some * error. Note that in case of success at least one message is returned, and only with * MoveOptions::DupFlags can it be more than one. + * + * The first element of the IdPathVec, is the main message that got move; any subsequent + * (if any) are the duplicate paths, sorted by path-name. */ Result move_message(Store::Id id, Option target_mdir = Nothing,