mirror of https://github.com/M66B/FairEmail.git
Allow rules for specific attachment mime types
This commit is contained in:
parent
3754cf966c
commit
6afefb61b7
|
@ -194,8 +194,23 @@ public class EntityRule {
|
|||
// Attachments
|
||||
if (jcondition.optBoolean("attachments")) {
|
||||
DB db = DB.getInstance(context);
|
||||
if (db.attachment().getAttachments(message.id).size() == 0)
|
||||
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
||||
if (attachments.size() == 0)
|
||||
return false;
|
||||
|
||||
if (jcondition.has("mimetype")) {
|
||||
String mimeType = jcondition.getString("mimetype");
|
||||
|
||||
boolean found = false;
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if (mimeType.equalsIgnoreCase(attachment.type)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Header
|
||||
|
|
|
@ -100,6 +100,7 @@ public class FragmentRule extends FragmentBase {
|
|||
private CheckBox cbSubject;
|
||||
|
||||
private CheckBox cbAttachments;
|
||||
private EditText etMimeType;
|
||||
|
||||
private EditText etHeader;
|
||||
private CheckBox cbHeader;
|
||||
|
@ -211,6 +212,7 @@ public class FragmentRule extends FragmentBase {
|
|||
cbSubject = view.findViewById(R.id.cbSubject);
|
||||
|
||||
cbAttachments = view.findViewById(R.id.cbAttachments);
|
||||
etMimeType = view.findViewById(R.id.etMimeType);
|
||||
|
||||
etHeader = view.findViewById(R.id.etHeader);
|
||||
cbHeader = view.findViewById(R.id.cbHeader);
|
||||
|
@ -291,6 +293,13 @@ public class FragmentRule extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
cbAttachments.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
||||
etMimeType.setEnabled(isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
adapterDay = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<String>());
|
||||
adapterDay.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
||||
spScheduleDayStart.setAdapter(adapterDay);
|
||||
|
@ -737,6 +746,8 @@ public class FragmentRule extends FragmentBase {
|
|||
cbSubject.setChecked(jsubject != null && jsubject.getBoolean("regex"));
|
||||
|
||||
cbAttachments.setChecked(jcondition.optBoolean("attachments"));
|
||||
etMimeType.setText(jcondition.optString("mimetype"));
|
||||
etMimeType.setEnabled(cbAttachments.isChecked());
|
||||
|
||||
etHeader.setText(jheader == null ? null : jheader.getString("value"));
|
||||
cbHeader.setChecked(jheader != null && jheader.getBoolean("regex"));
|
||||
|
@ -1037,6 +1048,7 @@ public class FragmentRule extends FragmentBase {
|
|||
}
|
||||
|
||||
jcondition.put("attachments", cbAttachments.isChecked());
|
||||
jcondition.put("mimetype", etMimeType.getText().toString().trim());
|
||||
|
||||
String header = etHeader.getText().toString();
|
||||
if (!TextUtils.isEmpty(header)) {
|
||||
|
|
|
@ -319,6 +319,28 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvMimeType"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_rule_mime_type"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbAttachments" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etMimeType"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/title_optional"
|
||||
android:inputType="textCapSentences|textAutoCorrect"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvMimeType" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvAndAttachments"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -329,7 +351,7 @@
|
|||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbAttachments" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/etMimeType" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorHeader"
|
||||
|
|
|
@ -1051,6 +1051,7 @@
|
|||
<string name="title_rule_recipient">Recipient contains</string>
|
||||
<string name="title_rule_subject">Subject contains</string>
|
||||
<string name="title_rule_attachments">Has attachments</string>
|
||||
<string name="title_rule_mime_type" translatable="false">Mime type</string>
|
||||
<string name="title_rule_header">Header contains</string>
|
||||
<string name="title_rule_time">Time between</string>
|
||||
<string name="title_rule_regex">Regex</string>
|
||||
|
|
Loading…
Reference in New Issue