From 5d3b2e6904894fa5949918bf787e5f0a5f37285d Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 23 Dec 2020 08:25:34 +0100 Subject: [PATCH] Refactoring --- app/src/main/java/eu/faircode/email/Core.java | 30 +++++-------------- .../java/eu/faircode/email/EntityMessage.java | 28 +++++++++++++++++ 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index fb81a97e87..9810b98806 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -2914,29 +2914,13 @@ class Core { } boolean check_reply = prefs.getBoolean("check_reply", false); - if (check_reply && - message.from != null && message.from.length > 0 && - message.reply != null && message.reply.length > 0) { - for (Address reply : message.reply) { - String r = ((InternetAddress) reply).getAddress(); - int rat = (r == null ? -1 : r.indexOf('@')); - if (rat > 0) { - String rdomain = DnsHelper.getParentDomain(r.substring(rat + 1)); - for (Address from : message.from) { - String f = ((InternetAddress) from).getAddress(); - int fat = (f == null ? -1 : f.indexOf('@')); - if (fat > 0) { - String fdomain = DnsHelper.getParentDomain(f.substring(fat + 1)); - if (!rdomain.equalsIgnoreCase(fdomain)) { - if (message.warning == null) - message.warning = context.getString(R.string.title_reply_domain, fdomain, rdomain); - else - message.warning += ", " + context.getString(R.string.title_reply_domain, fdomain, rdomain); - } - } - } - } - } + if (check_reply) { + String warning = message.getReplyCheck(context); + if (warning != null) + if (message.warning == null) + message.warning = warning; + else + message.warning += ", " + warning; } try { diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 51b1b8d2a0..7597c777a6 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -272,6 +272,34 @@ public class EntityMessage implements Serializable { return false; } + String getReplyCheck(Context context) { + if (from == null || from.length == 0) + return null; + if (reply == null || reply.length == 0) + return null; + + for (Address _reply : reply) { + String r = ((InternetAddress) _reply).getAddress(); + int rat = (r == null ? -1 : r.indexOf('@')); + if (rat < 0) + continue; + String rdomain = DnsHelper.getParentDomain(r.substring(rat + 1)); + + for (Address _from : from) { + String f = ((InternetAddress) _from).getAddress(); + int fat = (f == null ? -1 : f.indexOf('@')); + if (fat < 0) + continue; + String fdomain = DnsHelper.getParentDomain(f.substring(fat + 1)); + + if (!rdomain.equalsIgnoreCase(fdomain)) + return context.getString(R.string.title_reply_domain, fdomain, rdomain); + } + } + + return null; + } + Element getReplyHeader(Context context, Document document, boolean separate, boolean extended) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean language_detection = prefs.getBoolean("language_detection", false);