Skip to content

Commit

Permalink
Improve attachment name parsing
Browse files Browse the repository at this point in the history
See #261
  • Loading branch information
naveensingh committed Jan 3, 2025
1 parent 294571e commit 997f2f4
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import android.util.Xml
import org.xmlpull.v1.XmlPullParser

object AttachmentUtils {
private const val ELEMENT_TAG_IMAGE: String = "img"
private const val ELEMENT_TAG_AUDIO: String = "audio"
private const val ELEMENT_TAG_VIDEO: String = "video"
private const val ELEMENT_TAG_VCARD: String = "vcard"
private const val ELEMENT_TAG_REF: String = "ref"

private val ELEMENT_TAGS = arrayOf(
ELEMENT_TAG_IMAGE, ELEMENT_TAG_VIDEO, ELEMENT_TAG_AUDIO, ELEMENT_TAG_VCARD, ELEMENT_TAG_REF
)

fun parseAttachmentNames(text: String): List<String> {
val parser = Xml.newPullParser()
Expand Down Expand Up @@ -45,10 +54,11 @@ object AttachmentUtils {
continue
}

if (parser.name == "ref") {
val value = parser.getAttributeValue(null, "src")
names.add(value)
parser.nextTag()
if (parser.name in ELEMENT_TAGS) {
names.add(parser.getAttributeValue(null, "src"))
skip(parser)
} else {
skip(parser)
}
}
} else {
Expand Down

0 comments on commit 997f2f4

Please sign in to comment.