aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tagrules.cpp15
-rw-r--r--src/tagrules.h9
2 files changed, 23 insertions, 1 deletions
diff --git a/src/tagrules.cpp b/src/tagrules.cpp
index 0049278..c25ed59 100644
--- a/src/tagrules.cpp
+++ b/src/tagrules.cpp
@@ -41,7 +41,7 @@ bool isKnownKey(const QString &key)
QStringLiteral("id"), QStringLiteral("stage"),
QStringLiteral("enabled"), QStringLiteral("add"),
QStringLiteral("remove"), QStringLiteral("query"),
- QStringLiteral("note"),
+ QStringLiteral("note"), QStringLiteral("allow_archive"),
};
return known.contains(key);
}
@@ -256,6 +256,8 @@ void TagRules::load(const QString &path)
rule.stage = object.value(QStringLiteral("stage")).toInt(kDefaultStage);
rule.enabled = object.value(QStringLiteral("enabled")).toBool(true);
rule.note = object.value(QStringLiteral("note")).toString();
+ rule.allowArchive =
+ object.value(QStringLiteral("allow_archive")).toBool(false);
for (auto it = object.begin(); it != object.end(); ++it) {
if (!isKnownKey(it.key()))
@@ -267,6 +269,13 @@ void TagRules::load(const QString &path)
}
}
+bool TagRules::hookWouldSkip(const TagRule &rule)
+{
+ if (rule.remove.contains(QStringLiteral("unread")))
+ return true;
+ return rule.remove.contains(QStringLiteral("inbox")) && !rule.allowArchive;
+}
+
bool TagRules::save(const QString &path) const
{
const QString target = path.isEmpty() ? defaultPath() : path;
@@ -285,6 +294,10 @@ bool TagRules::save(const QString &path) const
QJsonArray::fromStringList(rule.remove));
object.insert(QStringLiteral("query"), rule.query);
object.insert(QStringLiteral("note"), rule.note);
+ // Written only where it does something, so a file without an
+ // archiving rule saves byte-identical (item 213).
+ if (rule.allowArchive && rule.remove.contains(QStringLiteral("inbox")))
+ object.insert(QStringLiteral("allow_archive"), true);
for (auto it = rule.unknown.begin(); it != rule.unknown.end(); ++it)
object.insert(it.key(), it.value());
array.append(object);
diff --git a/src/tagrules.h b/src/tagrules.h
index 4d3f0ab..e2c8667 100644
--- a/src/tagrules.h
+++ b/src/tagrules.h
@@ -39,6 +39,10 @@ struct TagRule
QStringList remove;
int stage = 50; ///< Ascending. Account tags 10, topic rules 50.
bool enabled = true;
+ /// Lets the post-new hook remove `inbox` from arriving mail for this rule
+ /// (item 213). Meaningless, and cleared on save, unless `remove` holds
+ /// `inbox`. `unread` stays refused regardless.
+ bool allowArchive = false;
/// Fields this version of qtmaildir does not understand, kept verbatim and
/// written back on save. Without this, one save from here silently strips
@@ -100,6 +104,11 @@ public:
/// could reach the file and never come back.
static QStringList validate(const QList<TagRule> &rules);
+ /// Whether the post-new hook will skip this rule whole. Mirrors
+ /// PROTECTED_REMOVALS in assets/hooks/post-new: `unread` always, `inbox`
+ /// unless the rule opts in with allowArchive.
+ static bool hookWouldSkip(const TagRule &rule);
+
/// No file yet, as distinct from a file that would not load. A fresh
/// install is not an error and must not be reported as one.
bool missing() const { return m_missing; }