Experimental: block list support

pull/172/head
M66B 5 years ago
parent 4f663365b7
commit 4504d69aaa

@ -69,6 +69,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.DateFormat;
@ -2148,6 +2151,47 @@ class Core {
message.warning = Log.formatThrowable(ex, false);
}
boolean check_spam = prefs.getBoolean("check_spam", BuildConfig.DEBUG);
if (check_spam)
try {
String host = helper.getReceivedFromHost();
if (host != null) {
InetAddress addr = InetAddress.getByName(host);
Log.i("Received from " + host + "=" + addr);
StringBuilder lookup = new StringBuilder();
if (addr instanceof Inet4Address) {
List<String> a = Arrays.asList(addr.getHostAddress().split("\\."));
Collections.reverse(a);
lookup.append(TextUtils.join(".", a)).append('.');
} else if (addr instanceof Inet6Address) {
StringBuilder sb = new StringBuilder();
byte[] a = addr.getAddress();
for (int i = 0; i < 8; i++)
sb.append(String.format("%02x",
((a[i << 1] << 8) & 0xff00) | (a[(i << 1) + 1] & 0xff)));
sb.reverse();
for (char kar : sb.toString().toCharArray())
lookup.append(kar).append('.');
}
lookup.append("zen.spamhaus.org");
try {
InetAddress.getByName(lookup.toString());
if (message.warning == null)
message.warning = lookup.toString();
else
message.warning += ", " + lookup;
} catch (UnknownHostException ignore) {
}
}
} catch (UnknownHostException ex) {
} catch (Throwable ex) {
Log.w(folder.name, ex);
}
boolean check_reply = prefs.getBoolean("check_reply", false);
if (check_reply &&
message.from != null && message.from.length > 0 &&

@ -96,6 +96,8 @@ public class MessageHelper {
static final int DEFAULT_ATTACHMENT_DOWNLOAD_SIZE = 256 * 1024; // bytes
static final long ATTACHMENT_PROGRESS_UPDATE = 1500L; // milliseconds
// https://tools.ietf.org/html/rfc4021
static void setSystemProperties(Context context) {
System.setProperty("mail.mime.decodetext.strict", "false");
@ -835,6 +837,18 @@ public class MessageHelper {
return result;
}
String getReceivedFromHost() throws MessagingException {
String[] received = imessage.getHeader("Received");
if (received == null || received.length == 0)
return null;
String[] h = MimeUtility.unfold(received[received.length - 1]).split("\\s+");
if (h.length > 1 && h[0].equalsIgnoreCase("from"))
return h[1];
return null;
}
private Address[] getAddressHeader(String name) throws MessagingException {
String header = imessage.getHeader(name, ",");
if (header == null)

Loading…
Cancel
Save