diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-08-31 15:34:17 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-08-31 15:34:17 +0200 |
commit | 240addee71f05e091f462a48dc9a590b070ccb61 (patch) | |
tree | 3f38c0ffd9c6b3fffcbdc6fa9a3725419f855ae9 /src/main/java/de/pixart/messenger/http | |
parent | ca21a38cb691aff03fb6a376cbd22e91f3c02ce1 (diff) |
refactored filename and extension parsing
Diffstat (limited to 'src/main/java/de/pixart/messenger/http')
-rw-r--r-- | src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java index 969ea1611..39249c655 100644 --- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java @@ -80,25 +80,23 @@ public class HttpDownloadConnection implements Transferable { } else { mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody().split("\n")[0])); } - 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 AbstractConnectionManager.Extension extension = AbstractConnectionManager.Extension.of(mUrl.getPath()); + if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) { 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; + final String ext; + if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) { + ext = extension.secondary; } else { - extension = lastPart; + ext = extension.main; } if (message.getStatus() == Message.STATUS_RECEIVED){ - message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : "")); + message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (ext != null ? ("." + ext) : "")); } else { - message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : "")); + message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (ext != null ? ("." + ext) : "")); } this.file = mXmppConnectionService.getFileBackend().getFile(message, false); final String reference = mUrl.getRef(); |