aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java26
-rw-r--r--src/main/java/de/pixart/messenger/services/MessageSearchTask.java20
-rw-r--r--src/main/java/de/pixart/messenger/utils/MessageUtils.java28
3 files changed, 46 insertions, 28 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index cfe3c7fb8..0d6d4c18e 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -16,10 +16,10 @@ import java.util.Set;
import de.pixart.messenger.Config;
import de.pixart.messenger.crypto.axolotl.FingerprintStatus;
-import de.pixart.messenger.http.AesGcmURLStreamHandler;
import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.Emoticons;
import de.pixart.messenger.utils.GeoHelper;
+import de.pixart.messenger.utils.MessageUtils;
import de.pixart.messenger.utils.MimeUtils;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.utils.XmppUri;
@@ -715,29 +715,7 @@ public class Message extends AbstractEntity {
public synchronized boolean treatAsDownloadable() {
if (treatAsDownloadable == null) {
- try {
- final String[] lines = body.split("\n");
- if (lines.length == 0) {
- treatAsDownloadable = false;
- return false;
- }
- for (String line : lines) {
- if (line.contains("\\s+")) {
- treatAsDownloadable = false;
- return false;
- }
- }
- final URL url = new URL(lines[0]);
- final String ref = url.getRef();
- final String protocol = url.getProtocol();
- final boolean encrypted = ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches();
- final boolean followedByDataUri = lines.length == 2 && lines[1].startsWith("data:");
- final boolean validAesGcm = AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted && (lines.length == 1 || followedByDataUri);
- final boolean validOob = ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted) && lines.length == 1;
- treatAsDownloadable = validAesGcm || validOob;
- } catch (MalformedURLException e) {
- treatAsDownloadable = false;
- }
+ treatAsDownloadable = MessageUtils.treatAsDownloadable(this.body, this.oob);
}
return treatAsDownloadable;
}
diff --git a/src/main/java/de/pixart/messenger/services/MessageSearchTask.java b/src/main/java/de/pixart/messenger/services/MessageSearchTask.java
index 1b10daa32..836b34b3b 100644
--- a/src/main/java/de/pixart/messenger/services/MessageSearchTask.java
+++ b/src/main/java/de/pixart/messenger/services/MessageSearchTask.java
@@ -46,6 +46,7 @@ import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.StubConversation;
import de.pixart.messenger.ui.interfaces.OnSearchResultsAvailable;
import de.pixart.messenger.utils.Cancellable;
+import de.pixart.messenger.utils.MessageUtils;
import de.pixart.messenger.utils.ReplacingSerialSingleThreadExecutor;
import rocks.xmpp.addr.Jid;
@@ -93,17 +94,28 @@ public class MessageSearchTask implements Runnable, Cancellable {
}
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToLast();
+ final int indexBody = cursor.getColumnIndex(Message.BODY);
+ final int indexOob = cursor.getColumnIndex(Message.OOB);
+ final int indexConversation = cursor.getColumnIndex(Message.CONVERSATION);
+ final int indexAccount = cursor.getColumnIndex(Conversation.ACCOUNT);
+ final int indexContact = cursor.getColumnIndex(Conversation.CONTACTJID);
+ final int indexMode = cursor.getColumnIndex(Conversation.MODE);
do {
if (isCancelled) {
Log.d(Config.LOGTAG, "canceled search task");
return;
}
- final String conversationUuid = cursor.getString(cursor.getColumnIndex(Message.CONVERSATION));
+ final String body = cursor.getString(indexBody);
+ final boolean oob = cursor.getInt(indexOob) > 0;
+ if (MessageUtils.treatAsDownloadable(body, oob)) {
+ continue;
+ }
+ final String conversationUuid = cursor.getString(indexConversation);
Conversational conversation = conversationCache.get(conversationUuid);
if (conversation == null) {
- String accountUuid = cursor.getString(cursor.getColumnIndex(Conversation.ACCOUNT));
- String contactJid = cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID));
- int mode = cursor.getInt(cursor.getColumnIndex(Conversation.MODE));
+ String accountUuid = cursor.getString(indexAccount);
+ String contactJid = cursor.getString(indexContact);
+ int mode = cursor.getInt(indexMode);
conversation = findOrGenerateStub(conversationUuid, accountUuid, contactJid, mode);
conversationCache.put(conversationUuid, conversation);
}
diff --git a/src/main/java/de/pixart/messenger/utils/MessageUtils.java b/src/main/java/de/pixart/messenger/utils/MessageUtils.java
index 1cf692f4d..8a3cdb707 100644
--- a/src/main/java/de/pixart/messenger/utils/MessageUtils.java
+++ b/src/main/java/de/pixart/messenger/utils/MessageUtils.java
@@ -29,7 +29,11 @@
package de.pixart.messenger.utils;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import de.pixart.messenger.entities.Message;
+import de.pixart.messenger.http.AesGcmURLStreamHandler;
public class MessageUtils {
public static String prepareQuote(Message message) {
@@ -51,4 +55,28 @@ public class MessageUtils {
}
return builder.toString();
}
+
+ public static boolean treatAsDownloadable(final String body, final boolean oob) {
+ try {
+ final String[] lines = body.split("\n");
+ if (lines.length == 0) {
+ return false;
+ }
+ for (String line : lines) {
+ if (line.contains("\\s+")) {
+ return false;
+ }
+ }
+ final URL url = new URL(lines[0]);
+ final String ref = url.getRef();
+ final String protocol = url.getProtocol();
+ final boolean encrypted = ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches();
+ final boolean followedByDataUri = lines.length == 2 && lines[1].startsWith("data:");
+ final boolean validAesGcm = AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted && (lines.length == 1 || followedByDataUri);
+ final boolean validOob = ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted) && lines.length == 1;
+ return validAesGcm || validOob;
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
} \ No newline at end of file