Added warning for dangerous files

pull/209/head
M66B 2 years ago
parent 9dee5e793b
commit 35e495cec1

@ -78,6 +78,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private boolean debug;
private int dp12;
private int dp36;
private int textColorTertiary;
private int colorWarning;
private List<EntityAttachment> items = new ArrayList<>();
@ -167,7 +169,10 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
? View.VISIBLE : View.INVISIBLE);
}
boolean dangerous = Helper.DANGEROUS_EXTENSIONS.contains(Helper.getExtension(attachment.name));
tvName.setText(attachment.name);
tvName.setTextColor(dangerous ? colorWarning : textColorTertiary);
tvName.setTypeface(null, dangerous ? Typeface.BOLD : Typeface.NORMAL);
if (attachment.size != null)
tvSize.setText(Helper.humanReadableByteCount(attachment.size));
@ -422,6 +427,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
this.debug = prefs.getBoolean("debug", false);
this.dp12 = Helper.dp2pixels(context, 12);
this.dp36 = Helper.dp2pixels(context, 36);
this.textColorTertiary = Helper.resolveColor(context, android.R.attr.textColorTertiary);
this.colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
setHasStableIds(true);

@ -6368,11 +6368,18 @@ public class FragmentCompose extends FragmentBase {
args.putBoolean("styled", styled);
int attached = 0;
for (EntityAttachment attachment : attachments)
List<String> dangerous = new ArrayList<>();
for (EntityAttachment attachment : attachments) {
if (!attachment.available)
throw new IllegalArgumentException(context.getString(R.string.title_attachments_missing));
else if (attachment.isAttachment())
attached++;
String ext = Helper.getExtension(attachment.name);
if (Helper.DANGEROUS_EXTENSIONS.contains(ext))
dangerous.add(attachment.name);
}
if (dangerous.size() > 0)
args.putString("remind_extension", String.join(", ", dangerous));
// Check for missing attachments
if (attached == 0) {
@ -6611,6 +6618,7 @@ public class FragmentCompose extends FragmentBase {
boolean remind_subject = args.getBoolean("remind_subject", false);
boolean remind_text = args.getBoolean("remind_text", false);
boolean remind_attachment = args.getBoolean("remind_attachment", false);
String remind_extension = args.getString("remind_extension");
boolean styled = args.getBoolean("styled", false);
int recipients = (draft.to == null ? 0 : draft.to.length) +
@ -6623,7 +6631,8 @@ public class FragmentCompose extends FragmentBase {
recipients > RECIPIENTS_WARNING ||
(styled && draft.isPlainOnly()) ||
(send_reminders &&
(remind_extra || remind_subject || remind_text || remind_attachment))) {
(remind_extra || remind_subject || remind_text ||
remind_attachment || remind_extension != null))) {
setBusy(false);
Helper.hideKeyboard(view);
@ -7504,6 +7513,7 @@ public class FragmentCompose extends FragmentBase {
final boolean remind_subject = args.getBoolean("remind_subject", false);
final boolean remind_text = args.getBoolean("remind_text", false);
final boolean remind_attachment = args.getBoolean("remind_attachment", false);
final String remind_extension = args.getString("remind_extension");
final boolean styled = args.getBoolean("styled", false);
final long size = args.getLong("size", -1);
final long max_size = args.getLong("max_size", -1);
@ -7535,6 +7545,7 @@ public class FragmentCompose extends FragmentBase {
final TextView tvRemindSubject = dview.findViewById(R.id.tvRemindSubject);
final TextView tvRemindText = dview.findViewById(R.id.tvRemindText);
final TextView tvRemindAttachment = dview.findViewById(R.id.tvRemindAttachment);
final TextView tvRemindExtension = dview.findViewById(R.id.tvRemindExtension);
final SwitchCompat swSendReminders = dview.findViewById(R.id.swSendReminders);
final TextView tvSendRemindersHint = dview.findViewById(R.id.tvSendRemindersHint);
final TextView tvTo = dview.findViewById(R.id.tvTo);
@ -7590,6 +7601,9 @@ public class FragmentCompose extends FragmentBase {
tvRemindText.setVisibility(send_reminders && remind_text ? View.VISIBLE : View.GONE);
tvRemindAttachment.setVisibility(send_reminders && remind_attachment ? View.VISIBLE : View.GONE);
tvRemindExtension.setText(getString(R.string.title_attachment_warning, remind_extension));
tvRemindExtension.setVisibility(send_reminders && remind_extension != null ? View.VISIBLE : View.GONE);
tvTo.setText(null);
tvVia.setText(null);
tvPlainHint.setVisibility(View.GONE);
@ -7608,7 +7622,8 @@ public class FragmentCompose extends FragmentBase {
Helper.setViewsEnabled(dview, false);
boolean reminder = (remind_extra || remind_subject || remind_text || remind_attachment);
boolean reminder = (remind_extra || remind_subject || remind_text ||
remind_attachment || remind_extension != null);
swSendReminders.setChecked(send_reminders);
swSendReminders.setVisibility(send_reminders && reminder ? View.VISIBLE : View.GONE);
tvSendRemindersHint.setVisibility(View.GONE);
@ -7620,6 +7635,7 @@ public class FragmentCompose extends FragmentBase {
tvRemindSubject.setVisibility(checked && remind_subject ? View.VISIBLE : View.GONE);
tvRemindText.setVisibility(checked && remind_text ? View.VISIBLE : View.GONE);
tvRemindAttachment.setVisibility(checked && remind_attachment ? View.VISIBLE : View.GONE);
tvRemindExtension.setVisibility(checked && remind_extension != null ? View.VISIBLE : View.GONE);
tvSendRemindersHint.setVisibility(checked ? View.GONE : View.VISIBLE);
}
});

@ -145,6 +145,7 @@ import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@ -217,6 +218,25 @@ public class Helper {
")+"
);
// https://support.google.com/mail/answer/6590#zippy=%2Cmessages-that-have-attachments
static final List<String> DANGEROUS_EXTENSIONS = Collections.unmodifiableList(Arrays.asList(
"ade", "adp", "apk", "appx", "appxbundle",
"bat",
"cab", "chm", "cmd", "com", "cpl",
"dll", "dmg",
"ex", "ex_", "exe",
"hta",
"ins", "isp", "iso",
"jar", "js", "jse",
"lib", "lnk",
"mde", "msc", "msi", "msix", "msixbundle", "msp", "mst",
"nsh",
"pif", "ps1",
"scr", "sct", "shb", "sys",
"vb", "vbe", "vbs", "vxd",
"wsc", "wsf", "wsh"
));
private static final ExecutorService executor = getBackgroundExecutor(1, "helper");
static ExecutorService getBackgroundExecutor(int threads, final String name) {

@ -29,11 +29,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_setup_quick_no_sent"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage" />
@ -56,11 +56,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="Invalid address"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnFixSent" />
@ -71,11 +71,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_dsn_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAddressError" />
@ -86,11 +86,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_size_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindDsn" />
@ -101,11 +101,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_pgp_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindSize" />
@ -116,11 +116,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_smime_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindPgp" />
@ -131,11 +131,11 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_to_missing"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindSmime" />
@ -146,10 +146,10 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_extra_missing"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindTo" />
@ -160,10 +160,10 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_noreply_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindExtra" />
@ -174,10 +174,10 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_external_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindNoReply" />
@ -188,10 +188,10 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_subject_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindExternal" />
@ -202,10 +202,10 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_text_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindSubject" />
@ -216,13 +216,27 @@
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_attachment_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindText" />
<TextView
android:id="@+id/tvRemindExtension"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
android:text="@string/title_attachment_warning"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindAttachment" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSendReminders"
android:layout_width="0dp"
@ -232,7 +246,7 @@
android:text="@string/title_advanced_send_reminders"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemindAttachment"
app:layout_constraintTop_toBottomOf="@id/tvRemindExtension"
app:switchPadding="12dp" />
<TextView
@ -306,10 +320,10 @@
android:layout_marginTop="6dp"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_plain_reminder"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPlainOnly" />

@ -1517,6 +1517,7 @@
<string name="title_text_reminder">Message is empty</string>
<string name="title_attachment_keywords">attached,attachment,attachments,included</string>
<string name="title_attachment_reminder">Did you intend to add an attachment?</string>
<string name="title_attachment_warning">Potentially dangerous: %1$s</string>
<string name="title_plain_reminder">All formatting will be lost</string>
<string name="title_dsn_reminder">Hard bounces damage the email reputation of the original sender!</string>
<string name="title_size_reminder">Message (%1$s) larger than server limit (%2$s)</string>

Loading…
Cancel
Save