Warn for blocking common domains

pull/206/head 1.1762
M66B 3 years ago
parent af54166a8a
commit 4599a373aa

@ -858,7 +858,7 @@ public class EntityRule {
return cal; return cal;
} }
static EntityRule blockSender(Context context, EntityMessage message, EntityFolder junk, boolean block_domain, List<String> whitelist) throws JSONException { static EntityRule blockSender(Context context, EntityMessage message, EntityFolder junk, boolean block_domain) throws JSONException {
if (message.from == null || message.from.length == 0) if (message.from == null || message.from.length == 0)
return null; return null;
@ -873,17 +873,8 @@ public class EntityRule {
if (block_domain) { if (block_domain) {
int at = sender.indexOf('@'); int at = sender.indexOf('@');
if (at > 0) { if (at > 0) {
boolean whitelisted = false;
String domain = UriHelper.getParentDomain(context, sender.substring(at + 1));
for (String d : whitelist)
if (domain.matches(d)) {
whitelisted = true;
break;
}
if (!whitelisted) {
regex = true; regex = true;
sender = ".*@.*" + domain + ".*"; sender = ".*@.*" + sender.substring(at + 1) + ".*";
}
} }
} }

@ -25,6 +25,8 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -48,6 +50,10 @@ import androidx.preference.PreferenceManager;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List; import java.util.List;
import java.util.Locale;
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
public class FragmentDialogJunk extends FragmentDialogBase { public class FragmentDialogJunk extends FragmentDialogBase {
@NonNull @NonNull
@ -264,6 +270,35 @@ public class FragmentDialogJunk extends FragmentDialogBase {
} }
}); });
try {
boolean common = false;
Address[] froms = InternetAddress.parseHeader(from, false);
String email = (froms.length == 0 ? null : ((InternetAddress) froms[0]).getAddress());
int at = (email == null ? -1 : email.indexOf('@'));
String domain = (at > 0 ? email.substring(at + 1).toLowerCase(Locale.ROOT) : null);
if (domain != null) {
List<String> domains = EmailProvider.getDomainNames(context);
for (String d : domains)
if (domain.matches(d)) {
common = true;
break;
}
}
if (common) {
int dp6 = Helper.dp2pixels(context, 6);
int colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
cbBlockDomain.setTextColor(colorWarning);
cbBlockDomain.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.twotone_warning_24, 0);
cbBlockDomain.setCompoundDrawablePadding(dp6);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
cbBlockDomain.setCompoundDrawableTintList(ColorStateList.valueOf(colorWarning));
}
} catch (Throwable ex) {
Log.e(ex);
}
// Initialize // Initialize
tvMessage.setText(inJunk tvMessage.setText(inJunk
? getString(R.string.title_folder_junk) ? getString(R.string.title_folder_junk)

@ -8003,7 +8003,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityContact.TYPE_JUNK, message.received); EntityContact.TYPE_JUNK, message.received);
if (block_domain) { if (block_domain) {
EntityRule rule = EntityRule.blockSender(context, message, junk, block_domain, whitelist); EntityRule rule = EntityRule.blockSender(context, message, junk, block_domain);
if (rule != null) { if (rule != null) {
if (message.folder.equals(junk.id)) { if (message.folder.equals(junk.id)) {
EntityFolder inbox = db.folder().getFolderByType(message.account, EntityFolder.INBOX); EntityFolder inbox = db.folder().getFolderByType(message.account, EntityFolder.INBOX);

@ -252,7 +252,6 @@ public class ServiceUI extends IntentService {
private void onJunk(long id) throws JSONException { private void onJunk(long id) throws JSONException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean block_sender = prefs.getBoolean("notify_block_sender", false); boolean block_sender = prefs.getBoolean("notify_block_sender", false);
List<String> whitelist = EmailProvider.getDomainNames(this);
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
try { try {
@ -269,7 +268,7 @@ public class ServiceUI extends IntentService {
EntityOperation.queue(this, message, EntityOperation.MOVE, junk.id); EntityOperation.queue(this, message, EntityOperation.MOVE, junk.id);
if (block_sender) { if (block_sender) {
EntityRule rule = EntityRule.blockSender(this, message, junk, false, whitelist); EntityRule rule = EntityRule.blockSender(this, message, junk, false);
if (rule != null) if (rule != null)
rule.id = db.rule().insertRule(rule); rule.id = db.rule().insertRule(rule);
} }

Loading…
Cancel
Save