summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-05-24 16:05:05 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-05-24 17:17:00 +0300
commitec3b55f2ab4e9997661fe774c459686394268f74 (patch)
tree7f6a041f99c766efcbef1c65e1f79853905d8a75 /lib
parent3e054523437a94adc4ba3966ff946134075080ef (diff)
message: retain non-file flags when moving
The content-flags won't change, and the unread-flag can be re-calculated. Add a unit test, and some small doc improvements. Fixes #2831.
Diffstat (limited to 'lib')
-rw-r--r--lib/message/mu-flags.hh7
-rw-r--r--lib/message/mu-message.cc8
-rw-r--r--lib/message/mu-message.hh20
-rw-r--r--lib/mu-store.hh20
4 files changed, 33 insertions, 22 deletions
diff --git a/lib/message/mu-flags.hh b/lib/message/mu-flags.hh
index 8e424dd..ee01702 100644
--- a/lib/message/mu-flags.hh
+++ b/lib/message/mu-flags.hh
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2022-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2022-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@@ -86,7 +86,7 @@ enum struct MessageFlagCategory {
};
/**
- * Info about invidual message flags
+ * Info about individual message flags
*
*/
struct MessageFlagInfo {
@@ -373,9 +373,6 @@ flags_maildir_file(Flags flags)
return flags;
}
-
-
-
/**
* Return flags, where flags = new_flags but with unmutable_flag in the
* result the same as in old_flags
diff --git a/lib/message/mu-message.cc b/lib/message/mu-message.cc
index 3d4d2df..339abd1 100644
--- a/lib/message/mu-message.cc
+++ b/lib/message/mu-message.cc
@@ -881,6 +881,14 @@ Message::update_after_move(const std::string& new_path,
priv_->doc.add(Field::Id::Path, new_path);
priv_->doc.add(Field::Id::Changed, priv_->ctime);
+ // note: content-flags are retained from the existing; the unread flag
+ // is implied. only file-flags are allowed for new_flags; anything else
+ // is filtered-out
+
+ new_flags = flags_maildir_file(new_flags);
+ new_flags |= flags_filter(flags(), MessageFlagCategory::Content);
+ new_flags = imply_unread(new_flags);
+
set_flags(new_flags);
if (const auto res = set_maildir(sanitize_maildir(new_maildir)); !res)
diff --git a/lib/message/mu-message.hh b/lib/message/mu-message.hh
index 9be9096..c6b6917 100644
--- a/lib/message/mu-message.hh
+++ b/lib/message/mu-message.hh
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2022-2024 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2022-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@@ -292,11 +292,10 @@ public:
*/
Flags flags() const { return document().flags_value(); }
-
/**
- * Update the flags for this message. This is useful for flags
- * that can only be determined after the message has been created already,
- * such as the 'personal' flag.
+ * Update the flags for this message. This is useful for flags that can
+ * only be determined after the message has been created already, such
+ * as the 'personal' flag.
*
* @param flags new flags.
*/
@@ -366,11 +365,14 @@ public:
*/
const Sexp& sexp() const;
- /*
- * And some non-const message, for updating an existing
- * message after a file-system move.
+ /**
+ * Update the message after a move
+ *
+ * @param new_path the new file-system path; non-file flags are ignored
+ * @param new_maildir the new maildir
+ * @param new_flags the new flags
*
- * @return Ok or an error.
+ * @return Ok() or some error.
*/
Result<void> update_after_move(const std::string& new_path,
const std::string& new_maildir,
diff --git a/lib/mu-store.hh b/lib/mu-store.hh
index 24130de..cc7946a 100644
--- a/lib/mu-store.hh
+++ b/lib/mu-store.hh
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2024 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2017-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@@ -306,20 +306,24 @@ public:
};
/**
- * Move a message both in the filesystem and in the store. After a successful move, the
- * message is updated.
+ * Move a message both in the filesystem and in the store.
+ *
+ * After a successful move, the message is updated. A moved message gets
+ * a new doc-id, since the message-path is a unique-id for the message
*
* @param id the id for some message
* @param target_mdir the target maildir (if any)
* @param new_flags new flags (if any)
* @param opts move options
*
- * @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.
+ * @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.
+ * 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<IdPathVec> move_message(Store::Id id,
Option<const std::string&> target_mdir = Nothing,