Option to require DMARC for favicons

pull/215/head
M66B 6 months ago
parent ccbea18943
commit cbbe6373eb

@ -1678,7 +1678,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
// Contact info
ContactInfo[] info = ContactInfo.getCached(context,
message.account, message.folderType, selector, addresses);
message.account, message.folderType, selector, Boolean.TRUE.equals(message.dmarc), addresses);
if (info == null) {
if (taskContactInfo != null) {
taskContactInfo.cancel(context);
@ -1690,6 +1690,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
aargs.putLong("account", message.account);
aargs.putString("folderType", message.folderType);
aargs.putString("selector", selector);
aargs.putBoolean("dmarc", Boolean.TRUE.equals(message.dmarc));
aargs.putSerializable("addresses", addresses);
taskContactInfo = new SimpleTask<ContactInfo[]>() {
@ -1698,8 +1699,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
long account = args.getLong("account");
String folderType = args.getString("folderType");
String selector = args.getString("selector");
boolean dmarc = args.getBoolean("dmarc");
Address[] addresses = (Address[]) args.getSerializable("addresses");
return ContactInfo.get(context, account, folderType, selector, addresses);
return ContactInfo.get(context, account, folderType, selector, dmarc, addresses);
}
@Override
@ -7624,6 +7626,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
args.putLong("account", message.account);
args.putString("folderType", message.folderType);
args.putString("selector", message.bimi_selector);
args.putBoolean("dmarc", Boolean.TRUE.equals(message.dmarc));
args.putSerializable("addresses", message.from);
new SimpleTask<ContactInfo[]>() {
@ -7632,8 +7635,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
long account = args.getLong("account");
String folderType = args.getString("folderType");
String selector = args.getString("selector");
boolean dmarc = args.getBoolean("dmarc");
Address[] addresses = (Address[]) args.getSerializable("addresses");
return ContactInfo.get(context, account, folderType, selector, addresses);
return ContactInfo.get(context, account, folderType, selector, dmarc, addresses);
}
@Override

@ -221,15 +221,15 @@ public class ContactInfo {
}
@NonNull
static ContactInfo[] get(Context context, long account, String folderType, String selector, Address[] addresses) {
return get(context, account, folderType, selector, addresses, false);
static ContactInfo[] get(Context context, long account, String folderType, String selector, boolean dmarc, Address[] addresses) {
return get(context, account, folderType, selector, dmarc, addresses, false);
}
static ContactInfo[] getCached(Context context, long account, String folderType, String selector, Address[] addresses) {
return get(context, account, folderType, selector, addresses, true);
static ContactInfo[] getCached(Context context, long account, String folderType, String selector, boolean dmarc, Address[] addresses) {
return get(context, account, folderType, selector, dmarc, addresses, true);
}
private static ContactInfo[] get(Context context, long account, String folderType, String selector, Address[] addresses, boolean cacheOnly) {
private static ContactInfo[] get(Context context, long account, String folderType, String selector, boolean dmarc, Address[] addresses, boolean cacheOnly) {
if (addresses == null || addresses.length == 0) {
ContactInfo anonymous = getAnonymous(context);
return new ContactInfo[]{anonymous == null ? new ContactInfo() : anonymous};
@ -237,7 +237,7 @@ public class ContactInfo {
ContactInfo[] result = new ContactInfo[addresses.length];
for (int i = 0; i < addresses.length; i++) {
result[i] = _get(context, account, folderType, selector, (InternetAddress) addresses[i], cacheOnly);
result[i] = _get(context, account, folderType, selector, dmarc, (InternetAddress) addresses[i], cacheOnly);
if (result[i] == null) {
if (cacheOnly)
return null;
@ -259,7 +259,7 @@ public class ContactInfo {
private static ContactInfo _get(
Context context,
long account, String folderType,
String selector, InternetAddress address, boolean cacheOnly) {
String selector, boolean dmarc, InternetAddress address, boolean cacheOnly) {
String key = MessageHelper.formatAddresses(new Address[]{address});
synchronized (emailContactInfo) {
ContactInfo info = emailContactInfo.get(key);
@ -277,13 +277,14 @@ public class ContactInfo {
final String ekey = (TextUtils.isEmpty(info.email) ? null : getKey(info.email));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean favicons_dmarc = prefs.getBoolean("favicons_dmarc", false);
boolean avatars = prefs.getBoolean("avatars", true);
boolean prefer_contact = prefs.getBoolean("prefer_contact", false);
boolean distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
boolean bimi = (prefs.getBoolean("bimi", false) && !BuildConfig.PLAY_STORE_RELEASE);
boolean gravatars = (prefs.getBoolean("gravatars", false) && !BuildConfig.PLAY_STORE_RELEASE);
boolean libravatars = (prefs.getBoolean("libravatars", false) && !BuildConfig.PLAY_STORE_RELEASE);
boolean favicons = prefs.getBoolean("favicons", false);
boolean bimi = (prefs.getBoolean("bimi", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
boolean gravatars = (prefs.getBoolean("gravatars", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
boolean libravatars = (prefs.getBoolean("libravatars", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
boolean favicons = (prefs.getBoolean("favicons", false) && (!favicons_dmarc || dmarc));
boolean generated = prefs.getBoolean("generated_icons", true);
boolean identicons = prefs.getBoolean("identicons", false);
boolean circular = prefs.getBoolean("circular", true);

@ -127,6 +127,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swFaviconsPartial;
private SwitchCompat swFaviconsManifest;
private TextView tvFaviconsHint;
private SwitchCompat swFaviconsDmarc;
private SwitchCompat swGeneratedIcons;
private SwitchCompat swIdenticons;
private SwitchCompat swCircular;
@ -217,7 +218,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"hide_toolbar", "edge_to_edge", "nav_options", "nav_categories", "nav_last_sync", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "show_unexposed",
"threading", "threading_unread", "indentation", "seekbar", "actionbar", "actionbar_swap", "actionbar_color",
"highlight_unread", "highlight_color", "color_stripe", "color_stripe_wide",
"avatars", "bimi", "bimi_vmc", "gravatars", "libravatars", "favicons", "favicons_partial", "favicons_manifest", "generated_icons", "identicons",
"avatars", "bimi", "bimi_vmc", "gravatars", "libravatars", "favicons", "favicons_partial", "favicons_manifest", "favicons_dmarc", "generated_icons", "identicons",
"circular", "saturation", "brightness", "threshold",
"email_format", "prefer_contact", "only_contact", "distinguish_contacts", "show_recipients", "reverse_addresses",
"font_size_sender", "sender_ellipsize",
@ -306,6 +307,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swFaviconsPartial = view.findViewById(R.id.swFaviconsPartial);
swFaviconsManifest = view.findViewById(R.id.swFaviconsManifest);
tvFaviconsHint = view.findViewById(R.id.tvFaviconsHint);
swFaviconsDmarc = view.findViewById(R.id.swFaviconsDmarc);
swGeneratedIcons = view.findViewById(R.id.swGeneratedIcons);
swIdenticons = view.findViewById(R.id.swIdenticons);
swCircular = view.findViewById(R.id.swCircular);
@ -916,6 +918,14 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swFaviconsDmarc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("favicons_dmarc", checked).apply();
ContactInfo.clearCache(compoundButton.getContext());
}
});
swGeneratedIcons.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1615,6 +1625,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swFaviconsPartial.setEnabled(swFavicons.isChecked());
swFaviconsManifest.setChecked(prefs.getBoolean("favicons_manifest", false));
swFaviconsManifest.setEnabled(swFavicons.isChecked());
swFaviconsDmarc.setChecked(prefs.getBoolean("favicons_dmarc", false));
swGeneratedIcons.setChecked(prefs.getBoolean("generated_icons", true));
swIdenticons.setChecked(prefs.getBoolean("identicons", false));
swIdenticons.setEnabled(swGeneratedIcons.isChecked());

@ -717,7 +717,8 @@ class NotificationHelper {
latest = message.received;
ContactInfo[] info = ContactInfo.get(context,
message.account, message.folderType, message.bimi_selector,
message.account, message.folderType,
message.bimi_selector, Boolean.TRUE.equals(message.dmarc),
message.isForwarder() ? message.submitter : message.from);
Address[] modified = (message.from == null

@ -240,7 +240,8 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
if (avatars) {
ContactInfo[] info = ContactInfo.get(context,
message.account, null, message.bimi_selector,
message.account, null,
message.bimi_selector, Boolean.TRUE.equals(message.dmarc),
message.isForwarder() ? message.submitter : message.from);
views.setImageViewBitmap(R.id.avatar, info.length == 0 ? null : info[0].getPhotoBitmap());
}

@ -1141,6 +1141,17 @@
app:layout_constraintTop_toBottomOf="@id/swFaviconsPartial"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swFaviconsDmarc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_favicons_dmarc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swFaviconsManifest"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swGeneratedIcons"
android:layout_width="0dp"
@ -1150,7 +1161,7 @@
android:text="@string/title_advanced_generated_icons"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swFaviconsManifest"
app:layout_constraintTop_toBottomOf="@id/swFaviconsDmarc"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -618,6 +618,7 @@
<string name="title_advanced_favicons">Show favicons</string>
<string name="title_advanced_favicons_partial">Scan only the first %1$s of the web page</string>
<string name="title_advanced_favicons_manifest">Scan web app manifests</string>
<string name="title_advanced_favicons_dmarc">Require DMARC verification for external images</string>
<string name="title_advanced_generated_icons">Show generated icons</string>
<string name="title_advanced_identicons">Show identicons</string>
<string name="title_advanced_circular">Show round icons</string>

Loading…
Cancel
Save