Detailed changes
@@ -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.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());
+ 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");
}
- packet.addChild("encryption","urn:xmpp:eme:0")
- .setAttribute("namespace","jabber:x:encrypted");
return packet;
}
@@ -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();
@@ -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<Message>() {
- @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);
@@ -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) {
@@ -185,7 +185,7 @@ public class MessageAdapter extends ArrayAdapter<Message> 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) {
@@ -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");
+ }
}