diff options
author | lookshe <github@lookshe.org> | 2016-03-12 02:28:22 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-03-12 02:28:22 +0100 |
commit | bf49abe865ca746fad452a759f3792ca322e1fce (patch) | |
tree | 89c57470ffb1bd4cf12364ccab8814156e0fa3f8 /src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | |
parent | 3041cc74cefb4a25f4d1af7109fcb141ec3293d8 (diff) |
Added method to get body from message if hasMeCommand and harmonized extraction of fileextension (FS#38)
Diffstat (limited to 'src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index cdc5d2e7..c8076811 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -82,22 +82,27 @@ public class HttpDownloadConnection implements Transferable { } else { mUrl = new URL(message.getBody()); } - String[] parts = mUrl.getPath().toLowerCase().split("\\."); - String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null; - String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null; - if ("pgp".equals(lastPart) || "gpg".equals(lastPart)) { + final String sUrlFilename = mUrl.getPath().substring(mUrl.getPath().lastIndexOf('/')).toLowerCase(); + final int lastDotPosition = sUrlFilename.lastIndexOf('.'); + final int secondToLastDotPosition = sUrlFilename.lastIndexOf('.', lastDotPosition - 1); + final String lastPart = lastDotPosition != -1 ? + sUrlFilename.substring(lastDotPosition + 1) : ""; + final String secondToLastPart = secondToLastDotPosition != -1 ? + sUrlFilename.substring(secondToLastDotPosition + 1, lastDotPosition - 1) : ""; + + if (!lastPart.isEmpty() && ("pgp".equals(lastPart) || "gpg".equals(lastPart))) { this.message.setEncryption(Message.ENCRYPTION_PGP); } else if (message.getEncryption() != Message.ENCRYPTION_OTR && message.getEncryption() != Message.ENCRYPTION_AXOLOTL) { this.message.setEncryption(Message.ENCRYPTION_NONE); } String extension; - if (VALID_CRYPTO_EXTENSIONS.contains(lastPart)) { - extension = secondToLast; + if (!lastPart.isEmpty() && VALID_CRYPTO_EXTENSIONS.contains(lastPart)) { + extension = secondToLastPart; } else { extension = lastPart; } - message.setRelativeFilePath(message.getUuid()+"."+extension); + message.setRelativeFilePath(message.getUuid() + "." + extension); this.file = FileBackend.getFile(message, false); String reference = mUrl.getRef(); if (reference != null && reference.length() == 96) { |