Properly parse attachment file names
This commit is contained in:
parent
db51241b81
commit
09956f809d
2 changed files with 80 additions and 7 deletions
|
|
@ -35,6 +35,7 @@ import com.simplemobiletools.smsmessenger.R
|
|||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||
import com.simplemobiletools.smsmessenger.databases.MessagesDatabase
|
||||
import com.simplemobiletools.smsmessenger.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.helpers.AttachmentUtils.parseAttachmentNames
|
||||
import com.simplemobiletools.smsmessenger.interfaces.AttachmentsDao
|
||||
import com.simplemobiletools.smsmessenger.interfaces.ConversationsDao
|
||||
import com.simplemobiletools.smsmessenger.interfaces.MessageAttachmentsDao
|
||||
|
|
@ -307,7 +308,8 @@ fun Context.getMmsAttachment(id: Long, getImageResolutions: Boolean): MessageAtt
|
|||
val selectionArgs = arrayOf(id.toString())
|
||||
val messageAttachment = MessageAttachment(id, "", arrayListOf())
|
||||
|
||||
var attachmentName = ""
|
||||
var attachmentNames: List<String>? = null
|
||||
var attachmentCount = 0
|
||||
queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor ->
|
||||
val partId = cursor.getLongValue(Mms._ID)
|
||||
val mimetype = cursor.getStringValue(Mms.Part.CONTENT_TYPE)
|
||||
|
|
@ -332,15 +334,14 @@ fun Context.getMmsAttachment(id: Long, getImageResolutions: Boolean): MessageAtt
|
|||
val attachment = Attachment(partId, id, fileUri.toString(), mimetype, width, height, "")
|
||||
messageAttachment.attachments.add(attachment)
|
||||
} else if (mimetype != "application/smil") {
|
||||
val attachment = Attachment(partId, id, Uri.withAppendedPath(uri, partId.toString()).toString(), mimetype, 0, 0, attachmentName)
|
||||
val attachment = Attachment(
|
||||
partId, id, Uri.withAppendedPath(uri, partId.toString()).toString(), mimetype, 0, 0, attachmentNames?.getOrNull(attachmentCount) ?: ""
|
||||
)
|
||||
messageAttachment.attachments.add(attachment)
|
||||
attachmentCount++
|
||||
} else {
|
||||
// todo: fix filename parsing, xml is shown some sometimes
|
||||
val text = cursor.getStringValue(Mms.Part.TEXT)
|
||||
val cutName = text.substringAfter("ref src=\"").substringBefore("\"")
|
||||
if (cutName.isNotEmpty()) {
|
||||
attachmentName = cutName
|
||||
}
|
||||
attachmentNames = parseAttachmentNames(text)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue