diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils/MessageUtils.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/MessageUtils.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/MessageUtils.java b/src/main/java/de/pixart/messenger/utils/MessageUtils.java index 1cf692f4d..8a3cdb707 100644 --- a/src/main/java/de/pixart/messenger/utils/MessageUtils.java +++ b/src/main/java/de/pixart/messenger/utils/MessageUtils.java @@ -29,7 +29,11 @@ package de.pixart.messenger.utils; +import java.net.MalformedURLException; +import java.net.URL; + import de.pixart.messenger.entities.Message; +import de.pixart.messenger.http.AesGcmURLStreamHandler; public class MessageUtils { public static String prepareQuote(Message message) { @@ -51,4 +55,28 @@ public class MessageUtils { } return builder.toString(); } + + public static boolean treatAsDownloadable(final String body, final boolean oob) { + try { + final String[] lines = body.split("\n"); + if (lines.length == 0) { + return false; + } + for (String line : lines) { + if (line.contains("\\s+")) { + return false; + } + } + final URL url = new URL(lines[0]); + final String ref = url.getRef(); + final String protocol = url.getProtocol(); + final boolean encrypted = ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches(); + final boolean followedByDataUri = lines.length == 2 && lines[1].startsWith("data:"); + final boolean validAesGcm = AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted && (lines.length == 1 || followedByDataUri); + final boolean validOob = ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted) && lines.length == 1; + return validAesGcm || validOob; + } catch (MalformedURLException e) { + return false; + } + } }
\ No newline at end of file |