mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-09 18:43:23 +02:00
Added checking block lists
This commit is contained in:
@@ -108,7 +108,7 @@ public class ActivityDSN extends ActivityBase {
|
||||
bos.write(buffer, 0, length);
|
||||
|
||||
String headers = MessageHelper.decodeMime(bos.toString(StandardCharsets.UTF_8.name()));
|
||||
result.headers = HtmlHelper.highlightHeaders(context, headers);
|
||||
result.headers = HtmlHelper.highlightHeaders(context, headers, false);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -65,6 +65,7 @@ import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.method.ArrowKeyMovementMethod;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.BackgroundColorSpan;
|
||||
import android.text.style.DynamicDrawableSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
@@ -612,6 +613,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
tvKeywordsEx = vsBody.findViewById(R.id.tvKeywordsEx);
|
||||
|
||||
tvHeaders = vsBody.findViewById(R.id.tvHeaders);
|
||||
tvHeaders.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
ibCopyHeaders = vsBody.findViewById(R.id.ibCopyHeaders);
|
||||
ibCloseHeaders = vsBody.findViewById(R.id.ibCloseHeaders);
|
||||
pbHeaders = vsBody.findViewById(R.id.pbHeaders);
|
||||
@@ -2007,7 +2009,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
}
|
||||
|
||||
if (show_headers && message.headers != null) {
|
||||
tvHeaders.setText(HtmlHelper.highlightHeaders(context, message.headers));
|
||||
tvHeaders.setText(HtmlHelper.highlightHeaders(context,
|
||||
message.headers, message.blocklist != null && message.blocklist));
|
||||
ibCopyHeaders.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
tvHeaders.setText(null);
|
||||
|
||||
@@ -21,6 +21,7 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
@@ -131,16 +132,8 @@ public class DnsBlockList {
|
||||
if (received == null || received.length == 0)
|
||||
return null;
|
||||
|
||||
String h = MimeUtility.unfold(received[received.length - 1]);
|
||||
String[] words = h.split("\\s+");
|
||||
for (int i = 0; i < words.length - 1; i++)
|
||||
if ("from".equalsIgnoreCase(words[i])) {
|
||||
String host = words[i + 1].toLowerCase(Locale.ROOT);
|
||||
if (!TextUtils.isEmpty(host))
|
||||
return isJunk(context, host, BLOCK_LISTS);
|
||||
}
|
||||
|
||||
return null;
|
||||
String host = getFromHost(MimeUtility.unfold(received[received.length - 1]));
|
||||
return (host == null ? null : isJunk(context, host, BLOCK_LISTS));
|
||||
}
|
||||
|
||||
private static boolean isJunk(Context context, String host, List<BlockList> blocklists) {
|
||||
@@ -252,6 +245,34 @@ public class DnsBlockList {
|
||||
return blocked;
|
||||
}
|
||||
|
||||
private static String getFromHost(String received) {
|
||||
String[] words = received.split("\\s+");
|
||||
for (int i = 0; i < words.length - 1; i++)
|
||||
if ("from".equalsIgnoreCase(words[i])) {
|
||||
String host = words[i + 1].toLowerCase(Locale.ROOT);
|
||||
if (!TextUtils.isEmpty(host))
|
||||
return host;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static void show(Context context, String received) {
|
||||
String host = DnsBlockList.getFromHost(MimeUtility.unfold(received));
|
||||
if (host == null)
|
||||
return;
|
||||
|
||||
if (host.startsWith("[") && host.endsWith("]"))
|
||||
host = host.substring(1, host.length() - 1);
|
||||
|
||||
Uri uri = Uri.parse(BuildConfig.MXTOOLBOX_URI)
|
||||
.buildUpon()
|
||||
.appendPath("/SuperTool.aspx")
|
||||
.appendQueryParameter("action", "blacklist:" + host)
|
||||
.appendQueryParameter("run", "toolpage")
|
||||
.build();
|
||||
Helper.view(context, uri, true);
|
||||
}
|
||||
|
||||
private static class CacheEntry {
|
||||
private final long time;
|
||||
private final boolean blocked;
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.text.TextDirectionHeuristics;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.AlignmentSpan;
|
||||
import android.text.style.BulletSpan;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.text.style.QuoteSpan;
|
||||
@@ -50,6 +51,7 @@ import android.text.style.URLSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.util.Base64;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -1967,7 +1969,7 @@ public class HtmlHelper {
|
||||
return ssb.toString();
|
||||
}
|
||||
|
||||
static Spanned highlightHeaders(Context context, String headers) {
|
||||
static Spanned highlightHeaders(Context context, String headers, boolean blocklist) {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(headers);
|
||||
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
|
||||
|
||||
@@ -2007,6 +2009,31 @@ public class HtmlHelper {
|
||||
if (date != null)
|
||||
ssb.append(' ').append(DTF.format(date));
|
||||
ssb.setSpan(new StyleSpan(Typeface.BOLD), s, ssb.length(), 0);
|
||||
|
||||
if (blocklist && i == received.length - 1) {
|
||||
Drawable d = context.getDrawable(R.drawable.twotone_flag_24);
|
||||
|
||||
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size);
|
||||
d.setBounds(0, 0, iconSize, iconSize);
|
||||
|
||||
int colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
|
||||
d.setTint(colorWarning);
|
||||
|
||||
ssb.append(" \uFFFC"); // Object replacement character
|
||||
ssb.setSpan(new ImageSpan(d), ssb.length() - 1, ssb.length(), 0);
|
||||
|
||||
if (!TextUtils.isEmpty(BuildConfig.MXTOOLBOX_URI)) {
|
||||
final String header = received[i];
|
||||
ClickableSpan click = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
DnsBlockList.show(widget.getContext(), header);
|
||||
}
|
||||
};
|
||||
ssb.setSpan(click, ssb.length() - 1, ssb.length(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
ssb.append('\n');
|
||||
|
||||
int j = 0;
|
||||
|
||||
Reference in New Issue
Block a user