Added option to skip quoted text for rule condition text contains

This commit is contained in:
M66B 2022-01-09 11:09:39 +01:00
parent c1f97ca0f8
commit bfc632c4b9
4 changed files with 21 additions and 2 deletions

View File

@ -338,6 +338,7 @@ public class EntityRule {
if (jbody != null) {
String value = jbody.getString("value");
boolean regex = jbody.getBoolean("regex");
boolean skip_quotes = jbody.optBoolean("skip_quotes");
if (!regex)
value = value.replaceAll("\\s+", " ");
@ -355,7 +356,8 @@ public class EntityRule {
throw new IllegalArgumentException(context.getString(R.string.title_rule_no_body));
Document d = JsoupEx.parse(html);
//d.select("blockquote").remove();
if (skip_quotes)
d.select("blockquote").remove();
String text = d.body().text();
if (!matches(context, message, value, text, regex))
return false;

View File

@ -108,6 +108,7 @@ public class FragmentRule extends FragmentBase {
private EditText etBody;
private CheckBox cbBody;
private CheckBox cbSkipQuotes;
private TextView tvDateAfter;
private TextView tvDateBefore;
@ -257,6 +258,7 @@ public class FragmentRule extends FragmentBase {
etBody = view.findViewById(R.id.etBody);
cbBody = view.findViewById(R.id.cbBody);
cbSkipQuotes = view.findViewById(R.id.cbSkipQuotes);
tvDateAfter = view.findViewById(R.id.tvDateAfter);
tvDateBefore = view.findViewById(R.id.tvDateBefore);
@ -967,6 +969,7 @@ public class FragmentRule extends FragmentBase {
etBody.setText(jbody == null ? null : jbody.getString("value"));
cbBody.setChecked(jbody != null && jbody.getBoolean("regex"));
cbSkipQuotes.setChecked(jbody != null && jbody.optBoolean("skip_quotes"));
long after = (jdate != null && jdate.has("after") ? jdate.getLong("after") : 0);
long before = (jdate != null && jdate.has("before") ? jdate.getLong("before") : 0);
@ -1303,6 +1306,7 @@ public class FragmentRule extends FragmentBase {
JSONObject jbody = new JSONObject();
jbody.put("value", body);
jbody.put("regex", cbBody.isChecked());
jbody.put("skip_quotes", cbSkipQuotes.isChecked());
jcondition.put("body", jbody);
}

View File

@ -458,6 +458,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbBody" />
<CheckBox
android:id="@+id/cbSkipQuotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_rule_skip_quotes"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etBody" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvBodyRemark"
android:layout_width="0dp"
@ -466,7 +474,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etBody" />
app:layout_constraintTop_toBottomOf="@id/cbSkipQuotes" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvAndBody"
@ -1002,10 +1010,14 @@
android:layout_height="0dp"
app:constraint_referenced_ids="
tvTitle,tvFolder,tvName,etName,tvOrder,etOrder,cbEnabled,cbStop,
tvCondition,
vSeparatorSender,tvSender,cbSender,etSender,ibSender,cbKnownSender,tvAndSender,
vSeparatorRecipient,tvRecipient,cbRecipient,etRecipient,ibRecipient,tvAndRecipient,
vSeparatorSubject,tvSubject,cbSubject,etSubject,tvAndSubject,
vSeparatorAttachments,cbAttachments,tvMimeType,etMimeType,tvAndAttachments,
vSeparatorHeader,tvHeader,cbHeader,etHeader,tvAndHeader,
vSeparatorBody,tvBody,cbBody,etBody,tvBodyRemark,cbSkipQuotes,tvAndBody,
vSeparatorDate,tvDate,tvDateAfter,btnDateAfter,tvDateBefore,btnDateBefore,tvAndDate,
vSeparatorSchedule,tvSchedule,spScheduleDayStart,spScheduleDayEnd,tvScheduleHourStart,tvScheduleHourEnd,
vSeparatorAction,tvAction,spAction,tvActionRemark,
vSeparatorParameters" />

View File

@ -1501,6 +1501,7 @@
<string name="title_rule_mime_type" translatable="false">Mime type</string>
<string name="title_rule_header">Header contains</string>
<string name="title_rule_body">Text contains</string>
<string name="title_rule_skip_quotes">Skip quoted text</string>
<string name="title_rule_body_remark">Using this condition will always download the message text, which may slow down the synchronization of the message list</string>
<string name="title_rule_time_abs">Absolute time (received) between</string>
<string name="title_rule_time_after">Received after</string>