From a056001ac67b4b65d7ac68c107ee16882f89acc1 Mon Sep 17 00:00:00 2001 From: Tobias Miosczka <6351397+TobiasMiosczka@users.noreply.github.com> Date: Sat, 19 May 2018 01:45:28 +0200 Subject: [PATCH] Version 0.6 Fixed bug where base64 encoded emails where ignored. --- pom.xml | 2 +- .../cinema/KDMManager/helper/EmailHelper.java | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 771add3..61166dc 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.tobiasmiosczka.cinema KDMManager - 0.5.0 + 0.6.0 diff --git a/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/helper/EmailHelper.java b/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/helper/EmailHelper.java index 0b79171..2e9e64b 100644 --- a/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/helper/EmailHelper.java +++ b/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/helper/EmailHelper.java @@ -53,16 +53,37 @@ private static KDM getKdmFromInputStream(InputStream inputStream, String fileNam ); } + private static String decode(String s) { + if (s == null) + return null; + if (s.matches("^=\\?.*\\?.*\\?.*\\?=$")) { + String cypher = s.replaceAll("^=\\?.*?\\?", "").replaceAll("\\?.*?\\?=$", ""); + //String charset = s.replaceAll("^=\\?", "").replaceAll("\\?.*?\\?.*?\\?=$", ""); + String text = s.replaceAll("^=\\?.*?\\?.*?\\?", "").replaceAll("\\?=$", ""); + switch (cypher) { + case "Q": + return text; + case "B": + return new String(Base64.getDecoder().decode(text)); + default: + return s; + } + } else { + return s; + } + } + private static Collection handleMessages(Message[] messages, IUpdate iUpdate) throws IOException, JDOMException, ParseException, MessagingException { Collection kdms = new HashSet<>(); for (int i = 0; i < messages.length; ++i) { Message message = messages[i]; iUpdate.onUpdateEmailLoading(i, messages.length); + if (message.getContentType().contains("multipart")) { Multipart multipart = (Multipart) message.getContent(); for (int j = 0; j < multipart.getCount(); ++j) { BodyPart bodyPart = multipart.getBodyPart(j); - String fileName = bodyPart.getFileName(); + String fileName = decode(bodyPart.getFileName()); if (fileName != null && (Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) || !StringHelper.isBlank(fileName))) { if (fileName.endsWith(".zip")) kdms.addAll(unzip(bodyPart.getInputStream()));