From 22229d6b4312108144e1f132272dd9e9d848fdf7 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 13 Apr 2017 21:24:52 +0200 Subject: treat URL as file if URL is in oob or contains key --- .../de/pixart/messenger/entities/Conversation.java | 2 +- .../java/de/pixart/messenger/entities/Message.java | 41 +++++----------------- 2 files changed, 10 insertions(+), 33 deletions(-) (limited to 'src/main/java/de/pixart/messenger/entities') diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 4d9b96fde..a3811a751 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -181,7 +181,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl for (final Message message : this.messages) { if (message.getUuid().equals(uuid) && message.getEncryption() != Message.ENCRYPTION_PGP - && (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable() != Message.Decision.NEVER)) { + && (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable())) { return message; } } diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index be30ced7a..89bd9069d 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -501,8 +501,8 @@ public class Message extends AbstractEntity { this.getBody().length() + message.getBody().length() <= Config.MAX_DISPLAY_MESSAGE_CHARS && !GeoHelper.isGeoUri(message.getBody()) && !GeoHelper.isGeoUri(this.body) && - message.treatAsDownloadable() == Decision.NEVER && - this.treatAsDownloadable() == Decision.NEVER && + !message.treatAsDownloadable() && + !this.treatAsDownloadable() && !message.getBody().startsWith(ME_COMMAND) && !this.getBody().startsWith(ME_COMMAND) && !this.bodyIsHeart() && @@ -614,12 +614,6 @@ public class Message extends AbstractEntity { this.oob = isOob; } - public enum Decision { - MUST, - SHOULD, - NEVER, - } - private static String extractRelevantExtension(URL url) { String path = url.getPath(); return extractRelevantExtension(path); @@ -662,37 +656,20 @@ public class Message extends AbstractEntity { } } - public Decision treatAsDownloadable() { + public boolean treatAsDownloadable() { if (body.trim().contains(" ")) { - return Decision.NEVER; + return false; } try { - URL url = new URL(body); - String ref = url.getRef(); + final URL url = new URL(body); + final String ref = url.getRef(); final String protocol = url.getProtocol(); final boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}"); - if (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted) { - return Decision.MUST; - } - if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { - return Decision.NEVER; - } else if (oob || encrypted) { - return Decision.MUST; - } - final String extension = extractRelevantExtension(url); - if (extension == null - || encryption == Message.ENCRYPTION_OTR - || encryption == Message.ENCRYPTION_AXOLOTL) { - return Decision.NEVER; - } else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension) - || Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) { - return Decision.SHOULD; - } else { - return Decision.NEVER; - } + return (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted) + || ((protocol.equalsIgnoreCase("http") || protocol.equalsIgnoreCase("https")) && (oob || encrypted)); } catch (MalformedURLException e) { - return Decision.NEVER; + return false; } } -- cgit v1.2.3