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()));