diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 659183d2..ec91cacc 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -139,16 +139,22 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket generatePgpChat(Message message) { MessagePacket packet = preparePacket(message); - if (Config.supportUnencrypted()) { - packet.setBody(PGP_FALLBACK_MESSAGE); + if (message.hasFileOnRemoteHost()) { + final String url = message.getFileParams().url.toString(); + packet.setBody(url); + packet.addChild("x",Namespace.OOB).addChild("url").setContent(url); + } else { + if (Config.supportUnencrypted()) { + packet.setBody(PGP_FALLBACK_MESSAGE); + } + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody()); + } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { + packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody()); + } + packet.addChild("encryption", "urn:xmpp:eme:0") + .setAttribute("namespace", "jabber:x:encrypted"); } - if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { - packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody()); - } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { - packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody()); - } - packet.addChild("encryption","urn:xmpp:eme:0") - .setAttribute("namespace","jabber:x:encrypted"); return packet; } diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 970ace6f..281ff04d 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -100,7 +100,7 @@ public class HttpDownloadConnection implements Transferable { || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL) && this.file.getKey() == null) { this.message.setEncryption(Message.ENCRYPTION_NONE); - } + } checkFileSize(interactive); } catch (MalformedURLException e) { this.cancel(); diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index e68d7b09..a5301af3 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -197,27 +197,7 @@ public class HttpUploadConnection implements Transferable { mXmppConnectionService.getFileBackend().updateMediaScanner(file); message.setTransferable(null); message.setCounterpart(message.getConversation().getJid().toBareJid()); - if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { - mXmppConnectionService.getPgpEngine().encrypt(message, new UiCallback() { - @Override - public void success(Message message) { - mXmppConnectionService.resendMessage(message,delayed); - } - - @Override - public void error(int errorCode, Message object) { - Log.d(Config.LOGTAG,"pgp encryption failed"); - fail("pgp encryption failed"); - } - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - fail("pgp encryption failed"); - } - }); - } else { - mXmppConnectionService.resendMessage(message, delayed); - } + mXmppConnectionService.resendMessage(message, delayed); } else { Log.d(Config.LOGTAG,"http upload failed because response code was "+code); fail("http upload failed because response code was "+code); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 1724a858..13d93249 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -415,7 +415,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) { - Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); + final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; if (serverMsgId == null) { @@ -474,6 +474,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else if (body == null && oobUrl != null) { message = new Message(conversation, oobUrl, Message.ENCRYPTION_NONE, status); message.setOob(true); + if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) { + message.setEncryption(Message.ENCRYPTION_DECRYPTED); + } } else { message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); } @@ -483,7 +486,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece message.setServerMsgId(serverMsgId); message.setCarbon(isCarbon); message.setTime(timestamp); - message.setOob(body != null && body.equals(oobUrl)); + if (body != null && body.equals(oobUrl)) { + message.setOob(true); + if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) { + message.setEncryption(Message.ENCRYPTION_DECRYPTED); + } + } message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); if (conversationMultiMode) { final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); @@ -624,7 +632,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } } else if (!packet.hasChild("body")){ //no body - Conversation conversation = mXmppConnectionService.find(account, from.toBareJid()); + final Conversation conversation = mXmppConnectionService.find(account, from.toBareJid()); if (isTypeGroupChat) { if (packet.hasChild("subject")) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 3f0c1f63..f67726d5 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -185,7 +185,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie filesize = params.size / (1024 * 1024)+ " MiB"; } else if (params.size >= 1024) { filesize = params.size / 1024 + " KiB"; - } else { + } else if (params.size > 0){ filesize = params.size + " B"; } if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) { diff --git a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java index 5f5f576a..327951c1 100644 --- a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java @@ -243,4 +243,12 @@ public final class CryptoHelper { return url; } } + + public static boolean isPgpEncryptedUrl(String url) { + if (url == null) { + return false; + } + final String u = url.toLowerCase(); + return !u.contains(" ") && (u.startsWith("https://") || u.startsWith("http://")) && u.endsWith(".pgp"); + } }