mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 01:36:55 +00:00
Stop rule group
This commit is contained in:
parent
920fb87dbf
commit
d44fee3762
6 changed files with 68 additions and 44 deletions
|
@ -2917,15 +2917,13 @@ class Core {
|
|||
// Deferred rule (download headers, body, etc)
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
long id = jargs.getLong(0);
|
||||
if (id < 0) {
|
||||
List<EntityRule> rules = db.rule().getEnabledRules(message.folder, true);
|
||||
for (EntityRule rule : rules)
|
||||
if (rule.matches(context, message, null, null)) {
|
||||
rule.execute(context, message);
|
||||
if (rule.stop)
|
||||
break;
|
||||
}
|
||||
EntityRule.run(context, rules, message, null, null);
|
||||
} else {
|
||||
EntityRule rule = db.rule().getRule(id);
|
||||
if (rule == null)
|
||||
|
@ -2936,6 +2934,11 @@ class Core {
|
|||
|
||||
rule.execute(context, message);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
private static void onDownload(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException, JSONException {
|
||||
|
@ -4952,13 +4955,9 @@ class Core {
|
|||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
boolean executed = false;
|
||||
if (pro)
|
||||
for (EntityRule rule : rules)
|
||||
if (rule.matches(context, message, headers, html)) {
|
||||
rule.execute(context, message);
|
||||
executed = true;
|
||||
if (rule.stop)
|
||||
break;
|
||||
if (pro) {
|
||||
int applied = EntityRule.run(context, rules, message, headers, html);
|
||||
executed = (applied > 0);
|
||||
}
|
||||
|
||||
if (EntityFolder.INBOX.equals(folder.type))
|
||||
|
|
|
@ -159,6 +159,31 @@ public class EntityRule {
|
|||
return false;
|
||||
}
|
||||
|
||||
static int run(Context context, List<EntityRule> rules,
|
||||
EntityMessage message, List<Header> headers, String html)
|
||||
throws JSONException, MessagingException {
|
||||
int applied = 0;
|
||||
|
||||
List<String> stopped = new ArrayList<>();
|
||||
for (EntityRule rule : rules) {
|
||||
if (rule.group != null && stopped.contains(rule.group))
|
||||
continue;
|
||||
if (rule.matches(context, message, headers, html)) {
|
||||
if (rule.execute(context, message))
|
||||
applied++;
|
||||
if (rule.stop)
|
||||
if (rule.group == null)
|
||||
break;
|
||||
else {
|
||||
if (!stopped.contains(rule.group))
|
||||
stopped.add(rule.group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return applied;
|
||||
}
|
||||
|
||||
boolean matches(Context context, EntityMessage message, List<Header> headers, String html) throws MessagingException {
|
||||
try {
|
||||
JSONObject jcondition = new JSONObject(condition);
|
||||
|
|
|
@ -1217,19 +1217,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
continue;
|
||||
|
||||
EntityLog.log(context, "Executing rules message=" + message.id);
|
||||
|
||||
for (EntityRule rule : rules) {
|
||||
EntityLog.log(context, "Executing rules evaluating=" + rule.name);
|
||||
if (rule.matches(context, message, null, null)) {
|
||||
EntityLog.log(context, "Executing rules matches=" + rule.name);
|
||||
if (rule.execute(context, message)) {
|
||||
EntityLog.log(context, "Executing rules applied=" + rule.name);
|
||||
applied++;
|
||||
}
|
||||
if (rule.stop)
|
||||
break;
|
||||
}
|
||||
}
|
||||
applied = EntityRule.run(context, rules, message, null, null);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
|
|
|
@ -77,6 +77,8 @@ public class WorkerDailyRules extends Worker {
|
|||
List<Long> mids = db.message().getMessageIdsByFolder(folder.id);
|
||||
for (long mid : mids)
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityMessage message = db.message().getMessage(mid);
|
||||
if (message == null || message.ui_hide)
|
||||
continue;
|
||||
|
@ -101,14 +103,13 @@ public class WorkerDailyRules extends Worker {
|
|||
continue;
|
||||
}
|
||||
|
||||
for (EntityRule rule : rules)
|
||||
if (rule.matches(context, message, null, null)) {
|
||||
rule.execute(context, message);
|
||||
if (rule.stop)
|
||||
break;
|
||||
}
|
||||
EntityRule.run(context, rules, message, null, null);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
EntityLog.log(context, EntityLog.Type.Rules, folder,
|
||||
|
|
|
@ -165,6 +165,16 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etAge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStopRemark"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_rule_stop_remark"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbStop" />
|
||||
|
||||
<!-- condition -->
|
||||
|
||||
<TextView
|
||||
|
@ -177,7 +187,7 @@
|
|||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbStop" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvStopRemark" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorSender"
|
||||
|
|
|
@ -1866,6 +1866,7 @@
|
|||
<string name="title_rule_daily">Run daily (only)</string>
|
||||
<string name="title_rule_age">Messages older than (days)</string>
|
||||
<string name="title_rule_stop">Stop processing rules after executing this rule</string>
|
||||
<string name="title_rule_stop_remark">If the rule is part of a group, only the processing of the group will be stopped</string>
|
||||
<string name="title_rule_sender">Sender contains</string>
|
||||
<string name="title_rule_sender_known">Sender is a contact</string>
|
||||
<string name="title_rule_recipient">Recipient contains</string>
|
||||
|
|
Loading…
Reference in a new issue