From 722012609be89c6a8f688ebd4c1d948d3eb11ba8 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 12 Apr 2019 20:41:06 +0200 Subject: [PATCH] Refactoring --- app/src/main/java/eu/faircode/email/Core.java | 6 ++--- .../java/eu/faircode/email/EntityMessage.java | 25 ------------------- .../java/eu/faircode/email/MessageHelper.java | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index b09906cbd4..38c2886e66 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1174,9 +1174,9 @@ class Core { // Local address contains control or whitespace in string ``mailing list someone@example.org'' message.deliveredto = helper.getDeliveredTo(); message.thread = helper.getThreadId(context, account.id, uid); - message.dkim = EntityMessage.getAuthentication("dkim", authentication); - message.spf = EntityMessage.getAuthentication("spf", authentication); - message.dmarc = EntityMessage.getAuthentication("dmarc", authentication); + message.dkim = MessageHelper.getAuthentication("dkim", authentication); + message.spf = MessageHelper.getAuthentication("spf", authentication); + message.dmarc = MessageHelper.getAuthentication("dmarc", authentication); message.from = froms; message.to = tos; message.cc = ccs; diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 3b118d916e..546e47600c 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -185,31 +185,6 @@ public class EntityMessage implements Serializable { } } - static Boolean getAuthentication(String type, String header) { - if (header == null) - return null; - - // https://tools.ietf.org/html/rfc7601 - Boolean result = null; - String[] part = header.split(";"); - for (int i = 1; i < part.length; i++) { - String[] kv = part[i].split("="); - if (kv.length > 1) { - String key = kv[0].trim(); - String[] val = kv[1].split(" "); - if (val.length > 0 && type.equals(key)) { - if ("fail".equals(val[0])) - result = false; - else if ("pass".equals(val[0])) - if (result == null) - result = true; - } - } - } - - return result; - } - public boolean uiEquals(Object obj) { if (obj instanceof EntityMessage) { EntityMessage other = (EntityMessage) obj; diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index e3f29b4f14..db21fed2af 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -460,6 +460,31 @@ public class MessageHelper { return (header == null ? null : header.replaceAll("\\r?\\n", "")); } + static Boolean getAuthentication(String type, String header) { + if (header == null) + return null; + + // https://tools.ietf.org/html/rfc7601 + Boolean result = null; + String[] part = header.split(";"); + for (int i = 1; i < part.length; i++) { + String[] kv = part[i].split("="); + if (kv.length > 1) { + String key = kv[0].trim(); + String[] val = kv[1].trim().split(" "); + if (val.length > 0 && type.equals(key)) { + if ("fail".equals(val[0])) + result = false; + else if ("pass".equals(val[0])) + if (result == null) + result = true; + } + } + } + + return result; + } + Address getSender() throws MessagingException { String sender = imessage.getHeader("Sender", null); if (sender == null)