diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Message.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Message.java | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index c377ed4a..12127ecc 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -7,6 +7,7 @@ import java.net.MalformedURLException; import java.net.URL; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; +import eu.siacs.conversations.utils.FileUtils; import eu.siacs.conversations.utils.MimeUtils; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -480,16 +481,12 @@ public class Message extends AbstractEntity { String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase(); - final int lastDotPosition = filename.lastIndexOf('.'); - final int secondToLastDotPosition = filename.lastIndexOf('.', lastDotPosition - 1); - final String lastPart = lastDotPosition != -1 ? - filename.substring(lastDotPosition + 1) : ""; - final String secondToLastPart = secondToLastDotPosition != -1 ? - filename.substring(secondToLastDotPosition + 1, lastDotPosition - 1) : ""; + final String lastPart = FileUtils.getLastExtension(filename); - if (lastDotPosition != -1) { + if (!lastPart.isEmpty()) { // we want the real file extension, not the crypto one - if (secondToLastDotPosition != -1 && Transferable.VALID_CRYPTO_EXTENSIONS.contains(lastPart)) { + final String secondToLastPart = FileUtils.getSecondToLastExtension(filename); + if (!secondToLastPart.isEmpty() && Transferable.VALID_CRYPTO_EXTENSIONS.contains(lastPart)) { return secondToLastPart; } else { return lastPart; |