aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
index d9fc9584..07f308fe 100644
--- a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
@@ -18,6 +18,7 @@ import javax.net.ssl.SSLHandshakeException;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.entities.FileParams;
import de.thedevstack.conversationsplus.enums.FileStatus;
import de.thedevstack.conversationsplus.exceptions.RemoteFileNotFoundException;
import de.thedevstack.conversationsplus.utils.MessageUtil;
@@ -75,8 +76,22 @@ public class HttpDownloadConnection implements Transferable {
this.message = message;
this.message.setTransferable(this);
try {
- mUrl = new URL(message.getFileParams().getUrl());
- final String sUrlFilename = mUrl.getPath().substring(mUrl.getPath().lastIndexOf('/')).toLowerCase();
+ String url = (null != message && null != message.getFileParams()) ? message.getFileParams().getUrl() : null;
+ if (null == url) {
+ /*
+ * If this code is reached and the URL is null something went wrong.
+ * Try again to extract the file parameters from the message.
+ */
+ MessageUtil.extractFileParamsFromBody(message);
+ url = (null != message.getFileParams()) ? message.getFileParams().getUrl() : null;
+ if (null == url) {
+ message.setTreatAsDownloadable(Message.Decision.NEVER); // TODO find sth better
+ this.cancel();
+ return;
+ }
+ }
+ mUrl = new URL(url);
+ final String sUrlFilename = mUrl.getPath().substring(mUrl.getPath().lastIndexOf('/') + 1).toLowerCase();
final String lastPart = FileUtils.getLastExtension(sUrlFilename);
if (!lastPart.isEmpty() && ("pgp".equals(lastPart) || "gpg".equals(lastPart))) {
@@ -85,18 +100,25 @@ public class HttpDownloadConnection implements Transferable {
&& message.getEncryption() != Message.ENCRYPTION_AXOLOTL) {
this.message.setEncryption(Message.ENCRYPTION_NONE);
}
+
String extension;
+ String originalFilename;
if (!lastPart.isEmpty() && VALID_CRYPTO_EXTENSIONS.contains(lastPart)) {
extension = FileUtils.getSecondToLastExtension(sUrlFilename);
+ originalFilename = sUrlFilename.replace("." + lastPart, "");
} else {
extension = lastPart;
+ originalFilename = sUrlFilename;
}
message.setRelativeFilePath(message.getUuid() + "." + extension);
this.file = FileBackend.getFile(message, false);
- String reference = mUrl.getRef();
- if (reference != null && reference.length() == 96) {
- this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
- }
+
+ FileParams fileParams = message.getFileParams();
+ if (null == fileParams) {
+ fileParams = new FileParams();
+ message.setFileParams(fileParams);
+ }
+ fileParams.setOriginalFilename(originalFilename);
if ((this.message.getEncryption() == Message.ENCRYPTION_OTR
|| this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL)